Announcement

Collapse
No announcement yet.

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

    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



          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          38 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X