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

Plot work only in real time using another indicator as input

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

    Plot work only in real time using another indicator as input

    Dear Support,

    when I try to plot a value of an indicator in another indicator, like:

    Value[0] = SMA(20)[0];

    The plot for the Value[0] occurs only during real time process, while during historical data my custom indicator doesn't plot anything.

    I can solve this problem by calculating indicator's Value[0] also in State.DataLoaded, but this is difficult when my custom logic is not so simple like a moving average.

    Is there another way to fix this?

    thank you, best regards

    Andrea


    #2
    Hello Andrea,

    Thank you for your post.

    In my testing with this very simple indicator, I am able to see it plot on historical data. All this indicator does is plot an SMA by calling it from within OnBarUpdate:

    Code:
        public class ExampleHostedIndicator : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "ExampleHostedIndicator";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    SMAPeriod                    = 20;
                    AddPlot(Brushes.Orange, "SMALine");
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                Value[0] = SMA(SMAPeriod)[0];
            }
    
            #region Properties
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="SMAPeriod", Order=1, GroupName="Parameters")]
            public int SMAPeriod
            { get; set; }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> SMALine
            {
                get { return Values[0]; }
            }
            #endregion
    
        }
    It wouldn't be advised to set Value[0] from State.DataLoaded.

    Are you not seeing the indicator plot on historical data when structured like the above code? Could you provide a screenshot of what you see?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Dear Kate,

      It seems that with your logic all is ok.

      I found that the problem is in one of my custom indicators, there is 1 of 5 that I use don't plot anything, while using the other 4 I have not problem.
      I will check my code and let you know

      thank you, best regards

      Andrea

      Comment


        #4
        Dear Kate,

        I was not able to solve my problem, I attach two images.

        In this image you can see that my first indicator (line gray) plot correctly the value of the third indicator (orange arrows).

        Click image for larger version

Name:	indicator ok.png
Views:	331
Size:	120.0 KB
ID:	1102378


        while, in this image the same indicator doesn't plot correctly the value of the third indicator, but begin to plot only in real time and also it is wrong.

        Click image for larger version

Name:	indicator error.png
Views:	287
Size:	99.1 KB
ID:	1102379

        I think that there is some code issue in my second indicator (orange arrows)

        What can be the problem?

        if you need I can send you my code, it's a normalized cumulative volume delta that I plot as candles

        thank you, best regards

        Andrea

        Comment


          #5
          Can you explain me this better?




          TickReplayIndicator myTickReplayIndicator = null;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Name = "TestHost";
          }
          else if (State == State.DataLoaded)
          {
          // Store a reference to the Tick Replay indicator before State.Historical
          // Doing so ensures the hosted indicator will run through Tick Replay
          myTickReplayIndicator = TickReplayIndicator();

          // For a strategy, you can just call AddChartIndicator(TickReplayIndicator());
          // However this also adds a copy of the indicator to the chart, which may or may not be desired
          // For calculation purposes only, storing the reference should all that needs to be required.
          }
          }

          Comment


            #6
            Hello AndreaBhs,

            Thank you for your reply.

            The script snipped you posted shows how to use an indicator that relies on Tick Replay data within a hosting indicator.

            Depending on your script, you may not need Tick Replay.

            I would like to take a look at the script if you're comfortable with providing that.

            Thanks in advance; I look forward to assisting you further.



            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by PaulMohn, Today, 03:49 AM
            0 responses
            3 views
            0 likes
            Last Post PaulMohn  
            Started by inanazsocial, Today, 01:15 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by rocketman7, Today, 02:12 AM
            0 responses
            10 views
            0 likes
            Last Post rocketman7  
            Started by dustydbayer, Today, 01:59 AM
            0 responses
            2 views
            0 likes
            Last Post dustydbayer  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            5 responses
            23 views
            0 likes
            Last Post trilliantrader  
            Working...
            X