OPEN-SOURCE SCRIPT

Trailing Take Profit - Close Based

ที่อัปเดต:
📝 Description
This script demonstrates a new approach to the trailing take profit.
Trailing Take Profit is a price-following technique. When used, instead of setting a limit order for the take profit target exiting from your position at the specified price, a stop order is conditionally set when the take profit target is reached. Then, the stop price (a.k.a trailing price), is placed below the take profit target at a distance defined by the user percentagewise. On regular time intervals, the stop price gets updated by following the "Trail Barrier" price (high by default) upwards. When the current price hits the stop price you exit the trade. Check the chart for more details.
This script demonstrates how to implement the close-based Trailing Take Profit logic for long positions, but it can also be applied for short positions if the logic is "reversed".


📢 NOTE
To generate some entries and showcase the "Trailing Take Profit" technique, this script uses the crossing of two moving averages. Please keep in mind that you should not relate the Backtesting results you see in the "Strategy Tester" tab with the success of the technique itself.
This is not a complete strategy per se, and the backtest results are affected by many parameters that are outside of the scope of this publication. If you choose to use this new approach of the "Trailing Take Profit" in your logic you have to make sure that you are backtesting the whole strategy.


⚔️ Comparison
In contrast to my older "Trailing Take Profit" publication where the trailing take profit implementation was tick-based, this new approach is close-based, meaning that the update of the stop price occurs at the bar close instead of every tick.

While comparing the real-time results of the two implementations is like comparing apples to oranges, because they have different dynamic behavior, the new approach offers better consistency between the backtesting results and the real-time results.
By updating the stop price on every bar close, you do not rely on the backtester assumptions anymore (check the Reasoning section below for more info).
The new approach resembles the conditional "Trailing Exit" technique, where the condition is true when the current price crosses over the take profit target. Then, the stop order is placed at the trailing price and it gets updated on every bar close to "follow" the barrier price (high). On the other hand, the older tick-based approach had more "tight" dynamics since the trailing price gets updated on every tick leaving less room for price fluctuations by making it more probable to reach the trailing price.


🤔 Reasoning
This new close-based approach addresses several practical issues the older tick-based approach had. Those issues arise mainly from the technicalities of the TV Backtester. More specifically, due to the assumptions the Broker Emulator makes for the price action of the history bars, the backtesting results in the TV Backtester are exaggerated, and depending on the timeframe, the backtesting results look way better than they are in reality.
The effect above, and the inability to reason about the performance of a strategy separated people into two groups. Those who never use this feature, because they couldn't know for sure the actual effect it might have in their strategy, (even if it turned out to be more profitable) and those who abused this type of "repainting" behavior to show off, and hijack some boosts from the community by boasting about the "fake" results of their strategies.
Even if there are ways to evaluate the effectiveness of the tick-based approach that is applied in an existing strategy (this is out of the topic of this publication), it requires extra effort to do the analysis. Using this closed-based approach we can have more predictable results, without surprises.


⚠️ Caveats
Since this approach updates the trailing price on bar close, you must wait for at least one bar to close after the price crosses over the take profit target.
เอกสารเผยแพร่

  • Update `chrono_utils` library
moving_averagePine utilitiestakeprofittrailingtrailingtakeprofit

สคริปต์โอเพนซอร์ซ

ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถเข้าใจและตรวจสอบได้ ต้องขอบคุณผู้เขียน! ที่ให้คุณใช้ได้ฟรี แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?


📧 Contact info
Telegram: @jason5480

🔗 Addresses
₿ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7

* Please contact me before any donation ☕

คำจำกัดสิทธิ์ความรับผิดชอบ