Hi all, I cant seem to get my pinescript to work when adding in the ma200, basically so it only longs and shorts above.below the ma 200, thanks
ema9 = ema(close, 9)
ema21 = ema(close, 21)
ma200 = sma(close, 200)
long = ema9 > ema21
short = ema9 < ema21
longcondition = long > ma200
shortcondition = short < ma200
plot(ema9, title=9
, color=color.blue, linewidth=1)
plot(ema21, title=21
, color=color.orange, linewidth =1)
plot(ma200,title=200
, color=color.green, linewidth = 1)
start = timestamp(2020,9,1,0,0)
end = timestamp(2020,10,31,0,0)
if time >= start and time <= end
strategy.entry("long", strategy.long, 1000.0, when = longcondition)
strategy.entry("short", strategy.short, 1000.0, when = shortcondition)
strategy.close(long
, when = closeshort)
strategy.close(short
, when = closelong)