PureBytes Links
Trading Reference Links
|
How would you like us to help? Have you given it a try to convert it
yourself?
_____
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of Tony Lei
Sent: Monday, 30 October 2006 3:12 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Stochastic Slow HELP
Hi all,
Can someone help me translate this TS stochastic code to AB? I went to the
AFL library and found various stochastics indicators but none match the TS
indicator. When I did the comparison, my data was the same for both TS and
AB. It is just that the AB indicator algorithm is different. The TS
function is in BLUE while the TS indicator is in RED.
thanks
{ Stochastic multiple-output "series" function with choice of Original or
Legacy
smoothing; see MULTIPLE-OUTPUT FUNCTIONS note below }
inputs:
PriceH( numericseries ),
PriceL( numericseries ),
PriceC( numericseries ),
StochLength( numericsimple ),
Length1( numericsimple ), { this input assumed to be a constant > 0;
used to slow
FastK to FastD = SlowK }
Length2( numericsimple ), { this input assumed to be a constant > 0;
used to slow
FastD to SlowD }
SmoothingType( numericsimple ), { this input is assumed to be constant;
pass in 1
for Original, 2 for Legacy }
oFastK( numericref ),
oFastD( numericref ),
oSlowK( numericref ),
oSlowD( numericref ) ;
variables:
LL( 0 ), { lowest low }
HH( 0 ), { highest high }
Num1( 0 ), { numerator 1 }
Den1( 0 ), { denominator 1 }
Num2( 0 ), { numerator 2 }
Den2( 0 ), { denominator 2 }
BarsToGo1( 0 ),
BarsToGo2( 0 ) ;
Stochastic = 1 ;
LL = Lowest( PriceL, StochLength ) ;
HH = Highest( PriceH, StochLength ) ;
Num1 = PriceC - LL ;
Den1 = HH - LL ;
if Den1 > 0 then
oFastK = Num1 / Den1 * 100
else
begin
oFastK = 0 ;
Stochastic = -1 ;
end ;
if SmoothingType = 1 then { Original }
begin
BarsToGo1 = Length1 - CurrentBar ;
if BarsToGo1 > 0 and CurrentBar > 0 then
begin
{ use approximate "backpropagated" calculations until we have enough
data }
Num2 = ( Cum( Num1 ) + BarsToGo1 * Num1[ CurrentBar - 1 ] ) /
Length1 ;
Den2 = ( Cum( Den1 ) + BarsToGo1 * Den1[ CurrentBar - 1 ] ) /
Length1 ;
end
else
begin
Num2 = Average( Num1, Length1 ) ;
Den2 = Average( Den1, Length1 ) ;
end ;
if Den2 > 0 then
oFastD = Num2 / Den2 * 100
else
begin
oFastD = 0 ;
Stochastic = -1 ;
end ;
BarsToGo2 = Length2 - CurrentBar ;
if BarsToGo2 > 0 and CurrentBar > 0 then
{ use approximate "backpropagated" calculations until we have enough
data }
oSlowD = ( Cum( oFastD ) + BarsToGo2 * oFastD[ CurrentBar - 1 ] ) /
Length2
else
oSlowD = Average( oFastD, Length2 ) ;
end
else if SmoothingType = 2 then { Legacy }
begin
oFastD = XAverage( oFastK, Length1 ) ;
oSlowD = XAverageOrig( oFastD, Length2 ) ;
end ;
oSlowK = oFastD ;
inputs:
AlertEndOfBar(true),
PriceH( High),
PriceL( Low),
PriceC( Close),
StochLength( 6),
SmoothingLength1( 3), { used to slow FastK to FastD = SlowK }
SmoothingLength2( 3), { used to slow FastD to SlowD }
SmoothingType( 1), { pass in 1 for Original, 2 for Legacy }
OverSoldC ( 20),
OverBoughtC ( 80),
MidLine ( 50),
OverSoldA ( 35),
OverBoughtA ( 65),
upColour(Blue),
downColour(Red),
colourDeltaBar(1);
variables:
oFastK( 0 ),
oFastD( 0 ),
oSlowK( 0 ),
oSlowD( 0 );
Value1 = Stochastic(
PriceH,
PriceL,
PriceC,
StochLength,
SmoothingLength1,
SmoothingLength2,
SmoothingType,
oFastK,
oFastD,
oSlowK,
oSlowD ) ;
Plot1( oSlowD, "SlowD") ;
Plot2 (OverSoldC, "OverSldC");
Plot3(OverBoughtC, "OverBotC");
Plot4 (OverSoldA, "OverSldA");
Plot5(OverBoughtA, "OverBotA");
Plot6(MidLine, "MidLine");
{ Color criteria }
if (oSlowD > oSlowD[1]) then
SetPlotColor[colourDeltaBar](1, upColour)
else if (oSlowD < oSlowD[1]) then
SetPlotColor[colourDeltaBar](1, downColour);
Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.27/517 - Release Date: 11/3/2006
|