Summary
This article shows how to stop your EA from opening more than one buy trade per day.
You do this with a simple variable-based “buy gate”:
0= buying is allowed1= buying is blockedAfter the first buy trade, the gate changes to
1At a chosen time each day, the gate resets back to
0
Use this when your bot keeps opening multiple buy trades and you only want one buy setup per day.
What the logic does
Without a gate, a simple setup like this could open a new buy trade every candle:
Run per Candle → Buy Now
That is usually not what you want.
Instead, you add a variable that controls whether the buy setup is allowed to continue.
Trading logic
1. Create a variable
Create a variable called:
Buy_Gate
Set the default value to:
0
Meaning:
0 = buy allowed 1 = buy blocked
2. Check the gate before buying
Add a Trade Rule before Buy Now:
Buy_Gate = 0
If true, the EA is allowed to continue to the Buy Now block.
Logic:
Run per Candle → Trade Rule: Buy_Gate = 0 → Buy Now
3. Close the gate after the buy trade
After Buy Now, add a Modify Variables block.
Set:
Buy_Gate = 1
Now the EA has taken its buy trade for the day.
On the next candle, the Trade Rule checks again:
Buy_Gate = 0
But now the value is 1, so the EA cannot take another buy trade.
4. Reset the gate once per day
Add a Run at Time block.
Choose when the gate should reset, for example:
01:00
After Run at Time, add a Modify Variables block:
Buy_Gate = 0
This opens the gate again for the next trading day.
Main blocks used
Run per Candle
Checks the trade setup once per new candle.
Trade Rule
Checks whether:
Buy_Gate = 0
Buy Now
Opens the buy trade when the gate is open.
Modify Variables
Changes the gate value:
Buy_Gate = 1
after the trade, and back to:
Buy_Gate = 0
at the reset time.
Run at Time
Resets the gate once per day at your chosen time.
Example structure
Run per Candle → Trade Rule: Buy_Gate = 0 → Buy Now → Modify Variables: Buy_Gate = 1
Separate reset logic:
Run at Time: 01:00 → Modify Variables: Buy_Gate = 0
How to use it
Create the
Buy_Gatevariable.Set its default value to
0.Add a Trade Rule before your Buy Now block.
Check if
Buy_Gate = 0.After Buy Now, set
Buy_Gate = 1.Add Run at Time.
At your chosen reset time, set
Buy_Gate = 0.Export and test in MT5 Visual Mode.
Watch the EA in Visual Mode and confirm that it only opens one buy trade before the daily reset.
Make it your own
You can adjust this logic depending on your strategy:
Use a different reset time, such as market open or midnight broker time
Create a separate
Sell_Gatefor sell tradesUse one shared
Daily_Trade_Gateif you want only one total trade per dayCombine the gate with your normal entry rules
Add Draw on Chart blocks to show when the gate opens or closes
Conclusion
A buy gate is a simple variable-based filter that stops your EA from taking more than one buy trade per day.
Use 0 to allow buying, set it to 1 after a trade, then reset it back to 0 once per day with Run at Time.
Always export and test in MT5 Visual Mode before using the EA on demo or live.
