Initialize cBot on condition - assistance please

Created at 08 Oct 2019, 00:41
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!
ZE

zedodia

Joined 30.05.2018

Initialize cBot on condition - assistance please
08 Oct 2019, 00:41


Hi, I am wondering how do you initialize a cBot on a condition? for simplicity sake, I would like to start my cBot (press play) but make it so it wont actually start the logic until a condition is met. For this example lets just use an SMA.

start cBot, once price touches the SMA, the logic is started.

 

do i put this code in

        protected override void OnStart()

or do i need a new class prior to this?


@zedodia
Replies

PanagiotisCharalampous
08 Oct 2019, 08:22

Hi zedodia,

You can use a flag and put the logic in OnTick or OnBar. The flag should be initialized to false and the condition checked on each tick/bar. If the condition is met set the flag to true. Execute the rest of the logic only if the flag is true.

Best Regards,

Panagiotis


@PanagiotisCharalampous