Ticks_mod_v1.0

Download script
Author: Rosh
Ticks_mod_v1.0

This script functions as a specialized visual tracking tool for the MetaTrader 4 platform. Its primary purpose is to monitor and display real-time price fluctuations—specifically the Bid, Ask, and Open prices—within a dedicated separate window on your trading chart.

Here is a breakdown of the logic used by this tool:

Core Tracking Mechanism

Unlike standard indicators that only update when a new candle (bar) forms, this script is designed to capture "ticks." A tick represents every single price change that occurs in the market. The script continuously captures these values and maps them onto three distinct lines:

  • Bid Price: The current price at which you can sell.
  • Ask Price: The current price at which you can buy.
  • Open Price: The price at which the current candle began.

Dynamic Data Management

Because market data moves so rapidly, displaying every single price point indefinitely would eventually slow down your platform. To prevent this, the script utilizes a "Shifting" logic:

  • Buffer Limitation: You can define a maximum number of ticks to display (defaulting to 500).
  • Memory Management: As new price data arrives, the script "pushes" the older data points to the left. Once the limit is reached, the oldest data is discarded to make room for the newest movements, ensuring your chart remains smooth and responsive.

Visual Organization

To keep the data organized for the user, the script includes a smart labeling system:

  • Automated Dividers: The tool automatically creates vertical dashed lines on the chart to separate different sections of time.
  • Time Tracking: It intelligently identifies new bars and places these dividers, allowing you to visually distinguish between different periods of trading activity while watching the continuous flow of price ticks.

Data Persistence

The script also utilizes "Global Variables." This means that it records the most recent Bid, Ask, and Open prices into the platform's memory. This ensures that these specific values are saved and accessible even if other parts of your trading setup need to reference those exact numbers.

Summary for the User: In essence, this tool provides a high-resolution view of market liquidity. It turns the "jittery" movement of live price ticks into a visible, flowing history that lets you see exactly how the Bid and Ask prices are dancing against each other in real-time, while keeping your chart clean and organized through automatic time dividers.

Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
Ticks_mod_v1.0
//+------------------------------------------------------------------+
//|                                                        Ticks.mq4 |
//|                                                       MetaQuotes |
//|                    http://www.alpari-idc.ru/ru/experts/articles/ |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://www.alpari-idc.ru/ru/experts/articles/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Lime
//---- buffers
extern int MaxDrawTicks=500;
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int myBars;
int tickCounter;
int delimeterCounter;
string nume1,nume2,nume3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    int i;
    nume1 ="Bid_"+Symbol();
    nume2 ="Ask_"+Symbol();    
    nume3 ="Open_"+Symbol();
    GlobalVariableSet(nume1,0);
    GlobalVariableSet(nume2,0);    
    GlobalVariableSet(nume3,0);    
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexEmptyValue(2,0.0);   
   
   Print("Îáíóëÿåì òèêè");
   for (i=Bars-1;i>=0;i--) ExtMapBuffer1[i]=0.0;
   for (i=Bars-1;i>=0;i--) ExtMapBuffer2[i]=0.0;
   for (i=Bars-1;i>=0;i--) ExtMapBuffer3[i]=0.0;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| ñäâèíåì ìàññèâ                                                   |
//+------------------------------------------------------------------+
void SetDelimeter()
  {
//----
   string delimeterDate=TimeToStr(Time[0]);
   if (myBars!=0)
      {
      Print("Ñòàâèì ðàçäåëèòåëü");      
      int handle=WindowFind("Ticks_mod_v1.0");
      if(!ObjectCreate(delimeterDate,OBJ_VLINE,handle,Time[0],0))
         {
         //Alert("Íåäà÷íàÿ ïîïûòêà ñîçäàíèÿ ðàçäåëèòåëÿ â îêíå ",
         //handle," ïî âðåìåíè ",TimeToStr(CurTime()));
         Print("Îøèáêà ¹",GetLastError(),", èìÿ ðàçäåëèòåëÿ ",delimeterDate);
         }
      else 
         {
         ObjectSet(delimeterDate,OBJPROP_COLOR,Yellow);
         ObjectSet(delimeterDate,OBJPROP_STYLE,STYLE_DASHDOT);
         ObjectsRedraw();           
         }
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| ñäâèíåì ìàññèâ                                                   |
//+------------------------------------------------------------------+
void ShiftArray()
  {
//----
   int V_lines,i1;
   string delimeterName;
   datetime firstTime;
   int BarFirstTime;
   
   if (tickCounter>2*MaxDrawTicks)
      {
      for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer1[i1]=0.0;
      for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer2[i1]=0.0;
      for (i1=tickCounter;i1>=MaxDrawTicks;i1--) ExtMapBuffer3[i1]=0.0;            
      tickCounter=MaxDrawTicks;
      }
   for(int cnt=tickCounter;cnt>0;cnt--)
      {
      ExtMapBuffer1[cnt]=ExtMapBuffer1[cnt-1];
      ExtMapBuffer2[cnt]=ExtMapBuffer2[cnt-1];
      ExtMapBuffer3[cnt]=ExtMapBuffer3[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);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   if (isNewBar())
      {
      // óñòàíîâèòü ðàçäåëèòåëü
      //tickCounter++;
      SetDelimeter();
      ExtMapBuffer1[0]=Bid;      
      ExtMapBuffer2[0]=Ask;   
      ExtMapBuffer3[0]=Open[0];         
      GlobalVariableSet(nume1,Bid);
      GlobalVariableSet(nume2,Ask);            
      GlobalVariableSet(nume3,Open[0]);        
      }
   else
      
      {
      tickCounter++;
      ShiftArray();
      ExtMapBuffer1[0]=Bid;      
      ExtMapBuffer2[0]=Ask;      
      ExtMapBuffer3[0]=Open[0];               
      GlobalVariableSet(nume1,Bid);
      GlobalVariableSet(nume2,Ask);         
      GlobalVariableSet(nume3,Open[0]);              
      }      
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments