Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse, I will get testing!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CortexZenUSA, Today, 12:53 AM
      0 responses
      1 view
      0 likes
      Last Post CortexZenUSA  
      Started by CortexZenUSA, Today, 12:46 AM
      0 responses
      1 view
      0 likes
      Last Post CortexZenUSA  
      Started by usazencortex, Today, 12:43 AM
      0 responses
      5 views
      0 likes
      Last Post usazencortex  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      168 responses
      2,265 views
      0 likes
      Last Post sidlercom80  
      Started by Barry Milan, Yesterday, 10:35 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X