Code Your Own Hanging Man Candle Pattern Recognition Indicator.

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

This code provides a basic framework for detecting Hanging Man 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.

//|                                            Hanging-Man-Finder.mq4|
//|                                        Copyright © 2023, Richpips|
//|                                |

// Define indicator input parameters
extern int lookback = 5;

// Define indicator buffers
double buffer[];

// Define indicator variables
int signal = 0;

// Define hanging man candle pattern function
bool HangingMan(int i) {
   if (i < 1) return false;
   if (Open[i] < Close[i] && Open[i-1] > Close[i-1] && Close[i] < Low[i-1] - (High[i-1] - Low[i-1]) / 2 && Close[i] > Low[i-1]) return true;
   return false;

// Define OnInit function
int OnInit() {
   // Set indicator buffers
   SetIndexBuffer(0, buffer, INDICATOR_DATA);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 159);
   IndicatorShortName("Hanging Man");


// Define OnCalculate function
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) {
   // Calculate indicator
   for (int i = prev_calculated; i < rates_total; i++) {
      if (HangingMan(i)) {
         signal = 1;
         buffer[i] = Low[i];
      } else {
         buffer[i] = EMPTY_VALUE;

   // Set signal and return value
   if (signal == 1) {
      signal = 0;
   } else {

This code defines an indicator that looks for a hanging man candle pattern in the chart data. The indicator uses the HangingMan function to identify the pattern, which checks if the current candlestick is a hanging man based on the criteria for this pattern. If the current candlestick is a hanging man, the buffer array is updated to show an arrow pointing downwards at the low of the candlestick.

The OnInit function sets up the indicator by defining the indicator buffers and styling the arrows. The OnCalculate function is called whenever the chart is updated and calculates the indicator value for each candlestick on the chart. The signal variable is used to ensure that only one arrow is displayed per hanging man pattern.

To use this indicator, simply add it to a chart in MetaTrader 4 and it will automatically highlight any hanging man patterns that appear on the chart. Note that this is just an example and should be tested thoroughly before using in a live trading environment.