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 NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      86 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      151 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      79 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      52 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      59 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X