array out of range in Mql4 EA

 
#property strict; //This line on the top

   int X_1 = (int)ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR)-1;
   int X_2 = (int)ChartGetInteger(0, CHART_VISIBLE_BARS)-2;
   int X_3 = X_1-X_2; 

   int LowBarNumber  = iLowest(Symbol(),Period(),MODE_LOW,X_2,X_3);
   int HighBarNumber  = iHighest(Symbol(),Period(),MODE_HIGH,X_2,X_3);


   LowMarginofChart = Low[LowBarNumber]+(margin*pips);     // (LowBarNumber)This is the error line.
   HighMarginofChart = High[HighBarNumber]-(margin*pips); // May be this is also.

hi,

I got this error in my code "array out of range in". with "Testing pass stopped due to a critical error in the EA"

When i run it Visual Mode, it OK! But without visual mode it stopped with error! I tried to fix it reading few solutions. But unable to  fix it. Please help me to fix it.

Thank you for your time.

 
LowMarginofChart = NormalizeDouble(iLow(_Symbol,Period(),LowBarNumber)+(margin*pips),Digits);
HighMarginofChart = NormalizeDouble(iHigh(_Symbol,Period(),HighBarNumber)+(margin*pips),Digits);
Print(LowMarginofChart);

I write it like this. Then error is fixed. Working well on Visual Mode.

But Without Visual mode, It never open Orders.

This Print result like that way.

result is: 2018.03.08 04:43:57.563    2018.03.05 23:47:30  EA EURUSD,H1: 0.0015
 

And i found this  Without "Visual Mode" :

   int LowBarNumber  = iLowest(Symbol(),Period(),MODE_LOW,X_2,X_3);
   int HighBarNumber  = iHighest(Symbol(),Period(),MODE_HIGH,X_2,X_3);
   Print(LowBarNumber + "  | " + HighBarNumber);

2018.03.08 05:00:23.509    2018.03.05 23:50:00  EA  EURUSD,H1: -1  | -1

With "Visual Mode":

2018.03.08 05:02:55.910    2018.01.12 16:02:30  EA  EURUSD,H1: 73  | 1


So how to fix it?

 
Without Visual Mode, It never take "X_1, X_2" values? May i correct?
 

Hello,

Where is the "Array out of range" error?

#property strict; //This line on the top

   int X_1 = (int)ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR)-1;
   int X_2 = (int)ChartGetInteger(0, CHART_VISIBLE_BARS)-2;
   int X_3 = X_1-X_2; 

   int LowBarNumber  = iLowest(Symbol(),Period(),MODE_LOW,X_2,X_3);
   int HighBarNumber  = iHighest(Symbol(),Period(),MODE_HIGH,X_2,X_3);


   LowMarginofChart = Low[LowBarNumber]+(margin*pips);     // (LowBarNumber)This is the error line.
   HighMarginofChart = High[HighBarNumber]-(margin*pips); // May be this is also.
Reason: