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).
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...
inputint InpSlowEMA=84; // Slow EMA periodinputint InpSignalSMA=9; // Signal SMA periodinputENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price//--- indicator buffersdouble ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];
//--- MA handlesint ExtFastMaHandle;
int ExtSlowMaHandle;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+voidOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(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 drawnPlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for Dindicator subwindow labelIndicatorSetString(INDICATOR_SHORTNAME,"MACD("+string(InpSlowEMA)+","+string(InpSignalSMA)+")");
//--- get MA handles
ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_SMA,InpAppliedPrice);
//--- initialization done
}
//+------------------------------------------------------------------+//| Moving Averages Convergence/Divergence |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,constint prev_calculated,
constdatetime &Time[],
constdouble &Open[],
constdouble &High[],
constdouble &Low[],
constdouble &Close[],
constlong &TickVolume[],
constlong &Volume[],
constint &Spread[])
{
//--- check for dataif(rates_total<InpSignalSMA)
return(0);
//--- not all data may be calculatedint 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 dataint 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 bufferif(IsStopped()) return(0); //Checking for stop flagif(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
{
Print("Getting fast EMA is failed! Error",GetLastError());
return(0);
}
//--- get SlowSMA bufferif(IsStopped()) return(0); //Checking for stop flagif(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 MACDfor(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);
}
//+------------------------------------------------------------------+
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
......................functions (search, calculate, etc.) generally return length/size, or -1 if unsuccessful, which makes error handling much easier.
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 is faster with csv or txt files?
What problems are you trying to solve by working with files?
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).
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.
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...
Первый вставленный кусок:input int Per=7; // Per input int Per1=21; // Per1 input int Shift=0; // ShiftКонецВторой вставленный кусокКонецTrying to master iCustom in mql5. In mql4 I was able to master it virtuosely :)
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