Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- strategy("TD9 Strat", overlay=true,default_qty_type=strategy.fixed, default_qty_value=1, initial_capital=1000, currency=currency.EUR,commission_type=strategy.commission.percent,commission_value=0.05)
- // === BACKTEST RANGE ===
- FromMonth = input(defval = 1, title = "From Month", minval = 1)
- FromDay = input(defval = 1, title = "From Day", minval = 1)
- FromYear = input(defval = 2018, title = "From Year", minval = 2014)
- ToMonth = input(defval = 1, title = "To Month", minval = 1)
- ToDay = input(defval = 1, title = "To Day", minval = 1)
- ToYear = input(defval = 9999, title = "To Year", minval = 2014)
- TPEnabled=1
- TPValue=45.0
- SLValue=25.0
- tp_val = input(TPValue, title='TP', type=float)/100
- sl_val = input(SLValue, title='SL', type=float)/100
- short_tp = strategy.position_avg_price * (1 - tp_val)
- long_tp = strategy.position_avg_price * (1 + tp_val)
- long_sl = strategy.position_avg_price * (1 - sl_val)
- short_sl = strategy.position_avg_price * (1 + sl_val)
- // === SERIES SETUP ===
- //SETUP
- //BUY SETUP
- compteur=0
- compteur:=nz(compteur[1],0)
- buySetupCondition = close < close[4]
- compteur := buySetupCondition ? compteur + 1 : compteur
- compteur := close >= close[4] and compteur!= 0 ? 0 : compteur
- buy= buySetupCondition
- c1 = compteur==1 and buy
- c2 = compteur==2 and buy
- c3 = compteur==3 and buy
- c4 = compteur==4 and buy
- c5 = compteur==5 and buy
- c6 = compteur==6 and buy
- c7 = compteur==7 and buy
- c8 = compteur==8 and buy
- c9 = compteur==9 and buy
- //SELL SETUP
- compteurS=0
- compteurS:=nz(compteurS[1],0)
- sellSetupCondition = close > close[4]
- compteurS := sellSetupCondition ? compteurS + 1 : compteurS
- compteurS := close <= close[4] and compteurS!= 0 ? 0 : compteurS
- sell= sellSetupCondition
- s1 = compteurS==1 and sell
- s2 = compteurS==2 and sell
- s3 = compteurS==3 and sell
- s4 = compteurS==4 and sell
- s5 = compteurS==5 and sell
- s6 = compteurS==6 and sell
- s7 = compteurS==7 and sell
- s8 = compteurS==8 and sell
- s9 = compteurS==9 and sell
- plotchar(s1 or c1?close:na,char='1',color=s1?green:red)
- plotchar(s2 or c2?close:na,char='2',color=s2?green:red)
- plotchar(s3 or c3?close:na,char='3',color=s3?green:red)
- plotchar(s4 or c4?close:na,char='4',color=s4?green:red)
- plotchar(s5 or c5?close:na,char='5',color=s5?green:red)
- plotchar(s6 or c6?close:na,char='6',color=s6?green:red)
- plotchar(s7 or c7?close:na,char='7',color=s7?green:red)
- plotchar(s8 or c8?close:na,char='8',color=s8?green:red)
- plotchar(s9 or c9?close:na,char='9',color=s9?green:red)
- // INTERSECTIONS
- //LONG & SHORT
- intersectionConditionB = (compteur == 8 or compteur == 9) and (high >= low[3] or high >= low[4])
- plotchar(intersectionConditionB?close:na,char='*',color=aqua,size=size.small)
- intersectionConditionS = (compteurS == 8 or compteurS == 9) and (low <= high[3] or low <= high[4])
- plotchar(intersectionConditionS?close:na,char='*',color=green,size=size.small)
- //COUNTDOWN
- countdownB=0
- countdownS=0
- countdownB:=nz(countdownB[1],0)
- countdownS:=nz(countdownS[1],0)
- cdConditionB = compteur>=9 and close < low[2]
- cdConditionS = compteurS>=9 and close > high[2]
- countdownB := cdConditionB and compteur>=9? countdownB + 1 : countdownB
- countdownS := cdConditionS and compteurS>=9? countdownS + 1 : countdownS
- countdownB := compteur<9 ? 0 : countdownB
- countdownS := compteurS<9 ? 0 : countdownS
- cdb1=cdConditionB and countdownB==1
- cds1=cdConditionS and countdownS==1
- cdb2=cdConditionB and countdownB==2
- cds2=cdConditionS and countdownS==2
- cdb3=cdConditionB and countdownB==3
- cds3=cdConditionS and countdownS==3
- cdb4=cdConditionB and countdownB==4
- cds4=cdConditionS and countdownS==4
- cdb5=cdConditionB and countdownB==5
- // cds5=cdConditionS and countdownS==5
- // cdb6=cdConditionB and countdownB==6
- // cds6=cdConditionS and countdownS==6
- // cdb7=cdConditionB and countdownB==7
- // cds7=cdConditionS and countdownS==7
- // cdb8=cdConditionB and countdownB==8
- // cds8=cdConditionS and countdownS==8
- // cdb9=cdConditionB and countdownB==9
- // cds9=cdConditionS and countdownS==9
- // cdb10=cdConditionB and countdownB==10
- // cds10=cdConditionS and countdownS==10
- // cdb11=cdConditionB and countdownB==11
- // cds11=cdConditionS and countdownS==11
- // cdb12=cdConditionB and countdownB==12
- // cds12=cdConditionS and countdownS==12
- // cdb13=cdConditionB and countdownB==13
- // cds13=cdConditionS and countdownS==13
- plotchar(cdb1 or cds1?close:na,char='1',color=cdb1?aqua:green,size=size.small,location=location.belowbar)
- plotchar(cdb2 or cds2?close:na,char='2',color=cdb2?aqua:green,size=size.small,location=location.belowbar)
- plotchar(cdb3 or cds3?close:na,char='3',color=cdb3?aqua:green,size=size.small,location=location.belowbar)
- plotchar(cdb4 or cds4?close:na,char='4',color=cdb4?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb5 or cds5?close:na,char='5',color=cdb5?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb6 or cds6?close:na,char='6',color=cdb6?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb7 or cds7?close:na,char='7',color=cdb7?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb8 or cds8?close:na,char='8',color=cdb8?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb9 or cds9?close:na,char='9',color=cdb9?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb10 or cds10?close:na,char='⑩',color=cdb10?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb11 or cds11?close:na,char='⑪',color=cdb11?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb12 or cds12?close:na,char='⑫',color=cdb12?aqua:green,size=size.small,location=location.belowbar)
- // plotchar(cdb13 or cds13?close:na,char='⑬',color=cdb13?aqua:green,size=size.small,location=location.belowbar)
- //MMA for bullish or bearish recognition
- lag1=input(1,minval=1,title="lag MMA 1")
- lag2=input(26,minval=1,title="lag MMA 2")
- mma1 = sma(close,lag1)
- mma2 = sma(close,lag2)
- plot(mma1,color=red,title="MMA 9")
- plot(mma2,color=green,title="MMA 18")
- //buycondition : green 1 and one in last 4 bars were in buycountdown (buyCD, depends on bullish or bearish trend)
- //sellcondition : green 1 and one in last 4 bars were in sellcountdown
- // plotchar(close>(buySetupCondition and compteur!=0 ? close[compteur] : 999999999),char='B',location=location.bottom,color=aqua,size=size.small)
- // plotchar(close<(sellSetupCondition and compteurS!=0 ? close[compteurS] : -9999999999),char='S',location=location.bottom,color=green,size=size.small)
- cd1 = input(1,minval=1,title="CD 1")
- cd2 = input(13,minval=1,title="CD 2")
- buyCD = mma2 < mma1 ? cd1 : cd2
- sellCD = mma2 > mma1? cd1 : cd2
- buycondition = compteurS==1
- sellcondition = compteur==1
- //plotchar(buycondition,char='B',location=location.bottom,color=aqua,size=size.small)
- //plotchar(sellcondition,char='S',location=location.bottom,color=green,size=size.small)
- plotgreen = plot(buySetupCondition and nz(compteurS[1],0)==0 ? close[compteur] : na, color = red, linewidth=2,style=linebr)
- plotred = plot(sellSetupCondition and nz(compteur[1],0)==0 ? close[compteurS] : na, color = green, linewidth=2,style=linebr)
- plot(close,linewidth=2,color=yellow)
- // === ALERTS ===
- strategy.entry("long", long=strategy.long, when = buycondition and strategy.position_size <=0)
- strategy.close("long", when = sellcondition )
- strategy.entry("short", long=strategy.short, when = sellcondition and strategy.position_size >=0)
- strategy.close("short", when = buycondition )
- if(TPEnabled)
- strategy.exit("TP","long", limit=long_tp)
- strategy.exit("TP","short", limit=short_tp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement