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

Linear Regression unexpected difference in 2 similar series

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

    Linear Regression unexpected difference in 2 similar series

    I am in the process of creating a data series with historical Tick data that would be the same as say a 10 min Series on Live data with CalculateOnBarClose = false. So this would be where each index = close of 10 mins series and index 0 would be updated on each tick with the current tick price.

    I have studied the differences between historic and live bars and in order to create the custom series the same as live data , once the first tick is seen after the 10 min bars close, I set my custom series, (if its not the tick after the min bar closed I just update index 0 of my custom series)

    Code:
    if(barJustClosed)
    					{
    						Print("First Tick of min bar just seen. Current 1 tickBar = "+ CurrentBars[0] + " Price " + Closes[0][0]);
    						barJustClosed = false;
    						
    						//set our custom series to replicate closings of live bars
    						fastClose[1] = Closes[0][1];
    						fastClose[0] = Closes[0][0];
    					}
    					else
    						//keep custom series updated with current close
    						fastClose[0] = Closes[0][0];

    I have run the attached indicator on the same days data and compared the output of both and despite the series being extremely close,( there are a few ticks difference due to the expected differences due to different data sources.). The Linear Regression of both have huge differences and the Linear Regression of the custom data series is way out from expected values.

    Here is an example of the outputs form the run on Live via Historic ;

    HISTORIC

    BarsInProgress 1 3254
    Current 1 Tick Bar number 163265 Time 20/04/2016 21:46:50 Price 163.27
    fastClose[0] = 163.27
    fastClose[1] = 163.27
    fastClose[2] = 163.27
    fastClose[3] = 163.25
    fastClose[4] = 163.26
    fastClose[5] = 163.26
    fastClose[6] = 163.26
    fastClose[7] = 163.26
    fastClose[8] = 163.26
    fastClose[9] = 163.25
    Time 20/04/2016 21:46:50 LinReg FastClose 163.46872727273
    If you look at all the inputs to the 10 period linear regression of the custom series FastClose the value 163.4687 is way out



    LIVE

    BarsInProgress 1 3254
    Current 1 Tick Bar number 210727 Time 20/04/2016 21:46:49 Price 163.27
    Closes[0] = 163.27
    Closes[1] = 163.27
    Closes[2] = 163.27
    Closes[3] = 163.25
    Closes[4] = 163.26
    Closes[5] = 163.26
    Closes[6] = 163.26
    Closes[7] = 163.26
    Closes[8] = 163.26
    Closes[9] = 163.25
    Time 20/04/2016 21:46:49 LinReg Closes Min Bars 163.270000000002

    So I would like to get to the bottom of why the LinReg on the custom series is so out. I have attached a sample indicator to demo the problem. Couldn't attach the output files as they were to big
    Attached Files

    #2
    Hello GKonheiser,

    Thank you for your post.

    We will test your script and follow up with you here.

    Comment


      #3
      Originally posted by GKonheiser View Post
      I am in the process of creating a data series with historical Tick data that would be the same as say a 10 min Series on Live data with CalculateOnBarClose = false. So this would be where each index = close of 10 mins series and index 0 would be updated on each tick with the current tick price.

      I have studied the differences between historic and live bars and in order to create the custom series the same as live data , once the first tick is seen after the 10 min bars close, I set my custom series, (if its not the tick after the min bar closed I just update index 0 of my custom series)

      Code:
      if(barJustClosed)
      					{
      						Print("First Tick of min bar just seen. Current 1 tickBar = "+ CurrentBars[0] + " Price " + Closes[0][0]);
      						barJustClosed = false;
      						
      						//set our custom series to replicate closings of live bars
      						fastClose[1] = Closes[0][1];
      						fastClose[0] = Closes[0][0];
      					}
      					else
      						//keep custom series updated with current close
      						fastClose[0] = Closes[0][0];

      I have run the attached indicator on the same days data and compared the output of both and despite the series being extremely close,( there are a few ticks difference due to the expected differences due to different data sources.). The Linear Regression of both have huge differences and the Linear Regression of the custom data series is way out from expected values.

      Here is an example of the outputs form the run on Live via Historic ;

      HISTORIC



      If you look at all the inputs to the 10 period linear regression of the custom series FastClose the value 163.4687 is way out



      LIVE




      So I would like to get to the bottom of why the LinReg on the custom series is so out. I have attached a sample indicator to demo the problem. Couldn't attach the output files as they were to big
      It sounds like it is time to make your own copy of the LinReg, and enable some Print() logging to see where the values are getting thrown off.

      Comment


        #4
        I wrote my own method a while back but want to understand what is going wrong with LinReg as mz method gives slightly different results too. Would be nice to see the actual calculation of the LinReg method but I am unable to do that in VS

        Comment


          #5
          Originally posted by GKonheiser View Post
          I wrote my own method a while back but want to understand what is going wrong with LinReg as mz method gives slightly different results too. Would be nice to see the actual calculation of the LinReg method but I am unable to do that in VS
          Yes you can. Just open the indicator. It is open source.

          Comment


            #6
            Hello GKonheiser,

            Thank you for your patience.

            I have included a video and a script in this response to hopefully clear things up for you on this matter. I would also ask that we keep this inquiry to one thread or one email as it will ensure we are providing accurate information on the case.

            The script is attached and the video is at the following link: http://screencast.com/t/wnFeUW9D
            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kevinenergy, 02-17-2023, 12:42 PM
            115 responses
            2,699 views
            1 like
            Last Post kevinenergy  
            Started by prdecast, Today, 06:07 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by Christopher_R, Today, 12:29 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by chartchart, 05-19-2021, 04:14 PM
            3 responses
            577 views
            1 like
            Last Post NinjaTrader_Gaby  
            Started by bsbisme, Yesterday, 02:08 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X