//@version=5 indicator("EMA Scalping Strategy",) // Define EMAs capital=input(100) leverage =input(1) risk_reward_ratio=input(1.5) trade_NewYork=input(true) trade_London=input(true) trade_Tokyo=input(true) trade_Sydney=input(true) ema1_length=input(25) ema2_length=input(50) ema3_length=input(100) ema1 = ta.ema(close, ema1_length) ema2 = ta.ema(close, ema2_length) ema3 = ta.ema(close, ema3_length) // Plot EMAs on the chart plot(ema1, color=color.blue) plot(ema2, color=color.orange) plot(ema3, color=color.red) // Define spread condition for Buy and Short scenarios buyCondition = (ema1 > ema2+0.0001) and (ema2 > ema3+0.0001) and close>ema1 and close>open and (ema1[7] > ema2[7]+0.0001) and (ema2[7] > ema3[7]+0.0001) shortCondition = (ema3 > ema2+0.0001) and (ema2 > ema1+0.0001) and close ema2[7]+0.0001) and (ema2[7] > ema1[7]+0.0001) // Define Buy signal longSignal = lowema1 and shortCondition // Cancel setup conditions cancelLongSetup = (lowema3)or(high[1]>ema3[1])or(high[2]>ema3[2])or(high[3]>ema3[3])or(high[4]>ema3[4])or(high[5]>ema3[5])or(high[6]>ema3[6])or(high[7]>ema3[7]) inNY = trade_NewYork and time > timestamp(year, month, dayofmonth, 09, 00) and time < timestamp(year, month, dayofmonth, 18, 00) inLO = trade_London and time > timestamp(year, month, dayofmonth, 03, 00) and time < timestamp(year, month, dayofmonth, 12, 00) inTO = trade_Tokyo and (time > timestamp(year, month, dayofmonth, 20, 00) or time < timestamp(year, month, dayofmonth, 05, 00)) inSY = trade_Sydney and (time > timestamp(year, month, dayofmonth, 17, 00) or time < timestamp(year, month, dayofmonth, 02, 00)) var int barsSincePattern1 = 0 shouldPlot1 = longSignal and (barsSincePattern1 >= 10 or na(barsSincePattern1)) if (inNY or inLO or inSY or inTO) if (shouldPlot1 and not cancelLongSetup and strategy.opentrades == 0) strategy.entry("Buy", strategy.long, qty=capital*leverage) alert("Buy", alert.freq_all) strategy.exit("Exit", "Buy", stop=ema2, limit=close+(risk_reward_ratio*(close-ema2))) barsSincePattern1 := shouldPlot1 ? 0 : barsSincePattern1 + 1 var int barsSincePattern = 0 shouldPlot = shortSignal and (barsSincePattern >= 10 or na(barsSincePattern)) if (inNY or inLO or inSY or inTO) if (shouldPlot and not cancelShortSetup and strategy.opentrades == 0) strategy.entry("Short", strategy.short, qty=capital*leverage) alert("Sell", alert.freq_all) strategy.exit("Exit", "Short", stop=ema2, limit=close-(risk_reward_ratio*(ema2-close))) barsSincePattern := shouldPlot ? 0 : barsSincePattern + 1