Ticker Candles

Download script
Author: mandorr@gmail.com
Ticker Candles

This script is designed to provide a unique visual representation of price action by creating custom "Ticker Candles" in a separate window on your trading platform. Instead of relying on standard time-based candles (like 1-minute or 1-hour charts), this indicator builds candles based on price movement and a user-defined volume of ticks.

Core Logic Overview

The primary goal of the script is to transform raw price data into a visual history of movement. It monitors every price change (tick) and aggregates these movements into "candles." Once the market has moved a specific number of times (the Volume), the script finalizes the current candle and starts a new one.

How the Data Processes

  • Price Tracking: The script continuously watches the current Bid price. It ignores minor fluctuations that do not change the actual price level, ensuring it only reacts to meaningful movements.
  • Dynamic Candle Creation: Each time a new candle is formed, the script captures the highest and lowest prices reached during that period. This allows it to define the "wick" or the vertical range of the movement.
  • Trend Identification: The script automatically determines the color of each candle based on its direction. If the price closes higher than it opened, it assigns one color (Blue); if it closes lower, it assigns another (Red).
  • Historical Memory: The indicator maintains a memory of past candles. As new movements occur, older data is shifted to make room for the newest information, allowing you to view a rolling history of recent price action.

Visual Elements

To ensure the information is easy to read at a glance, the script draws three specific components for every candle:

  1. High/Low Range: A thin line representing the extreme boundaries reached during that period.
  2. Open/Close Body: A thicker line (customizable by the user) connecting the starting and ending price of the movement, which clearly shows the "body" of the trade.
  3. Live Price Marker: A silver horizontal line that tracks the current live Bid price in real-time, allowing you to see exactly where the market stands relative to the historical candles.

User Customization

The logic is built to be flexible for different trading styles. Users can adjust:

  • Candle Volume: Controls how many price movements are required to complete one candle.
  • Candle Width: Adjusts how thick the main body of the candle appears.
  • Candles Count: Determines how many historical candles are displayed on the screen at once.
7 Views
0 Downloads
0 Favorites
Ticker Candles
// Ticker Candles.mq4
// Èíäèêàòîð

#property copyright "mandorr@gmail.com"
#property indicator_separate_window
#property indicator_buffers 2

extern int CandleVolume=100;  // Òèêîâûé îáúåì ñâå÷è
extern int CandleWidth=5;     // Øèðèíà ëèíèè ñâå÷è
extern int CandlesCount=1000; // Êîëè÷åñòâî îòîáðàæàåìûõ ñâå÷

double buffer0[];
double buffer1[];

int    candle_open [];
int    candle_high [];
int    candle_low  [];
int    candle_close[];

int    candle_volume;
int    candle_tick;
int    candle_size;

int    price_prev;
int    win_index;
string obj_name;
string win_name;

void init() {
   SetIndexBuffer(0,buffer0);
   SetIndexBuffer(1,buffer1);
   SetIndexStyle (0,DRAW_NONE);
   SetIndexStyle (1,DRAW_NONE);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexLabel (0,"High");
   SetIndexLabel (1,"Low");
   SetIndexDrawBegin(0,0);
   SetIndexDrawBegin(1,0);
   IndicatorDigits(Digits);
   price_prev=0;
   candle_tick=0;
   candle_size=0;
   candle_volume=MathMax(1,CandleVolume);
   win_name="Ticker Candles ("+candle_volume+")";
}

void deinit() {
   ObjectsDeleteAll(win_index);
}

void start() {
   int i, price;
   double open, high, low, close;
   datetime time;

   price=MathRound(Bid/Point);
   if (price==0) {return;}
   if (price==price_prev) {return;}
   price_prev=price;

   if (candle_size==0) {
      Clean();
      Setup();
   }

   candle_tick++;
   if (candle_tick>candle_volume) {
      candle_tick=1;
      candle_size++;
      if (candle_size>CandlesCount) {candle_size=CandlesCount;}
      else {
         ArrayResize(candle_open ,candle_size);
         ArrayResize(candle_high ,candle_size);
         ArrayResize(candle_low  ,candle_size);
         ArrayResize(candle_close,candle_size);
      }
      for (i=candle_size-1; i>0; i--) {
         candle_open [i]=candle_open [i-1];
         candle_high [i]=candle_high [i-1];
         candle_low  [i]=candle_low  [i-1];
         candle_close[i]=candle_close[i-1];
      }
      candle_open [0]=price;
      candle_high [0]=price;
      candle_low  [0]=price;
      candle_close[0]=price;
   }
   if (candle_high[0]<price) {candle_high[0]=price;}
   if (candle_low [0]>price) {candle_low [0]=price;}
   candle_close[0]=price;

   IndicatorShortName(win_name);
   win_index=WindowFind(win_name);

   for (i=0; i<candle_size; i++) {
      open =candle_open [i]*Point;
      high =candle_high [i]*Point;
      low  =candle_low  [i]*Point;
      close=candle_close[i]*Point;
      time =Time[i];

      color candle_color;
      if (close<open) {candle_color=Red;} else {candle_color=Blue;}

      obj_name="Win"+win_index+"_Candle"+i+"_HL";
      if (ObjectFind(obj_name)!=win_index) {
         ObjectCreate(obj_name,OBJ_TREND,win_index,time,high,time,low);
      }
      ObjectSet(obj_name,OBJPROP_TIME1,time);
      ObjectSet(obj_name,OBJPROP_TIME2,time);
      ObjectSet(obj_name,OBJPROP_PRICE1,high);
      ObjectSet(obj_name,OBJPROP_PRICE2,low);
      ObjectSet(obj_name,OBJPROP_STYLE,DRAW_LINE);
      ObjectSet(obj_name,OBJPROP_WIDTH,1);
      ObjectSet(obj_name,OBJPROP_RAY,false);
      ObjectSet(obj_name,OBJPROP_COLOR,candle_color);

      obj_name="Win"+win_index+"_Candle"+i+"_OC";
      if (ObjectFind(obj_name)!=win_index) {
         ObjectCreate(obj_name,OBJ_TREND,win_index,time,open,time,close);
      }
      ObjectSet(obj_name,OBJPROP_TIME1,time);
      ObjectSet(obj_name,OBJPROP_TIME2,time);
      ObjectSet(obj_name,OBJPROP_PRICE1,open);
      ObjectSet(obj_name,OBJPROP_PRICE2,close);
      ObjectSet(obj_name,OBJPROP_STYLE,DRAW_LINE);
      ObjectSet(obj_name,OBJPROP_WIDTH,CandleWidth);
      ObjectSet(obj_name,OBJPROP_RAY,false);
      ObjectSet(obj_name,OBJPROP_COLOR,candle_color);

      buffer0[i]=high;
      buffer1[i]=low ;
   }
   buffer0[candle_size]=0.0;
   buffer1[candle_size]=0.0;

   obj_name="Win"+win_index+"_Bid";
   if (ObjectFind(obj_name)!=win_index) {
      ObjectCreate(obj_name,OBJ_HLINE,win_index,Time[0],Bid);
   }
   ObjectSet(obj_name,OBJPROP_PRICE1,Bid);
   ObjectSet(obj_name,OBJPROP_STYLE,DRAW_LINE);
   ObjectSet(obj_name,OBJPROP_WIDTH,1);
   ObjectSet(obj_name,OBJPROP_COLOR,Silver);
}

void Clean() {
   for (int i=0; i<=CandlesCount; i++) {
      buffer0[i]=0.0;
      buffer1[i]=0.0;
   }
   IndicatorShortName(win_name);
   win_index=WindowFind(win_name);
   ObjectsDeleteAll(win_index);
}

void Setup() {
   candle_size=1;
   ArrayResize(candle_open ,1);
   ArrayResize(candle_high ,1);
   ArrayResize(candle_low  ,1);
   ArrayResize(candle_close,1);
   int price=MathRound(Bid/Point);
   candle_open [0]=price;
   candle_high [0]=price;
   candle_low  [0]=price;
   candle_close[0]=price;
}

// End

Comments