
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Maybe the developers should pay attention to the problem of initialization of indicator buffers? Why is there no such a problem in MT4? Maybe it's not the full understanding? The problem is that even after the mandatory initialization of buffers after taking an indicator off a chart in EACH of them, not all buffers contain rubbish and you can't get it out of there...
Personally I don't mind crutches, but only if these crutches are not too complicated and with positive effect. But writing to a file and then reading it is a crummy crutch.
How do you imagine it: "...after removing the indicator from the chart in some, not all buffers..."? In what way, after deleting of the indicator from the chart, do you have access to its indicator buffers?
Let's try to find the problem in details. You need a standard set: code + what you did + what you got...
How do you imagine it: "...after removing the indicator from the chart in some, not all buffers..."? In what way, after the removal of the indicator from the chart, do you have access to its indicator buffers?
Let's try to find the problem in details. You need a standard set: code + what you did + what you got...
Pure assumption: it may be getting into the same memory area during the current buffer access, which was occupied by the previous buffers.
I haven't got into the conversation, don't kick, Alexey wants the data in buffers to remain at restarting (on/off switch of the terminal) or only when prev_calculated = 0 (in case if prev_calculated > 0 earlier)?
How do you imagine it: "...after removing the indicator from the chart in some, not all buffers..."? In what way, after the removal of the indicator from the chart, do you have access to its indicator buffers?
Let's try to find the problem in details. You need a standard set: code + what you did + what you got...
Here is the code of indicator
| BalansEquityTest.mq5 |
| Viktorov |
| v4forex@yandex.ru |
\********************************************************************/
#property copyright "Viktorov"
#property link "v4forex@yandex.ru"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 3
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrGold, clrGreen, clrRed
#property indicator_width1 2
#property indicator_label1 "Balance"
#property indicator_type2 DRAW_HISTOGRAM2
#property indicator_color2 clrCrimson
#property indicator_width2 2
#property indicator_label2 "EquityMin"
#property indicator_type3 DRAW_HISTOGRAM2
#property indicator_color3 clrDarkViolet
#property indicator_width3 2
#property indicator_label3 "EquityMax"
double balance[];
double clrBalance[];
double equityMaxB[];
double equityMinB[];
double equityMax[];
double equityMin[];
double maxEquity, minEquity;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0, balance, INDICATOR_DATA);
SetIndexBuffer(1, clrBalance, INDICATOR_COLOR_INDEX);
SetIndexBuffer(2, equityMin, INDICATOR_DATA);
SetIndexBuffer(3, equityMinB, INDICATOR_DATA);
SetIndexBuffer(4, equityMax, INDICATOR_DATA);
SetIndexBuffer(5, equityMaxB, INDICATOR_DATA);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, 0.0);
ArrayInitialize(balance, 0.0); // принудительная
ArrayInitialize(equityMax, 0.0); // инициализация
ArrayInitialize(equityMaxB, 0.0); // всех
ArrayInitialize(equityMin, 0.0); // буферов
ArrayInitialize(equityMinB, 0.0); // индикатора
ArraySetAsSeries(balance, true); // все
ArraySetAsSeries(clrBalance, true); // буферы
ArraySetAsSeries(equityMax, true); // индикатора
ArraySetAsSeries(equityMaxB, true); // имеют
ArraySetAsSeries(equityMin, true); // флаг
ArraySetAsSeries(equityMinB, true); // AS_SERIES
IndicatorSetInteger(INDICATOR_DIGITS, 2);
IndicatorSetString(INDICATOR_SHORTNAME, "Show Money");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
if(prev_calculated == 0)
return(rates_total);
double bal = AccountInfoDouble(ACCOUNT_BALANCE);
double equity = AccountInfoDouble(ACCOUNT_EQUITY);
if(rates_total > prev_calculated)
{
minEquity = 0;
maxEquity = 0;
}
minEquity = fmin((minEquity == 0 ? AccountInfoDouble(ACCOUNT_BALANCE) : minEquity), equity);
maxEquity = fmax(maxEquity, equity);
balance[0] = AccountInfoDouble(ACCOUNT_BALANCE);
clrBalance[0] = 0.0;
equityMinB[0] = balance[0];
equityMin[0] = minEquity;
equityMaxB[0] = balance[0];
equityMax[0] = maxEquity;
if(balance[0] > balance[1])
clrBalance[0] = 1.0;
if(balance[0] < balance[1])
clrBalance[0] = 2.0;
Comment(PositionsTotal());
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
I'll post a video a bit later, it'll be clear then. I can't explain it more clearly on my fingers than before.
I hope you do not mind downloading and unzipping the video.
Unfortunately, the fact of its removal from the chart and attaching to it was not recorded, but it has the fact that the indicator is there, then it is gone and then it is there again. It is just deleting and attaching it back.
Pay attention to the data window after re-installing the indicator. Even after forced initialisation of buffers, there is still space debris there.
Here is the code for the indicator
I would like to make an experiment: leave only one chart open and use it to put and remove the indicator. And you need information about terminal and operating system (tab "Log" of the terminal).
What does one chart have to do with it? The fact that the indicator is only on one chart isn't enough?
added:
Although I do not believe that the OS can affect the behavior of the indicator, here is information about the system and the terminal
2016.10.16 20:56:34.904 Terminal Windows 7 Home Premium (x64 based PC), IE 11.00, UAC, AMD FX-4170 Quad-Core Processor , RAM: 10531 / 12255 Mb, HDD: 55167 / 244198 Mb, GMT+03:00
2016.10.16 20:56:34.904 Terminal MetaTrader 5 build 1455 started (MetaQuotes Software Corp.)
What does one chart have to do with it? Isn't the fact that the indicator is only on one chart enough?
2016.10.18 19:09:34.266 Terminal Windows 10 Pro (x64 based PC), IE 11.00, UAC, Intel Core i3-3120 M @ 2.50 GHz, RAM: 3638 / 8077 Mb, HDD: 39824 / 233310 Mb, GMT+02:00
2016.10.18 19:09:34.266 Terminal C:\Users\KVN\AppData\Roaming\MetaQuotes\Terminal\038 C9E8FAFF9EA373522ECC6D5159962
So... The situation is beginning to take shape. Add this code:
//---
if(prev_calculated==0)
{
Print("prev_calculated==0");
return(rates_total);
}
double bal=AccountInfoDouble(ACCOUNT_BALANCE);
2016.10.18 19:09:34.266 Terminal Windows 10 Pro (x64 based PC), IE 11.00, UAC, Intel Core i3-3120 M @ 2.50 GHz, RAM: 3638 / 8077 Mb, HDD: 39824 / 233310 Mb, GMT+02:00
2016.10.18 19:09:34.266 Terminal C:\Users\KVN\AppData\Roaming\MetaQuotes\Terminal\038 C9E8FAFF9EA373522ECC6D5159962
Started executing, but when I start the indicator there are plague numbers in one buffer almost all over the history.
After removing the indicator and putting it back in after a while the buffers are empty.
I will repeat the removal and putting it back in later.
Preliminary conclusions:
So... The situation is beginning to take shape. Add code like this:
//---
if(prev_calculated==0)
{
Print("prev_calculated==0");
return(rates_total);
}
double bal=AccountInfoDouble(ACCOUNT_BALANCE);
Added like this