Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

High[] and Low[] wrong values

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

  • kostolany
    replied
    Thank you very much, now everything is working perfectly!!

    Leave a comment:


  • sledge
    replied
    Originally posted by NinjaTrader_Jesse View Post
    Hello,

    It looks like you are using invalid names for your Plots.

    Low and High are DataSeries by default in NinjaScript so you have hidden the High and Low dataseries of actual market data and replaced them with your own:

    Nice catch.. I completely missed that.. (especially after commenting out his stuff and using the sample code without using exactly what was there..).

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello,

    It looks like you are using invalid names for your Plots.

    Low and High are DataSeries by default in NinjaScript so you have hidden the High and Low dataseries of actual market data and replaced them with your own:

    Code:
     [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 High
            {
                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 Low
            {
                get { return Values[1]; }
            }

    If you change the names of these to an acceptable name, the values should return to normal after removing the indicator from the chart completely and then re adding it.

    I look forward to being of further assistance.

    Leave a comment:


  • kostolany
    replied
    Hi,

    I have tested more options and I see, when I only set
    Low.Set(Low[3]);

    the indicator should show the low 4 bars ago(0=current,1=1bar back etc.)?
    I have attached a picture with the code and the chart. Has someone ever seen this before, is this a bug of ninjatrader?

    Attached Files

    Leave a comment:


  • kostolany
    replied
    Thank you for your help!
    I have a german Notebook with windows 10 and europe time and a demo version of ninjatrader. I hope it is not the demo, why it is not working.
    I have developed another indicator with Emas and Smas and there I had no problems, but I only worked with the Close[] prices.
    I have also tried it in other symbols, but it did not help.
    I have now attached the whole script, perhaps, I have made a mistake in the other regions:

    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 and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// HighLow Oil
        /// </summary>
        [Description("HighLow Oil")]
        public class HighLowRange2 : Indicator
        {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "High"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Low"));
                Overlay                = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                try
                {
                    if (CurrentBar < 13) return;
                    // High der letzten 12 Kerzen bestimmen
                    double HiHi = High[1];
                    if(HiHi<High[2]) HiHi=High[2];
                    if(HiHi<High[3]) HiHi=High[3];
                    if(HiHi<High[4]) HiHi=High[4];
                    if(HiHi<High[5]) HiHi=High[5];
                    if(HiHi<High[6]) HiHi=High[6];
                    if(HiHi<High[7]) HiHi=High[7];
                    if(HiHi<High[8]) HiHi=High[8];
                    if(HiHi<High[9]) HiHi=High[9];
                    if(HiHi<High[10]) HiHi=High[10];
                    if(HiHi<High[11]) HiHi=High[11];
                    if(HiHi<High[12]) HiHi=High[12];
                    
                    // Low der letzten 12 Kerzen bestimmen
                    double LoLo = Low[1];
                    if(LoLo>Low[2]) LoLo=Low[2];
                    if(LoLo>Low[3]) LoLo=Low[3];
                    if(LoLo>Low[4]) LoLo=Low[4];
                    if(LoLo>Low[5]) LoLo=Low[5];
                    if(LoLo>Low[6]) LoLo=Low[6];
                    if(LoLo>Low[7]) LoLo=Low[7];
                    if(LoLo>Low[8]) LoLo=Low[8];
                    if(LoLo>Low[9]) LoLo=Low[9];
                    if(LoLo>Low[10]) LoLo=Low[10];
                    if(LoLo>Low[11]) LoLo=Low[11];
                    if(LoLo>Low[12]) LoLo=Low[12];
                    //LoLo=Close[1];
                    Print(Low[1]);
                    // Use this method for calculating your indicator values. Assign a value to each
                    // plot below by replacing 'Close[0]' with your own formula.
                    High.Set(HiHi);
                    Low.Set(LoLo);
                }
                catch(Exception ex)
                {
                    Print(ex.ToString());
                }
            }
    
            #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 High
            {
                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 Low
            {
                get { return Values[1]; }
            }
    
            #endregion
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        public partial class Indicator : IndicatorBase
        {
            private HighLowRange2[] cacheHighLowRange2 = null;
    
            private static HighLowRange2 checkHighLowRange2 = new HighLowRange2();
    
            /// <summary>
            /// HighLow Oil
            /// </summary>
            /// <returns></returns>
            public HighLowRange2 HighLowRange2()
            {
                return HighLowRange2(Input);
            }
    
            /// <summary>
            /// HighLow Oil
            /// </summary>
            /// <returns></returns>
            public HighLowRange2 HighLowRange2(Data.IDataSeries input)
            {
                if (cacheHighLowRange2 != null)
                    for (int idx = 0; idx < cacheHighLowRange2.Length; idx++)
                        if (cacheHighLowRange2[idx].EqualsInput(input))
                            return cacheHighLowRange2[idx];
    
                lock (checkHighLowRange2)
                {
                    if (cacheHighLowRange2 != null)
                        for (int idx = 0; idx < cacheHighLowRange2.Length; idx++)
                            if (cacheHighLowRange2[idx].EqualsInput(input))
                                return cacheHighLowRange2[idx];
    
                    HighLowRange2 indicator = new HighLowRange2();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    HighLowRange2[] tmp = new HighLowRange2[cacheHighLowRange2 == null ? 1 : cacheHighLowRange2.Length + 1];
                    if (cacheHighLowRange2 != null)
                        cacheHighLowRange2.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheHighLowRange2 = tmp;
                    return indicator;
                }
            }
        }
    }
    
    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
        public partial class Column : ColumnBase
        {
            /// <summary>
            /// HighLow Oil
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.HighLowRange2 HighLowRange2()
            {
                return _indicator.HighLowRange2(Input);
            }
    
            /// <summary>
            /// HighLow Oil
            /// </summary>
            /// <returns></returns>
            public Indicator.HighLowRange2 HighLowRange2(Data.IDataSeries input)
            {
                return _indicator.HighLowRange2(input);
            }
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// HighLow Oil
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.HighLowRange2 HighLowRange2()
            {
                return _indicator.HighLowRange2(Input);
            }
    
            /// <summary>
            /// HighLow Oil
            /// </summary>
            /// <returns></returns>
            public Indicator.HighLowRange2 HighLowRange2(Data.IDataSeries input)
            {
                if (InInitialize && input == null)
                    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
    
                return _indicator.HighLowRange2(input);
            }
        }
    }
    #endregion
    Thanks!

    Leave a comment:


  • sledge
    replied
    Looks good here

    Works on ES.

    Is the internationalization an issue here?




    Code:
    			protected override void OnBarUpdate()
            {
                try
                {
                    if (CurrentBar < 13) return;
                    // High der letzten 12 Kerzen bestimmen
                    double HiHi = High[1];
                    if(HiHi<High[2]) HiHi=High[2];
                    if(HiHi<High[3]) HiHi=High[3];
                    if(HiHi<High[4]) HiHi=High[4];
                    if(HiHi<High[5]) HiHi=High[5];
                    if(HiHi<High[6]) HiHi=High[6];
                    if(HiHi<High[7]) HiHi=High[7];
                    if(HiHi<High[8]) HiHi=High[8];
                    if(HiHi<High[9]) HiHi=High[9];
                    if(HiHi<High[10]) HiHi=High[10];
                    if(HiHi<High[11]) HiHi=High[11];
                    if(HiHi<High[12]) HiHi=High[12];
                    
                    // Low der letzten 12 Kerzen bestimmen
                    double LoLo = Low[1];
                    if(LoLo>Low[2]) LoLo=Low[2];
                    if(LoLo>Low[3]) LoLo=Low[3];
                    if(LoLo>Low[4]) LoLo=Low[4];
                    if(LoLo>Low[5]) LoLo=Low[5];
                    if(LoLo>Low[6]) LoLo=Low[6];
                    if(LoLo>Low[7]) LoLo=Low[7];
                    if(LoLo>Low[8]) LoLo=Low[8];
                    if(LoLo>Low[9]) LoLo=Low[9];
                    if(LoLo>Low[10]) LoLo=Low[10];
                    if(LoLo>Low[11]) LoLo=Low[11];
                    if(LoLo>Low[12]) LoLo=Low[12];
                    Print(Low[1]);
                    // Use this method for calculating your indicator values. Assign a value to each
                    // plot below by replacing 'Close[0]' with your own formula.
                    //High.Set(HiHi);
                    //Low.Set(LoLo);
    	            Plot0.Set(HiHi);
    				Plot1.Set(LoLo);
                }
                catch(Exception ex)
                {
                    Print(ex.ToString());
                }
            }

    Code:
            #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 Plot0
            {
                get { return Values[0]; }
            }
            public DataSeries Plot1
            {
                get { return Values[1]; }
            }
    Attached Files

    Leave a comment:


  • kostolany
    started a topic High[] and Low[] wrong values

    High[] and Low[] wrong values

    Hi,

    I am trying to develope an indicator, which schows me the Highest High and Lowest Low from the last 12 Candles excluding the current bar.
    But, when I look at the Chart, it is always showing wrong values.
    I have attached a picture from the following code, does someone know, where the error is?
    Thanks

    Code:
    protected override void OnBarUpdate()
            {
                try
                {
                    if (CurrentBar < 13) return;
                    // High der letzten 12 Kerzen bestimmen
                    double HiHi = High[1];
                    if(HiHi<High[2]) HiHi=High[2];
                    if(HiHi<High[3]) HiHi=High[3];
                    if(HiHi<High[4]) HiHi=High[4];
                    if(HiHi<High[5]) HiHi=High[5];
                    if(HiHi<High[6]) HiHi=High[6];
                    if(HiHi<High[7]) HiHi=High[7];
                    if(HiHi<High[8]) HiHi=High[8];
                    if(HiHi<High[9]) HiHi=High[9];
                    if(HiHi<High[10]) HiHi=High[10];
                    if(HiHi<High[11]) HiHi=High[11];
                    if(HiHi<High[12]) HiHi=High[12];
                    
                    // Low der letzten 12 Kerzen bestimmen
                    double LoLo = Low[1];
                    if(LoLo>Low[2]) LoLo=Low[2];
                    if(LoLo>Low[3]) LoLo=Low[3];
                    if(LoLo>Low[4]) LoLo=Low[4];
                    if(LoLo>Low[5]) LoLo=Low[5];
                    if(LoLo>Low[6]) LoLo=Low[6];
                    if(LoLo>Low[7]) LoLo=Low[7];
                    if(LoLo>Low[8]) LoLo=Low[8];
                    if(LoLo>Low[9]) LoLo=Low[9];
                    if(LoLo>Low[10]) LoLo=Low[10];
                    if(LoLo>Low[11]) LoLo=Low[11];
                    if(LoLo>Low[12]) LoLo=Low[12];
                    Print(Low[1]);
                    // Use this method for calculating your indicator values. Assign a value to each
                    // plot below by replacing 'Close[0]' with your own formula.
                    High.Set(HiHi);
                    Low.Set(LoLo);
                }
                catch(Exception ex)
                {
                    Print(ex.ToString());
                }
            }
    Attached Files

Latest Posts

Collapse

Topics Statistics Last Post
Started by pmachiraju, 11-01-2023, 04:46 AM
8 responses
149 views
0 likes
Last Post rehmans
by rehmans
 
Started by mattbsea, Today, 05:44 PM
0 responses
5 views
0 likes
Last Post mattbsea  
Started by RideMe, 04-07-2024, 04:54 PM
6 responses
33 views
0 likes
Last Post RideMe
by RideMe
 
Started by tkaboris, Today, 05:13 PM
0 responses
5 views
0 likes
Last Post tkaboris  
Started by GussJ, 03-04-2020, 03:11 PM
16 responses
3,283 views
0 likes
Last Post Leafcutter  
Working...
X