Announcement

Collapse
No announcement yet.

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.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      79 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X