Summary
This article explains how to build a simple 20 Moving Average pullback strategy in Profectus.AI.
The idea is to look for price breaking above the 20 Moving Average, then either:
Enter directly after an engulfing candle rejects the moving average, or
Place a Buy Pending Order at the moving average after price has clearly broken above it.
This is an educational example. It is not investment advice. Always export and test your EA in MT5 Visual Mode before using it on a demo or live account.
What the strategy does
The strategy uses the 20 Moving Average as a dynamic price level.
Instead of buying randomly above the moving average, the bot waits for a clear condition first:
Price breaks above the 20 Moving Average
Price either touches/rejects the moving average or stays above it
No trade is currently open
Then the EA enters or prepares a buy setup
There are many ways to trade moving average pullbacks. This article shows two simple variations.
Variation 1: Engulfing candle rejection
This version enters a Buy Now trade when the last closed candle:
Engulfs the previous candle high
Has its low below the 20 Moving Average
Closes above the 20 Moving Average
This means price touched or moved below the moving average, then closed strongly back above it.
Trading logic
Use Candle ID 1 for the last fully closed candle.
Use Candle ID 2 for the candle before that.
Buy setup logic
Run per Candle
The EA checks the logic once when a new candle forms.
This avoids checking the same setup on every tick.
Engulfing condition
Check if:
Candle Close ID 1 > Candle High ID 2
This means the last closed candle closed above the high of the previous candle.
Pullback into the 20 Moving Average
Check if:
Candle Low ID 1 < Moving Average 20
This confirms that price moved below or into the moving average during the candle.
Close back above the 20 Moving Average
Check if:
Candle Close ID 1 > Moving Average 20
This confirms that price rejected the moving average and closed above it.
Prevent duplicate trades
Use Count Trades and check:
Trade Count = 0
This prevents the EA from opening multiple trades while one is already open.
Open buy trade
If all rules are true, connect the logic to:
Buy Now
Main blocks used
Run per Candle
Runs the strategy once when a new candle forms.
Use this for candle-close strategies where you want the EA to make decisions after a candle has closed.
Trade Rule
Used to compare values, for example:
Candle Close ID 1 > Candle High ID 2
or:
Candle Close ID 1 > Moving Average 20
Moving Average indicator
Use a Moving Average with period 20.
In this example, the moving average acts as the dynamic support level.
Count Trades
Checks how many trades or orders are currently open.
Use this before execution to avoid duplicate entries.
Buy Now
Opens an immediate buy position at the current market price.
Variation 2: Buy Pending Order at the 20 Moving Average
This version does not enter immediately.
Instead, it waits until price has clearly broken above the 20 Moving Average. Then it places a Buy Pending Order at the moving average level.
The idea is:
Price is above the moving average
The last closed candle stayed fully above the moving average
The bot places a buy order at the moving average
If price pulls back to the moving average, the order can be triggered
Trading logic
Run per Candle
The EA checks the setup once per candle.
Confirm price is above the 20 Moving Average
Check:
Candle Low ID 1 > Moving Average 20
This means the full last closed candle stayed above the moving average.
That confirms a cleaner breakout above the moving average.
Prevent duplicate orders or trades
Use Count Trades and check:
Trade Count = 0
Depending on your setup, you may want to count both open trades and pending orders.
Place Buy Pending Order
Use:
Buy Pending Order
Set the open level to:
Custom Price Level β Indicator β Moving Average 20
Set offset to 0 if you want the order placed exactly on the moving average.
If you want the order slightly above or below the moving average, use an offset.
Example:
Offset = 0
This places the order directly at the 20 Moving Average value.
Order expiration example
A moving average changes as new candles form.
If you place a pending order at the 20 Moving Average, the order level may become outdated when the next candle opens.
Example:
If you run the EA on the 4H timeframe, you can set the pending order to expire after 4 hours.
This means:
The EA places an order at the current 20 Moving Average level
After 4 hours, the order expires if not triggered
On the next candle, the EA can place a new order at the updated moving average level
This is a simple way to keep the pending order aligned with the latest moving average value.
Alternative: you can build trade management logic that selects old pending orders, deletes them, and places a fresh order at the updated moving average level.
How to use it
Open the Builder in Profectus.AI.
Add a Run per Candle block.
Add the required Trade Rule blocks.
Use Candle ID 1 for the last closed candle.
Use Candle ID 2 for the previous candle.
Add the Moving Average indicator with period 20.
Add Count Trades before execution.
Choose either:
Buy Now for the engulfing rejection version, or
Buy Pending Order for the pullback order version.
Export the EA as EX5/MQ5.
Load it into MetaTrader 5.
Export and test in MT5 Visual Mode.
While testing, watch whether the EA enters exactly where you expect it to enter.
Make it your own
You can adjust this strategy in many ways.
Examples:
Change the Moving Average period from 20 to 50 or 200
Add a spread filter before trade execution
Add a session filter to trade only during specific market hours
Add a stop loss below the signal candle low
Add take profit based on risk-reward, ATR, or previous highs
Use a Sell Now version by reversing the logic
Add Draw on Chart blocks to mark valid signals visually
Use order expiration or Delete Pending Orders logic to keep pending orders updated
For sell setups, reverse the conditions.
Example:
Candle Close ID 1 < Candle Low ID 2 Candle High ID 1 > Moving Average 20 Candle Close ID 1 < Moving Average 20 Count Trades = 0 Sell Now
This checks for a bearish engulfing rejection around the moving average.
Common mistakes
Using Candle ID 0 instead of Candle ID 1
Candle ID 0 is the current forming candle.
Its values can still change.
For candle-close logic, use Candle ID 1.
Running the strategy per tick
Run per Tick can trigger rapidly because it checks every price update.
For this strategy, Run per Candle is usually cleaner because the setup depends on closed candle logic.
Forgetting Count Trades
Without Count Trades, the EA may open repeated trades or orders.
Always check trade/order count before execution.
Placing pending orders without expiration
If the moving average changes but the old pending order stays active, the order may no longer match the intended setup.
Use order expiration or delete old pending orders with trade management logic.
Conclusion
The 20 Moving Average pullback strategy is a simple way to build structure around moving average trading.
The first version enters after an engulfing candle rejects the moving average.
The second version waits for a confirmed break above the moving average, then places a Buy Pending Order at the moving average for a possible pullback entry.
Both versions are examples only. Export and test in MT5 Visual Mode before making changes or using the EA on a demo account.
