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

Notification

Icon
Error

Options
Go to last post Go to first unread
Michel79  
#1 Posted : Sunday, November 06, 2011 4:48:03 AM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Hi, I just wanted to SUM a couple of rate of changes, but its not working (yet). Whats wrong about this: SUM(ROC(C, 5, %), ROC(C, 15, %)), ROC(C, 25, %)) It says: This variable or expression must contain only constant data. Thanks. Michel
jjstein  
#2 Posted : Sunday, November 06, 2011 11:14:34 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
One thing at a time...

If you want to add the Rate-of-Change together for different periods -- a week, 3 weeks and 5 weeks -- plot this:

ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%);


If you want to SUM() them, it will take the result for "x" number of days, and add them (not sure why you'd want this, though it might give an indication of Trend):

x:=10;
MyROC:=ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%);
Sum(MyRoc,x);


Hope that clarifies things. As a further example, if you wanted an average of the three ROC()'s, you would do it manually, rather than use MOV():

MyROC:=ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%);
MyROC/3;


MSFL (MetaStock Formula Language) isn't QUITE like Excel...but it can be helpful to think of MSFL "worded" functions as automatically stretching back through the data, as though you were working at the bottom of a column in a spreadsheet, while the simpler functions like "+", ">", etc. operate on individual variables, like "MyROC" in the example above.

Also, download and review the Formula Primer, if you haven't already.

Michel79  
#3 Posted : Sunday, November 06, 2011 2:42:05 PM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Thanks Johnatan. I needed the 1st one and learned some nice ways to deal with formula's. Got the manual. It's a formula that Gerald Appel calls in one of his books. It should give some good results on NASDAQ COMPOSITE when buying when crossing +4% and selling when crossing from above 4% downward. If would like to test this one on different indices. Would the buy order in system test be like: CROSS (ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%), 4) AND C>(C, -1) I thought the C>(C, -1) would be a way to avoid that it buys when coming down through 4%, and only buys when it actually is going upward. I would appreciate this last piece of the puzzle. grtz Michel
jjstein  
#4 Posted : Sunday, November 06, 2011 4:44:16 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Well, it seemed to do better on the COMP at -4%, and on the NDX at +4%, from what I could tell. Did he say anything about stops, smoothing, etc?

MyROC:=ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%);
Buy:=Cross(MyROC,4);
Sell:=Cross(4,MyROC);

init:=Cum(IsDefined(Buy+Sell))=1;
Season:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
Signal:=If(Season<>Ref(Season,-1),Season,0);

Signal; {1=Buy -1=Sell}


Michel79  
#5 Posted : Monday, November 07, 2011 10:52:08 AM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Hi thank you. The first part gives same results as my formula. Where should i put the last 4 rules? In the buy and sell section? And maybe you can explain a little bit about their meaning. :) Thanks. Appel doesn't call any other rules. grtz Michel
jjstein  
#6 Posted : Monday, November 07, 2011 12:48:26 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
>>Where should i put the last 4 rules?
I only see two -- The ROC formula and the "Buy if closing up from yesterday". If you list the others, I can put them in.


>>In the buy and sell section?
Yes -- the BUY signal must be set with any/all conditions.


>>And maybe you can explain a little bit about their meaning.
OK, lesson time!<g> I've added comments and some flexible inputs to the indicator; let me know if it's too complex, and I'll simplify it:


_Test
{ Flexible Inputs }
Display:=Input("Display 0=Indicator 1=Signal 2=Season",0,2,1);
Level:=Input("Level",-10,10,4);
Pd1:=Input("Short",1,100,5);
Pd2:=Input("Medium",1,100,15);
Pd3:=Input("Long",1,100,25);

{ Criteria }
MyROC:=ROC(C,Pd1,%)+ROC(C,Pd2,%)+ROC(C,Pd3,%);

{ Conditions }
Buy:=Cross(MyROC,4) and C>ref(C,-1);
Sell:=Cross(Level,MyROC);

{ GENERIC: Filter repeat signals, 1=Buy, -1=Sell }
init:=Cum(IsDefined(Buy+Sell))=1;
Season:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Display }
If(Display=1,Signal,If(Display=2,Season,MyROC));


Now, from the above Indicator, here is what you can do by creating and ATTACHing an Expert Advisor:
UserPostedImage

*************
EXPERT TABS
*************
TRENDS -- Use RIBBON button to set color. I set "Pattern" to (None).
------------
Bullish: FmlVar("_Test","Season")=1; { Ribbon=Green }
Bearish: FmlVar("_Test","Season")=-1; { Ribbon=Red }
Neutral: { Ribbon=Yellow }

HIGHLIGHTS
-------------------
Buy: FmlVar("_Test","Season")=1;
Sell: FmlVar("_Test","Season")=-1;
Default: 1

SYMBOLS -- Select symbol and color from the "Graphic" tab.
---------------
Buy: FmlVar("_Test","Signal")=1;
Sell: FmlVar("_Test","Signal")=-1;


Michel79  
#7 Posted : Monday, November 07, 2011 2:12:20 PM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Your efforts are highly appreciated. I'm not such a math-type, though. I got the formula in the tester so thank you for that (although still cant test on indices). I also tried to prepare the expert advisor, but its not taking the input under Trend. It says: "No indicator names in the indicator builder contain this text."
jjstein  
#8 Posted : Monday, November 07, 2011 2:55:35 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
You must have changed the name of the Indicator...

In the examples, the name of the Indicator is "_Test" (without the quotes).

Whenever an indicator or the variables within it are called from elsewhere -- another Indicator, Expert, Exploration or System Test -- you use either the FML() or FMLVAR() functions (see docs).

FmlVar("_Test","Signal")=1;

In this case, "_Test" is the name of the indicator, and "Signal" is the variable.

You're free to change "_Test" to anything you want, but then you must change the examples to be consistent.


Michel79  
#9 Posted : Tuesday, November 08, 2011 12:33:12 PM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Ok i got the indicator, expert advisor running, thank you. 1 leftover: I am not so sure if i put the data right for the system tester. I put the whole formule in the buy section. Subdividing the data will errors (ie., sell line at sell tab). MyROC:=ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%); Buy:=Cross(MyROC,4); Sell:=Cross(4,MyROC); init:=Cum(IsDefined(Buy+Sell))=1; Season:=ValueWhen(1,Buy-Sell0 OR init,Buy)*2-1; Signal:=If(SeasonRef(Season,-1),Season,0); Signal; {1=Buy -1=Sell} Thanks. BTW i get an error message when trying to plot the results: "Signal markers will not be drawn because the base security is not visible" Grt Michel
jjstein  
#10 Posted : Tuesday, November 08, 2011 1:38:11 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
1. It's fine to put the whole formula in the tabs, but you need to change to last lines in the tabs to:

BUY tab: Signal=1; {Positive one}
SELL tab: Signal=-1; {Negative one}


2. "Signal markers will not be drawn because the base security is not visible"

You must have deleted it from the chart. Open the chart, right-click on a blank area and left-click on "Display Base Security".

Then you should be able to plot the results. You don't need to re-run the System Test.


Michel79  
#11 Posted : Wednesday, November 09, 2011 11:33:06 AM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Hi, Testings working well. But i actually don't get the nice results mr. Appel presents in his book, based on the +4% buy-sell strategy. My tests never are similar like these presented data: Buy And Hold Nasdaq Comp. 2000 -39,3 2001 -21,1 2002 -31,5 2003 +50 Triple Moment Timing Model (Appel) 2000 +8,6 2001 +27,5 2002 +4,9 2003 +21,5 I was wondering if you do get these results and the error lies in my settings...? Or is the book possibly showing some nonsense results, which is hard to believe obviously :/. From taking a closer look on a presented graph in this same book, i see that Appel not always seems to sell at crossing +4% the first time and sometimes just holds position, till theres profit and than sells when it crosses 4% again. So alhtought he says its black and white-like trading on 4%, he himselfs is not keeping to it and probablys bases his sell-conclusion on other parameters. Maybe you are able to come to the nice results shown above, hope to hear from you. Thanks again. grtz Michel
jjstein  
#12 Posted : Wednesday, November 09, 2011 3:33:59 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
The System Tester gave me these results:

$COMP
2000: -3.0%
2001: +9.5%
2002: -32.1%
2003: +13.0%


>>I was wondering if you do get these results and the error lies in my settings...?
That's the most likely; re-read and see if you got the formula right, whether he's using a stop-loss, that there is no other criteria mentioned in the comments, etc.


>>From taking a closer look on a presented graph in this same book
You don't always see what you think you do; number measurements are far better.


Michel79  
#13 Posted : Thursday, November 10, 2011 12:11:59 PM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Well, after rereading i notice that he shortly mentions that the ROC's should be positive across all time frames (so ROC 5, 15 and 25). That should rule out some useless buys i guess. Later on he doesn't say this again when he summarizes the rule which is the reason i looked over it. It's probably the solution. I tried to add this to get the right tester, but it isnt working (again). AND(C,5,%)>0, ROC(C,15,%)>0, ROC(C,25,%)>0; Whats the right formula addon? If this is easy for you, can you say as well what to change in expert advisor? Muchos thanks :) Thx again. Michel
jjstein  
#14 Posted : Thursday, November 10, 2011 12:47:54 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Adding the "Positive" condition means the CROSS() needs to be changed to a ">" sign, since the MyROC combo may not happen at the exact time all three ROC's go positive.

You should be able to just "Copy& Paste" this, and the Expert & whatnot will stay the same, IF you used the FMLVAR() to call Indicator variables:

{ Criteria }
MyROC:=ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%);
Positive:=ROC(C,5,%)>0
AND ROC(C,15,%)>0
AND ROC(C,25,%)>0;

{ Conditions }
Buy:=MyROC>4 AND C>Ref(C,-1) and Positive;
Sell:=Cross(4,MyROC);

{ Filter repeat signals, 1=Buy -1=Sell }
init:=Cum(IsDefined(Buy+Sell))=1;
Season:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Plot, manually add Horizontal Lines at +4 and -4 }
MyROC;
UserPostedImage

Michel79  
#15 Posted : Friday, November 11, 2011 7:59:19 AM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

Ok i placed the formula like this in the system tester at both the sell and buy tab: { Criteria } MyROC:=ROC(C,5,%)+ROC(C,15,%)+ROC(C,25,%); Positive:=ROC(C,5,%)>0 AND ROC(C,15,%)>0 AND ROC(C,25,%)>0; { Conditions } Buy:=MyROC>4 AND C>Ref(C,-1) and Positive; Sell:=Cross(4,MyROC); { Filter repeat signals, 1=Buy -1=Sell } init:=Cum(IsDefined(Buy+Sell))=1; Season:=ValueWhen(1,Buy-Sell0 OR init,Buy)*2-1; Signal:=If(SeasonRef(Season,-1),Season,0); Signal; 1 (added this last line, with -1 at the sell tab) My observation tells me that the expert advisor gives right buy and sell timing, which is good and IMO should give some very good equity results from view. But the equity seems to drop back even after i got a Sell signal (and i would have sold position). It should not be possible that the equity from the sell moment drops back (should flat out IMO till i buy again). This can be viewed i.e. after the sell moment of april 2010 in NASDAQ COMP. A further dropback of equity takes place till september although theres no position taken during that time. Is there something looked over in the buy signal i use now? Unfortunately it's too hard for me to identify any errors in most parts of the formula :/. Thanks, i hope we will get to the results from the book..;P Grtz Michel
jjstein  
#16 Posted : Friday, November 11, 2011 10:57:01 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
>>Signal; 1

At the end, if that's not a typo, it should be

BUY: Signal=1;
SELL: Signal=-1;

The System Tester did not give me very good results.

Michel79  
#17 Posted : Monday, November 14, 2011 8:27:06 AM(UTC)
Michel79

Rank: Member

Groups: Registered, Registered Users
Joined: 11/5/2011(UTC)
Posts: 14

I have been thinking a little bit about how it can be that the results are so much different in system test than in Appels book. Last possibility is that Appel is trading on realtime prices and not on the Closing prices we use. Using closing prices causes buying and selling on lagging moments when price jumps/falls already occured. Question: is there a way to do system tests that are based on minute to minute prices? This might change the picture. Gr Michel
jjstein  
#18 Posted : Monday, November 14, 2011 10:23:27 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
>>Question: is there a way to do system tests that are based on minute to minute prices?

I don't know, as I only work with EOD data.

Something else may be amiss; I've not read the book, but the system seems simple and straightforward -- if it required anything fancy, I think it would have been made plain in the text.

If you are sure you haven't misunderstood it, there are two things you could try:

1. Since you are testing the COMP, try the same test in Excel.

2. Write a letter/email to Appel, tell him you are not getting the same results as his book, and ask "Why?". Odds are, you're not the only one, so he may have a ready answer.


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.