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

How to specify the last second of a minute bar in NT8?

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

    How to specify the last second of a minute bar in NT8?

    I'm trying to specify the last second of a minute bar in my strategy. Someone told me that:

    "The NinjaTrader.Core.Globals.Dispatcher is not a valid method in NinjaTrader 8's API.

    Unfortunately, NinjaTrader 8 does not provide a built-in method to execute code after a delay within the strategy's code. The typical way to handle time-based conditions in NinjaTrader is to use the OnBarUpdate method, which is called whenever a new bar is formed. However, this method does not allow for executing code at a specific time within a bar.

    One possible workaround is to use a higher-resolution data series (such as tick or volume data) in addition to your primary data series."

    So now I'm using second data, but I'd like to use minute data. Is there someway to specify the last second of a minute bar in NT8?

    Thanks

    #2
    Hello chinaexpert1a,

    Thanks for your post.

    You could use the AddDataSeries() method to add a 1-second series to your script and then create a condition that checks if the BarsInProgress value is equal to the added series and if the Time of the added 1-second series is 1 second before the minute bar closes.

    For example:

    //OnStateChange() State.Configure
    ​AddDataSeries(Data.BarsPeriodType.Second, 1);

    //OnBarUpdate()
    if (BarsInProgress == 1 && Time[0].Second == 59)
    {
    //do something
    }


    See the help guide documentation below for more information.

    AddDataSeries: https://ninjatrader.com/support/help...dataseries.htm
    BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm
    Time: https://ninjatrader.com/support/helpGuides/nt8/iseries_time.htm
    Make sure you have enough bars in the data series you are accessing: https://ninjatrader.com/support/help...nough_bars.htm
    Working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm
    Last edited by NinjaTrader_BrandonH; 05-24-2023, 11:43 AM.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      That only works if there is a trade tick in the 2nd to last second of the minute - otherwise there is no such 1-second bar. You could also consider using a timer.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by popecapllc, 08-09-2023, 07:42 PM
      11 responses
      1,873 views
      0 likes
      Last Post tradgrad  
      Started by morrnel, 05-12-2024, 06:07 PM
      7 responses
      106 views
      1 like
      Last Post tradgrad  
      Started by mmike, Yesterday, 10:33 PM
      0 responses
      4 views
      0 likes
      Last Post mmike
      by mmike
       
      Started by Pole123, Yesterday, 06:02 PM
      0 responses
      8 views
      0 likes
      Last Post Pole123
      by Pole123
       
      Started by samish18, Yesterday, 05:27 PM
      0 responses
      5 views
      0 likes
      Last Post samish18  
      Working...
      X