delay DateTime

Created at 22 Jul 2020, 14:22
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!
LU

luca.tocchi

Joined 25.03.2020

delay DateTime
22 Jul 2020, 14:22


how can I make a 1 hour delay with the DateTime function?

 

thanks


@luca.tocchi
Replies

PanagiotisCharalampous
22 Jul 2020, 14:24

Hi Luca,

You can use AddHours() method.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

luca.tocchi
22 Jul 2020, 14:28

RE:

 

thanks


@luca.tocchi

luca.tocchi
22 Jul 2020, 14:42

RE:

PanagiotisCharalampous said:

Hi Luca,

You can use AddHours() method.

Best Regards,

Panagiotis 

Join us on Telegram

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            Print(DateTime.Now);
            Print(DateTime.Now.AddHours(1));

            if (DateTime.Now.AddHours(1))
            {
                Print("ok");
           }
        }
    }
}

I want to print "ok" after 1 hour from power on

but so it gives me error

where am i wrong?


@luca.tocchi

PanagiotisCharalampous
22 Jul 2020, 14:46

Hi Luca.

AddHours() returns a DateTime object. In the if statement you need to have a boolean variable or a comparison.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

... Deleted by UFO ...