OPEN-SOURCE SCRIPT

Acrypto - Weighted Strategy

已更新
Hello traders!

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:
  • MACD
  • Stochastic RSI
  • RSI
  • Supertrend
  • MA crossover


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).

Important note:
Backtest the algorithm with different data stamps to avoid overfitting results

Best,
Alberto
發布通知
How it works:

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.

Features:

* 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

Trading type
* Longs: true
* Shorts: true

Datastamp
* Since 01/01/2021

Stop loss
* StopLoss: true
* Movestoploss: false
* Stop loss %: 6
* Move stop loss factor: -
* Stop source: hl2

Take profit
* 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

Delays
* Candle delay: 1
* Candle delay Stoch RSI: 2
* Candle delay RSI: 2
* Candle delay exit: 7

Weights
* 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
* default...

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
發布通知
Plots:

* 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.
發布通知
Solve: typo
發布通知
Update: typo
發布通知

* Update default values to match example H4 BTC/USDT - Binance
* Choose the maximum number of Take Profits (TP) as suggested @aynetbt
發布通知
Minor update:

* Add: buy/sell labels for possible reentries.
發布通知
Update:
* 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.
發布通知
Update:

* 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!
發布通知
* With this monthly performance, we can see that the algo has performed very well over the past two years, capturing the trend very accurately. However, from 2017 to 2019, the algorithm can't even make a profit! This is a disclaimer.

Best,
Alberto

PS Thank you all for your kind words.

P.S. Thanks all for your kind words.
發布通知
News!

* Add: New Stop-Loss (SL) strategy!
* Update: by default -> move stop loss to TP-2 and desactivate move stop loss to entry

Features:
* Set SL to previous TP targets
* Set SL to the average position (after TP)

Examples:
* 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.
發布通知
## What's Changed
- 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.
發布通知
## What's Changed
* Update: rename variables and include more delays
發布通知
## What's Changed
* Update: minor bug
發布通知
## What's Changed
* Add: basic basic editable alarm system
發布通知
## What's Changed
* Solve: error top/bottom. Many thanks to FFriZz for spotting it
發布通知
## What's Changed
* Solve: error alarm labels thanks to hugchri for spotting it!
發布通知
## What's Changed
* Solve: close orders in only long/short mode. Many thanks to kegesch for spotting it.
發布通知
## What's Changed
* Solve: color warnings @thouravi
* Add: include different TP messages for long and short orders by @AlbertoCuadra
發布通知
## What's Changed
* Update: default value of slow MA cross strategy
發布通知
## What's Changed
* Add: flag to activate/desactive the shadows of the strategy as suggested @iammatty.
* Update: default fast MA Cross strategy
backtestingmacrossoverMoving AveragesOscillatorssupertrendTrend Analysis

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?


更多:

免責聲明