Errors, bugs, questions - page 1175

 
A100:

......................functions (search, calculate, etc.) generally return length/size, or -1 if unsuccessful, which makes error handling much easier.

not so much as to sacrifice half the range of values.
 

Greetings. Any tips for newbies on what functions to use to set a common takeout on a grid of orders in the event of a reverse signal?

 
I'm learning file operations. Does anyone know if MQL4/5 works faster with csv or txt files?
 
paladin800:
I'm learning file operations. Does anyone know if MQL4/5 is faster with csv or txt files?
bin
 
papaklass:
What problems are you trying to solve by working with files?
You need to write the state of positions to a file and use MT4 to read this data. You need a correlation of positions of one symbol with other symbol(s). For example, if there is already a certain amount of positions on EURUSD, no more positions should be opened for GBPUSD. I know how to do it without file operations, I just want to learn how to work with file operations, just to broaden my horizons.
 

Please give a code example of how to call a linked resource indicator from an EA, which in turn uses another linked resource indicator in itself. For example, there is an indicator A, and B is called from it. There is also expert C that uses A. What should be written in #resource and when calling iCustom in all cases?

The help is not clearly written in this regard. The usual construction in indicator A:#resource "\\Indicators\B.ex4" and theniCustom(::Indicators\B.ex4) works fine when A is launched by itself.But if A is inserted into Expert Advisor#resource "\\Indicators\A.ex4", an errorcannot load resource for the attached indicator appearsindicating some absolute wrong synthesized path that somehow mentions Libraries directory, while indicator B is searched inside itself (MQL4\Libraries\::Indicators\B.ex4::Indicators\B.ex4).

 
meat:

Regarding ArraySize, I raised a similar problem on MQL4 the other day: https://www.mql5.com/ru/forum/152471. As far as I understand, everything should be the same in MQL5.

Perhaps, my message has been considered there :) Concerning this problem, the Service Desk has replied that the reason was incorrect operation of the optimizer and they will change the type to uint in new builds. In fact it is uint now, but it is undocumented :) And by the way, they will change it to uint for ArrayResize too. I advised them to change it to ulong, otherwise they will have to return to this problem because of the lack of 32-bit values when storing large volumes in the nearest future.

As for the value -1 on error, there should be no problem with it because: (int)-1 = (uint)-1 = 0xFFFFFFFFFF = UINT_MAX, i.e. the bit representation is the same. Though the comparison operation will give a different result. i.e. if it was so in the code

it will become incorrect.

Thanks again for the request, the return type of functions ArraySize and ArrayRange will not be changed, we will leave int type. We corrected the code optimizer, now the error described by you will not occur.

The total number of elements in the MQL array may not exceed INT_MAX and this will not change.
If you need arrays of larger size in an MQL program, you must create a separate class (for example, CBigArray).
 

Trying to master iCustom in mql5. I mastered it in mql4 :)

The problem is to draw something similar to MACD, but instead of a quick moving average the VIDYA indicator, which is in the Examples folder, should be used.

I took a standard MACD code and put parameters for VIDYA instead of the MA. The problem is that everything compiles but nothing is drawn.

I've marked two places in the code below where I've changed the standard MACD code. Otherwise everything is the same. Please tell me what else I'm missing. I'm assuming it's downstream somewhere in the code...

//+------------------------------------------------------------------+
//|                                                         MACD.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Moving Average Convergence/Divergence"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   2
#property  indicator_type1   DRAW_HISTOGRAM
#property  indicator_type2   DRAW_LINE
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_width1  2
#property  indicator_width2  1
#property  indicator_label1  "MACD"
#property  indicator_label2  "Signal"
//--- input parameters
Первый вставленный кусок:
input int                Per=7;               // Per
input int                Per1=21;             // Per1
input int                Shift=0            // Shift
Конец

input int                InpSlowEMA=84;               // Slow EMA period
input int                InpSignalSMA=9;              // Signal SMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double                   ExtMacdBuffer[];
double                   ExtSignalBuffer[];
double                   ExtFastMaBuffer[];
double                   ExtSlowMaBuffer[];
//--- MA handles
int                      ExtFastMaHandle;
int                      ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for Dindicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"MACD("+string(InpSlowEMA)+","+string(InpSignalSMA)+")");
//--- get MA handles
Второй вставленный кусок
   ExtFastMaHandle=iCustom(NULL,0,"Examples\\VIDYA",
                     Per,
                     Per1,
                     Shift
                     );
Конец
   ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_SMA,InpAppliedPrice);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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 &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
//--- check for data
   if(rates_total<InpSignalSMA)
      return(0);
//--- not all data may be calculated
   int calculated=BarsCalculated(ExtFastMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(ExtSlowMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
//--- we can copy not all data
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
//--- get Fast EMA buffer
   if(IsStopped()) return(0); //Checking for stop flag
   if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
     {
      Print("Getting fast EMA is failed! Error",GetLastError());
      return(0);
     }
//--- get SlowSMA buffer
   if(IsStopped()) return(0); //Checking for stop flag
   if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
     {
      Print("Getting slow SMA is failed! Error",GetLastError());
      return(0);
     }
//---
   int limit;
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
//--- calculate MACD
   for(int i=limit;i<rates_total && !IsStopped();i++)
      ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
//--- calculate Signal
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Nilog:

Trying to master iCustom in mql5. In mql4 I was able to master it virtuosely :)


What does it write to the log? No checks for errors (for example, when receiving a handle). Does the buffer number in the new indicator match the old one?
 

I don't know if this has already happened, but the question is, new bar, PLOT_EMPTY_VALUE value for the buffer is set to 0.0, but in fact there are sometimes completely different values