Code Your Own Shooting Star Candle Pattern Recognition Indicator.

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

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


//+------------------------------------------------------------------+
//|                                                 Shooting-Star.mq4|
//|                                          Copyright 2023, Richpips|
//|                                        https://www.richpips.com/ |
//+------------------------------------------------------------------+

#property indicator_chart_window

// Indicator Parameters
extern int lookback_period = 10;  // Number of periods to look back
extern double body_to_wick_ratio = 2.0;  // Minimum body-to-wick ratio
extern double shadow_to_body_ratio = 1.0;  // Maximum shadow-to-body ratio

// Indicator Initialization
int OnInit()
{
    IndicatorDigits(Digits + 1);
    SetIndexStyle(0, DRAW_ARROW);
    SetIndexArrow(0, 233);
    SetIndexBuffer(0, ExtMapBuffer1);
    SetIndexEmptyValue(0, 0.0);
    return(INIT_SUCCEEDED);
}

// Indicator Calculation
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[])
{
    int shift;
    double candle_body, candle_high, candle_low, candle_upper_shadow, candle_lower_shadow, body_wick_ratio, shadow_body_ratio;

    for(shift = lookback_period; shift >= 0; shift--)
    {
        candle_body = MathAbs(close[shift] - open[shift]);
        candle_high = MathMax(close[shift], open[shift]);
        candle_low = MathMin(close[shift], open[shift]);
        candle_upper_shadow = candle_high - MathMax(high[shift], low[shift]);
        candle_lower_shadow = MathMin(high[shift], low[shift]) - candle_low;
        body_wick_ratio = candle_body / MathMax(candle_upper_shadow, candle_lower_shadow);
        shadow_body_ratio = MathMax(candle_upper_shadow, candle_lower_shadow) / candle_body;

        if(candle_body > 0.0 && candle_upper_shadow >= body_wick_ratio * body_to_wick_ratio && candle_lower_shadow >= body_wick_ratio * body_to_wick_ratio && shadow_body_ratio <= shadow_to_body_ratio)
        {
            ExtMapBuffer1[shift] = candle_low - (0.25 * MathAbs(candle_high - candle_low));
        }
        else
        {
            ExtMapBuffer1[shift] = 0.0;
        }
    }

    return(rates_total);
}

Let’s break down how this indicator works:

  1. First, we define the input parameters for the indicator: lookback_period, body_to_wick_ratio, and shadow_to_body_ratio. These parameters will determine the sensitivity and specificity of the indicator.
  2. In the OnInit() function, we initialize the indicator settings such as the chart window, style, and buffer values.
  3. In the OnCalculate() function, we loop through the specified number of periods (lookback_period) and calculate the relevant candlestick values such as the body, high, low, upper shadow, lower shadow, body-to-wick ratio, and shadow-to-body ratio.
  4. We then check if the current candlestick meets the criteria for a shooting star pattern based on the input parameters.