//@version=2 strategy("G_strategy w/ degola Final", overlay=true) uema = input(34, minval=1, maxval=50, title="EMA UpTrend") dema = input(34, minval=1, maxval=50, title="EMA DownTrend") shema = input(false, title="Show EMA Trend is Based On?") haclose = (open + high + low + close)/4 haopen = na(haopen[1]) ? (open + close)/2 : (haopen[1] + haclose[1]) / 2 upEma = ema(haclose, uema) downEma = ema(haopen, dema) emaAvg = (upEma + downEma)/2 heikUpColor() => hlc3 >= emaAvg heikDownColor() => hlc3 < emaAvg trendHA= sma(close,3) // TrendLine with haikin ashi candles information plot(trendHA, color= (heikUpColor() ? lime: heikDownColor() ? red :na),style=circles,linewidth=6, transp=40) //Plot heikin ashi trendline lime and red circles // Begin Strategies: tim=input('160') out1 = security(tickerid, tim, open) out2 = security(tickerid, tim, close) plot(out1,color=red, linewidth=2) plot(out2,color=green, linewidth=2) longCondition = crossover(security(tickerid, tim, close),security(tickerid, tim, open)) // basics conditions for trade shortCondition = crossunder(security(tickerid, tim, close),security(tickerid, tim, open)) // basics conditions for trade thestatustrade= (longCondition ? 1 : shortCondition ? 2 : 0) // the actual status about the trade //trailSTOP w/RSI Criteria: freqrsi = input(14,"frenquência rsi",defval=14,minval=1) obv = input(70, title= "Overbought Value", minval=50) osv = input(30, title= "Oversold Value", maxval=50) myrsi = (rsi(close,freqrsi) > obv) //overbuy calculation myrsi2 =(rsi(close,freqrsi) < osv) //oversell calculation barcolor(rsi(close,freqrsi) > obv ? #483D8B : rsi(close,freqrsi) < osv ? #EE82EE : na) // OB & OS results on colored screen cordabarra= ((myrsi ? 1: myrsi2 ? 2: 0)) plot(cordabarra,color=black,linewidth=7,style=area) // just to see the compilation is right n=input(title="candles de degola",type=integer,defval=5,minval=1, step=1) // degola technique input factor=input(title="factor",defval=20,minval=0,step=0.1,maxval=100) // for degola factor roseou=(out1>out2 and cordabarra==2)?1:0 roxou=(out2>out1 and cordabarra==1)?1:0 trailstopvenda= (roseou==1 ? open[n]-(factor/100)*abs(open[n]-close[n]) : open[n+n]) //calculate sold_trailstop at outside the loop trailstopcompra= (roxou ==1? open[n]+(factor/100)*abs(open[n]-close[n]) : open[n+n]) //calculate buyed_trailstop at outside the loop //Session Time: sessSpec = input("0900-1930", type=session) //Block to specify the hours&minutes interval for the PC do the trades timeinrange(res, sess) => not na(time(res, sess)) timeconditional= timeinrange("1", sessSpec) if (longCondition) //Buying (call) and closing the buy trade thestatustrade=1 trailstopcompraefetivo=(roxou ==1 ? open[n]+((factor/100)*abs(open[n]-close[n])) : open[n+n]) strategy.entry("long", strategy.long, when= (timeconditional==1),comment="entradacomprado") strategy.close_all(when = (close <= trailstopcompraefetivo)) if (shortCondition) //Selling (put) an closing the sell trade thestatustrade=2 trailstopvendaefetivo=(roseou==1 ? open[n]-((factor/100)*abs(open[n]-close[n])) : open[n+n]) strategy.entry("short", strategy.short, when= (timeconditional==1),comment="entradavendido") strategy.close_all(when = (close >= trailstopvendaefetivo)) trailstopcompraefetivo=(roxou==1 ? open[n]+((factor/100)*abs(open[n]-close[n])) : open[n+n]) //calculate buyed_trailstop at outside the loop again trailstopvendaefetivo=(roseou==1 ? open[n]-((factor/100)*abs(open[n]-close[n])) : open[n+n]) //calculate sold_trailstop at outside the loop again plot(trailstopcompraefetivo , color=maroon,linewidth=6) //plot bottom trailstop plot(trailstopvendaefetivo, color=orange,linewidth=6) //plot top trailstop plot(thestatustrade,transp=15,color=navy,linewidth=6,style=area) //plot to help compilate drawdown= input(title="Drawdown (%)", type=float, defval=50) strategy.risk.max_drawdown(drawdown, strategy.percent_of_equity) // set maximum drawdown to 50% of maximum equity