OPEN-SOURCE SCRIPT

Target Trend + Filter Toggles Strategy [ChadAnt]

73
The strategy aims to enter a trade when the price crosses over/under a dynamic trend band and when a combination of user-selected filters confirms the move.

1. Trend Bands (Entry)
The core trend is defined by two smoothed moving averages (SMA based on length input) offset by a smoothed Average True Range (ATR) value.

Upper Band (sma_high): ta.sma(high, length) + atr_value

Lower Band (sma_low): ta.sma(low, length) - atr_value

atr_value is ta.sma(ta.atr(atrLength), smaLength) * atrMultiplier.

Trend Determination:

Long Trend (trend = true): Price crossovers the sma_high band.

Short Trend (trend = false): Price crossesunder the sma_low band.

Raw Signal: A trade signal (signal_up_raw / signal_down_raw) is triggered only when the trend state changes.

2. Stop Loss and Take Profit
Stop Loss (SL):

For a Long entry, the original stop price is the Lower Band (sma_low) at the time of the cross.

For a Short entry, the original stop price is the Upper Band (sma_high) at the time of the cross.

The Stop Loss Price is calculated using the distance from the entry price to the original stop, adjusted by the slAdjustment multiplier.

Take Profit (TP):

Calculated based on a Risk/Reward (R:R) ratio, which is rr_increment * tp_target_number.

TP Distance = Adjusted Stop Distance * R:R Ratio.

The strategy enters and exits in a single order pair using strategy.entry and strategy.exit, using the calculated stop_loss_price and take_profit_price.

3. Filters and Confirmation
The strategy includes toggles (use_..._filter) for many popular indicators: MACD, Volume, StochRSI, Awesome Oscillator (AO), and Moving Average/VWAP (Trend/Counter-Trend).

Filter Logic: Each filter checks for its specific confirmation condition (e.g., MACD zero-cross, AO color change, StochRSI out of extreme, Volume > SMA, Price above MA).

Lookback Period: The script uses a for loop (i = 0 to filter_lookback) to check if the required confirmation happened within the last filter_lookback bars.

Final Signal: The actual entry signal (signal_up / signal_down) is triggered only if the Raw Trend Change Signal occurs AND all currently active (toggled on) filters had their required confirmation event within the lookback period AND the trade is within the Time Window.

The draw_targets method is responsible for the powerful visual display on the chart:

When a new filtered signal occurs, it clears any old lines/labels and draws the new:

Entry line

Stop Loss line

Multiple Take Profit lines (up to num_targets), with the strategy's active TP level highlighted (🎯).

It also features logic to dynamically change the label/line of a TP level to a "✔" or the SL level to a "✖" if the price touches that level on subsequent bars.

The strategy is a highly flexible, multi-factor system built on the concept of trend reversal confirmation.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.