Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple Strategy Help

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

    Simple Strategy Help

    So i run this strategy and even though I have onbarclose = false the strategy doesnt try to execute a trade until the bar closes. I haven't tried it real time but hte historical performance always shows executions on the open of the next bar, and not the current bar in which the "If Then" conditions where met. Any ideas?

    Code:
    protected override void Initialize()
            {
                SetProfitTarget("", CalculationMode.Ticks, 8);
                SetStopLoss("", CalculationMode.Ticks, 25, false);
    
                CalculateOnBarClose = false;
                IncludeCommission = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
                if (Close[0] >= Bollinger(2.33, 8).Upper[0])
                {
                    EnterShortLimit(DefaultQuantity, Bollinger(2.33, 8).Upper[0], "Short");
                }
    
                // Condition set 2
                if (Close[0] <= Bollinger(2.33, 8.Lower[0])
                {
                    EnterLongLimit(DefaultQuantity, Bollinger(2.33, 8).Lower[0], "Long");
                }
            }

    #2
    floyd084, you would need to run this in realtime or replay for seeing the intrabar updates offered via CalculateOnBarClose = false. As in backtesting and processing historical data parts this would always be 'true' as the intrabar formation would not be available.

    Comment


      #3
      Thanks. I had a feeling that may be the problem, but the intra bar data is available, ninjatrader just isn't accessing it. Is there a work around to this? how does the historical performance "run"

      Comment


        #4
        Hello,

        When backtesting, events will always be processed at the end of the bar. For example if you are running on a 5 minute series, the events are processed at every 5 minute bar.

        However, it is possible to add a smaller time frame to process events "intrabar". Please see our Reference Sample on 'Backtesting NinjaScript Strategies with an intrabar granularity'

        You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        656 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        371 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X