Super!
Alors voici mon code:
Il faut d’abord mettre le graphique avec Renko puis la strategie peut être appliquée dans tradingview. Après avoir mis le graphique en Renko, on applique un RSI sur celui-ci et enfin on mets 2 moyenne mobiles sur ce rsi. Une court terme et une long terme. Ces moyennes mobiles vont créer les ordres de trades. On entrera dans un trade uniquement si la ‘Standard Deviation’ de x périod passée sera supérieur à une valeur fixe.
J’ai masqué certaines valeurs de paramètres allant de PERIODRSI et de VALEUR1 à 4. Je les rentrerai manuellement après votre contribution.
On applique un risk management de lors que la taille de la position dépend de la balance du compte. La quantité pour entrer dans la position fera que si le stop loss est touché, ce sera équivalent à une perte en capital de 1%. Aussi ajouté un trailing stop si possible
Cette stratégie sera appliquée sur des CFD dont dans le risk management il faudra prendre en compte la valeur d’un point je présume.
Merci beaucoup d’avance
//@version=3
strategy(title = "Strategy Code Example 2", shorttitle = "Strategy Code Example 2", overlay = true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, currency = currency.GBP, commission_type = strategy.commission.percent, commission_value = 0.1)
// RENKO INIT
renko_t = renko(tickerid, "open", "ATR", 10)
renko_low = security(renko_t, period, low)
plot(renko_low)
// RSI INIT
src = renko_low, len = input(PERIODRSI, minval=1, title="Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, color=green, linewidth=3)
// STANDARD DEVIATION
length = input(20, minval=1)
src5 = input(close, title="Source")
stdev = stdev(src5, length)
plot(stdev, color=blue)
// MA's INIT
// === GENERAL INPUTS ===
/// a couple of ma's..
maFast = ema(rsi, VALEUR1)
maSlow = ema(rsi, VALEUR2)
// === STRATEGY RELATED INPUTS ===
tradeInvert = input(defval = false, title = "Invert Trade Direction?")
// the risk management inputs
inpTakeProfit = input(defval = 1200, title = "Take Profit", minval = 0)
inpStopLoss = input(defval = 400, title = "Stop Loss", minval = 0)
inpTrailStop = input(defval = 400, title = "Trailing Stop Loss", minval = 0)
inpTrailOffset = input(defval = 0, title = "Trailing Stop Loss Offset", minval = 0)
// === RISK MANAGEMENT VALUE PREP ===
// if an input is less than 1, assuming not wanted so we assign 'na' value to disable it.
useTakeProfit = inpTakeProfit >= 1 ? inpTakeProfit : na
useStopLoss = inpStopLoss >= 1 ? inpStopLoss : na
useTrailStop = inpTrailStop >= 1 ? inpTrailStop : na
useTrailOffset = inpTrailOffset >= 1 ? inpTrailOffset : na
// === PLOTTING ===
fast = plot(maFast, title = "Fast MA", color = green, linewidth = 2, style = line, transp = 50)
slow = plot(maSlow, title = "Slow MA", color = red, linewidth = 2, style = line, transp = 50)
// === LOGIC ===
// is fast ma above slow ma?
aboveBelow = maFast >= maSlow ? true : false
// are we inverting our trade direction?
tradeDirection = tradeInvert ? aboveBelow ? false : true : aboveBelow ? true : false
// === STRATEGY - LONG POSITION EXECUTION ===
enterLong() => not tradeDirection[1] and tradeDirection and stdev[VALEUR4] >= VALEUR 3 // functions can be used to wrap up and work out complex conditions
exitLong() => tradeDirection[1] and not tradeDirection
// === STRATEGY - SHORT POSITION EXECUTION ===
enterShort() => tradeDirection[1] and not tradeDirection and stdev[VALEUR4] >= VALEUR3
exitShort() => not tradeDirection[1] and tradeDirection
// TRADING STARTEGY AND PARAMETERS
testStartYear = input(2012, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(2, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2018, "Backtest Stop Year")
testStopMonth = input(5, "Backtest Stop Month")
testStopDay = input(13, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
if time >= testPeriodStart
if time <= testPeriodStop
strategy.entry(id = "Long", long = true, when = enterLong()) // use function or simple condition to decide when to get in
strategy.entry(id = "Short", long = false, when = enterShort())
strategy.close(id = "Long", when = exitLong()) // ...and when to get out
strategy.close(id = "Short", when = exitShort())
if time >= testPeriodStart
if time <= testPeriodStop
strategy.exit("Exit Long", from_entry = "Long", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
strategy.exit("Exit Short", from_entry = "Short", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)