StefanReich

Tri-State Supertrend

StefanReich Cập nhật   
Tri-State Supertrend: Buy, Sell, Range

(Credits: Based on "Pivot Point Supertrend" by LonesomeTheBlue.)

Tri-State Supertrend incorporates a range filter into a supertrend algorithm.

So in addition to the Buy and Sell states, we now also have a Range state.

This avoids the typical "whipsaw" problem: During a range, a standard supertrend algorithm will fire Buy and Sell signals in rapid succession. These signals are all false signals as they lead to losing positions when acted on.

In this case, a tri-state supertrend will go into Range mode and stay in this mode until price exits the range and a new trend begins.

I used Pivot Point Supertrend by LonesomeTheBlue as a starting point for this script because I believe LonesomeTheBlue's version is superior to the classic Supertrend algorithm.

This indicator has two additional parameters over Pivot Point Supertrend:

  1. A flag to turn the range filter on or off
  2. A range size threshold in percent

With that last parameter, you can define what a range is. The best value will depend on the asset you are trading.

Also, there are two new display options.

  1. "Show (non-) trendline for ranges" - determines whether to draw the "trendline" inside of a range. Seeing as there is no trend in a range, this is usually just visual noise.
  2. "Show suppressed signals" - allows you to see the Buy/Sell signals that were skipped by the range filter.

How to use Tri-State Supertrend in a strategy

You can use the Buy and Sell signals to enter positions as you would with a normal supertrend. Adding stop loss, trailing stop etc. is of course encouraged and very helpful. But what to do when the Range signal appears?

I currently run a strategy on LDO based on Tri-State Supertrend which appears to be profitable. (It will quite likely be open sourced at some point, but it is not released yet.)

In that strategy, I experimented with different actions being taken when the Range state is entered:

  • Continue: Just keep last position open during the range
  • Close: Close the last position when entering range
  • Reversal: During the range, execute the OPPOSITE of each signal (sell on "buy", buy on "sell")

In the backtest, it transpired that "Continue" was the most profitable option for this strategy.

How ranges are detected

The mechanism is pretty simple: During each Buy or Sell trend, we record price movement, specifically, the furthest move in the trend direction that was encountered (expressed as a percentage).

When a new signal is issued, the algorithm checks whether this value (for the last trend) is below the range size set by the user. If yes, we enter Range mode.

The same logic is used to exit Range mode. This check is performed on every bar in a range, so we can enter a buy or sell as early as possible.

I found that this simple logic works astonishingly well in practice.

Pros/cons of the range filter

A range filter is an incredibly useful addition to a supertrend and will most likely boost your profits.

You will see at most one false signal at the beginning of each range (because it takes a bit of time to detect the range); after that, no more false signals will appear over the range's entire duration. So this is a huge advantage.

There is essentially only one small price you have to pay:

When a range ends, the first Buy/Sell signal you get will be delayed over the regular supertrend's signal. This is, again, because the algorithm needs some time to detect that the range has ended. If you select a range size of, say, 1%, you will essentially lose 1% of profit in each range because of this delay.

In practice, it is very likely that the benefits of a range filter outweigh its cost. Ranges can last quite some time, equating to many false signals that the range filter will completely eliminate (all except for the first one, as explained above).

You have to do your own tests though :)
Phát hành các Ghi chú:
Added alerts (Buy, Sell, Range, Trend Change). Small logic fix.
Phát hành các Ghi chú:
Improved display of suppressed signals
Phát hành các Ghi chú:
Fixed the name of the range alert (it was also called "Sell" by accident). Improved label display marginally.

Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?