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 George21, Today, 10:07 AM
      0 responses
      5 views
      0 likes
      Last Post George21  
      Started by Stanfillirenfro, Today, 07:23 AM
      9 responses
      23 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by DayTradingDEMON, Today, 09:28 AM
      2 responses
      16 views
      0 likes
      Last Post DayTradingDEMON  
      Started by navyguy06, Today, 09:28 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      8 responses
      32 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X