Questions des débutants MQL5 MT5 MetaTrader 5 - page 418

 

Bonjour, j'ai obtenu cette erreur - à partir du journal du testeur de stratégie:

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) - s'agit-il d'une chaîne de caractères et du numéro d'ordre du caractère dans la chaîne ?

 
-Aleks-:

Bonjour, j'ai obtenu cette erreur - à partir du journal du testeur de stratégie:

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) - s'agit-il d'une chaîne de caractères et du numéro d'ordre du caractère dans la chaîne ?

Oui.
 
-Aleks-:

Bonjour, j'ai obtenu cette erreur - à partir du journal du testeur de stratégie:

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) - s'agit-il d'une chaîne de caractères et du numéro d'ordre du caractère dans la chaîne ?

Souvent, le compilateur ne pointe pas directement vers l'erreur, mais elle est proche quelque part).
 
Karputov Vladimir:
Oui.

Deux ans que ça marche, et puis bang et erreur - je pense qu'il y a beaucoup de commandes à ce moment-là. Voici le code, ce qui ne va pas ici (mis en évidence en gras) - conseiller - s'il vous plaît


            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-:

Deux ans que ça marche, et puis bang et erreur - je pense qu'il y a beaucoup de commandes à ce moment-là. Voici le code, ce qui ne va pas ici (mis en évidence en gras) - conseiller - s'il vous plaît

Vous sortez du tableau de l'OrderBU.

Ajouté : utiliser le stylisme - cela aidera à rendre le code lisible.

 
-Aleks-:

Deux ans que ça marche, et puis bang et erreur - je pense qu'il y a beaucoup de commandes à ce moment-là. Voici le code, ce qui ne va pas ici (mis en évidence en gras) - conseiller - s'il vous plaît


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

Votre erreur "Out of array" signifie que l'EA demande une valeur supérieure à celle du tableau initialisé ou du tableau traité,

Par exemple, si le tableau traite 6 paramètres, l'initialisation doit être de 6 (de 0 à 5 ce que nous traitons), le comptage est de zéro et l'initialisation est de 1.

 
Karputov Vladimir:

Vous sortez du tableau de l'OrderBU.

Ajouté : utiliser le stylisme - cela aidera à rendre le code lisible.

Merci pour le conseil, la fenêtre du tableau est décente ArrayResize(OrderBU,1000) ; comment se fait-il que...

Vous payez des gens - ils l'écrivent, et ensuite vous vous asseyez et réfléchissez dessus.

 
Brokers avec 2 et 4 chiffres, combien de décimales sont les métaux ?
 
-Aleks-:

Merci pour le conseil, la fenêtre du tableau est décente ArrayResize(OrderBU,1000) ; comment se fait-il que...

Vous payez des gens - ils l'écrivent, et ensuite vous vous asseyez et réfléchissez dessus.

Puisque "deux ans ont passé", cela signifie que le code a été écrit pour l'ancienne mql4, et que sortir du tableau était "possible" là-bas, maintenant ça ne l'est plus, donc c'est une erreur. Vous avez raison.
 
Artyom Trishkin:
Puisque "deux années ont fonctionné", cela signifie que le code a été écrit pour l'ancienne mql4, où les dépassements de tableau étaient "autorisés", maintenant ils ne le sont plus, maintenant c'est une erreur. Vous avez raison.
Deux ans - en testeur :) Et le code de démonstration fonctionne depuis un an. il y avait beaucoup de règles de plantage là, quand je devais le connecter à cause de classes externes... Et maintenant il y a un bug que je ne sais pas comment résoudre - je vais augmenter la taille du tableau d'un chiffre, pour le moment. Pourquoi n'y a-t-il pas de taille automatique, comme pour un tampon graphique, ou y en a-t-il une ?