Download MetaTrader 5
To add comments, please log in or register
Sell products via the Market and track your sales statistics
C0mput3r
66
C0mput3r 2016.11.22 15:59 

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);}}
     

}
whroeder1
13605
whroeder1 2016.11.22 16:27  
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.
Marco vd Heijden
Moderator
4045
Marco vd Heijden 2016.11.22 19:34  
-4 -3 -2 are not valid bar values you are trying to read the future not yet existing bars ?
/
To add comments, please log in or register