This script is designed to transform standard price action charts into a Renko chart style, which focuses on price movement rather than the passage of time. Unlike traditional charts where every tick or minute creates a new candle, this tool filters out "market noise" to show you only significant structural changes in price.
How it Works
The logic follows a specific process to determine how price moves:
1. Measuring Market Volatility Before drawing any lines, the script calculates the average price range over a set period (determined by the ATR settings). This is crucial because it ensures that the "bricks" (the blocks of movement) adjust automatically to the current market environment—making the tool equally effective in low-volatility markets as it is in high-volatility ones.
2. Defining the Price "Brick" The script establishes a specific price distance, known as a "brick." A new price movement is only registered once the market moves by this predetermined amount. If the price flickers back and forth without reaching that distance, the chart remains unchanged. This helps traders ignore minor fluctuations and focus on the actual trend.
3. Determining Trend Direction The logic continuously monitors the closing prices:
- Upward Movement: If the price rises above the previous high by more than the size of one "brick," the script identifies a bullish move. It then calculates exactly how many bricks were covered and updates the price level accordingly.
- Downward Movement: Conversely, if the price drops below the previous low by more than the brick size, it identifies a bearish move and updates the lower boundary.
4. Visual Representation The script outputs two distinct price levels—an upper and a lower bound. When the price moves up, the "Up" level is pushed higher; when it moves down, the "Dn" level is pushed lower. By plotting these values, the tool creates a clean, stepped visual of the market trend where each "step" represents a confirmed change in price direction.
Summary for the User
Essentially, this script acts as a filter. It ignores the small, erratic movements of the market and only draws a new point when the price has moved significantly enough to justify a change in trend. This allows you to see the "core" direction of the market with much less visual clutter than a standard candle chart.
//+------------------------------------------------------------------+
//| Renko_v1.mq4 |
//| Copyright © 2005, TrendLaboratory Ltd. |
//| E-mail: igorad2004@list.ru |
//| Many Thanks To Konkop |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link "E-mail: igorad2004@list.ru"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Magenta
//---- input parameters
extern int PeriodATR=10;
extern double Katr=1.00;
//---- indicator buffers
double UpBuffer[];
double DnBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(0,UpBuffer);
SetIndexBuffer(1,DnBuffer);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="Renko("+PeriodATR+","+Katr+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"Renko");
//----
SetIndexDrawBegin(0,PeriodATR);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Renko_v1 |
//+------------------------------------------------------------------+
int start()
{
int i,shift;
double Up,Dn,Brick,AvgRange,dK,ATR,BrickUp,BrickDn;
for(shift=Bars-1-PeriodATR;shift>=0;shift--)
{
AvgRange=0;
for (i=PeriodATR-1;i>=0;i--)
{
dK = 1;
AvgRange+=dK*MathAbs(High[i+shift]-Low[i+shift]);
}
ATR = AvgRange/PeriodATR;
if (shift==Bars-1-PeriodATR)
{
Up=High[shift];
Dn=Low[shift];
Brick=Katr*(High[shift]-Low[shift]);
}
if (shift<Bars-1-PeriodATR)
{
if (Close[shift] > Up + Brick)
{
if (Brick==0)
BrickUp=0;
else
BrickUp=MathRound((Close[shift]-Up)/Brick)*Brick;
Up = Up + BrickUp;
Brick = Katr*ATR;
Dn = Up - Brick;
BrickDn = 0;
}
if (Close[shift] < Dn - Brick)
{
if (Brick==0)
BrickDn=0;
else
BrickDn=MathRound((Dn-Close[shift])/Brick)*Brick;
Dn = Dn - BrickDn;
Brick = Katr*ATR;
Up = Dn + Brick;
BrickUp = 0;
}
}
UpBuffer[shift]=Up;
DnBuffer[shift]=Dn;
}
return(0);
}
Comments