hamster-bot

hamster-bot MRS 2 (simplified version)

hamster-bot Mis à jour   
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)
A conventional MA is being built. (fuchsia line). A limit order is placed on this line to close the position.
2)
(green line) A limit order is placed on this line to open a long position
3)
(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
Notes de version:
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
Notes de version:
Added new MA type - ATR

Script open-source

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?