Critical errors i cant find?

 

Hi, i sent the attached code to be published but the moderator has stated the following :

Programs should not contain critical errors that lead to immediate termination:

  • division by zero
  • going beyond array boundary
  • using an incorrect object pointer

Start your program on a chart and try to change it timeframe or symbol. Restart the terminal with an indicator/Expert Advisor attached to it. Such actions should not lead to program errors.

Not enough history data or vice versa too many bars on the chart should not hinder the client terminal operation or cause excessive use of computer resources.


 

 When i look for myself to find the problem i cant see what hes talking about. I try to change timeframe, chart but it appears okay?

Documentation on MQL5: Language Basics / Data Types / Object Pointers
Documentation on MQL5: Language Basics / Data Types / Object Pointers
  • www.mql5.com
Language Basics / Data Types / Object Pointers - Reference on algorithmic/automated trading language for MetaTrader 5
 
Stephen Reynolds:

Hi, i sent the attached code to be published but the moderator has stated the following :

Programs should not contain critical errors that lead to immediate termination:

  • division by zero
  • going beyond array boundary
  • using an incorrect object pointer

Start your program on a chart and try to change it timeframe or symbol. Restart the terminal with an indicator/Expert Advisor attached to it. Such actions should not lead to program errors.

Not enough history data or vice versa too many bars on the chart should not hinder the client terminal operation or cause excessive use of computer resources.


 

 When i look for myself to find the problem i cant see what hes talking about. I try to change timeframe, chart but it appears okay?

Seems all ok. But try add after OnCalculate(...){

if(Bars<20) return(0); 

 
  
      double iMacdHist2 = iMACD(_Symbol,_Period,FastPeriod,SlowPeriod,SignalPeriod,iMacPrice,MODE_MAIN,i+1);  

when i=rates_total - 1

index i+1 does not exist

 
 


// Record Session High Count
      static int highBars = TimeMinute(TimeCurrent());
      highBars++;      
      static int lowBars = TimeMinute(TimeCurrent());  
      lowBars++;      
          
      int lowest = iLowest(_Symbol,_Period,MODE_LOW,lowBars,i);  
      double lowestLow = Low[lowest];
      int highest = iHighest(_Symbol,_Period,MODE_HIGH,highBars,i);  
      double highestHigh = High[highest];

Your use of this static inside the for loop looks suspect.

highBars/lowBars don't always get reset each tick and could extend beyond the size of the array on subsequent ticks. If this happens then lowest and highest call will return -1 and the subsequent Low and High array accesses will cause a critical out of bounds error