The problem is that it always draws the most recent bars corona on all past bars. I have tried several different methods of drawing it with no success so I figured I would post the code here and see if anyone with more custom drawing experience can figure it out.
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
GDI problem - Ehlers Corona Indicators
Collapse
X
-
GDI problem - Ehlers Corona Indicators
I am trying to port Ehlers Corona Indicators to NT, have them very near complete but I cannot get the coronas to draw properly.
The problem is that it always draws the most recent bars corona on all past bars. I have tried several different methods of drawing it with no success so I figured I would post the code here and see if anyone with more custom drawing experience can figure it out.Tags: None
-
here is the relevant drawing code from plot override.
Code:int bars = ChartControl.BarsPainted, index; bars = CalculateOnBarClose ? (ChartControl.BarsPainted - 2) : (ChartControl.BarsPainted - 1); double x1, y1, y2; double vscale = bounds.Height / ChartControl.MaxMinusMin(max, min); Exception caughtException; while (bars >= 0) { //index = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + bars; index = ((ChartControl.LastBarPainted - ChartControl.BarsPainted) - 1) + bars; if (ChartControl.ShowBarsRequired || ((index - base.Displacement) >= base.BarsRequired)) { try { x1 = // horizontal position of bar to plot (((ChartControl.CanvasRight - ChartControl.BarMarginRight) - (barPaintWidth / 2)) - ((base.ChartControl.BarsPainted - 1) * base.ChartControl.BarSpace)) + (bars * (base.ChartControl.BarSpace)); for (int i = 11; i < 60; ++i) { double v = (i+1)/2; y1 = (bounds.Y + bounds.Height) - (int)((v + 1.5 - min) * vscale + 0.5); y2 = (bounds.Y + bounds.Height) - (int)((v - min) * vscale + 0.5); SolidBrush brush = new SolidBrush(_colors[(int) Math.Round(_filters[index-1][i].dB[0])]); graphics.FillRectangle(brush, new Rectangle((int)x1 - barPaintWidth / 2, (int)y2, barPaintWidth, (int)Math.Abs(y1 - y2))); } } catch (Exception exception) { caughtException = exception; } } bars--; } graphics.SmoothingMode = smoothingMode;
Comment
-
No there is 48 horizontal colored lines per bar, they are plotting correctly.
The issue is that once the bar changes, all past bars on the chart show the 48 colors assigned to the CurrentBar, rather than the colors that go with that bar.
I have tried adding 48 plot objects which all contain horizontal lines and coloring them in the plot method but couldn't get that to work either, and it is much more resource intensive than using graphics.FillRectangle() so it wouldn't be a good solution anyways.
On this pdf you can see how it is supposed to look:
Comment
-
sefstrat, did you already take at look at this from the sharing section? http://www.ninjatrader-support2.com/...endline&desc=1BertrandNinjaTrader Customer Service
Comment
-
Tomas, sorry the code is somewhat convoluted because I have been experimenting with different drawing techniques but I am pretty certain it is correct.
Bertrand, yes I have seen TLFit and consulted it while writing this drawing code. Unfortunately however, TLFit does not draw properly on my computer either (it has the exact same problem, all bars show the fit of currentbar).
That is one thing I find confusing since obviously TLFit worked before (based on the screenshot from when it was posted), has there been any changes to NT drawing code since then that would affect this?
Can you try TLfit on your machine and see if it works properly?
Comment
-
Hi sefstrat,
it seems that i was right. The problem appeared during clonning. When changing line
_filters[CurrentBar] = (FilterBank[])_filters[CurrentBar - 1].Clone();
to
FilterBank[] b = new FilterBank[60];
for (int n = 11; n < 60; n++)
b[n] = (FilterBank)_filters[CurrentBar - 1][n].Clone();
_filters[CurrentBar] = b;
it starts to work as expected.
Tomas
Comment
-
Thanks Tomas, you are the man.
I implemented ICloneable to make it easier to debug the drawing code, apparently that didn't work out so well.
The fact that TLFit was doing the same thing made me a little too certain the problem wasn't with my code, still not sure why TLFit doesn't work for me but no matter.
Later this afternoon I will finish the rest of the corona indicators and post them here. =)
(And yes I will use the correct line color in the final product eDanny )
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
4 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment