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

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.​
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rhyminkevin, Today, 04:58 PM
          3 responses
          46 views
          0 likes
          Last Post Anfedport  
          Started by iceman2018, Today, 05:07 PM
          0 responses
          5 views
          0 likes
          Last Post iceman2018  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          7 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          50 views
          0 likes
          Last Post futtrader  
          Working...
          X