Doji_Reader_2
Download scriptThe Doji Reader 2 is a specialized visual tool designed for traders using the MetaTrader platform to identify specific types of Japanese Candlestick patterns. Its primary purpose is to automatically scan historical and live price data to highlight "Doji" candles—patterns that typically signify market indecision or a potential trend reversal.
Core Functionality
The script automatically monitors the price action to detect three specific types of Doji patterns. When these conditions are met, the tool provides visual cues on your chart and can trigger real-time notifications:
- Regular Doji: Identifies candles where the opening and closing prices are very close to each other, resulting in a small body with long "tails" (wicks) on both the top and bottom.
- Dragonfly Doji: Specifically looks for candles with a very small upper tail and a long lower tail, which often suggests that the price dropped significantly during the period but recovered back to the starting point.
- Gravestone Doji: Conversely identifies candles with a long upper tail and a very small lower tail, suggesting that the price rose significantly but fell back to the starting point before the candle closed.
Customizable Visuals
To help traders spot these signals quickly, the script allows for significant visual customization:
- Visual Markers: You can choose to display colored boxes around the candles, "stars" (arrows) at specific price points, and text labels that identify exactly which type of Doji has been detected.
- Styling Options: Users can personalize the colors of the boxes and stars, adjust the thickness of the markers, and toggle whether the identification text appears vertically or horizontally.
- Automatic Scaling: The script includes logic to handle different broker formats (such as 4-digit vs. 5-digit pricing) and automatically adjusts the spacing of the labels based on the timeframe you are viewing (e.g., M1, H1, D1).
Real-Time Alerts
Beyond visual aids, the script serves as an active monitoring system. If the "Alert" feature is enabled, the software will trigger a pop-up notification whenever a new Doji pattern is confirmed on the live chart. It includes a built-in check to ensure you are only notified once per candle (using volume tracking) to prevent repetitive alerts on the same price movement.
Technical Behavior
The logic operates by scanning every historical candle on the current chart and comparing the High, Low, Open, and Close prices against user-defined thresholds (such as maximum body size and minimum tail length). This allows for precise filtering, ensuring that only candles meeting your specific definition of a "Doji" are highlighted.
//+------------------------------------------------------------------+
//| Doji Reader 2.mq4 |
//| Copyright © 2009, MQL PROGRAMMING |
//| mailto:mqlprogramming@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MQL PROGRAMMING"
#property link "mailto:mqlprogramming@gmail.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2
extern bool AnAlert=true; //false to disable alert
extern bool ShowCandleBox=true; //false to hide the candle box
extern color BoxColor=SkyBlue; //add your fav color
extern bool ShowStar=true; //false to hide star
extern color StarColor=NavajoWhite; //add your fav color
extern int StarWidth=2; //add width size of star
extern bool ShowText=true; //false to hide text
extern color FontColor=White; //add your fav color
extern int FontSize=8; //add font size
extern bool VerticalText=false; //add true to verticalize text
extern bool MyBrokerHas5Digits=false; //add true if use 5 decimals
//---- input parameters for regular doji
extern bool FindRegularDoji=true; //false to disable
extern int MinLengthOfUpTail=3; //candle with upper tail equal or more than this will show up
extern int MinLengthOfLoTail=3; //candle with lower tail equal or more than this will show up
extern double MaxLengthOfBody=1; //candle with body less or equal with this will show up
//---- input parameters for dragonfly doji
extern bool FindDragonflyDoji=true; //false to disable
extern int MaxLengthOfUpTail1=0; //candle with upper tail equal or more than this will show up
extern int MinLengthOfLoTail1=3; //candle with lower tail equal or more than this will show up
extern double MaxLengthOfBody1=1; //candle with body less or equal with this will show up
//---- input parameters for gravestone doji
extern bool FindGravestoneDoji=true; //false to disable
extern int MinLengthOfUpTail2=3; //candle with upper tail equal or more than this will show up
extern int MaxLengthOfLoTail2=0; //candle with lower tail equal or more than this will show up
extern double MaxLengthOfBody2=1; //candle with body less or equal with this will show up
//---- initialization for variables
int counter1=1, counter2=1, counter3=1;
string name1="Doji", name2="Dragonfly", name3="Gravestone";
bool sound1=false, sound2=false, sound3=false;
double H=0.0, L=0.0, C=0.0, O=0.0, pt=0, pt1=0, dis=0;
datetime T=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
ObjectCreate(name1, OBJ_LABEL, 0, 0, 0);
ObjectSet(name1, OBJPROP_XDISTANCE, 15);
ObjectSet(name1, OBJPROP_YDISTANCE, 21);
ObjectSetText(name1, "Doji Reader 2, MQL PROGRAMMING", 8, "Tahoma", Gold);
if(Digits<4) pt1=0.01;
else pt1=0.0001;
if(MyBrokerHas5Digits)
{
if(Digits<4) pt=0.001;
else pt=0.00001;
switch (Period())
{
case 1: dis=10*pt1; break;
case 5: dis=15*pt1; break;
case 15: dis=25*pt1; break;
case 30: dis=35*pt1; break;
case 60: dis=45*pt1; break;
case 240: dis=75*pt1; break;
case 1440: dis=175*pt1; break;
case 10080: dis=230*pt1; break;
case 43200: dis=350*pt1; break;
}
}
else
{
pt=pt1;
switch (Period())
{
case 1: dis=20*pt; break;
case 5: dis=30*pt; break;
case 15: dis=50*pt; break;
case 30: dis=75*pt; break;
case 60: dis=90*pt; break;
case 240: dis=150*pt; break;
case 1440: dis=350*pt; break;
case 10080: dis=460*pt; break;
case 43200: dis=700*pt; break;
}
}
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- delete all object
ObjectsDeleteAll(0, OBJ_LABEL);
ObjectsDeleteAll(0, OBJ_TREND);
ObjectsDeleteAll(0, OBJ_RECTANGLE);
ObjectsDeleteAll(0, OBJ_ARROW);
ObjectsDeleteAll(0, OBJ_TEXT);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
for(i=Bars-1; i>0; i--)
{
H=High[i]; L=Low[i]; C=Close[i]; O=Open[i];
T=Time[i];
if(FindRegularDoji)
{
if(H-C>=MinLengthOfUpTail*pt && C-L>=MinLengthOfLoTail*pt && MathAbs(C-O)<=MaxLengthOfBody*pt)
{
sound1=true;
if(ShowCandleBox)
{
if(ObjectFind("box 1"+counter1)==-1)
{
ObjectCreate("box 1"+counter1, OBJ_RECTANGLE, 0, Time[i+1], High[i]+(MathMin(Open[i], Close[i])-Low[i])/2, Time[i-1], Low[i]-(MathMin(Open[i], Close[i])-Low[i])/2);
ObjectSet("box 1"+counter1, OBJPROP_COLOR, BoxColor);
}
}
if(ShowStar)
{
if(ObjectFind("star 1"+counter1)==-1)
{
ObjectCreate("star 1"+counter1, OBJ_ARROW, 0, Time[i], High[i]+(MathMin(Open[i], Close[i])-Low[i])/2+dis, 0);
ObjectSet("star 1"+counter1, OBJPROP_ARROWCODE, 181);
ObjectSet("star 1"+counter1, OBJPROP_COLOR, StarColor);
ObjectSet("star 1"+counter1, OBJPROP_WIDTH, StarWidth);
}
}
if(ShowText)
{
if(ObjectFind("txt 1"+counter1)==-1)
{
ObjectCreate("txt 1"+counter1, OBJ_TEXT, 0, Time[i], Low[i]-dis);
ObjectSetText("txt 1"+counter1, name1, FontSize, "Tahoma", FontColor);
if(VerticalText) ObjectSet("txt 1"+counter1, OBJPROP_ANGLE, 90);
}
}
counter1++;
}
}
if(FindDragonflyDoji)
{
if(H-C<=MaxLengthOfUpTail1*pt && C-L>=MinLengthOfLoTail1*pt && MathAbs(C-O)<=MaxLengthOfBody1*pt)
{
counter2++;
sound2=true;
if(ShowCandleBox)
{
if(ObjectFind("box 2"+counter2)==-1)
{
ObjectCreate("box 2"+counter2, OBJ_RECTANGLE, 0, Time[i+1], High[i]+(MathMin(Open[i], Close[i])-Low[i])/2, Time[i-1], Low[i]-(MathMin(Open[i], Close[i])-Low[i])/2);
ObjectSet("box 2"+counter2, OBJPROP_COLOR, BoxColor);
}
}
if(ShowStar)
{
if(ObjectFind("star 2"+counter2)==-1)
{
ObjectCreate("star 2"+counter2, OBJ_ARROW, 0, Time[i], High[i]+(MathMin(Open[i], Close[i])-Low[i])/2+dis, 0);
ObjectSet("star 2"+counter2, OBJPROP_ARROWCODE, 181);
ObjectSet("star 2"+counter2, OBJPROP_COLOR, StarColor);
ObjectSet("star 2"+counter2, OBJPROP_WIDTH, StarWidth);
}
}
if(ShowText)
{
if(ObjectFind("txt 2"+counter2)==-1)
{
ObjectCreate("txt 2"+counter2, OBJ_TEXT, 0, Time[i], Low[i]-dis);
ObjectSetText("txt 2"+counter2, name2, FontSize, "Tahoma", FontColor);
if(VerticalText) ObjectSet("txt 2"+counter2, OBJPROP_ANGLE, 90);
}
}
}
}
if(FindGravestoneDoji)
{
if(H-C>=MinLengthOfUpTail2*pt && C-L<=MaxLengthOfLoTail2*pt && MathAbs(C-O)<=MaxLengthOfBody2*pt)
{
counter3++;
sound3=true;
if(ShowCandleBox)
{
if(ObjectFind("box 3"+counter3)==-1)
{
ObjectCreate("box 3"+counter3, OBJ_RECTANGLE, 0, Time[i+1], High[i]+(MathMin(Open[i], Close[i])-Low[i])/2, Time[i-1], Low[i]-(High[i]-MathMax(Open[i], Close[i]))/2);
ObjectSet("box 3"+counter3, OBJPROP_COLOR, BoxColor);
}
}
if(ShowStar)
{
if(ObjectFind("star 3"+counter3)==-1)
{
ObjectCreate("star 3"+counter3, OBJ_ARROW, 0, Time[i], High[i]+(MathMin(Open[i], Close[i])-Low[i])/3+dis, 0);
ObjectSet("star 3"+counter3, OBJPROP_ARROWCODE, 181);
ObjectSet("star 3"+counter3, OBJPROP_COLOR, StarColor);
ObjectSet("star 3"+counter3, OBJPROP_WIDTH, StarWidth);
}
}
if(ShowText)
{
if(ObjectFind("txt 3"+counter3)==-1)
{
ObjectCreate("txt 3"+counter3, OBJ_TEXT, 0, Time[i], Low[i]-dis);
ObjectSetText("txt 3"+counter3, name3, FontSize, "Tahoma", FontColor);
if(VerticalText) ObjectSet("txt 3"+counter3, OBJPROP_ANGLE, 90);
}
}
}
}
}
if(!AnAlert) return(0);
if(Volume[0]>1) return(0);
H=High[1]; L=Low[1]; C=Close[1]; O=Open[1];
if(FindRegularDoji)
{
if(H-C>=MinLengthOfUpTail*pt && C-L>=MinLengthOfLoTail*pt && MathAbs(C-O)<=MaxLengthOfBody*pt)
{
Alert("new regular doji at ",Symbol()," M",Period());
}
}
if(FindDragonflyDoji)
{
if(H-C<=MaxLengthOfUpTail1*pt && C-L>=MinLengthOfLoTail1*pt && MathAbs(C-O)<=MaxLengthOfBody1*pt)
{
Alert("new dragonfly doji at ",Symbol()," M",Period());
}
}
if(FindGravestoneDoji)
{
if(H-C>=MinLengthOfUpTail2*pt && C-L<=MaxLengthOfLoTail2*pt && MathAbs(C-O)<=MaxLengthOfBody2*pt)
{
Alert("new gravestone doji at ",Symbol()," M",Period());
}
}
return(0);
} //end of file
//+------------------------------------------------------------------+
Comments