EA : enter a position with no tick coming in

 

Hi guys,

I coded an EA that works on the CAC40 CFD.(usually called FRA40)

That CFD at my broker is open from 8:00 to 22h00 CET.

The EA decides if it will open a position in the last 5 seconds before the daily closure occurs, meaning between 21h59h55 and 21h59:59.

And of course the order opening routine is in the OnTick function.

Problem is that liquidity being low at that time, no tick may come in between 21h59h55 and 21h59:59, so my order may be "missed".

Does anyone can think of a way to force the order to be trigerred with no new tick coming in ? Something that would  tell the EA that if entering conditions are met between 21h59h55 and 21h59:59 ---> enter at market price.

Thanks,

Ben.

 
Benoit Arsac:

Hi guys,

I coded an EA that works on the CAC40 CFD.(usually called FRA40)

That CFD at my broker is open from 8:00 to 22h00 CET.

The EA decides if it will open a position in the last 5 seconds before the daily closure occurs, meaning between 21h59h55 and 21h59:59.

And of course the order opening routine is in the OnTick function.

Problem is that liquidity being low at that time, no tick may come in between 21h59h55 and 21h59:59, so my order may be "missed".

Does anyone can think of a way to force the order to be trigerred with no new tick coming in ? Something that would  tell the EA that if entering conditions are met between 21h59h55 and 21h59:59 ---> enter at market price.

Thanks,

Ben.

You could use the OnTimer() function for this purpose.

https://www.mql5.com/en/docs/event_handlers/ontimer

Please just be aware that OnTimer() will not be triggered in the strategy tester.

Documentation on MQL5: Event Handling / OnTimer
Documentation on MQL5: Event Handling / OnTimer
  • www.mql5.com
//|                                               OnTimer_Sample.mq5 | //|                        Copyright 2018, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | "It is recommended to run the EA at the end of a trading week before the weekend...
 
Jan Flodin:

You could use the OnTimer() function for this purpose.

https://www.mql5.com/en/docs/event_handlers/ontimer

Please just be aware that OnTimer() will not be triggered in the strategy tester.

Thanks for the tip but not sure how to use it.

Can I call the Ontick function from the Ontimer fonction ? Indeed all the business logic is in Ontick...so the easy way would be to have at a certain time Ontimer triggering Ontick. Is that possible ?

 
Benoit Arsac:

Thanks for the tip but not sure how to use it.

Can I call the Ontick function from the Ontimer fonction ? Indeed all the business logic is in Ontick...so the easy way would be to have at a certain time Ontimer triggering Ontick. Is that possible ?

As you have described it above you let the EA take one trade per day, 1-5 seconds before market close. So I guess that you already have some time filter activated. In this scenario you are probably not so dependent on ticks so you can follow the example in the link I provided you with and put your logic in the OnTimer() block.

 
Benoit Arsac:

Thanks for the tip but not sure how to use it.

Can I call the Ontick function from the Ontimer fonction ? Indeed all the business logic is in Ontick...so the easy way would be to have at a certain time Ontimer triggering Ontick. Is that possible ?

Yes, you can!

Every second expert call OnTick function in the example.

int OnInit() 
  { 
//--- create a timer with a 1 second period 
   EventSetTimer(1); 
  
//--- 
   return(INIT_SUCCEEDED); 
  } 
//+------------------------------------------------------------------+ 
//| Expert deinitialization function                                 | 
//+------------------------------------------------------------------+ 
void OnDeinit(const int reason) 
  { 
//--- destroy the timer after completing the work 
   EventKillTimer(); 
  
  } 
//+------------------------------------------------------------------+ 
//| Expert tick function                                             | 
//+------------------------------------------------------------------+ 
void OnTick() 
  { 
//--- 
  
  } 
//+------------------------------------------------------------------+ 
//| Timer function                                                   | 
//+------------------------------------------------------------------+ 
void OnTimer() 
  { 
 //---
  OnTick();

  }
 
Jan Flodin:

As you have described it above you let the EA take one trade per day, 5 seconds before close. So I guess that you already have some time filter activated. In this scenario you are not dependent on ticks so you can follow the example in the link I provided you with and put your logic in the OnTimer() block.

Oh Boy ;-)

I knew nothing about the Ontimer function so I actually made my own time calculations functions that are called from within Ontick....so no tick no time function call.... that's why I asked for a workaround as the time is not checked if no tick comes in.

Besides time is only one little piece of the different triggers used to decide if the trade should be opened or not.

Might have to do some rethinking but roughly....if I follow you,  I would just need to cut/paste my ontick content into ontimer and instead of beeing checked at every tick, my business logic would be checked every "whatever time I choose", that's the idea ?

 
Nikolaos Pantzos:

Yes, you can!

Every second expert call OnTick function in the example.

Hmmm ! That could be the low hanging fruit. In this case I would set this in a way that ontick gets called once or twice between 21h59h55 and 21h59:59, that should trigger the order just like if a tick had come in right ?

Reason: