// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © jovi848.mcintyre //@version=4 strategy("My Strategy", overlay=true,slippage=2,initial_capital=2000*100,currency="USD",default_qty_type=strategy.fixed,default_qty_value=10000,commission_type=strategy.commission.percent,commission_value=0.001) fast = 12, slow = 26 fastMA = ema(close, fast) slowMA = ema(close, slow) macd = fastMA - slowMA signal = sma(macd, 9) EMA = ema(close,150) isChartUnderEMA = EMA>close isSignalandMACDAboveZero = signal > 0 and macd > 0 isSignalandMACDUnderZero = signal < -0 and macd < -0 longCondition = crossunder(signal,macd) and not isChartUnderEMA and isSignalandMACDUnderZero and strategy.position_size == 0 shortCondition = crossunder(macd,signal) and isChartUnderEMA and isSignalandMACDAboveZero and strategy.position_size == 0 // plot(series=longCondition? close*1.0018:na, color=color.lime,style=plot.style_cross, linewidth=2) // plot(series=shortCondition? close*1.0018:na, color=color.yellow,style=plot.style_cross, linewidth=2) ATR = atr(7) stop_level = high - (ATR*2) profit_level = close + (ATR*3) stop_loss = valuewhen(longCondition,stop_level,0) entry_price = valuewhen(longCondition,close[0],0) profit = valuewhen(longCondition,profit_level,0) float trail_stop_price = (((profit-entry_price)*.75)+entry_price)*1.0 trailing_stop_condition = (high>trail_stop_price) // if(trailing_stop_condition) // profit := (profit-entry_price)*1.25+ entry_price // strategy.exit("TP Trailing Stop", "My Long Entry Id", stop=1, limit=profit) // plot(series=trailing_stop_condition and strategy.position_size > 0? profit:na, color=color.yellow,style=plot.style_cross, linewidth=2) plot1 = plot(series=strategy.position_size > 0 ?profit:na , color=color.green,style=plot.style_linebr, linewidth=1) plot2 = plot(strategy.position_size > 0 ?entry_price:na , color=color.green,style=plot.style_linebr, linewidth=1) plot3 = plot(series=strategy.position_size > 0 ?stop_loss:na , color=color.red,style=plot.style_linebr, linewidth=1) fill(plot1,plot2, title="Long Ribbon", color=color.green) fill(plot2,plot3, title="Long Ribbon", color=color.red) if(longCondition) strategy.entry("My Long Entry Id", strategy.long)//,when = isDate() and isTime(entryTime)) strategy.exit("TP/SL LONG", "My Long Entry Id", stop=stop_level, limit=profit_level) if (shortCondition) stop_level := high + (ATR*2) profit_level := close - (ATR*3.5) // strategy.entry("My Short Entry Id", strategy.short)//,when = isDate() and isTime(entryTime)) // strategy.exit("TP/SL Short", "My Short Entry Id", stop=stop_level, limit=profit_level) plot(EMA,color=color.orange) // plot(series=longCondition or shortCondition? profit_level:na, color=color.lime,style=plot.style_cross, linewidth=2) // plot(series=longCondition or shortCondition? stop_level:na, color=color.red,style=plot.style_cross, linewidth=2)