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

stacking 2 or more plots one above the other

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

    stacking 2 or more plots one above the other

    Can anyone help show how to get plot (bars) of an indicator 2 painted either over the interval from 1 to 2 (or from -1 to 2- in the negative case) so that they are stacked to the plot (bars) of another indicator 1 whose plot (bars) is painted over the interval from 1 through 2 (or form -1 through -2, in the negative case)
    In the attached sample indicator aaCheckHarami.cs (given by joining indicators aaCandleCheckHarami.cs and aaCandleCheckHaramiCross.cs ) how would it be it possible to have the red bars of the second indicator painted just from 1 through 2 (or just from -1 through -2 in the negative case), ie stacked above (below) the blue bars of the first indicator whose bars are going just from 0 through 1 ( or from 0 through -1 in the negative case)
    Thx.
    Click image for larger version

Name:	NQ 03-20 (3 Minute) 2020_01_20 (13_01_03).png
Views:	286
Size:	56.6 KB
ID:	1084365

    #2
    Hello guidoisot,

    Thank you for the post.

    From the description I am not clear on what you are trying to do, I want to further clarify the goal.

    how would it be it possible to have the red bars of the second indicator painted just from 1 through 2 (or just from -1 through -2 in the negative case)
    Are you asking how to omit certain value data and only show values that are positive?

    , ie stacked above (below) the blue bars of the first indicator whose bars are going just from 0 through 1 ( or from 0 through -1 in the negative case)
    In the image you show 3 separate indicators, are you trying to combine them into a single panel and have the values vertically align or do you still want separate panels? I am having a hard time understanding the description in contrast to the image provided, if you can further explain the overall effect you want to see that would be helpful.

    I look forward to being of further assistance.


    JesseNinjaTrader Customer Service

    Comment


      #3

      Hello Jesse,
      thank you fo ryour reply.

      Originally posted by NinjaTrader_Jesse View Post
      are you trying to combine them into a single panel and have the values vertically align
      yes. This is exactly what I am trying to get: combine into one single indicator 2 different indicators so that their individual outputs on two different panels, both ranging from -1 to +1, are replaced by a merged output on a single panel ranging from -2, +2,

      thx

      Comment


        #4
        Hello guidoisot,

        Thank you for the additional details, that helps.

        Do you want to simply overlay the indicators as they are now or did you intend to modify the values being plotted at all?

        If you only wanted to overlay them it would be easiest to manually do that by dragging them into the same panel. A strategy could also be used for its AddChartIndicator to accomplish that.

        From an Indicator the alternative would be to make a single indicator that plots all three values in a single panel. You could do that by just making a new empty indicator and then adding the parts from the three files to that single indicator effectively combining them.



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello,

          Originally posted by NinjaTrader_Jesse View Post
          Do you want to simply overlay the indicators as they are now or did you intend to modify the values being plotted at all?
          as regards just the second indicator I would like to modify its values so that on the indicator panel there will be an histogram (a bar) going from 1 to 2 (or from -1 to -2, in the negative case)

          Originally posted by NinjaTrader_Jesse View Post
          If you only wanted to overlay them it would be easiest to manually do that by dragging them into the same panel. A strategy could also be used for its AddChartIndicator to accomplish that.
          This is what I have been doing so far manually, but sometimes the indicators' bars overlap one another

          Originally posted by NinjaTrader_Jesse View Post
          From an Indicator the alternative would be to make a single indicator that plots all three values in a single panel. You could do that by just making a new empty indicator and then adding the parts from the three files to that single indicator effectively combining them.
          also in this case I am not sure how to tell at some values (resulting as being = 2, or =-2) to plot on the indicator panel an histogram going just from 1 to 2 and not from to 2 (-1 to -2 vs + to -2, for the negative case) so when this happens at the same price bar they do not overlap to the plot of the first indicator which is =+1 or -1


          thx

          Comment


            #6
            Hello guidoisot,

            Thank you for the clarification.

            It sounds like it would be best to make an indicator for the purpose you wanted. Likely the most simple approach is to use everything the existing indicators have by combining their logic into one file.

            Because you want modifications to some of the indicators values you could do that as well when you combine them and that would be reflected in the plots.

            What you are asking for would likely require making some conditions to tell the indicator when to plot or when not to plot values. If you don't want values to overlap you would have to identify what the values are at that time so you can form a condition to avoid that.

            To prevent two plots from overlapping or plotting in the same bar you could use the existing logic to set all of the plots and then add another small condition after that to reset plots which should not be visible. You can use the Reset() method on a plot to clear its value: https://ninjatrader.com/support/help...lightsub=reset


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              I am not sure I can follow what you are suggesting. I read that the reset command maintains the value of Values[1][0] = +2 (for example for the strategy builder purposes), but ignores the (whole) value of Values[1][0] for printing purposes.

              IsSuspendedWhileInactive = true;/*
              Open_Time = DateTime.Parse("15:29", System.Globalization.CultureInfo.InvariantCulture) ;
              Close_Time = DateTime.Parse("21:59", System.Globalization.CultureInfo.InvariantCulture) ;*/

              AddPlot(new Stroke(Brushes.MediumSlateBlue), PlotStyle.Bar, "CandleCheck");
              AddPlot(new Stroke(Brushes.Red), PlotStyle.Bar, "CandleCheck2");
              Plots[0].AutoWidth = true;

              AddLine(Brushes.Gray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
              }
              else if (State == State.Configure)
              {
              }
              else if (State == State.DataLoaded)
              { CandlestickPattern1 = CandlestickPattern(Close, ChartPattern.BullishHaramiCross, 4);
              CandlestickPattern2 = CandlestickPattern(Close, ChartPattern.BearishHaramiCross, 4);
              CandlestickPattern3 = CandlestickPattern(Close, ChartPattern.BullishHaramiCross, 4);
              CandlestickPattern4 = CandlestickPattern(Close, ChartPattern.BearishHaramiCross, 4);
              }
              }

              protected override void OnBarUpdate()
              { if (CurrentBars[0] < 4)
              return;
              { Values[0][0] = +0;
              Values[1][0] = +0;
              }

              // Set 1
              if (CandlestickPattern1[0] == 1)
              { Values[0][0] = +1; }

              // Set 2
              if (CandlestickPattern2[0] == 1)
              { Values[0][0] = -1; }

              // Set 1
              if (CandlestickPattern3[0] == 1)
              { Values[1][0] = +2; }

              // Set 2
              if (CandlestickPattern4[0] == 1)
              { Values[1][0] = -2; }

              }

              public override void OnCalculateMinMax()
              {
              MinValue = - 2;
              MaxValue = + 2;
              }


              However I understand that what we want is not avoiding the whole plot but just plotting a portion of the Values[1][0] = 2, ie we want to plot only its part going from +1 through +2. Looking back at the code of the merged indicator: when adding the plot CandlesCheck2 (at line 56) is it possible solve the problem by adding also a condition to the plot so that, when Values[1][0] = +2, it will be plotted with a bar going just from +1 through +2 (or -1 through -2 for the negative case) and not from 0 through 2. ?
              this would allow to have a complete visualization of all the plots avoiding possible overlapping, and would also allow using these plots in the Strategy Builder, as needed.

              An alternative would be using (large size) Dot vs Bars as the format of the plot, but here the problem is that when Values are = 0 there are a lot of overlapping large size Dots on the zero line of the plot panel. I dropped this option because I did not know how tell the script to avoid plotting Dots when the Values are = 0
              Looking forward to your reply.
              thx

              attached is image of chart similar to what we want to get

              Click image for larger version  Name:	stacking plots one another.jpg Views:	0 Size:	26.3 KB ID:	1084452
              Last edited by guidoisot; 01-20-2020, 02:46 PM.

              Comment


                #8
                However I understand that what we want is not avoiding the whole plot but just plotting a portion of the Values[1][0] = 2, ie we want to plot only its part going from +1 through +2. Looking back at the code of the merged indicator: when adding the plot CandlesCheck2 (at line 56) is it possible solve the problem by adding also a condition to the plot so that, when Values[1][0] = +2, it will be plotted with a bar going just from +1 through +2 (or -1 through -2 for the negative case) and not from 0 through 2. ?
                If you wanted to modify the value in some way you can make adjustments to the values after you set them to further control what is being plotted.

                It would likely be most simple to add some more logic below the existing logic to check what values were plotted and then reset the values to the correct value if needed. If we are going based on your example of Values[1][0] = +2, it would possibly look similar to:

                if( Values[1][0] >= 2)
                {
                ​​​​​​​ Values[1][0] = 2;
                }

                You could use the Bar style plot and then whole values like 1 or 2 to create the bars similar to the buy sell volume indicator. The bar style would extend from 0 though, if you specifically wanted cubes like you have shown that would require either the Dots style like you mentioned or to use custom rendering.

                To avoid showing dots where you dont want them you can either modify the logic to not set a value to the plot when it is 0 or use the Reset() method which tells a plots value for the bar to not be plotted.



                I look forward to being of further assistance.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thank you for your reply.
                  Unfortunately I would not know where to add some more logic below the existing logic to check what values were plotted.
                  Within the same onbarupdate already existing?
                  or in a new section defined as “protected override void OnBarUpdate()”
                  By reading the ninjascript helponline I could not find out how and where to use the reset command also because the examples it shows do not tell much about what we are discussing here.

                  Maybe it is easier if I just try to use the Dot format, but how can I modify the logic “not to set a value to the plot when it is 0” or how can I use the reset method for this? Could you please show an example?

                  After spending some time on this subject I would say that this possibility of vertically stacking the outputs coming by several indicators into a single consolidated panel, could be a useful default feature for the platform. I would like to submit a new feature request for its implementation. Please could you help me also on this?
                  Thank you

                  Comment


                    #10
                    Hello guidoisot,


                    Unfortunately I would not know where to add some more logic below the existing logic to check what values were plotted.
                    Within the same onbarupdate already existing?
                    or in a new section defined as “protected override void OnBarUpdate()”
                    A script will only have one OnBarUpdate override. If you have any confusion surrounding the structure of a NinjaScript file it may be beneficial to first go through some of the existing indicators to see how they are structured. One common item which you will see with all items is that they all only have one OnBarUpdate override being used.
                    https://ninjatrader.com/support/help...ub=onbarupdate

                    Your new code could go near the end of the existing OnBarUpdate because you are trying to effect the values the existing logic made. The code will run from top to bottom through the override reaching your newer code last so it can set the plot to the value you wanted.


                    By reading the ninjascript helponline I could not find out how and where to use the reset command also because the examples it shows do not tell much about what we are discussing here.
                    The page I linked shows an example for Reset() specifically and provides a description for that method. This is not going to be specific to what we are looking at in your code because that is custom and the help guide is just general information relating to how this works in NinjaScript. Calling Reset() simply means you effectively ignore the value of the current bar for plotting purposes.

                    When I had suggested Reset it was not clear of the overall goal you had and it seemed that you wanted to hide some data. This can be used to hide data. As you provided more details it seems you want to instead modify the values and still plot them in a custom way so you will likely instead want to use logic here to change the values instead of hiding the plot value.


                    Maybe it is easier if I just try to use the Dot format, but how can I modify the logic “not to set a value to the plot when it is 0” or how can I use the reset method for this? Could you please show an example?
                    The dot may be easier because this is just a style for the plot. To modify the logic to not set a plot I had provided a sample of this in the last message.

                    Code:
                    if( Values[1][0] >= 2)
                    {
                    Values[1][0] = 2;
                    }
                    In this example I am checking if the plot was set to a value greater or equal to 2, if so I change the plot value to 2. To not set data you can do the same concept, add a condition in which the plot is to be set.

                    Code:
                    if(Values[1][0] < 0)
                    {
                    // note that I did not call Values[1][0] = 2;, if you don't call this code nothing is being set
                    }

                    You could form any number of conditions like this where you change or modify the value.


                    After spending some time on this subject I would say that this possibility of vertically stacking the outputs coming by several indicators into a single consolidated panel, could be a useful default feature for the platform. I would like to submit a new feature request for its implementation. Please could you help me also on this?

                    What you are asking for would is a custom indicator so you are already on the correct path toward that goal. Most indicators do not share values or timing to where stacking like you had shown would be possible. You had additionally asked to show a portion of the values depending on where it falls which is custom to your goal so I am not certain what I could feature request with this item as described. You are certainly on the right track to making what you want you would just need to continue to learn NinjaScript to make this a more smooth process.


                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Jesse.
                      Thank you for your reply.


                      As far as I can understand Values[1] can also be <0 (when it must be = - 2)

                      so I thought I should not to set exactly the same condition of your example,

                      Code:
                      if(Values[1][0] < 0)
                      {  }
                      First I tried to set the condition “if(Values[1][0]” is inside interval (-1;+1), “then Values[1][0] does not exist”, but this did not work: all the zeros were still there.

                      I then set the condition for Values[1][0] not equal neither to -2 nor to +2, but still it does not work, because on the indicator panel all the dots at zero still show up, as shown on the attached chart.

                      I am not sure what is wrong in in my interpretation of your example when I try to replicate it, as follows:

                      Code:
                      protected override void OnBarUpdate()
                               {     if (CurrentBars[0] < 4)
                                      return;
                                      {              Values[0][0] = +0;
                                                     Values[1][0] = +0;
                                      }
                                       // Set 1
                                      if (CandlestickPattern1[0] == 1)
                                      {                                                             Values[0][0] = +1;                                          }
                      
                                                       // Set 2
                                      if (CandlestickPattern2[0] == 1)
                                      {                                                             Values[0][0] = -1;                                           }
                                       // Set 1
                                      if (CandlestickPattern3[0] == 1)
                                      {                                                             Values[1][0] = +2;                                          }
                                                       // Set 2
                                      if (CandlestickPattern4[0] == 1)
                                      {                                                             Values[1][0] = -2;                                           }
                                      if(Values[0][0] != -1  || Values[0][0] != 1)
                                                                                     {              }
                                      if(Values[1][0] != -2  || Values[1][0] != 2)
                                                                                     {              }
                               }
                               public override void OnCalculateMinMax()
                               {
                                        MinValue =  - 2;
                                        MaxValue =  + 2;
                               }
                               #region Properties
                               [Browsable(false)]
                               [XmlIgnore]
                               public Series<double> Pinch
                               {
                                      get { return Values[0]; }
                               }
                               #endregion
                      I thought about requesting this additional feature for the format of the bars because it came to my mind that this has been one of the basic histograms chart type options offered by Microsoft since the first versions of Excel and even before by Lotus 123.
                      Regards.
                      gt

                      Click image for larger version

Name:	NQ 03-20 (1 Minute) 2020_01_22 (14_05_51).png
Views:	241
Size:	80.2 KB
ID:	1084682

                      Comment


                        #12
                        Hello
                        I just noticed that an alternative to the Dot format for the plots is "Block" which is much closer to what I was looking for, except for the fact that there is still the zero line full of unwanted Blocks.

                        Click image for larger version

Name:	ES 03-20 (1 Minute) 2020_01_22 (16_31_00).png
Views:	385
Size:	75.4 KB
ID:	1084703

                        Comment


                          #13
                          Hello guidoisot,

                          The values at 0 are there because you are setting the plots to 0:
                          Code:
                          
                          
                          {      
                                  Values[0][0] = +0;
                                  Values[1][0] = +0;
                          }
                          If you don't want 0 values just don't set the plot to 0. The plot will not be shown if you are not setting a value to it for that bar. Because you are setting it to 0 for every bar it has a default value of 0.

                          The other conditions you had added otherwise are not doing anything so you would still need to add code into those conditions if you wanted to change the plot value in some way. Instead of having an empty body like { } you would add the code in between the braces to reset the value to what you wanted.

                          Code:
                          if(Values[0][0] != -1 || Values[0][0] != 1)
                          {
                          // add code here to do something when the value is not equal to -1 or not equal to positive 1
                          }


                          I look forward to being of further assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Thank you Jesse.
                            I have made changes you explained.
                            Compiles ok, now.
                            However the .cs file is included in NT8 directory of the custom indicators, but the indicator does not show up on the right click on chart list of available indicators .... !
                            Don't know why.
                            Thank you.
                            gt
                            Last edited by guidoisot; 01-23-2020, 05:33 AM.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            166 responses
                            2,233 views
                            0 likes
                            Last Post sidlercom80  
                            Started by thread, Yesterday, 11:58 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post thread
                            by thread
                             
                            Started by jclose, Yesterday, 09:37 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post jclose
                            by jclose
                             
                            Started by WeyldFalcon, 08-07-2020, 06:13 AM
                            10 responses
                            1,414 views
                            0 likes
                            Last Post Traderontheroad  
                            Started by firefoxforum12, Yesterday, 08:53 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post firefoxforum12  
                            Working...
                            X