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

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.
    BertrandNinjaTrader Customer Service

    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 royhagerman, Today, 04:30 AM
        0 responses
        1 view
        0 likes
        Last Post royhagerman  
        Started by haas88, 03-21-2024, 02:22 AM
        18 responses
        208 views
        0 likes
        Last Post haas88
        by haas88
         
        Started by Board game geek, Today, 02:20 AM
        0 responses
        6 views
        0 likes
        Last Post Board game geek  
        Started by knighty6508, Today, 01:20 AM
        2 responses
        15 views
        0 likes
        Last Post knighty6508  
        Started by franatas, Today, 01:53 AM
        0 responses
        5 views
        0 likes
        Last Post franatas  
        Working...
        X