relative newbie trying to code an indicator that marks bars that are completely below the 20 EMA (i.e. high below 20 EMA) and only mark the first instance since there was a whole bar above the MA (i.e. low above MA) and alos the opposite (ie first whole bar above the MA). When I put in while loops to try and determine the shifts of the most recent bars above and below the MA the platform crashes. I'm not sure what I am doing wrong. I may need to separate the while loops from the for function calculating Range used in positioning of arrows but not sure how to do this. Suggestions for what I am doing wrong. Thanks
Probably your loops take too much time . . . you cannot decelerate the interface thread. Limit limit on the first run of the indicator to 100 bars and see how it goes . . .
int CountLowAboveMA=2; while(Low[i+CountLowAboveMA] <= iMA(NULL,0,20,0,1,0,i)) { CountLowAboveMA++; }What happens when i = Bars - 1? Low[i+n] is zero, ALWAYS, because it is off the chart. The Condition is ALWAYS true. Infinite loop.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
relative newbie trying to code an indicator that marks bars that are completely below the 20 EMA (i.e. high below 20 EMA) and only mark the first instance since there was a whole bar above the MA (i.e. low above MA) and alos the opposite (ie first whole bar above the MA). When I put in while loops to try and determine the shifts of the most recent bars above and below the MA the platform crashes. I'm not sure what I am doing wrong. I may need to separate the while loops from the for function calculating Range used in positioning of arrows but not sure how to do this. Suggestions for what I am doing wrong. Thanks