copy_rates_from_pos will randomly not return the correct candles

 

I pull my candles in this way:

lines = mt5.copy_rates_from_pos(chart, mt5.TIMEFRAME_M5, 0, 25)

It should return the last 25 candles. Sometimes it does, sometimes it doesn't.

Success output:

[2023.09.19 05:01:00] [***]chart=EURUSD+ lenlines=25
[2023.09.19 05:01:00] x=0 linestamp=300 line=(1695092400, 1.06919, 1.06954, 1.06918, 1.06954, 271, 0, 0)
[2023.09.19 05:01:00] x=1 linestamp=305 line=(1695092700, 1.06954, 1.06964, 1.06951, 1.06955, 221, 0, 0)
[2023.09.19 05:01:00] x=2 linestamp=310 line=(1695093000, 1.06955, 1.06955, 1.06936, 1.06942, 130, 0, 0)
[2023.09.19 05:01:00] x=3 linestamp=315 line=(1695093300, 1.06941, 1.0696, 1.06941, 1.06957, 126, 0, 0)
[2023.09.19 05:01:00] x=4 linestamp=320 line=(1695093600, 1.06957, 1.06966, 1.06949, 1.0695, 92, 0, 0)
[2023.09.19 05:01:00] x=5 linestamp=325 line=(1695093900, 1.0695, 1.06952, 1.06927, 1.0693, 109, 0, 0)
[2023.09.19 05:01:00] x=6 linestamp=330 line=(1695094200, 1.0693, 1.0694, 1.06918, 1.06933, 110, 0, 0)
[2023.09.19 05:01:00] x=7 linestamp=335 line=(1695094500, 1.06933, 1.06933, 1.06894, 1.06907, 105, 0, 0)
[2023.09.19 05:01:00] x=8 linestamp=340 line=(1695094800, 1.06907, 1.06909, 1.06882, 1.06883, 141, 0, 0)
[2023.09.19 05:01:00] x=9 linestamp=345 line=(1695095100, 1.06881, 1.06897, 1.06878, 1.06883, 206, 0, 0)
[2023.09.19 05:01:00] x=10 linestamp=350 line=(1695095400, 1.06883, 1.06899, 1.06883, 1.06888, 230, 0, 0)
[2023.09.19 05:01:00] x=11 linestamp=355 line=(1695095700, 1.06889, 1.06899, 1.06878, 1.06884, 216, 0, 0)
[2023.09.19 05:01:00] x=12 linestamp=400 line=(1695096000, 1.06884, 1.06894, 1.06865, 1.06865, 288, 0, 0)
[2023.09.19 05:01:00] x=13 linestamp=405 line=(1695096300, 1.06868, 1.0687, 1.06845, 1.06855, 173, 0, 0)
[2023.09.19 05:01:00] x=14 linestamp=410 line=(1695096600, 1.06856, 1.06859, 1.06839, 1.06846, 196, 0, 0)
[2023.09.19 05:01:00] x=15 linestamp=415 line=(1695096900, 1.06846, 1.0686, 1.06844, 1.06851, 225, 0, 0)
[2023.09.19 05:01:00] x=16 linestamp=420 line=(1695097200, 1.0685, 1.06856, 1.06848, 1.0685, 79, 0, 0)
[2023.09.19 05:01:00] x=17 linestamp=425 line=(1695097500, 1.0685, 1.06851, 1.06824, 1.06827, 120, 0, 0)
[2023.09.19 05:01:00] x=18 linestamp=430 line=(1695097800, 1.06826, 1.06835, 1.06808, 1.06814, 169, 0, 0)
[2023.09.19 05:01:00] x=19 linestamp=435 line=(1695098100, 1.06814, 1.06829, 1.06812, 1.06815, 172, 0, 0)
[2023.09.19 05:01:00] x=20 linestamp=440 line=(1695098400, 1.06815, 1.06824, 1.06812, 1.06823, 185, 0, 0)
[2023.09.19 05:01:00] x=21 linestamp=445 line=(1695098700, 1.06823, 1.06838, 1.06817, 1.06835, 157, 0, 0)
[2023.09.19 05:01:00] x=22 linestamp=450 line=(1695099000, 1.06835, 1.06841, 1.06828, 1.06835, 186, 0, 0)
[2023.09.19 05:01:00] x=23 linestamp=455 line=(1695099300, 1.06835, 1.06843, 1.06832, 1.06837, 110, 0, 0)
[2023.09.19 05:01:00] x=24 linestamp=500 line=(1695099600, 1.06837, 1.06843, 1.06836, 1.06839, 32, 0, 0)

Failure output:

[2023.09.19 05:01:00] [***]chart=GBPCAD+ lenlines=25
[2023.09.19 05:01:00] x=0 linestamp=2130 line=(1695072600, 1.67011, 1.67026, 1.66996, 1.66998, 89, 11, 0)
[2023.09.19 05:01:00] x=1 linestamp=2135 line=(1695072900, 1.66998, 1.67017, 1.66995, 1.6701, 72, 10, 0)
[2023.09.19 05:01:00] x=2 linestamp=2140 line=(1695073200, 1.6701, 1.67016, 1.66995, 1.66999, 113, 8, 0)
[2023.09.19 05:01:00] x=3 linestamp=2145 line=(1695073500, 1.66998, 1.67, 1.66978, 1.66997, 92, 11, 0)
[2023.09.19 05:01:00] x=4 linestamp=2150 line=(1695073800, 1.66995, 1.67005, 1.66973, 1.67004, 98, 8, 0)
[2023.09.19 05:01:00] x=5 linestamp=2155 line=(1695074100, 1.67004, 1.67021, 1.66977, 1.66985, 169, 7, 0)
[2023.09.19 05:01:00] x=6 linestamp=2200 line=(1695074400, 1.66985, 1.67039, 1.66985, 1.67011, 111, 10, 0)
[2023.09.19 05:01:00] x=7 linestamp=2205 line=(1695074700, 1.6701, 1.67024, 1.67004, 1.67014, 110, 9, 0)
[2023.09.19 05:01:00] x=8 linestamp=2210 line=(1695075000, 1.67014, 1.6705, 1.67009, 1.67026, 172, 7, 0)
[2023.09.19 05:01:00] x=9 linestamp=2215 line=(1695075300, 1.67026, 1.6705, 1.66991, 1.67041, 86, 11, 0)
[2023.09.19 05:01:00] x=10 linestamp=2220 line=(1695075600, 1.6704, 1.67044, 1.67028, 1.67044, 52, 9, 0)
[2023.09.19 05:01:00] x=11 linestamp=2225 line=(1695075900, 1.67043, 1.67049, 1.67018, 1.67039, 104, 5, 0)
[2023.09.19 05:01:00] x=12 linestamp=2230 line=(1695076200, 1.67039, 1.67051, 1.67033, 1.6704, 69, 9, 0)
[2023.09.19 05:01:00] x=13 linestamp=2235 line=(1695076500, 1.6704, 1.67047, 1.6703, 1.67036, 58, 11, 0)
[2023.09.19 05:01:00] x=14 linestamp=2240 line=(1695076800, 1.67036, 1.67052, 1.67032, 1.67032, 66, 9, 0)
[2023.09.19 05:01:00] x=15 linestamp=2245 line=(1695077100, 1.67031, 1.67034, 1.67012, 1.67034, 85, 10, 0)
[2023.09.19 05:01:00] x=16 linestamp=2250 line=(1695077400, 1.67034, 1.67052, 1.67025, 1.67052, 85, 9, 0)
[2023.09.19 05:01:00] x=17 linestamp=2255 line=(1695077700, 1.67053, 1.67059, 1.67027, 1.67044, 109, 10, 0)
[2023.09.19 05:01:00] x=18 linestamp=2300 line=(1695078000, 1.67043, 1.67045, 1.67031, 1.67038, 89, 8, 0)
[2023.09.19 05:01:00] x=19 linestamp=2305 line=(1695078300, 1.67038, 1.67045, 1.67031, 1.67042, 73, 10, 0)
[2023.09.19 05:01:00] x=20 linestamp=2310 line=(1695078600, 1.67042, 1.67089, 1.67038, 1.67066, 85, 7, 0)
[2023.09.19 05:01:00] x=21 linestamp=2315 line=(1695078900, 1.67066, 1.67069, 1.67055, 1.67058, 35, 10, 0)
[2023.09.19 05:01:00] x=22 linestamp=2320 line=(1695079200, 1.67058, 1.67061, 1.67048, 1.67057, 35, 9, 0)
[2023.09.19 05:01:00] x=23 linestamp=2325 line=(1695079500, 1.67057, 1.6706, 1.67027, 1.67055, 52, 10, 0)
[2023.09.19 05:01:00] x=24 linestamp=2330 line=(1695079800, 1.67056, 1.67059, 1.67056, 1.67059, 2, 14, 0)

'linestamp' is the timestamp in %H%M format.

Both of these outputs are from the same pull at the same hour, but for different charts.

It can fail or succeed on any chart. There doesn't seem to be a pattern, specific time or specific chart.

Documentation on MQL5: Python Integration / copy_rates_from_pos
Documentation on MQL5: Python Integration / copy_rates_from_pos
  • www.mql5.com
copy_rates_from_pos - Python Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
[Deleted]  
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
MQL5 forum: Expert Advisors and Automated Trading
MQL5 forum: Expert Advisors and Automated Trading
  • www.mql5.com
How to create an Expert Advisor (a trading robot) for Forex trading