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

linear regression parallel trendline code



PureBytes Links

Trading Reference Links

Thanks to everyone with DDE info.
Below is the code I got from www.traders2traders.com
It works fine.  Depending on the criteria you use for the parallel 
channels, parts of them scale off the screen, especially when 
you extend the channels.  Is there a way to modify the code so 
that you can see the entire channel?  In other words, the price 
scaling needs to somehow autoadjust so that you can see the plotted 
trendlines.

The other interesting thing is that I have the study NOT to update 
tick by tick.  It is not necessary, gets too busy and active. 
 The interesting thing is that on a 20 tick chart, the indicator 
will draw its channels and then redraw the trendlines on the 
next bar.  It goes along fine for a while and then four or five 
bars will go by and it won't redraw.  Then all of a sudden, it 
will "catch up" and redraw those channels as it should.  I am 
using 2000i.

Any thoughts are appreciated.

Input:Len(15),offset(1), K(AvgTrueRange(30)), YYYMMDD(0),
     SlctTime(0),Color(2), BarsPlus(0),Ext(False),Size(0);

Var:LRV(0),LRV1(0),LRV2(0),LRVAgo(0),LRVAgo1(0),LRVAgo2(0),
   g0(0),x(0), g(0),j(0),TL(0),TL1(0),TL2(0),
   Flag(0),flag1(0),flag2(0), BK(BarsPlus);
   
g=LinearRegValue(c, Len,0);
j= LinearRegValue(c, Len, Len-1);
x=LinearRegSlope(c,Len);        {only used with an alert}
                
LRV =g + offset*K ;   LRVAgo =j + offset*K ;    
LRV1 =g;              LRVAgo1 =j ;              
LRV2 =g - offset*K ;  LRVAgo2 =j - offset*K;            

If YYYMMDD=0 and AtCommentarybar then begin
   Flag = 2;
   Value0=1;
End else begin
If Date=YYYMMDD AND (Time=SlctTime OR SlctTime=0) and Flag=0 
then begin
  Flag = 2;
  Value0=1;
  end else begin
    if LastBarOnChart AND YYYMMDD = 0 AND Flag = 0 Then Begin
      Flag = 1; 
      Value0=1; 
    end;
  end;
End;

If (Flag = 1 OR Flag = 2) and value0=1 Then Begin
 value0=2;
 TL=TL_New(D[Len-1+BK],T[Len-1+BK],LRVAgo[BK],D[BK],T[BK],LRV[BK]);
 TL1=TL_New(D[Len-1+BK],T[Len-1+BK],LRVAgo1[BK],D[BK],T[BK],LRV1[BK]);
 TL2=TL_New(D[Len-1+BK],T[Len-1+BK],LRVAgo2[BK],D[BK],T[BK],LRV2[BK]);

 TL_SetSize(TL, size);  
 TL_SetColor(TL, Color);
 TL_SetExtRight(TL, Ext);

 TL_SetSize(TL1, size);
 TL_SetColor(TL1, Color);
 TL_SetExtRight(TL1, Ext);

 TL_SetSize(TL2, size);
 TL_SetColor(TL2, Color);
 TL_SetExtRight(TL2, Ext);
End;

If Flag = 1 Then Begin
 TL_SetBegin(TL, D[Len-1+ BK],T[Len-1+ BK], LRVAgo[BK]);
 TL_SetEnd(TL, D[BK],T[BK], LRV[BK]);

 TL_SetBegin(TL1, D[Len-1+ BK],T[Len-1+ BK], LRVAgo1[BK]);   
   
 TL_SetEnd(TL1, D[BK],T[BK], LRV1[BK]); 

 TL_SetBegin(TL2, D[Len-1+ BK],T[Len-1+ BK], LRVAgo2[BK]);   
   
 TL_SetEnd(TL2, D[BK],T[BK], LRV2[BK]); 
End;

If CheckAlert  then
 if x<0 and C crosses over LRV then    alert=true;
        
If CheckAlert  then
 if x>0 and C crosses under LRV2 then   alert=true;

{if false then plot1(flag2,"");   }       {only needed for TS4}



Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.