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

Plots with Dashstyles

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

    Plots with Dashstyles

    Hi,

    It appears that a plot can only have one dash style. Is it possible to dynamically change the dash style of a plot based on bar conditions? Or stated differently, can a plot have more than one dash style? Please advise. Thank you.

    #2
    Hello Zeos6,

    Thank you for your post.

    We would need to set the Pens for two separate plots in the Initialize() method and then color the plots transparent when the plot is not needed in the OnBarUpdate() method. I added an example below:
    Code:
            protected override void Initialize()
            {
    			Pen MyPen1 = new Pen(Color.Blue);
    			MyPen1.DashStyle = DashStyle.Dash;
    			Pen MyPen2 = new Pen(Color.Red);
    			MyPen2.DashStyle = DashStyle.Solid;
    
    			Add(new Plot(MyPen1, PlotStyle.Line, "Plot_ROC1"));
    			Add(new Plot(MyPen2, PlotStyle.Line, "Plot_ROC2"));
    			Overlay	 = false;
            }
    
            protected override void OnBarUpdate()
            {
    			if (CurrentBar <= Period) return;
    
    			if (Rising(ROC(Period)))
    			{
             		PlotColors[0][0] = Color.Blue;
    				PlotColors[1][0] = Color.Transparent;
    			}
    			else if (Falling(ROC(Period)))
    			{
    				PlotColors[0][0] = Color.Transparent;
    				PlotColors[1][0] = Color.Red;
    			}
    			
    			Values[0].Set(ROC(Period)[0]);
    			Values[1].Set(ROC(Period)[0]);
            }

    Comment


      #3
      Thank you PatrickH. I was wondering if we still had to do the two plot work around and the answer clearly is still yes. Thank you for letting me know. Appreciate the info.

      Comment


        #4
        Hi PatrickH

        The plot styles code you provided does not seem to work. In fact, the plot styles are not being added correctly. Maybe I am overlooking something here but see the following code. Simply put it in the Initialize and see how the plots get specified in the Property Grid.

        Pen aPen = new Pen(Color.FromKnownColor(KnownColor.Firebrick), 5);
        aPen.DashStyle = DashStyle.Solid;


        Pen lPen = aPen;
        lPen.Width =
        1;
        lPen.DashStyle = DashStyle.Dot;


        Add(
        new Plot(aPen, PlotStyle.Line, "AMarket"));
        Add(
        new Plot(lPen, PlotStyle.Line, "LMarket"));


        Thanks for your thoughts.

        Comment


          #5
          Hello Zeos6,

          Thank you for your response.

          When the indicator is first added to the chart it will set the Plots as we have them, then if we change the code and then press F5 to reload NinjaScript on our chart the plots do not change. We will actually need to right click in our chart after compiling the changes in our indicator--> select Indicators--> select the indicator added to our chart--> then select Remove--> Apply--> and then select the indicator again and then New--> OK. This should reload the indicator with the recent changes to the code.

          Comment


            #6
            HI PatrickH,

            I am not sure what you are saying here but I know how to compile and load an indicator to a chart. I have done as you suggested and the result is the same. Did you actually try the code I posted?

            Comment


              #7
              Hello Zeos6,

              Thank you for your response.

              I did not test your code, but I would ask the following concerning your code. Where are you placing your code? In the Initialize() method? Can you provide the full .cs file for review?

              The code I provided works on my end, please make sure to test the code I provided and advise if you see the behavior as you do with your code.

              Comment


                #8
                Thanks PatrickH. Your code does work as indicated. Hmmm. I will check my code once again. Thank you.

                Comment


                  #9
                  Hi PatrickH,

                  I have figured out the issue with my code which has led me to a general question about the use of Pens in NT. Since the Pen object is IDisposable it needs to be disposed in order to prevent resource leaks. Where are the pens created in the Initialize() section of the script disposed?

                  Comment


                    #10
                    Hello Zeos6,

                    Thank you for your response.

                    That is correct, the Pen would need to be disposed of. So we would need to define the Pens as variables in the variables section of the code and then dispose of them on termination:
                    Code:
                    		protected override void OnTermination()
                    		{
                    			myPen1.Dispose();
                    			myPen2.Dispose();
                    		}
                    For information on the OnTermination() method please visit the following link: http://www.ninjatrader.com/support/h...rmination2.htm

                    Comment


                      #11
                      Thanks for confirming PatrickH. I thought so - and I had done so.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by helpwanted, Today, 03:06 AM
                      1 response
                      13 views
                      0 likes
                      Last Post sarafuenonly123  
                      Started by Brevo, Today, 01:45 AM
                      0 responses
                      11 views
                      0 likes
                      Last Post Brevo
                      by Brevo
                       
                      Started by aussugardefender, Today, 01:07 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post aussugardefender  
                      Started by pvincent, 06-23-2022, 12:53 PM
                      14 responses
                      242 views
                      0 likes
                      Last Post Nyman
                      by Nyman
                       
                      Started by TraderG23, 12-08-2023, 07:56 AM
                      9 responses
                      387 views
                      1 like
                      Last Post Gavini
                      by Gavini
                       
                      Working...
                      X