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

Notification

Icon
Error

Options
Go to last post Go to first unread
Vega  
#1 Posted : Tuesday, April 10, 2007 5:36:21 AM(UTC)
Vega

Rank: Member

Groups: Registered, Registered Users, Subscribers
You have been a member since:: 4/4/2007(UTC)
Posts: 11

Hello again reuters&metastock community, these are very likely

very basic question for more experienced metastock programmer,

but with red face I´ll turn to your expert advice>


1. Using explorer how can I modify time functions. I explored formula primer, but

did´t find it. For example if you have simple Cross(Stoch(21,3),20) formula. If I would like

to know if stock has crossed this function let´s say ie. during last 5 days ?


2. What about if one want to show if both of these has occured ie. in last 5 days in expert chart or one could prefer to see if Stock ie. crossed first and later RSI did the same ?

Cross(Stoch(5,3),20)

AND

Cross(RSI(14),30)


3.

Is there any more sofisticated way to write this simple formula as adding
all of those macd crosses ?

Cross(Stoch(21,3),20)
AND
Cross(Mov(MACD(),21,E),MACD())
OR
Cross(Mov(MACD(),13,E),MACD())
OR
Cross(Mov(MACD(),8,E),MACD())
OR
Cross(Mov(MACD(),5,E),MACD())









wabbit  
#2 Posted : Tuesday, April 10, 2007 6:29:01 AM(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)
Vega,

Have a look at the Alert() function. It serves to "extend' the period when a condition is true. For example Alert(Cross(Stoch(21,3),20),5) will return a value of TRUE on the bar when the cross event occurred and for the next four bars after it (total five bars).

Be warned though, this code will not tell you if the Stoch(20,3) is still above the threshold, just that it crossed up through the threshold in the last 5 bars. This is why yuo often see Cross() events written as:

x:=Stoch(20,3)>20;
event:=x and Alert(x=0,5);

which says the Stoch() must be above the threshold and some time in the last five bars the Stoch() must have been below the threshold; it is a more 'precise' way to deal with Cross() events.


There is a lot of learning here. Please take some to digest the information and ask any questions if you need.


wabbit [:D]




minnamor  
#3 Posted : Tuesday, April 10, 2007 11:14:31 PM(UTC)
minnamor

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 126
Location: Italy

You can write the explorer so as to show both the position and the number of bars since trigger. The code would be:

Stoch(21,3)>20 + (barssince(Cross(Stoch(21,3),20))/10000).

Hence, if trigger was, say, 3 days ago, the explorer would yield 1.0003.

Maurizio

Vega  
#4 Posted : Thursday, April 12, 2007 6:08:11 AM(UTC)
Vega

Rank: Member

Groups: Registered, Registered Users, Subscribers
You have been a member since:: 4/4/2007(UTC)
Posts: 11

Thank you both for your answer,

I found that this metastock code is actually pretty interesting, perhaps something
that move novicer can learn.

Just a one more question, I found explorer pretty nice to look at certain techical event at one eye for so many stocks. I wrote this code meaning in explorer it would simply plot +1 if Cross 14RIS30 has occured or +1 if Cross 70RSI14 has occured.

Could one tell me what´s wrong with this code - I received error message "column `A` expected", but help didn´t recognice or adviced this error more exact information.

Colunn A
a:=If Cross(RSI(14),30) AND Cross(70,RSI(14)) ,1,-1);
a;

I would not prefer to split buy&sell signal for 2 different columns (A and B),
is this possible at all ?

Exactly the same way as
Filter CoiB

ColumnB

filter CoiB

long>

{colB: Buy}

EL:=Cross(Stoch(14,1),20);

CL:=Cross(80,Stoch(14,1)) OR Stoch(14,1)<20;

ES:=Cross(80,Stoch(14,1));

CS:=Cross(Stoch(14,1),20) OR Stoch(14,1)>80;

State:=If(Cum(1)=1,0,If(EL,1,If(ES,-1,If((CL AND PREV=1) OR (CS AND PREV=-1),0,PREV))));

State=1 AND Ref(State,-1)<1

short>

{colB: Sell}

EL:=Cross(Stoch(14,1),20);

CL:=Cross(80,Stoch(14,1)) OR Stoch(14,1)<20;

ES:=Cross(80,Stoch(14,1));

CS:=Cross(Stoch(14,1),20) OR Stoch(14,1)>80;

State:=If(Cum(1)=1,0,If(EL,1,If(ES,-1,If((CL AND PREV=1) OR (CS AND PREV=-1),0,PREV))));

State=-1 AND Ref(State,-1)>-1






*PP  
#5 Posted : Thursday, April 12, 2007 10:00:50 AM(UTC)
*PP

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/1/2006(UTC)
Posts: 135
Location: Romania

hi Vega,

Column A
a:=If (Cross(RSI(14),30) OR Cross(70,RSI(14)) ,1,-1);
a;

replace "AND" with "OR" and don`t forget to open parenthesis after if function

cheers

Vega  
#6 Posted : Thursday, April 12, 2007 6:45:00 PM(UTC)
Vega

Rank: Member

Groups: Registered, Registered Users, Subscribers
You have been a member since:: 4/4/2007(UTC)
Posts: 11

Hi PP,

What about if one want to show if both of these has occured ie. in last 5 days in expert chart or one could prefer to see if Stock ie. crossed first and later RSI did the same ?

Cross(Stoch(5,3),20)

Where are the periods, not hunting special bars just for example if using explorer and want to see only those where this "certain event" has happened in last 5 days ?

I tried to add , 5 after formula, but once again it gave some weird errors.
wabbit  
#7 Posted : Thursday, April 12, 2007 6:53:00 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)
In the MetaStock language, when a condition is TRUE it equates to a value of 1 (actually, its non-zero but thats another discussion) and if a condition is FALSE it equates to a value of zero. You can use TRUE and FALSE in your code, but its more efficient to use 1 and 0.

As MS presents us with these numerical representations of TRUE and FALSE, sometimes it is betteer or more efficient ot continue working with numbers as numbers e.g.

If (Cross(RSI(14),30) OR Cross(70,RSI(14)) ,1,-1);

returns values of 1 if the condition is TRUE or -1 if the condition is FALSE. I don't see any benefit here to redefine TRUE and FALSE, so we rewrite as:

Cross(RSI(14),30) OR Cross(70,RSI(14))

which will return a value of 1 when the condition is TRUE and 0 when FALSE.

If you really need the values to be 1 when TRUE and -1 when FALSE (for some obscure reason), we treat the expression as a number and rewrite it thus:

2*(Cross(RSI(14),30) OR Cross(70,RSI(14))-1

to give us values of 1 and -1.

Mathematical expressions are very slightly faster than If() functions in MS. For many people this is not very important, but when traders are in RT on ticks, evey millisecond saved, helps.


Hope this helps.

wabbit [:D]

wabbit  
#8 Posted : Thursday, April 12, 2007 7:03:35 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)
Vega wrote:
Hi PP,
What about if one want to show if both of these has occured ie. in last 5 days in expert chart or one could prefer to see if Stock ie. crossed first and later RSI did the same ?


Does it matter which event happens first?

Lets assume you want one Cross event first (condition1) followed by the other Cross event (condition2) then look for the latest Cross and use the Alert() function to find if the first Cross event happened within your time frame:

condition2 and Alert(condition1,timeperiods)

If you dont care which event happend first, you have code for both:

(condition
2 and Alert(condition1,timeperiods)) or (condition1 and Alert(condition2,timeperiods))


BTW: I would have a very close look at the computation of the RSI() and STOCH(). Without wanting to start a long argument, they are essentially the same thing, so looking for one Stoch() event to be followed by an RSI() event is like asking the same question twice. I strongly recommend you look into these indicators.

...and another thing. I strongly recommend you get out of the habit of talking about bars as days. At sometime later in your trading you might start trading longer or shorter timeframes, if your mind is stuck that one bar is one day it is a hard habit to break. Think of bars as bars now, don't pick up the bad habits. So in fact you are looking for, "What about if one want to show if both of these has occured ie. in last 5 BARS in expert chart " This line of thinking can now be applied to a weekly chart, a 60 minute chart, even a tick chart, and of course the daily chart.


Hope this helps.

wabbit [:D]

Vega  
#9 Posted : Thursday, April 12, 2007 7:12:50 PM(UTC)
Vega

Rank: Member

Groups: Registered, Registered Users, Subscribers
You have been a member since:: 4/4/2007(UTC)
Posts: 11

Hello wappit,

PP gave me pretty clear example how to work with 1- and +1, but a bit another side of the wall using same formula and reading formula primer there´s actually no hardly any examples how to work with timely functions. For example>

If using this formula in explorer>

Cross(RSI(14),30)

It gives me all the stocks in certain portofolio where event has occured, even, it
has occured 3 monts ago. One might need to see only those where it has happened ie. in last 5 hours or as in my case during last 5 days.

Regards,

Vega
wabbit  
#10 Posted : Thursday, April 12, 2007 8:21:29 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)
Vega wrote:
If using this formula in explorer>

Cross(RSI(14),30)

It gives me all the stocks in certain portofolio where event has occured, even, it
has occured 3 monts ago. One might need to see only those where it has happened ie. in last 5 hours or as in my case during last 5 days.


This is not quite right. The code above, if used in the explorer will return those stocks when the Cross() event has occurred on the last BAR of the data. If this stock hasn't traded for three months or three years, it will still be returned in the results list because the Cross() event was still true for the last bar of the data.

If you want to find out when the most recent Cross() event took place you need to do something more akin to:

{ColA - ElapsedBars}
x:=Cross(RSI(14),30);
barssince(x);

{filter}
ColA>=0;

This will give you the number of bars that have elapsed since the Cross() event was true, but again, the stock that stopped trading three years ago but is still listed in your data will be returned by this exploration. To exclude those stocks that have not traded in some recent period, there are a number of methods which are well covered in other threads of the Forum.


I hope this helps.

wabbit [:D]

*PP  
#11 Posted : Friday, April 13, 2007 3:29:50 AM(UTC)
*PP

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/1/2006(UTC)
Posts: 135
Location: Romania

Vega wrote:
Hello wappit,

If using this formula in explorer>

Cross(RSI(14),30)

It gives me all the stocks in certain portofolio where event has occured, even, it
has occured 3 monts ago. One might need to see only those where it has happened ie. in last 5 hours or as in my case during last 5 days.

Regards,

Vega

Vega,

To solve this problem the most simple solution is:

Column A

Alert(cross(rsi(14),30),5)

and in Filter column:

day:= 13; {for today for example}
month:= 4;
year:= 2007;
v1:= If(day = DayOfMonth(),1,0);
v2:= If(month = Month(),1,0);
v3:= If(year = Year(),1,0);
v1=1 AND v2=1 AND v3=1

enable filter and scan the stocks. The explorer will return 1 only if RSI has crossed above 30 in the last 5 days and the stock was traded today, if it was not traded in the last day it will be rejected and if it was traded but the condition was not met in the last 5 days will return 0. With this method u can scan whatever day u want by changing the date that u want in the Filter column and also changing the date in exploration options to be the same as the date in the filter column (here the date is usually set as "Moste recent date")

wabbit  
#12 Posted : Friday, April 13, 2007 6:07:05 AM(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)
Guys,

As mentioned elsewhere on this forum, Richard Dale has generously posted his dates plugin that makes excluding non-trading stocks a piece of cake. Download his free product from:
http://www.tradernexus.com/nexusdate/
*PP  
#13 Posted : Friday, April 13, 2007 6:19:11 AM(UTC)
*PP

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/1/2006(UTC)
Posts: 135
Location: Romania

wabbit wrote:
Guys,

As mentioned elsewhere on this forum, Richard Dale has generously posted his dates plugin that makes excluding non-trading stocks a piece of cake. Download his free product from:
http://www.tradernexus.com/nexusdate/
uasish  
#14 Posted : Friday, April 13, 2007 12:46:44 PM(UTC)
uasish

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/13/2005(UTC)
Posts: 170

Thanks: 7 times

Wabbit,

Learned to-day ,so simple mathametical expression instead of if() .

"2*(Cross(RSI(14),30) OR Cross(70,RSI(14))-1"

Asish

Vega  
#15 Posted : Friday, April 13, 2007 3:25:40 PM(UTC)
Vega

Rank: Member

Groups: Registered, Registered Users, Subscribers
You have been a member since:: 4/4/2007(UTC)
Posts: 11

Hello guys and great weekend all!,

Expired stocks were not an issue, but thank you for let me know how to avoid seeing stocks which are not trading anymore (even, I wonder why one would have those stocks still in his database).

Wappitt, using End-Of-Day data, I added ie. these for my explorer>

{ColC - ElapsedBars}
x:=Cross(CCI(14),-100);
BarsSince(x);

Filter>

colC

This, what about if one want to see if function is true or false. I believe starting to looks alike something I was searching.

{ColC - ElapsedBars}
x:=Cross(CCI(14),-100)) 1,0; (ie. adding true or false signals)
BarsSince(x);

Filter>

colC

Regards,

Vega


*PP  
#16 Posted : Saturday, April 14, 2007 1:33:33 AM(UTC)
*PP

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/1/2006(UTC)
Posts: 135
Location: Romania

Vega wrote:
Hello guys and great weekend all!,

This, what about if one want to see if function is true or false. I believe starting to looks alike something I was searching.

{ColC - ElapsedBars}
x:=Cross(CCI(14),-100)) 1,0; (ie. adding true or false signals)
BarsSince(x);

Filter>

colC

Regards,

Vega


Vega, the x event will return 1 or 0 by itself; u do not need to add true or false signals. More, u did not corectly added true or false signals because u forgot to put the if function: if(cross....,1,0).

wabbit  
#17 Posted : Saturday, April 14, 2007 10:09:50 AM(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)
Vega,

As already pointed out, you forgot the If() component of the code too.

In future, please do not retype code or try to give us a "representation" of what you are trying to do, it just leads to extra difficulties that we just don't have the time to solve; instead, copy the code from MS and paste it into a post. This way we get to the code that is ACTUALLY running and this aids fault-finding and bug-hunting.

It helps us help you.


wabbit [:D]
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.