Code Your Own Doji Candle Pattern Recognition Indicator.

Here is an example of an .mq4 code for an indicator that can find a Doji candle pattern within a chart.

This code provides a basic framework for detecting Doji candle patterns and showing them on a trading chart. It is important to thoroughly test and verify this custom indicator before using it in live trading.

You are welcome to modify and customized the below example to fit your specific trading strategy.

//+------------------------------------------------------------------+
//|                                                    DojiFinder.mq4|
//|                                        Copyright © 2023, Richpips|
//|                                          https://www.richpips.com|
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1

//---- input parameters
extern int Period = 14;

//---- buffers
double DojiBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
    //---- indicator buffers mapping
    SetIndexBuffer(0, DojiBuffer, INDICATOR_DATA);

    //---- indicator buffers settings
    SetIndexStyle(0, DRAW_ARROW);
    SetIndexArrow(0, 233);
    SetIndexEmptyValue(0, 0.0);

    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
    int counted_bars = IndicatorCounted();
    int limit = Bars - counted_bars;

    for(int i = limit; i >= 0; i--)
    {
        if(iDoji(NULL, Period, i) == 1)
        {
            DojiBuffer[i] = High[i] + 10 * Point;
        }
        else
        {
            DojiBuffer[i] = 0.0;
        }
    }

    return(0);
}

//+------------------------------------------------------------------+
//| Function to find Doji candle pattern                              |
//+------------------------------------------------------------------+
int iDoji(string symbol, int timeframe, int shift)
{
    double OpenPrice = Open[shift];
    double ClosePrice = Close[shift];
    double HighPrice = High[shift];
    double LowPrice = Low[shift];

    double BodySize = MathAbs(OpenPrice - ClosePrice);
    double UpperShadow = HighPrice - MathMax(OpenPrice, ClosePrice);
    double LowerShadow = MathMin(OpenPrice, ClosePrice) - LowPrice;

    if(BodySize < UpperShadow && BodySize < LowerShadow)
    {
        return(1);
    }
    else
    {
        return(0);
    }
}

This indicator uses the iDoji function to determine whether a candlestick is a Doji pattern or not. It then plots an arrow above the high of the Doji candlestick. The indicator can be customized by changing the Period input parameter to adjust the period of the moving average used in the iDoji function.

The start() function is the main function of the indicator, and it loops through each bar on the chart to check whether a Doji candle pattern has formed. If a Doji has formed, the midpoint of the bar is stored in the buffer. If not, a value of 0 is stored in the buffer.

The IsDoji() function is used to determine whether a given bar is a Doji candle pattern. It calculates the size of the body, upper and lower shadows of the candle and compares them. If the sum of the body, upper and lower shadows is zero or if the upper and lower shadows are less than half the size of the body, the candle is considered a Doji.