Of course it's possible. Use a one second timer and store your data in an array.
There is no difference if you want to buffer/store 1 second bar data for 60 seconds, 29 minutes or 100 minutes. You still have to store the data in an organised array. By organised, I mean use a array of a structure that keeps track of all the data you need, such as open, close, high, low, volume, EMAs, Heikin Ashi or what ever else you need to keep a running value on for each of the 1 second bars.
You don't have to delete and reconstruct the arrays for each new 1 second bar. Just loop through a pre-sized array for the window size you require, keeping an a index/pointer for the "Tail" and "Head" of the data (standard coding 101 techniques, eg. a FIFO queue array).
Besides, in MetaTrader/MQL5 you have access to History Data for every single real tick quote, so you can easily build very accurate 1 second bar data without having to collect it one-by-one on every OnTick event (see CopyTicks() and CopyTicksRange() functions).
PS! You could also use Object Oriented Programming (classes, etc.), but since you are having difficulty with a simply Array solution, it is best that you first understand the basics before diving into the "deep end" of OOP programming.
There is no difference if you want to buffer/store 1 second bar data for 60 seconds, 29 minutes or 100 minutes. You still have to store the data in an organised array. By organised, I mean use a array of a structure that keeps track of all the data you need, such as open, close, high, low, volume, EMAs, Heikin Ashi or what ever else you need to keep a running value on for each of the 1 second bars.
You don't have to delete and reconstruct the arrays for each new 1 second bar. Just loop through a pre-sized array for the window size you require, keeping an a index/pointer for the "Tail" and "Head" of the data (standard coding 101 techniques, eg. a FIFO queue array).
Besides, in MetaTrader/MQL5 you have access to History Data for every single real tick quote, so you can easily build very accurate 1 second bar data without having to collect it one-by-one on every OnTick event (see CopyTicks() and CopyTicksRange() functions).
PS! You could also use Object Oriented Programming (classes, etc.), but since you are having difficulty with a simply Array solution, it is best that you first understand the basics before diving into the "deep end" of OOP programming.
I posted a circular buffer at Stuck on retrieving previous bid prices by each second? - Timeframes - MQL4 and MetaTrader 4 - MQL4 programming forum
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
How can I get the last 60 sec data in mql5?
I mean not bar of 1 min, I want that every second I will get new data and erese the last second data.
is it posssible ?
Thank You.