Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with gression channel

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

    Problem with gression channel

    When I draw a regression channel and tray and access it in various modes I have problems accessing the data.

    In the strategy analyzer I can't get the time or the y values

    When it runs on historical data I can't get the y values until it runs on current data

    Here is my code

    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.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class MyCustomStrategy : Strategy
        {
            #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
            }
    		
    		IRegressionChannel reg;
    		bool first = true;
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			
    			if(first)
    			{
    				ClearOutputWindow();
    				if(CurrentBar < 1600)return;
    				first = false;
    				reg = DrawRegressionChannel("regg",11,1,Color.Blue);				
    				Print(String.Format("first == true Time: {0} startY: {1} endY: {2} historical: {3} toStr: {4}",
    					Time[0],reg.StartY,reg.EndY,Historical,reg.ToString()));				
    			}
    			else
    			{
    				if(reg == null)return;
    				Print(String.Format("first == false Time: {0} startY: {1} endY: {2} historical: {3} toStr: {4}",
    					Time[0],reg.StartY,reg.EndY,Historical,reg.ToString()));
    			}
            }
        }
    }
    Here is the output

    I deleted some output but it just repeats itself. As you can see as soon as it gets to live data the info on the y values is there.

    **NT** Disabling NinjaScript strategy 'MyCustomStrategy/67a15dcc3a36481b8d579656a9698772'
    **NT** Enabling NinjaScript strategy 'MyCustomStrategy/67a15dcc3a36481b8d579656a9698772' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
    first == true Time: 01/08/2016 09:15:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 09:20:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:15:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:20:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:25:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:30:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:35:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:40:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:45:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:50:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 12:55:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 13:00:00 startY: 0 endY: 0 historical: True toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'
    first == false Time: 01/08/2016 13:05:00 startY: 1.11759090909091 endY: 1.1167 historical: False toStr: Name='Regression Channel' Time='01/08/2016 08:20:00' StartBar='1539' EndTime='01/08/2016 09:10:00' EndBar='1549'

    #2
    Hello,

    Thank you for providing the sample on this.

    I do also see the same output you are, I will need to look further into this to determine what specifically is happening.

    Once I have reviewed the sample further I will reply back with more details.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello,

      I wanted to reply back on this item.

      It appears in NT7 that this tool would require that you call the tool on the same bar it is accessed in historical, otherwise the call would need to be on each OnBarUpdate. This no longer happens in NT8 so this could have potentially be a bug with this tool as a Dot does not exhibit the same behavior.

      For the time being, the following example seems to allow for the values to be used at a later time:

      Code:
      private IRegressionChannel myRegression;
      private int bar = 0;
      private bool once;
      protected override void OnBarUpdate()
      {
      	if (once)
      	{
      		myRegression = DrawRegressionChannel("areg", true, CurrentBar - bar, CurrentBar - bar + 10, Color.Blue, DashStyle.Solid, 1, Color.Blue, DashStyle.Solid, 1, Color.Blue, DashStyle.Solid, 1);
      	
      		if (myRegression != null)
      			Print(string.Format("Ongoing value {0} | {1}\r\nStartY: {2} | EndY: {3}", Time[0], myRegression.ToString(), myRegression.StartY, myRegression.EndY ));
      	}
      	else if (once == false && CurrentBar > 11)
      	{
      		myRegression = DrawRegressionChannel("areg", true, 10, 0, Color.Blue, DashStyle.Solid, 1, Color.Blue, DashStyle.Solid, 1, Color.Blue, DashStyle.Solid, 1);
      		bar = CurrentBar;
      		Print(string.Format("initial set {0} | {1}\r\nStartY: {2} | EndY: {3}", Time[0], myRegression.ToString(), myRegression.StartY, myRegression.EndY ));
      		once = true;
      	}
      }
      Unfortunately it seems this is required to get a value after the bar in which it was set, I am also seeing on the bar where it is set the value is not yet available. I will also submit these items for review to development to ensure that NT8 does not exhibit this.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      59 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      21 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X