[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Help - Trying to plot linear regression lines



PureBytes Links

Trading Reference Links

I also tried putting everything inside the BarCount loop but now I get an error with LineArray (Error 5 - the function expects a different argument type here):


// Plot the Linear Regression Lines
  if (ParamToggle("Show slope signals", "No|Yes", True))
  {
   
    for (b = LinePeriod; b < BarCount; b++)
    {

      if (slopeSignalLong[b])
      {
        X2          = b;
        X1          = b - LinePeriod;
        Intercept   = LinRegIntercept(C[b], LinePeriod);
        Slope       = LinRegSlope(C[b], LinePeriod);      
        Y2          = Slope * X2 + Intercept;                       
        Y1          = Slope * X1 + Intercept;                                 
        RegLine     = LineArray( X1, Y1, X2, Y2,0 );
        Plot(RegLine, "RegLine", colorBrown, styleThick | styleDashed);
      }

      if (slopeSignalShort[b])
      {
        X2          = b;
        X1          = b - LinePeriod;
        Intercept   = LinRegIntercept(C[b], LinePeriod);
        Slope       = LinRegSlope(C[b], LinePeriod);      
        Y2          = Slope * X2 + Intercept;                       
        Y1          = Slope * X1 + Intercept;                                 
        RegLine     = LineArray( X1, Y1, X2, Y2,0 );
        Plot(RegLine, "RegLine", colorTurquoise, styleThick | styleDashed);
      }
    }
   }





--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> I've been trying to plot linear regression lines, with no luck. Hoping
> someone can point out my error.
>
> When I am determining to enter a trade, my trading formula tests against
> the slope of the linear regression line over the last 4 Closes (in
> addition to other tests). For visual tracking purposes, I want to plot
> these linear regression lines.
>
> Part of my trading formula resides in a BarCount loop, and inside this
> loop I successfully populate arrays, TestSignalLong and TestSignalShort.
> When these arrays are true, I want to plot the linear regression lines.
>
> Here is what I tried coding but it does not properly plot the lines. I
> get weird results:
>
>
>
> X2 = Cum(1); //
> 2nd X-coordinate in Cartesian line formula: Y = M*X + B
> LinePeriod = 4; //
> look-back period for linear regression line
> X1 = LastValue(X2) - LinePeriod; //
> 1st X-coordinate in Cartesian line formula: Y = M*X + B
> Slope = LastValue( LinRegSlope(C, LinePeriod) ); //
> this is the 'M' in Cartesian line formula: Y = M*X + B
> Intercept = LastValue( LinRegIntercept(C, LinePeriod) ); // this
> is the 'B' in Cartesian line formula: Y = M*X + B
> Y2 = Slope * X2 + Intercept; //
> 2nd Y-coordinate in Cartesian line formula: Y = M*X + B
> Y1 = Slope * X1 + Intercept; //
> 1st Y-coordinate in Cartesian line formula: Y = M*X + B
>
>
> // Barcount Loop
> for (i = LinePeriod; i < BarCount; i++)
> {
>
> //----------------------------------------------------------------------\
> ------------------------------------------------------------------------
> // MY TRADING FORMULA GOES HERE. DURING THE FORMULA, ARRAYS ARE FILLED
> FOR:
> // TestSignalLong[i] AND TestSignalShort[i], for use in the Indicator
> below
> //----------------------------------------------------------------------\
> ------------------------------------------------------------------------\
> -
> }
>
>
> if (Status("action") == 1 /* Indicator */)
> {
>
> // Plot Linear Regression Lines for each TestSignal
> if (ParamToggle("Show slope signals", "No|Yes", True))
> {
> firstVisibleBar = Status("firstVisibleBar");
> lastVisibleBar = Status("lastVisibleBar");
> for (b = firstVisibleBar; b < BarCount AND b <= lastVisibleBar; b++)
> {
> if (TestSignalLong[b])
> {
> RegLine = LineArray( X1[b], Y1[b], X2[b], Y2[b] );
> Plot(RegLine, "RegLine", colorBrown, styleThick | styleDashed);
> }
> if (TestSignalShort[b])
> {
> RegLine = LineArray( X1[b], Y1[b], X2[b], Y2[b] );
> Plot(RegLine, "RegLine", colorTurquoise, styleThick |
> styleDashed);
> }
> }
> }
>
> Plot(C, "Close", colorGreen, styleThick);
>
> }
>
__._,_.___

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___