OPEN-SOURCE SCRIPT

EMA Crossover Indicator with UTC Time Filter and Profit Labels

190
The PineScript code provided is an indicator for TradingView that implements two user-defined Exponential Moving Averages (EMAs) with default periods of 5 and 9, generates buy and sell signals at EMA crossovers, filters these signals based on a user-specified UTC time window, and adds labels when the price moves 100 points in the profitable direction from the entry point. Below is a detailed description of the script's functionality, structure, and key components:

Overview
Purpose: The indicator plots two EMAs on the chart, identifies crossover points to generate buy and sell signals, restricts signals to a user-defined UTC time range, and labels instances where the price moves 100 points in the profitable direction after a signal.
  • Platform:
Written in PineScript v5 for TradingView.
  • Indicator Type:
Overlay indicator (plotted directly on the price chart).

Key Features
  1. User-Defined EMAs:

The script calculates two EMAs based on user inputs:

Short EMA: Default period is 5 bars.

  • - **Long EMA**:
Default period is 9 bars.

Users can adjust these periods via input settings (minimum period of 1).

2. Crossover Signals:

Buy Signal: Triggered when the Short EMA crosses above the Long EMA
( ta.crossover ).

Sell Signal: Triggered when the Short EMA crosses below the Long EMA
( ta.crossunder ).

Labels are added at these crossover points:

"BUY" label (green, positioned below the bar) for bullish crossovers.

"SELL" label (red, positioned above the bar) for bearish crossovers.

3. UTC Time Filter:

Users can specify a UTC time window during which signals are valid.

Inputs include:

Start Hour and Minute (default: 00:00 UTC).

End Hour and Minute (default: 23:59 UTC).

The isTimeInRange() function checks if the current bar's timestamp falls within this
window, handling both same-day and overnight ranges (e.g., 22:00 to 02:00).

Only crossovers occurring within the specified time window generate signals and
labels.

4. Profit Tracking (+100 Points):

The script tracks the price movement after a buy or sell signal:

For a buy signal, a "+100" label is added if the price increases by 100 points
or more from the entry price.

For a sell signal, a "+100" label is added if the price decreases by 100 points
or more from the entry price.

The points threshold is user-configurable (default: 100.0 points).

Labels are color-coded (green for buy, red for sell) and placed only once per signal to
avoid chart clutter.

5. Visual Elements:

EMAs: Plotted on the chart (Short EMA in blue, Long EMA in red).
Labels:

Buy/Sell crossover labels are placed at the low/high of the bar, respectively.

"+100" labels are placed at the low (for buy) or high (for sell) of the bar where
the profit threshold is met.

Code Structure
Indicator Declaration:

indicator("EMA Crossover Indicator with UTC Time Filter and Profit Labels",
overlay=true): Defines the indicator name and sets it to overlay on the price chart.

Inputs:
emaShortPeriod and emaLongPeriod: Integer inputs for EMA periods
(defaults: 5 and 9).

startHour, startMinut, endHour, endMinute: Integer inputs for UTC time window
(defaults: 00:00 to 23:59).

pointsThreshold: Float input for the profit target (default: 100.0 points).

EMA Calculations:

emaShort = ta.ema(close, emaShortPeriod): Computes the Short EMA using the
closing price.
emaLong = ta.ema(close, emaLongPeriod): Computes the Long EMA.

Time Filter Function:

isTimeInRange(0: Converts the current bar's UTC time and user inputs to minutes,
then checks if the current time is within the specified range. Handles overnight
ranges correctly.

State Management:

Variables: entryPrice (stores signal entry price), isBuySignal and isSellSignal (track
active signal type), `profitLabelPlaced` (prevents multiple profit labels).

Reset on new signals to prepare for the next trade.

Signal Detection and Labeling:


Detects crossovers using ta.crossover and ta.crossunder.

Places "BUY" or "SELL" labels if the crossover occurs within the UTC time window.

Monitors price movement post-signal and places a "+100" label when the threshold is
met.

Usage
Setup: Add the indicator to a TradingView chart. Adjust EMA periods, UTC time
window, and points threshold via the indicator settings.
Output:

Two EMA lines (blue and red) appear on the chart.

"BUY" and "SELL" labels appear at valid crossover points within the UTC time window.

"+100" labels appear when the price moves 100 points in the profitable direction after
a signal.
Applications: Useful for traders who want to:

Follow EMA crossover strategies.
Restrict trading signals to specific time sessions (e.g., London or New York session).
- Identify when a trade reaches a specific profit target.

Notes
Points Definition: The 100-point threshold is in the same units as the asset's
price (e.g., $100 for stocks, 100 pips for forex). Adjust `pointsThreshold` for
different assets.

Time Zone: Signals are filtered based on UTC time, ensuring consistency across
markets.
Label Management: The script ensures only one "+100" label per signal to keep
the chart clean.
Limitations: The profit label is triggered only once per signal and does not
account for multiple hits of the threshold unless a new signal occurs.

If you need further clarification or want to add features (e.g., alerts, additional profit levels, or different time filters), let me know!

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.