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

Draw line on indicator like RegressionChannel.middle ?

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

    Draw line on indicator like RegressionChannel.middle ?

    I'm wanting to plot on the indicator the RegressionChannel of the indicator values ...

    When I use DrawRegressionChannel() it seems to plot the values from the price, and not the indicator.

    Code:
    DrawRegressionChannel("indRisingRegressionChannel"+CurrentBar,lookbackmax,0,convergencecolor);
    I've also tried:
    Code:
    DrawRegressionChannel("indRegressionChanprice"+CurrentBar,true,lookbackmax,0,Color.Transparent,DashStyle.Solid,1,convergencecolor,DashStyle.Solid,1,Color.Transparent,DashStyle.Solid,1);
    It's correct for the price panel object, but not the indicator....

    What am I missing here?

    Thanks

    Matt

    #2
    Matt, which DrawOnPricePanel setting are you working with?

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Sorry - I should have mentioned...

      In Initialize() I have DrawOnPricePanel=false;

      then in my indicator drawing section I have the regressionline wrapped between something like:

      Code:
      drawOnPricePanel=false;
      
      DrawRegressionLine(....);
      
      drawOnPricePanel=true;

      the regression line is drawing in the indicator panel, so that's not really the problem...

      The problem is that the values used in drawing the regression line are Price values, and not indicator values....

      BTW - I'm on NT 7B13 (if that matters)

      Matt

      Comment


        #4
        Note:

        It seems that the drawing tool from the toolbar is also using the Price values, and not the indicator values...

        so if I hit shift+F10 and draw a regression channel on an indicator, it will draw, but it's drawing using price data, and not indicator data.

        again, this is on NT7B13

        Matt

        Comment


          #5
          Thanks Matt, I checked into it and this is expected for the Regression Channel drawing tool, as it would not offer a IDataSeries input.

          For calculating this on indicators, please work with the RegressionChannel indicator we offer -

          BertrandNinjaTrader Customer Service

          Comment


            #6
            But how do I draw a line on an indicator that's equivalent to the Middle line? (which should just be the linear regression line).

            I can calculate the values on a point by point basis, but I'd like to draw a line of the linear regression at that point...

            It almost seems that the RegressionChannel indicator needs to give access to the slope and the intercept so that this can be calculated by others indicators...

            Comment


              #7
              tazatek, since you can access the RegressionChannel's data point by point, wouldn't it be possible to calculate the slope/intercept from that data? You could even use DrawLine() to plot your own regression line.

              I was just browsing through some properties trying to find something that would help you out and found these three methods:
              1. LinRegSlope()
              2. LinRegIntercept()
              3. LinReg()

              I believe you should be able to get the values you want through some combination of the above methods.
              AustinNinjaTrader Customer Service

              Comment


                #8
                one would think so

                I've been playing with the LinRegSlope and LinRegIntercept but seem to be getting no where with it.

                This is what I've been trying, but not been successful:
                Code:
                // indicatorBarEnd ends up being zero and lookbackmax is 10
                // Indicator is a DataSeries object that holds the indicator values
                
                (indicatorBarEnd*LinRegSlope(Indicator,lookbackmax)[0]+LinRegIntercept(Indicator,lookbackmax)[0])
                I'm just using y=mx+b where slope = LinRegSlope(Indicator,lookbackmax)[0], b = LinRegIntercept(Indicator,lookbackmax)[0] and x = bar


                what I find is that at bar = 0, my intercept is wrong (the equation should equal just the intercept, but it doesn't).

                Here's what I end up plotting, and get weird lines. I think I'm mis-understanding how LinearRegression is being implemented by NT.

                Code:
                // This code should draw a line from the first point(left-most), to the last point (the intercept, right-most)
                
                DrawLine("indTrendLine"+CurrentBar, true, indicatorBarStart, indicatorBarStart*LinRegSlope(Indicator,lookbackmax)[0]+LinRegIntercept(Indicator,lookbackmax)[0],indicatorBarEnd,indicatorBarEnd*LinRegSlope(Indicator,lookbackmax)[0]+LinRegIntercept(Indicator,lookbackmax)[0],convergencecolor,DashStyle.Solid,2);

                Is my basic understanding of this correct? If it is, then I suspect a trivial error on my side...

                On the other hand, maybe I'm just not understanding the implementation, and could use some assistance in understanding how LinReg, LinSlope and LinIntercept play together.

                Thanks

                Matt

                Comment


                  #9
                  Matt, from what I can tell your understanding is correct. After looking over your code, I have two ideas for you to try:

                  1) replace lookbackmax with CurrentBar because that will run the calculations over the entire set of data instead of just the past lookbackmax bars.
                  2) take a look at the indicator's code itself (LinRegSlope, LinRegIntercept) to determine exactly how the slope/intercept is calculated.

                  If you can't figure out how NT does linear regression, another option would be to code your own slope and intercept finding algorithm. The code presented in that link doesn't look to difficult to implement.
                  AustinNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by arvidvanstaey, Today, 02:19 PM
                  4 responses
                  11 views
                  0 likes
                  Last Post arvidvanstaey  
                  Started by samish18, 04-17-2024, 08:57 AM
                  16 responses
                  60 views
                  0 likes
                  Last Post samish18  
                  Started by jordanq2, Today, 03:10 PM
                  2 responses
                  9 views
                  0 likes
                  Last Post jordanq2  
                  Started by traderqz, Today, 12:06 AM
                  10 responses
                  18 views
                  0 likes
                  Last Post traderqz  
                  Started by algospoke, 04-17-2024, 06:40 PM
                  5 responses
                  47 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X