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

Indicator loaded in strategy is calculated OET instead of continuing calculated OBC

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

    Indicator loaded in strategy is calculated OET instead of continuing calculated OBC

    Indicator (OnBarClose) loaded in strategy (OnEachTick) is calculated like the strategy on OnEachTick instead of continuing to be calculated on OnBarClose.
    I load an indicator (OBC) in my strategy (OET). unfortunately, the indicator is now also calculated on OET instead of on OBC, why? if the indicator is loaded at the same time on another chart without a strategy, everything works. the aim is to start the strategy and with it the indicator. the indicator does its calculations on OBC and then passes on parameters to the strategy via a public property (this works).

    Strategy:
    Code:
    protected override void OnStateChange()
    {
       case State.SetDefaults:
                Calculate = Calculate.OnEachTick;
    
       case State.DataLoaded:
                sidiSuperTrend = SidiSuperTrend(StrategyIdString);
    
       if (sidiSuperTrend != null)
         {
            sidiSuperTrend.Strategy = this;
            priorShowSupertrend = ShowSupertrend;
    [COLOR=#e74c3c]sidiSuperTrend.Calculate = Calculate.OnBarClose; // has no influence [/COLOR]
            AddChartIndicator(sidiSuperTrend);
         }
    ...
    }
    Indicator:
    Code:
    protected override void OnStateChange()
    {
       case State.SetDefaults:
       Calculate = Calculate.OnBarClose;
       ...
    }
    Click image for larger version

Name:	Screenshot_1.jpg
Views:	211
Size:	298.4 KB
ID:	1146533
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    I have also tried the following:

    Strategy:
    Code:
    sidiSuperTrend = SidiSuperTrend(StrategyIdString, Calculate.OnBarClose);
    Indiactor:
    Code:
    [Browsable(false), NinjaScriptProperty]
    [Display(Name = "CalculateMode", Description = "", Order = 1, GroupName = "Parameters")]
    public Calculate CalculateMode { get; set; }
    overwriting "Calculate" in OnStateChange via "NinjaScriptProperty" does not work either. it is overwritten for a short time, but reset before OBU ???

    Click image for larger version

Name:	Screenshot_2.jpg
Views:	191
Size:	129.4 KB
ID:	1146539
    Click image for larger version

Name:	Screenshot_3.jpg
Views:	177
Size:	22.1 KB
ID:	1146540
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    Comment


      #3
      Indicators used inside a Strategy inherit their Calculate setting from the Strategy.

      This is by design, and is documented here.
      Scroll down a little, study "Tips" section.

      Comment


        #4
        Originally posted by bltdavid View Post
        Indicators used inside a Strategy inherit their Calculate setting from the Strategy.

        This is by design, and is documented here.
        Scroll down a little, study "Tips" section.
        yes i know that, but that does not help me with the solution. is there only the possibility to change the indicator to OnEachTick and work with IsFirstTickOfBar, or is there a faster and better way to avoid major changes in the indicator code?

        sidlercom80
        NinjaTrader Ecosystem Vendor - Sidi Trading

        Comment


          #5
          Ah, so the issue you're complaining about is well known to you.

          You are experiencing what we call "documented and expected" behavior,
          which you dislike, and so your real question is, how do I get around it?

          That's not that uncommon, it can be a very legitimate complaint.
          So, why not just start with that as your question?



          It's quite possible that changing the indicator to work with OnEachTick
          may be the fastest and easiest route. Or not. Sometimes this is easy,
          and sometimes this is hard. It will depend on the calculations and the
          data series used inside your indicator. It also depends on you having
          the indicator source code, and how well you know that code.

          If you want to run your Strategy with OnEachTick, then the indicators
          used by that Strategy need to handle OnEachTick.

          The Calculate setting propagates from the parent script down to all
          embedded scripts. You cannot get around that. Full stop. End of story.

          But, let's think about this.
          Why does your Strategy need to use OnEachTick?
          Does it really need to do that?

          One way around it may be to redesign your Strategy to use OnBarClose, and
          then add a 1-Tick secondary data series to the Strategy, which then handles
          the things your OnEachTick code used to do.

          Isolating all changes by reworking your Strategy has advantages.
          How? Because your Strategy and indicators can all run as OnBarClose,
          and thus the indicators won't need any code changes of their own.

          Adding 1-Tick secondary data series is pretty common with strategies. It is
          often used with custom code for stop orders that need to auto trail, or for
          custom risk management, such as limiting the daily losses/profits via
          instantaneous PnL tracking.

          My point is:
          What are you trying to achieve that makes OnEachTick a requirement?
          Does your Strategy really need to use OnEachTick to achieve that?

          Perhaps a 1-Tick secondary data series is the better solution.
          Last edited by bltdavid; 03-14-2021, 03:45 PM.

          Comment


            #6
            Hi bltdavid, i changed my strategy to OnBarClose on your advice, a bit of a hassle, but so far it's working quite well. when i designed the strategy, i had problems with the logic in using multiple time units, so i decided to use OnEachTick at that time. there's a lot to learn from you
            sidlercom80
            NinjaTrader Ecosystem Vendor - Sidi Trading

            Comment


              #7
              Glad to hear!

              And thank you for the kind words.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by alifarahani, Today, 09:40 AM
              6 responses
              31 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Kaledus, Today, 01:29 PM
              5 responses
              14 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Waxavi, Today, 02:00 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by gentlebenthebear, Today, 01:30 AM
              3 responses
              17 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X