Errori, bug, domande - pagina 297

 
alexluek:
Alpari per tutte le coppie

Se non mi sbaglio, Alpari ha un lotto minimo di 0,10.

Ma per la validità e la verifica, come detto sopra, è meglio usare

double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
 

Errori durante la lettura di linee lunghe da file di testo

void testStr()
  {
   string fn= "test_str.txt",sRead,sWrite="";
   int cnStr=100,cnSymb=6000,i,fh;
   fh=FileOpen(fn,FILE_WRITE|FILE_TXT|FILE_ANSI);
   if(fh==INVALID_HANDLE) return;
   for(i=0; i<cnSymb; i++)
     {
      sWrite+=(string)(i%10);
     }
   int wrLen;
   for(i=0; i<cnStr; i++)
     {
      wrLen=FileWriteString(fh,sWrite+"\r\n")-2;
     }
   FileClose(fh);

   fh=FileOpen(fn,FILE_READ|FILE_TXT|FILE_ANSI);
   if(fh==INVALID_HANDLE) return;
   int readLen,minCn,j,error1Cn=0,error2Cn=0;
   for(i=0; i<cnStr; i++)
     {
      sRead=FileReadString(fh);
      readLen=StringLen(sRead);
      if(readLen!=wrLen)
        {
         if(error1Cn<3) Print("ERROR1 str: ",i," readLen: ",readLen,", wrLen: ",wrLen);
         error1Cn++;
        }
      int minCn=MathMin(readLen,wrLen);
      ushort chR,chW;
      for(j=0; j<minCn; j++)
        {
         chR = StringGetCharacter(sRead, j);
         chW = StringGetCharacter(sWrite, j);
         if(chR!=chW) break;
        }
      if(j!=minCn)
        {
         if(error2Cn<3) Print("ERROR2 str: ",i," symbol: ",j," chR: ",chR," chW: ",chW," readLen: ",readLen,", wrLen: ",wrLen);
         error2Cn++;
        }
     }
   FileClose(fh);
   Print("Str count: ",cnStr," str size: ",cnSymb," error1Cn: ",error1Cn," error2Cn: ",error2Cn);
  }
//---
void OnStart(){testStr();}

Sto ricevendo

Str count: 100 str size: 6000 error1Cn: 3 error2Cn: 1
ERROR1 str: 99 readLen: 0, wrLen: 6000
ERROR1 str: 98 readLen: 0, wrLen: 6000
ERROR2 str: 0 symbol: 5373 chR: 53 chW: 51 readLen: 5998, wrLen: 6000
ERROR1 str: 0 readLen: 5998, wrLen: 6000


Per favore, correggetelo il prima possibile.

 

Potete dirmi come fare in modo che la finestra dei dati visualizzi i nomi dei suoi buffer?

//+------------------------------------------------------------------+
//|                                                    ind_proba.mq5 |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window

#property indicator_plots   5  //must set, can be bigger than necessary, can not be bigger than indicator_buffers
#property indicator_buffers 15 //must set, can be bigger than necessary
                               //BufferPattern
#property indicator_type1   DRAW_COLOR_BARS  //DDDDC
#property indicator_width1  2
#property indicator_color1  Blue,Red,Green

//--- input parameters
double OpenBarBuff[];   //  data buffer
double HighBarBuff[];
double LowBarBuff[];
double CloseBarBuff[];
double ColorBarBuff[];   // color buffer
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

   SetIndexBuffer(0,OpenBarBuff,INDICATOR_DATA);
   SetIndexBuffer(1,HighBarBuff,INDICATOR_DATA);
   SetIndexBuffer(2,LowBarBuff,INDICATOR_DATA);
   SetIndexBuffer(3,CloseBarBuff,INDICATOR_DATA);
   SetIndexBuffer(4,ColorBarBuff,INDICATOR_COLOR_INDEX);

   PlotIndexSetString(0,PLOT_LABEL,"Open");
   PlotIndexSetString(1,PLOT_LABEL,"High");
   PlotIndexSetString(2,PLOT_LABEL,"Low");
   PlotIndexSetString(3,PLOT_LABEL,"Close");
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   CalcBars(rates_total,prev_calculated,open,high,low,close);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CalcBars(const int rates_total,
             const int prev_calculated,
             const double &open[],
             const double &high[],
             const double &low[],
             const double &close[])
  {
//--- auxiliary variables
   int i=0;
//--- set position for beginning
   if(i<prev_calculated) i=prev_calculated-1;
//--- start calculations
   while(i<rates_total)
     {
      OpenBarBuff[i]=open[i];
      HighBarBuff[i]=high[i];
      LowBarBuff[i]=low[i];
      CloseBarBuff[i]=close[i];
      ColorBarBuff[i]=(double)((close[i]>open[i])?0:(close[i]<open[i])?1:2);
      i++;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Vedere l'esempio sotto Proprietà del programma
 
Rosh:
Vedere l'esempio sotto Proprietà del programma

Grazie.
 
BoraBo:

Potete dirmi come fare in modo che la finestra dei dati visualizzi i nomi dei suoi buffer?

...
#property indicator_plots   1 
#property indicator_buffers 5
...
PlotIndexSetString(0,PLOT_LABEL,"Open;High;Low;Close");
...
 
BZSP:

Errori durante la lettura di linee lunghe da file di testo

Per favore, correggete il prima possibile.

Grazie per il messaggio, risolto.
 
mql5:
Grazie per il messaggio, corretto.
Grazie! Quando arriva la nuova costruzione?
 

La classe standard CChart è difettosa.

#include <Charts\Chart.mqh> // подключаем класс
void OnStart()
  {   
   CChart eur; // создаём объект
   eur.Attach(); // приатачиваем к чарту
  }

Esegui lo script e voilà, il grafico viene spazzato via dal vento :o)

Il grafico viene cancellato senza alcun messaggio di errore.

Документация по MQL5: Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений / Ошибки компиляции
Документация по MQL5: Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений / Ошибки компиляции
  • www.mql5.com
Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений / Ошибки компиляции - Документация по MQL5
 
Urain:

La classe CChart standard è difettosa.

Esegui lo script e voilà, il grafico viene spazzato via dal vento :o)

Il grafico viene cancellato senza alcun messaggio di errore.

Quando lo script finisce, tutti gli oggetti vengono distrutti automaticamente, inclusa un'istanza della classe CChart. Ma i distruttori degli oggetti creati sono chiamati durante il processo di distruzione. Nel nostro caso, il distruttore assomiglia a questo per la classe CChart

void CChart::Close()
  {
   if(m_chart_id!=-1)
     {
      ChartClose(m_chart_id);
      m_chart_id=-1;
     }
  }

cioè il grafico su cui è in esecuzione lo script è chiuso.

PS Leggete l'articolo L'ordine di creazione e distruzione degli oggetti in MQL5.

Motivazione: