|
|
How to handle time function?
Last post 05-26-2007, 12:36 by patt. 5 replies.
-
05-24-2007, 12:46 |
-
patt
-
-
-
Joined on 09-08-2006
-
-
Posts 10
-
-
|
How to handle time function?
I would like to plot an indicator for intraday chart, starting at the specific timing. Here is the code :
Dy:=Input ("Day ",1,31,1);
Mo:=Input ("Month ",1,12,1);
Yr:=Input ("Year ",2005,2010,2007);
Hr:=Input ("Hours 01 - 24",1,24,9);
Mn:=Input ("Minutes 00 -59",00,30,30);
Prd:=Input ("LookBack ",3,25,7);
X:=BarsSince(DayOfMonth()=Dy AND Month()=Mo AND Year()= Yr AND Hour()=Hr AND Minute()=Mn);
MyHigh::= HighestSince(1,x=0,H);
Plt := MyHigh*ATR(Prd);
Plt ;
The starting point sometime works but often doen't.
Another pont is : what should I do if I have more than 6 inputs since this is over the limit .
Thanks for your advice.
|
|
-
-
05-24-2007, 23:01 |
-
wabbit
-
-

-
Joined on 10-29-2004
-
Perth, Western Australia
-
Posts 1,634
-
-
|
Re: How to handle time function?
Patt, A common problem when people use the "=" comparison is they forget that very rarely will this ever be true, so their code often fails. With respect to dates, if there is not a bar on the chart with exactly the same date and time information that you have in your filter, the equality condition will never be met. You need to ensure you trap all of the other possibilities too: |
Dy:=Input ("Day ",1,31,1); Mo:=Input ("Month ",1,12,1); Yr:=Input ("Year ",2005,2010,2007); Hr:=Input ("Hours 01 - 24",1,24,9); Mn:=Input ("Minutes 00 -59",00,30,30); Prd:=Input ("LookBack ",3,25,7);
x:= (Year() > yr) OR (Year() = yr AND Month() > mo) OR (Year() = yr AND Month() = mo AND DayOfMonth() > dy) OR (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() > hr) OR (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() = hr AND Minute() >= mn);
MyHigh:= HighestSince(1,barssince(x)=0,H); Plt:=MyHigh*ATR(Prd); Plt;
|
Untested.... You might want to reconsider the barssince() condition too? I don't think the code is doing what you expected it to? You might want to try cum(isdefined(x))=1 instead? Hope this helps. wabbit
MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
05-25-2007, 10:42 |
-
patt
-
-
-
Joined on 09-08-2006
-
-
Posts 10
-
-
|
Re: How to handle time function?
This help a lot. I will look around and might come back for more questions :-)
|
|
-
05-25-2007, 13:31 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: How to handle time function?
Patt, your working code solution is waiting for you here.
wabbit:|
Dy:=Input ("Day ",1,31,1); Mo:=Input ("Month ",1,12,1); Yr:=Input ("Year ",2005,2010,2007); Hr:=Input ("Hours 01 - 24",1,24,9); Mn:=Input ("Minutes 00 -59",00,30,30); Prd:=Input ("LookBack ",3,25,7);
x:= (Year() > yr) OR (Year() = yr AND Month() > mo) OR (Year() = yr AND Month() = mo AND DayOfMonth() > dy) OR (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() > hr) OR (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() = hr AND Minute() >= mn);
MyHigh:= HighestSince(1,barssince(x)=0,H); Plt:=MyHigh*ATR(Prd); Plt;
|
There are a number of reasons why the code above cannot work:
1) Six Input function errors;
2) Invalid variable name "mo" - a variable cannot be assigned a name that matches the parameters reserved for use in formulas, mo() = Momentum;
3) The variable "x" does not signal the start of the Time & Date period, but rather the whole period since, and this won't work effectively with the HighestSince() function;
4) The BarsSince() function is not only unnecessary, but also introduces unwanted null (N/A) bars into the plot.
Hope this helps.
jose '-)
MetaStockTools.com
|
|
-
05-26-2007, 12:36 |
-
patt
-
-
-
Joined on 09-08-2006
-
-
Posts 10
-
-
|
Re: How to handle time function?
Jose, Thanks for the solution.
|
|
|
|