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

Re: [amibroker] Help with Kirshenbaum indicator



PureBytes Links

Trading Reference Links

hi Fred,
 
thanks for your nice words.  I do not see the need for a change to LPeriod-1.  In the code below I add a parameter "shift". When you shift it in the parameter window you see what is line is actually calculated, where it is located and where it puts the resulting bandwidth number (see also interpretation window). It seems OK to me. Especially when you use  C = Cum(1) you can see that the least squares fit lies exactly on to of the Cum(1) function. 
 
Your second point I'm not sure,
 
rgds, Ed
 
 
SetBarsRequired(10000,10000);

shift =
Param( "shift", 0, 0, 100, 1
);
PPeriod =
Param( "P Period", 12, 2, 100, 1
);
LPeriod =
Param( "L Period", 12, 2, 100, 1
);
NPeriod =
Param( "N Period", 2, 0, 10, 0.25
);
Bandwidth =
Null
;

//C = Cum(1);


EmaP =
EMA(C
,PPeriod);

saveLine =
Null
;

aaa =
LinRegIntercept(C
, LPeriod);
bbb =
LinRegSlope(C
, LPeriod);

for (i = BarCount - 1 - shift; i < BarCount
- shift; i++) {

   AE =
0
;
   
for (j = 0
; j < LPeriod; j++) {
   
      
// calculate point on regression line

      RegPoint = aaa[ i ] + bbb[ i ] * j;

      
// calculate the standard error using the distance from line

      AE = AE + (
C[ (i - LPeriod) + j + 1 ] - RegPoint) ^ 2
;
      
printf( "Regpoint:  %g\n"
, Regpoint );
      
printf( "C[ (i - LPeriod) + j + 1 ]:  %g\n", C[ (i - LPeriod) + j + 1
] );

      saveLine[ i - LPeriod + j +
1
] = RegPoint;
   
   }
   
// standard error

avErr = (AE / LPeriod) ^
0.5
;

// save the bandwidth

Bandwidth[ i ] = avErr * NPeriod;   
   
}


SetChartOptions(0, chartShowDates
);
GraphXSpace = 5
;
Plot(saveLine,"",colorRed,1
);
Plot(saveLine,"",colorYellow,9
);
Plot(C,"",colorWhite,64
);
Plot(saveLine,"",colorRed,1
);

EmaP =
IIf(Bandwidth,EmaP,Null
);
PlotShapes(IIf(Bandwidth,shapeDownTriangle,0),colorGold, layer = 0, yposition = EmaP + Bandwidth, offset = 0
);
PlotShapes(IIf(Bandwidth,shapeUpTriangle,0),colorGold, layer = 0, yposition = EmaP - Bandwidth, offset = 0
);

""
;
""
;
Title=Name()+ ", O: "+WriteVal(O)+ ", H: "+WriteVal(H)+ ", L: "+WriteVal(L)+ ", C: "+WriteVal(C) +
 
 
 
 
 
----- Original Message -----
From: fred
Sent: Monday, March 06, 2006 11:15 AM
Subject: Re: [amibroker] Help with Kirshenbaum indicator

With much interest i read the contributions regarding the Kirshenbaum indicator. Special thanks to Ed (Emp62) his contributions gave me a valuable insight how loops actually work...
 
When thorougly checking the calculated values, i came across different values (LinReg values) 
In my opinion the formula should be slightly changed as follows:
 
Original Empc posting:
aaa = LinRegIntercept(C, LPeriod);
bbb =
LinRegSlope(C
, LPeriod);
in my opinion should be changed to:
 
aaa = LinRegIntercept(C, LPeriod-1);
bbb =
LinRegSlope(C
, LPeriod-1);
Another thought when studying the indicator:
The "standard error calculation" measures the distance (C-Regpoint) for Lperiod days.
Obviously it make a huge difference whether the symbol is a 10$ trading stock or the Dow Index of 11000 points.
So my suggestion is to normalize the calculation for instance (C/Regpoint-1)*100 to calculate the procentual change.
 
Fred
 
 
 
 
 
SetBarsRequired(10000,10000);
PPeriod =
Param( "P Period", 12, 2, 100, 1
);
LPeriod =
Param( "L Period", 12, 2, 100, 1
);
NPeriod =
Param( "N Period", 2, 0, 10, 0.25
);
Bandwidth =
0
;

EmaP =
EMA(C
,PPeriod);

aaa =
LinRegIntercept(C
, LPeriod);
bbb =
LinRegSlope(C
, LPeriod);

for (i = LPeriod; i < BarCount
; i++) {
      
   AE =
0
;
   
for (j = 0
; j < LPeriod; j++) {
   
      
// calculate point on regression line

      RegPoint = aaa[ i ] + bbb[ i ] * j;
      
      
// calculate the standard error using the distance from line

      AE = AE + (
C[ (i - LPeriod) + j + 1 ] - RegPoint) ^ 2
;
   
   }
   
// standard error

avErr = (AE / LPeriod) ^
0.5
;

// save the bandwidth

Bandwidth[ i ] = avErr * NPeriod;

}


Buy = Ref(Cross(EmaP - Bandwidth,C),-1); BuyPrice = O
;
Sell = Ref(Cross(C, EmaP + Bandwidth),-1); SellPrice = O
;


SetChartOptions(0, chartShowDates
);
GraphXSpace = 5
;
Plot(C,"",colorWhite,64
);
Plot(EmaP,"",colorWhite,1
);
Plot(EmaP + Bandwidth,"",colorRed,1
);
Plot(EmaP - Bandwidth,"",colorBrightGreen,1
);

PlotShapes(IIf(Buy,shapeUpTriangle,0),colorWhite, layer = 0, yposition = BuyPrice, offset = 0
);
PlotShapes(IIf(Sell,shapeDownTriangle,0),colorYellow, layer = 0, yposition = SellPrice, offset = 0 );
 
 
 
----- Original Message -----
From: aajohah
Sent: Saturday, March 04, 2006 11:14 PM
Subject: RE: [amibroker] Help with Kirshenbaum indicator

With those settings I do not see there being a buy or sell on the chart since the close price is not out of the bands anywhere

 

Am I missing something?


Mark

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of emp62
Sent: Saturday, March 04, 2006 4:23 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Help with Kirshenbaum indicator

 

hi,

 

I changed 1 line in the code. I think it is good now. See chart below which resembles your original chart very good (settings I use for that chart are: 5, 7, 4.5)

 

code:

 

SetBarsRequired(10000,10000);
PPeriod =
Param( "P Period", 12, 2, 100, 1 );
LPeriod =
Param( "L Period", 12, 2, 100, 1 );
NPeriod =
Param( "N Period", 2, 0, 10, 0.25 );
Bandwidth =
0;

EmaP =
EMA(C,PPeriod);

aaa =
LinRegIntercept(C, LPeriod);
bbb =
LinRegSlope(C, LPeriod);

for (i = LPeriod; i < BarCount; i++) {
      
   AE =
0;
   
for (j = 0; j < LPeriod; j++) {
   
      
// calculate point on regression line
      RegPoint = aaa[ i ] + bbb[ i ] * j;
      
      
// calculate the standard error using the distance from line
      AE = AE + (C[ (i - LPeriod) + j +
1 ] - RegPoint) ^ 2;
   
   }
   
// standard error
avErr = (AE / LPeriod) ^
0.5;

// save the bandwidth
Bandwidth[ i ] = avErr * NPeriod;

}

SetChartOptions(0, chartShowDates);
GraphXSpace =
5;
Plot(C,"",colorWhite,64);
Plot(EmaP,"",colorWhite,1);
Plot(EmaP + Bandwidth,"",colorRed,1);
Plot(EmaP - Bandwidth,"",colorBrightGreen,1);




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

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





YAHOO! GROUPS LINKS