# Optimising System Conditions with Metastock System Tester



## bassmann (3 May 2008)

I have a hypothesis that I may have too many trading conditions in my system strategies that could be optimised by exploring the permutations of my trading rules. My objective is to A) eliminate correlated signals and B) define the best combination of rules in a particular strategy.



My generic strategy consists of something like;



Entry1:=myEntryCondition1;

Entry2:=myEntryCondition2;

Entry3:=myEntryCondition3;

Exit1:=myExitCondition1;

Exit2:=myExitCondition2;

Exit3:=myExitCondition3;



mySignal:=If(Exit1=-1 OR Exit2=-1 OR Exit3=-1,-1,

If(Entry1=1 AND Entry2=1 AND Entry3=1,1,0));



Where 1=Entry and -1=Exit for a long position.



Back to my hypothesis, if I was to eliminate one of these conditions (or run variations on the conditions) then I a may get superior results.



The possible permutations of Entry are true if;

Entry1, Entry2, Entry3 are True 
Entry1, Entry2 are True 
Entry2, Entry3 are True 
Entry1Entry3 are True 
Entry1 is True 
Entry2 is True 
Entry3 is True 


The same can be said for the Exit conditions (and also further combinations of Entry and Exit)



How can I test this hypothesis with the Metastock System Optimiser where OptX would include/exclude a condition based on a 1/0 opt value. How could I optimise mySignal to do this?



Best regards,

bassmann


----------



## wabbit (3 May 2008)

Hi bassmann,

The easiest way is to multiply (or AND) your conditions with an optimised variable:

Entry1:=myEntryCondition1 * opt1;
Entry2:=myEntryCondition2 * opt2;
Entry3:=myEntryCondition3 * opt3;
Exit1:=myExitCondition1 * opt4;
Exit2:=myExitCondition2 *opt5;
Exit3:=myExitCondition3 * opt6;
etc

with each of the optimised variables having values of zero or one.

Also, read up on how MS thinks of just about everything in Boolean terms as this will make your coding a bucket load easier!

e.g.
x := If(Entry1=1 AND Entry2=1 AND Entry3=1,1,0);

is more easily written (and read) as:
x := Entry1 AND Entry2 AND Entry3;



Hope this helps.

wabbit 

P.S. Be careful to always keep in the back of your mind, the fine difference between optimising and curve fitting.


----------



## bassmann (4 May 2008)

Hi Wabbit,

I have ammended my MScode as you suggest and it does simplify things somewhat. 

I have since run 2 System Tests, the first to optimise the Exits and the second for Entries.

The method you suggested i.e. to optimise my condition with (* optX) works for Exits but not for Entries. I think this is because my 3 Exit rules use OR whereas my Entry rules uses AND. This is supported by the fact that the results from the Entry System Test only include those where all 3 Entry conditions were true. Nothing for the other 6 possible permutations. 


Hope this makes sense. Got the problem half solved (i.e. the Exits). Have already isolated I need to work on my Trailing Stop because the system test show I get far superior results without it. I just need a different approach for the Entries to overcome the AND issue.

Yours thoughts much appreciated,

bassmann


----------



## wabbit (4 May 2008)

bassmann,

I am not entirely sure what you mean so I will have a guess... my head is in the middle of uni assignments at the moment...

With the 3 entry conditions, you have a number of permutations (as you have already pointed out).  You can isolate each of these with an opt variable:

opt1 {1 to 7, step 1}

entry:=
if(opt1=1,Entry1,
if(opt1=2,Entry2,
if(opt1=3,Entry3,
if(opt1=4,Entry1 and Entry2,
if(opt1=5,Entry1 and Entry3,
if(opt1=6,Entry2 and Entry3,
Entry1 and Entry2 and Entry3
))))))


I guess the other way to achieve the same aim is to change the AND for OR in the original problem.  MS will loop through the opt variables meaning that it will also "visit" every permutation; it seems simpler.

Try both and see what works and what doesn't.  Please let us know how you progress.


wabbit


----------



## bassmann (4 May 2008)

Thanks wabbit,

1. Yes I think that your suggestion will work i.e., but what I didn't mention was that my real problem has 8 Entry Conditions that give 40,000 permuations so not fealialbe to code in this solution. 

opt1 {1 to 7, step 1}

entry:=
if(opt1=1,Entry1,
if(opt1=2,Entry2,
if(opt1=3,Entry3,
if(opt1=4,Entry1 and Entry2,
if(opt1=5,Entry1 and Entry3,
if(opt1=6,Entry2 and Entry3,
Entry1 and Entry2 and Entry3
))))))

I have got to 8 conditions as I developed my system over a period of time and now wish to assess if I have actually overdone it, I also wish to understand the influence of the combination of conditions on each other.



2. Your second suggestion of changing AND to OR in the original problem, I agree it will go through all permutations, but won't this change the way signals are generated. For e.g. a permuation with 6 signals should be true for all 6 conditions using AND, if I change it to OR is will trigger if only 1 of the 6 is true as i understand it. I need to think about this further.

You have been great help that has got me moving down the right track. I will give this some thought over the next few days and post and update how this pans out.

regards,

bassmann


----------



## Chorlton (6 May 2008)

wabbit said:


> Hi bassmann,
> 
> The easiest way is to multiply (or AND) your conditions with an optimised variable:
> 
> ...






Hi Wabbit,

Interestingly, I was trying to do something similar in Amibroker ie. optimisation of entry signals.

Out of interest, do you believe your approach would work in AB?  If so, I shall take a closer look....

Thanks in advance,

Chorlton


----------



## wabbit (6 May 2008)

Chorlton,

AB has its own system of commands for optimisation.


wabbit


----------

