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

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.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    4 views
    0 likes
    Last Post rbeckmann05  
    Started by rhyminkevin, Today, 04:58 PM
    4 responses
    52 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by iceman2018, Today, 05:07 PM
    0 responses
    5 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    8 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    14 views
    0 likes
    Last Post 00nevest  
    Working...
    X