Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with 2 calculation options

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

    Strategy with 2 calculation options

    I have a strategy that run on Calculate.OnBarClose

    But one or more functions inside the strategy like ExitLong() or ExitShort() I want to run them on calculation.OnEachTick while keeping the the rest of strategy running on Calculate.OnBarClose

    How can I achieve this?
    Thanks

    #2
    I tried using IsFirstTickOfBar But for some reason when I add it to my strategy, the strategy stop working

    Code:
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = @"strateysample";
                    Name                        = "Strategy_Short2";
                    Calculate                    = Calculate.OnEachTick;
    
                }
    
                if (State == State.Configure)
                {
                    //indicator
                }
            }
    
            protected override void OnBarUpdate()
            {
            if (IsFirstTickOfBar)
                {
    
                /// SHORT Trades    
                if ( // From Monday to Friday
                       (Times[0][0].TimeOfDay >= new TimeSpan(17, 10, 0))
                    )
                  {
                    EnterShort(Contracts, "Short");
                    justEntered = true;
                   }
                  }
               }​​
    This is a sample of my strategy with if (IsFirstTickOfBar), this way it does not work.
    But When I remove the if (IsFirstTickOfBar)​ The strategy works fine on Calculate.OnEachTick
    I need the strategy to work on Calculate.OnBarClose and have only few conditions inside my strategy that works Calculate.OnEachTick​​

    Comment


      #3
      Hello onlinebusiness,

      IsFirstTickOfBar will restrict the code in the action block for that condition to only when a new bar forms.

      If the behavior is not what you expect, debug the script using Print() and TraceOrders.


      Print the time of the bar, all values in the conditions with labels for all values and comparison operators.
      Provide the output saved to a text file for assistance.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi chelsea, thank you for the assistance

        Do you see something wrong with my code above, I tried using IsFirstTickOfBar but it didn't work.

        Can provide me with a simple sample of using IsFirstTickOfBar in code so I can compare it with my strategy code. I would very much appreciate it.

        I want the whole strategy to using OnBareClose
        But only the ExitShort or ExitLong to be on OnEachTick

        Comment


          #5
          Hello onlinebusiness,

          Thanks for your note.

          You could find a reference sample linked below that uses IsFirstTickOfBar to separate some logic so that is calculates OnEachTick and other logic that calculates OnBarClose.

          SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm

          You will set your host script to Calculate.OnEachTick and use if(IsFirstTickOfBar) and place all code that needs to calculate once every bar within that condition check. Then place all code that you want to calculate OnEachTick outside of the IsFirstTickOfBar condition check.

          Please let us know if we may assist further.​
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          48 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X