OPEN-SOURCE SCRIPT

Tri-State Supertrend

تم تحديثه
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 :)
ملاحظات الأخبار
Added alerts (Buy, Sell, Range, Trend Change). Small logic fix.
ملاحظات الأخبار
Improved display of suppressed signals
ملاحظات الأخبار
Fixed the name of the range alert (it was also called "Sell" by accident). Improved label display marginally.
Trend Analysis

نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعد‎‎قوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟


يعمل أيضًا:

إخلاء المسؤولية