MRS
MRS - Mean Reversion Strategy. It is a counter-trend strategy based on the assumption that the price returns to its average after deviating from it. The opening order is placed at an offset from the average price. The closing order is placed at the average price without an offset. On a sharp price deviation a position opens, and it closes when the price returns to the average.
Trades are generated when the price moves away from the average by a certain percentage. ⚠️ But if the price keeps moving in the same direction without a pullback, the position will be at a loss. The price falls - the strategy buys (going against the trend). The price rises - it sells (also against the trend). But sooner or later the close happens at the average price anyway.
As a rule, positions in this strategy are held briefly. And in a calm market you can stay without a position for a long time.
Order type used: Limit. Placed in advance and moved as the average price changes.
In the simplest form there are three MA lines (moving averages) on the chart.
● The Fuchsia base MA shows the price of the closing limit order. No offset
● The Green long MA - the price of the limit BUY order that opens a LONG position. It is the base MA shifted down by a %.
● The Red short MA - the price of the limit SELL order that opens a SHORT position. It is the base MA shifted up by a %.
How it works: if both long and short are on, 2 orders are placed. If only long or short is on, 1 order. While waiting for a position, the orders move along their lines on every new candle. When the price reaches our opening order, a position opens and a closing order is placed at the base MA. The closing order also moves along its MA until it is filled. Then the cycle repeats.
MA line settings (opening and closing orders)
There can be several opening lines for each side (ma_long, ma_short) - this gives a grid of orders with averaging in (MultiMA).
There is one closing line for each side (ma_close_long, ma_close_short) - the whole position is closed with one order.
- id - line sequence number, no repeats
- type - moving average type
SMA, EMA, GMA, HARMONIC, TEMA, DEMA, ZLEMA, WMA, VWMA, RMA, EHMA, THMA, HMA, DMA, ATR, H, L - source - price source
open, high, low, close, hl2, hlc3, ohlc4, hlcc4, oc2 - len - MA length
- multiplier - offset. 1 means no offset, 0.99 means -1%, 1.01 means +1%
- lot_x - lot multiplier: order size = base lot * lot_x. Not used for the closing order
- order_type -
limitormarket. A market order is sent when the price reaches the line - post_only - limit order as maker only
- hidden - hidden limit order (BitMEX only)
Lot setup. In the basic settings set balance_percentage = 100 and risk = 1. Then lot_x = 1 - an order for 100% of the balance, 0.5 - for 50%, 1.5 - for 150%.
Strategy parameters
entry_on_close- for market opening orders: check the entry condition against the last candle's close price instead of the current pricetrade_offset- for market opening orders: take the MA value N candles backreverse_mode- for market opening orders: enter not when the price crosses the line, but when the price is above the line (for a buy) or below it (for a sell), no further than 1% from itrecalculate- recalculate order sizes on every update, even if a position is already openclose_on_signal- starting from the second candle after entry, close the position with a market order as soon as the price touches the closing lineclose_on_wrong_side- if the price has moved beyond the closing line by more than 0.5% and the limit order was not filled, close the position with a market orderemergency_stop- emergency stop: if the opening line ends up on the other side of the closing line (the lines crossed), the bot cancels all orders and closes the positionnotification_trade_report- a Telegram report for each closed trade: average entry price, exit price and the result in %position_priority- position priority for the position limiter (see below)
Position limiter
The limiter is set for an API key with the "open_positions_limiter": 64 parameter in the key file in the settings_account folder. Default 0 - off.
Only MRS bots whose position_priority is not 0 take part in the limiter.
position_priorityfrom 1 to 5. 5 is the lowest priority, such a position closes first- If there are as many open positions as set in the limiter, opening orders are cancelled on pairs without a position - no new positions are opened
- If more positions opened than the limit (for example at the same time), the extra ones are closed: first with priority 5, then 4, 3, 2, 1. With equal priority - a random one
- Positions with priority 0 are not counted and not closed by the limiter
In the interface the limiter is shown like this: [100 | (4/64)] - 100 bots on this API, 4 positions open, limit 64.
The same open_positions_limiter parameter also limits the HiDeep, RedFlag, SmartProfit and ShadowOverlap strategies: when there are as many open positions on them as the limit, bots without a position do not open new trades. Priorities are not used for them.
ColorBox - close on the N-th candle
A closing option that turns MRS into ColorBox: the position closes at the close of the N-th candle after entry. You can add a candle color condition, for example close after the 2nd green candle. Set separately for long and short. Details are in the "Position closing and common options" section.
Backtest
Test in the built-in backtester
Script (PineScript) for testing the strategy on historical data in the TradingView strategy tester. The strategy is popular, and you can find many variations under different names.
-
Links:
- A simple version of the strategy with a minimum of settings. I recommend starting with this script.
- A script with a large set of parameters that can be reproduced in the trading bot.
- A script that can place many opening orders (increasing the position | averaging in).
Recommendations:
(not strict, you can break them for research purposes)
● A limit order limits the strategy's capacity. On low-liquidity instruments the tester result will be overstated.
● On spot, test long only. Long and short at the same time is for experienced users.
● On futures a counter-trend strategy carries a liquidation risk.
● Typical timeframe - 1h. Altcoin/bitcoin or altcoin/altcoin pairs.
Backtest the strategy on historical data in the tester and run it in hamster-bot.