Dukascopy
 
 
Wiki JStore Search Login

How to implement a series of OR statements
 Post subject: How to implement a series of OR statements Post rating: 0   New post Posted: Sun 09 Jun, 2013, 00:33 

User rating: 1
Joined: Mon 21 Jan, 2013, 09:11
Posts: 51
Location: New ZealandNew Zealand
Hi.
A series of AND statements can be implemented (I think) by connecting IF boxes.
But how can a series of OR statements be implemented?
For example, if you had a number of variables A, B, ....F, what VJF boxes would be used for the following: -

IF A<B do something, such as Buy or sell, OR
If C>D do the same thing, OR
IF E<F do the same thing, else
Do nothing.

Thanks,
Ted


 
 Post subject: Re: How to implement a series of OR statements Post rating: 0   New post Posted: Sun 09 Jun, 2013, 14:55 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
If you want to AND a list of IFs together, then the TRUE output of each IF feeds into the next IF.

IF(A) true ------------------> IF(B) true ------------------> IF(C) true ---------------------> ACTION
.........false NOTHING.............false NOTHING.............false NOTHING

the only way ACTION can excute is if all IF tests output true.

If you want to OR a list of IFs together, then the TRUE output of each IF feeds into the ACTION you want to perform
and the FALSE output of each IF feeds into the next IF.

IF(A) false ------------------> IF(B) false ------------------> IF(C) false ---------------------> NOTHING
.........true ACTION..................true ACTION...................true ACTION

ACTION executes if either test returns TRUE and only once. If all tests fail then the NOTHING route is taken.

General Background: that might help with refactoring logic for easier implementation

Logically, solving the problem of transforming list of AND tests into a list of OR tests requires the use of De Morgan's Laws (https://en.wikipedia.org/wiki/De_Morgan%27s_laws)

This states that A & B & C & D is equivalent to ~(~A || ~B || ~C || ~D)

So for each input as well as the output you negate it with ~ and use || (or) for your logical tests.

....and also that A || B || C || D is equivalent to ~(~A & ~B & ~C & ~D)

So for each input as well as the output you negate it with ~ and use & (and) for your logical tests.

e.g.

where A = 1 B = 1 C = 1 D = 1 and A & B & C & D ---> 1 & 1 & 1 & 1 = true

~(~A || ~B || ~C || ~D) ---> ~(~1 || ~1 || ~1 || ~1) ---> ~(0 || 0 || 0 || 0) ---> ~(0) ---> 1 = true

where A = 0 B = 0 C = 0 D = 0 and A || B || C || D ---> 0 || 0 || 0 || 0 = false

~(~A & ~B & ~C & ~D) ---> ~(~0 & ~0 & ~0 & ~0) ---> ~(1 & 1 & 1 & 1) ---> ~(1) ---> 0 = false

To achieve negation, you either literally negate the input/output or if the variables A,B,C,D are more complex than simple numbers
used here then look for false outputs where you would look for true and look for true outputs where you would look for false as
negating complex variables requires using De Morgans Law on each variable to negate it.

Hope this helps


 
 Post subject: Re: How to implement a series of OR statements Post rating: 0   New post Posted: Sun 09 Jun, 2013, 22:30 

User rating: 1
Joined: Mon 21 Jan, 2013, 09:11
Posts: 51
Location: New ZealandNew Zealand
Hi
Thank you for your response, I'll now see how it works out with the VJF boxes.
I haven't heard of De Morgan's law, so I'll have a look at that as well.
Ted


 
 Post subject: Re: How to implement a series of OR statements Post rating: 0   New post Posted: Mon 10 Jun, 2013, 09:15 

User rating: 1
Joined: Mon 21 Jan, 2013, 09:11
Posts: 51
Location: New ZealandNew Zealand
Suppose I have 6 variables, A, B, C, D, E, F.

If A>B and C<D and E>F open a trade, to buy.
If any one of these 3 conditions fails, close the trade.
That is
If A<B or C>D or E<F then close the trade.

I have tried to express this in terms of the VJF boxes, and the attachment will show my attempt.
Could someone take a look, and tell me how I could or should do it.
Thanks,
Ted


Attachments:
SixVariables.vfs [23.91 KiB]
Downloaded 297 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: How to implement a series of OR statements Post rating: 1   New post Posted: Mon 10 Jun, 2013, 10:45 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
I'm not a VJF user but consider the following.

The concept of a variable in my explanation above is not literal so might be confusing so I'll rewrite it this way:

If you want to AND a list of IFs together, then the TRUE output of each IF feeds into the next IF.

.
.
IF[T1] true ------------------> IF[T2] true ------------------> IF[T3] true ---------------------> ACTION
       false NOTHING                   false NOTHING                   false NOTHING
.
.

the only way ACTION can execute is if all IF tests T1-T3 output true.

Consider also that NOTHING doesn't HAVE TO BE nothing, it can be anything such as:

.
.
IF[T1] true ------------------> IF[T2] true ---------------------> IF[T3] true ---------------------> OPEN[]
       false CLOSE[]                   false CLOSE[]                      false CLOSE[]
.
.

Consider further that IF[X] --> IF[some test involving two vars] --> represents an IF box within VJF that has true and false output 'pins' and that

CLOSE[] represents either a market operation box within VJF that makes a close happen, or it represent an arrow to another IF box, IF[C1] that checks if there's a position or checks something else before making a close happen on the IF[C1] 'true' pin.

OPEN[] represents either a market operation box within VJF that makes an open happen, or it represent an arrow to another IF box, IF[O1] that checks there's no position or checks something else before making an open happen on the IF[O1] 'true' pin.

Now taking a look at T1-T3 and then considering that you have tests involving two sides, VJF already supports tests with two side so we map these to T1-T3 such that:

T1 = A>B
T2 = C<D
T3 = E>F

.
.
IF[A>B] true ------------------> IF[C<D] true ------------------> IF[E>F] true ---------------------> OPEN[]
        false CLOSE[]                    false CLOSE[]                    false CLOSE[]
.
.

So the true pins link each other to create the 'AND' effect.
The false pins link to the close operation to create the 'exception' / 'something went wrong' effect.

Oh and look out for those EQUAL cases, if A<B or C>D or E<F then close the trade is really: A<=B or C>=D or E<=F


 
 Post subject: Re: How to implement a series of OR statements Post rating: 2   New post Posted: Tue 11 Jun, 2013, 17:02 
Visual JForex expert at Dukascopy
User avatar

User rating:
Joined: Mon 22 Apr, 2013, 11:30
Posts: 604
Location: UkraineUkraine
Hello Everyone.

Lets take following simple example:

If ( A>=B ) OR ( C>= D ) OR ( E>=F ) Then open BUY Else open SELL

That can be solved with cascade of IF blocks:

Image

Best regards.


Attachments:
Pic1.png [63.6 KiB]
Downloaded 442 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com