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

Plz any body TS8 Stocastic Code conversion required for TS2000i



PureBytes Links

Trading Reference Links

Hi,

Please any body can convert below TS8 Stocstic
indicator for TS2000i. Full code with functions are
given below. If you need any other function let me
know and i will send you in few hours.


Awaiting

With kind regards
Muhammad


INDICATOR CODE IN TS8 LANUGAGE

inputs: 
	PriceH( High ),  
	PriceL( Low ), 
	PriceC( Close ), 
	StochLength( 5 ), 
	SmoothingLength1( 5 ), { used to slow FastK to FastD
= SlowK }
	SmoothingLength2( 2 ), { used to slow FastD to SlowD
}
	SmoothingType( 1 ), { pass in 1 for Original, 2 for
Legacy }
	OverSold( 20 ), 
	OverBought( 80 ), 
	OverSColor( Green ),
	OverBColor( Red );

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", Cyan );
Plot2 (OverSold, "OverSld");
Plot3(OverBought, "OverBot");

{ Color criteria }
if Plot1 > OverBought then 
	SetPlotColor( 1, OverBColor ) 
else if Plot1 < OverSold then 
	SetPlotColor( 1, OverSColor ) ;

{ Alert criteria }
if Plot1 crosses over OverSold then
	Alert( "Indicator exiting oversold zone" )
else if Plot1 crosses under OverBought then
	Alert( "Indicator exiting overbought zone" ) ;






FUNCTIONS

STOCASTIC FUNCTION

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 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 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 ;






LOWEST FUNCTION

inputs: Price( numericseries ), Length( numericsimple
) ;
variables: oExtremeVal( 0 ), oExtremeBar( 0 ) ;

Value1 = Extremes( Price, Length, -1, oExtremeVal,
oExtremeBar ) ;

Lowest = oExtremeVal ;






EXTREMES FUNCTION

inputs: 
	Price( numericseries ), 
	Length( numericsimple ), 
	HiLo( numericsimple ), { pass in 1 for Highest(Bar),
-1 for Lowest(Bar) }
	oExtremeVal( numericref ), 
	oExtremeBar( numericref ) ;

variables: 
	MyVal( 0 ), 
	MyBar( 0 ) ;

MyVal = Price ;
MyBar = 0 ;

for Value1 = 1 to Length - 1 
	begin
	if ( HiLo = 1 and Price[Value1] > MyVal ) 
		or ( HiLo = -1 and Price[Value1] < MyVal ) 
	then
		begin
		MyVal = Price[Value1] ;
		MyBar = Value1 ;
		end ;
	end ;

oExtremeVal = MyVal ;
oExtremeBar = MyBar + ExecOffset ;

Extremes = 1 ;






HIGHEST FUNCTION

inputs: Price( numericseries ), Length( numericsimple
) ;
variables: oExtremeVal( 0 ), oExtremeBar( 0 ) ;

Value1 = Extremes( Price, Length, 1, oExtremeVal,
oExtremeBar ) ;

Highest = oExtremeVal ;







CUM FUNCTION

inputs: Price( numericseries ) ;

Cum = Cum[1] + Price ;







AVERAGE FUNCTION

inputs: 
	Price( numericseries ), 
	Length( numericsimple ) ; { will get divide-by-zero
error if Length = 0 }

Average = Summation( Price, Length ) / Length ;







XAVERAGE FUNCTION


inputs: 
	Price( numericseries ), 
	Length( numericsimple ) ; { this input assumed to be
a constant >= 1 }

variables: 
	SmoothingFactor( 2 / ( Length + 1 ) ) ;

if CurrentBar = 1 then
	XAverage = Price
else
	XAverage = XAverage[1] + SmoothingFactor * ( Price -
XAverage[1] ) ;


XAVERAGEOIG FUNCTION


inputs: 
	Price( numericseries ), 
	Length( numericsimple ) ; { this input assumed to be
a constant >= 1 }

variables: 
	SmoothingFactor( 1 / Length ) ;

if CurrentBar = 1 then
	XAverageOrig = Price
else
	XAverageOrig = XAverageOrig[1] + SmoothingFactor * (
Price - XAverageOrig[1] ) ;






		
__________________________________________