Ticker Renko

Download script
Author: mandorr@gmail.com
Ticker Renko

Ticker Renko Logic Overview

This script transforms standard market price data into a Renko chart format. Unlike traditional candlestick charts, which are based on time intervals (e.g., every 5 minutes or 1 hour), Renko charts ignore time and focus exclusively on price movement. The goal is to provide a cleaner visual representation of trends by filtering out minor market "noise."

Core Functional Logic

1. Price-Based Construction The script calculates blocks based on a user-defined "Box Size." Instead of creating a new bar for every second that passes, the logic only creates a new visual "brick" when the price moves by a specific amount. This allows traders to see the continuous flow of price action regardless of how fast or slow the market is moving.

2. Movement Detection and Trend Direction The indicator monitors the live bid price and compares it against the boundaries of the current Renko brick:

  • Continuation: If the price continues to move significantly in the same direction as the current brick, the script extends that brick's size until the movement threshold is met.
  • Reversal: If the price moves aggressively enough in the opposite direction to exceed the previous brick's boundaries by more than one box size, the script identifies a "reversal." It then closes the old brick and starts a new one in the opposite color (Blue for upward movement, Red for downward movement).

3. Data Synchronization (The Setup Phase) To ensure the Renko chart aligns correctly with historical data, the script performs a specialized initialization sequence:

  • It scans historical 1-minute price data to reconstruct the path the market took.
  • It intelligently reorders price points (High, Low, Open) to ensure that the bricks are built logically from the past toward the present.
  • This ensures that the "history" you see on your screen accurately reflects how the price actually moved to reach its current level.

4. Visual Rendering Rather than using standard bars, the script dynamically draws lines and objects in a separate window:

  • Trend Bricks: These are rendered as vertical segments. The color instantly shifts based on whether the current trend is bullish or bearish.
  • Live Bid Tracker: A silver horizontal line is displayed to show the current live market price relative to the Renko bricks, helping users see exactly where the price sits in relation to the established price levels.

Summary for the User

Essentially, this script acts as a filter. It strips away the "jitter" of second-by-second price fluctuations and presents you with a structural map of the market. You will see a clear sequence of blocks: every time the price moves significantly enough to change the trend, a new block is born, making it easier to identify support, resistance, and trend reversals at a glance.

Price Data Components
Series array that contains open prices of each barSeries array that contains the highest prices of each bar
5 Views
0 Downloads
0 Favorites
Ticker Renko
// Ticker Renko.mq4
// Èíäèêàòîð

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

extern int BoxSize=100;    // Ðàçìåð êèðïè÷à
extern int BarWidth=5;     // Øèðèíà ëèíèè áàðà
extern int BarsCount=1000; // Êîëè÷åñòâî îòîáðàæàåìûõ áàðîâ

int    win_index;
int    box_size;
int    price_prev;
int    bar_size;
int    bar_high[];
int    bar_low [];
int    bar_dir [];
double buffer0 [];
double buffer1 [];
string obj_name, 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;
   bar_size=0;
   box_size=MathMax(1,BoxSize);
   win_name="Ticker Renko ("+box_size+")";
}

void deinit() {
   ObjectsDeleteAll(win_index);
}

void start() {
   int i, j, price, total, box_count;
   bool reverse;
   double price1, price2;
   datetime time1, time2;

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

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

   box_count=0;
   reverse=false;
   if ((price>bar_high[0]) && (bar_dir[0]>0)) {
      box_count=(price-bar_high[0])/box_size;
      bar_high[0]=bar_high[0]+box_count*box_size;
   }
   if ((price<bar_low[0]) && (bar_dir[0]<0)) {
      box_count=(bar_low[0]-price)/box_size;
      bar_low[0]=bar_low[0]-box_count*box_size;
   }
   if ((price>bar_low[0]) && (bar_dir[0]<0)) {
      box_count=(price-bar_low[0])/box_size;
      if (box_count>1) {reverse=true;}
   }
   if ((price<bar_high[0]) && (bar_dir[0]>0)) {
      box_count=(bar_high[0]-price)/box_size;
      if (box_count>1) {reverse=true;}
   }

   if (reverse) {
      bar_size++;
      total=BarsCount; if (BarsCount>Bars) {total=Bars;}
      if (bar_size>total) {bar_size=total;}
      else {
         ArrayResize(bar_high,bar_size);
         ArrayResize(bar_low ,bar_size);
         ArrayResize(bar_dir ,bar_size);
      }
      for (i=bar_size-1; i>0; i--) {
         bar_high[i]=bar_high[i-1];
         bar_low [i]=bar_low [i-1];
         bar_dir [i]=bar_dir [i-1];
      }
      if (bar_dir[1]<0) {
         bar_high[0]=bar_low[1]+box_count*box_size;
         bar_low [0]=bar_low[1]+box_size;
         bar_dir [0]=1;
      }
      if (bar_dir[1]>0) {
         bar_high[0]=bar_high[1]-box_size;
         bar_low [0]=bar_high[1]-box_count*box_size;
         bar_dir [0]=-1;
      }
   }

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

   for (i=0; i<bar_size; i++) {
      price1=bar_low [i]*Point;
      price2=bar_high[i]*Point;
      time1=Time[i];
      time2=Time[i];
      box_count=(bar_high[i]-bar_low[i])/box_size;

      color bar_color;
      if (bar_dir[i]<0) {bar_color=Red;} else {bar_color=Blue;}

      obj_name="Win"+win_index+"_Bar"+i;
      if (ObjectFind(obj_name)!=win_index) {
         ObjectCreate(obj_name,OBJ_TREND,win_index,time1,price1,time2,price2);
      }
      ObjectSet(obj_name,OBJPROP_TIME1,time1);
      ObjectSet(obj_name,OBJPROP_TIME2,time2);
      ObjectSet(obj_name,OBJPROP_PRICE1,price1);
      ObjectSet(obj_name,OBJPROP_PRICE2,price2);
      ObjectSet(obj_name,OBJPROP_STYLE,DRAW_LINE);
      ObjectSet(obj_name,OBJPROP_WIDTH,BarWidth);
      ObjectSet(obj_name,OBJPROP_RAY,false);
      ObjectSet(obj_name,OBJPROP_COLOR,bar_color);

      buffer0[i]=price2;
      buffer1[i]=price1;
   }
   buffer0[bar_size]=0.0;
   buffer1[bar_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<=BarsCount; i++) {
      buffer0[i]=0.0;
      buffer1[i]=0.0;
   }
   IndicatorShortName(win_name);
   win_index=WindowFind(win_name);
   ObjectsDeleteAll(win_index);
}

// Èñïîëüçîâàíèå ïîñëåäîâàòåëüíîñòè òèêîâ èç OHL ìèíóòíîãî ãðàôèêà
void Setup() {
   int i, j, k, total, value_prev, value[4], box_count;
   bool reverse;
   double open, high, low, median;
   // íà÷àëüíûé áàð
   bar_size=1;
   ArrayResize(bar_high,1);
   ArrayResize(bar_low ,1);
   ArrayResize(bar_dir, 1);
   total=10*BoxSize*BarsCount; if (total>iBars(NULL,PERIOD_M1)) {total=iBars(NULL,PERIOD_M1);}
   open=iOpen(NULL,PERIOD_M1,total-1);
   value[0]=MathRound(open/Point);
   value_prev=box_size*(value[0]/box_size); // ïðèâÿçêà ê öåíå, êðàòíîé box_size ïóíêòîâ
   bar_high[0]=value_prev+box_size;
   bar_low [0]=value_prev;
   bar_dir [0]=1;
   // Ýìóëÿöèÿ ïîñëåäîâàòåëüíîñòè òèêîâ èç OHL ìèíóòíîãî ãðàôèêà
   for (i=total-1; i>=0; i--) {
      open=iOpen(NULL,PERIOD_M1,i);
      high=iHigh(NULL,PERIOD_M1,i);
      low =iLow (NULL,PERIOD_M1,i);
      median=0.5*(high+low);
      value[0]=MathRound(open/Point);
      value[1]=MathRound(high/Point);
      value[2]=MathRound(low /Point);
      value[3]=0;
      if (open<median) {
         // Ïîìåíÿòü ïîñëåäîâàòåëüíîñòü ñ OHL íà OLH
         value[3]=value[1];
         value[1]=value[2];
         value[2]=value[3];
      }
      for (k=0; k<=2; k++) {
         if (value[k]==value_prev) {continue;}
         value_prev=value[k];
         box_count=0;
         reverse=false;
         if ((value[k]>bar_high[0]) && (bar_dir[0]>0)) {
            box_count=(value[k]-bar_high[0])/box_size;
            bar_high[0]=bar_high[0]+box_count*box_size;
         }
         if ((value[k]<bar_low[0]) && (bar_dir[0]<0)) {
            box_count=(bar_low[0]-value[k])/box_size;
            bar_low[0]=bar_low[0]-box_count*box_size;
         }
         if ((value[k]>bar_low[0]) && (bar_dir[0]<0)) {
            box_count=(value[k]-bar_low[0])/box_size;
            if (box_count>1) {reverse=true;}
         }
         if ((value[k]<bar_high[0]) && (bar_dir[0]>0)) {
            box_count=(bar_high[0]-value[k])/box_size;
            if (box_count>1) {reverse=true;}
         }
         if (reverse) {
            bar_size++;
            if (bar_size>BarsCount) {bar_size=BarsCount;}
            else {
               ArrayResize(bar_high,bar_size);
               ArrayResize(bar_low ,bar_size);
               ArrayResize(bar_dir ,bar_size);
            }
            for (j=bar_size-1; j>0; j--) {
               bar_high[j]=bar_high[j-1];
               bar_low [j]=bar_low [j-1];
               bar_dir [j]=bar_dir [j-1];
            }
            if (bar_dir[1]<0) {
               bar_high[0]=bar_low[1]+box_count*box_size;
               bar_low [0]=bar_low[1]+box_size;
               bar_dir [0]=1;
            }
            if (bar_dir[1]>0) {
               bar_high[0]=bar_high[1]-box_size;
               bar_low [0]=bar_high[1]-box_count*box_size;
               bar_dir [0]=-1;
            }
         }
      }
   }
   RefreshRates();
   price_prev=MathRound(Bid/Point);
}

// End

Comments