I have converted quite a few of my indicators from 7 to 8 but I have had problems with this one and wondered if anyone can help, please.
Here is a screenshot. The red dots are not correct and the blue dots dont even appear.
Here is the code
Ninjatrader8
#region Using declarations
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Reflection;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript.DrawingTools;
using NinjaTrader.NinjaScript.Indicators;
#endregion
// This namespace holds all indicators && is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
public class NewDelta : Indicator
{
#region Variables
// Wizard generated variables
private int risk = 3; // Default setting for Risk
private double moneyRisk = 1.500; // Default setting for MoneyRisk
// User defined variables (add any user defined variables below)
private int value1=1, value2=18, value3=9, value4=0, value20=70, value21=30, value8=1000000;
private int value41=0, value42=0, value7=0, value43=0, value44=0;
private double value5=0, value9=0, value10=0, value11=0, value12=1000000, value13=0, value14=1000000, value15=0, value16=0, value17=0, value18=0, value19=0;
private bool condition1=false, condition2=false;
#endregion
/// <summary>
/// This method is used to configure the indicator && is called once before any bar data is loaded.
/// </summary>
private void Initialize()
{
//Add(new Plot(Color.Green, PlotStyle.Dot, "BuyStop"));
AddPlot(new Stroke(Brushes.Blue), PlotStyle.Dot, "BuyStop3");
AddPlot(new Stroke(Brushes.Red), PlotStyle.Dot, "SellStop3");
AddPlot(new Stroke(Brushes.Cyan), PlotStyle.Block, "BOBuy");
AddPlot(new Stroke(Brushes.Magenta), PlotStyle.Block, "BOSell");
IsOverlay = true;
Calculate = Calculate.OnEachTick;
}
protected override void OnStateChange()
{
switch (State)
{
case State.SetDefaults:
Name = "NewDelta";
Description = "Enter the description of your new custom indicator here";
Initialize();
break;
}
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(CurrentBar < 10)
return;
if(CurrentBar == 10)
{
value20 = 67 + Risk;
value21 = 33 - Risk;
value1 = Risk;
value2 = 18 + value1 * 3;
}
double value17_1 = value17, value11_1 = value11, value12_1 = value12;
value18 = (Range()[0] == 0) ? SMA(StCminusC3(), 10)[0] : SMA(Range(), 10)[0];
//value19 = MoneyRisk * value18 * TickSize; //BIGPOINTVALUE TickSize
value19 = MoneyRisk * value18 * Instrument.MasterInstrument.PointValue;
value4 = value3;
value4 = (MRO(delegate { return Math.Abs(Open[0]-Close[1]) >= value18 * 2; }, 1, 9) > -1) ? 3 : value3;
value4 = (MRO(delegate { return Math.Abs(Close[3]-Close[0]) >= value18 * 4.600000; }, 1, 6) > -1) ? 4 : value3;
value15 = SMA(Close, 9)[0];
value16 = SMA(Close, value2)[0];
value17 = (MAX(High,value4)[0] - MIN(Low,value4)[0] != 0) ? 100 - (100 * (MAX(High,value4)[0] - Close[0])/(MAX(High,value4)[0] - MIN(Low,value4)[0])) : 0;
if(value17 > value20)
{
condition1 = true;
condition2 = false;
}
if(value17 < value21)
{
condition1 = false;
condition2 = true;
}
value5 = (Close[value1] < Median[0]) ? High[0] + Low[0] - Low[value1] : High[0] + Low[0] - High[value1];
if(value17_1 < value20 && value17 >= value20)
value13 = StTrueLow1()[0] - 0.100000 * Risk * value18;
if(value17_1 > value21 && value17 <= value21)
value14 = StTrueHigh()[0] + 0.100000 * Risk * value18;
if(Math.Abs(Open[0]-Close[1]) >= value18 * 1.618000)
{
if(value17_1 < value20 && value17 >= value20)
value13 = Low[0] - 0.100000 * Risk * value18;
if(value17_1 > value21 && value17 <= value21)
value14 = High[0] + 0.100000 * Risk * value18;
}
value9 = (1.618000 * value18 < Low[0] - value11) ? Low[0] - (1.618000 * value18) : value11;
value10 = (1.618000 * value18 < value12 - High[0]) ? High[0] + (1.618000 * value18) : value12;
value11 = (Low[0] - value9 > value19/Instrument.MasterInstrument.PointValue) ? Low[0] - (Risk * Instrument.MasterInstrument.PointValue * 0.06 + value20 * value19 * 0.01)/Instrument.MasterInstrument.PointValue : value9;
value12 = (value10 - High[0] > value19/Instrument.MasterInstrument.PointValue) ? High[0] + (Risk * Instrument.MasterInstrument.PointValue * 0.06 + value20 * value19 * 0.01)/Instrument.MasterInstrument.PointValue : value10;
if(Low[0] - value11 > MoneyRisk * value18)
value11 = Low[0] - (1 + 0.100000 * Risk) * value18;
if(value12 - High[0] > MoneyRisk * value18)
value12 = High[0] + (1 + 0.100000 * Risk) * value18;
if(value15 >= value16 && value7 >= value11)
value11 = value7;
if(value15 <= value16 && value8 <= value12)
value12 = value8;
if(value15 <= value16 && value7 <= value11)
value11 = value7;
if(value15 >= value16 && value8 >= value12)
value12 = value8;
if(value13 > value11)
value11 = value13;
if(value14 < value12)
value12 = value14;
if(MRO(delegate { return value17 > value20; }, 2, 2) > -1 && value11 <= value11_1)
value11 = value11_1;
if(MRO(delegate { return value17 < value21; }, 2, 2) > -1 && value12 >= value12_1)
value12 = value12_1;
//Log("v11 " + value11.ToString() + " close " + Close[0].ToString() + " v18 " + value18.ToString() + " cond1 " + condition1.ToString() +
// " high " + High[0].ToString() + " vt2 " + StTrendVT2(14, 3)[0] + " v17 " + value17.ToString(), LogLevel.Information);
if(value11 > 0 && condition1 && Close[0] > StTrendVT2(3, 14)[0] && value11 <= High[0])
BuyStop3[0] = value11;
//PLOT1 (value11, "BuyStop3") ;
if(value12 > 0 && condition2 && Close[0] < StTrendVT2(3, 14)[0] && value12 >= Low[0])
SellStop3[0] = value12;
//PLOT2 (value12, "SellStop3") ;
if(value17 > value20 && Close[1] < value12_1 && Close[0] > value12)
BOBuy[0] = value12;
//PLOT3 (value12, "BOBuy") ;
if(value17 < value21 && Close[1] > value11_1 && Close[0] < value11)
BOSell[0] = value11;
//PLOT4 (value11, "BOSell") ;
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Series<double> BuyStop3
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Series<double> SellStop3
{
get { return Values[1]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Series<double> BOBuy
{
get { return Values[2]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Series<double> BOSell
{
get { return Values[3]; }
}
[NinjaScriptProperty]
[Display(Description = "", GroupName = "Parameters", Order = 1)]
public int Risk
{
get { return risk; }
set { risk = Math.Max(1, value); }
}
[NinjaScriptProperty]
[Display(Description = "", GroupName = "Parameters", Order = 1)]
public double MoneyRisk
{
get { return moneyRisk; }
set { moneyRisk = Math.Max(1, value); }
}
#endregion
}
}
Thanks
Lucy

Comment