- Katılım
- 23 Eki 2020
- Mesajlar
- 1,828
Here is a version of Vidya using a P variable that matches MetaStock's built-in Variable Moving Average. You can overlay them in different colours on the same chart to satisfy yourself that they are indeed the same (but remember to use the same number of periods). There is a small difference at the start due to different initialisation, after which they are identical. The coding is spelled out for the benefit of anyone studying the book. It can be adapted by adding a variable input for the CMO length (9), or made universal by replacing each C with a P, or the Abs(CMOsc) can be replaced with a different volatility index that ranges between 0 and 1. from HHP | ||
| ||
Chande's Vidya Using P Variable - Version I Pds:= Input("Number of Periods?",1,1000,20); Alpha:= 2/(Pds+1); {Chande Momentum Oscillator} {UD = Up day} {DD = Down day} UD:= Sum((C-Ref(C,-1))*(C>Ref(C,-1)),9); DD:= Sum((Ref(C,-1)-C)*(C<Ref(C,-1)),9); CMOsc:= (UD-DD)/(UD+DD); k:= Abs(CMOsc); Vidya:= (Cum(1) < Pds) * C + (Cum(1)>=Pds) * ((Alpha * k * C) + (1-Alpha * k) * PREV); Vidya
|