I have been developing a fully customizable algo over the last year. The algorithm is based on a set of different strategies, each with its own weight (weighted strategy). The set of strategies that I currently use are 5:
Moreover, the algo includes STOP losses criteria and a taking profit strategy. The algo must be optimized for the desired asset to achieves its full potential. The 1H and 4H dataframe give good results. The algo has been tested for several asset (same dataframe, different optimization values).
Backtest the algorithm with different data stamps to avoid overfitting results
The algorithm is based on a combination of well-documented indicators. First, the algorithm calculated the weight_strategy, which represents a value from 0 to 5 of the number of strategies that are fulfilled (in case the weight of each strategy is the same). To open a position, the value of weight_strategy must be greater than the value of weight_signal, by default 2. Modify the indicator parameters for the desired asset and data frame. Set stop-loss and take profit criteria.
* The algorithm allows to trade with long, short or both positions.
* Backtest the algorithm over a defined interval (data stamp), e.g., from 01/01/2021
* Set stoploss (SL) orders based on a percentage of the previous candle source, e.g., close or hl2 (high + low)/2. Only close the position after the candle is close!
* It can moves the stoploss every time the algo takes profit (TP)
* Take profit based on a percentage of the open position. It is possible to define different values for short positions. Define the percentage of TP to close from the open position.
* Define delays to evaluate the strategies of more previous candles:
+ Candle Delay is for MACD strategy
+ Candle delay Stoch RSI is for the Stochastic RSI strategy.
+ RSI Candle Delay is for the RSI strategy.
+ Candle delay Exit is the number of candles the algorithm waits to open a new position.
* Choose if you want to use the weighted strategy or just some of them.
* Choose the weight (relevance) of each strategy.
* Customize the well-documented MACD strategy.
* Customize the well-documented Stochastic RSI strategy.
* Customize the well-documented RSI strategy.
* Customize the well-documented Supertrend strategy.
* Customize the well documented MA cross strategy.
Example 4H BTC/USDT - Binance
* Longs: true
* Shorts: true
* Since 01/01/2021
* StopLoss: true
* Movestoploss: false
* Stop loss %: 6
* Move stop loss factor: -
* Stop source: hl2
* Take profits: true
* Long - take profit each x (%): 6.8
* Long- take from open position: 15
* Short - take profit each x (%): 13
* Short - take from open position: 15
* Candle delay: 1
* Candle delay Stoch RSI: 2
* Candle delay RSI: 2
* Candle delay exit: 7
* Default (same weights and at least 2 strategies must be satisfied)
Strategy 1: MACD
* MA1: 16
* MA1 type: EMA
* MA1 source: hl2
* MA2: 36
* MA2 type: EMA
* MA source: high
Strategy 2: Stoch RSI
* Exit SRSI long: 70
* Exit SRSI short: 27
Strategy 3: RSI
* Exit RSI long: 77
* Exit RSI short: 30
Strategy 4: Supertrend
* ATR period: 2
* Source: hl2
* ATR multiplier: 2.4
* change ATR calculation method: true
Strategy 5: MA CROSS
* MA1: 50
* MA1 type: EMA
* MA1 source: close
* MA2: 88
* MA2 type: EMA
* MA source: close
* The color-trend represents when at least one of the strategies is satisfied, long in teal and short in gray and there is not a draw, same number of strategies satisfies for long and short.
* The + represent the next Take Profit (TP) target in teal and the Stop-Loss (SL) in gray.
* Plot labels for every time each strategy satisfies to open a long/short position
* Detect potential TOP and BOTTOMS based on a combination of RSI, Stoch RSI, MACD, volume, and the weighted-strategy.
* Choose the maximum number of Take Profits (TP) as suggested @aynetbt
* Add: buy/sell labels for possible reentries.
* Add: Stop position in case the algo detects a potential Top/Bottom.
- It can close a specific percentage of the remaining open long position.
- It can close a specific percentage of the remaining open short position.
* Add: monthly table performance. All the credits to @QuantNomad. I have only changed some colors and also adapted the calculations to the last previous candle. The purpose of this change is to make this script compatible with this weighted strategy. Thanks again to @QuantNomad for this amazing script!
PS Thank you all for your kind words.
P.S. Thanks all for your kind words.
* Add: New Stop-Loss (SL) strategy!
* Update: by default -> move stop loss to TP-2 and desactivate move stop loss to entry
* Set SL to previous TP targets
* Set SL to the average position (after TP)
* Set TP-2 and move SL to entry is desactivated: this implies that if you are in TP3 the SL will correspond with the previous TP1. However, if you are in TP2 the SL will not change, because there is not a TP0.
* Set TP-2 and move SL to entry is activated: same as before, but now in TP2 the SL will move to the average entry position.
- Solve: minor bug defining default_qty_value
- Solve: typos
The script is now available on Github! https://github.com/AlbertoCuadra/algo_trading_weighted_strategy
From github it is much easier to debug, share ideas, control versions and most importantly work with other developers.
- Solve: error TP same bar. Thanks to @aynetbt for letting me know.
- Solve: error TP-TOP, TP-BOTTOM when the percentage was smaller than 100. I was always closing the entire trade, not a percentage.
- Add: includes TP-TOP and TP-BOTTOM limit orders based on the previous candle with the TOP/BOTTOM label.
The patch for TPs will only work if you have enabled the "After is filled" option in the properties tab. Due to the intra-bar calculation, you can have multiple TPs in the same order. This setting is desactivated by default.
* Update: rename variables and include more delays
* Update: minor bug
* Add: basic basic editable alarm system
* Solve: error top/bottom. Many thanks to @FFriZz for spotting it
* Solve: error alarm labels thanks to @hugchri for spotting it!
* Solve: close orders in only long/short mode. Many thanks to @kegesch for spotting it.
* Solve: color warnings @thouravi
* Add: include different TP messages for long and short orders by @AlbertoCuadra
* Update: default value of slow MA cross strategy
* Add: flag to activate/desactive the shadows of the strategy as suggested @iammatty.
* Update: default fast MA Cross strategy
Dalam semangat TradingView yang sebenar, penulis skrip ini telah menerbitkannya dengan menggunakan sumber terbuka supaya pedagang-pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda dapat menggunakannya secara percuma tetapi penggunaan semula kod ini dalam penerbitan adalah dikawalselia oleh Peraturan Rumah. Anda boleh menyukainya untuk menggunakannya pada carta.
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.