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

Indicator Bug

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

    Indicator Bug

    I found this somewhat on accident, but it can produce amazing results as i believe the program is looking forward during backtesting. This DOES NOT WORK in real time. Only during backtesting.


    Case:
    15 min bar chart

    If you have a strategy and you call from within BIP=1 (1 minute added period) the strategy Indicator(BarsArray[0])

    And then within Indicator.cs
    Another Added Period Type of 1 min is added

    And within BIP=1.....The Value.Set will plot a different value on the screen versus a print statement located within either the strategy or the indicator.

    This can be a bit hard to follow, but the value that is plotted on the chart is given a different value than if you Print(Value.ToString()); within the same indicator. So the issue has something to do with adding another time frame to an indicator and then laying it on top of a chart with a less granular time frame.

    I questioned this from day one, as i do not have all the code listed but enough to show the issue - our ProfitFactor went to about 60 Out of sample with about 2 trades a day with this indicator "logic ---likely illogic" added to the code.



    Code:
    	protected override void Initialize()
            {
             
    			Add(PeriodType.Minute,1); // index 
    			CalculateOnBarClose = false; 
    			Add(new Plot(Color.Blue, PlotStyle.Line, "Plot0"));
    			Add(new Plot(Color.Red,PlotStyle.Line, "Plot1")); 
         		Overlay				= true;
    			//Add(PeriodType.Minute,1); 
    			
    		
           	}
    			 
                 protected override void OnBarUpdate()
            {
    		
    		if (BarsInProgress == 1)
    		{
    			
    			if (CurrentBars[0] < 5)
    			return;
    				
    					
    		
    			Value.Set(Highs[1][0]); 
    		 	// WITH NO VALUE.SET Ninja Defaults to the Close of the BIP of the Chart, so index 0 
    			
    			// value is only printing every 15 minutes even though its inside of a 1 min bip index
    			[B]NOTE:   VALUE.TOSTRING() and VALUE= plotted on chart are not the same[/B]
    			Print(ToTime(Time[0]) + "  valuebip=1  " + Value.ToString () + " Highs[0][0]  " + Highs[0][0]); 
    			//Plot1.Set(Highs[1][0]); 
    			
    			//Plot0.Set(value9); 
    	
    		} // end bip 1

    #2
    Hi Ben, I'm not 100% sure I follow you - so you have a MultiSeries strategy calling a MultiSeries indicator and print from the added series in the indicator is not returning as to your expectations here? Would you have a sample I could run here on my end to check into?

    If you're working with any custom series you would need to ensure they are synced correctly to the BarsArray you need them on - http://www.ninjatrader.com/support/f...ead.php?t=3572
    BertrandNinjaTrader Customer Service

    Comment


      #3
      In the calling indicator/strategy, OnBarUpdate for the 15-minute bar doesn't get called until AFTER OnBarUpdate is called for the next 14 1-Minute bars in BIP==1 in the called indicator. You can show this by Printing the Time inside OnBarUpdate in both the calling and called indicators. When you do Value.Set within BIP==1 in the called indicator, you are passing data from 14 minutes into the future. Sadly, it only works in backtesting!

      It's one of the many problems with NT7's "synchronization".

      I can't explain why your Print statement only prints every 15 minutes, though; I would think OnBarUpdate should be called every minute in your case.

      -Kevin

      Comment


        #4
        Kevin, yeah i actually noticed this now. I think of it more as an accidential coding error in this context as i did not intend to leave the BarsArray[0] within the strategy...but when i did the equity curve was about a 45 degree line so it did ponder the question of "why??? "

        Bertrand if you plot this indicator just as is you will see that the chart plots a line above the high of the actual bar from time to time. It should give you an idea.

        #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;
        using System.Collections.Generic;
        using System.Text;
        using System.Linq;
        #endregion

        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        ///

        [Description("Long Entry Strat - Dual Data")]
        public class bkCloseLongData : Indicator
        {
        double value1 = 0;
        double value2 = 0;
        double value3 = 0;
        double value4 = 0;
        double value8 = 0;
        double value9 = 0;
        public double value10=0;
        public double pf1=.95;
        public double maxnum;
        int dataSeries = 15;
        protected override void Initialize()
        {

        Add(PeriodType.Minute,1); // index
        Add(PeriodType.Minute,16); // index 2

        CalculateOnBarClose = false;
        Add(new Plot(Color.Blue, PlotStyle.Line, "Plot0"));
        Add(new Plot(Color.Red,PlotStyle.Line, "Plot1"));
        Overlay = true;
        //Add(PeriodType.Minute,1);


        }

        protected override void OnBarUpdate()
        {

        if (BarsInProgress == 1)
        {

        if (CurrentBars[0] < 5)
        return;




        Value.Set(High[0]);
        // WITH NO VALUE.SET Ninja Defaults to the Close of the BIP of the Chart, so index 0
        Print(ToTime(Time[0]) + " valuebip=1 " + Value.ToString () + " Highs[2][0] " + Highs[2][0]);
        Plot1.Set(Highs[1][0]);

        //Plot0.Set(value9);

        } // end bip 1

        if(BarsInProgress ==0)
        {
        //Value.Set(Highs[1][0]);
        // Print(ToTime(Time[0]) + " VALUE bip=15 " + Value.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 Plot0
        {
        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 Plot1
        {
        get { return Values[1]; }
        }
        [Description("")]
        [GridCategory("Parameters")]
        public double Pf1
        {
        get { return pf1; }
        set { pf1 = value; }
        }
        [Description("")]
        [GridCategory("Parameters")]
        public int DataSeries
        {
        get { return dataSeries; }
        set { dataSeries = value; }
        }


        #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 bkCloseLongData[] cachebkCloseLongData = null;

        private static bkCloseLongData checkbkCloseLongData = new bkCloseLongData();

        /// <summary>
        /// Long Entry Strat - Dual Data
        /// </summary>
        /// <returns></returns>
        public bkCloseLongData bkCloseLongData(int dataSeries, double pf1)
        {
        return bkCloseLongData(Input, dataSeries, pf1);
        }

        /// <summary>
        /// Long Entry Strat - Dual Data
        /// </summary>
        /// <returns></returns>
        public bkCloseLongData bkCloseLongData(Data.IDataSeries input, int dataSeries, double pf1)
        {
        if (cachebkCloseLongData != null)
        for (int idx = 0; idx < cachebkCloseLongData.Length; idx++)
        if (cachebkCloseLongData[idx].DataSeries == dataSeries && Math.Abs(cachebkCloseLongData[idx].Pf1 - pf1) <= double.Epsilon && cachebkCloseLongData[idx].EqualsInput(input))
        return cachebkCloseLongData[idx];

        lock (checkbkCloseLongData)
        {
        checkbkCloseLongData.DataSeries = dataSeries;
        dataSeries = checkbkCloseLongData.DataSeries;
        checkbkCloseLongData.Pf1 = pf1;
        pf1 = checkbkCloseLongData.Pf1;

        if (cachebkCloseLongData != null)
        for (int idx = 0; idx < cachebkCloseLongData.Length; idx++)
        if (cachebkCloseLongData[idx].DataSeries == dataSeries && Math.Abs(cachebkCloseLongData[idx].Pf1 - pf1) <= double.Epsilon && cachebkCloseLongData[idx].EqualsInput(input))
        return cachebkCloseLongData[idx];

        bkCloseLongData indicator = new bkCloseLongData();
        indicator.BarsRequired = BarsRequired;
        indicator.CalculateOnBarClose = CalculateOnBarClose;
        #if NT7
        indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
        indicator.MaximumBarsLookBack = MaximumBarsLookBack;
        #endif
        indicator.Input = input;
        indicator.DataSeries = dataSeries;
        indicator.Pf1 = pf1;
        Indicators.Add(indicator);
        indicator.SetUp();

        bkCloseLongData[] tmp = new bkCloseLongData[cachebkCloseLongData == null ? 1 : cachebkCloseLongData.Length + 1];
        if (cachebkCloseLongData != null)
        cachebkCloseLongData.CopyTo(tmp, 0);
        tmp[tmp.Length - 1] = indicator;
        cachebkCloseLongData = 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>
        /// Long Entry Strat - Dual Data
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.bkCloseLongData bkCloseLongData(int dataSeries, double pf1)
        {
        return _indicator.bkCloseLongData(Input, dataSeries, pf1);
        }

        /// <summary>
        /// Long Entry Strat - Dual Data
        /// </summary>
        /// <returns></returns>
        public Indicator.bkCloseLongData bkCloseLongData(Data.IDataSeries input, int dataSeries, double pf1)
        {
        return _indicator.bkCloseLongData(input, dataSeries, pf1);
        }
        }
        }

        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
        public partial class Strategy : StrategyBase
        {
        /// <summary>
        /// Long Entry Strat - Dual Data
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.bkCloseLongData bkCloseLongData(int dataSeries, double pf1)
        {
        return _indicator.bkCloseLongData(Input, dataSeries, pf1);
        }

        /// <summary>
        /// Long Entry Strat - Dual Data
        /// </summary>
        /// <returns></returns>
        public Indicator.bkCloseLongData bkCloseLongData(Data.IDataSeries input, int dataSeries, double pf1)
        {
        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.bkCloseLongData(input, dataSeries, pf1);
        }
        }
        }
        #endregion

        Comment


          #5
          Ben, please try setting the plots from BIP 0 as they are synched to the primary series used in your script.
          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by nandhumca, Yesterday, 03:41 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by The_Sec, Yesterday, 03:37 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by vecnopus, Today, 06:15 AM
          0 responses
          1 view
          0 likes
          Last Post vecnopus  
          Started by Aviram Y, Today, 05:29 AM
          0 responses
          5 views
          0 likes
          Last Post Aviram Y  
          Started by quantismo, 04-17-2024, 05:13 PM
          3 responses
          27 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X