Exact Hour:Minute:Second action issue (onTick missing the time setting)

Created at 04 Jul 2022, 22:07
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CA

capanna.paolo

Joined 04.07.2022

Exact Hour:Minute:Second action issue (onTick missing the time setting)
04 Jul 2022, 22:07


Dear all,

if i understood it correctly i can set my cBot to execute some actions onStart, onBars or onTick.

I wrote a cBot that can place an order at a specific time (hour:minute:second) under the onTick part of the code.

This sometimes fails since on that specific time there are no price changes and so the onTick doesn't fire the lines of the code.

 

How can i solve this issue? Is there a sort of "while True" loop that i can put in the code so that it doesn't miss my specific time setting?

 

Thanks in advance.

BR

P.


@capanna.paolo
Replies

firemyst
06 Jul 2022, 03:40

If it doesn't matter, why not just look for the first OnTick that happens after your specified time and execute the order then? So instead of checking if the time matches exactly, just check if onTickTime >= your specified time and if so, execute your actions. If you want it limited to only occur within a few seconds after your specified time, then pseudo logic would be:

if (onTIckTime >= yourSpecifiedTime && onTickTime <= OnTickTime + numberOfAllowedSecondsAfter)

{

   // do what you have to do

}

 

If you do want it at the exact hour:minute:second and a tick doesn't come through, then there's nothing you can do as that's based on the market.


@firemyst

capanna.paolo
06 Jul 2022, 08:14

RE:

I solved it with the function onTimer, thanks!

 

firemyst said:

If it doesn't matter, why not just look for the first OnTick that happens after your specified time and execute the order then? So instead of checking if the time matches exactly, just check if onTickTime >= your specified time and if so, execute your actions. If you want it limited to only occur within a few seconds after your specified time, then pseudo logic would be:

if (onTIckTime >= yourSpecifiedTime && onTickTime <= OnTickTime + numberOfAllowedSecondsAfter)

{

   // do what you have to do

}

 

If you do want it at the exact hour:minute:second and a tick doesn't come through, then there's nothing you can do as that's based on the market.

 


@capanna.paolo