Sometimes you want parts of your strategy to only run when a certain condition happens — for example, when a crossover occurs, a breakout is confirmed, or a variable turns on (1).
This article shows how to create simple on/off gates inside Profectus.AI using numeric variables (0/1) and Trade Rule blocks, so you can control which logic paths are active at any given time.
The Concept: On/Off Gates
Think of a variable as a light switch for your decision tree:
0 = off → the branch is inactive
1 = on → the branch is active
You can use this to control when a part of your EA becomes active.
Once your condition is met, you switch the variable to 1, let the system execute the logic, and then reset it back to 0 to wait for the next opportunity.
Example: EMA Crossover Active for 3 Candles
Let’s say we have:
EMA 20 (fast) --> Yellow
EMA 50 (slow) --> Red
EMA 238 (trend filter) --> Green
We want the system to:
When EMA 20 crosses EMA 50 but price hasn’t yet moved above EMA 238, activate a short-term signal that stays valid for 3 candles, then turns off again.
In this picture, we see the EMA20 (yellow) crossing the EMA50 (red) while still being below the EMA238: set cross_flag = 1. This marks the beginning of counting. Hence, the following three candles are marked with red arrows. on the fourth candle, the cross_flag sets back to zero.
Step-by-Step Logic
Create two variables
cross_flag→ starts as 0cross_age→ starts as 0
Trigger the crossover
When EMA 20 crosses EMA 50
AND price is still below EMA 238
→ setcross_flag = 1
→ setcross_age = 0
Count the candles
Add a Run per Candle block.
If
cross_flag = 1, then:
→cross_age = cross_age + 1
Auto-reset after 3 candles
If
cross_age > 3, then:
→cross_flag = 0
→cross_age = 0
Your EA will now keep the signal active for 3 candles after the EMA crossover, allowing other logic blocks to run during that time.
After 3 candles, the signal resets and waits for the next valid crossover.


