24hour average of two moving average differences
Forums › ProRealTime English forum › ProOrder support › 24hour average of two moving average differences
- This topic has 7 replies, 2 voices, and was last updated 7 years ago by robdav.
-
-
01/26/2017 at 12:02 PM #22566
I’ve noticed that using the difference between two moving averages can provide a good exit point for a position when it gets over a certain value.
Some sample code:
MA5 = Average[5](close)
MA10 = Average[10](close)MADIFF = abs(MA5-MA10)
MADIFFpoints = MADIFF >= 2.2*pointsizeIF MADIFFpoints=1 THEN
EXITSHORT AT MARKET
ENDIFThe problem I have is that depending on the stock price, the MA difference can be quite large between different stocks.
I would therefore like to be able to dynamically calculate the average MA difference over the last 24 hours and then do something with that.
My question is, how can I code that?
Many thanks
Robert01/26/2017 at 12:18 PM #2256801/26/2017 at 12:54 PM #22574Yes, of course but I should add though that I’m using EMAs and not MAs as shown above, my mistake.
If you look at the difference of EMA5 and EMA10 on the FTSE it’s normally in the range 0-6 but Alphabet Inc for example is more in the range 0-100 so it’s that difference I want to use programmatically if that makes sense.
01/26/2017 at 1:51 PM #2258101/26/2017 at 2:44 PM #22589I’ve just been looking at a few examples. It seems that generally the range on a daily basis is fairly predictable barring massive price spikes which are hard to code for.
Therefore I think if I could establish what the range was for the differences in the two EMAs over the last 24 hour period and then say use 30% of that range as a value then that would suffice. I guess what I’m saying is the range/value wouldn’t need to be reset each day (unless it’s easy to do?) as it’s generally the same.
I have attached a couple of screen shots of the range I’m trying to capture in case it explains it better than I do. I can catch go exits when the difference get to a certain value.
Thanks Nicolas.
01/26/2017 at 2:49 PM #2259301/26/2017 at 3:58 PM #22611So basically, you want an average of the EMA difference. If you only need the average of the last 24 hours on a 5 minutes charts, you’ll need to adapt the period to 12*24 (12 bars of 5 minutes in an hour):
12345678factor = 40 //percent factor of the averageMA5 = exponentialAverage[5](close)MA10 = exponentialAverage[10](close)DIFF = abs(MA5-MA10)MADIFF = average[288](diff)*(factor/100)return diff, MAdiffI added a “factor” for you to adapt the trigger line (in percentage).
1 user thanked author for this post.
01/26/2017 at 4:44 PM #22628 -
AuthorPosts
Find exclusive trading pro-tools on