How Do I Detect How Many Times a Moving Average Has Been Touched?
How Do I Detect How Many Times a Moving Average Has Been Touched?
05 Apr 2023, 16:35
I want to know how many times a moving average has been touched whilst above/below/breakout (can be open/high/low/close) or bounced off of it and even a false breakout of it.
Any ideas would be greatly appreciated.
The code is quite long but I could cut it down and post the bare bones of it if necessary.
Kind regards.
Replies
ctid5083541
06 Apr 2023, 15:03
RE:
Thanks for your input firemyst. I'm only interested in bars, ticks and renko are unlikely to be necessary. I only want to know if the moving average has been tested or a false breakout has recently occurred.
Kind regards.
firemyst said:
Are you wanting to check for each "tick", or only the previous bar?
It sounds like you're wanting to check each tick, but am not 100% sure.
If you want to check the previous bar when a new bar is formed, if you are on Renko charts it'll be a bit more complex than any of the other kinds of charts since cTrader doesn't keep track of Renko "tails" for bar related data.
Otherwise, pseudo business logic:
1) get current bar's open
2) check if open is initially above/below the MA
3) if open was below MA, then on each tick:
a) get the MA's current value
b) get the Symbol Ask/Bid/Closing price (whatever you want to consider has touched the MA)
c) check if the above price is >= MA current value
4) if open was above MA, then:
a) repeat steps 3a/3b
b) check if the price is <= MA current value
Hope that helps and is what you're after?
@ctid5083541
firemyst
06 Apr 2023, 08:23
Are you wanting to check for each "tick", or only the previous bar?
It sounds like you're wanting to check each tick, but am not 100% sure.
If you want to check the previous bar when a new bar is formed, if you are on Renko charts it'll be a bit more complex than any of the other kinds of charts since cTrader doesn't keep track of Renko "tails" for bar related data.
Otherwise, pseudo business logic:
1) get current bar's open
2) check if open is initially above/below the MA
3) if open was below MA, then on each tick:
a) get the MA's current value
b) get the Symbol Ask/Bid/Closing price (whatever you want to consider has touched the MA)
c) check if the above price is >= MA current value
4) if open was above MA, then:
a) repeat steps 3a/3b
b) check if the price is <= MA current value
Hope that helps and is what you're after?
@firemyst