How to get the price from 5 seconds ago?

 
I'm working on a scalper robot and I would be very grateful if someone could give me a tip on how to get the price from 5 seconds ago, regardless of the candle and preferably without using an array (if that's possible)!

Thanks in advance for everyone's help!

Hugs!
  
 
Marcelo Peres:
I'm working on a scalper robot and I would be very grateful if someone could give me a tip on how to get the price from 5 seconds ago, regardless of the candle and preferably without using an array (if that's possible)!

Thanks in advance for everyone's help!

Hugs!
  

I would like to get the difference from this price from 5 seconds ago with iClose(NULL, PERIOD_M1, 0)...

 
Just store it, for later.
int OnInit(){ EventSetTimer(1); … }
#define MAX_LOOKBACK 100
double price[MAX_LOOKBACK]={0}; int count=0;
double price_was(int seconds=5){ 
    int i=count-seconds; if(i <= 0) return EMPTY;
    return price[i % MAX_LOOKBACK]; 
}
void OnTimer(){
    price[ ++count % MAX_LOOKBACK] = iClose(_Symbol, _Period, 0);
}

What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)

 
William Roeder #:
Just store it, for later.

What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)

For what I operate, there are hundreds of ticks per minute...
Thanks...

 
Marcelo Peres #: For what I operate, there are hundreds of ticks per minute... Thanks...

An what difference does that make?

The code works irrespective of the tick volume.

But if you don't like that method then just use CopyTicks instead with the exact time you want to lookup.

Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
  • www.mql5.com
CopyTicks - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5