OPEN-SOURCE SCRIPT

EMA 200 MultiTF G/R + Cross Alerts by LifeHack Trader

37
1. Indicator Setup

The script starts by defining the version of Pine Script (v5) and creating an indicator called "EMA 200 MultiTF G/R + Cross Alerts by LifeHack Trader."

The overlay=true parameter ensures that the indicator is plotted directly on the price chart.

2. Function to Get EMA200

A custom function getEma200 is defined to retrieve the 200-period Exponential Moving Average (EMA) for a specified timeframe (tf).

This function uses the request.security function to fetch the close price's EMA from different timeframes.

3. Calculate EMA200 for Multiple Timeframes

The script calculates the EMA200 for four timeframes: 15 minutes ("15"), 1 hour ("60"), 4 hours ("240"), and 1 day ("D").

These values are stored in variables (ema15, ema1h, ema4h, ema1d) and represent the EMA for each timeframe.

4. Determine Price Above or Below EMA200 (G/R)

For each timeframe, the script checks whether the closing price is above or below the EMA200.

It uses boolean checks to determine if the price is above the EMA200, assigning the status "G" (Green) for above and "R" (Red) for below.

5. Cross Signal Detection (Up/Down)

The script detects crossovers and crossunders between the price and EMA200 for each timeframe.

A crossover signal is detected when the price crosses above the EMA200 (bullish), and a crossunder signal is detected when the price crosses below the EMA200 (bearish).

These signals are stored in separate variables (crossUp, crossDown).

6. Display a Table with G/R Status and Cross Alerts

A table is created and displayed in the top-right corner of the chart. The table shows the status (G or R) for each timeframe and the cross signal (▲ for crossover, ▼ for crossunder, or - for no cross event).

The table is updated with the respective values for each timeframe every time a new bar is formed.

7. Alert Conditions

The script defines alert conditions based on the crossovers and crossunders.

When a price crosses above the EMA200 (cross-up), an alert is triggered for a potential buy opportunity. When the price crosses below the EMA200 (cross-down), an alert is triggered for a potential sell opportunity.

Alerts are configured for each timeframe (15 minutes, 1 hour, 4 hours, and 1 day).

This script provides a comprehensive system for monitoring price action relative to the EMA200 on multiple timeframes, highlighting crossovers, and delivering visual feedback and alerts based on the price's relationship with the EMA.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。