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

Re: Usable Hist.-Volatility in Metastock



PureBytes Links

Trading Reference Links

> Is there any way to code an equivalent to the Tradestation
> Volatility-StdDev. (Hist.-Vola) in Metastock? The code in Easy
> Language uses a For..To loop wich is AFAIK not available in Metastock?

More of a For...Do statement ?
Actualy it is an If...Then statement with a For...Do statement routine nested and
with also more If...Then statement routines nested.
Somehow this originates from the old DOS-batch-language commands, and with
the formula's Function for the Module, this Easy Language Function's coding
could be(en have) taken straight from VB / VBA macro / VBScript.
But, lets continue on creating the Omega's Statistical Volatility (SDOC)-indicator
for use in the MetaStock 6.52 program.

> The built-in Vola-indicators in MS ("Chaikins", "Option Vola.") seem
> to deliver some strange values!?

{ from this table below have choosen the 20 days for standard "logical lookback
  period" in the Statistical Volatility (SDOC)-indicator, eg the normal period used
  for generaly calculating historical volatility (measurements) }
 
Option Volatility      = 21 days for historical option volatility measurement
Chaikin's Volatility = 10 days in the ROC(Mov(H-L,10,S),10,$)
                                    {makes total lookback = 20 days}
CMO's Volatility     = 20 days for the Chande's Momentum Oscilator's
                                    volatility measurement
Variance Volatility = 20 days for the Variance indicator's volatility
BollingerBands      = 20 days for the John Bollinger's bands volatility periods 
 
> Many thanks for your input,
> ciao Jens
> 
> ok, here is the TradeStation function:
> 
> {*******************************************************************
> Description : This Function returns Statistical Volatility
> - Standard Deviation of Closes
> Provided By : Omega Research, Inc. (c) Copyright 1999
> ********************************************************************}
> 
> Inputs: NumDays(Numeric);

{ For the Input function see MetaStock man. p230+271 and
  for some reason here, the user gets the option to adjust the standard
  20-days period for Volatility measurement, eg into another quantity
  for lookback days for the to be measured historical volatility period }
 
> Variables: AssetPrice(0), Answer(0), Count(0), NoData(0),
> VoltyDays(0), AvgDiff(0), SumDiff(0);

{ For the to be used variables for the data in this Easy Language Function,
  in a MetaStock Function there is no need to sum these up. Like in
  Omega's EL, only the assigning of each induvidual variable in this
  formula Module is sufficiant }
  
> If DataCompression = 2 then Begin {Check For Daily Data}
> VoltyDays = NumDays;
> For Count = 1 To VoltyDays + 1 Begin
> AssetPrice = Close[Count];
> If AssetPrice = 0 then NoData = 1;{Check For Enough History}
> End;
> 
> { 
> If NoData = 0 Then Begin
> }
> AvgDiff = Average((log(Close[0] / Close[1])), VoltyDays);
> SumDiff = Summation(((Log(Close[0] / Close[1])) - AvgDiff) *
                      ((Log(Close[0] / Close[1])) - AvgDiff), VoltyDays);
> Answer = (SquareRoot(SumDiff / VoltyDays)) *
                      15.90957; {Annualize Calculation}
> If Answer <= 0 Then Answer = 0;
> If Answer >= 2.99 Then Answer = 2.99;
> End;
> {
> End;
> }
> 
> VolatilityStdDev = Answer;
> 
> 

{ For the 2x Sub-sets of the Omega's EL's Statistical Volatility
  -Function's data, find below the full and inevatibily
  "at some places to be joined/mended" translation }

{
Indicator Name :

Statistical Volatility (SDOC)-indicator (Omega)

Formula:
}

{ MetaStock DataSet 1 }
NumDays:= Input("Enter Volatility Period", 1, 100, 20);
VoltyDays:= NumDays;
Count:= VoltyDays+1;
Data:= Ref(C,-Count);
AssetPrice:= If(Data>0,Data,0);
NoData:= If(AssetPrice<=0,1,0);

{ MetaStock DataSet 2 }
Diff:= Log(C/Ref(C,-1)); 
AvgDiff:= Mov(Diff, VoltyDays, S);
SumDiff:= Sum((Diff-AvgDiff) * (Diff-AvgDiff), VoltyDays);
Answer:= Sqrt(SumDiff/VoltyDays) * 15.90957;
SDOC:= If(Answer<=0,0,
       If(Answer>=2.99,2.99,Answer));
VolStdev:= SDOC;
{DataCompression}
If((DayOfWeek()=1 OR 2 OR 3 OR 4 OR 5 AND
{Count}
Data>0 AND
{NoData}
NoData=0),VolStdev,0)

-------------------------------------------------------------------------------------

You can Copy + Paste (from this mail) into the MetaStock's
Indicator Builder, eg Click "Tools|Indicator Builder|New", and
give the indicator its name (see above) by Pasting the name
"Name:" field and by Pasting the full formula (eg both the above
data Sub-sets) in the "Formula:" field. 

Regards,
Ton Maas
ms-irb@xxxxxxxxxxxxx
Dismiss the ".nospam" bit (including the dot) when replying.

/////////////////////////////////////////////////////////////////////////////////////////////////////////

----- Original Message ----- 
From: Jens Rogala
To: <metastock@xxxxxxxxxxxxx>
Sent: vrijdag 16 juli 1999 19:50
Subject: Usable Hist.-Volatility in Metastock

-----------------snip (see above)---------------------