Retry Order

Created at 27 Feb 2019, 18:52
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!
GDPR-83_694920's avatar

GDPR-83_694920

Joined 27.02.2019 Blocked

Retry Order
27 Feb 2019, 18:52


Hi

I am trying to work out the correct way to retry an order that for whatever reason did not execute

After reading as much as I can on here and trying many variations of code this is an example of what I am currently running in forward testing to see how it goes

  private void ExecuteMO()
        {
            var result = ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BotLabel", 10, 10);
            if (!result.IsSuccessful)
                ExecuteMO();
        }

I am not entirely convinced it is working properly and am really not sure this is the correct way to do things so can anyone let me know how best to code for whenever a trade is not succesful please?

Many thanks!


Replies

PanagiotisCharalampous
28 Feb 2019, 11:49

Hi Max T,

There is a risk that your code might end up in an infinite loop. It is better to examine the reason of the unsuccessful order before sending a new one. If for example you are sending a wrong volume or TP/SL levels then you will end up in a loop.

Best Regards,

Panagiotis


@PanagiotisCharalampous

GDPR-83_694920
28 Feb 2019, 12:33

Hi Panagiotis

Many thanks for the reply and yes was also concerned about an infinite loop but can I please confirm if I am understanding the '.IsSuccesful' correcty

Is the usage meant only for detecting technical problems due to issues with the code (bad volume etc.) or also for detecting completion of actual order execution (order does not complete at the broker for whatever reason therefore order is 'unsuccessful' and I want to retry/place the order again ASAP)


PanagiotisCharalampous
28 Feb 2019, 12:37

Hi Max T,

It is meant to detect both. If the order has not been accepted for any reason, the order will not be successfull.

Best Regards,

Panagiotis


@PanagiotisCharalampous

GDPR-83_694920
28 Feb 2019, 12:41

Great! Thank you so much for confirming - my code is minimal and stragithforward so there should never (...! ;) be any bad volume etc. issues and it is only the completion of the order execution that concerns me so want the code to retry placing the order again and again until sucesful so will go with the above and continue forward testing to see how things go

Many thanks again very much appreciated!