OPEN-SOURCE SCRIPT

VAWSI and Trend Persistance Reversal Strategy SL/TP

This is a completely revamped version of my "RSI and ATR Trend Reversal Strategy."

What's New?
The RSI has been replaced with an original indicator of mine, the "VAWSI," as I've elected to call it.
The standard RSI measures a change in an RMA to determine the strength of a movement.
The VAWSI performs very similarly, except it uses another original indicator of mine, the VAWMA.
VAWMA stands for "Volume (and) ATR Weight Moving Average." It takes an average of the volume and ATR and uses the ratio of each bar to weigh a moving average of the source.
It has the same formula as an RSI, but uses the VAWMA instead of an RMA.

Next we have the Trend Persistence indicator, which is an index on how long a trend has been persisting for. It is another original indicator. It takes the max deviation the source has from lowest/highest of a specified length. It then takes a cumulative measure of that amount, measures the change, then creates a strength index with that amount.

The VAWSI is a measure of an emerging trend, and the Trend Persistence indicator is a measure of how long a trend has persisted.

Finally, the 3rd main indicator, is a slight variation of an ATR. Rather than taking the max of source - low or high- source and source - source[1], it instead takes the max of high-low and the absolute value of source - the previous source. It then takes the absolute value of the change of this, and normalizes it with the source.

Inputs

Minimum SL/TP ensures that the Stop Loss and Take Profit still exist in untrendy markets. This is the minimum Amount that will always be applied.

VAWSI Weight is a divided by 100 multiplier for the VAWSI. So value of 200 means it is multiplied by 2. Think of it like a percentage.

Trend Persistence weight and ATR Weight are applied the same. Higher the number, the more impactful on the final calculation it is.

Combination Mult is an outright multiplier to the final calculation. So a 2.0 = * 2.0

Trend Persistence Smoothing Length is the length of the weighted moving average applied to the Trend Persistence Strength index.

Length Cycle Decimal is a replacement of length for the script.
Here we used BlackCat1402's Dynamic Length Calculation, which can be found on his page. With his permission we have implemented it into this script. Big shout out to them for not only creating, but allowing us to use it here.
The Length Cycle Decimal is used to calculate the dynamic length. Because TradingView only allows series int for their built-in library, a lot of the baseline indicators we use have to be manually recreated as functions in the following section.

The Strategy
As usual, we use Heiken Ashi values for calculations.
We begin by establishing the minimum SL/TP for use later.
Next we determine the amount of bars back since the last crossup or crossdown of our threshold line.
We then perform some normalization of our multipliers. We want a larger trend or larger VAWSI amount to narrow the threshold, so we have 1 divide them. This way, a higher reading outputs a smaller number and vice versa. We do this for both Trend Persistence, and the VAWSI.
The VAWSI we also normalize, where rather than it being a 0-100 reading of trend direction and strength, we absolute it so that as long as a trend is strong, regardless of direction, it will have a higher reading. With these normalized values, we add them together and simply subtract the ATR measurement rather than having 1 divide it.

Here you can see how the different measurements add up. A lower final number suggests imminent reversal, and a higher final number suggests an untrendy or choppy market.
ATR is in orange, the Trend Persistence is blue, the VAWSI is purple, and the final amount is green.

We take this final number and depending on the current trend direction, we multiply it by either the Highest or Lowest source since the last crossup or crossdown. We then take the highest or lowest of this calculation, and have it be our Stop Loss or Take Profit. This number cannot be higher/lower than the previous source to ensure a rapid spike doesn't immediately close your position on a still continuing trend. As well, the threshold cannot be higher/ lower than the the specified Stop Loss and Take Profit

Only after the source has fully crossed these lines do we consider it a crossup or crossdown. We confirm this with a barstate.isconfirmed to prevent repainting. Next, each time there is a crossup or crossdown we enter a long or a short respectively and plot accordingly.

I have the strategy configured to "process on order close" to ensure an accurate backtesting result. You could also set this to false and add a 1 bar delay to the "if crossup" and "if crossdown" lines under strategy so that it is calculated based on the open of the next bar.

Final Notes
The amounts have been preconfigured for performance on RIOT 5 Minute timeframe. Other timeframes are viable as well. With a few changes to the parameters, this strategy has backtested well on NVDA, AAPL, TSLA, and AMD. I recommend before altering settings to try other timeframes first.

This script does not seem to perform nearly as well in typically untrendy and choppy markets such as crypto and forex. With some setting changes, I have seen okay results with crypto, but overfitting could be the cause there.

Thank you very much, and please enjoy.
Notas de prensa
Updated Chart
Notas de prensa
I updated the minimum/maximum on the upper and lower bands to instead be open rather than src[1]. This should prevent the strategy from entering buys/sells when the price is moving in an undesirable direction just because the daily open was higher than the previous days close.
Bands and Channelsoriginalstoplosstakeprofittrendreversal

Script de código abierto

Siguiendo fielmente el espíritu de TradingView, el autor de este script lo ha publicado en código abierto, permitiendo que otros traders puedan entenderlo y verificarlo. ¡Olé por el autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la reutilización de este código en la publicación se rige por las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.