OPEN-SOURCE SCRIPT

Trend Retest Strategy

1. The Two Lines: Support & Resistance Levels
Red Line (recentHigh):
Plots the highest price level over the last 7 days (42 bars on the 4-hour timeframe). This acts as a dynamic resistance level.

Example: If price approaches this line and reverses, it signals a potential resistance retest.

Green Line (recentLow):
Plots the lowest price level over the last 7 days (42 bars on 4H). This acts as a dynamic support level.

Example: If price bounces off this line, it signals a support retest.

These lines update automatically as new price data forms.
Why 42 bars?

4-hour chart = 6 bars per day (24 hours / 4 = 6).

6 bars/day × 7 days = 42 bars.

2. Entry Signals (Arrows)
The arrows appear when all your strategy’s conditions align:

For Long Entries (▲ Green Triangle Below Bar):
Daily Trend: Daily RSI ≥ 50 (bullish).

MA Crossover: 20-period SMA crosses above 50-period SMA on the 4H chart.

RSI Confirmation: 4H RSI is ≥ 50 and rising (bullish momentum).

Retest: Price is within 0.5% of either the recentHigh (resistance) or recentLow (support).

Volume: Current volume > 20-period average volume.

Candle Confirmation: A bullish candle closes above the open.

For Short Entries (▼ Red Triangle Above Bar):
Daily Trend: Daily RSI < 50 (bearish).

MA Crossover: 20-period SMA crosses below 50-period SMA on the 4H chart.

RSI Confirmation: 4H RSI is ≤ 50 and falling (bearish momentum).

Retest: Price is near recentHigh or recentLow (same 0.5% threshold).

Volume: Volume exceeds its 20-period average.

Candle Confirmation: A bearish candle closes below the open.

3. How It All Fits Together
Step 1: The indicator checks the daily RSI to confirm the broader trend.

Step 2: On the 4H chart, it tracks the moving averages (MA20 and MA50) and RSI for momentum.

Step 3: When price retests the dynamic support/resistance lines (red/green), it waits for volume and candle confirmation to validate the retest.

Step 4: If all rules align, an arrow appears (long or short).

Example Scenario (Long Entry):
Daily Chart: RSI = 60 (bullish).

4H Chart:

MA20 crosses above MA50.

RSI = 55 and rising.

Price dips to the green support line (within 0.5%).

Volume spikes above average.

A bullish candle closes higher.

Result: A green ▲ appears below the bar.

Feragatname