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 #

Calendar Days <-> Bar Periods by Jose Silva

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
From: Jose Silva <josesilva22 [at] yahoo [dot] com>
To: equismetastock [at] yahoogroups [dot] com <equismetastock [at] yahoogroups [dot] com>
Date: Sunday, July 30, 2006, 6:43:32 AM
Subject: [EquisMetaStock Group] Calendar days <-> bar periods
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

This MetaStock utility indicator converts chart bar periods to calendar Days/Weeks and vice versa.

Useful for creating indicators such as Moving Averages based on calendar periods rather than the (default) bars.

MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste formula below.



Calendar Days <-> Bar Periods

{ Bars <--> Calendar Week/Day, period converter.

Incorporating Gregorian calendar Week/Day
counter v3.0 - period count is independent
of any missing chart data.

CCopyright 2002~2006 Jose Silva.
The grant of this license is for personal use
only - no resale or repackaging allowed.
All code remains the property of Jose Silva.
http://www.metastocktools [dot] com }

{ User inputs }
pds:=Input("Conversion Periods",1,2520,21);
choose:=Input("[1]Bars -> CalendarPeriods, [2]CalPds ->
Bars",1,2,1);
use:=Input("Calendar Periods: [1]Days, [2]Weeks",1,2,1);
adj:=Input("Week's start: [0]Sunday, [1]Monday",0,1,1);

{ Calendar counter engine }
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0
OR Frac(Year()/400)=0;
y:=Year()*365+Int(Year()/4)
-Int(Year()/100)+Int(Year()/400)-730484;
m:=
If(Month()=2,31-leap,
If(Month()=3,59,
If(Month()=4,90,
If(Month()=5,120,
If(Month()=6,151,
If(Month()=7,181,
If(Month()=8,212,
If(Month()=9,243,
If(Month()=10,273,
If(Month()=11,304,
If(Month()=12,334,
-leap)))))))))));
DayNr:=y+m+DayOfMonth();
adj:=adj+If(DayNr<1,1,2)
-(Frac(Year()/100)=0 AND Frac(Year()/400)<>0);
WkCount:=Int((DayNr-adj)/7)+(Year()>=2000);

{ Choose Days/Weeks }
Cal:=If(use=1,DayNr,WkCount);

{ Bars -> Calendar Days/Weeks, average }
calendar:=Cal-Ref(Cal,-pds);
avgCal:=Cum(calendar)/Cum(IsDefined(calendar));

{ Calendar Days/Weeks -> Bars }
bars:=pds
/((Cal-ValueWhen(1,Cum(1)=1,Cal)+1)/Cum(1));

{ Choose Bars->CalPds or CalPds->Bars }
convert:=If(choose=1,calendar,bars);
avg:=Int(If(choose=1,avgCal,bars)*10+.5)/10;

{ Plot in own window }
Int(convert*10+.5)/10;avg



Source / From: TOP
equismetastock [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.

TradeStation® Pro, TradeStation® 2000i, OptionStation®, SuperCharts®, PowerEditor® and EasyLanguage®
are registered trademarks of TradeStation Technologies, Inc. Other names and marks referred to are the property of their respective owners.

All information provided on this website is for educational purposes only. Trading involves risk, including possible loss of principal and other losses.

Ten i inne materiały na tej stronie zostały zamieszczone zostały jedynie w celach edukacyjnych, nie ponoszę żadnej odpowiedzialno¶ci za ich stosowanie.

Gra na giełdzie i rynkach walutowych (FOREX) niesie ze sob± ryzyko poważnych strat finansowych!