| 
Rank: Advanced Member
 Groups: Registered, Registered UsersJoined: 1/19/2005(UTC)
 Posts: 1,065
 Location: Koh Pha-Ngan, Earth
 
 Was thanked: 2 time(s) in 2 post(s)
 | 
            
	      
                This handy indicator works in a similar way to MetaStock's Ref() function, but uses calendar days (instead of data bars) for its lookback periods. Calendar days lookback is from the last chart bar only.
[code:1:690c50aafc]
==================
Calendar day Ref()
==================
---8<----------------------
{ CalendarDay-based Ref() function v1.0
 ©Copyright 2005 Jose Silva
 For personal use only.
 http://www.metastocktools.com }
{ User inputs }
days:=Input("Calendar Days lookback",0,36500,7);
x:=Input("[1]Open [2]High [3]Low [4]Close [5]WCl [6]Vol",1,6,4);
plot:=Input("Calendar Lookback: [1]Price, [2]Signal",1,2,1);
{ Data Array }
x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,WC(),
 If(x=6,V,C)))));
{ Calendar days counter, available from
 http://www.metastocktools.com/#metastock }
calendar:=Fml("Calendar Day counter");
{ Calendar day CountDown }
countDown:=LastValue(calendar)-calendar;
{ Lookback reference signal }
signalZone:=countDown<=days OR Cum(1)=1;
signal:=signalZone*Alert(signalZone=0,2)
 OR Cum(1)=1;
{ Reference price x calendar days ago }
calRef:=If(signalZone,ValueWhen(1,signal,x),x);
{ Plot on price chart }
If(plot=1,calRef,signal)
---8<----------------------
[/code:1:690c50aafc]
Wishing all a Merry Xmas, and a Happy & Prosperous 2006!
jose '-) |