Questions from Beginners MQL5 MT5 MetaTrader 5 - page 578
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
DataCandles is a structure. The array where we write the candlesticks from the history is array[]. So we need to make it as a timeseries to make its indexing coincide with indexing of candlesticks on the chart. I.e. the zero cell of array[] will correspond to the closest candlesticks to the current date.
I.e. 1. we copy candlesticks into array array[], 2. we make it a time series, and then read values from it into the structure.
You can do without array[] - just write data directly from the chart into the structure, but I suggested this for compatibility with Five - it allows to copy directly only in the indicator using high[i], low[i] and other data, but in the script or Expert Advisor, we will have to first copy the necessary history interval into the array, which I did.
Alert (series);
like this?
Both alerts still return false
Alert (series);
like this?
Both alerts still return false
So, this is a bug which should be reported to "Errors, Bugs, Questions".
Here is a check script, it shows time of copied candlesticks in zero and last cells of array[]:
So this is a bug which should be reported to "Errors, bugs, questions".
Here is a check script, it shows time of copied candlesticks in zero and last cells of array[]:
Outputs this:
Array is series: false
time array[0]: 2016.05.12 21:00
time array[9]: 2016.05.12 12:00
It comes up with this:
Array is series: false
time array[0]: 2016.05.12 21:00
time array[9]: 2016.05.12 12:00
I checked it - always false, but time is correct: if at start of script select Array array as time series "Yes", then:
If you select "No", then:
the times of the candlesticks written to the array are reversed, which means ArraySetAsSeriess() works correctly, but ArrayIsSeries() does not, it always outputs false, which I have already written to the above bug thread.
Oh this programming. The further into the woods....
Understand, you don't need to know the direction of the array. The algorithm is looking for repeats. So it doesn't care what order the bars are processed in.
you need. Because then I need to find out which candlesticks formed a match and take the price Low from the closest to the current price.
There is a candle time in the structure for this, by which you can find the closest candle to any time you need.
And you don't need to output the candlestick numbers - they don't coincide with real bar numbers. Because we fill the array, and the indexes in the array belong only to the candlestick's number in the array, not on the chart.
I checked what it gives out - always false, but the time is correct: if you select Array array as time series "Yes" when running the script, then:
If you select "No", then:
The times of the candlesticks written to the array are reversed, which means ArraySetAsSeriess() works correctly, but ArrayIsSeries() does not, it always outputs false, which I have already written to the above bug thread.
I slightly modified the code:
ArraySetAsSeries(array,true); //there just put true
and then added numbers of candlesticks for self-check:
Alert("Array is series: ",ArrayIsSeries(array),
"\nCandle "+IntegerToString(0,2,'0')+" time array[0]: ",TimeToString(array[0].time,TIME_DATE|TIME_MINUTES),
"\nSwitch "+IntegerToString(searchperiod-1,2,'0')+" time array[",string(searchperiod-1),"]:",TimeToString(array[ArraySize(array)-1].time,TIME_DATE|TIME_MINUTES));
It gives the following output:
Array is series: false
Candle 00 time array[0]: 2016.05.12 22:00
Candle 09 time array[9]: 2016.05.12 13:00
To do this, there is a candle time in the structure, by which you can find the closest candle to any time you need.
I've changed the code a bit:
ArraySetAsSeries(array,true); //there just put true
and then added numbers of candlesticks for self-check:
Alert("Array is series: ",ArrayIsSeries(array),
"\nCandle "+IntegerToString(0,2,'0')+" time array[0]: ",TimeToString(array[0].time,TIME_DATE|TIME_MINUTES),
"\nSwitch "+IntegerToString(searchperiod-1,2,'0')+" time array[",string(searchperiod-1),"]:",TimeToString(array[ArraySize(array)-1].time,TIME_DATE|TIME_MINUTES));
It gives the following output:
Array is series: false
Candle 00 time array[0]: 2016.05.12 22:00
Candle 09 time array[9]: 2016.05.12 13:00