PDA

View Full Version : Brush filling


cclsys
08-17-2009, 12:30 PM
I am trying to figure out the following but after quite some time have got nowhere:

Take the Donchian Channel:

If condition X

paint a backcolor only between the Donchians (something which can be done for sure)

else

Don't paint anything.

I have samples of brush filling but both involve continuously painting between two Values but alternating colors based on a crossover. I am simply too dense to extrapolate the basic brush filling commands from the crossover conditions. (The samples are Slingshot and IchiCloud from the shared section).

I would be very grateful is someone could provide an example of brushfilling between the Donchians with a condition. From there I can figure it out - and also share the results.

The goal is to create a trading range fill when the range narrows and stabilizes. I can already do this fine with back color but I would prefer to have it painted only between the Donchians rather than the whole screen. Small thing, but nice to get right and also opportunity to learn more about coding in Ninja.

Thanks in advance.

NinjaTrader_Bertrand
08-17-2009, 12:39 PM
cclsys, unfortunately I'm not aware of sample code for this. Have you tried setting the fillcolor to transparent when there's no range being formed according to your conditions?

You could also play around with different opacity settings for this.

http://www.ninjatrader-support.com/HelpGuideV6/DrawRegion.html

cclsys
08-17-2009, 01:00 PM
cclsys, unfortunately I'm not aware of sample code for this. Have you tried setting the fillcolor to transparent when there's no range being formed according to your conditions?

You could also play around with different opacity settings for this.

http://www.ninjatrader-support.com/HelpGuideV6/DrawRegion.html

Bernard: you are way ahead of me. I can't figure out how to set the fill color between two points in the first place. I can do a back color for the whole screen easily enough, but trying to do a fill I got nowhere. I couldn't find anything in the help menus, even referencing the brush code. My only samples are for filling in two lines and changing when the crossover, which in the coding is quite complex. I am unable to figure out which part of the code is the simple brush fill aspect and which deals only with the crossover conditions. So I am hoping for an example of simple fill code, i.e. filling between two MA's, or as I have suggested: two Donchian lines (i.e. the upper and lower plots). From there I am sure I can figure it out.

Opacity is a later issue but of course one can simply choose pale colors if necessary. Thxs.

Not that it means much, but I attach a pic of the back color trading range formulation in operation (back color is Salmon). I would prefer that the color remain within, and change along with, the upper and lower Donchians which is one aspect of the code used to determine whether or not the mkt is in trading range type action.

NinjaTrader_Bertrand
08-17-2009, 01:17 PM
cclsys, it's perhaps best when you check out the Standard Error Bands indicator I posted some time ago to the sharing, it's filling the areas betweens the different bands - http://www.ninjatrader-support2.com/vb/local_links.php?action=jump&id=150&catid=1

cclsys
08-17-2009, 03:06 PM
cclsys, it's perhaps best when you check out the Standard Error Bands indicator I posted some time ago to the sharing, it's filling the areas betweens the different bands - http://www.ninjatrader-support2.com/vb/local_links.php?action=jump&id=150&catid=1

Thanks. I could not find the DrawRegion by looking for things like 'brush', 'fill', 'color' etc. So that is very helpful.

Now I have added it in but it ignores my condition - which works fine in an above section of code as shown in an attached pic - and simply paints between Upper and Lower for long periods of time, or not at all for some reason, but neither spot seems to have anything to do with the code.

Again, the condition
if ((ExtendUp[0] >= ExtendDown[0]) )

works fine (I have been using it for months). But DrawRegion doesn't regard it as kosher for some reason.

Also changing it to:

"if (lRoption && ExtendUp[0] < ExtendDown[0])
return;
if (lRoption && ExtendUp[0] >= ExtendDown[0])

{DrawRegion("Trading Range", CurrentBar, 0, Upper, Lower, Color.Empty, Color.Salmon, 5);}
"

makes no difference. It just fills all the time between the Donchians.

NinjaTrader_Bertrand
08-17-2009, 03:24 PM
From the chart you posted it seems like the condition works properly but the upper and lower values you enter as boundaries are not properly used. Please check those and ensure the correct ones are entered in the DrawRegion call.

cclsys
08-17-2009, 04:00 PM
From the chart you posted it seems like the condition works properly but the upper and lower values you enter as boundaries are not properly used. Please check those and ensure the correct ones are entered in the DrawRegion call.

I am not sure I understand but all I can say in reply is that Upper and Lower are two Plot Series that represent the Upper and Lower Donchians and plot accurately. They are Upper.Set and Lower.Set, they plot fine etc.

Is that not correct, therefore? Also, when it does plot, it plots those values perfectly. The problem is that it does not start or stop plotting based on the condition. The values seem not to be the issue.

cclsys
08-17-2009, 04:04 PM
For example, I have made a new version of your St Error Smooth and added the following at the end:

//assign plotted values to the DataSeries objects
Middle.Set(lrSeries[0]);
Upper.Set(lrSeries[0] + WidthMiddle * erSmo);
Lower.Set(lrSeries[0] - WidthMiddle * erSmo);
Upper2.Set(lrSeries[0] + WidthOuter * erSmo);
Lower2.Set(lrSeries[0] - WidthOuter * erSmo);

//fill the 2 sets of bands with color and allow for custom opacity level for both
//DrawRegion("StdErrorSmooth1", CurrentBar, 0, Lower2, Lower, Color.Empty, LowerColor, OpacityOuter);
//DrawRegion("StdErrorSmooth2", CurrentBar, 0, Lower, Upper, Color.Empty, MiddleColor, OpacityMiddle);
//DrawRegion("StdErrorSmooth3", CurrentBar, 0, Upper, Upper2, Color.Empty, UpperColor, OpacityOuter);

if ( (DLR(2000,true,27).ExtendUp[0]) >= (DLR(2000,true,27).ExtendDown[0]))
DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Salmon, OpacityOuter);
//else
//DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);
//RemoveDrawObject("StdErrorSmooth1");

++++++++

Even if I write it this way it still plots all the time no matter what:

if ( (DLR(2000,true,27).ExtendUp[0]) >= (DLR(2000,true,27).ExtendDown[0]))
DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Salmon, OpacityOuter);
if ( (DLR(2000,true,27).ExtendUp[0]) < (DLR(2000,true,27).ExtendDown[0]))
DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);

In all cases, the result is that it plots between your Upper2 and Lower2 all the time and ignores the condition. It's exactly the same problem I have with my Donchian one. Can't get it to respond to condition. Adding in RemoveDrawObject makes not the slightest difference even though I know for a fact that the condition is not always true. Also, clearly the values work since the plots are accurate (in both indicators), just not their on-offing.

NinjaTrader_Bertrand
08-17-2009, 04:05 PM
cclsys, if you refer to the chart you posted, it does seems to respect the condition you have set...it would be easiest if you can attach the full source code so I can plot this on my end here to check, thanks

cclsys
08-17-2009, 04:11 PM
cclsys, if you refer to the chart you posted, it does seems to respect the condition you have set...it would be easiest if you can attach the full source code so I can plot this on my end here to check, thanks

Sorry. I thought I had attached code earlier. Here it is again.

cclsys
08-17-2009, 04:13 PM
If you prefer, here is your standard error with fill and with my conditions for my Donchians. But if you can insert any simple condition that turns the filling-in on and off, that would be most helpful.

cclsys
08-18-2009, 07:00 AM
In my inbox I received the following msg from Bertrand but don't see it on the thread:

"cclsys, unfortunately I'm not aware of sample code for this. Have you tried setting the fillcolor to transparent when there's no range being formed according to your conditions?"

In the StdErrorFill code above I have:

if ( (DLR(2000,true,27).ExtendUp[0]) >= (DLR(2000,true,27).ExtendDown[0]))
DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Salmon, OpacityOuter);
if ( (DLR(2000,true,27).ExtendUp[0]) < (DLR(2000,true,27).ExtendDown[0]))
DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);

It plots always between the two lines ExtendUp and ExtendDown correctly, but does not plot empty when the condition is nullified, just keeps plotting.

I also tried:
else
DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);

and also tried:
else
RemoveDrawObject("StdErrorSmooth1");

The result is always the same: it plots between the two lines all the time.

NinjaTrader_Bertrand
08-18-2009, 07:22 AM
cclsys, please check the attached file out, it shows how to achieve this with an opacity setting of 0.

cclsys
08-18-2009, 09:56 AM
Well it paints one way (the first condition), but not the other. This is better, but similar to my problem except mine paints all the time versus only painting during the first condition whereas yours doesn't paint the second condition but at least stops painting the first condition. I tried moving the lingo over but now I get no painting all of the time. But before when it painted, it was painting the correct values, so I know the values are correct. Mystery!

Then I remembered the log!

The log error reads:

Error on calling the 'OnBarUpdate' method for indicator 'StdErrFill' on bar 0: StdErrFill.DrawRegion: startBarsAgo out of valid range 0 through 0
I don't know what this means but I added in the condition
if (CurrentBar < Period) return;
that was the problem.

Now it works fine.

I have learned a lesson: always check the log. This has been suggested before but since most of the time when I have problems there are no log errors, I have not got in the habit of checking it. Lesson learned.

NinjaTrader_Bertrand
08-18-2009, 10:02 AM
cclsys, what this script does it this, if the Condition is true it paints a DrawRegion with opacity of 10, if it's not true it paints another DrawRegion with opacity of 0 > so essentially it's not displaying. So I believe you can create your 'range' coloring with this workaround.

cclsys
08-18-2009, 10:16 AM
The problem had to do with the post I put in just as yours came in. There was nothing wrong with the coding of the DrawRegion all along. It was something else altogether.

That said, thanks for exaplaining about the stochastic spread. I missed that Opacity of 0 would mean that it didn't display. In any case, it's now working fine, pic attached.

Not that this is vitally important - again learning how to code is more the point here - but the idea behind this was to highlight the trading range (between the Donchians) once it narrows without coloring the entire screen so as to a) keep the overall trend in mind visually and b) highlight the specific range area and also c) if that range is protracted and starts narrowing, this will show clearly on the chart so the breakout levels become more pronounced than when the entire screen is (in my case) pink.

Thanks to all.

Have now attached Donchian only version soon in case anyone else would find this of interest/helpful. Also pic showing this indicator alone in action.

NinjaTrader_Bertrand
08-18-2009, 10:24 AM
Great you have it figured out cclsys!

cclsys
08-18-2009, 10:43 AM
Great you have it figured out cclsys!


Thank you, Bernard, for helping me to figure it out. In retrospect I should have looked harder for Draw Region to start with. But since the filling code I had in a couple of different indicators used 100+ line brush commands, I just assumed no such method existed. I suspect it didn't when these codes were written.

Then I am still not sure what I was doing wrong when it painted all the time, but once you gave me a good sample, I I didn't pay proper attention to log errors to determine that the problem was not with the Drawline lingo but elsewhere.

Interesting that your StdError bands (impressive Lin Reg coding from scratch on your part) worked fine without the CurrentBar < X condition before, but with the condition added to DrawRegion it became a deal (or I should say code) breaker.

Anyway, thanks again.

NinjaTrader_Bertrand
08-18-2009, 10:59 AM
cclsys, you're welcome - any time you attempt to access bars not present in the data series objects this error would surface, so this tip will be helpful - http://www.ninjatrader-support2.com/vb/showthread.php?t=3170

My code did not attempt to do this, while your conditions did > just always an individual scenario.