Order delay between execution and plt - page 2

 
Malacarne:

So, usually how this works in real life?

Do you wait for confirmation of MA crossover, or do you trade directly on tick, even if the bar is not yet closed? As we all know, one single tick is no guarantee that the crossover will actually take place...

That's why we need a new bar event handler...

To be honest, in real life trading things are working each time more in real time, and in high speed, using tick by tick decisions, but this is not the point.

The point is: new bar is relevant, mainly to avoid waste of resources, but in my opinion the root cause of this problem probably is another.
 
To clarify my point of view, it would be necessary do the following tests too:

1. Check the slippage and other order relevant parameters for BM&FBovespa, since testing bar 0 and the condition is true, trade had to be executed.

2.Change test from bar 0 to bar 1, to check if the new bar event filter is really the root cause or have some influence (I don't think so, but just to confirm).

After these tests we can go on to identify the real problem.

 
Malacarne:

So, usually how this works in real life?

Do you wait for confirmation of MA crossover, or do you trade directly on tick, even if the bar is not yet closed? As we all know, one single tick is no guarantee that the crossover will actually take place...

That's why we need a new bar event handler...

As far as I understand we are using tick by tick but again, in a 5 mins timeframe, the MM crossed and only after the new candle, the system released the order.

The code is quite simple:

if(iMA_buf1[0]-iMA_buf2[0]>=0 && iMA_buf1_tick_anterior-iMA_buf2_tick_anterior<0)
     {
      if(FirstOperation==true)
        {
         m_Trade.Buy(contratos,my_symbol);
         FirstOperation=false;
        }
      else
        {
          m_Trade.Buy(contratos*2,my_symbol);
        }
     }
Files:
Sem_tetulo.png  124 kb
 
YouTrade:

As far as I understand we are using tick by tick but again, in a 5 mins timeframe, the MM crossed and only after the new candle, the system released the order.

The code is quite simple:

if(iMA_buf1[0]-iMA_buf2[0]>=0 && iMA_buf1_tick_anterior-iMA_buf2_tick_anterior<0)
     {
      if(FirstOperation==true)
        {
         m_Trade.Buy(contratos,my_symbol);
         FirstOperation=false;
        }
      else
        {
          m_Trade.Buy(contratos*2,my_symbol);
        }
     }

Hello, which value is actually assigned to iMA_buf1_tick_anterior and iMA_buf2_tick_anterior ?

Anyway, the difference of moving averages is not, IMHO, the best approach to determine a crossover...

 
Malacarne:

Hello, which value is actually assigned to iMA_buf1_tick_anterior and iMA_buf2_tick_anterior ?

Anyway, the difference of moving averages is not, IMHO, the best approach to determine a crossover...

   iMA_buf1_tick_anterior=iMA_buf1[0];

   iMA_buf2_tick_anterior=iMA_buf2[0];

It is the value of the MMA[0] one tick before. I use to compare the values tick/tick to determine crossover.

What is IMHO ? What is the best approach to determine a crossover ?

Regards ...

 
YouTrade:
   iMA_buf1_tick_anterior=iMA_buf1[0];

   iMA_buf2_tick_anterior=iMA_buf2[0];

It is the value of the MMA[0] one tick before. I use to compare the values tick/tick to determine crossover.

What is IMHO ? What is the best approach to determine a crossover ?

Regards ...

IMHO means "in my humble opinion" (In Portuguese: "em minha humilde opinião")

The best approach to determine a crossover is to compare the MA values two periods ago with the MA values one period ago. 

 

To add more information about this subject, I took the log file from the EA.

The buy order was sent @ 01:54PM but the MA crossed @ 01:51PM (metatrader) and 01:50PM using another system we use here (graphs attached).


GG         0             13:54:48.189      M3M5 (WINM14,M5)   [1]iMA_buf1[0]:52286.92 --- iMA_buf2[0]:52270.65 --- SUB:16.26 --- iMA1ta:52233.83 --- iMA2ta:52235.98 --- SUB:-2.15
PF           0             13:54:48.189      M3M5 (WINM14,M5)   [3]FirstOperation==false - Buy

QS          0             13:54:48.189      M3M5 (WINM14,M5)   [3]iMA_buf1[0]:52286.92 --- iMA_buf2[0]:52270.65 --- SUB:16.26 --- iMA1ta:52233.83 --- iMA2ta:52235.98 --- SUB:-2.15

Files:
q1.png  12 kb
w2.png  13 kb
 
YouTrade:

To add more information about this subject, I took the log file from the EA.

The buy order was sent @ 01:54PM but the MA crossed @ 01:51PM (metatrader) and 01:50PM using another system we use here (graphs attached).


GG         0             13:54:48.189      M3M5 (WINM14,M5)   [1]iMA_buf1[0]:52286.92 --- iMA_buf2[0]:52270.65 --- SUB:16.26 --- iMA1ta:52233.83 --- iMA2ta:52235.98 --- SUB:-2.15
PF           0             13:54:48.189      M3M5 (WINM14,M5)   [3]FirstOperation==false - Buy

QS          0             13:54:48.189      M3M5 (WINM14,M5)   [3]iMA_buf1[0]:52286.92 --- iMA_buf2[0]:52270.65 --- SUB:16.26 --- iMA1ta:52233.83 --- iMA2ta:52235.98 --- SUB:-2.15

Are you sure you are using the same methods to compute the moving averages on these two different softwares ??
 
YouTrade:

As far as I understand we are using tick by tick but again, in a 5 mins timeframe, the MM crossed and only after the new candle, the system released the order.

The code is quite simple:

if(iMA_buf1[0]-iMA_buf2[0]>=0 && iMA_buf1_tick_anterior-iMA_buf2_tick_anterior<0)
     {
      if(FirstOperation==true)
        {
         m_Trade.Buy(contratos,my_symbol);
         FirstOperation=false;
        }
      else
        {
          m_Trade.Buy(contratos*2,my_symbol);
        }
     }

Note YouTrade, you already have the buffer, so you don't need to create such variables, like iMA_buf1_tick_anterior.

You just need to choose the right position of the array, for instance:

if (iMA_buf1[0]>iMA_buf2[0] && iMA_buf1[1]<=iMA_buf2[1]) ...

If you use bar [0] you already get the last tick when you copy buffer (update it) at OnTick().

If you just want to use complete bars (don't depend on tick by tick) just avoid use bar [0], for instance:

if (iMA_buf1[1]>iMA_buf2[1] && iMA_buf1[2]<=iMA_buf2[2]) ...

Finally, if you want to avoid waste of resources, you can use a new bar detection algorithm, but in my opinion this is just a level about what you need now, I would check order parameters before, mainly if you are using a Forex ready code direct to trade BM&FBovespa. 

Remark1: this is just buffer usage examples, not an algorithm or trading style suggestion to use moving averages.
Remark2: please use the SRC button in this editor to insert your code, as the examples above that I just fixed to you.

Reason: