A3Sh

RSI+PA+DCA Strategy

A3Sh 업데이트됨   
Dear Tradingview community,

This RSI based trading strategy is created as a training exercise. I am not a professional trader, but a committed hobbyist. This not a finished trading strategy meant for trading, but more a combination of different trading ideas I liked to explore deeper. The aim with this exercise was to gain more knowledge and understanding about price averaging and dollar cost averaging strategies. Aside that I wanted to learn how to program a pyramiding strategy, how to plot different order entry layers and how to open positions on a specific time interval.

In this script I adapted code from a couple of strategy examples by Coinrule. Who wrote simple and powerful examples of RSI based strategies and pyramiding strategies.

Also the HOWTO scripts shared by vitvlkv were very helpful for this exercise. In the script description you can find all the sources to the code.

A PA strategy could be a helpful addition to ease the 'stress-management to buy when price drops and resolution in selling when the price is rising' (Coinrule).

The idea behind the strategy is fairly simple and is based on an RSI strategy of buying low. A position is entered when the RSI and moving average conditions are met. The position is closed when it reaches a specified take profit percentage. As soon as the first the position is openend multiple PA (price average) layers are setup based on a specified percentage of price drop. When the price crosses the layer another position with somewhat the same amount of assets is entered. This causes the average cost price (the red plot line) to decrease. If the price drops more, another similar amount of assets is bought with another price average decrease as result. When the price starts rising again the different positions are separately closed when each reaches its specified take profit. The positions can be re-openend when the price drops again. And so on. When the price rises more and crosses over the average price and reached the specified take profit on top of it, it closes all the positions at once and cancels all orders. From that moment on it waits for another price dip before it opens a new position.

Another option is to activate a DCA function that opens a position based on a fixed specified amount. It enters a position at the start of every week and only when there are already other positions openend and if the current price is below the average price of the position. Like this buying on a time interval can help lowering the average price in case the market is down.

I read in some articles that price averaging is also called dollar cost averaging as the result is somewhat the same. Although DCA is really based on buying on fixed time intervals. These strategies are both considered long term investment strategies that can be profitable in the long run and are not suitable for short term investment schemes. The downturn is that the postion size increases when the general market trend is going down and that you have to patiently wait until the market start rising again.

Another notable aspect is that the logic in this strategy works the way it does because the entries are exited based on the FIFO (first in first out) close entry rule. This means that the first exit is applied to the first entry position that is openend. In other words that when the third entry reaches its take profit level and exits, it actually exits the first entry. If you take a close look in the 'List of Trades' of your Strategy Tester panel, you can see that some 'Long1' entries are closed by an 'Exit 3' and not by an 'Exit 1'. This means that your trade partly loses, but causes a decrease in average price that is later balanced out by lower or repeated entering and closing other positions. You can change this logic to a real sequential way of closing your entries, but this changes the averaging logic considerably. In case you want to test this you need to change, in this line in the strategy call 'close_entries_rule = "FIFO"', the word FIFO to ANY.

In the settings you can specify the percentage of portfolio to use for each trade to spread the risk and for each order a trading fee of 0.075% is calculated.


릴리즈 노트:
Added a second Take Profit input option specifically for the Exit all Take profit that gets activated a specified % above the price average. (white line).
As @bobdenic suggested, the Exit All Take Profit is plotted (red line).
The Moving Average is changed into a green line.
릴리즈 노트:
Added close_entries_rule = "FIFO" to the strategy declaration. I forgot to add it in the first version. If you change FIFO to ANY it will change the order of closing the entries. Meaning it will close Entry 1 with Close 1, Entry 2 with Close 2, etc. As described above. Use it as you like best.
Cleaned up the script a bit.
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?