02-18-2009, 11:06 AM
|
#5 |
Join Date: Oct 2006 Location: na Thanks: 33
Thanked 89 Times in 58 Posts
| Re: Need Code for W %R with 2 HMAs for TS? This should do what you are looking for. I dont have TS, but I do have OEC and got it compile in there. I had to add a couple functions that you will probably not need, but no big deal. I didnt do anything with coloring, that's a pretty basic thing. Hope this is what you were looking for. Code: inputs:
RLength( 14 ),
OverSold( 20 ),
OverBought( 80 ),
price(Close),
length1(20),
Length2(40);
variables:
PctR(0), HMA1(0), HMA2(0);
PctR = PercentR( RLength ) ;
HMA1= jtHMA(PctR, length1);
HMA2=jtHMA(PctR,length2);
Plot1( PctR, "%R" ) ;
Plot2( OverBought, "OverBot" ) ;
Plot3( OverSold, "OverSld" ) ;
Plot4(HMA1, "HMA1");
Plot5(HMA2, "HMA2");
#function jtHMA
Inputs: price(NumericSeries), length(NumericSimple);
Vars: halvedLength(0), sqrRootLength(0);
if ((ceiling(length / 2) - (length / 2)) <= 0.5) then
halvedLength = ceiling(length / 2)
else
halvedLength = floor(length / 2);
if ((ceiling(SquareRoot(length)) - SquareRoot(length)) <= 0.5) then
sqrRootLength = ceiling(SquareRoot(length))
else
sqrRootLength = floor(SquareRoot(length));
Value1 = 2 * WAverage(price, halvedLength);
Value2 = WAverage(price, length);
Value3 = WAverage((Value1 - Value2), sqrRootLength);
jtHMA = Value3;
#function PercentR
inputs: Length( numericsimple ) ;
variables: HH( 0 ), Divisor( 0 ) ;
HH = Highest( High, Length ) ;
Divisor = HH - Lowest( Low, Length ) ;
if Divisor <> 0 then
PercentR = 100 - ( ( HH - Close ) / Divisor ) * 100
else
PercentR = 0 ;
#function WAverage
inputs:
Price( numericseries ),
Length( numericsimple ) ; { will get divide-by-zero error if Length = 0 }
variables:
WtdSum( 0 ),
CumWt( 0 ) ;
WtdSum = 0 ;
for Value1 = 0 to Length - 1
begin
WtdSum = WtdSum + ( Length - Value1 ) * Price[Value1] ;
end ;
CumWt = ( Length + 1 ) * Length * .5 ;
WAverage = WtdSum / CumWt ; |
| |