Alert Error "array out of range" - page 3 123 New comment texoro 2014.04.24 11:13 #21 ok, tanks Keith Watford 2014.04.24 11:56 #22 GumRai: That is NOT all the code You call a function, DrawAllert and what is this? if (trendDown > trendUp) DrawAllert("Il trend è rialzista",clrRed); else if (trendDown > trendUp) DrawAllert("Il trend è ribassista",clrRed); The if and the else are the same condition!! DrawAllert("Il trend è ribassista",clrRed); will never be executed ffoorr: will always be executed How do you come to that conclusion? Keith Watford 2014.04.24 12:05 #23 You post what you claim to be the complete code with no buffers Then you post code that includes buffers You try to resize buffers . Go and learn some simple code. Don't try to run when you haven't learned how to crawl. William Roeder 2014.04.24 12:14 #24 First you tell us you are using arrays, so we tell you to resize them.double MovingAvarage40Buffer[]; double MovingAvarage50Buffer[]; int start() { : ArrayResize(MovingAvarage20,5);ArrayResize(ma20,5); ArrayResize(MovingAvarage40,5);ArrayResize(ma40,5); ArrayResize(MovingAvarage50,5);ArrayResize(ma50,5); Now you post all the code and you re not using arrays, you are using buffers. Do NOT resize buffers.double MovingAvarage40Buffer[]; double MovingAvarage50Buffer[]; int init(){ SetIndexBuffer(0,MovingAvarage20Buffer); ... } int start(){ /* ArrayResize(MovingAvarage20,5);*/ArrayResize(ma20,5); /* ArrayResize(MovingAvarage40,5);*/ArrayResize(ma40,5); : Count starts at zero. No need for the decrement Contradictory information on IndicatorCounted() - MQL4 forum int counted_bars = IndicatorCounted(); if( counted_bars > 0) counted_bars --; int limit=Bars-counted_bars; for(int j=0; j<limit; j++) To calculate a N moving average you must have N bars but you ask with j=Bars - 1. Handle your maximum look back.int counted_bars = IndicatorCounted(); #define LOOKBACK PeriodMovingAvarage50 // Largest if(counted_bars < LOOKBACK) counted_bars = LOOKBACK; for(int j=Bars - 1 - counted_bars; j >= 0; j--) Get in the habit of counting down. Is 50 the Largest or is 40? Typo? MovingAvarage20Buffer[j]= iMA(NULL, 0, PeriodMovingAvarage20,0, MODE_EMA, PRICE_CLOSE,j); MovingAvarage40Buffer[j]= iMA(NULL, 0, PeriodMovingAvarage40,0, MODE_EMA, PRICE_CLOSE,j); MovingAvarage5Buffer[j]= iMA(NULL, 0, PeriodMovingAvarage40,0, MODE_EMA, PRICE_CLOSE,j); Why are you putting a 50 MA into a buffer labeled 5? Same condition if (trendDown > trendUp) DrawAllert("Il trend è rialzista",clrRed); else if (trendDown > trendUp) DrawAllert("Il trend è ribassista",clrRed); If it's not up is MUST be down if (trendDown > trendUp) DrawAllert("Il trend è rialzista",clrRed); else //if (trendDown > trendUp) DrawAllert("Il trend è ribassista",clrRed); Or use the new Ternary Operator ?: - MQL4 DocumentationDrawAllert(trendDown > trendUp ? "Il trend è rialzista" : "Il trend è ribassista", clrRed); ffoorr 2014.04.24 14:19 #25 Gumrai, yes i'am wrong, ... "else if" will never be executed, but the "if" will be ? if (trendDown > trendUp) DrawAllert("Il trend è rialzista",clrRed); else if (trendDown > trendUp) DrawAllert("Il trend è ribassista",clrRed); 123 New comment
That is NOT all the code
You call a function, DrawAllert and what is this?
The if and the else are the same condition!!
DrawAllert("Il trend è ribassista",clrRed);
will never be executed
will always be executed
How do you come to that conclusion?
You post what you claim to be the complete code with no buffers
Then you post code that includes buffers
You try to resize buffers .
Go and learn some simple code. Don't try to run when you haven't learned how to crawl.
Gumrai, yes i'am wrong, ... "else if" will never be executed, but the "if" will be ?