Testing 'CopyTicks' - page 14

 
Rashid Umarov:

For example

Slightly reworked

string GetTickFlag( uint tickflag )
{
  string flag = "";

#define  TICKFLAG_MACRO(A) flag += ((bool)(tickflag & TICK_FLAG_##A)) ? " TICK_FLAG_" + #A : "";
  TICKFLAG_MACRO(BID)
  TICKFLAG_MACRO(ASK)
  TICKFLAG_MACRO(LAST)
  TICKFLAG_MACRO(VOLUME)
  TICKFLAG_MACRO(BUY)
  TICKFLAG_MACRO(SELL)
#undef  TICKFLAG_MACRO

  if (flag == "")
    flag = "FLAG_UNKNOWN";
     
  return(flag);
}

Result

2016.09.14 13:52:33.925 Test (Si-9.16,M1)       Tick23: time = 2016.09.13 18:52:35.505 bid = 0.0 ask = 0.0 last = 65253.0 volume = 35  TICK_FLAG_BID TICK_FLAG_ASK

It turns out that both prices change to zero from non-zero values. And after zeros go back to non-zeros.

 
fxsaber:

Indicator shows that CopyTicks may not be giving away the last ticks

Even more interesting

string GetTickFlag( uint tickflag )
{
  string flag = "";

#define  TICKFLAG_MACRO(A) flag += ((bool)(tickflag & TICK_FLAG_##A)) ? " TICK_FLAG_" + #A : "";
  TICKFLAG_MACRO(BID)
  TICKFLAG_MACRO(ASK)
  TICKFLAG_MACRO(LAST)
  TICKFLAG_MACRO(VOLUME)
  TICKFLAG_MACRO(BUY)
  TICKFLAG_MACRO(SELL)
#undef  TICKFLAG_MACRO

  if (flag == "")
    flag = " FLAG_UNKNOWN (" + (string)tickflag + ")";
     
  return(flag);
}

#define  TOSTRING(A) " " + #A + " = " + (string)Tick.A

string TickToString( const MqlTick &Tick )
{
  static int i = 0;
  
  i++;
  
  return("Tick" + (string)i + ":" + TOSTRING(time) + "." + (string)(Tick.time_msc %1000) +
         TOSTRING(bid) + TOSTRING(ask) + TOSTRING(last)+ TOSTRING(volume) + GetTickFlag(Tick.flags));
}

bool MySymbolInfoTick( const string Symb, MqlTick &Tick, const uint Type = COPY_TICKS_ALL )
{
  MqlTick Ticks[];
  const int Amount = ::CopyTicks(Symb, Ticks, Type, 0, 1);
  const bool Res = (Amount > 0);
  
  if (Res)
    Tick = Ticks[Amount - 1];
  
  return(Res);
}

#define  INDICATOR // Переключение между индикатором и экспертом

#ifdef  INDICATOR
  #define  NAME "Indicator: "

  #property indicator_chart_window
  #property indicator_buffers 0
  #property indicator_plots   0

  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[] )
#else
  #define  NAME "Expert: "

  void OnTick( void )
#endif
{
  MqlTick Tick1, Tick2;
  
  if (SymbolInfoTick(_Symbol, Tick1) && MySymbolInfoTick(_Symbol, Tick2))
    if (Tick1.time_msc != Tick2.time_msc)
      Print(NAME + ((Tick1.time_msc > Tick2.time_msc) ? "EventTime > CopyTicks_Time" : "EventTime < CopyTicks_Time") +
            "\nFrom Event: " + TickToString(Tick1) + "\nFrom CopyTicks: " + TickToString(Tick2) + "\n");

#ifdef  INDICATOR 
  return(rates_total);
#endif
}
Result
2016.09.14 14:25:24.533 Test2 (Si-9.16,M1)      From CopyTicks: Tick16: time = 2016.09.14 14:25:06.62 bid = 65013.0 ask = 65015.0 last = 65014.0 volume = 1 TICK_FLAG_LAST TICK_FLAG_VOLUME TICK_FLAG_SELL
2016.09.14 14:25:24.533 Test2 (Si-9.16,M1)      From Event: Tick15: time = 2016.09.14 14:25:06.68 bid = 65013.0 ask = 65015.0 last = 65014.0 volume = 1 TICK_FLAG_LAST TICK_FLAG_VOLUME TICK_FLAG_SELL
2016.09.14 14:25:24.533 Test2 (Si-9.16,M1)      Indicator: EventTime > CopyTicks_Time
2016.09.14 14:25:24.533 Test2 (Si-9.16,M1)      
2016.09.14 14:25:24.533 Test2 (Si-9.16,M1)      From CopyTicks: Tick14: time = 2016.09.14 14:25:06.62 bid = 65013.0 ask = 65015.0 last = 65014.0 volume = 1 TICK_FLAG_LAST TICK_FLAG_VOLUME TICK_FLAG_SELL
2016.09.14 14:25:24.533 Test2 (Si-9.16,M1)      From Event: Tick13: time = 2016.09.14 14:25:06.68 bid = 65013.0 ask = 65015.0 last = 65014.0 volume = 1 TICK_FLAG_LAST TICK_FLAG_VOLUME TICK_FLAG_SELL
2016.09.14 14:25:24.533 Test2 (Si-9.16,M1)      Indicator: EventTime > CopyTicks_Time
2016.09.14 14:25:18.974 Test2 (Si-9.16,M1)      
2016.09.14 14:25:18.974 Test2 (Si-9.16,M1)      From CopyTicks: Tick12: time = 2016.09.14 14:25:00.519 bid = 65011.0 ask = 65012.0 last = 65012.0 volume = 8 TICK_FLAG_LAST TICK_FLAG_VOLUME TICK_FLAG_BUY
2016.09.14 14:25:18.974 Test2 (Si-9.16,M1)      From Event: Tick11: time = 2016.09.14 14:25:00.510 bid = 65011.0 ask = 65012.0 last = 65012.0 volume = 8 FLAG_UNKNOWN (0)
2016.09.14 14:25:18.974 Test2 (Si-9.16,M1)      Indicator: EventTime < CopyTicks_Time

CopyTicks can both lag behind and be ahead of the Event-tick. Event-tick often has a zero flag.

ZZY Correct the MqlTick flag to flags in the MqlTick help.

 

How others use CopyTicks is beyond me. No trust, unfortunately. Very raw.

EA

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

void OnTick( void )
{
  static MqlTick PrevTick;  
  static int Amount = 0;
  
  MqlTick Ticks[];
  
  if (Amount > 0)
  {
    Amount = CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, PrevTick.time_msc);
    
    int i;
    
    for (i = 0; i < Amount; i++)
      if (_R(Ticks[i]) == PrevTick) // https://www.mql5.com/ru/code/16280
        break;
        
    if (i == Amount)
      Print("В истории (length = " + (string)Amount + ") нет тика, что был на предыдущем Event.");
  }
  else
    Amount = CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, TimeCurrent() * 1000);
    
  if (Amount > 0)
    PrevTick = Ticks[Amount - 1];  
}

Result

2016.09.15 11:04:02.810 Test2 (RTS-9.16,M1)     В истории (length = 2) нет тика, что был на предыдущем Event.
2016.09.15 11:03:59.312 Test2 (RTS-9.16,M1)     В истории (length = 13) нет тика, что был на предыдущем Event.
2016.09.15 11:03:59.290 Test2 (RTS-9.16,M1)     В истории (length = 1) нет тика, что был на предыдущем Event.

The tick that was in the history is already absent in the next Tick-event!

Dear developers, bring CopyTicks to a working condition. Even simple tests are failing.

 
At the moment CopyTicks with some stretch, but works in real time with input parameter from == 0.
 

I need to add new history ticks to the array on each OnTick. Has anyone implemented this?

I'm struggling - it's not working. I can't manage to bypass curvature of CopyTicks.

 
fxsaber:
At the moment CopyTicks with some stretch, but works in real time with input parameter from == 0.
Here is one of the stretches
void OnTick( void )
{
  MqlTick Ticks[];
  
  const int Amount = CopyTicks(_Symbol, Ticks);
  
  if ((Amount > 1) && (Ticks[Amount - 1].time_msc < Ticks[Amount - 2].time_msc))
    Print("Некорректная история!");
}
Result
2016.09.15 13:11:13.231 Test4 (RTS-9.16,M1)     Некорректная история!
2016.09.15 13:10:48.954 Test4 (RTS-9.16,M1)     Некорректная история!
We take the edge ticks, and find that the most recent tick has less time than the previous one.
 
fxsaber:
Here's one of the stretchesReceive the extreme ticks, and find that the most recent tick has a shorter time than the previous one.

Check out the code for this indicator

https://www.mql5.com/ru/forum/94399/page6#comment_2776784

Таблица всех сделок. Доступ через MQL5
Таблица всех сделок. Доступ через MQL5
  • reviews: 1
  • www.mql5.com
Как организовать получение таблицы сделок? Пока не важно из индикатора или из советника...
 
fxsaber:
We take the extreme ticks, and find that the most recent tick has a shorter time than the previous one.
This applies only to COPY_TICKS_ALL. With the other modes, the suggested EA has not detected any errors.
 
Do I have to write to Service Desk about the reports in this thread or do the developers monitor it themselves?
 
fxsaber:
Do I have to write to Service Desk about the reports in this thread or do the developers monitor it themselves?
You'd better write to them. It won't be superfluous.