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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      134 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      67 views
      0 likes
      Last Post PaulMohn  
      Working...
      X