Hello Forum
Wondering if someone might explain to me, or point me to the right part of the documentation ( I am not sure what topic to look under) how I go about achieving the following.
I have attached a simple indicator that draws up arrows when certain conditions are satisfied and down arrows when other conditions are satisfied.
The conditions themselves aren't important here and the attached example has grossly simplified conditions just to aid clarity
Anyway I would like to add consideration of divergence to my indicator, but I am not sure how to reference the previous occurrence that my buffer conditions are satisfied.
In this example when the ExtMapBuffer[i] conditions are satisfied and an up pointing arrow is drawn.
But if I want to compare the MACD values for this candle to the MACD value that occurred the last time an arrow was drawn, I need to be able to define last successful buffer.
And I am not sure how to do this? I assume each arrow drawn by a buffer becomes a unique object, but how are they referenced?
Indicator arrows are not Objects, don't even use the word object loosely to describe them or you risk confusing yourself and others. Indicator buffers are, by default, filled with a value of EMPTY_VALUE, if you don't change the value of the buffer index locations they will all contain EMPTY_VALUE. So you can tell when a location has a value in it as it will no longer be EMPTY_VALUE. To find the previous occurrence look through the previous values in the buffer until you find the next one that is not EMPTY_VALUE.
Thanks Raptor, I'll take care with my use of the word Objects.
I understand your advice that the arrow buffer will be either EMPTY_VALUE or not, depending on the conditions and I have used statements like" if (Buffer[i] != 0 )... previously in my code, but I am still not sure how to go about finding (using code) the previous non EMPTY_VALUE so that I can compare it with the current bar non EMPTY_VALUE
In words what I am wanting to do is. if the current buffer value is not empty, find the next occurrence of the buffer value[i] where (i>=1) such that buffer i does not equal 0
Extending on this it would seem logical to define variables (current_value and previous_value) such that:
if (Buffer[0] != 0), Buffer[0]=current_value
if (Buffer[i] != 0, where i>0) Buffer[i] = previous_value
But how would I write this such that I only got the last occasion of previous value
I suppose how do I stop the loop at that point so that I can compare current_value to previous_value
This is where my knowledge of how to code this falls short of what I can deduce logically
A little help would be greatly appreciated.
Thanks in advance
Thanks Raptor, I'll take care with my use of the word Objects.
I understand your advice that the arrow buffer will be either EMPTY_VALUE or not, depending on the conditions and I have used statements like" if (Buffer[i] != 0 )... previously in my code, but I am still not sure how to go about finding (using code) the previous non EMPTY_VALUE so that I can compare it with the current bar non EMPTY_VALUE
In words what I am wanting to do is. if the current buffer value is not empty, find the next occurrence of the buffer value[i] where (i>=1) such that buffer i does not equal 0
Extending on this it would seem logical to define variables (current_value and previous_value) such that:
if (Buffer[0] != 0), Buffer[0]=current_value
if (Buffer[i] != 0, where i>0) Buffer[i] = previous_value
But how would I write this such that I only got the last occasion of previous value
if (Buffer[0] != 0), Buffer[0]=current_value
if (Buffer[i] != 0, where i>0) Buffer[i] = previous_value
It seems to me you think EMPTY_VALUE is same as 0
Don't make that mistake ..... It isn't change ' != 0' for ' != EMPTY_VALUE'
I think
It seems to me you think EMPTY_VALUE is same as 0
Don't make that mistake ..... It isn't change ' != 0' for ' != EMPTY_VALUE'
Indeed . . .
EMPTY_VALUE | 0x7FFFFFFF | Default custom indicator empty value. |
I think
It seems to me you think EMPTY_VALUE is same as 0
Don't make that mistake ..... It isn't change ' != 0' for ' != EMPTY_VALUE'
Thank you I had definitely confused EMPTY_VALUE and 0, but can obviously see the distinction now you point it out
Very much appreciate the continuing help you guys give us newbies.
A Buffer is an Array but a little bit different, but it is indexed the same way as the bars are, 0 is the buffer value for the current bar, 1 is for the next bar to the left, etc. If Buffer[0] is you current arrow then you most likely have a re-painting indicator, that aside, what you want now is to find the previous arrow, so create a loop, for or while, they are interchangeable, that starts at 0, the last arrow position and loops through checking if Buffer[i] is != EMPTY_VALUE, when you find the next one that isn't EMPTY_VALUE it is your next arrow.
Thanks Raptor, suspect this is going to take me a while to learn, but I will get there and post results, or my best attempt at your suggested way forward.
int iLast = iNotEmpty(Buffer), iPrev = iNotEmpty(Buffer, iLast+1); ////////////////////////////////////////////////////////////////////////////////// int iNotEmpty(double ar[], int iBeg=0, int iLimit=WHOLE_ARRAY, int w=EMPTY_VALUE){ if(iLimit == WHOLE_ARRAY) iLimit = ArraySize(ar); for(; iBeg < iLimit; iBeg++) if(ar[iBeg] != w) return(iBeg); return(EMPTY); }How hard was that?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello Forum
Wondering if someone might explain to me, or point me to the right part of the documentation ( I am not sure what topic to look under) how I go about achieving the following.
I have attached a simple indicator that draws up arrows when certain conditions are satisfied and down arrows when other conditions are satisfied.
The conditions themselves aren't important here and the attached example has grossly simplified conditions just to aid clarity
Anyway I would like to add consideration of divergence to my indicator, but I am not sure how to reference the previous occurrence that my buffer conditions are satisfied.
In this example when the ExtMapBuffer[i] conditions are satisfied and an up pointing arrow is drawn.
But if I want to compare the MACD values for this candle to the MACD value that occurred the last time an arrow was drawn, I need to be able to define last successful buffer.
And I am not sure how to do this? I assume each arrow drawn by a buffer becomes a unique object, but how are they referenced?
Any help would be appreciated, thanks in advance.