turning from onTick to onStart

 

Hey there, using this code snippet:

void OnTick()
  {
   MqlTick last_tick;

   if(SymbolInfoTick(Symbol(),last_tick))
     {
      Print(last_tick.time,": Bid = ",last_tick.bid,
            " Ask = ",last_tick.ask,"  Volume = ",last_tick.volume);
     }
   else Print("SymbolInfoTick() failed, error = ",GetLastError());

  }

I was able to get the bid,ask and volume every tick.

Now i just need the last bid,ask and volume every start e.g.

When i activate the 1h chart,

i just want those three value´s every hour once, i tried:

void OnStart()
  {
   MqlTick last_tick;

   if(SymbolInfoTick(Symbol(),last_tick))
     {
      Print(last_tick.time,": Bid = ",last_tick.bid,
            " Ask = ",last_tick.ask,"  Volume = ",last_tick.volume);
     }
   else Print("SymbolInfoTick() failed, error = ",GetLastError());

  }
But this doesnt work, anybody could help? Greetings!!
 
nikoscher:

Hey there, using this code snippet:

I was able to get the bid,ask and volume every tick.

Now i just need the last bid,ask and volume every start e.g.

When i activate the 1h chart,

i just want those three value´s every hour once, i tried:

But this doesnt work, anybody could help? Greetings!!

You can't use a tick-based function (MqlTick) inside OnStart... That's why you have OnStart and OnTick...

In this case you have to use a kind of "new H1 bar" function inside OnTick. Something like:

//--- globals
int oldHour = -1;
MqlDateTime time;

//--- inside OnTick
TimeTradeServer(time);
if(time.hour!=oldHour)
  {
   Print("This will be printed once every hour!");
   oldHour = time.hour;
  }
 
ok thanks i just thought i can use onStart like in mql4..
 

but how can i get last value´s from last hour updated?

this doesnt work:

//--- globals
int oldHour = -1;
MqlDateTime time;

void OnTick()
  {
  
   TimeTradeServer(time);
   if(time.hour!=oldHour)
   {
      Print("This will be printed once every hour!",last_tick.time,": Bid = ",last_tick.bid," Ask = ",last_tick.ask);
      oldHour = time.hour;
   }

  }
So the last_tick should stay?
 
nikoscher:

but how can i get last value´s from last hour updated?

this doesnt work:

So the last_tick should stay?

Of course! You cannot forget to use

MqlTick last_tick;
SymbolInfoTick(Symbol(),last_tick);

Try this:

//--- globals
int oldHour = -1;
MqlDateTime time;
MqlTick last_tick;

void OnTick()
  {
   SymbolInfoTick(Symbol(),last_tick);
   TimeTradeServer(time);
   //---
   if(time.hour!=oldHour)
    {
     Print("This will be printed once every hour!",last_tick.time,": Bid = ",last_tick.bid," Ask = ",last_tick.ask);
     oldHour = time.hour;
    }
  }
 
mhm strange i still get value´s every "tick"..
Reason: