PDA

View Full Version : Plotting variables


MAX
10-30-2006, 06:45 AM
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.

NinjaTrader_Ray
10-30-2006, 07:30 AM
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

MAX
10-30-2006, 10:19 PM
Perfect.

Now is working fine.

Thanks very much.