Author: Dmitry Yakovlev, Russia,Omsk, WM R865705290089
Info+Ticks

This script is a specialized trading information dashboard and visual tool for the MetaTrader 4 platform. It serves as an on-screen assistant that provides real-time calculations, risk management data, and price movement tracking to help a trader make informed decisions without manually crunching numbers.

Visual Data Display (Dashboard)

The primary function of this script is to create a dynamic information panel on the trading chart. This panel automatically updates to show several key metrics:

  • Dynamic Risk Management: The tool calculates specific trade sizes (lot sizes) based on your account's free margin and your desired risk percentage. It offers two views: one based on your custom risk setting and another showing what a 100% risk trade would look like.
  • Automated Stop-Loss and Take-Profit: Based on recent market volatility (the "High" and "Low" price ranges over a set period), the script automatically calculates suggested profit targets and risk limits.
  • Account Overview: It displays your current "Free Margin" (available funds) and calculates the actual dollar amount you would be risking based on your percentage settings.
  • Volatility Analysis: The script measures two types of price movement: the "High-to-Low" range (total movement) and the "Open-to-Close" change (directional movement). This helps a trader understand how much the market is actually moving compared to how much it is trending.

Tick Tracking and Charting

Beyond the data dashboard, the script handles a specific type of visual tracking:

  • Real-Time Tick Plotting: It captures price changes at every "tick" (the smallest possible price movement). This allows for a more granular view of price action than standard candles can provide.
  • Dynamic Array Shifting: To keep the chart clean and prevent performance lag, the script manages a rolling window of these ticks, ensuring only a specific number of recent movements are displayed at once.
  • New Bar Markers: Every time a new candle (bar) opens on the chart, the script automatically draws a vertical line. This serves as a visual divider to help you easily distinguish between different time periods or sessions.

Logic Summary for Traders

In simple terms, this script acts like an automated "Trading Assistant." It looks at how much the market has moved in the last few minutes, calculates exactly how much money you should risk on your next trade to stay within your safety limits, and puts all that information into a readable box on your screen. Simultaneously, it paints a high-resolution history of every tiny price movement (tick) while marking the start of each new candle with a visual divider.

Miscellaneous
Implements a curve of type %1Uses files from the file systemIt reads information from a fileIt writes information to file
11 Views
0 Downloads
0 Favorites
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);
}

Comments