• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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
    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 Guru73, Today, 01:35 AM
          0 responses
          0 views
          0 likes
          Last Post Guru73
          by Guru73
           
          Started by Maxwell123, Today, 12:34 AM
          0 responses
          3 views
          0 likes
          Last Post Maxwell123  
          Started by esquissa, Yesterday, 11:59 PM
          0 responses
          2 views
          0 likes
          Last Post esquissa  
          Started by i2w8am9ii2, Yesterday, 04:41 PM
          1 response
          8 views
          0 likes
          Last Post Lancer
          by Lancer
           
          Started by vivekniwas, Yesterday, 10:21 PM
          0 responses
          2 views
          0 likes
          Last Post vivekniwas  
          Working...
          X