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

Notification

Icon
Error

Options
Go to last post Go to first unread
alexstox  
#1 Posted : Monday, December 12, 2011 1:14:00 AM(UTC)
alexstox

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/6/2011(UTC)
Posts: 8

Hello. Dear professionals please help in 2 tasks. How to describe these 2 occurrence in Metastock formulas. 1. If I want to trade intra-day and have HOURLY or 5-MINUTES charts, how could I get PREVIOUS DAY CLOSE in formula? 2. I want to trade only from 8.00 AM to 8.00 PM (for example). How can I write this condition to BUY or SELL rules?
alexstox  
#2 Posted : Tuesday, December 13, 2011 12:33:41 AM(UTC)
alexstox

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/6/2011(UTC)
Posts: 8

help please
mstt  
#3 Posted : Tuesday, December 13, 2011 1:29:28 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi alextox

Try this.

{Day CLOSE}
Day:=DayOfWeek();
NewDay:= Day <> ValueWhen(2,1,Day);
DayClose:=ValueWhen(1,NewDay,ValueWhen(2,1,C));
DayClose;

Just in case the Forum decides to mangle my code here's what it says in English.

Day:=day-of-week
NewDay:= Day not equal previous bar's day
DayClose:= ValueWhen(1, NewDay, CLOSE for previous bar)
plot DayClose

This code can easily return the wrong price IF your chart is at a higher periodicity than the underlying data. If chart and underlying data are the same periodicity then there's no problem as far as I can see. The formula should still function correctly on stock data with time stamps coinciding with normal trading hours (no time stamps near midnight). On 24 hour data you very likely to have a problem. Test the formula and see if it returns the same daily CLOSE as several different chart periodicities.

Roy
alexstox  
#4 Posted : Wednesday, December 28, 2011 9:58:31 AM(UTC)
alexstox

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/6/2011(UTC)
Posts: 8

thank you for help. 1. Would you be so kind to explain me in details what expression ValueWhen(2,1,Day) mean? You wrote that it's "previous bar's day". But I cant understand why. -- it returns DayOfWeek if 1 occurs second time in DayOfWeek? =(((( 2. When I just put your Day CLOSE condition to BUY rules = it buy once, when any rules to SELL rules = it buy at every time after selling one. For example: if I want to sell at 16:00 - it will sell and buy new one at this time.
mstt  
#5 Posted : Wednesday, December 28, 2011 2:28:28 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Hi alextox

1. ValueWhen(2,1,Day) is functionally the same as Ref(Day,-1) - it returns Day delayed by one bar.

2. From memory the code I provided returned the CLOSE for the previous days trading. How you use that information is up to you. I don't understand what it is that you are now asking.

Roy

Users browsing this topic
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.