MRS - Mean Reversion Strategy (Countertrend) (Envelope strategy)
This script does not claim to be unique and does not mislead anyone. Even the unattractive backtest result is attached. The source code is open. The idea has been described many times in various sources. But at the same time, their collection in one place provides unique opportunities.
Published by popular demand and for ease of use. so that users can track the development of the script and can offer their ideas in the comments. Otherwise, you have to communicate in several telegram chats.
Representative of the family of counter-trend strategies. The basis of the strategy is Mean reversion. You can also read about the Envelope strategy.
Mean reversion, or reversion to the mean, is a theory used in finance that suggests that asset price volatility and historical returns eventually will revert to the long-run mean or average level of the entire dataset.
The strategy is very simple. Has very few settings. Good for beginners to get acquainted with algorithmic trading. A simple adjustment will help avoid overfitting. There are many variations of this strategy, but for understanding it is better to start with this implementation.
Principle of operation. 1) [Closing] A conventional MA is being built. (fuchsia line). A limit order is placed on this line to close the position. 2) [BUY | LONG] (green line) A limit order is placed on this line to open a long position 3) [SELL | SHORT] (red line) A limit order is placed on this line to open a short position
Attention! Please note that a limit order is used. Conclude that the strategy has a limited capacity. And the results obtained on low-liquid instruments will be too high in the tester. On real auctions there will be a different result.
Note for testing the strategy in the spot market: When testing in the spot market, do not include both long and short at the same time. It is recommended to test only the long mode on the spot. Short mode for more advanced users.
Settings: Available types of moving averages:
SMA
EMA
TEMA - triple exponential moving average
DEMA - Double Exponential Moving Average
ZLEMA - Zero lag exponential moving average
WMA - weighted moving average
Hma - Hull Moving Average
Thma - Triple Exponential Hull Moving Average
Ehma - Exponential Hull Moving Average
H - MA built based on highs for n candles | ta.highest(len)
L - MA built based on lows for n candles | ta.lowest(len)
DMA - Donchian Moving Average
A Kalman filter can be applied to all MA
The peculiarity of the strategy is a large selection of MA and the possibility of shifting lines. You can set up a reverse trending strategy on the Donchian channel for example.
Use Long - enable/disable opening a Long position Use Short - enable/disable opening a Short position
Lot Long, % - % allocated from the deposit for opening a Long position. In the spot market, do not use % greater than 100% Lot Short, % - allocated % of the deposit for opening a Short position
Start date - the beginning of the testing period End date - the end of the testing period (Example: only August 2020 can be tested)
Mul - multiplier. Used to offset lines. Example: Mul = 0.99 is shift -1% Mul = 1.01 is shift +1%
Non-strict recommendations: 1) Test the SPOT market on crypto exchanges. (The countertrend strategy has liquidation risk on futures) 2) Symbols altcoin/bitcoin or altcoin/altcoin. Example: ETH/BTC or DOGE/ETH 3) Timeframe is usually 1 hour
If the script passes moderation, I will supplement it by adding separate settings for closing long and short positions according to their MA
릴리즈 노트
new option "distance_filter" value in %. If you set it to 0, it means the filter is turned off and not used. The filter disables trading and removes orders if the distance between the opening order and the closing one is less than a specified one
릴리즈 노트
Added new MA type - ATR
릴리즈 노트
Added pump filter
릴리즈 노트
Settings for pump filter (source and offset)
릴리즈 노트
Experimental function. Pump filter 2. If the Maximum for N candles ago is more than X greater than the minimum, then a filter is turned on that disables opening new positions.
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.