Candles_last4barsEli_mtf

Download script
Author: Copyright � 2006, Eli Hayun
Candles_last4barsEli_mtf

This script is designed for traders who need to visualize higher time frame price action directly on their current chart. Its primary purpose is to "project" the visual data of larger candles onto a smaller, more granular timeframe, allowing you to see the broader market structure without having to switch back and forth between different windows.

Core Functionality

The logic operates by identifying the price movements of a higher time frame (such as a 4-hour or Daily candle) and drawing them as distinct visual objects on your current chart. Instead of just showing a single line, it reconstructs the "body" and "range" of those larger candles so you can see where the price is moving in relation to the bigger picture.

How it Works

  • Multi-Timeframe Awareness: The script looks at a specific higher time frame defined by the user (for example, 240 minutes). It captures the high, low, open, and close prices from that timeframe.
  • Visual Reconstruction: For every large candle on that higher timeframe, the script draws two specific components on your screen:
    1. The Range (High/Low): It identifies the full vertical span of the larger candle.
    2. The Body (Open/Close): It highlights the actual "meat" of the price movement—the difference between where the price opened and where it closed.
  • Dynamic Coloring: To make the chart easy to read at a glance, the script automatically changes colors based on the price action. If the higher timeframe candle was bullish (closed higher than it opened), it paints the objects in a specific "Up" color; if it was bearish, it switches to a "Down" color.
  • Continuous Updates: The logic is built to refresh constantly. As new price data comes in, the script cleans up old drawings and redraws them to ensure that your visual representation of the market structure remains accurate and up-to-date.

User Experience

For the trader, this means you can stay on a 1-minute or 5-minute chart to catch precise entries while still seeing clearly defined blocks representing the 4-hour or Daily trends. It bridges the gap between "big picture" analysis and "micro" execution by providing a real-time visual overlay of the dominant market candles.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each bar
12 Views
0 Downloads
0 Favorites
Candles_last4barsEli_mtf
//+------------------------------------------------------------------+
//|                                                 #MTF Candles.mq4 |
//|                                      Copyright © 2006, Eli Hayun |
//|                                          http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli Hayun"
#property link      "http://www.elihayun.com"
//----
#property indicator_chart_window
//---- input parameters
extern int       CandlesTF=240;
extern color     UpCandleColor=DeepSkyBlue;
extern color     DownCandleColor=Red;
extern int       withHL = 2;
extern int       withOC = 4;
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-currentTF";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() 
  {
  DeleteObjects();
  }

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() 
 {
  DeleteObjects();

  return(0);
 }


void DeleteObjects() 
   {


   double dif=MathAbs(Time[1] - Time[2]);
   int ix=0;
   datetime dtStart=dif * 8 + Time[0];
   for(int ii=0; ii<8; ii+=2)
     {
      ObjectDelete("rect"+ii); 
      ObjectDelete("OTrnd"+ii); 
      ObjectDelete("CTrnd"+ii);

     }     
 return(0); 
}



//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   double dif=MathAbs(Time[1] - Time[2]);
   int ix=0;
   datetime dtStart=dif * 8 + Time[0];
   for(int ii=0; ii<8; ii+=2)
     {
      ObjectDelete("rect"+ii); ObjectDelete("OTrnd"+ii); ObjectDelete("CTrnd"+ii);
      
      ObjectCreate("rect"+ii,OBJ_TREND, 0, dtStart, iLow(NULL, CandlesTF,ix), dtStart, iHigh(NULL,CandlesTF,ix));
      color clr=DownCandleColor; if (iOpen(NULL, CandlesTF,ix) < iClose(NULL, CandlesTF,ix)) clr=UpCandleColor;
      ObjectSet("rect"+ii, OBJPROP_COLOR, clr);
      ObjectSet("rect"+ii, OBJPROP_WIDTH, withHL);
      ObjectSet("rect"+ii, OBJPROP_RAY, False);
    
      ObjectCreate("OTrnd"+ii, OBJ_TREND, 0, dtStart, iOpen(NULL, CandlesTF,ix), dtStart, iClose(NULL,CandlesTF,ix));
      ObjectSet("OTrnd"+ii, OBJPROP_COLOR, clr);
      ObjectSet("OTrnd"+ii, OBJPROP_WIDTH, withOC);
      ObjectSet("OTrnd"+ii, OBJPROP_RAY, False);
//    ObjectSet("CTrnd"+ii, OBJPROP_WIDTH, 2);
      
//    ObjectCreate("CTrnd"+ii, OBJ_TREND, 0, dtStart, iClose(NULL, CandlesTF,ix), dtStart+dif, iClose(NULL,CandlesTF,ix));
//    ObjectSet("CTrnd"+ii, OBJPROP_WIDTH, 2);
//    ObjectSet("CTrnd"+ii, OBJPROP_RAY, False);
      dtStart-=dif * 2;
      ix++;

//    if (CandlesTF <Period()) CandlesTF =Period();

    }
//----
   return(0);
 }
//+------------------------------------------------------------------+

Comments