CopyTicks question

 

Hello all,

I'm trying to get the TICK_FLAG_BUY and TICK_FLAG_SELL information from 'flags' in MqlTick struct provided by the CopyTicks fuction on a custom indicator but it seems I never get that information from this function.

The Symbol I'm testing it has Times & Sales enabled and this information can be seen in the transaction table in Depth of Market window, where buy transactions are in blue and sell transactions in pink. But I can't get this information with the CopyTicks function.
Am I missing something here?

Thanks for the attention.

Regards,

Leonardo

 
Which broker ? symbol ? Demo or real account ?
 
Alain Verleyen:
Which broker ? symbol ? Demo or real account ?
Hello Alain,

I'm not operating Forex, I'm under a Brazilian broker named XP Investimentos and yes, I'm using real (production) account. The symbol I'm using (WINXY) is refers to a future contract.

Thanks,

Leonardo 
 
LeoBaeta:
Hello Alain,

I'm not operating Forex, I'm under a Brazilian broker named XP Investimentos and yes, I'm using real (production) account. The symbol I'm using (WINXY) is refers to a future contract.

Thanks,

Leonardo 
Should work, though I can't check with this broker.

Are you sure your code is correct ?

Edit: I just tried with WINJ17 on Rico-Demo and it works.
 
Alain Verleyen:
Should work, though I can't check with this broker.

Are you sure your code is correct ?

Edit: I just tried with WINJ17 on Rico-Demo and it works.

Here is my code:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
     MqlTick tick;
     if(SymbolInfoTick(Symbol(),tick))
     {
      string s;
      if((tick.flags  &TICK_FLAG_BID)==TICK_FLAG_BID)       s+="BID|";
      if((tick.flags  &TICK_FLAG_ASK)==TICK_FLAG_ASK)       s+="ASK|";
      if((tick.flags  &TICK_FLAG_LAST)==TICK_FLAG_LAST)     s+="LAST|";
      if((tick.flags  &TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME) s+="VOL|";
      if((tick.flags  &TICK_FLAG_BUY)==TICK_FLAG_BUY)       s+="BUY|";
      if((tick.flags  &TICK_FLAG_SELL)==TICK_FLAG_SELL)     s+="SELL|";
      Print(s);
     }
     return 0;
  }
    

It's the OnCalculate function of my custom indicator. It should work, shouldn't it?
I get all flags on my string, except the BUY and SELL ones.

Thanks again,

Leonardo

 
Since anding with a bit mask can only result in zero or the bit mask and since non-zero is true
if((tick.flags  &TICK_FLAG_BID)==TICK_FLAG_BID)       s+="BID|";
if((tick.flags  &TICK_FLAG_ASK)==TICK_FLAG_ASK)       s+="ASK|";
if((tick.flags  &TICK_FLAG_LAST)==TICK_FLAG_LAST)     s+="LAST|";
if((tick.flags  &TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME) s+="VOL|";
if((tick.flags  &TICK_FLAG_BUY)==TICK_FLAG_BUY)       s+="BUY|";
if((tick.flags  &TICK_FLAG_SELL)==TICK_FLAG_SELL)     s+="SELL|";
Code can be simplified.
if(tick.flags & TICK_FLAG_BID)    s+="BID|";
if(tick.flags & TICK_FLAG_ASK)    s+="ASK|";
if(tick.flags & TICK_FLAG_LAST)   s+="LAST|";
if(tick.flags & TICK_FLAG_VOLUME) s+="VOL|";
if(tick.flags & TICK_FLAG_BUY)    s+="BUY|";
if(tick.flags & TICK_FLAG_SELL)   s+="SELL|";
 
whroeder1:
Since anding with a bit mask can only result in zero or the bit mask and since non-zero is true
if((tick.flags  &TICK_FLAG_BID)==TICK_FLAG_BID)       s+="BID|";
if((tick.flags  &TICK_FLAG_ASK)==TICK_FLAG_ASK)       s+="ASK|";
if((tick.flags  &TICK_FLAG_LAST)==TICK_FLAG_LAST)     s+="LAST|";
if((tick.flags  &TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME) s+="VOL|";
if((tick.flags  &TICK_FLAG_BUY)==TICK_FLAG_BUY)       s+="BUY|";
if((tick.flags  &TICK_FLAG_SELL)==TICK_FLAG_SELL)     s+="SELL|";
Code can be simplified.
if(tick.flags & TICK_FLAG_BID)    s+="BID|";
if(tick.flags & TICK_FLAG_ASK)    s+="ASK|";
if(tick.flags & TICK_FLAG_LAST)   s+="LAST|";
if(tick.flags & TICK_FLAG_VOLUME) s+="VOL|";
if(tick.flags & TICK_FLAG_BUY)    s+="BUY|";
if(tick.flags & TICK_FLAG_SELL)   s+="SELL|";
You're right, whroeder1. Thanks for the hint.

Leonardo
 
LeoBaeta:It's the OnCalculate function of my custom indicator. It should work, shouldn't it?

I get all flags on my string, except the BUY and SELL ones.

Thanks again,

Leonardo

Yes your code is ok. I tested it and got the BUY/SELL.

Seems it's not available on your real account, but I don't know why. Ask your broker and/or write to ServiceDesk (and please keep us posted).
 
Alain Verleyen:
Yes your code is ok. I tested it and got the BUY/SELL.

Seems it's not available on your real account, but I don't know why. Ask your broker and/or write to ServiceDesk (and please keep us posted).

I wonder why this information is available at the Depth of Market window (at the transaction list) but not via CopyTicks function...

Also tried with stocks and also on the broker's MT5 demo account but no success.


Anyway, I'll contact my broker service and I'll inform you as soon as I get an answer.

Regards

Edit: Just a note: I started this thread with a question for CopyTicks function but my sample code above is using the SymbolInfoTick instead. Actually I tested with both functions (because both should be able to get the last MqlTick) and I (naturally) got the same results.
 

Hello,

I've got an answer from my broker today.

They said they didn't have someone internally that could help me and that they had to contact a 3rd party programmer to analyse the problem. So the programmer only said that those Buy and Sell flags indeed don't work and that what programmers usually do is to compare the last price with tick's Bid and Ask. If >=Ask then it's a Buy, if <=Bid it's a Sell.

Indeed it seems to be an alternative solution, although I didn't test it yet. 

But why TICK_FLAG_BUY and TICK_FLAG_SELL don't work on that broker remains a mystery of the universe...

‌‌Leonardo

 
LeoBaeta:

Hello,

I've got an answer from my broker today.

They said they didn't have someone internally that could help me and that they had to contact a 3rd party programmer to analyse the problem. So the programmer only said that those Buy and Sell flags indeed don't work and that what programmers usually do is to compare the last price with tick's Bid and Ask. If >=Ask then it's a Buy, if <=Bid it's a Sell.

Indeed it seems to be an alternative solution, although I didn't test it yet. 

But why TICK_FLAG_BUY and TICK_FLAG_SELL don't work on that broker remains a mystery of the universe...

‌‌Leonardo

Thanks. Did you write to Metaquotes ServiceDesk ?
Reason: