OPEN-SOURCE SCRIPT
Atualizado

Previous Candle Range indicator

506
Primary Functions:
  1. Display the high, low, open, and close of the previous candle from a selected timeframe
  2. Show a 50% level (midpoint between high and low)
  3. Optionally show customizable percentage levels (e.g., 61.8% Fibonacci level)
  4. Help identify:

  • Support and resistance zones
  • Breakout levels
  • Potential reversal points
  • Stop-loss and take-profit placements


🎨 Visual Design

Line Color Style Width Description
-----------------------------------------------------------------------------------------------------------------
High White (25% opacity) Dashed 1 Previous candle's highest price

Low White (25% opacity) Dashed 1 Previous candle's lowest price

Open Green (#13ab22) Solid 2 Previous candle's opening price (bullish candle)

Close Green (#13ab22) Solid 2 Previous candle's closing price (bullish candle)

Open Red (#af5c4c) Solid 2 Previous candle's opening price (bearish candle)

Close Red (#af5c4c) Solid 2 Previous candle's closing price (bearish candle)

50% Level Blue (#0d6aec) Dashed 1 Midpoint between high and low

Custom Level Gre (#b0d837) Dashed 1 User-defined percentage level
-----------------------------------------------------------------------------------------------------------------
How It Works
1. Timeframe Logic
  • The indicator detects if the current chart timeframe is smaller than the selected reference timeframe
  • Lines are only displayed when the current chart is at or below the selected timeframe
  • Example: If "D" is selected, lines show on charts ≤ Daily timeframe


2. Candle Data Retrieval
  • Uses request.security() to fetch OHLC data from the selected timeframe
  • Always gets the previous candle (not the current)
  • Updates when a new candle forms on the selected timeframe

4. Line Management
  • Lines extend 19 bars forward from their start point
  • Old lines are deleted when a new candle forms
  • Lines are hidden when chart timeframe > selected timeframe


Best Practices
✅ When to Use
  • Multi-timeframe analysis: Identify key levels from higher timeframes
  • Swing trading: Use daily/weekly levels for swing positions
  • Day trading: Use 1H/4H levels for intraday trades
  • Scalping: Use 5m/15m levels for quick trades


⚠️ Important Notes
  • Lines extend 19 bars forward - adjust if needed
  • Weekly and Monthly timeframes ignore weekends for accuracy
  • The indicator works best with clear price action
  • Combine with other indicators for confirmation


The combination of the 50% level and customizable percentage levels makes it suitable for various trading styles, from scalping to swing trading.
Created by: Awab_Hassan
Notas de Lançamento
X
Notas de Lançamento
X
Notas de Lançamento
X
Notas de Lançamento
Overview
This update modernises the indicator, making it more accurate, maintainable, and feature‑rich. Key improvements include time‑based line drawing, support for higher timeframe EMAs, and the addition of three new monthly timeframes (3‑Month, 6‑Month, 12‑Month) for longer‑term analysis. The entire codebase has been refactored for clarity and performance.

1. Extended Timeframe Options
Updated the switch mapping with the correct minute equivalents.
Why: Enables traders to analyse quarterly, semi‑annual, and yearly ranges directly, without having to switch timeframes. This is particularly useful for swing and position traders who monitor key structural levels.

2. Line Drawing – From Bar‑Index to Time‑Based Coordinates
Old: Used xloc.bar_index with a fixed extension (number of bars to the right). This caused misalignment when the chart had gaps, different compression, or after scrolling.

New: Uses xloc.bar_time and explicit OpenTime / CloseTime (computed with timezone support). The extension input and all barindex logic have been removed.
Lines now perfectly span the entire selected timeframe (e.g., the exact 4‑hour session) regardless of missing bars or chart zoom. This ensures levels are always anchored to the actual candle boundaries.

3. New Feature: Higher Timeframe EMA Confirmation
Added inputs: allow_EMA, lenEMA, src, offset.

Added a plot() call that displays the EMA (computed on the selected higher timeframe) directly on the chart, with low opacity.

Why: Provides an extra layer of context – the EMA shows the prevailing trend on the same timeframe as the range, helping traders decide whether to favour breakouts or rejections. This is a common requirement for multi‑timeframe strategies.

Overall Benefits
Accurate levels – always match the exact high/low/close of the previous period, even on irregular charts.
Greater analytical power – new monthly timeframes and built‑in EMA simplify multi‑timeframe analysis.
Cleaner – easier to customise and maintain.
Time‑zone aligned – reliable for session‑based trading.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.