Errors, bugs, questions - page 297

 
alexluek:
Alpari for all pairs

If I'm not mistaken, Alpari has a minimum lot size of 0.10.

But for validity and verification, as mentioned above, it is better to use

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

Errors when reading long lines from text files

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

I'm getting

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


Please fix it as soon as possible.

 

Can you tell me how to make the data window display its buffer names ?

//+------------------------------------------------------------------+
//|                                                    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);
  }
//+------------------------------------------------------------------+
 
See example under Programme Properties
 
Rosh:
See example under Programme Properties

Thank you.
 
BoraBo:

Can you tell me how to make the data window display its buffer names ?

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

Errors when reading long lines from text files

Please fix as soon as possible.

Thanks for the message, fixed.
 
mql5:
Thanks for the message, corrected.
Thank you! When is the new build coming?
 

The standard CChart class is glitchy.

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

Run the script and voila, the chart is blown away by the wind :o)

The chart is deleted without any error messages.

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

The standard CChart class is glitchy.

Run the script and voila, the chart is blown away by the wind :o)

The chart is deleted without any error messages.

When the script finishes, all objects are destroyed automatically, including an instance of CChart class. But the destructors of created objects are called during the destruction process. In our case, the destructor looks like this for the CChart class

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

i.e. the chart on which the script is running is closed.

PS Read the article The Order of Object Creation and Destruction in MQL5.

Reason: