• 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

how to plot existing indicator in another indicator

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

    how to plot existing indicator in another indicator

    1. i started coding a indicator and realized, i want to plot the EMA(9) on the chart when my indicator gets displayed. how do i add it to it?

    #2
    Hello junkone,

    Thanks for your post.

    This is not possible in NinjaTrader 8. A feature request has been created based on this thread: http://ninjatrader.com/support/forum...ad.php?t=61584

    We have added your vote for this feature request (SFT-899).
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by junkone View Post
      1. i started coding a indicator and realized, i want to plot the EMA(9) on the chart when my indicator gets displayed. how do i add it to it?
      Create a Plot and populate it with the requisite EMA value.

      Comment


        #4
        Hello junkone,

        For the sake of clarity, member Kogaman is providing a solution for adding a plot with a few lines of code and I was responding to the use of AddChartIndicator() which works (to plot the indicators) in strategies but not in another indicator. (At least we have another vote for the feature!)

        I apologize if I misunderstood or confused the original question.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          To elaborate, there is an AddPlot() method you can call from an indicator, which will add an array called Value[] to your indicator:

          http://ninjatrader.com/support/helpG...us/addplot.htm

          Code:
          protected override void OnStateChange()
          {
          	if (State == State.SetDefaults)
          	{
          		AddPlot(Brushes.Orange, "IndicatorPlot");
          	}
          }
          After that is set, in your OnBarUpdate method, you can then assign the Value[0] of the current bar to the other indicator value of the current bar

          Code:
          protected override void OnBarUpdate()
          {
          	// set the AddPlot value to an EMA indicator
          	Value[0] = EMA(9)[0];			
          }
          MatthewNinjaTrader Product Management

          Comment


            #6
            interesting logic. i tried it but it does not plot anything.
            Code:
            public class S_Trading_System : Indicator
                {
                    
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Description = @"Enter the description for your new custom Indicator here.";
                            Name = "S_Trading_System";
                            Calculate = Calculate.OnEachTick;
                            IsOverlay = false;
                            DisplayInDataBox = true;
                            DrawOnPricePanel = false;
                            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;
                            AddPlot(Brushes.Orange, "Mean");
                        }
                        else if (State == State.Configure)
                        {
                            AddPlot(Brushes.Aqua, "EMA 9");
                            AddPlot(Brushes.DarkGray, "EMA 22");
                        }
                    }
            
                    protected override void OnBarUpdate()
                    {
                        //Add your custom indicator logic here.
                        // Only process entry signals on a bar by bar basis (not tick by tick)
            
                        switch (BarsInProgress)
                        {
                            case 0:
                                BarsinProgress0();
                                break;
                            case 1:
                                Value[0] = EMA(9)[0];
                                break;
                            case 2:
                                Value[0] = EMA(22)[0];
                                break;
                            default:
                                Alert(" undefind bars in progress" + BarsInProgress, Priority.High, " undefind bars in progress" + BarsInProgress, NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav", 10, Brushes.Black, Brushes.Yellow);
            
                                break;
                        }
                       
            
                    }
            
                    private void BarsinProgress0()
                    {
                        if (IsFirstTickOfBar)
                        {
            
                            Value.Reset();
                            if (CrossAbove(EMA(9), EMA(22), 1))
                            {
                                Draw.Text(this, "crossabove" + CurrentBar, "look for long", 1, Low[1]);
                                
            
                                //Draw.ArrowLine(this, "crossabove_" + CurrentBar, 1, bounds.Y, 1, bounds.height, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                                Share("Twitter", Instrument.FullName + "Look for Long");
            
            
                            }
                            else
                            {
                                if (CrossBelow(EMA(9), EMA(22), 1))
                                {
                                    Share("Twitter", Instrument.FullName + "Look for Short");
                                    Draw.Text(this, "crossbelow" + CurrentBar, "look for short", 1, High[1]);
                                    
                                    Values[0][1] = 2;
                                }
                            }
            
            
            
            
                        }
                        // if it had crossed above recently, draw line from the start of the crossover to the end of crossover
                        if (EMA(9)[0] > EMA(22)[0])
                        {
                             
                        }
                        if (EMA(9)[0] < EMA(22)[0])
                        {
                            
                        }
                        //Print(" start=" + start + " end " + end);
            
                        // Process 
                    }
                   
            
                }
            }

            Comment


              #7
              Originally posted by junkone View Post
              interesting logic. i tried it but it does not plot anything.
              Code:
              public class S_Trading_System : Indicator
                  {
                      
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description = @"Enter the description for your new custom Indicator here.";
                              Name = "S_Trading_System";
                              Calculate = Calculate.OnEachTick;
                              IsOverlay = false;
                              DisplayInDataBox = true;
                              DrawOnPricePanel = false;
                              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;
                              AddPlot(Brushes.Orange, "Mean");
                          }
                          else if (State == State.Configure)
                          {
                              AddPlot(Brushes.Aqua, "EMA 9");
                              AddPlot(Brushes.DarkGray, "EMA 22");
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          //Add your custom indicator logic here.
                          // Only process entry signals on a bar by bar basis (not tick by tick)
              
                          switch (BarsInProgress)
                          {
                              case 0:
                                  BarsinProgress0();
                                  break;
                              case 1:
                                  Value[0] = EMA(9)[0];
                                  break;
                              case 2:
                                  Value[0] = EMA(22)[0];
                                  break;
                              default:
                                  Alert(" undefind bars in progress" + BarsInProgress, Priority.High, " undefind bars in progress" + BarsInProgress, NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav", 10, Brushes.Black, Brushes.Yellow);
              
                                  break;
                          }
                         
              
                      }
              
                      private void BarsinProgress0()
                      {
                          if (IsFirstTickOfBar)
                          {
              
                              Value.Reset();
                              if (CrossAbove(EMA(9), EMA(22), 1))
                              {
                                  Draw.Text(this, "crossabove" + CurrentBar, "look for long", 1, Low[1]);
                                  
              
                                  //Draw.ArrowLine(this, "crossabove_" + CurrentBar, 1, bounds.Y, 1, bounds.height, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                                  Share("Twitter", Instrument.FullName + "Look for Long");
              
              
                              }
                              else
                              {
                                  if (CrossBelow(EMA(9), EMA(22), 1))
                                  {
                                      Share("Twitter", Instrument.FullName + "Look for Short");
                                      Draw.Text(this, "crossbelow" + CurrentBar, "look for short", 1, High[1]);
                                      
                                      Values[0][1] = 2;
                                  }
                              }
              
              
              
              
                          }
                          // if it had crossed above recently, draw line from the start of the crossover to the end of crossover
                          if (EMA(9)[0] > EMA(22)[0])
                          {
                               
                          }
                          if (EMA(9)[0] < EMA(22)[0])
                          {
                              
                          }
                          //Print(" start=" + start + " end " + end);
              
                          // Process 
                      }
                     
              
                  }
              }
              I am assuming that that is your entire code.

              In which case, BarsInProgress will always be zero, as you have not defined any other barSeries. In other words, your code is doing exactly what you wrote, and never accessing that which does not exist anyway. In your code, I see multiple artifices that depend on ideas that seem not to be clearly understood.

              You came in here asking for help with something that you did not yet quite understand. Matthew gave you some annotated code to demonstrate what could be achieved. It might pay you better dividends if you took only that code, with no other ideas, and verified what that it does what you wish. Once, you are confident that the code does what you expect, further exploration of ideas is then much more viable.

              Just my $0.02.

              Comment


                #8
                Originally posted by koganam View Post
                I am assuming that that is your entire code.

                In which case, BarsInProgress will always be zero, as you have not defined any other barSeries. In other words, your code is doing exactly what you wrote, and never accessing that which does not exist anyway. In your code, I see multiple artifices that depend on ideas that seem not to be clearly understood.

                You came in here asking for help with something that you did not yet quite understand. Matthew gave you some annotated code to demonstrate what could be achieved. It might pay you better dividends if you took only that code, with no other ideas, and verified what that it does what you wish. Once, you are confident that the code does what you expect, further exploration of ideas is then much more viable.

                Just my $0.02.
                all is good. i thought add plot makes it multibar and i realize the error now. thanks for the hint.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by YevhenShynkarenko, Today, 02:55 AM
                0 responses
                20 views
                0 likes
                Last Post YevhenShynkarenko  
                Started by pjsmith, Today, 02:20 AM
                0 responses
                8 views
                0 likes
                Last Post pjsmith
                by pjsmith
                 
                Started by faisamtrader, Yesterday, 10:03 PM
                0 responses
                8 views
                0 likes
                Last Post faisamtrader  
                Started by johnnybegoode, Yesterday, 08:11 PM
                0 responses
                4 views
                0 likes
                Last Post johnnybegoode  
                Started by Bionian, Yesterday, 02:47 PM
                2 responses
                26 views
                0 likes
                Last Post Bionian
                by Bionian
                 
                Working...
                X