|
Raleigh, USA
Posts: 3 since May 2011
Thanks Given: 0
Thanks Received: 1
|
I’m new to Ninjatrader and have really struggled with coding thus far but trying to learn it. I want to write code into the attached Ninjascript that will signal a BUY arrow on the oscillator when the following conditions occur:
REI line below -40 for 6 or fewer consecutive bars AND
Close[1] < Close[2] AND
Open [0] <= High[1] and High[2] AND
(High[0] > High[1]) OR (High[0] > High[2]) AND High[0]>Open[0]
I also want it to cancel the above BUY condition signal if the following occurs:
REI line below -40 for 7 or more consecutive bars
Can someone help me with this?
///<summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
///</summary>
protectedoverridevoid Initialize()
{
Add(new Line(Color.Blue, -45, "Lower"));
Add(new Line(Color.Blue, 45, "Upper"));
Add(new Plot(Color.LimeGreen, "DeMarkREI_Plot_Up"));
Add(new Plot(Color.Red, "DeMarkREI_Plot_Down"));
rei = new DataSeries(this);
}
///<summary>
/// Calculates the indicator value(s) at the current index.
///</summary>
protectedoverridevoid OnBarUpdate()
{
if (CurrentBar>period)
{
double SUM=0;
double SUMABS=0;
double DeMarkREI=0;
double TDREI=0;
for(int x=0; x<period; x++)
{
SUM += ((High[x]-High[x+2])+(Low[x]-Low[x+2]));
SUMABS += (Math.Abs(High[x]-High[x+2])+Math.Abs(Low[x]-Low[x+2]));
}
if (SUMABS>0) DeMarkREI=SUM/SUMABS;
TDREI=100*DeMarkREI;
rei.Set(TDREI);
if (Rising(rei))
{
if (!wasRising) DeMarkREI_Plot_Rising.Set(1,rei[1]);
DeMarkREI_Plot_Rising.Set(TDREI);
wasRising=true;
}
else
{
if (wasRising) DeMarkREI_Plot_Falling.Set(1,rei[1]);
DeMarkREI_Plot_Falling.Set(TDREI);
wasRising=false;
}
}
}
#region Properties
///<summary>
///</summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries DeMarkREI_Plot_Rising
{
get { return Values[0]; }
}
///<summary>
///</summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries DeMarkREI_Plot_Falling
{
get { return Values[1]; }
}
///<summary>
///</summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries DeMarkREI_Values
{
get { return rei; }
}
[Description("Number of bars to calculate")]
[Category("Parameters")]
publicint Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
|