This is surely some total basic question, but I am also total basic in Ninjascript. Your help would be appreciated.
I found in the resources that one should test for 0 after OnBarUpdate().
So I did with all variables like so:
if (CloseSetBear==0)
{
CloseSetBear=1;
}
else if (CloseSetBear!= 0)
return;
Still I get the same error message over again. Did I miss something, or is the code I use above wrong?
I checked all double variables you see in the code:
public class RSXDivergenceMarker : Indicator
{
private bool DIVBear;
private double CloseSetBear;
private double RSXSetBear;
private bool DIV2Bear;
private double CloseD_Bear;
private double RSXD_Bear;
private bool DIVBull;
private double CloseSetBull;
private double RSXSetBull;
private bool DIV2Bull;
private double CloseD_Bull;
private double RSXD_Bull;
private NinjaTrader.NinjaScript.Indicators.Jurik_Research. JRC_RSX JRC_RSX1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Uses RSX to mark momentum divergences on chart,";
Name = "RSXDivergenceMarker";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
RSX_Length = 15;
Over = 30;
OverD = 30;
OverD2 = 30;
Under = -30;
UnderD = -30;
UnderD2 = -30;
MarkerOffset = 5;
MarkerOffsetD2 = 5;
BarsLookback = 40;
MarkerOffsetNegative = -5;
MarkerOffsetNegativeD2 = -5;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
// Set 1
if ((JRC_RSX1[2] < JRC_RSX1[1])
&& (JRC_RSX1[1] > JRC_RSX1[0])
&& (JRC_RSX1[0] > Over))
{
DIVBear = true;
CloseSetBear = Close[0];
RSXSetBear = JRC_RSX1[0];
Draw.ArrowDown(this, @"RSXDivergence Arrow down_1", true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
}
// Set 2
if ((JRC_RSX1[2] < JRC_RSX1[1])
&& (JRC_RSX1[1] > JRC_RSX1[0])
&& (JRC_RSX1[0] > OverD)
&& (DIVBear == true)
&& (Close[0] > CloseSetBear)
&& (JRC_RSX1[0] < RSXSetBear))
{
CloseD_Bear = Close[0];
RSXD_Bear = JRC_RSX1[0];
Draw.Diamond(this, @"RSXDivergence Diamond_1", true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
DIV2Bear = true;
Alert(@"RSXDivergence_1", Priority.Medium, @"Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.GreenYellow, Brushes.Black);
}
// Set 3
if ((JRC_RSX1[2] < JRC_RSX1[1])
&& (JRC_RSX1[1] > JRC_RSX1[0])
&& (JRC_RSX1[0] > OverD2)
&& (DIV2Bear == true)
&& (Close[0] > CloseD_Bear)
&& (JRC_RSX1[0] < RSXD_Bear))
{
Draw.Diamond(this, @"RSXDivergence Diamond_1", true, 0, (High[0] + (MarkerOffsetD2 * TickSize)) , Brushes.Gold);
Alert(@"RSXDivergence_1", Priority.High, @"Double Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Red, Brushes.Black);
Draw.Diamond(this, @"RSXDivergence Diamond_1", true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
}
// Set 4
if ((JRC_RSX1[2] > JRC_RSX1[1])
&& (JRC_RSX1[1] < JRC_RSX1[0])
&& (JRC_RSX1[0] < Under))
{
DIVBull = true;
CloseSetBull = Close[0];
RSXSetBull = JRC_RSX1[0];
Draw.ArrowUp(this, @"RSXDivergence Arrow up_1", true, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
}
// Set 5
if ((JRC_RSX1[2] > JRC_RSX1[1])
&& (JRC_RSX1[1] < JRC_RSX1[0])
&& (JRC_RSX1[0] < UnderD)
&& (DIVBull == true)
&& (Close[0] < CloseSetBull)
&& (JRC_RSX1[0] > RSXSetBull))
{
DIV2Bull = true;
CloseD_Bull = Close[0];
RSXD_Bull = JRC_RSX1[0];
Draw.Diamond(this, @"RSXDivergence Diamond_4", false, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
Alert(@"RSXDivergence_1", Priority.Medium, @"Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.GreenYellow, Brushes.Black);
}
// Set 6
if ((JRC_RSX1[2] > JRC_RSX1[1])
&& (JRC_RSX1[1] < JRC_RSX1[0])
&& (JRC_RSX1[0] < UnderD2)
&& (DIV2Bull == true)
&& (Close[0] < CloseD_Bull)
&& (JRC_RSX1[0] > RSXD_Bull))
{
Draw.Diamond(this, @"RSXDivergence Diamond_4", false, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
Draw.Diamond(this, @"RSXDivergence Diamond_4", false, 0, (Low[0] + (MarkerOffsetNegativeD2 * TickSize)) , Brushes.Gold);
Alert(@"RSXDivergence_1", Priority.High, @"Double Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Red, Brushes.Black);
}
Comment