Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

Pinescript N00b

Oct 11, 2020 - 6:43 AM

Viewed 504 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/20499 COPY
  • 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)

    0
  • I got it thanks

    longCond = crossover(s9ema, s21ema) and (s9ema > s200ema) and (s21ema > s200ema)
    shortCond = crossunder(s9ema, s21ema) and (s9ema < s200ema) and (s21ema < s200ema)

    1
  • Yes your update looks correct

    0

    Dave - Helping traders becoming the best version of themselves
CONTENTS