DRP2
Download scriptThis tool is designed as a visual aid for traders to identify and analyze price action patterns on a trading chart. It automatically scans historical price data to highlight specific areas of interest based on the relationship between a candle's opening, closing, high, and low prices.
Core Functionality
The script works by reviewing a set number of historical bars (customizable by the user) and calculating a specific "reference point" for each individual candle. The logic follows these rules:
- For Bearish Candles: When the price closes lower than it opened, the tool calculates a value based on the average of the high, low, closing price, and the low again.
- For Bullish Candles: When the price closes higher than it opened, it calculates a value using the average of the high, low, closing price, and the high again.
- For Neutral Candles: If the opening and closing prices are identical, it simply takes the average of the high and low.
Visual Representation
Instead of just providing a number, the script translates these calculations into visual objects directly on your chart. For every bar it processes, it creates a colored rectangle (the default is red).
The vertical position of these rectangles is determined by the difference between the calculated reference point and the candle's high and low prices. Essentially, this creates a visual "zone" for each bar.
Technical Behavior
- Data Processing: The tool limits its analysis to a user-defined amount of historical data (e.g., 1,000 bars) to ensure the platform remains responsive and does not overload with unnecessary calculations.
- Dynamic Updates: The script is designed to handle the passage of time correctly, ensuring that it maps these visual zones accurately even when navigating through different timeframes or historical gaps.
- Clean Management: When the indicator is removed from the chart, it includes a routine to automatically clean up and delete the generated rectangles, keeping your workspace tidy.
//+------------------------------------------------------------------+
//| DRP.mq4 |
//| Yuriy Tokman |
//| yurietokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link "yurietokman@gmail.com"
#property indicator_chart_window
extern color colir = Red;
extern int barsToProcess=1000;
int total=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
string name;
for(int i=0;;i++) {
name=StringConcatenate("drp",DoubleToStr(i,0));
if(!ObjectDelete(name)) break;
}
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted(),
per=Period()*60,
limit=0,
i=0;
string name;
datetime time=0;
limit=Bars-counted_bars;
if(limit>barsToProcess)
limit=barsToProcess;
i=limit-1;
while (i>=0)
{
double x=0.0,
h = iHigh(NULL,0,i),
l = iLow(NULL,0,i),
o = iOpen(NULL,0,i),
c = iClose(NULL,0,i);
if(c<o) x=(h+l+c+l)/2;
else if(c>o) x=(h+l+c+h)/2;
else if(c==o) x=(h+l)/2;
if(ObjectGet(StringConcatenate("drp",DoubleToStr(total-1,0)),
OBJPROP_TIME1)==Time[0]) {
ObjectSet(StringConcatenate("drp",DoubleToStr(total-1,0)),
OBJPROP_PRICE1,x-l);
ObjectSet(StringConcatenate("drp",DoubleToStr(total-1,0)),
OBJPROP_PRICE2,x-h);
break;
}
time=Time[i]+per;
while(iBarShift(0,0,time,true)==-1 && time<Time[0])
time+=per; // åñëè "äûðà" â èñòîðèè
name=StringConcatenate("drp",DoubleToStr(total,0));
ObjectCreate(name,OBJ_RECTANGLE,0,
Time[i],x-l,time,x-h);
ObjectSet(name,OBJPROP_COLOR,colir);
total++;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments