Complex Rules
Last updated November 4, 2024
How To Build 'Complex Rules' On Coinrule
Trading Rules on Coinrule can be powerful and complex at the same time.
This article runs through some complex rules to lay out how the rule logic works and also covers some common misconceptions.
Case 1: Condition Block - How the Sell Action will be triggered
What you need to know
For the rule to Sell, the following condition logic must be TRUE:
1 or 2 or 3 AND 4
Expressed with brackets: (1 or 2 or 3) AND (4)
Some points to consider:
- Condition 4 above must always be TRUE for the Sell to occur because of the sequential order
- Any time you use AND, it relates to ALL previous conditions inside the block. That means that an 'AND' in the condition block, the following condition must be TRUE for the rule to trigger
Scenarios:
- 1 and 4 are TRUE: The rule sells
- 2 and 4 are TRUE: The rule sells
- 3 and 4 are TRUE: The rule sells
- Only 1 and 2 TRUE: The rule does not sell
- Only 1 TRUE: The rule does not sell
- Only 4 TRUE: The rule does not sell
- 4 is not just related to 3 but to ALL conditions in this block
A common misconception is around the grouping of blocks. It is NOT: (1 or 2) OR (3 and 4).
Let's look at examples:
Example 1:
- Rule previously bought Ethereum with USDT at $3,000
- Price decreases 4% from $3,000, RSI is 50
- Condition 1 is TRUE, Condition 2 is FALSE, Condition 3 is FALSE, Condition 4 is TRUE: RULE SELLS
Example 2
- Rule previously bought Ethereum with USDT at $3,000
- Price decreases 2% from $3,000, RSI is 50
- Condition 1 is FALSE, Condition 2 is FALSE, Condition 3 is FALSE, Condition 4 is TRUE: Nothing happens
Example 3
- Rule previously bought Ethereum with USDT at $3,000
- Price increases 5% from $3,000
- Condition 1 is FALSE, Condition 2 is FALSE, Condition 3 is TRUE, Condition 4 is FALSE: Nothing happens
Example 4
- Rule previously bought Ethereum with USDT at $3,000
- Price increases 5% from $3,000 ($3,150), then decreases 2% ($3,087)
- Condition 1 is FALSE, Condition 2 is FALSE, Condition 3 is FALSE, Condition 4 is TRUE: Nothing happens
Example 5
- Rule previously bought Ethereum with USDT at $3,000
- Price increases 7% from $3,000 ($3,210), then decreases 2% ($3,145.8)
- Condition 1 is FALSE, Condition 2 is FALSE, Condition 3 is TRUE, Condition 4 is TRUE: Rule SELLS
Example 6
- Rule previously bought Ethereum with USDT at $3,000
- Price unchanged, RSI is 66
- Condition 1 is FALSE, Condition 2 is TRUE, Condition 3 is FALSE, Condition 4 is FALSE: Nothing happens
Example 7
- Rule previously bought Ethereum with USDT at $3,000
- Price increases 5% ($3,150), then price decreases 2% ($3,087), RSI is 66
- Condition 1 is FALSE, Condition 2 is TRUE, Condition 3 is FALSE, Condition 4 is TRUE: Rule SELLS
Case 2: Condition Block - How the Sell Action will be triggered
The difference compared to Case 1 is the 'and' rather than 'or' in Condition 2.
For the rule to Sell, the following condition logic must be TRUE:
1 AND 2 or 3 AND 4
Expressed with brackets: ((1 and 2) OR (3)) AND (4)
- If 3 is FALSE, BOTH 1 AND 2 must be TRUE together with 4 for the rule to sell
- Condition 4 must always be TRUE for the rule to sell because of the sequential order
Scenarios:
- 1 AND 2 are TRUE, 3 and 4 are FALSE: Nothing happens
- 1 is FALSE, 2 is TRUE, 3 is TRUE, 4 is TRUE: Rule SELLS because 3 AND 4 are TRUE
- 1 and 2 are TRUE, 3 is FALSE, 4 is TRUE: Rule SELLS because 1 AND 2 AND 4 are TRUE
About 'OR' inside Condition Blocks
- The OR inside a condition block does not create a separate group of conditions that have to be TRUE
- The OR inside a condition block provides an alternative possible condition for a rule to be met
- It should NOT be confused with the OR Operator which does create a separate group of conditions
Case 3: Wait Operator
The recently introduced 'Wait For' operator is a powerful tool to validate a trend.
Here are some examples of how it applies in a complex rule:
Example 1:
- Rule previously bought Ethereum with USDT at $3,000
- Price decreases by 4% from $3,000
- Block 1 above is triggered: the rule SELLS
Example 2:
- Rule previously bought Ethereum with USDT at $3,000
- Price increases by 1% from $3,000, RSI is 70 in a timeframe of 5 minutes The following Sequence is now active:
- First condition after OR Operator is TRUE
- Block 2 in the image above is triggered
- 'Wait for' loop starts and waits for 5 minutes
- Important to note: once the 'Wait For' loop has been triggered here, Block 1 will no longer be checked
- Scenario 1: after the 5 minute wait, RSI is greater than 65 in a timeframe of 15 minutes: Rule SELLS
- Scenario 2: after the 5 minute wait, RSI is lower than 65 in a timeframe of 15 minutes: Loop restarts the 5 minute wait and then again checks if RSI is greater than 65 on a timeframe of 15 minutes
- The 'Wait For' Loop will continue running until the RSI condition is met and will then trigger the following Sell Action
Case 4: Two Actions with OR Operator
You can also use an OR operator to create two possible Action scenarios.
In the above rule, the first condition will be checked, if the condition is NOT met, the rule will continue by checking the condition after the OR. If the condition after the OR IS met, the rule will trigger. If the condition is NOT met, the rule will continue by checking the first condition.
This enables you to build strategies that would trigger a BUY action and a SELL action based on two different conditions.
Try out these strategies now on Coinrule to maximize your profits and returns!