auto close

Created at 22 May 2024, 19:58
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!
LI

lindstroemjohan

Joined 30.11.2023

auto close
22 May 2024, 19:58


Hi I have built an code that says if open trade at 21.30 then close positions.

It works in backtesting but not live at my demo account, what is wrong?

if (utcTime.Hour == 19 && utcTime.Minute >= 30) // 19:30 UTC corresponds to 21:30 UTC+2
            {
                if (isTradeInitiated)
                {
                    CloseOpenTrades();
                }
                Stop();
            }
        }

        private void CloseOpenTrades()
        {
            foreach (var position in Positions)
            {
                if (position.Label == Label)
                {
                    ClosePosition(position);
                }
            }
        }


@lindstroemjohan
Replies

PanagiotisCharalampous
23 May 2024, 05:34

Hi there,

Please share with us the following

  • The complete cBot code.
  • Some screenshots, including the cBot log, showing that the cBot is running, even when the condition to stop it is met.

Best regards,

Panagiotis


@PanagiotisCharalampous