Stop the bot on certain days of the week.

Created at 20 Aug 2020, 01:12
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!
SA

samuel.jus.cornelio

Joined 19.03.2020

Stop the bot on certain days of the week.
20 Aug 2020, 01:12


     

Stop the bot on certain days of the week.
I tried the commands below but it unfortunately didn't work. Could someone tell me how I can solve this problem?

Thank you very much

 

 

 

 

   protected override void OnTick()
        {




            {
                if (Server.Time.DayOfWeek == DayOfWeek.Friday)
                    if (Server.Time.DayOfWeek == DayOfWeek.Sunday)
                        if (Server.Time.DayOfWeek == DayOfWeek.Saturday)

                            Stop();
            }


@samuel.jus.cornelio
Replies

PanagiotisCharalampous
20 Aug 2020, 07:51

Hi Sam,

It does not work because you expect a day to a Friday and a Saturday and a Sunday at the same time. Try an OR condition instead.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

samuel.jus.cornelio
20 Aug 2020, 12:18

RE:

PanagiotisCharalampous said:

Hi Sam,

It does not work because you expect a day to a Friday and a Saturday and a Sunday at the same time. Try an OR condition instead.

Best Regards,

Panagiotis 

Join us on Telegram

 

 


@samuel.jus.cornelio

samuel.jus.cornelio
20 Aug 2020, 12:25

RE:

PanagiotisCharalampous said:

Hi Sam,

It does not work because you expect a day to a Friday and a Saturday and a Sunday at the same time. Try an OR condition instead.

Best Regards,

Panagiotis 

Join us on Telegram

 

 

I tried it that way and it didn't work either.

I am using this code to test a strategy in Backtesting. It needs to work from Monday to Thursday. stopping on Friday and returning only on Monday Could you please give me an example of how to create these command lines?  

 

 

 

 

 

   protected override void OnTick()
        {






            {

                if (Server.Time.DayOfWeek == DayOfWeek.Friday)
                {
                    Stop();
                }
                if (Server.Time.DayOfWeek == DayOfWeek.Sunday)
                {
                    Stop();
                }
                if (Server.Time.DayOfWeek == DayOfWeek.Saturday)
                {
                    Stop();
                }
            }


@samuel.jus.cornelio

samuel.jus.cornelio
20 Aug 2020, 22:45

RE:

PanagiotisCharalampous said:

Hi Sam,

It does not work because you expect a day to a Friday and a Saturday and a Sunday at the same time. Try an OR condition instead.

Best Regards,

Panagiotis 

Join us on Telegram

 

 

Hello Panagiotis, don't forget about me. brother


@samuel.jus.cornelio

PanagiotisCharalampous
21 Aug 2020, 08:38

Hi Sam,

Your code will stop the cBot completely on the specific days. Try something like this instead

            var day = Server.Time.DayOfWeek;
            if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
            {
                // Trade
            }

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

samuel.jus.cornelio
21 Aug 2020, 17:00

RE:

PanagiotisCharalampous said:

Hi Sam,

Your code will stop the cBot completely on the specific days. Try something like this instead

            var day = Server.Time.DayOfWeek;
            if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
            {
                // Trade
            }

Best Regards,

Panagiotis 

Join us on Telegram

 

man, you are the best. now it's working perfectly.

THAAANKS


@samuel.jus.cornelio

marian.kosa
27 Jul 2021, 10:45

RE:

PanagiotisCharalampous said:

Hi Sam,

Your code will stop the cBot completely on the specific days. Try something like this instead

            var day = Server.Time.DayOfWeek;
            if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
            {
                // Trade
            }

Best Regards,

Panagiotis 

Join us on Telegram

I was trying similar stuff, like this, but i am getting error "Error CS0103: The name 'DayOfWeek' does not exist in the current context". Did something changed since than?


@marian.kosa

amusleh
27 Jul 2021, 12:17

Hi,

DayOfWeek type is not part of Automate API, it's part of .NET framework.

To use DayOfWeek on your code you must add "using System;" on top of your indicator/cBot code file.


@amusleh

marian.kosa
27 Jul 2021, 12:36

RE:

Thank you. That was the piece of information i was missing. I guess, i can delete other lines with "using System.xxxx;"

amusleh said:

Hi,

DayOfWeek type is not part of Automate API, it's part of .NET framework.

To use DayOfWeek on your code you must add "using System;" on top of your indicator/cBot code file.

 


@marian.kosa