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 Study vs Strategy EMA Discrepency

Jan 23, 2021 - 8:10 PM

Viewed 699 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/22552 COPY
  • Small problem I'm needing help with. Simple Pivot Reversal script, with an EMA confirmation. On study, I can get flags to appear at the proper location; In this case when HIGH is greater than the High Price AND when the EMA is greater than it was on the last bar. HOWEVER, in a strategy it appears late and I'm not sure why. Suggestions? Both Study and Strategy do indeed have the same criteria for flags and strategy entries.

    https://imgur.com/a/i73tfbK

    Experimenting I did determine the EMA confirmation is the issue. The flag/strategy entry line up perfectly without it enabled. But it appears in a strategy it doesn't recognize the EMA being higher than it was on the last bar

    Strategy;

    //EMA
    out1 = ema(ema1src, ema1len)
    ema1up = useema1 ? out1 > out1[1] : true
    ema1down = useema1 ? out1 < out1[1] : true

    if (longcondition and ema1up)
    strategy.entry(Long, strategy.long, qty = pos_size, comment=Long, stop=hprice + syminfo.mintick)

    Study;

    //EMA1
    out1 = ema(ema1src, ema1len)
    ema1up = iff(useema1, out1 > out1[1], true)
    ema1down = iff(useema1, out1 < out1[1], true)

    long_final = long and ema1up
    plotshape(long_final, text=Long, color=color.green, location=location.belowbar, style=shape.labelup, size=size.normal, textcolor=color.white)

    0
  • Hello there

    Maybe try with those 2 functions:

    rising: https://www.tradingview.com/pine-script-reference/v4/#fun_rising

    falling: https://www.tradingview.com/pine-script-reference/v4/#fun_falling

    0

    Dave - Helping traders becoming the best version of themselves
CONTENTS