Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converted Indicator from 7 to 8 problems

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Converted Indicator from 7 to 8 problems

    Hi

    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
    Code:
    #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

    #2
    Here is the Ninjatrader 7 code:

    Ninjatrader 7
    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    // This namespace holds all indicators && is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    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>
    protected override void Initialize()
    
    {
    Add(new Plot(Color.Blue, PlotStyle.Dot, "BuyStop3"));
    Add(new Plot(Color.Red, PlotStyle.Dot, "SellStop3"));
    Add(new Plot(Color.Cyan, PlotStyle.Block, "BOBuy"));
    Add(new Plot(Color.Magenta, PlotStyle.Block, "BOSell"));
    Overlay = true;
    CalculateOnBarClose = false;
    }
    
    /// <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.Set(value11);
    //PLOT1 (value11, "BuyStop3") ;
    
    if(value12 > 0 && condition2 && Close[0] < StTrendVT2(3, 14)[0] && value12 >= Low[0])
    SellStop3.Set(value12);
    //PLOT2 (value12, "SellStop3") ;
    
    if(value17 > value20 && Close[1] < value12_1 && Close[0] > value12)
    BOBuy.Set(value12);
    //PLOT3 (value12, "BOBuy") ;
    
    if(value17 < value21 && Close[1] > value11_1 && Close[0] < value11)
    BOSell.Set(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 DataSeries 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 DataSeries 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 DataSeries 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 DataSeries BOSell
    {
    get { return Values[3]; }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public int Risk
    {
    get { return risk; }
    set { risk = Math.Max(1, value); }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public double MoneyRisk
    {
    get { return moneyRisk; }
    set { moneyRisk = Math.Max(1, value); }
    }
    #endregion
    }
    }

    Comment


      #3
      Hello lucyjoy,

      Thanks for your post.

      I would suggest that you use print statements to print out the values of the many variables you are using. A print statement will send its output to the new>Ninjascript output window.

      As you have so many similarly named variables, I would suggest starting with one plot and print out all of the variables that go into producing the plot and/or the conditions to show the plot.

      For example, with this line for the blue dots that you report are not printing:
      Code:
       
        if(value11 > 0 && condition1 && Close[0] > StTrendVT2(3, 14)[0] && value11 <= High[0])         BuyStop3[0] = value11;
      I would add a print statement to print out, before the if statement, the values of value11, conditions, Close[0], StTrendVT2(3, 14)[0], and High[0] From that print you then you would be able to see why the plot is not plotted. Youmay then need to go back further in your code to print out what makes up condition1 or value11 to see why the if condition is not being true.

      Here is a link to out debugging tips: https://ninjatrader.com/support/help...script_cod.htm

      Comment


        #4
        Thanks for the information, I could not get this to work. I am not really a developer. I followed a tutorial to convert this and got 3/4 working ok. This one is identical but I cannot get it to show plot3... Damn... Is there anyone on here that has a service to help or something. Sorry.

        Comment


          #5
          Hello lucyjoy,

          Thanks for your reply.

          As a small Ninjascript team, we cannot provide programming/debugging services.

          We can leave this thread open for any forum members that would like to assist.

          Alternatively, if you would like an indicator converted for you, we can provide a link to 3rd party developers in the NinjaTrader ecosystem that could provide that service.


          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          599 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          344 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          558 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          557 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X