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

How hide \ show plot dynamically?

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

    How hide \ show plot dynamically?

    Hello.

    I'd like to hide \ show plots dynamically while indicator working.

    In NT7 this worked fine:
    PHP Code:
    if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color Color.Empty;
    if( 
    SMA1[0] > SMA2[0] ) Plots[0].Pen.Color Color.Black


    In NT8 it not work.
    And variant below not work too.

    PHP Code:
    Plots[0].Pen = new PenBrushes.Transparent);
    Plots[0].Opacity 0;
    Plots[0].Brush Vis.Empty_Brush;

    OnRenderTargetChanged()
    {
       
    Plots[0].BrushDXBrushes.Empty.ToDxBrush();   
       
    Plots[2].BrushDX = new DxSolidColorBrushRenderTarget, new Color40000) );



    Is there any way to do it?
    Last edited by fx.practic; 09-13-2017, 02:25 PM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    Set the Plot[index].Brush and then refresh with ForceRefresh().

    Attached is an example.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Maybe I am missing something here, but can't you simply build your plots dynamicaly?
      Just add them in the (State == State.Configure) and you can use variable to turn them on and off. Using InvokeAsync((Action) for this seems a bit of an overkill.

      Comment


        #4
        Thanks a lot, Chelsea! Great example of lucidity.



        Zeos6, I am don't quite understand how to do this with manipulations in the (State == State.Configure):
        PHP Code:
        if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color Color.Empty; 
        if( 
        SMA1[0] > SMA2[0] ) Plots[0].Pen.Color Color.Black
        Also, I have idea to make checkbox, that hide \ show some plots.
        Last edited by fx.practic; 09-13-2017, 03:17 PM.
        fx.practic
        NinjaTrader Ecosystem Vendor - fx.practic

        Comment


          #5
          Need additional clarification: I trying to hide plot, with each dot colored with PlotBrushes[][].
          And this method not work.

          Is there any way to hide colored plot too?

          Now I using SendKey(F5), but this is ugly.
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            Hello fx.practic,

            Yes, a single bar's plot color can be set with PlotBrushes[plot index][bars ago].

            Are you setting this to Brushes.Transparent?

            Are you getting an error?

            Do you have an export of a reduced script to demonstrate?
            Last edited by NinjaTrader_ChelseaB; 09-19-2017, 03:27 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi fx.practic,

              If you are trying to dynamically change plot colors on each point, have a look at the following thread:


              There is a sample multi colored plot indicator from the NT Team, from JoshP. It will probably do what you are looking for.

              Comment


                #8
                Zeos6: I mean not set color of one dot, but how to make transparent all dots of particular plot. Thank You for link.

                Chelsea, let me clarify, what I tried.

                Transparent color is
                PHP Code:
                Color.FromArgb0255255255 ); 
                Empty color is
                PHP Code:
                Color.FromArgb000); 
                Brushes don't contain Brushes.Empty, so I used
                PHP Code:
                Brush empty_brush = new SolidColorBrush(  Color.FromArgb000) );
                empty_brush.Freeze(); 

                No Brushes.Transparent, neither empty_brush work if:
                PHP Code:
                    Value[0] = Close[0];
                    
                PlotBrushes[0][0] = Brushes.Red
                Can You advice me some new ways?
                Attached Files
                Last edited by fx.practic; 09-16-2017, 12:32 AM.
                fx.practic
                NinjaTrader Ecosystem Vendor - fx.practic

                Comment


                  #9
                  Hi fx.practic,

                  I am really not sure what it is you are trying to accomplish. If you are trying to hide/show in real time, as your NT7 code seems to indicate, then the multicolored plot link I provided will work for you. If you are trying to show/hide at the start - during configuration, then my original suggestion will work.

                  EDIT: Have you tried something along the lines of ....

                  Code:
                  if(State == State.SetDefaults)
                  {
                      AddPlot(Brushes.Blue, "SMA1");
                      AddPlot(Brushes.Red, "SMA2");
                       ...
                  }
                  
                  protected override void OnBarUpdate()
                  {
                      // Check that we have enough bars on our chart before processing
                      if(CurrentBar < Period) 
                          return;
                              
                       // Set the plots
                      Values[0][0]     = SMA(High, Period)[0];     // SMA1
                      Values[1][0]    = SMA(Low, Period)[0];       // SMA2
                  
                  if (Values[0][0] > Values[1][0])
                  {
                      // SMA1 > SMA2 code would set 
                      // set SMA1 to lime and the SMA2 to transparent
                                  PlotBrushes[0][0] = Brushes.Lime;
                                  PlotBrushes[1][0] = Brushes.Transparent;
                  }
                  else if (Values[0][0] < Values[1][0]))
                  {
                      // SMA1 < SMA2 code would set 
                      // set SMA1 to transparent and the SMA2 to Purple
                                  PlotBrushes[0][0] = Brushes.Transparent;
                                  PlotBrushes[1][0] = Brushes.Purple;
                  }
                  else
                  {
                      // SMA1 = SMA2 code would set 
                      // set SMA1 to orchid and the SMA2 to green
                                  PlotBrushes[0][0] = Brushes.Orchid;
                                  PlotBrushes[1][0] = Brushes.Green;
                  }
                      ...
                  }
                  Last edited by Zeos6; 09-16-2017, 12:53 PM.

                  Comment


                    #10
                    Zeos6, let my explain what I need on this video:
                    https://monosnap.com/file/M1NByU2N5l...VvkhDeVMXsJouC
                    fx.practic
                    NinjaTrader Ecosystem Vendor - fx.practic

                    Comment


                      #11
                      Oh OK. You want to show/hide your SMA using a button. Is that correct?

                      By the way, this is not what your NT7 code indicates.
                      if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color = Color.Empty;
                      if(
                      SMA1[0] > SMA2[0] ) Plots[0].Pen.Color = Color.Black;

                      Comment


                        #12
                        Zeos6, that is exactly what I want.
                        Yes, it work in NT7 in way You provide.
                        But, it not work in NT8 if:
                        PHP Code:
                        if( SMA1[0] < SMA2[0] ) Plots[0].Pen.Color Color.Empty; 
                        if( 
                        SMA1[0] > SMA2[0] ) Plots[0].Pen.Color Color.Black;

                        Brushes[0][0] = Brushes[1][0] = Brushes.Pink

                        And I need to hide multycolored plot in NT8.
                        Last edited by fx.practic; 09-17-2017, 03:01 PM.
                        fx.practic
                        NinjaTrader Ecosystem Vendor - fx.practic

                        Comment


                          #13
                          Hi fx.practic,

                          Attached is a simple skeleton code that does what you indicated you wanted. It's based off of what ChelseaB gave you. It works at my end. I am sure you can adapt it to your needs.
                          Attached Files

                          Comment


                            #14
                            I didn't find the key row in Your code:
                            PHP Code:
                            PlotBrushes[0][0] = Brushes.Orange
                            Please, try this.
                            Attached Files
                            fx.practic
                            NinjaTrader Ecosystem Vendor - fx.practic

                            Comment


                              #15
                              Hello fx.practic,

                              I am trying to help you but now I am confused again. The code I sent you does exactly what you showed in your video. I have no idea what you mean by

                              PlotBrushes[0][0] = Brushes.Orange;

                              and how that even comes into this discussion. Is this multi timeframe?
                              What exactly is it that you want to do? The information you have provided is contradictory.if you can clearly explain what you want I might be able to help you. As it stands now, I have no idea what the issue is.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Irukandji, Today, 09:34 AM
                              0 responses
                              0 views
                              0 likes
                              Last Post Irukandji  
                              Started by TraderBCL, Today, 04:38 AM
                              3 responses
                              24 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              11 responses
                              1,423 views
                              0 likes
                              Last Post jculp
                              by jculp
                               
                              Started by RubenCazorla, Today, 09:07 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post RubenCazorla  
                              Started by BarzTrading, Today, 07:25 AM
                              2 responses
                              29 views
                              1 like
                              Last Post BarzTrading  
                              Working...
                              X