Perguntas de Iniciantes MQL5 MT5 MetaTrader 5 - página 418

 

Olá, recebi este erro - do registo de teste de estratégia:

2015.08.26 14:09:47.704 2001.08.29 16:15 matriz fora do alcance em 'Kamikadze_MA_V_04_42_Fibo_03.mq4' (929,29)

(929,29) - isto é uma corda e o número de sequência do carácter na corda?

 
-Aleks-:

Olá, recebi este erro - do registo de teste de estratégia:

2015.08.26 14:09:47.704 2001.08.29 16:15 matriz fora do alcance em 'Kamikadze_MA_V_04_42_Fibo_03.mq4' (929,29)

(929,29) - isto é uma corda e o número de sequência do caracter na corda?

Sim.
 
-Aleks-:

Olá, recebi este erro - do registo de teste de estratégia:

2015.08.26 14:09:47.704 2001.08.29 16:15 matriz fora do alcance em 'Kamikadze_MA_V_04_42_Fibo_03.mq4' (929,29)

(929,29) - isto é uma corda e o número de sequência do carácter na corda?

Muitas vezes o compilador não aponta directamente para o erro, mas está por perto algures)
 
Karputov Vladimir:
Sim.

Dois anos funciona, e depois bang e erro - penso que há muitas encomendas nesse ponto. Aqui está o código, o que está errado aqui (destacado em negrito) - aconselhar - por favor


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

Dois anos funciona, e depois bang e erro - penso que há muitas encomendas nesse ponto. Aqui está o código, o que está errado aqui (destacado em negrito) - aconselhar - por favor

Vai para fora da gama OrderBU.

Acrescentado: utilizar o estilo - isto ajudará a tornar o código legível.

 
-Aleks-:

Dois anos funciona, e depois bang e erro - penso que há muitas encomendas nesse ponto. Aqui está o código, o que está errado aqui (destacado em negrito) - aconselhar - por favor


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

O seu erro "Out of array" significa que a EA pede um valor superior ao array é inicializado ou o array é processado,

Por exemplo, se a matriz processar 6 parâmetros, na inicialização deve ser 6 (de 0 a 5 o que estamos a processar), a contagem é de zero e a inicialização é de 1.

 
Karputov Vladimir:

Vai para fora da gama OrderBU.

Acrescentado: utilizar o estilo - isto ajudará a tornar o código legível.

Obrigado pela dica, a janela da matriz é decente ArrayResize(OrderBU,1000); como é que...

Paga-se às pessoas - elas escrevem-na, e depois senta-se e intriga-se sobre ela.

 
Corretores com 2 e 4 dígitos, quantas casas decimais são metais?
 
-Aleks-:

Obrigado pela dica, a janela da matriz é decente ArrayResize(OrderBU,1000); como é que...

Paga-se às pessoas - elas escrevem-na, e depois senta-se e intriga-se sobre ela.

Desde que "passaram dois anos", significa que o código foi escrito para o antigo mql4, e sair da matriz era "possível" lá, agora não é, por isso agora é um erro. Tem razão.
 
Artyom Trishkin:
Desde "dois anos tem estado a funcionar", significa que o código foi escrito para o antigo mql4, onde as ultrapassagens de matriz eram "permitidas", agora não o são, agora é um erro. Tem razão.
Dois anos - em testador :) E o código de demonstração tem estado a funcionar há um ano. Houve lá muitos erros, quando tive de o ligar por causa de aulas externas... E agora há um bug que não sei como corrigir - vou aumentar o tamanho da matriz em um dígito, por enquanto. Porque não existe um tamanho automático, como para um buffer gráfico, ou existe?