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

Re: Building a Model LinearRegChanel



PureBytes Links

Trading Reference Links

>Subject:     Re: Building a Model  LinearRegChanel
>Sent:        17/03/98 7:59 am
>Received:    17/03/98 1:48 pm
>From:        anatop, anatop@xxxxxxxxxxx
>To:          Timothy Morge, tmorge@xxxxxxxxxxxxxxx
>             greene@xxxxxxxxxxxxxxx
>CC:          omega-list@xxxxxxxxxx
>             The Code, veeger2001@xxxxxxxxxxx
>
>Hi
>
>Here is the code of a Linear RegressionChannel
>given to my by Gregory Wood
>
>Have fun
>
>
>Hans-Peter Moeckli
>anatop@xxxxxxxxxxx
>
>
>------------------------------------------
>input:  price(c), labTL("R"), colorTL(tool_GREEN), thickTL(0);
>
>{ ======================================
>This is my implementation of Linear Regression Channels. You are welcome to
>use this code freely.  You may redistribute it provided you include this
>comment block, plus a description of any changes you make.
>
>If you extend it, or adapt it to other uses, I'd appreciate a look at what
>you've done.  Thanks.
>
>     Gregory Wood
>     SwissFranc@xxxxxxxxxxxxxxxx
>
>01/26/97 v1.0 - Initial distribution
>========================================}
>
>{ 
>USAGE
>
>Use the text tool to indicate the beginning and end of the channel(s) you 
>want.  The default uses "R"s (upper case, no quotes). Then to show the 
>channel(s), go to Format Analysis Techniques, select this indicator, and 
>press the "Status" button two times (this is not a double-click, really 
>press it two times).
>
>The channel is based on Price, which defaults to Close, but you can change 
>it to High or Low.
>
>You can set the color and thickness of the channels.
>
>You can show a series of channels by putting more "R"s on the chart.  Each 
>pair of "R"s will get its own channel.
>
>If you want separate channels or different colors, you can add the 
>indicator multiple times. Be sure to give each one a different labTL value.
>
>}
>
>array: dd[20](0),tt[20](0),vv[20](0),bb[20](0);
>var: iMax(20), ix(0), hh(0), ll(0), hhbb(0), llbb(0);
>var: pvv1(0), pbb1(0), pvv2(0), pbb2(0), x1(0), x2(0), y1(0), y2(0);
>var: ii(0), jj(0), kk(0), hval(0), lval(0);
>var: handl(0);
>
>if currentbar = 1 then begin { examine all the text strings and save some 
>info about the ones we recognize }
>   handl = text_getfirst(2);
>   while handl > 0 begin
>      if text_getstring(handl) = labTL then begin { save the item's date, 
>time, value and handle }
>            if ix < iMax - 1 then begin
>          
>      tt[ix] = text_gettime(handl);
>                dd[ix] = text_getdate(handl);
>                vv[ix] = text_getvalue(handl);
>                ix = ix + 1;
>           end;
>      end;
>      handl = text_getnext(handl,2); { IMPORTANT -- infinite loop if this is
>missing!  }
>   end;
>end;
>
>for ii = 0 to ix - 1 begin { check each point }
>   if time = tt[ii] and date = dd[ii] then begin { we've found a selected
>point }
>      bb[ii] = currentbar; { remember where we found it }
>      plot1(price,""); { show the user which point we used for the
>calculations }
>      if ii > 0 then begin { need at least 1 point }
>         { The regression line passes through (x1,y1) and (x2,y2) }
>         x1 = bb[ii];
>         x2 = bb[ii-1];
>         y1 = LinearRegValue(price, x1-x2 ,0);
>         y2 = LinearRegValue(price, x1-x2, x1-x2);
>
>         { Draw the regression line }
>         handl = TL_New(date[currentbar-x2],time[currentbar-x2],y2,
>date[currentbar-x1],time[currentbar-x1],y1 );
>         TL_SetExtRight(handl, true);
>         TL_SetExtLeft(handl, false);
>         TL_SetSize(handl, thickTL);
>         TL_SetColor(handl, colorTL);
>
>         { find the max excursion on each side of the line }
>         hval = 0;
>         lval = 0;
>         for kk = x2 to x1 begin
>             value1 = pnt2line(x1,y1,x2,y2, barnumber[currentbar-kk],
>high[currentbar-kk]);
>             if value1 > 0 and hval < value1 then begin
>                hval = value1;
>                hh = h[currentbar-kk];
>                hhbb = kk;
>             end;
>             value2 = pnt2line(x1,y1,x2,y2, barnumber[currentbar-kk],
>low[currentbar-kk]);
>             if value2 < 0 and lval > value2 then begin
>                lval = value2;
>                ll = l[currentbar-kk];
>                llbb = kk;
>             end;
>         end;
>
>         { Now draw the channel lines }
>         plot2[currentbar-hhbb](hh,"");
>         pvv1 = TLValue(ll,llbb, ll-(y2-y1), llbb-(x2-x1), x1);
>         pvv2 = TLValue(ll,llbb, ll-(y2-y1), llbb-(x2-x1), x2);
>         handl = TL_New(date[currentbar-x2],time[currentbar-x2],pvv2,
>date[currentbar-x1], time[currentbar-x1],pvv1);
>         TL_SetExtRight(handl, true);
>         TL_SetExtLeft(handl, false);
>         TL_SetSize(handl, thickTL);
>         TL_SetColor(handl, colorTL);
>
>         plot3[currentbar-llbb](ll,"");
>         pvv1 = TLValue(hh,hhbb, hh-(y2-y1), hhbb-(x2-x1), x1);
>         pvv2 = TLValue(hh,hhbb, hh-(y2-y1), hhbb-(x2-x1), x2);
>         handl = TL_New(date[currentbar-x2],time[currentbar-x2],pvv2,
>date[currentbar-x1], time[currentbar-x1],pvv1);
>         TL_SetExtRight(handl, true);
>         TL_SetExtLeft(handl, false);
>         TL_SetSize(handl, thickTL);
>         TL_SetColor(handl, colorTL);
>
>      end;
>   end;
>end;
>
>
>
>>Whoops - forgot to give you the end of it.  Once you have the regression
>line -
>>use the parallel line function and add 2 parallel lines.  You move one to
>the
>>bottom of the channel - the other to the top.  Where's the top and bottom?
>>Sometimes easy to say - sometimes hard to say- but there should be an equal
>>distance between the middle line - and the top and bottom lines.  Trader
>Vic
>>has written some good things about drawing trend lines in his books
>(although I
>>don't follow him religiously).
>>
>
>