create one EA to writes the Ticks-data, but always reports array out of range when debugging, thank you for your help!
The following code is relatively simple, but in the mt5 Testing Visualization linear array out of range an error message.
I'm a novices, and I had searched for a long time and have not found the reason for the error, but I think it might be caused by the caching problem in the OnTick() function.
Please give guidance from experts, thank you!
***
Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window
#property copyright "Copyright 2021, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" MqlTick myticks[]; double tick_bid[]; double tick_ask[]; int OnInit() { return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { ArraySetAsSeries(myticks,true); ArrayResize(myticks,50); CopyTicks("XAUUSD",myticks,COPY_TICKS_INFO,0,50); ArrayInitialize(tick_bid,0); ArrayInitialize(tick_ask,0); ArrayResize(tick_bid,50); ArrayResize(tick_ask,50); for(int i=0;i<50;i++) { tick_bid[i]=myticks[i].bid; tick_ask[i]=myticks[i].ask; } }
you have to resize the myticks list too
The following code is relatively simple, but in the mt5 Testing Visualization linear array out of range an error message.
I'm a novices, and I had searched for a long time and have not found the reason for the error, but I think it might be caused by the caching problem in the OnTick() function.
Please give guidance from experts, thank you!
Please try this code
CopyTicks(_Symbol,tick,COPY_TICKS_INFO,0,iBars(_Symbol,PERIOD_CURRENT));
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The following code is relatively simple, but in the mt5 Testing Visualization linear array out of range an error message.
I'm a novices, and I had searched for a long time and have not found the reason for the error, but I think it might be caused by the caching problem in the OnTick() function.
Please give guidance from experts, thank you!