Date equals even day

Created at 30 Jun 2020, 13:27
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!
DA

davidp13

Joined 06.05.2014

Date equals even day
30 Jun 2020, 13:27


I'm trying to test the outcome to only trade on even days in any given month. So I have an array that contains numbers from 2 to 30 and I'm trying to match that to the day so if the date in the backtest is 14/06/2020 then it should trade, but if it is 15/06/2020 it should not. This is what I have, but in only looks at todays date. I dont know how to get the historic date.

 

        protected override void OnTick()
        {
            int[] arr = new int[15] 
            {
                2,4,6,8,10,12,14,16,18,20,22,24,26,28,30
            };

            for (int i = 0; i < arr.Length; i++)
            {
                    if (arr[i] == DateTime.Today.Day && Time.Hour == 13 && Time.Minute == 30)
                    {
                        ExecuteMarketOrder(TradeType.Buy, SymbolName, 1);
                    }
            }


@davidp13
Replies

davidp13
30 Jun 2020, 13:58

RE:

I worked it out. I used Server.Time.Day instead of DateTime.Today.Day and it worked. 

 

 


@davidp13