How to write code for automatic turn on and turn off Robot for someday.

Created at 30 Aug 2018, 19:05
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!
MA

maxxx2532@gmail.com

Joined 29.11.2017

How to write code for automatic turn on and turn off Robot for someday.
30 Aug 2018, 19:05


Hi everyone. How to write code for automatic turn on for someday at time set time and turn off in another day. Thank you.


@maxxx2532@gmail.com
Replies

PanagiotisCharalampous
31 Aug 2018, 10:34

Hi 

In principle you could have a function that checks if the cBot should be working or not. See below

 private bool ShutDown()
        {
                if (Server.Time.TimeOfDay >= tradingStarts && Server.Time.TimeOfDay < tradingStops)
                {
                    return true;
                }
                else
                {
                    return false;
                }
        }

You should define the tradingStarts and tradingStops parameters yourself.

Then you can use this function to determine if the cBot should execute its logic or not. See below

        protected override void OnTick()
        {
                if (!ShutDown())
                {
                      //Do something
                }
         }

However you will need to customize all the above according to your needs.

Best Regards,

Panagiotis


@PanagiotisCharalampous