Nested Conditions

It would be nice if we could nest conditions for take profit. Currently the ‘logic’ allows us to only create a single array of conditions using AND or OR. I would like to create a condition like (A AND B) OR (C AND D) in order to take profit on a deal.

1 Like

You could always use a separate bot for the first and the second part of the condition. Or is it again about mixing timeframes and starting deals as soon as a higher trameframe’s condition gets activated?

It’s about take profit conditions, not opening conditions.
The idea is to have an aggressive/quicker take profit during higher timeframe downtrends and a more conservative/slower take profit during higher timeframe uptrends.

So this would go into the direction of a volatility or ATR based dynamic take profit?

I use PNR RSI take profit, but better to take profit when crossing up a level vs. crossing down depending on trend

I understand from @aressanch that we might get at some point support for AND and OR operations.

And if/else can be achieved with logical expressions as long as they are implemented in a flexible enough way.

I believe @bomanyd wants to be able to do something like this:

1- If a deal is still open and we entered an uptrend then exit using certain TA conditions that are more relaxed to let the deal run longer
2- if the deal is open and we entered a downtrend then use tighter conditions for the exit.

This cannot be achieved with two separated bots since what we need is the conditions to dynamically change depending on which trend you are. Assume the deal remains open for 10 days. And you flip from uptrend to downtrend every day.

This bot then should only exit if either:

UPTREND() && UPTREND_EXIT_COND() 
||
DOWNTREND() && DOWNTREND_EXIT_COND() 

The above is shown using AND and OR operators but it might look more elegant with if and else.

if UPTREND()  && UPTREND_EXIT_COND() 
  exit()
else if DOWNTREND() && DOWNTREND_EXIT_COND()  
  exit()

Two bots unfortunately can’t achieve the same as above.

1. If-Then (Implication):

In logic, “if A, then B” (denoted as A → B) can be expressed as:

  • A → B ≡ ¬A ∨ B
    This means if A is true, then B must be true. If A is false, then the statement is true regardless of B.

2. If and Only If (Biconditional):

“If and only if A, then B” (denoted as A ↔ B) can be expressed as:

  • A ↔ B ≡ (A → B) ∧ (B → A)
  • Or equivalently, A ↔ B ≡ (A ∧ B) ∨ (¬A ∧ ¬B)
    This means A and B must both be either true or both false.

3. If-Then-Else:

“If A, then B, else C” can be expressed as:

  • (A → B) ∧ (¬A → C)
  • Or equivalently, (A ∧ B) ∨ (¬A ∧ C)
    This means if A is true, then B must be true; if A is false, then C must be true.

4. For All (Universal Quantifier):

The universal quantifier ∀x : P(x) (for all x, P(x) is true) can be expressed in Boolean logic as a conjunction (AND) over all elements of the domain:

  • ∀x : P(x) ≡ P(x₁) ∧ P(x₂) ∧ … ∧ P(xₙ) for all possible values of x in the domain.
    This means P(x) must be true for every x.

5. Exists (Existential Quantifier):

The existential quantifier ∃x : P(x) (there exists an x such that P(x) is true) can be expressed as a disjunction (OR) over all elements of the domain:

  • ∃x : P(x) ≡ P(x₁) ∨ P(x₂) ∨ … ∨ P(xₙ)
    This means there must be at least one x for which P(x) is true.

Summary:

  • If A, then B: ¬A ∨ B
  • If and only if A, then B: (A → B) ∧ (B → A)
  • If A, then B, else C: (A ∧ B) ∨ (¬A ∧ C)
  • For all x, P(x): P(x₁) ∧ P(x₂) ∧ … ∧ P(xₙ)
  • Exists x, P(x): P(x₁) ∨ P(x₂) ∨ … ∨ P(xₙ)

This approach formalizes natural language conditions in terms of Boolean logic, allowing their direct use in algorithms or proofs. By converting logical expressions to Boolean algebra, you can implement these expressions in computational systems, such as circuits or programming languages. For example, these transformations are crucial in constructing conditional logic in code or verifying statements in formal proofs.

These logical forms form the foundation of propositional and predicate logic, widely used in mathematics, computer science, and related fields.