Why you may receive an error with this content?
2020.06.10 18:14:59.111 program file ExpertsmyBots oTradepatternsTradingmyIndicatorsPACandlePatterns.ex5 read error
Here are 2 functions that explain the question:
//==================================================================================================================================================================================================
All parameters of the indicator are used by default. Accordingly, in mqlparam, I put only the name of the indicator in the first index of the array. Nothing else. After creating the indicator handle, I set a breakpoint to find out the cause of the error. I attach the screen.
// Creates a handle of the candlepatterns indicator on the specified index. ===================================================================================================================================
int Signal :: createCandlePatternsHandle(const int bufferIndex, const int shift, ENUM_TIMEFRAMES tf = PERIOD_CURRENT) {
int handle = iCustom(_Symbol, _Period, "CandlePatterns", true, true, true, 30);
Print("_LastError = " + _LastError);
Print("handle = " + handle);
// return (handle != INVALID_HANDLE) ? true : false;
return handle;
}
//==================================================================================================================================================================================================
// Returns the values of the candlepatterns indicator at the specified index. ==============================================================================================================================
double Signal :: getCandlePatternsValue(const int bufferIndex, const int shift, ENUM_TIMEFRAMES tf = PERIOD_CURRENT) {
double havingPattern[];
ArrayResize(havingPattern, 1);
int handle = createCandlePatternsHandle(bufferIndex, shift, tf);
ResetLastError();
int res = CopyBuffer(handle, bufferIndex, shift, 1, havingPattern);
Print("res = " + res);
return havingPattern[0];
}
In the debugger window, you can see that the indicator handle is 1. Accordingly, the handle is created without errors because there is no -1 error.
The types of all passed variables correspond to those required by the signature of the copybuffer function()
The buffer number was set to 0..
How IS IT that some kind of reading error occurs? After all, the indicator is working. The handle is created. The error is related to the copybuffer () function, as I understand it. But how can this be? How to check it?
program file Experts….THE PATH TO THE EXPERT..CandlePatterns.ex5 read error
Share
traderchik
in general, i came up with a slightly different test. to make it easier to check just what i threw a script with the following content:
//+------------------------------------------------------------------+
//| forOnce.mq5 |
//| hoz |
//| |
//+------------------------------------------------------------------+
#property copyright "hoz"
#property link ""
#property version "1.00"
int candlePatternsHandle = -1;
int copied;
double havingPattern[1];
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart() {
candlePatternsHandle = iCustom(_Symbol, _Period, "CandlePatterns");
Print(__FUNCTION__ + ":: _candlePatternsHandle = " + candlePatternsHandle);
while (candlePatternsHandle < 0) {
Print(__FUNCTION__ + ":: candlePatternsHandle = " + candlePatternsHandle);
Sleep(5000);
}
for (int i = 0; i < 5; i++) {
copied = CopyBuffer(candlePatternsHandle, 1, i, 1, havingPattern);
Print(__FUNCTION__ + ":: copied = " + copied);
// Print(__FUNCTION__ + ":: havingPattern[" + i + "] = " + havingPattern[0] + " ; i = " + i);
if (havingPattern[0] != EMPTY_VALUE) {
// Print(__FUNCTION__ + ":: havingPattern[0] != EMPTY_VALUE");
// Print(__FUNCTION__ + ":: havingPattern[", + i + "] = " + DoubleToString(havingPattern[0]));
}
}
}
in this case, i want to get the value of the 1st buffer of the indicator using the copybuffer () function. It doesn’t work. In the log I see:
2020.06.12 20:53:58.161 forOnce (GBPUSD,W1) OnStart:: _candlePatternsHandle = 10
2020.06.12 20:53:58.261 forOnce (GBPUSD,W1) OnStart:: copied = -1
2020.06.12 20:53:58.261 forOnce (GBPUSD,W1) OnStart:: copied = -1
2020.06.12 20:53:58.261 forOnce (GBPUSD,W1) OnStart:: copied = -1
2020.06.12 20:53:58.261 forOnce (GBPUSD,W1) OnStart:: copied = -1
2020.06.12 20:53:58.261 forOnce (GBPUSD,W1) OnStart:: copied = -1
If I change 1 to 0, i.e. I want to get the value of the 0th buffer, then everything turns out:
2020.06.12 20:56:48.967 forOnce (GBPUSD,W1) OnStart:: _candlePatternsHandle = 10
2020.06.12 20:56:49.068 forOnce (GBPUSD,W1) OnStart:: copied = 1
2020.06.12 20:56:49.068 forOnce (GBPUSD,W1) OnStart:: copied = 1
2020.06.12 20:56:49.068 forOnce (GBPUSD,W1) OnStart:: copied = 1
2020.06.12 20:56:49.068 forOnce (GBPUSD,W1) OnStart:: copied = 1
2020.06.12 20:56:49.068 forOnce (GBPUSD,W1) OnStart:: copied = 1
By the way, when I get data from the 0th buffer, everything is clear. The desired bar is located, with a pattern that displays the indicator. The opening price of this bar is printed (if I comment out the line for this in the script). In fact, all thoughts converged on the fact that something is wrong only with the copybuffer () function, or with the indicator. With the function copybuffer (), it is unlikely that something is wrong because it is used by everyone and not for the first year. It means something with a turkey.
But it is interesting that both buffers, in fact, are written almost by copy-paste from one another with a change in only one condition. That’s what’s interesting. How to check this point is very interesting..
The script and the indicator, which turned off the rendering and threw all the inclusions into it, I attach. If it is more convenient, I can attach it to libraries. They are compact. But the code is then read more conveniently because there is no excess in the context of logic.
In fact, I have laid out an indicator and a script that can read data from the bfers of this indicator. But data is read only from 1 buffer (0th index). the other buffer is not read. That’s really interesting. It seems that the terminal drives. I have it running portably. The code has already been broken not once.
alexeyvik
And how do you want to change in this cycle
for (int i = 0; i < 119; i++) {
copied = CopyBuffer(candlePatternsHandle, 1, i, 1, havingPattern);
Print(__FUNCTION__ + ":: copied = " + copied);
if (havingPattern[0] != EMPTY_VALUE) {
Print(__FUNCTION__ + ":: havingPattern[0] != EMPTY_VALUE");
Print(__FUNCTION__ + ":: havingPattern[", + i + "] = " + DoubleToString(havingPattern[0]));
}
the value of the array in the null index???
ps; sorry, not to change, but to read a different value than it is there.
alex_all
Already interesting) you would make a delay so that the calculations are all accurate, and the error is output at each iteration. I’ll check later.
Still confuses that in an array exact 0.0 though it is not initialized by it, and it not 4-ka, there it seems as usually garbage.
traderchik
No. The indicator has only 2 buffers now. The buffer indexes are 0 and 1. Of course, they are present in the indicator. This can be seen with the naked eye in the attached file (indicator)
I also thought about it today. But I didn’t want to pull the moderators for this.
scriptong
THIS Happens if the buffer index is specified incorrectly. Check the bufferindex value passed to getcandlepatternsvalue and see if the indicator has a buffer with this index. It’s clearly not there.
PS And why is the topic in the section for MQL4? I think we should move it to the section for MQL5.
alex_all
getlasterror to start
traderchik
How do I check it? I see that there is an error. The types of parameters are correct. Why the error is a question..
alex_all
the slash must be double in file paths \
why do you constantly create an indicator? the handle should be saved once.
otherwise, the code is incomplete to suggest. getcandlepatternsvalue with which pairs you call.
And maybe there’s a mistake in the turkey
traderchik
They’re lying there. I understood the first moment. For some reason, if the indicator is not in the Indicators folder itself, but deeper in the hierarchy, then an error occurs when reading the indicator. In my case, the path was like this:
Indicators/myIndicators/PA
I move the indicator to the root because there are not many options and the reading error no longer appears. But there is still one more point.
All the same, the data from the indicator buffer is not read by the copybuffer () function. copybuffer () returns -1 permanently. Although, the indicator handle is 10 and there are no errors at all when creating the indicator handle..