Simplified, CopyOpen is unnecessary for OnCalculate, but so it sees only the history from the terminal window?
Array mas is created with zero size on every tick and doesn't change its size anywhere else. So any access to it will cause array overrun.
To solve the problem, we should either resize it to the size, that will contain readings of all history bars, or bind it to the indicator buffer (declared as a global variable of the program). If I understand correctly, these values should be displayed using the indicator.
Simplified, CopyOpen I understand is superfluous for OnCalculate, but so it only sees the history from the terminal window?
Example:
//+------------------------------------------------------------------+//| Test.mq5 |//| Copyright 2018, MetaQuotes Software Corp. |//| https://mql5.com/ru/users/artmedia70 |//+------------------------------------------------------------------+#property copyright"Copyright 2018, MetaQuotes Software Corp."#property link"https://mql5.com/ru/users/artmedia70"#property version"1.00"#property indicator_separate_window#property indicator_buffers1#property indicator_plots1//--- plot OC#property indicator_label1"Open/Close"#property indicator_type1DRAW_LINE#property indicator_color1clrRed#property indicator_style1STYLE_SOLID#property indicator_width11//--- indicator buffersdouble BufferOC[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- Задаём массив BufferOC как буфер индикатораSetIndexBuffer(0,BufferOC,INDICATOR_DATA);
//--- Устанавливаем ему направление индексации как у таймсерииArraySetAsSeries(BufferOC,true);
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//--- Проверка на минимальное колиество баров для расчётаif(rates_total<1) return0;
//--- Установка массивов буферов как таймсерийArraySetAsSeries(open,true);
ArraySetAsSeries(close,true);
//--- Проверка и расчёт количества просчитываемых баровint limit=rates_total-prev_calculated;
if(limit>1) // если это первый запуск, или изменение истории, или открытие нового бара
{
limit=rates_total-1; // установим начало цикла на начало исторических данныхArrayInitialize(BufferOC,EMPTY_VALUE); // инициализируем массив
}
//--- Расчёт индикатораfor(int i=limit; i>=0 && !IsStopped(); i--)
{
if(close[i]==0) continue;
BufferOC[i]=open[i]/close[i];
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+
The mas array is created with a zero size on every tick and does not change its size anywhere else. Therefore, any reference to it will cause exit from the array.
To solve the problem, you should either resize it to the size that will contain readings of all history bars, or bind it to the indicator buffer (declared as a global variable of the program). If I understand correctly, it is these values that must be displayed using the indicator.
My mistake, mas[] should really be a global array, but the indicator buffer is not suitable either, it will rather be an intermediate multidimensional array. What is the best way to determine the optimal array size for M5, not through indicator buffer?
My inaccuracy, mas[] is really a global array, but indicator buffer is not suitable either, rather it would be an intermediate multidimensional array. What's the best way to determine optimal array size for M5, not through indicator buffer?
I don't understand what I mean by multidimensional. We are speaking of a one-dimensional array. In addition, in MQL4 the maximum dimension of an array is 4.
To make the array the same size as the timeseries, we should resize it according to the number of bars available on the chart for the needed symbol and period:
double fArray[];
int nBarsCnt = iBars(<символ>, <таймфрейм>);
if (ArrayResize(fArray, nBarsCnt) != nBarsCnt)
{
// Не удалось изменить размер массиваreturn;
}
ArraySetAsSeries(fArray, true);
My inaccuracy, mas[] is really a global array, but indicator buffer is not suitable either, rather it would be an intermediate multidimensional array. What's the best way to determine the optimal array size for M5, not through an indicator buffer?
Why don't you want to use arrays as indicator buffers? They are monitored by the subsystem, which makes your job easier.
how to do it properly?
How do you do it?
Simplified so, CopyOpen I understand is superfluous for OnCalculate, but so it only sees the history from the terminal window?
Simplified, CopyOpen is unnecessary for OnCalculate, but so it sees only the history from the terminal window?
Array mas is created with zero size on every tick and doesn't change its size anywhere else. So any access to it will cause array overrun.
To solve the problem, we should either resize it to the size, that will contain readings of all history bars, or bind it to the indicator buffer (declared as a global variable of the program). If I understand correctly, these values should be displayed using the indicator.
Simplified, CopyOpen I understand is superfluous for OnCalculate, but so it only sees the history from the terminal window?
Example:
The mas array is created with a zero size on every tick and does not change its size anywhere else. Therefore, any reference to it will cause exit from the array.
To solve the problem, you should either resize it to the size that will contain readings of all history bars, or bind it to the indicator buffer (declared as a global variable of the program). If I understand correctly, it is these values that must be displayed using the indicator.
My mistake, mas[] should really be a global array, but the indicator buffer is not suitable either, it will rather be an intermediate multidimensional array. What is the best way to determine the optimal array size for M5, not through indicator buffer?
My inaccuracy, mas[] is really a global array, but indicator buffer is not suitable either, rather it would be an intermediate multidimensional array. What's the best way to determine optimal array size for M5, not through indicator buffer?
I don't understand what I mean by multidimensional. We are speaking of a one-dimensional array. In addition, in MQL4 the maximum dimension of an array is 4.
To make the array the same size as the timeseries, we should resize it according to the number of bars available on the chart for the needed symbol and period:
My inaccuracy, mas[] is really a global array, but indicator buffer is not suitable either, rather it would be an intermediate multidimensional array. What's the best way to determine the optimal array size for M5, not through an indicator buffer?
Why don't you want to use arrays as indicator buffers? They are monitored by the subsystem, which makes your job easier.
And the intermediate indicator buffer array is easy to do:
Hello.
The volumes on the platform are tick volumes, will there be real volumes?
Hello.
On the platform the volumes are ticking, will there be any real volumes?
It won't. Use MT5, some brokers provide real volumes there.
Good afternoon!
Please help with the following problem:
1) After some conditions are met, a pending order opens:
{ price=High[1]+OrderPoint*Point; stoploss=Low[1]-Point; takeprofit=price+price-stoploss; OrderSend(Symbol(),OP_BUYSTOP,1,price,3,stoploss,takeprofit); }Please tell me what to add and where to delete a pending order if price has already passed stop loss (of this pending order).
Sorry for the stupid question, I got lost in the forums while searching for an answer.
Thanks in advance!