Hello,
How do I find out the number of bars between two reference points is greater than X. Is there a function for this?
Thanks.
Bars are identified by their time.
You know what TF your strategy is running on, so in a 30-minute TF the difference between, say, 100000 and 113000 will return 3 bars elapsed.
Is that what you meant?
Thanks for your reply Robertogozzi but not quite what I meant.
I want to know if point B has moved more than x bars from point A, irrespective of time-frame.
So for example, if an instrument has retraced more than 6 bars before detecting a bullish engulfing candle
I don’t know exactly what you mean, anyway when any event of your choice occurs tou may use BARINDEX to save that bar. At a later moment, whenever you choose to, you may retrueve that value and compare it to the caurrent BARINDEX to know exactly how many bars have elapsed.
This is an example saving the bar number when an average crossing happens and computes the number of bars elapsed from then to the next crossing:
ONCE EventBar = 0
a = Average[20](close)
b = Average[100](close)
IF (a CROSSES OVER b) OR (a CROSSES UNDER b) THEN //in case of any crossing
x = BARINDEX - EventBar //x will tell you how many bars have elapsed since the previous crossing
EventBar = BARINDEX //make it ready for the next count
ENDIF
Roberto
Thanks Roberto, BARINDEX is exactly what I’m looking for.
Hi Roberto,
I have the highest high during intraday being drawn on current bar. If for example the highest high bar occurred x bars ago and that particular bar had another value drawn on it by an indicator.
How do I make reference to that highest high bar (x bars ago) and have the code also show on current bar the value of the indicator on that x bar?
@
IG_CFD_Trader
Do not double post. You opened another topic.
Thank you 🙂