Swing Structure Trader
- Experts
-
Alejandro Matias Pingaro
Ingeniero en Sistemas. Programo bots (asesores expertos) e indicadores en MQL5 para MetaTrader 5. Mi tesis de grado fue sobre estrategias de inversión para trading.
Bots desarrollados: DS (v1 a v3), EPP (v1 a v5), CML/CMS, TSC y SUPPLY.
Qué incluyo en cada trabajo: - Versione: 1.0
- Attivazioni: 10
Swing Structure Trader is an Expert Advisor for MetaTrader 5 that
takes its stop loss and its take profit from the swing structure of
the chart, not from a fixed point count.
THE STOPS COME FROM THE CHART
This is the main idea of the EA. Most Expert Advisors ask for a stop
loss of so many points and apply that same number everywhere, no
matter where price actually is.
This one reads the chart first. It finds the swing highs and the swing
lows of the selected timeframe, takes the first one above price as the
resistance and the first one below price as the support, and places
the orders against them:
- On a buy, the stop loss goes below the support and the take profit
just before the resistance.
- On a sell, the stop loss goes above the resistance and the take
profit just before the support.
You set how many points beyond the level the stop loss sits, and how
many points before the level the take profit sits. Everything else
follows the structure, so the distances change as the chart changes.
DIRECTION FILTER
The EA compares the last two swing highs against each other and the
last two swing lows against each other.
- Both rising: it only buys.
- Both falling: it only sells.
- Mixed: it does not trade at all.
Peaks are confirmed with a configurable number of bars on each side,
so a peak is only counted once the bars around it are closed.
WHEN THE RATIO DOES NOT ADD UP
If the current market price does not reach the minimum reward to risk
ratio you asked for, the EA does not discard the setup. It solves for
the exact price where that ratio is met and leaves a pending order
waiting there:
entry = (target + RR * stop) / (1 + RR)
The pending order is cancelled on its own if the trend changes, if the
levels move or if the EA is switched off. It can also be given a
lifetime in hours.
ONE DECISION PER CLOSED BAR
The EA evaluates once per closed bar of the selected timeframe, not on
every tick. Between evaluations it only listens to the remote control.
A pending order that is already working is left alone. It is only
redone when the direction changes, when a level moves further than the
tolerance you set, or when the calculated entry price actually changes.
The result is an EA that places an order and lets it work, instead of
cancelling and recreating it against every small move.
AUTOMATIC BROKER ADAPTATION
Before sending any order, the EA corrects six things that differ from
one broker to another. Nothing has to be configured:
- It adjusts the lot to the minimum, maximum and step allowed by the
symbol, with the number of decimals the step accepts.
- It calculates the required margin and skips the trade if free margin
is not enough.
- It measures every distance against the price the broker checks, and
uses the real spread, not a declared value.
- If the stop loss lands closer than the broker allows, it widens it up
to that minimum. A parameter caps how far that widening may go, and
the log reports the change. The take profit is never widened: if the
target is too close, the trade goes to the pending order path
instead, where a lower entry makes the target larger on its own.
- It respects the freeze level. When a pending order is already too
close to price the broker does not allow it to be cancelled, so the
EA leaves it alone instead of retrying and failing.
- It checks that the symbol accepts trading and that the server time
falls inside a trading session, so nothing is sent during a daily
break or a market close.
LEVELS DRAWN ON THE CHART
Every swing high inside the configured range is drawn in green and
every swing low in red, so the levels the EA is working with are
visible at all times.
ON SCREEN PANEL
The chart shows an enable and disable button and one line of status
explaining what the EA is doing right now and why.
The EA can also be switched on and off from a phone. Sending a manual
order with one of two key volumes enables or disables it, which is
useful when only the mobile terminal is at hand.
The EA only manages its own trades, identified by the magic number, so
it can run next to other EAs or next to manual trading.
ONE TRADE AT A TIME
There is no grid, no averaging and no martingale. The EA holds one
position at a time and one pending order at a time. There is also an
option to stop the EA automatically after the first filled order.
PARAMETERS
Trade volume, magic number, start enabled, one order only, the two key
volumes for remote control, peaks timeframe, bars on each side of a
peak, bars back to scan, range in points to map, draw levels, points
beyond the opposite level, points before the target level, minimum
stop loss in points, minimum reward to risk ratio, pending order
lifetime, maximum stop loss widening and the tolerance in points a
level may move before the order is redone.
WORKS ON ANY SYMBOL AND TIMEFRAME
There is nothing tied to a particular pair. The distances are given in
points of the symbol, so they have to be rescaled when moving between
instruments with a different number of decimals. On a currency pair
with five decimals 200 points are 20 pips, while on gold with two
decimals 200 points are 2 dollars.
RECOMMENDATIONS
Test it on a demo account for several weeks before using real money.
Results vary between brokers because they depend on the spread, on
slippage and on server time.
The range in points decides how far the EA looks for levels. Too small
and it finds nothing, too large and it picks up levels that no longer
matter for the current move.
A worthwhile test: split the period in two halves, find the values on
the first half and apply them unchanged on the second one. If the
result collapses, the values were fitted to the past.
RISK WARNING
Trading leveraged financial markets involves the risk of losing all
invested capital. This product is an automatic execution tool, not
investment advice. Each user is responsible for the settings chosen and
for the trades performed. Past behaviour does not guarantee or suggest
future results.
