1

I want to create a Stack, Queue or List of MqlTick instances.

The following code:

#include <Generic\Queue.mqh>
CQueue<MqlTick> myQueue;

Produces these errors:

'' - objects are passed by reference only ICollection.mqh 14 18

'm_array' - objects are passed by reference only Queue.mqh 140 19

And this:

#include <Generic\Queue.mqh>
CQueue<MqlTick *> longQueue;

Gives: class type expected, pointer to type 'MqlTick' is not allowed MyTest.mq5

If I do:

#include <Generic\Queue.mqh>
#include <Object.mqh>
CQueue<CObject *> longQueue;

MqlTick currentTick;
longQueue.Add(&currentTick);

The compiler says:

'Add' - no one of the overloads can be applied to the function call MyTest.mq5
could be one of 2 function(s)   MyTest.mq5
   bool CQueue<CObject*>::Add(CObject*) Queue.mqh   30  22
   bool ICollection<CObject*>::Add(CObject*)    ICollection.mqh 14  14

Because MqlTick is a struct and not an instance of CObject.

Trayan Momkov
  • 842
  • 1
  • 7
  • 18

1 Answers1

0

If you are trying to acess previous data you could use CopyTicksRange, the output array is organized as a Stack, with the most recent tick, in the 0 index of the MqlTick struct containing the tick info.

MqlTick ticksarray[];
double Most_recent_tick_last_price;
datetime Most_recent_tick_time;

#Setting the time period
input datetime Start_date = D'2021.07.26 09:06';
input datetime End_date = D'2021.07.27 18:00'; 
ulong Start = ulong(Start_date)*1000;
ulong End   = ulong(End_date  )*1000;

#Saving ticks on a array:
CopyTicksRange(_Symbol,ticksarray,COPY_TICKS_INFO,Start,End);

#Acessing specific values:
Most_recent_tick_time= ticksarray[0].time
Most_recent_tick_last_price= ticksarray[0].last

If you want just the current tick info, you can use SymbolInfoTick.

MqlTick current_tick[];
double current_ask,current_bid;
void OnTick()
  {
    SymbolInfoTick(_Symbol,current_tick);
    current_bid = current_tick.bid;
    current_ask = current_tick.ask;
  }