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

Check BarsPeriod

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

    Check BarsPeriod

    I need to check the BarPeriod of the strategy. If the user is trying to use a different period (4 in this case) the strategy should stop. I have this code and it worked for instrument check but it is not working for the period. Would you please help me?

    if (BarsPeriod.BarsPeriodType != BarsPeriodType.Minute && BarsPeriod.Value != 4)
    {
    Draw.TextFixed(this, "BR", "YOU ARE NOT CERTIFIED AS OPTIMIZER WITH WMBoT", TextPosition.BottomRight);
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Announcement.wav");
    CloseStrategy("Not Licensed " + Time[0].ToString());
    return;
    }

    #2
    Hi Jorge.andres.o,
    When do you want the strategy to stop?
    Alt. 1: If the BarsPeriodType is not Minute and the BarsPeriod.Value is not 4 (cumulative conditions) or
    Alt. 2: If either the BarsPeriodType is not Minute or the BarsPeriod.Value is not 4 (alternative conditions)?
    I think, you coded the first alternative. By consequence, if the user picks Minute but changes the BarsPeriod.Value to 5, only one of the conditions to stop the strategy is true.
    Therefore, the strategy is not closed. Perhaps you just need to change the && (and) to || (or)?
    This worked just fine at my end and stopped the strategy ...
    NT-Roland

    Comment


      #3
      Hello Jorge.andres.o,

      As a heads up, if the strategy is disabled with CloseStrategy(), this would also remove any drawing objects drawn by the strategy.
      You may want allow the strategy to remain enabled, but add a return in OnBarUpdate to prevent any logic from being evaluated, or alternatively use Log() to log a message.

      This code would need to be in State.DataLoaded within OnStateChange(). May I confirm that this is where the code is?

      The condition you have would only be true if the bar type is not 4 minute.

      Use a print to ensure that the condition is evaluating as true. Print the BarsPeriodType and the Value to the output window. Please include the output with your reply.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you NT-Roland

        Comment


          #5
          NinjaTrader_ChelseaB
          I will check it thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Yesterday, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Yesterday, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Yesterday, 03:01 PM
          2 responses
          22 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Yesterday, 07:24 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X