'Timed Events'

Created at 24 Feb 2025, 10:45
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!
BE

BelgaTrade

Joined 24.02.2025

'Timed Events'
24 Feb 2025, 10:45


Hi

I want my script to check each position every 60 minutes. The CheckOpenPositions() works as expected because I've tried calling it without using a timer. What it does is that it scans all open positions and closes those who are in loss.

I had an idea that I wanted to instruct it do do this every 60 minutes. I set up the code and in backtesting mode I can see that it indeed closes my positions in loss every 60 minutes when I look at the history tab. All closed positions are closed with -1 pip in loss. This cannot be possible that every single position looks the same after 60 minutes.
I'm not sure how this timer object works, and maybe it fails because in backtesting mode there are no “real” time?

Anyway! Here's my code:

protected override void OnStart()
        {
     
           Timer.Start(TimeSpan.FromMinutes(60));
    
        }
        
        protected override void OnTimer()
        {
             CheckOpenPositions();
        }

 

 


@BelgaTrade
Replies

firemyst
07 Mar 2025, 00:16

Where's the rest of your code?

I don't see where you've:

  1. added the timer tick event
  2. what the “check open positions” method does

@firemyst