Price to reverse trend of SMA
Forums › ProRealTime English forum › ProBuilder support › Price to reverse trend of SMA
- This topic has 5 replies, 2 voices, and was last updated 3 years ago by JC_Bywan.
-
-
07/06/2021 at 5:46 PM #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.
Price to reverse trend of SMA12345678910111213141516171819DEFPARAM DRAWONLASTBARONLY=TRUEN=20SMA7= Average[N](close)ATR=AverageTrueRange[14](close)IF SMA7[1]<SMA7[2] THEN //currently in downtrend and waiting for a reversex =round((1 + SMA7 - SMA7[1] * (1 - 2 / (N+1)))*(N+1)/2)ENDIFIF SMA7[1]>SMA7[2] THEN //currently in uptrend and waiting for a reversex =round((-1 + SMA7 - SMA7[1] * (1 - 2 / (N+1)))*(N+1)/2)ENDIFdrawtext(" SMA7 #x# ",barindex,0.5*ATR+highest[20](BollingerUp[20](close)),SansSerif,Bold,16)coloured(0,0,255)Return x07/06/2021 at 5:59 PM #173238I 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!
2345678910111213141516171819DEFPARAM DRAWONLASTBARONLY=TRUEN=20EMA20= ExponentialAverage[N](close)ATR=AverageTrueRange[14](close)IF EMA7[1]<EMA7[2] THEN //currently in downtrend and waiting for a reversex =round((1 + EMA7 – EMA7[1] * (1 – 2 / (N+1)))*(N+1)/2)ENDIFIF EMA7[1]>EMA7[2] THEN //currently in uptrend and waiting for a reversex =round((–1 + EMA7 – EMA7[1] * (1 – 2 / (N+1)))*(N+1)/2)ENDIFdrawtext(” SMA7 #x# “,barindex,0.5*ATR+highest[20](BollingerUp[20](close)),SansSerif,Bold,16)coloured(0,0,255)Return x07/06/2021 at 8:10 PM #173252Hi, here is post #96165 from french forum with answer to same question: https://www.prorealcode.com/topic/formulation-ema/page/2/#post-96165
07/06/2021 at 8:24 PM #173256Thank you for your feeback.
Doyou mean this code to find the “Close” at which EMA reverses?
defparam drawonlastbaronly=trueonce customEMA=closeonce prevEMA=closeEMALength = 10alpha = 2/(EMALength+1)once irange = 200 //ticksmincalc = prevEMA*100lasttest=mincalcif barindex>EMALength thenCustomEMA= alpha*Close + (1–alpha)*CustomEMA[1]for i = –irange to irange dopricetest=(Close+i*ticksize)calc = alpha*pricetest + (1–alpha)*CustomEMA[1]mincalc = min(mincalc,abs(calc–CustomEMA[1]))if mincalc<=ticksize and mincalc<lasttest thenlasttest=mincalcresult=pricetest//breakendifnextDRAWTEXT(” ———- #result# EMA”,barindex,result,dialog,standard,20) coloured(200,0,204)endifreturn 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”07/06/2021 at 8:41 PM #17325907/07/2021 at 7:42 AM #173269Hi, 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.
-
AuthorPosts
Find exclusive trading pro-tools on