NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-14-2008, 05:26 AM   #1
Lambo
Junior Member
 
Join Date: Aug 2008
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default Color Plotting

I can't seem to get multiple color on my plot. It will plot in one color only instead of changing based on the LR0 and LR1 values. I've included the code below. Can anyone point me in the right direction?

------------------------------

Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));

...

if (LR0 > LR1)
{
Plots[
0].Pen = new Pen(Color.Green);
}
if (LR0 < LR1)
{
Plots[
0].Pen = new Pen(Color.Red);
}
if (LR0 == LR1)
{
Plots[
0].Pen = new Pen(Color.Orange);
}

Plot0.Set (LR0);
Lambo is offline  
Reply With Quote
Old 08-14-2008, 07:14 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Plots can only have one color so you will have to employ an approach where you use two plots. Following is a referenfce sample that will show you just how to do that.

http://www.ninjatrader-support.com/v...ead.php?t=3227
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-14-2008, 12:02 PM   #3
Lambo
Junior Member
 
Join Date: Aug 2008
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default

I used the suggested code almost verbatim. It is included below. I now get errors:
"The name "RisePlot" does not exist in the current context.
Cannot apply indexing with [] to an expression of type 'double'

-------------

protectedoverridevoid Initialize()
{
Add(
new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Rise"));
Add(
new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Fall"));
Add(
new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "Neutral"));
CalculateOnBarClose =
false;
Overlay =
false;
PriceTypeSupported =
false;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
....if (LR0 > LR1)
{
RisePlot.Set(
1, LR0[1]);
RisePlot.Set(LR0[
0]);
}

}
Lambo is offline  
Reply With Quote
Old 08-14-2008, 12:20 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Replace RisePlot with:

Value.Set(1, LR0[1]);
Value.Set(LR0[
0]);
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-14-2008, 02:27 PM   #5
Lambo
Junior Member
 
Join Date: Aug 2008
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default

Ray, I've done a lot of coding in my life and this language has got to be the most esoteric and confusing one I have ever run across.

I don't understand what Value.Set does or how that will let me plot different colors based on rise, fall and neutral.

Also, there must be some very subtle but strict structure necessary because now I go back to create a new version and just typing an "If" statement causes it to declare that a ";" is expected, but I'm using exactly the same statements I used earlier with success. Further to my point, I used the same statements that the example multi-color plot program used, but I get the errors I noted earlier. Goofy stuff, it is. Sigh.
Lambo is offline  
Reply With Quote
Old 08-14-2008, 02:49 PM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

You can tell Bill Gates that you don't like C#!

On a serious note, have you checked out our Indicator tutorials in the Help Guide?
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-14-2008, 03:20 PM   #7
Lambo
Junior Member
 
Join Date: Aug 2008
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default

Touche'

By the way, I think he is no longer with Microsoft (except of course for owning the company).

I'll check it out.

Thanks,
Paul
Lambo is offline  
Reply With Quote
Old 08-29-2008, 03:02 PM   #8
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

Quote:
Originally Posted by Lambo View Post
if (LR0 > LR1)
{
Plots[0].Pen = new Pen(Color.Green);
}
I just want to point out that the property Plots[x].Pen.Color is a useful way to access color x of a multi-color indicator. If you have a bunch of different colors, you will need a bunch of different plots. If you want to change the color of a price bar when one particular color (say for plot i) appears in the indicator, then

BarColor = Plots[i].Pen.Color;

...will do the trick. It's a nice way to combine an indicator and a paintbar into the same indicator.

-Alex
Last edited by anachronist; 08-29-2008 at 06:56 PM.
anachronist is offline  
Reply With Quote
Old 08-29-2008, 03:27 PM   #9
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

Quote:
Originally Posted by Lambo View Post
Ray, I've done a lot of coding in my life and this language has got to be the most esoteric and confusing one I have ever run across.
Actually, your reference to RisePlot didn't work because you didn't create any plot by that name. Instead, you created a plot called Rise. If you didn't create the code template through the Wizard (and I suggest you do this for better understanding), then you will have to create a definition of Rise and its return value in the properties block.
Quote:
I don't understand what Value.Set does or how that will let me plot different colors based on rise, fall and neutral.
All of these are synonymous: Values[0].Set(x), Values[0][0] = x, Rise.Set(x), Rise[0] = x (assuming that Rise is your first [index 0] plot). Sometimes it's convenient to set multiple plot values inside a loop, in which case you can use the Values[] array instead of referencing each individual plot by name. Note Values[] is plural, not singular Value. The singular word refers only to the first plot, I think.
Quote:
Goofy stuff, it is. Sigh.
I suggest starting over with the Wizard to define all your inputs and plots, and then look at what it did in the properties block at the end of the code. After you do this enough times, you'll know what is expected when you code indicators by hand, or if you need to add or delete parameters or plots from the indicator.

-Alex
Last edited by anachronist; 08-29-2008 at 03:31 PM.
anachronist is offline  
Reply With Quote
Old 08-29-2008, 03:46 PM   #10
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Thanks for the comments Alex, helpful.
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom plotting bobajob78 General Programming 5 04-09-2008 01:04 PM
Plotting the bid/ask lurkerlurker NinjaScript File Sharing Discussion 3 04-01-2008 03:59 PM
Plotting Bid and Ask volumes fishbed Indicator Development 1 12-07-2007 10:57 AM
Indicator not plotting Burga1 Indicator Development 11 12-06-2007 02:26 PM
PLOTTING THE BID camelcom Charting 1 04-05-2006 12:36 AM


All times are GMT -6. The time now is 08:32 PM.