Strategy · Pine Script v4 · On the chart

Soulevement / Ressaut Strategy

by Sanji-dev· code credited to Sanji_moku

This strategy combines Ichimoku Kinko Hyo components, a Stochastic oscillator, and specific candlestick patterns to generate trade signals.

View on GitHub

GitHub stars7on the repository
Pine versionv4older, still runs
Lines of code224
Settings17inputs
LicenceMIT
Last update2 years ago19 Apr 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

224 lines of Pine Script v4 from [EA]Soulevement & Ressaut strategy.pinescript, published under MIT. Keep the author's credit and licence lines when you reuse it.

[EA]Soulevement & Ressaut strategy.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sanji_moku

//@version=4
strategy(title = "Soulevement/Ressaut strategy", shorttitle = "Soulevement/Ressaut strategy", overlay = true, initial_capital=10000)

// ---------------- INPUT  -------------- //
// Ichimoku lines   //
TenkanLen = input(9, title = "Tenkan-Sen", minval = 1)
KijunLen  = input(26, title = "Kijun-Sen", minval = 1)
SSBLen    = input(52, title = "Senkou Span B", minval = 1)
Offset    = input(26, title = "Offset", minval = 1)

// Date Input Range  //
mySession = input(title="Hours range for Alert", type=input.session, defval="0900-1700:23456")

// Activate //
alert       = input(false, title = "Enable Alert")
ShowTwist   = input(true, title = "Show Twist")
showSession = input(false, title = "Show Date Range")
ShowLines   = input(true, title = "Show Ichimoku Lines")

periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)

risk_per_trade = input(title="Risk par trade (%)",type=input.float,minval=0,maxval=100,step=0.1,defval=2)
tp_multi = input(title="Ratio Take Profit en % (%)",type=input.float,minval=1,maxval=100,step=0.1,defval=2)
nbrpips = input(title="Stop Loss en Pips",type=input.integer,minval=0,maxval=300,step=0.1,defval=5)*10

// ---------------- FONCTIONS  -------------- //
mediumHL(len) => avg(highest(len),lowest(len))
InSession(session) => na(time(timeframe.period, session)) == false  // InSession() determines if a price bar falls inside the specified session

// ---------------- ICHIMOKUES VALUES -------------- //
TenkanValue = mediumHL(TenkanLen)
KijunValue = mediumHL(KijunLen)
SSAValue = avg(TenkanValue,KijunValue)
SSBValue = mediumHL(SSBLen)
Chikou = close

Bas = lowest(close,52)
Haut= highest(close,52)

k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

breakOutHaut = close > highest(52)[1]
breakOutBas = close < lowest(52)[1]

var inRange = false
var entree = 0.0
// ---------------- CONDITIONS -------------- //
twist = (SSAValue[1] > SSBValue[1] and SSAValue[0] < SSBValue[0]) or (SSAValue[1]<SSBValue[1] and SSAValue[0]>SSBValue[0]) or (SSAValue[0] == SSBValue[0])

// Get user input
fibLevel = input(title="Fib Level", type=input.float, defval=0.333)
colorFilter = input(title="Color Must Match", type=input.bool, defval=false)

// Calculate fibonacci level for current candle
bullFib = (low - high) * fibLevel + high
bearFib = (high - low) * fibLevel + low

// Determine which price source closes or opens highest/lowest
lowestBody = close < open ? close : open
highestBody = close > open ? close : open

// Determine if we have a valid hammer or shooting star
hammerCandle = lowestBody >= bullFib and (not colorFilter or close > open)
starCandle = highestBody <= bearFib and (not colorFilter or close < open)

condition_haut_avant = close[2] > open[2] and open[1] >= close[2]
condition_bas_avant = close[2] < open[2] and open[1] <= close[2]

confirmation_haut = close < open and open <= close[1]
confirmation_bas = close > open and open >= close[1]

if twist
    inRange := true
    
if inRange[1] and (breakOutHaut or breakOutBas)
    inRange := false
    
surachat = k>80 and d>80
survente = k<20 and d<20

isGreenCandle() => 
    if close > open
        true
    else
        false

lowerShadow() => 
    if isGreenCandle()
        open - low
    else 
        close - low

upperShadow() => 
    if isGreenCandle()
        high - close
    else 
        high - open

realBody() => 
    abs(close - open)

hammerAndHangingMan=(lowerShadow() > 2 * realBody() and upperShadow() < realBody())

bullishEngulfing=(open[1] > close[1] and close > open and close[1] >= open and open[1] < close)

bearishEngulfing=(close[1] > open[1] and open > close and close[1] <= open and close < open[1])

buy_signal = inRange and survente and (hammerCandle or bullishEngulfing) and (strategy.position_size == 0)
sell_signal = inRange and surachat and (starCandle or bearishEngulfing) and (strategy.position_size == 0)




if (strategy.position_size[1] == 0) and (strategy.position_size != 0) // New position entry
    entree := open

newpos = (strategy.position_size[1] == 0) and (strategy.position_size != 0)

//conditionLong = bullishStar and ressaut and (strategy.position_size == 0)
//conditionShort = bearishStar and soulevement and (strategy.position_size == 0)



//ENTRY AND EXIT

//---PIPS---//
//var SL_from_Long = close - nbrpips * syminfo.mintick
//var TP_from_Long = close + nbrpips * 2 * syminfo.mintick
//SL_from_Long := strategy.position_size == 0 ? close - nbrpips * syminfo.mintick : SL_from_Long[1]
//TP_from_Long := strategy.position_size == 0 ? close + nbrpips * tp_multi * syminfo.mintick : TP_from_Long[1]


//---Kijun---//
//var SL_from_Long = (KijunValue[1] - 20 * syminfo.mintick )
//var TP_from_Long = close +(close - SL_from_Long) * tp_multi
//SL_from_Long := strategy.position_size == 0 ? (KijunValue[1] - 20 * syminfo.mintick ): SL_from_Long[1]
//TP_from_Long := strategy.position_size == 0 ? close +(close - SL_from_Long) * tp_multi : TP_from_Long[1]

//---Low and High---//
var SL_from_Long = low - nbrpips * syminfo.mintick
var TP_from_Long = close + (close - SL_from_Long) * tp_multi
SL_from_Long := strategy.position_size == 0 ? low - nbrpips * syminfo.mintick : SL_from_Long[1]
TP_from_Long := strategy.position_size == 0 ? close + (close - SL_from_Long) * tp_multi : TP_from_Long[1]



//---PIPS---//
//var SL_from_Short = close + nbrpips * syminfo.mintick
//var TP_from_Short = close - nbrpips * 2 * syminfo.mintick
//SL_from_Short := strategy.position_size == 0 ? close + nbrpips * syminfo.mintick : SL_from_Short[1]
//TP_from_Short := strategy.position_size == 0 ? close - nbrpips * tp_multi * syminfo.mintick : TP_from_Short[1]

//---Kijun---//
//var SL_from_Short = (KijunValue[1] + 20 * syminfo.mintick )
//var TP_from_Short = close - (SL_from_Short - close) * tp_multi
//SL_from_Short := strategy.position_size == 0 ? (KijunValue[1] + 20 * syminfo.mintick ): SL_from_Short[1]
//TP_from_Short := strategy.position_size == 0 ? close - (SL_from_Short - close) * tp_multi : TP_from_Short[1]

//---Low and High---//
var SL_from_Short = high + nbrpips * syminfo.mintick
var TP_from_Short = close - (SL_from_Short - close) * tp_multi
SL_from_Short := strategy.position_size == 0 ? high+ nbrpips * syminfo.mintick : SL_from_Short[1]
TP_from_Short := strategy.position_size == 0 ? close - (SL_from_Short - close) * tp_multi : TP_from_Short[1]


// ---------------- RISK MANAGEMENT -------------- //
riskEquity  = risk_per_trade * strategy.equity * 0.01
entryPrice = close 
posSize     = riskEquity / (entryPrice - SL_from_Long)
posSizeShort     = riskEquity / (SL_from_Short - entryPrice)

// ---------------- ORDERS -------------- //
strategy.entry("Ressaut", strategy.long, qty=posSize, when=buy_signal)
strategy.exit("Stop Long","Ressaut", stop = SL_from_Long, limit = TP_from_Long)
//strategy.exit("Stop Long","Long Breakout", stop = stopLoss, trail_points=start_trail, trail_offset=stop_trail)

strategy.entry("Soulèvement", strategy.short,qty=posSizeShort, when=sell_signal)
strategy.exit("Stop Short","Soulèvement", stop = SL_from_Short, limit = TP_from_Short)


// ---------------- PLOT -------------- //
plot(ShowLines ? TenkanValue : na, title = "Tenkan-Sen", color = color.red, linewidth = 1)
plot(ShowLines ? KijunValue : na , title = "Kijun-Sen", color = color.blue, linewidth = 1)
plot(ShowLines ? SSAValue : na , title = "Senkou Span A", color = color.orange, linewidth = 2, offset = Offset)
plot(ShowLines ? SSBValue : na , title = "Senkou Span B", color = color.aqua, linewidth = 2, offset = Offset)
plot(ShowLines ? Chikou : na , title = "Chikou Span", color = color.black, linewidth = 1, offset = -Offset)
//plot(Bas,title="Bas")
//plot(Haut, title="Haut")
bgcolor(color=InSession(mySession) and showSession? color.red : na, title="Trading Session", transp=96)

plotshape(twist and ShowTwist, text="Twist", textcolor=color.black, style=shape.diamond, color=color.black,location= location.abovebar, size=size.tiny)
plotshape(sell_signal, textcolor=color.red, style=shape.triangledown, color=color.red,location= location.abovebar, size=size.tiny)
plotshape(buy_signal, textcolor=color.green, style=shape.triangleup, color=color.green,location= location.belowbar, size=size.tiny)

//alertcondition(condition=twist,
//     title="Twist detector",
  //   message= "Twist")
  
line_entree = plot(strategy.position_size != 0 ? entree : na , color=color.black, style=plot.style_linebr)

// = plot(strategy.position_size > 0 ? stop_trail/100 : na, style=plot.style_linebr, color=color.orange, linewidth=1, title="Stop trail")
//lineStart_Trail_from_Long = plot(strategy.position_size > 0 ? start_trail/100 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Activate Trail SL")
//lineSL_from_Long = plot(strategy.position_size > 0 ? stopLoss : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")

//fill(lineStop_trail_from_Long, lineStart_Trail_from_Long, color=color.orange)
//fill(lineStart_Trail_from_Long, line_entree, color=color.green)
//fill(line_entree, lineSL_from_Long, color=color.red)

lineTP_from_Long = plot(strategy.position_size > 0 ? TP_from_Long : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")
lineSL_from_Long = plot(strategy.position_size > 0 ? SL_from_Long : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
fill(lineTP_from_Long, line_entree, color=color.green)
fill(line_entree, lineSL_from_Long, color=color.red)

lineTP_from_Short = plot(strategy.position_size < 0 ? TP_from_Short : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")
lineSL_from_Short= plot(strategy.position_size < 0 ? SL_from_Short : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")

fill(lineTP_from_Short, line_entree, color=color.green)
fill(line_entree, lineSL_from_Short, color=color.red)

Overview

Soulevement / Ressaut Strategy identifies Kumo twists and range breakouts while evaluating candle body shapes using Fibonacci threshold filters. Trades can be constrained to active session hours, with position sizing based on percentage account risk, fixed pip stop losses, and take profit targets. All indicator lines and session overlays are rendered directly on the main price chart.

Details

Published by

Sanji-dev on GitHub

Code credit

Sanji_moku, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Oscillators & momentum, Candlestick patterns, Moving averages

Markets

Forex

Timeframes

M1-M5, M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Tenkan-Senint9TenkanLen
Kijun-Senint26KijunLen
Senkou Span Bint52SSBLen
Offsetint26Offset
Hours range for Alertsession0900-1700:23456mySession
Enable Alertboolfalsealert
Show TwistbooltrueShowTwist
Show Date RangeboolfalseshowSession
Show Ichimoku LinesbooltrueShowLines
Kint14periodK
Dint3periodD
Smoothint3smoothK
Show all 17 settings
SettingTypeDefaultVariable
Risk par trade (%)float2risk_per_trade
Ratio Take Profit en % (%)float2tp_multi
Stop Loss en Pipsint5nbrpips
Fib Levelfloat0.333fibLevel
Color Must MatchboolfalsecolorFilter
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Improvisando [Alorse]

by Hugs-4-Bugs
4 stars

This strategy combines candlestick price action with Exponential Moving Average, RSI, and MACD filters to identify short-term trend trades. A long signal occurs when a bullish candle engulfs the previous open while price remains above the EMA, RSI stays below

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Improvisando [Alorse]
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers