PDA

View Full Version : Colored Support and Resistance Zones


CarlosAlberto
08-23-2007, 05:16 PM
I use the Constant Lines indicator to plot Support and Resistance lines. However a line is much too precise. An area of support (or resistance) may be from 0.5 to 2 points wide (in ES). Two contiguous line may not be easily visible in a busy chart. Thus, I wish to combine two immediate Constant Lines in a single S/R zone by giving them the same color and coloring (with transparency) the area in between the constant lines. There are examples of this in some indicators in the File Sharing Section (TRO Buy Zone, VWAP) but I am having problems in putting the indicator together. I am not a programmer and the painted and transparency/opacity section are in the properties section of the code and I do not know how too handle that. I can do minor modifications in the main code and I expect learn more in due time. Could someone provide guidance and help
Thank you

NinjaTrader_Josh
08-23-2007, 05:26 PM
The coloring methods used in those indicators are more advanced techniques. Basically what you want to do is create two DataSeries. One for each of your lines. If you reference the indicators you mentioned already you will notice there is the following loop: for (int seriesCount = 0; seriesCount < 2; seriesCount++) What you want to do is just change the loop parameters to reflect which DataSeries you want to be coloring. In this example the space between DataSeries 0 and DataSeries 1 will be colored.

In essence, the color filling technique used follows the two lines and creates what is known as paths for each. It then fills in the space inbetween the two paths. The only modifying you need to do is to tell it which lines to create paths from.

NinjaTrader_Ray
08-23-2007, 06:51 PM
NT 6.5 will have a DrawRegion() method that will take care of this.

fragalles
07-09-2008, 06:06 AM
hello,

i have been using this method:
http://www.ninjatrader-support.com/vb/showthread.php?t=4331

to make a modification to the Dynamic Support and Resitance Indicator (see attachment) but when i load it on several charts and scroll back historical data my pc running vista locks the application and i am getting a low memory warning message.

The pc has 4 GB ram, i am just using 4 instruments with 14 days historical data, i think this should not be an issue, please correct the attached indicator if possible, but i think ninjatrader has a bug that simply does not allow extensive drawing methods like the draw region ...

regards
peter

NinjaTrader_Dierk
07-09-2008, 06:12 AM
We'll look into and will let you know.

NinjaTrader_Dierk
07-09-2008, 07:00 AM
There is a bug in your indicator code. Basically you are calling the indicator itself in your OnBarUpdate method of that indicator:

DrawRegion("Bollinger Upper Region", CurrentBar, 0, SupportAndResistance(55).Resistance, SupportAndResistance(55).Support, Color.Black, Color.Blue, 1);

-> infinite recursion

fragalles
07-09-2008, 07:22 AM
There is a bug in your indicator code. Basically you are calling the indicator itself in your OnBarUpdate method of that indicator:

DrawRegion("Bollinger Upper Region", CurrentBar, 0, SupportAndResistance(55).Resistance, SupportAndResistance(55).Support, Color.Black, Color.Blue, 1);

-> infinite recursion

According to the sample the drawregion should contain the top of the region (SupportAndResistance(55).Resistance) and after that the bottom of the region (SupportAndResistance(55).Support)

Can you send me the code snippet what i should be using instead to get a region drawn inbetween the DynamicSR indicators Resistance and Support line?

Thank you very much

NinjaTrader_Dierk
07-09-2008, 07:27 AM
Not sure I follow. Where in the sample code of SampleDrawRegion would see a recursive call of SampleDrawRegion (which is what you did on your code)?

Unfortunately we don't have any other sample at hard at this time. As last resort you could contact a certified NinjaScript consultant: http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm

fragalles
07-09-2008, 07:45 AM
There is a bug in your indicator code. Basically you are calling the indicator itself in your OnBarUpdate method of that indicator:

DrawRegion("Bollinger Upper Region", CurrentBar, 0, SupportAndResistance(55).Resistance, SupportAndResistance(55).Support, Color.Black, Color.Blue, 1);

-> infinite recursion

In the example is this line of code:
DrawRegion("tag1", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Lime, 2);

So i simply exchanged Bollinger.Upper with my indicator and its resistance
data series... (using attached indicator as a base from where to start my own indicator)

Maybe i misunderstand something, so maybe i should reference to the original DynamicSR indicator rather than putting every logic and draw function into a new indicator?

NinjaTrader_Dierk
07-09-2008, 07:48 AM
Try
DrawRegion("tag1", CurrentBar, 0, Resistance, Support, Color.Empty, Color.Lime, 2);

fragalles
07-09-2008, 07:59 AM
Try
DrawRegion("tag1", CurrentBar, 0, Resistance, Support, Color.Empty, Color.Lime, 2);

This works, great, thank you very much

sub5mango
07-10-2008, 04:29 AM
hi

I am trying to use the DrawRegion like this:
DrawRegion("fill", CurrentBar, 0, 1253, 1253, Color.Empty, Color.Lime, 2);
I just want to fill between two price values across the chart but I keep getting compile errors.

What section of the code do I put the DrawRegion?

Can I use just numbers?

NinjaTrader_Dierk
07-10-2008, 04:50 AM
No you can't. One argument has to be a series.
http://www.ninjatrader-support.com/HelpGuideV6/DrawRegion.html

sub5mango
07-10-2008, 05:00 AM
Hi Dierk,

so I am using the constant line indicator and I want to color between two lines so I use this line in the section

protectedoverridevoid OnBarUpdate()

DrawRegion("fill", 0, CurrentBar, Line1Value, Line2Value, Color.Black, Color.Khaki, 2);

Line1Value and Line2Value are both DataSeries right, created by the Add?

But it still won't compile.

NinjaTrader_Dierk
07-10-2008, 05:04 AM
I can't tell by your code snippet if LineValue1/2 are of type IDataSeries.

Please
a) consult the doc link I posted
b) check your code on the type of LineValue1/2
c) and take a close look at the compile error message.

This should provide you an idea what's going wrong.

sub5mango
07-10-2008, 11:11 AM
Hi Dierk

Thanks for the references and I think these are data series, am I wrong?
Heres the code.

protectedoverridevoid Initialize()
{
Add(new Plot(Color.Red, PlotStyle.Line, "Line1"));
Add(new Plot(Color.Red, PlotStyle.Line, "Line2"));

}
protectedoverridevoid OnBarUpdate()
{
if (Line1Value != 0) Line1.Set(Line1Value);
if (Line2Value != 0) Line2.Set(Line2Value);

DrawRegion("First", CurrentBar, 0, Line1, Line2, Color.Black, Color.Khaki, 2);

}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public DataSeries Line1
{
get { return Values[0]; }
}

//repeated for Line2

}

[Description("Line 1 value")]
[Category("Parameters")]
publicdouble Line1Value
{
get { return line1Value; }
set { line1Value = value; }
}

NinjaTrader_Dierk
07-10-2008, 11:15 AM
If you get an error, double click on the error message to see what's wrong.

davidwm88
07-23-2008, 09:00 PM
I am having a very difficult time with constructing this, if someone could show me the code for an example, it would be very useful and appreciated.

What would the code be to color the region between
y=11656 and
y=11676

NinjaTrader_Josh
07-23-2008, 10:15 PM
If what you want is to do a simple rectangle coloring I suggest you use DrawRectangle().

DrawRectangle("tag1", CurrentBar, 11676, 0, 11656, Color.Blue);

toddae
01-28-2009, 07:00 AM
What would the correct code be to have a custom rectangle that is plotted across a single day?

So, the inputs might be:

dim Topedge as double;
dim Bottomedge as double;
dim RectangleDate as ?;

// and the draw command would be something like:
// except i don't know how to set the left and right edges...
DrawRectangle("Rect", CurrentBar, Topedge, 0, Bottomedge, Color.Blue);

NinjaTrader_Josh
01-28-2009, 07:33 AM
DrawRectangle("Rect", Bars.BarsSinceSession, Topedge, 0, Bottomedge, Color.Blue);