Questions from Beginners MQL5 MT5 MetaTrader 5 - page 418

 

Hello, got this error - from strategy tester log :

2015.08.26 14:09:47.704 2001.08.29 16:15 array out of range in 'Kamikadze_MA_V_04_42_Fibo_03.mq4' (929,29)

(929,29) - is this a string and the sequence number of the character in the string?

 
-Aleks-:

Hello, got this error - from strategy tester log :

2015.08.26 14:09:47.704 2001.08.29 16:15 array out of range in 'Kamikadze_MA_V_04_42_Fibo_03.mq4' (929,29)

(929,29) - is this a string and the sequence number of the character in the string?

Yes.
 
-Aleks-:

Hello, got this error - from strategy tester log :

2015.08.26 14:09:47.704 2001.08.29 16:15 array out of range in 'Kamikadze_MA_V_04_42_Fibo_03.mq4' (929,29)

(929,29) - is this a string and the sequence number of the character in the string?

Often the compiler does not point directly to the error, but it is nearby somewhere)
 
Karputov Vladimir:
Yes.

Two years it works, and then bang and error - I think there are a lot of orders at that point. Here is the code, what is wrong here (highlighted in bold) - advise - please


            if(!CloseOk)
              {
               if(OrderType()==OP_BUY)
                 {
                  //Print("BUY=",OrderTicket());      
                  nBuy++;
                  if(lastTimeBuy<1 || lastTimeBuy<OrderOpenTime())lastTimeBuy=OrderOpenTime();
                  //if (TP_Error<stplvl/Point)TP_Error=stplvl/Point;
                  //if (OrderOpenPrice()+stplvl>MAT)NewTP=Ask+TP_Error*Point;else NewTP=MAT;
                  //if (TP_Error==0)NewTP=MAT;
                  NewTP=NormalizeDouble(MAT,Digits);
                  if(MathAbs(NewTP-OrderTakeProfit())>1*Point)
                    {//модифицируем ТП
                     if(swCommentary)
                        Print("Модификация Тейк-Профита BUY "+DoubleToStr(NewTP,Digits)+" OPEN="+OrderOpenPrice());
                     ModifyStopTake(0,stpls,NewTP);takepr=NewTP;
                    }
                  if(BU!=0 && OrderStopLoss()!=(OrderOpenPrice()+BU*Point) && //безубыток
                     Bid>BUbuy && Ask>(OrderOpenPrice()+BU*Point+stplvl) &&
                     (Levl_Zerro==0 || (maMirrorOBuy<(OrderOpenPrice()-Levl_Zerro*Point))))
                    {
                     if(swCommentary)Print("Безубыток BUY "+DoubleToStr(OrderOpenPrice()+BU*Point,Digits));
                     if(maMBlock!=1){Print("BUY 2");ModifyStopTake(0,OrderOpenPrice()+BU*Point,takepr);stpls=OrderOpenPrice()+BU*Point;}
                     OrderBU[NorderBU]=OrderTicket();NorderBU++;

                    }//maMBlock!=1&&
                  if(BarSL!=0 && iBarShift(NULL,0,OrderOpenTime())>=BarSL)
                    {
                     if(swCommentary)Print("BARSL BUY");ClosePosBySelect();
                     if(blockBarSL>0)
                       {
                        YesBarSLBuy=0;if(swCommentary)Print("blockBARSL BUY");
                        //ClosePositions("NULL",OP_BUY,Magic);
                        ClosePosBySelect();
                       }
                    }//BARSL
                 }
               if(OrderType()==OP_SELL)
                 {
                  //Print("SELL=",OrderTicket());
                  nSell++;
                  if(lastTimeSell<1 || lastTimeSell<OrderOpenTime())lastTimeSell=OrderOpenTime();
                  //if (TP_Error<stplvl/Point)TP_Error=stplvl/Point;
                  //if (OrderOpenPrice()-stplvl<MAT)NewTP=Bid-TP_Error*Point;else NewTP=MAT;
                  //if (TP_Error==0)NewTP=MAT;
                  NewTP=NormalizeDouble(MAT,Digits);
                  if(MathAbs(NewTP-OrderTakeProfit())>1*Point)
                    {//модифицируем ТП
                     if(swCommentary)
                        Print("Модификация Тейк-Профита SELL "+DoubleToStr(NewTP,Digits)+" OPEN="+OrderOpenPrice()+
                              " STOP="+OrderStopLoss());
                     ModifyStopTake(0,stpls,NewTP);takepr=NewTP;
                    }
                  if(BU!=0 && OrderStopLoss()!=(OrderOpenPrice()-BU*Point) && Bid<BUsell && //безубыток
                     Bid<(OrderOpenPrice()-BU*Point-stplvl) &&
                     (Levl_Zerro==0 || ((OrderOpenPrice()+Levl_Zerro*Point)<maMirrorOSell)))
                    {
                     if(swCommentary)Print("Безубыток SELL "+DoubleToStr(OrderOpenPrice()-BU*Point,Digits));
                     if(maMBlock!=1){Print("SELL 2");ModifyStopTake(0,OrderOpenPrice()-BU*Point,takepr);stpls=OrderOpenPrice()-BU*Point;}
                     OrderBU[NorderBU]=OrderTicket();NorderBU++;
                    }  // maMBlock!=1&&
                  if(BarSL!=0 && iBarShift(NULL,0,OrderOpenTime())>=BarSL)
                    {
                     if(swCommentary)Print("BARSL SELL");
                     ClosePosBySelect();
                     if(blockBarSL>0)
                       {
                        YesBarSLSell=0;if(swCommentary)Print("BARSL SELL");
                        //ClosePositions("NULL",OP_SELL,Magic);
                        ClosePosBySelect();
                       }
                    }//BARSL       
                 }
              }

 
-Aleks-:

Two years it works, and then bang and error - I think there are a lot of orders at that point. Here is the code, what is wrong here (highlighted in bold) - advise - please

You are going outside of the OrderBU array.

Added: use styling - this will help make the code readable.

 
-Aleks-:

Two years it works, and then bang and error - I think there are a lot of orders at that point. Here is the code, what is wrong here (highlighted in bold) - advise - please


            if(!CloseOk)
              {
               if(OrderType()==OP_BUY)
                 {
                  //Print("BUY=",OrderTicket());      
                  nBuy++;
                  if(lastTimeBuy<1 || lastTimeBuy<OrderOpenTime())lastTimeBuy=OrderOpenTime();
                  //if (TP_Error<stplvl/Point)TP_Error=stplvl/Point;
                  //if (OrderOpenPrice()+stplvl>MAT)NewTP=Ask+TP_Error*Point;else NewTP=MAT;
                  //if (TP_Error==0)NewTP=MAT;
                  NewTP=NormalizeDouble(MAT,Digits);
                  if(MathAbs(NewTP-OrderTakeProfit())>1*Point)
                    {//модифицируем ТП
                     if(swCommentary)
                        Print("Модификация Тейк-Профита BUY "+DoubleToStr(NewTP,Digits)+" OPEN="+OrderOpenPrice());
                     ModifyStopTake(0,stpls,NewTP);takepr=NewTP;
                    }
                  if(BU!=0 && OrderStopLoss()!=(OrderOpenPrice()+BU*Point) && //безубыток
                     Bid>BUbuy && Ask>(OrderOpenPrice()+BU*Point+stplvl) &&
                     (Levl_Zerro==0 || (maMirrorOBuy<(OrderOpenPrice()-Levl_Zerro*Point))))
                    {
                     if(swCommentary)Print("Безубыток BUY "+DoubleToStr(OrderOpenPrice()+BU*Point,Digits));
                     if(maMBlock!=1){Print("BUY 2");ModifyStopTake(0,OrderOpenPrice()+BU*Point,takepr);stpls=OrderOpenPrice()+BU*Point;}
                     OrderBU[NorderBU]=OrderTicket();NorderBU++;

                    }//maMBlock!=1&&
                  if(BarSL!=0 && iBarShift(NULL,0,OrderOpenTime())>=BarSL)
                    {
                     if(swCommentary)Print("BARSL BUY");ClosePosBySelect();
                     if(blockBarSL>0)
                       {
                        YesBarSLBuy=0;if(swCommentary)Print("blockBARSL BUY");
                        //ClosePositions("NULL",OP_BUY,Magic);
                        ClosePosBySelect();
                       }
                    }//BARSL
                 }
               if(OrderType()==OP_SELL)
                 {
                  //Print("SELL=",OrderTicket());
                  nSell++;
                  if(lastTimeSell<1 || lastTimeSell<OrderOpenTime())lastTimeSell=OrderOpenTime();
                  //if (TP_Error<stplvl/Point)TP_Error=stplvl/Point;
                  //if (OrderOpenPrice()-stplvl<MAT)NewTP=Bid-TP_Error*Point;else NewTP=MAT;
                  //if (TP_Error==0)NewTP=MAT;
                  NewTP=NormalizeDouble(MAT,Digits);
                  if(MathAbs(NewTP-OrderTakeProfit())>1*Point)
                    {//модифицируем ТП
                     if(swCommentary)
                        Print("Модификация Тейк-Профита SELL "+DoubleToStr(NewTP,Digits)+" OPEN="+OrderOpenPrice()+
                              " STOP="+OrderStopLoss());
                     ModifyStopTake(0,stpls,NewTP);takepr=NewTP;
                    }
                  if(BU!=0 && OrderStopLoss()!=(OrderOpenPrice()-BU*Point) && Bid<BUsell && //безубыток
                     Bid<(OrderOpenPrice()-BU*Point-stplvl) &&
                     (Levl_Zerro==0 || ((OrderOpenPrice()+Levl_Zerro*Point)<maMirrorOSell)))
                    {
                     if(swCommentary)Print("Безубыток SELL "+DoubleToStr(OrderOpenPrice()-BU*Point,Digits));
                     if(maMBlock!=1){Print("SELL 2");ModifyStopTake(0,OrderOpenPrice()-BU*Point,takepr);stpls=OrderOpenPrice()-BU*Point;}
                     OrderBU[NorderBU]=OrderTicket();NorderBU++;
                    }  // maMBlock!=1&&
                  if(BarSL!=0 && iBarShift(NULL,0,OrderOpenTime())>=BarSL)
                    {
                     if(swCommentary)Print("BARSL SELL");
                     ClosePosBySelect();
                     if(blockBarSL>0)
                       {
                        YesBarSLSell=0;if(swCommentary)Print("BARSL SELL");
                        //ClosePositions("NULL",OP_SELL,Magic);
                        ClosePosBySelect();
                       }
                    }//BARSL       
                 }
              }

Your error "Out of array" means that the EA asks for a value greater than the array is initialized or the array is processed,

For example, if the array processes 6 parameters, in the initialisation should be 6 (from 0 to 5 what we are processing), counting is from zero and the initialisation is from 1.

 
Karputov Vladimir:

You are going outside the OrderBU array.

Added: use styling - this will help make the code readable.

Thanks for the tip, the array window is decent ArrayResize(OrderBU,1000); how come...

You pay people - they write it, and then you sit and puzzle over it.

 
Brokers with 2 and 4 digits, how many decimal places are metals?
 
-Aleks-:

Thanks for the tip, the array window is decent ArrayResize(OrderBU,1000); how come...

You pay people - they write it, and then you sit and puzzle over it.

Since "two years have passed", it means that the code was written for old mql4, and getting out of the array was "possible" there, now it's not, so now it's an error. And you're right.
 
Artyom Trishkin:
Since "two years has been working", it means that the code was written for old mql4, where array overruns were "allowed", now they are not, now it's an error. You're right.
Two years - in tester :) And the demo code has been working for a year. There were a lot of errors there, when I had to plug it in because of external classes... And now there's a bug that I don't know how to fix - I'm going to increase the array's size by one digit, for now. Why isn't there an auto-size, like for a graphical buffer, or is there?
Reason: