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

How to Overload BarsInProgress when calling the BarsSinceExitExecution method

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

    How to Overload BarsInProgress when calling the BarsSinceExitExecution method

    Hi everyone,

    I'm trying to use 2 dataseries, one of them is UniRenko, but when I use this condition on my entry setup:

    && (BarsSinceExitExecution() > 1 || BarsSinceExitExecution() == -1)

    I'm getting the following error:

    Strategy 'XXXX': Error on calling 'OnBarUpdate' method on bar 253: Strategy 'XXXX/-1': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceExitExecution() method in the context of a multi-time frame and instrument strategy.

    I asume that BarsInProgress == 0 and BarsInProgress == 1 belongs to the primary data series, which is the UniRenko one.

    Added like this:

    AddDataSeries(Instrument, new BarsPeriod { BarsPeriodType = (BarsPeriodType)2018, BaseBarsPeriodValue = 14, Value = 2, Value2 = 32 });
    AddDataSeries(Instrument, Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);

    I don't know how to solve this problem.

    Thank you in advance.


    #2
    Hello J0shTrader,

    Thanks for your post.

    You are using an overload for BarsSinceExitExecution that does not have any parameters. The error is letting you know that since the strategy is a Multi Time Frame/Multi Instrument strategy, you need to use an overload that lets you specify the BarsInProgress index of the data series in which you want to count the number of bars since the exit order was executed. BarsInProgress == 0 is the primary data series and BarsInProgress == 1 is the first added data series in the script.

    Please reference the Help Guide to see overloads for BarsSinceEntryExecution, and please also see our complete Multi Time Frame and Instruments documentation for working with Multi Time Frame strategies.



    Multi Time Frame and Instruments (Important read!) - https://ninjatrader.com/support/help...nstruments.htm

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you so much Jim, now it works.

      One more question; what I need to achieve is, filter the strategy based on UniRenko chart by some indicators pointing to the secondary Data Series,
      Do I need to manage BarsInProgres == 2, or just using the indicator defined in State.DataLoaded is enough?

      Momentum1 = Momentum(Closes[2], MPeriod); <--- I'm using Closes[2] as secondary Data Series, but I'm using Momentum1 in BarsInProgress == 1

      Thanks

      Last edited by J0shTrader; 02-10-2021, 02:07 AM.

      Comment


        #4
        I followed this thread trying to do the same thing with a sample code i found here. When code is executed i was suprised by the following error: "An order placed at '8/9/2021 6:00:00 PM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met" prints. No historcal bars are evaluated. Then the strategy enabled.

        Believe the following 2 lines are correct as per Jim above:
        AddDataSeries(this.Instrument.FullName, new BarsPeriod { BarsPeriodType = (BarsPeriodType)2018, BaseBarsPeriodValue = 8, Value = 3, Value2 = 16 });
        if(Position.MarketPosition == MarketPosition.Long && BarsSinceEntryExecution(0, "matthewrenko1long", 0)>= 1) // to specify BarsInProgress == 0

        What is happening that code believes BarsRequiredToTrade not met? I tried setting a low number; didn't matter. Is it looking for BarsInProgress ==1 to exceed BarsRequiredToTrade? Code attempt attached. Thank you all!
        Attached Files

        Comment


          #5
          Hello Kicks.Spin,

          You would want to confirm what the CurrentBar index is when the order is submitted and compare that with what you have entered for BarsRequiredToTrade to confirm why you have received that error.

          You can also consider modifying your check on line 96 to include a check ensuring that CurrentBar is greater than BarsRequiredToTrade for the order submission logic to be processed.

          Code:
           if (CurrentBar < EntryStrength || CurrentBar < ExitStrength || CurrentBar < BarsRequiredToTrade)
              return;
          J0shTrader , apologies for not replying earlier. We had closed the ticket before we saw your edited reply. If you have a follow up question after a ticket is resolved, it is ok to double post. Editting a post after we already closed a ticket in our ticketing system will not reopen the ticket, so we won't see the new question.

          What you have is fine though, you are free to instantiate an indicator with one data series and access it on the BarsInProgress index of another data series.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Brevo, Today, 01:45 AM
          0 responses
          3 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          3 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          239 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          384 views
          1 like
          Last Post Gavini
          by Gavini
           
          Started by oviejo, Today, 12:28 AM
          0 responses
          6 views
          0 likes
          Last Post oviejo
          by oviejo
           
          Working...
          X