OPEN-SOURCE SCRIPT

Aroon Buy & Sell (5m Trend, 100% Signal on 1m)

199
Purpose of the Script:
This Pine Script creates a buy and sell signal system that:

Tracks trend direction on the 5-minute (5m) chart using Aroon indicators.

Generates buy and sell signals on the 1-minute (1m) chart based on the 5-minute trend and when Aroon Up/Down reaches 100%.

Components of the Script:
1. Aroon Calculation Function (f_aroon):
This function calculates the Aroon Up and Aroon Down values based on the high and low of the last 14 bars:

Aroon Up: Measures how recently the highest high occurred over the last 14 bars.

Aroon Down: Measures how recently the lowest low occurred over the last 14 bars.

Both values are expressed as a percentage:

Aroon Up is calculated by 100 * (14 - barssince(high == highest(high, 14))) / 14

Aroon Down is calculated by 100 * (14 - barssince(low == lowest(low, 14))) / 14

2. Getting Aroon Values for 5m and 1m:
aroonUp_5m, aroonDown_5m: These are the Aroon values calculated from the 5-minute chart (Aroon Up and Aroon Down).

aroonUp_1m, aroonDown_1m: These are the Aroon values calculated for the 1-minute chart, on which we will plot the signals.

3. Trend Detection (5-minute):
Bullish trend: When the Aroon Up crosses above the Aroon Down on the 5-minute chart, indicating a potential upward movement (uptrend).

Bearish trend: When the Aroon Down crosses above the Aroon Up on the 5-minute chart, indicating a potential downward movement (downtrend).

These are detected using ta.crossover() functions:

bullishCross_5m: Detects when Aroon Up crosses above Aroon Down.

bearishCross_5m: Detects when Aroon Down crosses above Aroon Up.

We then track these crossovers using two variables:

inBullishTrend_5m: This is set to true when we are in a bullish trend (Aroon Up crosses above Aroon Down on 5m).

inBearishTrend_5m: This is set to true when we are in a bearish trend (Aroon Down crosses above Aroon Up on 5m).

4. Cooldown Logic:
This prevents the signals from repeating too frequently:

buyCooldown: Ensures that a buy signal is only generated every 20 bars (approx. every 100 minutes).

sellCooldown: Ensures that a sell signal is only generated every 20 bars (approx. every 100 minutes).

We use:

buyCooldown := math.max(buyCooldown - 1, 0) and sellCooldown := math.max(sellCooldown - 1, 0) to decrease the cooldown over time.

5. Buy/Sell Signal Logic:
Buy signal: A buy signal is generated when:

The 5-minute trend is bullish (Aroon Up > Aroon Down on 5m).

Aroon Down on the 1-minute chart reaches 100% (indicating an extreme oversold condition in the context of the current bullish trend).

The signal is only generated if the cooldown (buyCooldown == 0) allows it.

Sell signal: A sell signal is generated when:

The 5-minute trend is bearish (Aroon Down > Aroon Up on 5m).

Aroon Up on the 1-minute chart reaches 100% (indicating an extreme overbought condition in the context of the current bearish trend).

The signal is only generated if the cooldown (sellCooldown == 0) allows it.

6. Plotting the Signals:
Plot Buy Signals: When a buy signal is triggered, a green "BUY" label is plotted below the bar.

Plot Sell Signals: When a sell signal is triggered, a red "SELL" label is plotted above the bar.

The signal conditions are drawn on the 1-minute chart but rely on the trend from the 5-minute chart.

7. Alert Conditions:
Alert for Buy signal: An alert is triggered when the buy signal condition is met.

Alert for Sell signal: An alert is triggered when the sell signal condition is met.

How It Works:
Trend Tracking (5m): The script looks for the trend on the 5-minute chart (bullish or bearish based on Aroon Up/Down crossover).

Signal Generation (1m): The script then checks the 1-minute chart for an Aroon value of 100% (for either Aroon Up or Aroon Down).

Signals: Based on the trend, if the conditions are met, the script plots buy/sell signals and sends an alert.

Key Points:
5-minute trend: The script determines the market trend on the 5-minute chart.

1-minute signal: Signals are plotted on the 1-minute chart based on Aroon values reaching 100%.

Cooldown: Prevents signals from repeating too frequently.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.