Info+Ticks





//+------------------------------------------------------------------+
//|                                                        Ticks.mq4 |
//|                                                       MetaQuotes |
//|                    http://www.alpari-idc.ru/ru/experts/articles/ |
//|                                                  copyright "Rosh"|
//+------------------------------------------------------------------+
//--------------------------------------------------------------------
//| Info.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_separate_window
#property indicator_buffers 1
#property indicator_color1 Navy

#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

extern string  _Ticks="Ïàðàìåòðû Ticks:";
extern int     MaxDrawTicks=500;
extern string  _cColor="Öâåò òåêñòà:";
extern color   cColor=Green;
extern string  _calc_lot="Äëÿ ðàñ÷åòà ëîòà:";
extern int     mini_forex=0;
extern int     period=300;
extern int     RiskPercent=25;
extern int     TP=0;
extern int     SL=0;
extern string  _donate1="Íà æèçíü è ïèâî :-) WebMoney åñëè íå æàëêî";
extern string  _donate2="R865705290089";

//< ticks
double ExtMapBuffer1[];
int myBars;
int tickCounter;
int delimeterCounter;
// ticks>

double prev_profit=0, cur_prof5=0, prev_prof5=0;
double wh;
int    per=10;
double TakeProfit=0, StopLoss=0;

void init()
{
   CheckDonate();

   per=period/Period();
   IndicatorShortName("Info+Ticks");
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   for (int i=Bars-1;i>=0;i--) ExtMapBuffer1[i]=0.0;
}

void deinit()
{
}

int start()
{
	int i;
   
   //<ticks / Rosh
   int counted_bars=IndicatorCounted();
   if (isNewBar())
   {
      // óñòàíîâèòü ðàçäåëèòåëü
      //tickCounter++;
      SetDelimeter();
      ExtMapBuffer1[0]=Bid;
   }
   else
   {
      tickCounter++;
      ShiftArray();
      ExtMapBuffer1[0]=Bid;
   }
   // ticks>
   //---------------------------------------------------------------
   
   //===================================================================
      int R=50;
      double min=Ask,max=Ask;
      for(i=0;i<per;i++)
      {
         min=MathMin(min,Low[i]);
         max=MathMax(max,High[i]);
      }
      R =MathAbs(min/Point-max/Point);
      //---------------------------
      if(TP==0) TakeProfit=MathMin(R,200); else TakeProfit=TP;
      if(SL==0) StopLoss=MathMin(R*2,300); else StopLoss=SL;
      double lot=0;
      
      wh=WindowFind("Info+Ticks");
      
      int XX=10,YY=15,YS=12,XS=200;
      ObjectDelete("time_TP");
      ObjectCreate("time_TP", OBJ_LABEL,wh,0,0);
      ObjectSet("time_TP", OBJPROP_CORNER,0);
      ObjectSet("time_TP", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_TP", OBJPROP_YDISTANCE,YY);
      ObjectSetText("time_TP", "TakeProfit : "+DoubleToStr(TakeProfit,0), 9, "Courier New", cColor);

      YY+=YS;
      ObjectDelete("time_SL");
      ObjectCreate("time_SL", OBJ_LABEL,wh,0,0);
      ObjectSet("time_SL", OBJPROP_CORNER,0);
      ObjectSet("time_SL", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_SL", OBJPROP_YDISTANCE,YY);
      ObjectSetText("time_SL", "StopLoss   : "+DoubleToStr(StopLoss,0), 9, "Courier New", cColor);

      YY+=YS;
      ObjectDelete("time_mar");
      ObjectCreate("time_mar", OBJ_LABEL,wh,0,0);
      ObjectSet("time_mar", OBJPROP_CORNER,0);
      ObjectSet("time_mar", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_mar", OBJPROP_YDISTANCE,YY);
      ObjectSetText("time_mar", "FreeMargin : "+DoubleToStr(AccountFreeMargin(),2)+"$", 9, "Courier New", cColor);

      YY+=YS;
      ObjectDelete("time_per");
      ObjectCreate("time_per", OBJ_LABEL,wh,0,0);
      ObjectSet("time_per", OBJPROP_CORNER,0);
      ObjectSet("time_per", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_per", OBJPROP_YDISTANCE,YY);
      ObjectSetText("time_per", "RiskPercent: "+DoubleToStr(RiskPercent,0)+"("+DoubleToStr(AccountFreeMargin()*RiskPercent/100,2)+"$)", 9, "Courier New", cColor);

      YY=10;XX+=XS;
      ObjectDelete("time_lot");
      ObjectCreate("time_lot", OBJ_LABEL,wh,0,0);
      ObjectSet("time_lot", OBJPROP_CORNER,0);
      ObjectSet("time_lot", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_lot", OBJPROP_YDISTANCE,YY);
      lot=CalcLot(RiskPercent,StopLoss);
      ObjectSetText("time_lot", "lot "+DoubleToStr(RiskPercent,0)+"% risk : "+DoubleToStr(lot,2), 9, "Courier New", cColor);

      YY+=YS;
      ObjectDelete("time_lot100");
      ObjectCreate("time_lot100", OBJ_LABEL,wh,0,0);
      ObjectSet("time_lot100", OBJPROP_CORNER,0);
      ObjectSet("time_lot100", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_lot100", OBJPROP_YDISTANCE,YY);
      lot=CalcLot(100,StopLoss);
      ObjectSetText("time_lot100", "lot 100% risk: "+DoubleToStr(lot,2), 9, "Courier New", cColor);
      
      double sum1=0,sum2=0;
      for(i=0;i<per;i++) {sum1+=MathAbs(High[i]-Low[i]);sum2+=MathAbs(Open[i]-Close[i]);}
      double sred1=sum1/Point/per;
      double sred2=sum2/Point/per;
      
      YY+=YS;
      ObjectDelete("time_sr1");
      ObjectCreate("time_sr1", OBJ_LABEL,wh,0,0);
      ObjectSet("time_sr1", OBJPROP_CORNER,0);
      ObjectSet("time_sr1", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_sr1", OBJPROP_YDISTANCE,YY);
      ObjectSetText("time_sr1", "ñðåä.hi-lo   : "+DoubleToStr(sred1,2), 9, "Courier New", cColor);
      
      YY+=YS;
      ObjectDelete("time_sr2");
      ObjectCreate("time_sr2", OBJ_LABEL,wh,0,0);
      ObjectSet("time_sr2", OBJPROP_CORNER,0);
      ObjectSet("time_sr2", OBJPROP_XDISTANCE,XX);
      ObjectSet("time_sr2", OBJPROP_YDISTANCE,YY);
      ObjectSetText("time_sr2", "ñðåä.op-cl   : "+DoubleToStr(sred2,2), 9, "Courier New", cColor);
      
      WindowRedraw();
   //===================================================================

}


//+------------------------------------------------------------------+
double CalcLot(int lp=25,int sl=100)
{
   double lots; 

   double mm=0.01;
   lots=MathFloor(AccountFreeMargin()*lp/100/1000*100)/100;
   mm=((AccountFreeMargin()*lp/100)/(0.1*sl)*0.01);
   if(mm<lots) lots=MathFloor(mm*100)/100;
   if(lots<0.01) lots=0;

   if(mini_forex==0)
   {
      lots=MathFloor(lots*10)/10;
      if(lots<0.1) lots=0;
   }

   return(lots);
}

//+------------------------------------------------------------------+
//| ñäâèíåì ìàññèâ                                                   |
//+------------------------------------------------------------------+
void SetDelimeter()
  {
//----
   string delimeterDate=TimeToStr(Time[0]);
   if (myBars!=0)
      {
      //Print("Ñòàâèì ðàçäåëèòåëü");      
      int handle=WindowFind("Ticks");
      if(!ObjectCreate(delimeterDate,OBJ_VLINE,handle,Time[0],0))
         {
         //Alert("Íåäà÷íàÿ ïîïûòêà ñîçäàíèÿ ðàçäåëèòåëÿ â îêíå ",
         //handle," ïî âðåìåíè ",TimeToStr(CurTime()));
         //Print("Îøèáêà ¹",GetLastError(),", èìÿ ðàçäåëèòåëÿ ",delimeterDate);
         }
      else 
         {
         ObjectSet(delimeterDate,OBJPROP_COLOR,DarkGreen);
         ObjectSet(delimeterDate,OBJPROP_STYLE,STYLE_DASHDOT);
         ObjectsRedraw();
         }
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| ñäâèíåì ìàññèâ                                                   |
//+------------------------------------------------------------------+
void ShiftArray()
  {
//----
   int V_lines;
   string delimeterName;
   datetime firstTime;
   int BarFirstTime;
   
   if (tickCounter>2*MaxDrawTicks)
      {
      for (int i=tickCounter;i>=MaxDrawTicks;i--) ExtMapBuffer1[i]=0.0;
      tickCounter=MaxDrawTicks;
      }
   for(int cnt=tickCounter;cnt>0;cnt--)
      {
      ExtMapBuffer1[cnt]=ExtMapBuffer1[cnt-1];
      }
   V_lines=ObjectsTotal();
   for (int z=0;z<V_lines;z++)
      {
      delimeterName=ObjectName(z); 
      if (ObjectFind(delimeterName)!=-1)
         {
         if (ObjectType(delimeterName)==OBJ_VLINE) 
            {
            firstTime=ObjectGet(delimeterName,OBJPROP_TIME1);
            BarFirstTime=iBarShift(NULL,0,firstTime);
            firstTime=Time[BarFirstTime+1];
            ObjectSet(delimeterName,OBJPROP_TIME1,firstTime); 
            }
         }       
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| ïðèçíàê íîâîãî áàðà                                              |
//+------------------------------------------------------------------+
bool isNewBar()
  {
//----
   bool res=false;
   if (myBars!=Bars)
      {
      res=true;
      myBars=Bars;
      }   
//----
   return(res);
  }


void CheckDonate()
{
   int fd=0; string pay="0"; datetime dt=0;
   string fn="InfoTicks.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,"Åñëè Âàì ïîíðàâèëñÿ èíäèêàòîð Info+Ticks,\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);
}





Sample





Analysis



Market Information Used:

Series array that contains the lowest prices of each bar
Series array that contains the highest prices of each bar
Series array that contains close prices for each bar
Series array that contains open prices of each bar
Series array that contains open time of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:



Custom Indicators Used:
shell32
user32

Order Management characteristics:

Other Features:

Uses files from the file system
It reads information from a file
It writes information to file