array out of range in 'MySc.mq4' (505,14)

 

i write a code to scan some indicators in definite time frame and i define some functions 

in a function i want to compare stochastic index for some shift time 


void twoColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")

{

   double Stochastic[];  

   int limit; 

   int counted_bars=IndicatorCounted();

   if(counted_bars<0) counted_bars=0;

   if(counted_bars<1) limit=Bars-1;

   else limit=Bars-counted_bars;

   for(int i=0; i<limit; i++)

   {

    Print(IntegerToString(i)+" x");

   Stochastic[i]=iStochastic(symbolName, MATimeframe, 14, 4, 4, MODE_SMA, 0, MODE_MAIN, i);   

   string tooltip=symbolName+".: "+GetPeriodStr(MATimeframe)+"\n Stoch :"+DoubleToStr(Stochastic[i],2)+"\nStoch : "+DoubleToStr(Stochastic[i-5],2);

   DrawLabel("ma_"+symbolName,x,y,DoubleToStr(Stochastic[i-1],1)+"    "+DoubleToStr(Stochastic[i-1],1),fontSize,fontName,clrWhite,tooltip);

   }

 }



but it show error in windows and stop running when i change time frame 

2020.12.05 00:12:06.001 MySc EURUSD,M5: array out of range in 'MyScanner.mq4' (505,14)

2020.12.05 00:12:06.001 MySc EURUSD,M5: 0 x


what is my errors and how can solve it  ?


 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. Trader98: what is my errors and how can solve it  ?
       double Stochastic[];  
       ⋮
       Stochastic[i]=iStochastic(…
    Your array has no size, therefor array exceeded. Perhaps it should be a buffer.
 
Trader98:

i write a code to scan some indicators in definite time frame and i define some functions 

in a function i want to compare stochastic index for some shift time 


but it show error in windows and stop running when i change time frame 

2020.12.05 00:12:06.001 MySc EURUSD,M5: array out of range in 'MyScanner.mq4' (505,14)

2020.12.05 00:12:06.001 MySc EURUSD,M5: 0 x


what is my errors and how can solve it  ?


You can do :

void twoColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")

{

   double Stochastic[];  

   int limit; 

   int counted_bars=IndicatorCounted();

   if(counted_bars<0) counted_bars=0;

   if(counted_bars<1) limit=Bars-1;

   else limit=Bars-counted_bars;

   ArrayResize(Stochastic,limit);

   for(int i=0; i<limit; i++)

   {

    Print(IntegerToString(i)+" x");

   Stochastic[i]=iStochastic(symbolName, MATimeframe, 14, 4, 4, MODE_SMA, 0, MODE_MAIN, i);   

   string tooltip=symbolName+".: "+GetPeriodStr(MATimeframe)+"\n Stoch :"+DoubleToStr(Stochastic[i],2)+"\nStoch : "+DoubleToStr(Stochastic[i-5],2);

   DrawLabel("ma_"+symbolName,x,y,DoubleToStr(Stochastic[i-1],1)+"    "+DoubleToStr(Stochastic[i-1],1),fontSize,fontName,clrWhite,tooltip);

   }

 }
 
remcous:

You can do :

thank you

but it does not work and show errors again

 
Trader98:

thank you

but it does not work and show errors again

Where are errors ? Have you try to debug step by step ? Coding and debugging is an art :-)

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
remcous:

Where are errors ? Have you try to debug step by step ? Coding and debugging is an art :-)

THANK FOR replying.

it show same error as past errors.

MySc EURUSD,H1: array out of range in 'MySc.mq4' (638,139)


i have a critical challenge and problem in working with arrAY in mql4.

and debug step by step does not help me to solve it.

i think that i should add a forgotten command or function to donot permit to exeed size of array. but i donot know what command i should add ?



The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products. If any errors are identified by the Market...
 

It tells you to look on line 505 cursor position 14.( line 638, pos 139 on the next one)

That is the exact location of the error.

Also this:

DoubleToStr(Stochastic[i-1],1)

If i == 0 and you do i-1 then that is -1 and that array location does not exist.

 
Marco vd Heijden:

It tells you to look on line 505 cursor position 14.( line 638, pos 139 on the next one)

That is the exact location of the error.

Also this:

If i == 0 and you do i-1 then that is -1 and that array location does not exist.

thank you for replying.  @Marco vd Heijden @Marco vd Heijden @Marco vd Heijden

Reason: