Previous Ticks

 

Novice MQL5 programmer here.

Is there a way to check the price of a previous tick?

MqlTick's "last" variable is not available in the forex market :(

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Structure for Current Prices
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Structure for Current Prices - Documentation on MQL5
 

 

 
FinGeR:

 

Unfortunately, I am in the Forex market so, MqlTick's "last" variable is *not* available in the Forex market. 

Any other ideas? 

 
lin-unix:

Unfortunately, I am in the Forex market so, MqlTick's "last" variable is *not* available in the Forex market. 

Any other ideas? 

SymbolInfoTick()?


 
lin-unix:

Novice MQL5 programmer here.

Is there a way to check the price of a previous tick?

MqlTick's "last" variable is not available in the forex market :(


save each new MqlTick in a static variable in OnTick()

static MqlTick Last_Tick;

OnTick()

{

...

if (Last_Tick = ..) // access last tick

Last_Tick = MqlTick()  // save the tick

}




 
I like the idea of keeping a local copy of ticks, but lets say my EA just gets gets turned on. It needs to have access to the previous tick in the market to do some calculations, but it can't have a copy of the previous tick because my EA was not running at the time the previous tick came in. Is there any way that my EA could still get information from the previous tick by say, querying the existing market data somehow?
 
lin-unix:
I like the idea of keeping a local copy of ticks, but lets say my EA just gets gets turned on. It needs to have access to the previous tick in the market to do some calculations, but it can't have a copy of the previous tick because my EA was not running at the time the previous tick came in. Is there any way that my EA could still get information from the previous tick by say, querying the existing market data somehow?

No. You just have to check if it is the first tick the EA encounters, then let it just copy the tick and return. The next tick you will have the data for calculation.

 P.S. If you just turned on your EA, it will not matter a great deal to wait one more tick. 

 
amir_avatar:

No. You just have to check if it is the first tick the EA encounters, then let it just copy the tick and return. The next tick you will have the data for calculation.

 P.S. If you just turned on your EA, it will not matter a great deal to wait one more tick. 

Agree, or if you really can't wait, you can copy the same last tick value as the preivious tick, so you still can do the calculation.
 
Thanks guys, I will wait for the second tick before I begin my calculations.
Reason: