logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
patt  
#1 Posted : Thursday, May 24, 2007 12:46:14 PM(UTC)
patt

Rank: Member

Groups: Registered, Registered Users
Joined: 9/8/2006(UTC)
Posts: 14

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.
Jose  
#2 Posted : Thursday, May 24, 2007 9:31:02 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Patt, your code fails when the selected date falls on a bar with no data in it (N/A or null bar). I'm unable to post your code solution in this forum due to copyright issues. Please re-post your MetaStock query at the Trader's Consortium MetaStock forum, and I will have a solution ready for you there. jose '-)
wabbit  
#3 Posted : Thursday, May 24, 2007 11:01:42 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
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:

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:=
(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 [:D]

patt  
#4 Posted : Friday, May 25, 2007 10:42:30 AM(UTC)
patt

Rank: Member

Groups: Registered, Registered Users
Joined: 9/8/2006(UTC)
Posts: 14

This help a lot. I will look around and might come back for more questions :-)
Jose  
#5 Posted : Friday, May 25, 2007 1:31:04 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Patt, your working code solution is waiting for you here.
wabbit wrote:
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:=
(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 '-)
patt  
#6 Posted : Saturday, May 26, 2007 12:36:59 PM(UTC)
patt

Rank: Member

Groups: Registered, Registered Users
Joined: 9/8/2006(UTC)
Posts: 14

Jose, Thanks for the solution.
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.