Loop Question
Hi, I am creating an EA from several custom indicators and am having a difficulty understanding loops. I need to count back x number of bars ( on an H1 chart) until I find the value of an indicator that is greater than 0. Once found, I need to return that value and compare it to the close of the last bar (the bar that has just closed). Can anyone point me in the right direction? Thanks for your help.
- Direction of Calculating an indicator
- How to code?
- How does one learn to make indicators?
tjeods:
Hi, I am creating an EA from several custom indicators and am having a difficulty understanding loops. I need to count back x number of bars ( on an H1 chart) until I find the value of an indicator that is greater than 0. Once found, I need to return that value and compare it to the close of the last bar (the bar that has just closed). Can anyone point me in the right direction? Thanks for your help.
Hi, I am creating an EA from several custom indicators and am having a difficulty understanding loops. I need to count back x number of bars ( on an H1 chart) until I find the value of an indicator that is greater than 0. Once found, I need to return that value and compare it to the close of the last bar (the bar that has just closed). Can anyone point me in the right direction? Thanks for your help.
Try something like . . .
int index = 0, exitloopearly = 1000; double indicatorvalue = 0.0; while(indicatorvalue <= 0.0 && index < exitloopearly) { indicatorvalue = iCustom( . . . ., index ); index++; } if (indicatorvalue > Close[1]) { do stuff . . . }
or this ...
#define LOOKBACK 20 double indicatorValue=0.0; for( int n=1; n<LOOKBACK; n++ ){ indicatorValue = iCustom( . . . ., n ); if( indicatorValue > 0.0 ) break; } if( indicatorValue > Close[1] ){ // do your stuff here }
RaptorUK, dabbler, Wow, thanks. This really helps. I should be able to make one of these work.