//
//  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