RAQ

# How to Create an EA with 2 Buying Criteria

Q: The system I am trying to build has 2 different buying criteria and each buying criteria has 3 different rules, in this case how this should be done?

Buying criteria number 1 rules are:

1. rule A          2. rule B         3.rule C

Buying criteria number 2 rules are:

1. rule x          2. rule y           3. rule z

A trade should be opened if either criteria 1 or 2 are true.

A: One way to do this in VTS is to create 2 Logic Elements and connect them in Parallel.

Logic A has conditions for Rules A, B and C. Each condition is connected by the AND statement. This means all of the conditions must be true for the Logic to evaluate to true.

Same thing for Logic B, but use Rules x, y and z.

Here us what Logic A might look like:

This is what the drawing might look like:

Notes:

(1) In this drawing, both Logic1 and Logic2 will always exceute. The logics are connected in parallel. To control which logic executes first, double-click the link and select a Link Number:

(2) Only one trade will be opened if the deafult value of MAXTRADES is left as 1.  It is highly recommended that MAXTRADES is left as one. This is because it can be difficult to manage more than 1 open trade within an EA.

(3) There is another way to implement this same logic using the parenthesis in a Logic element.  This is more advanced, but is also more powerful. The resulting logic would look like:

IF:   ( ( RuleA AND RuleB AND RuleC ) OR ( RuleX AND RuleY AND RuleZ ) )

Notice how the parenthesis balance. Warning, it’s very easy to inject a syntax error using this technique.