Linear regression Channels

free & uncensored discussion arena for TheRumpledOne

Moderator: moderators

User avatar
TheRumpledOne
rank: 10000+ posts
rank: 10000+ posts
Posts: 15538
Joined: Sun May 14, 2006 9:31 pm
Reputation: 3035
Location: Oregon
Real name: Avery T. Horton, Jr.
Gender: None specified
Contact:

Postby TheRumpledOne » Sat Jun 24, 2006 4:09 pm

I am stumped...

Code only seems to plot correctly for current date.

I want to NORMALIZE the %Alpha.




Code: Select all

// TRO_LnRgChnnlDaily
   
{daily Bar Version
"Ln Rg Chnnl Daily" [JP.Gaskill LR Lines5]}


{Attn: TradeStation
if this indicator is posted on the TradeStation Forum, I,
TheRumpledOne, did NOT post it there,
so I can't be blamed for this indicator having my contact info.}


{MODIFYING Programmer: Avery T. Horton, Jr. aka TheRumpledOne,
gifts and donations accepted, PO Box 43575, Tucson, AZ 85733 }

{ © Copyright 2006 Avery T. Horton, Jr.}


 

Inputs:

iMode("R"),

   Begin_Date(0),Begin_Time(0),LookBack(55),
   End_Date(LastCalcDate),End_Time(LastCalcTime),
   Price(close),UseSdtDev(false),Mult1(1.6),Mult2(2),Mult3(2.5),
   CenterColor(lightgray),CenterSize(0),
   UpperColor(blue),UpperSize(0),
   LowerColor(blue),LowerSize(0),
   SlopeColor(black),TextOffset(1),
   ExtendRight(false),ExtendLeft(false),
   UpSndOn(false),DwnSndOn(false),// Switches Added JPG
   {C:\Sounds\} UpSound("INSERTPATHNAME.WAV"),{C:\Sounds\} DownSound("INSERTPATHNAME.WAV");//Placed in TS Program Directory JP

Vars:

N_PctAlpha(0),
   
PctAlpha(0),

StdDev_Value(0),Start_Date(Date),Start_Time(time),Start_Price(0),End_Price(0),
   oLRSlope(0),oLRAngle(0),LRIntercept(0),oLRValueRaw(0),x(0),Count(0),
   IntraBarPersist SlopeRefNum(-99),IntraBarPersist RatioRefNum(-99),ActualBars(0),
   NextToLastbar(false),
   
   IntraBarPersist Prev_Close(0),
   IntraBarPersist UpAlertBar(0),
   IntraBarPersist DownAlertBar(0);

Arrays:
   Prices[2500](0),Dates[2500](0),Times[2500](0),
   IntraBarPersist TLs[7](-99),Mults[3](0),TempPrices[2500](0);


variables:
 
FG1(white),
BG1(black),

fg2(white),
bg2(black),

fg3(white),
bg3(black),

fg4(white),
bg4(black);


{ INITIALIZE }

FG1 = WHITE;
BG1 = BLACK;

fg2 = WHITE;
bg2 = BLACK;

fg3 = WHITE;
bg3 = BLACK;

fg4 = WHITE;
bg4 = BLACK;

if barnumber = 1 then
begin
   Mults[1] = Mult1;
   Mults[2] = Mult2;
   Mults[3] = Mult3;

   if Begin_Date > 0 and Begin_Time > 0 then
   begin
      Start_Date = Begin_Date;
      Start_Time = Begin_Time;   
   end;         
end;

if date >= Begin_Date or (date = Begin_Date and Time >= Begin_Time) then
begin
   Count = Count + 1;
   Prices[Count] = Price;
   Dates[Count]  = Date;
   Times[Count]  = Time;
end;

NextToLastbar = LastBarOnChart = false and NextDate(-1) = End_Date and NextTime(-1) = End_Time;

//if (date = End_Date and Time = End_Time and BarStatus(1) = 2) or NextToLastbar then
   
if date = End_Date and Time = End_Time then
begin   
//Erase Lines
   {   
   if SlopeRefNum >= 0 then value1 = Text_Delete(SlopeRefNum);
   if RatioRefNum >= 0 then value1 = Text_Delete(RatioRefNum);

   SlopeRefNum = -99;
   RatioRefNum = -99;
   
   for x = 1 to 7
   begin      
      if TLs[x] >= 0 then value1 = TL_Delete(TLs[x]);
      TLs[x] = -99;
   end;
}
   ActualBars = Count;
   if LookBack <> 0 then ActualBars = MinList(Count,LookBack);
   for x = 1 to ActualBars
   begin
      TempPrices[x] = Prices[Count-ActualBars+x];
   end;
   Start_Date = Dates[Count-ActualBars+1];
   Start_Time = Times[Count-ActualBars+1];

   value1 = LinRegArray(TempPrices,ActualBars,0,oLRSlope,oLRAngle,LRIntercept,oLRValueRaw);
   Start_Price = oLRValueRaw;
   value1 = LinRegArray(TempPrices,ActualBars,ActualBars-1,oLRSlope,oLRAngle,LRIntercept,oLRValueRaw);
   End_Price = oLRValueRaw;

   if UseSdtDev
      then StdDev_Value = StdDev_a(TempPrices,ActualBars)
      else StdDev_Value = StdErrorArray(TempPrices,ActualBars);

   TLs[4] = TL_New(Start_Date,Start_Time,Start_Price,date,time,End_Price);
   if TLs[4] >= 0 then
   begin
      value1 = TL_SetColor(TLs[4],CenterColor);
      value1 = TL_SetSize(TLs[4],CenterSize);
      value1 = TL_SetExtRight(TLs[4],ExtendRight);
      value1 = TL_SetExtLeft(TLs[4],ExtendLeft);
   end;

   for x = 1 to 3
   begin
// Draw Lower Line      
      if Mults[3-x+1] <> 0 then
      begin
         TLs[x] = TL_New(Start_Date,Start_Time,Start_Price-Mults[3-x+1]*StdDev_Value,date,time,End_Price-Mults[3-x+1]*StdDev_Value);
         if TLs[x] >= 0 then
         begin            
            value1 = TL_SetColor(TLs[x],LowerColor);
            value1 = TL_SetSize(TLs[x],LowerSize);
            value1 = TL_SetExtRight(TLs[x],ExtendRight);
            value1 = TL_SetExtLeft(TLs[x],ExtendLeft);   
         end;      
      end;

// Draw Upper Line      
      if Mults[x] <> 0 then
      begin
         TLs[x+4] = TL_New(Start_Date,Start_Time,Start_Price+Mults[x]*StdDev_Value,date,time,End_Price+Mults[x]*StdDev_Value);
         if TLs[x+4] >= 0 then
         begin            
            value1 = TL_SetColor(TLs[x+4],UpperColor);
            value1 = TL_SetSize(TLs[x+4],UpperSize);
            value1 = TL_SetExtRight(TLs[x+4],ExtendRight);
            value1 = TL_SetExtLeft(TLs[x+4],ExtendLeft);
         end;
      end;
   end;
end;

if lastbaronchart then
begin
   if Barnumber <> UpAlertBar then
      begin
      x = 1;
      while Barnumber <> UpAlertBar and x <= 7
      begin
         if TLs[x] >= 0 then
          begin
            value1 = TL_GetValue(TLs[x],date,time);
            if close > value1 and Prev_Close < value1 then
            begin
               If UpSndOn then condition1 = PlaySound(UpSound);
               Alert(GetSymbolName + " Crosses above " + NumToStr(value1,3));
               UpAlertBar = Barnumber;
            end;               
         end;
         x = x + 1;
      end;         
   end;   

   if Barnumber <> DownAlertBar then
      begin
      x = 1;
      while Barnumber <> DownAlertBar and x <= 7
      begin
         if TLs[x] >= 0 then
          begin
            value1 = TL_GetValue(TLs[x],date,time);
            if close < value1 and Prev_Close > value1 then
            begin
               If DwnSndOn then condition1 = PlaySound(DownSound);
               Alert(GetSymbolName + " Crosses Below " + NumToStr(value1,3));
               DownAlertBar = Barnumber;
            end;               
         end;
         x = x + 1;
      end;         
   end;   

end;



// %Alpha = (Price – (LRValue raw [Length]) / StdDev (Price, Length));

value2 = StdDev_a(TempPrices,ActualBars) ;

PctAlpha =  (close - End_Price ) / StdDev_a(TempPrices,ActualBars) ;

Prev_Close = close;


N_PctAlpha = _fNormalizer( PctAlpha , LookBack ) * 100 ;

If iMode = "R"
then begin
Plot1( End_Price    , "End_Price", fg1 ) ;
SetPlotBGColor( 1, bg1);

 
Plot2( PctAlpha  , "PctAlpha ", fg2 ) ;
SetPlotBGColor( 2, bg2);


Plot3( N_PctAlpha  , "N_PctAlpha ", fg3 ) ;
SetPlotBGColor( 3, bg3);


Plot4( value2    , "StdDev_a", fg4 ) ;
SetPlotBGColor( 4, bg1);


end
else begin
   
Plot2( PctAlpha  , "PctAlpha ", fg2 ) ;
SetPlotBGColor( 2, bg2);


end;

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “TheRumpledOne”