Author: Dmitry Yakovlev, Russia,Omsk WM R865705290089
ShadowsTF3

This script is designed to modify the visual representation of price action on a trading chart by overlaying custom-constructed "candles" based on specific timeframes. Instead of relying solely on the standard bars provided by your broker, it reconstructs and draws unique graphical elements that help visualize price movement over defined periods.

Core Functionality

The primary purpose of the script is to group price data into larger blocks (defined by the user). It scans historical price data—specifically looking for highs, lows, opens, and closes—and translates them into a visual "Shadow" effect. This allows traders to see a summarized version of market volatility and trends that might be harder to distinguish on standard timeframes.

Key Features & Logic

  • Timeframe Reconstruction: You can specify a custom timeframe (e.g., 240 minutes). The script automatically calculates the necessary data points to build these larger visual blocks, ensuring they align correctly with the current chart.
  • Price Range Visualization: For every period calculated, the script identifies the highest and lowest prices reached. It then draws:
    • High/Low Zones: Rectangles that represent the upper and lower extremes of price movement during that specific timeframe.
    • Body Representation: A central colored block (Green for upward moves, Red for downward moves) that represents the primary price action between the opening and closing points.
    • Midline Markers: A horizontal line is automatically drawn at the mathematical midpoint of the High and Low prices, providing a clear "equilibrium" reference point.
  • Trend Tracking: The script includes an optional visual element that draws a direct trend line from the opening price to the closing price of each reconstructed period. This highlights the direction of the move immediately.
  • Dynamic Depth Control: Users can decide how far back into history these custom candles should be drawn. You can choose a fixed number of bars or have it calculate based on the total available history on your chart.

Visual Customization

The script provides several options to tailor the look of the indicators to suit different trading styles:

  • Color Coding: You can customize the colors for the high/low zones, the price bodies (Up/Down), the midline, and the trend lines.
  • Fill Options: There is a toggle to "fill" the candle bodies and boundary boxes, which helps in creating a more solid visual map of the market's "shadows."
  • Border Visibility: A specific border can be enabled to clearly define the outer limits of the price action for each timeframe block.

Summary for the User

Essentially, this tool acts as a "visual synthesizer." It takes raw, messy price data and organizes it into clean, structured blocks that show you the extremes (High/Low), the center point (Midline), and the overall momentum (Trend) of specific time intervals at a single glance.

Price Data Components
Series array that contains open time of each barSeries array that contains open prices of each barSeries array that contains close prices for each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
Uses files from the file systemIt reads information from a fileIt writes information to file
10 Views
0 Downloads
0 Favorites
ShadowsTF3
//
//  ShadowsTF.mq4 
//  Dmitry Yakovlev 
//  dmitry_yakovlev@rambler.ru
//  Íà ïèâî WebMoney R865705290089
//------------------------------------------------------------------
#property copyright "Dmitry Yakovlev, Russia,Omsk  WM R865705290089"
#property link      "dmitry_yakovlev@rambler.ru"

#property indicator_chart_window

#import  "shell32.dll"           //Connect a dll (provided with Windows)             
  int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd); 
#import "user32.dll"
  int MessageBoxA(int hWnd ,string lpText,string lpCaption,int uType);
#import

//---- input 
extern string    _tf="Òàéìôðåéì (ìèí):";
extern int       tf=240;
extern string    _idepth="Ê-âî áàðîâ,åñëè 0-âñå";
extern int       idepth=30;
extern string    _shift="Ñäâèã (ìèíóò)";
extern int       iMin=60;
extern string    _Filled="Çàêðàñêà áàðîâ?(false-ðàìêà)";
extern bool      Filled=true;
extern string    _Border="+Êîíòóð?";
extern bool      Border=true;
extern string    _hilo="Öâåò High/Low, Up, Down";
extern color     HiLoColor=DarkGray;
extern color     UpColor=MediumSeaGreen;
extern color     DnColor=Tomato;
extern string    _MidColor="Öâåò ëèíèè (High+Low)/2 (None-áåç ëèíèè)";
extern color     MidColor=Yellow;
extern string    _BordColor="Öâåò êîíòóðà";
extern color     BordColor=Yellow;
extern string    _Trend="Ìèêðî Òðåíä îò Open äî Close";
extern bool      Trend=true;
extern string    _donate1="Íà ïèâî :-) WebMoney";
extern string    _donate2="R865705290089";
//+------------------------------------------------------------------+
int depth=30;
int k=1;

void init()
{
   CheckDonate();
   
   k=MathRound(tf/Period());
   if(idepth==0) depth=Bars; else depth=idepth;
   deleteAll();
   if(tf==0 || tf<Period()) tf=Period();
   if(tf<=Period())
   {
      if(Period()==PERIOD_M1) tf=PERIOD_M5;
      if(Period()==PERIOD_M5) tf=PERIOD_M15;
      if(Period()==PERIOD_M15) tf=PERIOD_M30;
      if(Period()==PERIOD_M30) tf=PERIOD_H1;
      if(Period()==PERIOD_H1) tf=PERIOD_H4;
      if(Period()==PERIOD_H4) tf=PERIOD_D1;
      if(Period()==PERIOD_D1) tf=PERIOD_W1;
   }
   if(iMin>=tf) iMin=0;
}

void deinit()
{
   if(idepth==0) depth=Bars;  else depth=idepth;
   deleteAll();
}

int start()
{
   int      counted_bars=IndicatorCounted();
   int      i=0, ti=0,cdow,ii,jj;
   datetime t1,t2,ct;
   double   p1,p2,p3,p4;
   if(idepth==0) depth=(Bars-counted_bars)/k;  else depth=idepth;
//----
   deleteAll();
   int cnt=0,plus=0,FirstBar=1;
   for(i=0;i<depth;i++)
   {
      cdow=TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,i));
      ct=iTime(Symbol(),PERIOD_D1,i)+iMin*60;
      
      FirstBar=1;
      for(ii=ct;ii<(ct+24*60*60);ii+=tf*60)
      {
         if(ii>TimeCurrent()) break;
         
         t1=ii;
         if(cdow==1 && FirstBar==1) t1=iTime(Symbol(),PERIOD_D1,i)+61*60;
         t2=ii+tf*60-Period()*30;
         if(t2>TimeCurrent()) t2=TimeCurrent();
         FirstBar=0;
      
         p3=iOpen(Symbol(),0,iBarShift(Symbol(),0,t1+plus,false));
         p4=iClose(Symbol(),0,iBarShift(Symbol(),0,t2,false));

         p1=-100; p2=+100;
         for(jj=t1+plus;jj<=t2;jj+=60)
         {
            p1=MathMax(p1,iHigh(Symbol(),0,iBarShift(Symbol(),0,jj,false)));
            p2=MathMin(p2,iLow(Symbol(),0,iBarShift(Symbol(),0,jj,false)));
         }
         drawCandle(cnt,t1,t2,p1,p2,p3,p4); cnt++;
      }
   }
   //----
   return(0);
}

double myHigh(int TF=0, int shift=0, int num=10)
{
   double ret=iHigh(Symbol(),TF,shift);
   for(int i=shift;i<=(shift+num);i++)
      if(i>=0) ret=MathMax(ret,iHigh(Symbol(),TF,i));
      else ret=MathMax(ret,iHigh(Symbol(),TF,0));
   return(ret);
}
double myLow(int TF=0, int shift=0, int num=10)
{
   double ret=iLow(Symbol(),TF,shift);
   for(int i=shift;i<=(shift+num);i++)
      if(i>=0) ret=MathMin(ret,iLow(Symbol(),TF,i));
      else ret=MathMin(ret,iLow(Symbol(),TF,0));
   return(ret);
}


//+------------------------------------------------------------------+
void drawCandle(int n,int t1,int t2, double p1, double p2, double p3, double p4)
{
   string ml="mid_"+DoubleToStr(tf,0)+"_"+DoubleToStr(n,0);
   string n1="canhi_"+DoubleToStr(tf,0)+"_"+DoubleToStr(n,0);
   string n2="canopcl_"+DoubleToStr(tf,0)+"_"+DoubleToStr(n,0); 
   string n3="canlo_"+DoubleToStr(tf,0)+"_"+DoubleToStr(n,0); 
   string n4="canbord_"+DoubleToStr(tf,0)+"_"+DoubleToStr(n,0); 
   string n5="cantr_"+DoubleToStr(tf,0)+"_"+DoubleToStr(n,0); 
   color clr=UpColor;
   double p_open=p3,p_close=p4;
   
   if(p4>p3) 
   {
      double sw=p3;
      p3=p4;
      p4=sw;
      clr=UpColor;
   }
   else
      clr=DnColor;
   
   // mid line (high+low)/2 === (p1+p2)/2
   ObjectCreate(ml, OBJ_TREND, 0, t1, (p1+p2)/2, t2, (p1+p2)/2);
   ObjectSet(ml, OBJPROP_COLOR, MidColor);
   ObjectSet(ml,OBJPROP_WIDTH,2);
   ObjectSet(ml, OBJPROP_RAY, 0);
   ObjectSet(ml, OBJPROP_STYLE, STYLE_SOLID);

   ObjectCreate(n1, OBJ_RECTANGLE, 0, t1, p1, t2, p3);
   ObjectSet(n1, OBJPROP_COLOR, HiLoColor);
   ObjectSet(n1,OBJPROP_BACK,Filled);
   ObjectSet(n1,OBJPROP_WIDTH,1);
   ObjectSet(n1,OBJPROP_STYLE,0);

   ObjectCreate(n2, OBJ_RECTANGLE, 0, t1, p3, t2, p4);
   ObjectSet(n2, OBJPROP_COLOR, clr);
   ObjectSet(n2,OBJPROP_BACK,Filled);
   ObjectSet(n2,OBJPROP_WIDTH,1);
   ObjectSet(n2,OBJPROP_STYLE,0);

   // <trend
   if(Trend)
   {
      ObjectCreate(n5, OBJ_TREND, 0, t1, p_open, t2, p_close);
      if(p_open<p_close) ObjectSet(n5, OBJPROP_COLOR, Lime);
      if(p_open>p_close) ObjectSet(n5, OBJPROP_COLOR, Red);
      ObjectSet(n5,OBJPROP_RAY,false);
      ObjectSet(n5,OBJPROP_WIDTH,2);
      ObjectSet(n5,OBJPROP_STYLE,0);
   }
   // trend>
   
   ObjectCreate(n3, OBJ_RECTANGLE, 0, t1, p4, t2, p2);
   ObjectSet(n3, OBJPROP_COLOR, HiLoColor);
   ObjectSet(n3,OBJPROP_BACK,Filled);
   ObjectSet(n3,OBJPROP_WIDTH,1);
   ObjectSet(n3,OBJPROP_STYLE,0);
   
   // hi-lo border
   if(Filled && Border)
   {
      ObjectCreate(n4, OBJ_RECTANGLE, 0, t1, p1, t2, p2);
      ObjectSet(n4, OBJPROP_COLOR, Yellow);
      ObjectSet(n4,OBJPROP_BACK,false);
      ObjectSet(n4,OBJPROP_WIDTH,1);
      ObjectSet(n4,OBJPROP_STYLE,0);
   }
}

void deleteAll()
{
   for(int i=-10;i<depth*24*60/tf;i++)
   {
      ObjectDelete("mid_"+DoubleToStr(tf,0)+"_"+DoubleToStr(i,0));
      ObjectDelete("canhi_"+DoubleToStr(tf,0)+"_"+DoubleToStr(i,0));
      ObjectDelete("canopcl_"+DoubleToStr(tf,0)+"_"+DoubleToStr(i,0));
      ObjectDelete("canlo_"+DoubleToStr(tf,0)+"_"+DoubleToStr(i,0));
      ObjectDelete("canbord_"+DoubleToStr(tf,0)+"_"+DoubleToStr(i,0)); 
      ObjectDelete("cantr_"+DoubleToStr(tf,0)+"_"+DoubleToStr(i,0)); 
   }
}

void CheckDonate()
{
   int fd=0; string pay="0"; datetime dt=0;
   string fn="ShadowsTF.txt";
   fd=FileOpen(fn,FILE_READ|FILE_CSV,";");
   if(fd>=1)
   {
      pay=FileReadString(fd); if(pay!="0" && pay!="1") pay="0";
      dt=StrToTime(FileReadString(fd));
   }
   else
   {
      dt=TimeCurrent();
      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
      FileWrite(fd,"0",TimeToStr(dt,TIME_DATE));
   }
   FileClose(fd);
   
   if(pay=="0" && (TimeCurrent()-dt)>10*24*60*60) // 5 äíåé
   {
      if(MessageBoxA(0,"Åñëè Âàì ïîíðàâèëñÿ èíäèêàòîð ShadowsTF,\n õîòèòå ïîìî÷ü àâòîðó ìàòåðèàëüíî?","Âîïðîñ",4)==6)
      {
         ShellExecuteA(0,"Open","iexplore.exe","wmk:payto?Purse=R865705290089&Amount=100&Desc=Indicator&BringToFront=Y&ExecEvenKeeperIsOffline=Y","",7);
         pay="1";
      }
      dt=TimeCurrent();
      
      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
      FileWrite(fd,pay,TimeToStr(dt,TIME_DATE));
      FileClose(fd);
   }
   FileClose(fd);
}


Comments