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.
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!
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
NinjaTrader
Plots with Dashstyles
Collapse
X
-
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.Tags: None
-
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]); }
-
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
-
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
-
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
-
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
-
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(); }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by TheTradingMantis, 10-31-2017, 03:18 PM
|
5 responses
1,251 views
0 likes
|
Last Post
by TheAngryCube
Today, 04:06 PM
|
||
Started by Padan, Today, 02:02 AM
|
9 responses
23 views
0 likes
|
Last Post Today, 03:27 PM | ||
Started by spottysallrite, Today, 11:31 AM
|
7 responses
22 views
0 likes
|
Last Post Today, 03:26 PM | ||
Started by nandhumca, Today, 03:15 PM
|
1 response
4 views
0 likes
|
Last Post Today, 03:23 PM | ||
Started by PopovDS, 03-11-2024, 12:49 PM
|
3 responses
17 views
0 likes
|
Last Post
by PopovDS
Today, 03:16 PM
|
Comment