CustomCandle_MTF

Download script
Author: � 2006, mankurt
CustomCandle_MTF

This script is designed as a visual overlay for the MetaTrader trading platform. Its primary purpose is to aggregate and display higher-timeframe price data directly onto your current chart, allowing you to see the "big picture" movements without constantly switching between different time intervals.

Core Functionality

The logic works by taking a larger timeframe (which you specify in the settings) and projecting its price action—specifically the candles' bodies and their high/low extremes—onto the smaller timeframe chart you are currently viewing. It acts as a visual bridge, syncing multi-timeframe analysis into a single view.

Key Logic Components

1. Timeframe Compatibility & Filtering The script includes built-in "rules of engagement." It checks to ensure that the timeframe you want to see is compatible with your current chart (for example, it ensures the higher timeframe is actually larger than your current one and divisible by the current period). If the settings don't align correctly, the script will provide an on-screen notification explaining why it cannot display the data.

2. Dynamic Object Creation Instead of simply drawing lines, the script dynamically creates and manages visual objects:

  • Rectangles: These represent the "body" of the higher timeframe candle. They change color based on price movement (Green for upward moves, Red for downward moves).
  • Trendlines/Shadows: These represent the "wicks" or extremes of the higher timeframe price action. The script identifies the highest and lowest points reached during that specific period and draws them accordingly.

3. Intelligent Color Coding & Labeling The script automatically analyzes the relationship between the opening and closing prices of the higher timeframe candle to determine its visual properties:

  • Bullish Move: If the price closed higher than it opened, the body is colored as an "Up Bar."
  • Bearish Move: If the price closed lower than it opened, the body is colored as a "Down Bar."
  • Neutral Move (Doji): If the price closed exactly where it opened, it identifies this as a "Doji" and applies a unique neutral color.
  • Data Labels: The script attaches text labels to these shapes, providing the exact numerical values for the Open, High, Low, and Close prices directly on the chart.

4. Real-Time Updates The logic is designed to be "live." It continuously monitors the current price action. As the current higher timeframe candle evolves, the script updates the dimensions and positions of the visual shapes in real-time. Once a higher timeframe period completes, it archives that data as a finished object and begins drawing the next one.

5. On-Screen Dashboard In addition to the visual shapes on the chart, the script provides a text summary in the corner of the screen. This gives you a quick numerical readout of the current higher timeframe's Open, High, Low, and Close prices at a glance.

6 Views
0 Downloads
0 Favorites
CustomCandle_MTF
#property link      "mankurt@freemail.ru"
#property copyright "© 2006, mankurt"
#property indicator_chart_window
//+------------------------------------------------------------------------------------------------+
extern int   TimeFrame=240;
extern color UpCandle=Lime;
extern color DnCandle=Red;
extern color DojiColor=Blue;
extern int   Width=1;
extern bool  BGCandle=false;
//+------------------------------------------------------------------------------------------------+
int      Nbar,OpenBar,timer,i,timerTF,name,MidBar;
double   HighPrevBar,LowPrevBar,ClosePrevBar;
double   OpenNewBar,HighNewBar,LowNewBar,CloseNewBar;
double   HighCurBar,LowCurBar,CloseCurBar;
double   priceNewSH,priceNewSL,pricePrevSH,pricePrevSL,priceCurSH,priceCurSL;
string   nameNewCandle,namePrevCandle;
string   nameNewShadowH,nameNewShadowL,namePrevShadowH,namePrevShadowL;
string   NameBar, NameHigh, NameLow;
datetime TimeOpenNewBar,TimeCloseNewBar,TimeClosePrevBar;
datetime timeNewShadow,timePrevShadow;
bool     NewBar;
//+------------------------------------------------------------------------------------------------+
int init(){
IndicatorShortName("M"+TimeFrame+" íà M"+Period());
Nbar=TimeFrame/Period();
timer=Period()*60;
timerTF=TimeFrame*60;
name=0;
TimeOpenNewBar=Time[Bars-1];
OpenNewBar=Open[Bars-1];
NewBar=false;
NameBar="Bar M"+TimeFrame+"-";
NameHigh="High M"+TimeFrame+"-";
NameLow="Low M"+TimeFrame+"-";
return(0);}
//+------------------------------------------------------------------------------------------------+
int deinit(){
for(int DelOBJ=1; DelOBJ<=name; DelOBJ++){
ObjectDelete(NameBar+DelOBJ);
ObjectDelete(NameHigh+DelOBJ);
ObjectDelete(NameLow+DelOBJ);}
Comment("");
return(0);}
//+------------------------------------------------------------------------------------------------+
int start(){
if(TimeFrame>1440)
{Comment("\n"," TimeFrame more than D1 is not supporting!!!");return(0);}
if(Period()>240)
{Comment("\n"," Period more than H4 is not supporting!!!");return(0);}
if(TimeFrame<=Period()||MathMod(TimeFrame,Period())!=0)
{Comment("\n"," TimeFrame should be more or divisible by M",Period());return(0);}
i=Bars-IndicatorCounted();
while(i>0){i--;
while(i>=0) if(Time[i]==TimeOpenNewBar||BarNew(i,TimeFrame)==false)i--;
             else{NewBar=true; name++; break;}
if(i<0) i=0;
if(NewBar==true){
//+-----------------------------------------Previos Bar--------------------------------------------+
  OpenBar=iBarShift(0,0,TimeOpenNewBar,false);
  TimeClosePrevBar=Time[i+1];
  ClosePrevBar=Close[i+1];
  HighPrevBar=High[Highest(0,0,MODE_HIGH,OpenBar-i,i+1)];
  LowPrevBar=Low[Lowest(0,0,MODE_LOW,OpenBar-i,i+1)];
  namePrevCandle=NameBar+(name-1);
  MidBar=OpenBar-MathRound((OpenBar-i)/2);
  timePrevShadow=Time[MidBar];
  pricePrevSH=PriceShadow(OpenNewBar,ClosePrevBar,0);
  pricePrevSL=PriceShadow(OpenNewBar,ClosePrevBar,1);
  namePrevShadowH=NameHigh+(name-1);
  namePrevShadowL=NameLow+(name-1);
//+----------------------------------Modifi Previos Bar & Shadow-----------------------------------+
if(ObjectFind(namePrevCandle)==0){
  ObjectMove(namePrevCandle,1,TimeClosePrevBar,ClosePrevBar);
  PropBar(OpenNewBar,ClosePrevBar,namePrevCandle);
  if(OpenBar==i+1) ObjectSet(namePrevCandle,OBJPROP_WIDTH, Width*3);}
if(ObjectFind(namePrevShadowH)==0){
  if(pricePrevSH==HighPrevBar) ObjectDelete(namePrevShadowH);
   else{ObjectMove(namePrevShadowH,0,timePrevShadow,pricePrevSH);
    ObjectMove(namePrevShadowH,1,timePrevShadow,HighPrevBar);
    ColorShadow(OpenNewBar,ClosePrevBar,namePrevShadowH);
    ObjectSetText(namePrevShadowH,"High="+DoubleToStr(HighPrevBar,Digits),7,"Tahoma");}}
if(ObjectFind(namePrevShadowL)==0){
  if(pricePrevSL==LowPrevBar) ObjectDelete(namePrevShadowL);
   else{ObjectMove(namePrevShadowL,0,timePrevShadow,pricePrevSL);
    ObjectMove(namePrevShadowL,1,timePrevShadow,LowPrevBar);
    ColorShadow(OpenNewBar,ClosePrevBar,namePrevShadowL);
    ObjectSetText(namePrevShadowL,"Low="+DoubleToStr(LowPrevBar,Digits),7,"Tahoma");}}
//+-------------------------------------------New Bar----------------------------------------------+
  OpenNewBar=Open[i];
  TimeOpenNewBar=Time[i];
  HighNewBar=High[i];
  LowNewBar=Low[i];
  CloseNewBar=Close[i];
  TimeCloseNewBar=Time[i]+timerTF-timer;
  nameNewCandle=NameBar+name;
  timeNewShadow=Time[i]+MathRound(Nbar/2)*timer;
  priceNewSH=PriceShadow(OpenNewBar,CloseNewBar,0);
  priceNewSL=PriceShadow(OpenNewBar,CloseNewBar,1);
  nameNewShadowH=NameHigh+name;
  nameNewShadowL=NameLow+name;
  NewBar=false;}
 else{
//+------------------------------------------Current Bar-------------------------------------------+
  OpenBar=iBarShift(0,0,TimeOpenNewBar,false);
  CloseCurBar=Close[i];
  HighCurBar=High[Highest(0,0,MODE_HIGH,OpenBar+1,i)];
  LowCurBar=Low[Lowest(0,0,MODE_LOW,OpenBar+1,i)];
  priceCurSH=PriceShadow(OpenNewBar,CloseCurBar,0);
  priceCurSL=PriceShadow(OpenNewBar,CloseCurBar,1);}
//+------------------------------Create New Object & Modifi Current--------------------------------+
if(ObjectFind(nameNewCandle)!=0){
  ObjectCreate(nameNewCandle,OBJ_RECTANGLE,0,TimeOpenNewBar,OpenNewBar,TimeCloseNewBar,CloseNewBar);
  ObjectSet(nameNewCandle,OBJPROP_STYLE, STYLE_SOLID);
  PropBar(OpenNewBar,CloseNewBar,nameNewCandle);}
 else{
  ObjectMove(nameNewCandle,1,TimeCloseNewBar,CloseCurBar);       
  PropBar(OpenNewBar,CloseCurBar,nameNewCandle);}
if(ObjectFind(nameNewShadowH)!=0){
  ObjectCreate(nameNewShadowH,OBJ_TREND,0,timeNewShadow,priceNewSH,timeNewShadow,HighNewBar);
  ObjectSet(nameNewShadowH,OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet(nameNewShadowH,OBJPROP_WIDTH, Width);
  ObjectSet(nameNewShadowH,OBJPROP_RAY, false);
  ColorShadow(OpenNewBar,CloseNewBar,nameNewShadowH);}
 else{
  ObjectMove(nameNewShadowH,0,timeNewShadow,priceCurSH);
  ObjectMove(nameNewShadowH,1,timeNewShadow,HighCurBar);
  ColorShadow(OpenNewBar,CloseCurBar,nameNewShadowH);}
if(ObjectFind(nameNewShadowL)!=0){
  ObjectCreate(nameNewShadowL,OBJ_TREND,0,timeNewShadow,priceNewSL,timeNewShadow,LowNewBar);
  ObjectSet(nameNewShadowL,OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet(nameNewShadowL,OBJPROP_WIDTH, Width);
  ObjectSet(nameNewShadowL,OBJPROP_RAY, false);
  ColorShadow(OpenNewBar,CloseNewBar,nameNewShadowL);}
 else{
  ObjectMove(nameNewShadowL,0,timeNewShadow,priceCurSL);
  ObjectMove(nameNewShadowL,1,timeNewShadow,LowCurBar);
  ColorShadow(OpenNewBar,CloseCurBar,nameNewShadowL);}}
//+-------------------------------------Comment OHLC-----------------------------------------------+
Comment(Symbol(),",M",TimeFrame,"   O=",OpenNewBar,",  H=",HighCurBar,
                                ",  L=",LowCurBar,",  C=",CloseCurBar,"\n");
return(0);}
//+---------------------Main Function "New Bar or Old Bar"-----------------------------------------+
bool BarNew (int j, int tmf)
{int t0=1440*(TimeDayOfWeek(Time[j])-1)+60*TimeHour(Time[j])+TimeMinute(Time[j]),
t1=1440*(TimeDayOfWeek(Time[j+1])-1)+60*TimeHour(Time[j+1])+TimeMinute(Time[j+1]);
if(MathMod(t0,tmf)-MathMod(t1,tmf)==t0-t1)return(false);
else return(true);}
//+---------------------Function "Price Shadow"----------------------------------------------------+
double PriceShadow (double OpnB, double ClsB, int swt)
{double prH, prL;
if(OpnB<ClsB){prH=ClsB; prL=OpnB;}
if(OpnB>ClsB){prH=OpnB; prL=ClsB;}
if(OpnB==ClsB){prH=ClsB; prL=ClsB;}
switch(swt){case 0:return(prH);break;
case 1:return(prL);break;}}
//+---------------------Function "Properti Bars"---------------------------------------------------+
void PropBar (double OpPr, double ClPr, string NmOBJ)
{string Cl=" Close="+DoubleToStr(ClPr,Digits);
string Op=" Open="+DoubleToStr(OpPr,Digits);
if(OpPr==ClPr){ObjectSet(NmOBJ,OBJPROP_BACK, false);
ObjectSet(NmOBJ,OBJPROP_COLOR,DojiColor);
ObjectSetText(NmOBJ,"Doji "+Op+Cl,7,"Tahoma");}
if(OpPr<ClPr){ObjectSet(NmOBJ,OBJPROP_COLOR,UpCandle);
ObjectSet(NmOBJ,OBJPROP_BACK, BGCandle);
ObjectSetText(NmOBJ,"UpBar "+Op+Cl,7,"Tahoma");}
if (OpPr>ClPr){ObjectSet(NmOBJ,OBJPROP_COLOR,DnCandle);
ObjectSet(NmOBJ,OBJPROP_BACK, BGCandle);
ObjectSetText(NmOBJ,"DnBar "+Op+Cl,7,"Tahoma");}
ObjectSet(NmOBJ,OBJPROP_WIDTH, Width);}
//+----------------------Function "Color Shadow"---------------------------------------------------+
void ColorShadow (double OP, double CP, string NOBJ)
{if(OP==CP)ObjectSet(NOBJ,OBJPROP_COLOR,DojiColor);
if(OP<CP)ObjectSet(NOBJ,OBJPROP_COLOR,UpCandle);
if (OP>CP)ObjectSet(NOBJ,OBJPROP_COLOR,DnCandle);}
//+----------------------------------------------END-----------------------------------------------+

Comments