NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 10-30-2006, 06:45 AM   #1
MAX
Senior Member
 
Join Date: Sep 2006
Location: Rome, , Italy
Posts: 131
Thanks: 2
Thanked 1 time in 1 post
Post imported post

I'd like to plot and indicator for trend.
If a certain condition is met then the trend is up and the indicator plots 1, otherwise, if another condition is met the the trend is down and the indicator plots -1.

Following is the code:

if (CurrentBar < Barre1)
return;
if (Close[0] > MAX(High, Barre1)[1])
{
Plot0.Set(1);
}

if (Close[0] < MIN(Low, Barre1)[1])
{
Plot1.Set(-1);
}

The problem is that there are empty spaces but I'd like to have the previous value (1 or -1) until the trend does not change.

How can I write the code to plot the previous value and have a continuous indicator?

Thanks for any help.
MAX is offline  
Reply With Quote
Old 10-30-2006, 07:30 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
Post imported post

Usea variableto store the current trend value. Declare the variable under the variables section:

private double trend = 1;

Then in the OnBarUpdate():

if (CurrentBar < Barre1)
return;

if (Close[0] > MAX(High, Barre1)[1])
trend = 1;
else if (Close[0] < MIN(Low, Barre1)[1])
trend = -1;

Plot1.Set(trend);


Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-30-2006, 10:19 PM   #3
MAX
Senior Member
 
Join Date: Sep 2006
Location: Rome, , Italy
Posts: 131
Thanks: 2
Thanked 1 time in 1 post
Post imported post

Perfect.

Now is working fine.

Thanks very much.
MAX 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


All times are GMT -6. The time now is 02:52 PM.