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

Addchartindicator() and calculate on tick

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

    Addchartindicator() and calculate on tick

    Can I get some assistance making an indicator added to a strategy via AddChartIndicator() calculate on tick when the strategy calculates on close?

    #2
    Hello Rogue_Two,

    Thanks for your post.

    The added indicator will adopt the host's calculate mode. Please see tip#3 in the help guide page: https://ninjatrader.com/support/help...?calculate.htm

    You can accomplish your goal by setting your strategy to Calculate.OnEachTick and then recode your strategy to only run when IsFirstTickOfBar is true to continue running the strategy once per bar. The help guide has an example of separating your code to run on each tick and on each bar within the same script: https://ninjatrader.com/support/foru...y-tick?t=19387
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I'll give that a try. Thanks Paul!

      Comment


        #4
        I changed the calculate mode to "Calculate.OnEachTick" and now the indicator I added via AddChartIndicator is now calculating on tick, which is what I wanted.

        Now, I am trying to get the triggers to "Calculate on bar close" and after looking through the links you posted I tried this:

        Code:
        // Overbought
           if (IsFirstTickOfBar)
           {
              if (CrossBelow(StochRSI1, Overbought, 1)) 
              {
               EnterShort(Convert.ToInt32(OrderQuantity), "");
               myBelowNeutral = false;
              }
        
              if (Position.MarketPosition == MarketPosition.Short && StochRSI1[0] < Neutral)
              {
              myBelowNeutral = true;
              }
        
              if (Position.MarketPosition == MarketPosition.Short && myBelowNeutral == false && CrossAbove(StochRSI1, Overbought, 1))
              {
               EnterLong(Convert.ToInt32(OrderQuantity), "");
              }
           }
        I was hoping this would allow my triggers to "calculate on bar close" but it seems I'm missing something here. I also tried shifting the index value back one value to ensure the strategy is using data from the recently closed bar but I am running into errors due to there being double and bools in my triggers.

        Comment


          #5
          Hello Rogue_Two,

          Thanks for your post.

          There is not enough information posted for me to assist in where the errors are. You can use the compile error information to identify the line and then based on the line what variables are declared as that will usually answer the questions of double verses bools. Also, make sure the errors are indeed for the script you are working on, check the file name column on the left of the errors.

          Once the compile errors have been cleared, I recommend adding print statements to your code so you can evaluate what the variables are using in the conditions. Here is a link to our trips on debugging: https://ninjatrader.com/support/help...script_cod.htm



          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bmartz, 03-12-2024, 06:12 AM
          5 responses
          32 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          13 views
          0 likes
          Last Post Aviram Y  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X