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 to plot different Plots on different panels

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

    Indicator to plot different Plots on different panels

    Hello,

    I have an indicator that works with one instrument and plots bars (Plot object with PlotStyle.Bar). I would like to make it multi-instrument. The multi-instrument indicator will plot 4 Plot objects with PlotStyle.Bar - one for primary instrument and 3 for supplementary instruments. The plots will overlap and will not be visible well.

    I think that the best way is to visualize different plots on different panels.

    Is it possible to set up an indicator (with NinjaScript) to plot different plots on different panels?

    Is it possible to set up the number of panels on a chart with NinjaScript? Then the multi-instrument indicator would call single-instrument indicator for each instrument and different plots would be on different panels. Is it possible to make it with NinjaScript?

    Thanks,

    Valentin

    #2
    Hello Valentin,

    It is not possible to have an indicator plot in more than one panel.

    However, you can make 4 indicators and add these each to their own panel.

    Then with Indicator().PanelUI you can set the panel numbers of each of these.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Valentin,

      It is not possible to have an indicator plot in more than one panel.

      However, you can make 4 indicators and add these each to their own panel.

      Then with Indicator().PanelUI you can set the panel numbers of each of these.
      Thank you Chelsea.

      Could you provide sample code how to use Indicator().PanelUI?

      Is it possible to pass panel number as argument to single-instrument indicator? Something like this:

      SingleInstrumentIndicator(PrimaryInstrument, PanelNumber1)
      SingleInstrumentIndicator(SuppInstrument1, PanelNumber2)

      Would I need 4 "different" single-instrument indicators - with the same logic but with different names?

      Valentin

      Comment


        #4
        Hello Valentin,

        No, indicators do not have an overload parameter that changes the panel.

        Attached is a strategy that demonstrates setting the panel of a few added indicators. The strategy is called MultiplePanelIndicatorsStrategyExample.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Plot syntax

          If I can jump in here with a question, I am trying to plot a VOLMA value in series 1 of a multi series chart that will show these values in a new panel of series 0. (If this is possible) Here is my code so far: My problem is with the syntax of the commented line to show Plot 0 (and number 1 for the underlying series. I have been able to do a similar thing using a draw command in series 1 that shows in series 0. Any help would be appreciated.



          protected override void Initialize()
          {
          Overlay = false;
          CalculateOnBarClose = true;
          Add(PeriodType.Second, 1);
          Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line,"Plot0"));
          // Add(VOLMA,14,0,1);
          }

          protected override void OnBarUpdate()
          {
          if(BarsInProgress == 1)
          Plot0.Set(Close[0]);
          }

          Comment


            #6
            Hello Pete77,

            The VOLMA only has a period input.. (and optional input series)

            Add(VOLMA(14));

            Below is a public link to the help guide that shows how to call the VOLMA indicator.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you. You sent me to the right place.
              My message talks about multi series when I meant multi time frame.

              Under Initialize I am trying to call VOLMA for index 1.
              The best I can come up with, using data series for input is: Add(VOLMA(Close[1][0]),14);
              Does not work. Can you help me here? Unfortunately I don't have basic understanding of this programming language.

              Comment


                #8
                Hello Pete77,

                Actually there is an issue with that.

                Add() must be called in Initialize(). When a secondary series is added with Add(), that data is not ready yet to be used for an indicator (or anything else) until OnStartUp().

                This means that with NinjaTrader 7 it is not possible to use Add() to add a secondary series and also Add() an indicator initialized in that series.

                NinjaTrader 8 has corrected this issue by allowing data to be added in State.Configure with AddDataSeries() and then the once the data is loaded the indicator can be added to the chart with AddChartIndicator() in State.DataLoaded.

                You could instead, add the data series directly to the hosted indicator. (Meaning add the secondary series to the code of the indicator being called and change the logic of that hosted script to use the secondary series for calculations instead of trying to set the input series from the host script)
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I have a question. I have done some successful scripts in ver 7, but I have never used plots, and I am trying to understand them. Looking at examples I cannot see how the plot knows what to plot. How do you make the connection (for example with the values of a called indicator)? The name at the end of the plot sentence in quotes is just an identifer as far as I can see. It must be under OnBarUpdate some how.
                  Can you explain?

                  Comment


                    #10
                    Hello Pete77,

                    Plots are fairly simple. Add a plot, set the value for the plot on each bar.

                    Add() adds the plot.

                    Value.Set(double value) sets the value for the plot on that bar.

                    This is usually set in OnBarUpdate which updates after every bar close. This allows you to set the Value on each bar.

                    Below is a public link to the help guide on Value and Values (Values if there are multiple plots).



                    And a public link to the help guide on Add() for adding plots.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for the quick reply. I am not there yet. I want to plot a line representing the output of VOLMA, that I have called. How do I represent these output values in Value.Set under OnBarUpdate?


                      Which gets back to my lack of understanding "How do you tell a plot what to plot?"


                      I know I am missing something very simple here.
                      Last edited by Pete77; 07-24-2018, 05:05 PM.

                      Comment


                        #12
                        Hello Pete77,

                        Thank you for your response.

                        Below is a basic example of setting the Plot to the VOLMA. Please let me know if you have any questions.

                        Code:
                                protected override void Initialize()
                                {
                                    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                                    Overlay				= false;
                                }
                                protected override void OnBarUpdate()
                                {
                                    Plot0.Set(VOLMA(14)[0]);
                                }

                        Comment


                          #13
                          Thanks very much, that saves me hours of searching for an example of that syntax.


                          Question: does that syntax call call VOLMA, or do I add it first in Initialize?


                          Another question: I have copied the below code snippet right off NinjaScript help, but I get an error when compiling: "DataSeries does not contain a definition for "Pen"


                          if (VOLMA(14)[0] > 100)
                          Plot0.Pen = new Pen(Color.Red);
                          else
                          Plot0.Pen = new Pen(Color.White);

                          ?
                          Last edited by Pete77; 07-25-2018, 02:34 PM.

                          Comment


                            #14
                            "You could instead, add the data series directly to the hosted indicator. (Meaning add the secondary series to the code of the indicator being called and change the logic of that hosted script to use the secondary series for calculations instead of trying to set the input series from the host script)"

                            How do I insert properly something such as part of your post in my reply? I see how to do that from a NinjaScript editor, but not from a previous post.



                            Meanwhile, I have not been able to find an explanation or syntax example to fill in the "input" part of my code below. Could you help me out there? I realize I have to somehow refer to my 1 second secondary chart dataseries.



                            if(BarsInProgress == 1)
                            Plot0.Set(______VOLMA(14)[0]);
                            Last edited by Pete77; 07-28-2018, 11:15 AM.

                            Comment


                              #15
                              Hello Pete77,

                              Thank you for your response.

                              Does that syntax call VOLMA, or do I add it first in Initialize?
                              The syntax I provided will call VOLMA directly with no need to add it in Initialize().
                              I have copied the below code snippet right off NinjaScript help, but I get an error when compiling: "DataSeries does not contain a definition for "Pen"
                              The code should be as follows:
                              Code:
                              if (VOLMA(14)[0] > 100)
                              PlotColors[0][0] = Color.Red;
                              else
                              PlotColors[0][0] = Color.White;
                              Please visit the following link for more details: https://ninjatrader.com/support/help...plotcolors.htm
                              How do I insert properly something such as part of your post in my reply? I see how to do that from a NinjaScript editor, but not from a previous post.
                              This would require adding a secondary bar series to the script and changing the calculations to use that added series. This is detailed in our 'Multi Time Frame and Instruments' section of the Help Guide at the following link: https://ninjatrader.com/support/help...nstruments.htm
                              Meanwhile, I have not been able to find an explanation or syntax example to fill in the "input" part of my code below. Could you help me out there? I realize I have to somehow refer to my 1 second secondary chart dataseries.
                              Below is a basic example of the Input.
                              Code:
                                      protected override void Initialize()
                                      {
                                          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                              			Add(PeriodType.Second, 1);
                              			volma = VOLMA(Inputs[1], 14);
                                      }
                              Please let me know if you have any questions.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mmckinnm, Today, 01:34 PM
                              3 responses
                              5 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by f.saeidi, Today, 01:32 PM
                              2 responses
                              4 views
                              0 likes
                              Last Post f.saeidi  
                              Started by alifarahani, 04-19-2024, 09:40 AM
                              9 responses
                              55 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              3 responses
                              60 views
                              0 likes
                              Last Post NinjaTrader_SeanH  
                              Started by traderqz, Today, 12:06 AM
                              9 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X