Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Running Logic 2 Sec Before Bar Close

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

    Running Logic 2 Sec Before Bar Close

    I'm trying to make a trade entry decision 2 seconds before the 1 minute bar closes. So 12:00:58, 12:01:58, etc.
    My latest attempt is to add the 1 second data stream of my instrument and watch for the proper time in OnBarUpdate. Unfortunately, the instrument doesn't have an OnBarUpdate for every second. I can still use that method for grabbing the latest price, but I need some way to call a decision function 2 seconds before the next bar close or 58 seconds after each minute OnBarUpdate.
    Thanks!

    #2
    Hello athyssen,

    Thanks for your post.

    "the instrument doesn't have an OnBarUpdate for every second."

    I understand that you have added a secondary 1-second data series to your script and state that the instrument doesn't have an OnBarUpdate() for every second.

    If you have a secondary 1-second data series added to a script with AddDataSeries() and run the script with Calculate.OnBarClose, the OnBarUpdate() method of that secondary 1-second data series will process OnBarUpdate() at the close of each 1-second bar.

    This could be confirmed by adding prints to your script that print out BarsInProgress and the current Time[0]. If there is only 1 added series, we will see a print showing the BarsInProgress value is 1 and the Time will show that OnBarUpdate() is called for each second that occurs.

    See this demonstration video showing the above concept: https://brandonh-ninjatrader.tinytak...MV8yMDY3NTA1OA

    Something you could consider doing is adding a secondary 2-second data series to the script using AddDataSeries(). Then in OnBarUpdate() create a condition that checks if the Time of the added 2-second data series Seconds value ends in 58 and call your action, such as EnterLong().

    The condition might look something like this:

    Code:
    if (Times[1][0].Second == 58)
    {
        //do something here
    }
    See the help guide documentation below for more information.

    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
    Times[][]: https://ninjatrader.com/support/help...ries_times.htm

    Let me know if I may assist further.
    <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

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    81 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    149 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