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

Notification

Icon
Error

Options
Go to last post Go to first unread
Flash  
#1 Posted : Tuesday, June 3, 2008 5:58:58 PM(UTC)
Flash

Rank: Newbie

Groups: Registered, Registered Users
Joined: 3/15/2008(UTC)
Posts: 5

Hi,

I am trying to learn how to use the MDK. I have written a few indicators that I have acyually been able to place in MeatStock. I am having a hard time trying to write the following program. I want to use the crossing of MACD and its signal line to create a table in the Expert Avdvisor. Below is an example of what I am trying to do.

S0 S3

S1 S2

B0 B2 S4

-------------------------------------------------------------------------------------------------------------------------------------------Zero Line

B1 B3

According to Gerald Appel, a valid buy signal occurs when the MACD has crossed from above zero

to below zero since its last buy signal. Therefore, in the above graph, the only valid buy signals are B1 and B3.

I am unable to write a program that goes into the past to find out how much the stock moved between B1 and S2 and B3 and S4. I would like to find the percent move the closing price made for all the days between B1 and S2 and the percent move the closing price made for al the days in between B3 and S4. Thisis only a short version as I would like to do this for four years of data.

Once that is done, I would like to find the minimum, median and maximum % move the stock made and place it in the expert advisor or where ever any body thinks it belongs.

Any input would be greatly appreciated,

Flash

wabbit  
#2 Posted : Tuesday, June 3, 2008 7:04:47 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)
Hi Flash,

Welcome to the Forum.

Must this be completed in the MDK? You could achieve the aim of the project using MSFL and drawing an indicator line in a subwindow on the chart?

I don't have a lot of time now to code all the niceties, but his might get you on the way, and the concept translate easily to the external codes too.

Code:
data:=CLOSE;
myMACD:=MACD();
trigger:=Mov(myMACD,9,e);

x:=myMACD>trigger;
buy:=x and alert(x=0,2);
x:=myMACD<trigger;
sell:=x and alert(x=0,2);

entryPrice:=valuewhen(1,buy,data);

pct:=if(barssince(buy)<barssince(sell), 100*(data-entryPrice)/entryPrice, 0);

{plot}
pct;


This code is only a quickie, but hopefully give you some ideas about how to achieve you aim. You can add in there that on the most recent buy signal, tests for counting if its the first below the zero macd line since the previous sell signal etc...

Let us know how you progress.


wabbit [:D]

Flash  
#3 Posted : Tuesday, June 10, 2008 1:40:48 PM(UTC)
Flash

Rank: Newbie

Groups: Registered, Registered Users
Joined: 3/15/2008(UTC)
Posts: 5

Hi Wabbit,

Thank you for the input; however I am do not think that it will work. I need somthing that will go into the past several occurances.

S0 S3

S1 S2

B0 B2 S4

-------------------------------------------------------------------------------------------------------------------------------------------Zero Line

B1 B3

According to Gerald Appel, a valid buy signal occurs when the MACD has crossed from above zeroto below zero since its last buy signal. Therefore, in the above graph, the only valid buy signals are B1 and B3.

I need somthing that will allow me to access every point between B1 and S2 and B3 and S4. I need every closing price between those two data points. Also, keep in mind, that this will go about four years in the past so there will be a lot of these different points to get closing prices for .

Thanks,

Flash

Branden Russell  
#4 Posted : Tuesday, June 10, 2008 1:51:49 PM(UTC)
Branden Russell

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/28/2005(UTC)
Posts: 276
Location: Salt Lake City, UT

I haven't used the MetaStock Formula Language in far too long to tell you whether you can do this in that or not. With an MSX DLL, you can pass in all the data you need (Open, High, Low, Close, Volume). As you do your calculation, the data is in an array and you can go back data points all the way until the beginning of the data. So you can use that to calculate the next point. Edit: You can try asking in the Formula section of the forums for help about using the built in MetaStock Formula Language if you think you can do it in that.
wabbit  
#5 Posted : Tuesday, June 10, 2008 7:04:13 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)
Flash wrote:
Thank you for the input; however I am do not think that it will work. I need somthing that will go into the past several occurances.

<snip>

According to Gerald Appel, a valid buy signal occurs when the MACD has crossed from above zeroto below zero since its last buy signal. Therefore, in the above graph, the only valid buy signals are B1 and B3.

I need somthing that will allow me to access every point between B1 and S2 and B3 and S4. I need every closing price between those two data points. Also, keep in mind, that this will go about four years in the past so there will be a lot of these different points to get closing prices for.


Did you try the code? Instead of telling us why you don't think something will not work, do a proper test and tell us how it actually does not meet the expectations. Show actual results versus expected results, not speculation.

I mentioned in my post above, I didn't have time to code all of the niceties for you. All you had to do was add the code to find the first buy signal below the MACD zero line.

Code:
data:=CLOSE;
myMACD:=MACD();
trigger:=Mov(myMACD,9,E);

{MACD LE and LX criteria}
x:=myMACD>trigger;
buy:=x AND Alert(x=0,2);
x:=myMACD<trigger;
sell:=x AND Alert(x=0,2);

{count and reset}
count:=Cum(buy);
reset:=myMACD>0;
counter:=count-ValueWhen(1,reset,count);

{first LE where MACD is below zero}
buy:=buy AND counter=1;

{price for comparison}
entryPrice:=ValueWhen(1,buy,data);
pct:=If(BarsSince(buy)<BarsSince(sell), 100*(data-entryPrice)/entryPrice, 0);

{plot}
pct;



wabbit [:D]

Flash  
#6 Posted : Wednesday, June 11, 2008 12:28:49 PM(UTC)
Flash

Rank: Newbie

Groups: Registered, Registered Users
Joined: 3/15/2008(UTC)
Posts: 5

Hi Wabbit;

I am sorry if I offended you somehow. I have had my fun meter pegged trying to learn how to use the MDK. I cannot tell you how how many hours I have spent with this thing. It is very frustrating not understanding why some things do not work and other things do.

Anyway, I do not know the MetaStock formula language that well and it would have taken me a long time to do what you did.

Thanks for all,

Flash

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.