XPeriodCandle_HTF
Download scriptThis script is a specialized financial trading tool designed to handle "Multi-Timeframe" data analysis. In simple terms, it allows a trader to look at information from a higher timeframe (like a 4-hour chart) while they are currently viewing a lower timeframe (like a 15-minute chart) without losing the visual context of the current price action.
Here is a breakdown of how the logic works:
Core Functionality
The primary job of this script is to bridge the gap between different time periods. It creates a custom visual element—specifically "Candles"—that represents data from a higher timeframe but displays them onto your current chart. This helps traders identify the broader market trend and significant price levels (the "big picture") while simultaneously executing trades on smaller, faster movements.
Key Logical Components
-
Higher Timeframe Retrieval: The script is configured to look at a specific higher timeframe (defaulting to H4). It systematically pulls data from that timeframe—specifically the Open, High, Low, and Close prices—and maps them onto the current view.
-
Dynamic Smoothing: To make the data more readable and less "noisy," the script includes a sophisticated smoothing engine. It offers several different mathematical methods (such as SMA, EMA, JJMA, etc.) to ensure that the visual representations of the higher timeframe candles aren't too erratic or jagged.
-
Visual Rendering: Instead of just plotting simple lines, the script is designed to draw actual candle shapes. It handles five distinct data "buffers":
- The High price point.
- The Low price point.
- The Open price point.
- The Close price point.
- A color index that determines whether the candle should appear bullish, bearish, or neutral based on the price action of that period.
-
Smart Synchronization: One of the most complex parts of the logic is how it handles "Time Alignment." Because a single 4-hour candle covers many smaller 15-minute candles, the script uses a counting and mapping system. It ensures that the data from the higher timeframe is correctly placed so that it aligns perfectly with the timestamps on your current chart. It effectively "stretches" or "aligns" the big data points to fit the small ones without creating gaps or overlapping errors.
Summary for the User
When you use this, you aren't just seeing a line; you are seeing a visual overlay of "Parent Candles." This allows you to see where the major price boundaries were set on a larger scale, helping you avoid trading against the primary momentum of the market while still enjoying the precision of a smaller timeframe.
ÿþ/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
/ / | X P e r i o d C a n d l e _ H T F . m q 5 |
/ / | C o p y r i g h t © 2 0 1 8 , N i k o l a y K o s i t s i n |
/ / | K h a b a r o v s k , f a r r i a @ m a i l . r e d c o m . r u |
/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
# p r o p e r t y c o p y r i g h t "