Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder condition  the last second of a one minute bar ninjatrader

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

    Strategy Builder condition  the last second of a one minute bar ninjatrader

    I want to make a condition on strategy builder that's true on the last second of a one minute bar. I want to do this condition because for some reason my strategy when I test it on Playback it Doesn't open a trade when operated on everytick. When my strategies conditions are met bars ago 1 It should immediately open a trade On the bars ago 0 Which it does perfectly on Strategy Analyzer. But not on playback If I operate my strategy on bar-close, Then it opens the trade, but one bar later Then it should. The only way it works on every tick is if The strategies calculations. And execution is in the same bar o But that ruins my strategy because all those calculations have to be true at the moment of the close of the bar. But I cannot make that work, so the only other way. Is to make a condition. that's only true in the last second of the bar, then My strategy would work. I would appreciate any help or advice I can get. Best regards.

    #2
    Hello Szebi,

    Thank you for your post.

    Unfortunately this cannot be achieved in the Strategy Builder. To achieve this logic, you will need to unlock your code.

    In an unlocked script, you can use AddDataSeries() to add a 1-second series to your script, have a condition to check 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:
    Code:
    //in OnStateChange();
    
    if (State == State.Configure)
    
    {
    
    ​AddDataSeries(Data.BarsPeriodType.Second, 1);
    
    }
    
    ​
    
    //in 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
    Times - https://ninjatrader.com/support/help...ries_times.htm
    Multi Time Frames & Instruments - https://ninjatrader.com/support/help...nstruments.htm

    Please let me know if you have any other questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    51 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    32 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    99 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    177 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    170 views
    0 likes
    Last Post CarlTrading  
    Working...
    X