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 03-16-2009, 08:40 AM   #1
marketmasher
Member
 
Join Date: Sep 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
Default Making SampleMultiColoredPlot Generic

If I replace the hard-coded SMA(Period) with Value.Set(SMA(Period)[0]); first, and then try to substitute the "Value" reference for the SMA(Period) condition for the coloring of the plots, it stops working. I've tried different combos, but nothing seems to work - it either ignores the color changes or plots nothing. My goal is to make the coloring code portion generic with the Values set for it above the conditions.
marketmasher is offline  
Reply With Quote
Old 03-16-2009, 09:02 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Hi marketmasher, not sure what you are trying to achieve, can you please post the code you already have? You would still need 3 Plots for every color you wish to use and link to those to your dataseries objects (Values[0], Values[1], Values[2])
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-16-2009, 10:10 AM   #3
marketmasher
Member
 
Join Date: Sep 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
Hi marketmasher, not sure what you are trying to achieve, can you please post the code you already have? You would still need 3 Plots for every color you wish to use and link to those to your dataseries objects (Values[0], Values[1], Values[2])
Thanks for the response. Basically I am trying to make it so I can substitute any Data Series into the mulit-color plot, but in this case I 1st tried to just generalize what SampleMultiColorPlot is doing, trying to make the Value series hold the result of SMA(Period) - which I could then replace to get the coloring effect on any other calc.

{
// Checks to make sure we have at least 1 bar before continuing
if (CurrentBar < 1)
return;
Value.Set(SMA(Period)[0]); // Try to make this calc part interchangeable with another calc later...
// Plot green if the SMA is rising
// Rising() returns true when the current value is greater than the value of the previous bar.
if (Rising(Value))
{
// Connects the rising plot segment with the other plots
RisingPlot.Set(1, Value[1]);

// Adds the new rising plot line segment to the line
RisingPlot.Set(Value[0]);
}

// Plot red if the SMA is falling
// Falling() returns true when the current value is less than the value of the previous bar.
else if (Falling(Value))
{
// Connects the new falling plot segment with the rest of the line
FallingPlot.Set(1, Value[1]);

// Adds the new falling plot line segment to the line
FallingPlot.Set(Value[0]);
}

// Plot yellow if the SMA is neutral
else
{
// Connects the neutral plot segment with the rest of the line
NeutralPlot.Set(1, Value[1]);

// Adds the new neutral plot line segment to the line
NeutralPlot.Set(Value[0]);
}
marketmasher is offline  
Reply With Quote
Old 03-16-2009, 10:46 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

marketmasher,

Like Bertrand mentioned, you need three plots. Value[] only references the first plot or whichever plot is assigned to Values[0].

You need to make your own DataSeries to store your calculation. Your current code is likely trying to set RisingPlot.Set() and then take Value.Set(). They are referencing the same Values[0].
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-16-2009, 10:47 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Ok now I follow you, please check this zip - I guess it implements what you look for.
Attached Files
File Type: zip GenMultiColorPlot.zip (3.9 KB, 14 views)
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-16-2009, 11:36 AM   #6
marketmasher
Member
 
Join Date: Sep 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
Ok now I follow you, please check this zip - I guess it implements what you look for.

Aces! Thank you. I guess I can't use the Value series that gets created with the Plot for this and have to create a dataseries.
marketmasher 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
generic classes and functions majkie General Programming 2 08-29-2008 07:17 PM
Generic class syntax checker problem Rollins General Programming 1 06-11-2008 10:35 PM
Generic Indicator Overlay on price monpere Indicator Development 9 04-17-2008 05:26 AM
SampleMultiColoredPlot.zip Mike Winfrey Indicator Development 4 01-23-2008 08:58 AM
Using C#.Net 2.0 Generic Lists in NinjaScript whitmark Strategy Development 1 10-08-2007 07:08 AM


All times are GMT -6. The time now is 07:36 PM.