PDA

View Full Version : A problem with an indicator.


MGDavid
07-19-2007, 08:36 AM
Hi all,

I'm a beginner with ninjaScript and i am trying to develop a simple indicator:
I need that :
If the close[0] is greater that close [1] ------>Indicator value = Close [0] and Remember this close
If the close[0] is not greater that close [1]----> indicator value = Remember.

I am trying this code...
__________________________________________________ _______

double remember = 0;

If (Close[0] > Close[1])
{
Plot0.Set(Close[0]);
Remember = (close[0]); -------- > I need that this variable remember this Close !.
}
else
{
Plot0.set(Remember);
}
__________________________________________________ _______
If i write this code the indicator values will be “ close” or “0” but do not remember the last close when the sentence is false

Does anyone have an example script that shows how to remember values ?.
I need that the indicator remember that close.

Sorry for my english and thanks for your help.


Regards

NinjaTrader_Ray
07-19-2007, 08:42 AM
You need to create a variable whose scope (liftime) is that of the indicator.

Under the variables section of the indicator add:

private double remember = 0;

then your code would look like:

if (Close[0] > Close[1])
{
Plot0.Set(Close[0]);
remember = Close[0];
}
else
{
Plot0.Set(remember);
}

NinjaTrader_Dierk
07-19-2007, 08:50 AM
Also: make sure you add code like this:

if (CurrentBar < 1)
return;

MGDavid
07-19-2007, 09:05 AM
Yeah !
Now! ,the indicator is working very well !
Thanks a lot for your help Ray and thanks for your time.:)
This support is fantastic !

Regards