Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Run a strategy 10 seconds before 15 minute bar closes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Run a strategy 10 seconds before 15 minute bar closes

    Hi guys,

    I am a bit stuck so if anyone can point me in the right direction, I would be most appreciative.

    I have a strategy that runs OnBarUpdate which runs when the bar closes. What I want to do is run it 10 seconds before the bar closes.

    The strategy exports some price data along with some indicator data to a text file. Nothing too exciting.

    Is this possible?

    Any sample code would be fantastic,

    Thanks in advance,

    #2
    Hello,

    Thank you for the post.

    You could likely do this a few ways.

    One would be to utilize a Secondary Series and then check that the Secondary series time is Greater than or Equal to the next Primary Series time minus 10 seconds.

    Here is an example of Calculating the next 15 minute time, and subtracting 10 seconds from that time:

    Code:
    protected override void Initialize()
    {
        Add("ES 09-17", PeriodType.Second, 10);
    }
    
    protected override void OnBarUpdate()
    {
        if (CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
        if (BarsInProgress == 1)
        {
            DateTime targetTime = Times[0][0].AddMinutes(15).AddSeconds(-10);
            Print(Times[1][0] + " + " + targetTime);
            if (Times[1][0] == targetTime) { Print("10 seconds before Time"); }
        }
    }
    Please keep in mind that this adds specifically 15 minutes to the primary bars time. This does not account for the session or have any other special considerations. If you needed to, you could add further logic to account for other situations as you see the need.


    I look forward to being of further assistance.

    Comment


      #3
      Thanks Jesse, I will get testing!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X