Price to reverse trend of SMA

Forums ProRealTime English forum ProBuilder support Price to reverse trend of SMA

Viewing 6 posts - 1 through 6 (of 6 total)
  • #173237

    Hello Community,

    I’m looking for the simplest way to estimate the price at which the SMA20 would reverse from downtrend to uptrend or the opposite.

    I tried this code. Can you please review and comment?

    Thank you for your time.

     

     

    #173238

    I realize a made a few mistakes. In addition, my code tries to find what price is required to move the EMA by “1”, which is not what I’m trying to acheive.

    I’d like to find the price that reverses the EMA trend.

    Thanks for your help!

    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    DEFPARAM DRAWONLASTBARONLY=TRUE
    N=20
    EMA20= ExponentialAverage[N](close)
    ATR=AverageTrueRange[14](close)
    IF EMA7[1]<EMA7[2] THEN //currently in downtrend and waiting for a reverse
    x =round((1 + EMA7 EMA7[1] * (1 2 / (N+1)))*(N+1)/2)
    ENDIF
    IF EMA7[1]>EMA7[2] THEN //currently in uptrend and waiting for a reverse
    x =round((1 + EMA7 EMA7[1] * (1 2 / (N+1)))*(N+1)/2)
    ENDIF
    drawtext(”                                  SMA7 #x# “,barindex,0.5*ATR+highest[20](BollingerUp[20](close)),SansSerif,Bold,16)coloured(0,0,255)
    Return x

     

     

     

    #173252

    Hi, here is post #96165 from french forum with answer to same question: https://www.prorealcode.com/topic/formulation-ema/page/2/#post-96165

    #173256

    Thank you for your feeback.

    Doyou mean this code to find the “Close” at which EMA reverses?

    defparam drawonlastbaronly=true
    once customEMA=close
    once prevEMA=close
    EMALength = 10
    alpha = 2/(EMALength+1)
    once irange = 200 //ticks
    mincalc = prevEMA*100
    lasttest=mincalc
    if barindex>EMALength then
    CustomEMA= alpha*Close + (1alpha)*CustomEMA[1]
    for i = irange to irange do
      pricetest=(Close+i*ticksize)
      calc = alpha*pricetest + (1alpha)*CustomEMA[1]
      mincalc = min(mincalc,abs(calcCustomEMA[1]))
      if mincalc<=ticksize and mincalc<lasttest then
       lasttest=mincalc
       result=pricetest
       //break
      endif
    next
    DRAWTEXT(”                                            ———-    #result#  EMA”,barindex,result,dialog,standard,20) coloured(200,0,204)
    endif
    return result as “Close result”,mincalc as “min distance found”,customEMA coloured(200,0,0) style(line,2) as “real EMA”,CustomEMA[1] coloured(255,0,255) as “prevema”
    #173259

    Noobywan, As you mentionned yourself in post #96165, the code only provides the EMA[1], but not the EMA at which the trend reverses.

    #173269

    Hi, for ema case it’s both:

    • the ema at which it reverses is ema[1] (“by definition” because it is the limit for ema between going up or down), so that’s what was used in the post to create the equation to solve,
    • and the solution to the equation ema=ema[1] in the post was close=ema[1] (if not mistaken at the time I did it)

     

    For comparison, if I also come back to first post and look at an sma of N periods case, then:

    • similarily the level where sma would reverse is sma=sma[1],
    • that would be for close=sma[N]
    1 user thanked author for this post.
Viewing 6 posts - 1 through 6 (of 6 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login