MetaStock™ Zone Forum & FAQ Artykuły Linki Elliott Waves EasyLanguage™ Zone

 A B C D E F G H I J K L M N O P R S T U V W Y Z #

Bollinger Band - Last Extreme

Can someone show me a method of writing a formula that uses Typ() as the DA for a 20/2 Bollinger Band for all days PRIOR to a given bar, but for that bar's BB value, the BB calc would use the Open price for DA instead???

Second attempt for my previous Q: any way to access the Interval of a chart within an indicator, to base boolean decisions (or other math) on it???

Jim

Figured it out - just have to do it longhand - if anyone can come up with a faster way, esp if it avoids the expansion of the Std Dev calc, please let me know.

The following function finds the 20-bar, 2-SD Upper BBand based on 19 previous Typ()'s, and the current High. It uses the current Low for the Lower BBand, and the current Open for the middle.

Intended use: for backtesting, to simulate what the 20/2 BB would be using intraday "Last" value for the final daily bar, to see if an extreme-band crossover would occur when the day's value was at its extreme ...

One could adapt this for many other uses ...

Bollinger Band - Last-Extreme / for 20-bar, 2-SD

PSum := Ref(Sum(Typ(),19),-1);

MA := (PSum+High)/20;
SOS :=
Power(Ref(Typ(),-19)-MA,2) +
Power(Ref(Typ(),-18)-MA,2) +
Power(Ref(Typ(),-17)-MA,2) +
Power(Ref(Typ(),-16)-MA,2) +
Power(Ref(Typ(),-15)-MA,2) +
Power(Ref(Typ(),-14)-MA,2) +
Power(Ref(Typ(),-13)-MA,2) +
Power(Ref(Typ(),-12)-MA,2) +
Power(Ref(Typ(),-11)-MA,2) +
Power(Ref(Typ(),-10)-MA,2) +
Power(Ref(Typ(),-9)-MA,2) +
Power(Ref(Typ(),-8)-MA,2) +
Power(Ref(Typ(),-7)-MA,2) +
Power(Ref(Typ(),-6)-MA,2) +
Power(Ref(Typ(),-5)-MA,2) +
Power(Ref(Typ(),-4)-MA,2) +
Power(Ref(Typ(),-3)-MA,2) +
Power(Ref(Typ(),-2)-MA,2) +
Power(Ref(Typ(),-1)-MA,2) +
Power(High-MA,2);
HiSD := Sqrt(SOS/20);

MA := (PSum+Low)/20;
SOS :=
Power(Ref(Typ(),-19)-MA,2) +
Power(Ref(Typ(),-18)-MA,2) +
Power(Ref(Typ(),-17)-MA,2) +
Power(Ref(Typ(),-16)-MA,2) +
Power(Ref(Typ(),-15)-MA,2) +
Power(Ref(Typ(),-14)-MA,2) +
Power(Ref(Typ(),-13)-MA,2) +
Power(Ref(Typ(),-12)-MA,2) +
Power(Ref(Typ(),-11)-MA,2) +
Power(Ref(Typ(),-10)-MA,2) +
Power(Ref(Typ(),-9)-MA,2) +
Power(Ref(Typ(),-8)-MA,2) +
Power(Ref(Typ(),-7)-MA,2) +
Power(Ref(Typ(),-6)-MA,2) +
Power(Ref(Typ(),-5)-MA,2) +
Power(Ref(Typ(),-4)-MA,2) +
Power(Ref(Typ(),-3)-MA,2) +
Power(Ref(Typ(),-2)-MA,2) +
Power(Ref(Typ(),-1)-MA,2) +
Power(Low-MA,2);
LoSD := Sqrt(SOS/20);

MA := (Psum+(O+H+L)/3)/20;

MA + HiSD*2;
MA;
MA - LoSD*2

Source / From: TOP
Metastockusers[at]yahoogroups[dot]com

Equis and MetaStock® and MetaStock Professional® are registered trademarks of Equis International. Achelis Binary Wave®, The DownLoader®,
Expert Advisor®, OptionScope®, Quotecenter® and Smart Charts® are trademarks of Equis International, a Thomson Reuters company.