Array out of range

 

Hi Guys,

Could anyone assist me with why I get an array out of range error with this code and how to fix it? 

I am very new to MT4 coding. 

Thanks in advance! 

extern int MagicNumber=10001;
extern double Lots =0.1;
extern double StopLoss=100;
extern double TakeProfit=30;
extern int TrailingStop=0;
extern int Slippage=3;
double price=Ask;


//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int start()

{
  double result;
   
  {
     
     if((Close[-4]<Close[-3])&&(Close[-3]<Close[-2])&&(Close[-2]<Close[-1])) // Here is your open buy rule
     
      {result=OrderSend(Symbol(),OP_BUY,1,Ask,Slippage,30,100,"MyOrder",MagicNumber,0,clrGreen);}}
     

}
 
C0mput3r: I am very new to MT4 coding.
     
     if((Close[-4]<Close[-3])&&(Close[-3]<Close[-2])&&(Close[-2]<Close[-1])) // Here is your open buy rule
Apparently
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Bar zero is the currently forming bar. Bar one is one period back. You are trying to look at the future, so to prevent reality from being destroyed, the terminal errored you with array out of range.
 
-4 -3 -2 are not valid bar values you are trying to read the future not yet existing bars ?