Author: Copyright � 2006, Alex Sidd (Executer)
ExCandles

This script is a specialized technical analysis tool designed to identify specific price action patterns on a trading chart. Instead of using standard mathematical formulas like Moving Averages or RSI, it analyzes the physical shapes and relationships of consecutive candlesticks to highlight potential shifts in market momentum.

Core Logic Overview

The tool scans historical price data to detect ten distinct types of candlestick formations. When the script identifies one of these patterns, it automatically places a visual marker (an arrow) on the chart to alert the user. These markers are color-coded: Red arrows typically indicate bearish (downward) pressure, while Blue arrows indicate bullish (upward) pressure.

Identified Patterns

The logic is divided into several categories based on candlestick geometry:

  • Single Candle Reversals:

    • Shooting Star & Hammer: The script looks for candles with very small bodies and long "wicks" (tails). A Hammer suggests a potential price floor, while a Shooting Star suggests a potential ceiling.
    • Specific Price Ratios: For these to be valid, the script calculates the ratio of the wick length relative to the candle body to ensure they meet specific structural proportions.
  • Multi-Candle Formations:

    • Morning & Evening Stars: These are three-candle patterns where a large move is followed by a small "transition" candle and then a reversal in the opposite direction. The script validates these by checking that the candles overlap or maintain a specific distance from one another.
    • Bullish & Bearish Engulfing: These occur when a two-candle sequence shows a much larger candle completely "swallowing" the previous one, signaling a total takeover of momentum by either buyers or sellers.
    • Doji Stars (Morning & Evening): The script identifies specific types of Doji candles—where the opening and closing prices are nearly identical—occurring in a sequence that suggests market indecision followed by a breakout.
  • Advanced Geometric Patterns:

    • "Cover of Darkness" & "Light in the Darkness": These represent more complex interactions between two candles where the price action shows a specific type of penetration or rejection of previous highs and lows, translated into visual signals.

How it Works on Your Chart

  1. Historical Scan: The script reviews the most recent price bars (based on a user-defined period).
  2. Pattern Matching: It runs every candle through a series of "True/False" checks based on the definitions above.
  3. Visual Output: If a pattern is confirmed, it creates a permanent arrow object on your chart.
    • Bearish Signals (Red): Placed above the high of a candle to suggest a possible price drop.
    • Bullish Signals (Blue): Placed below the low of a candle to suggest a possible price rise.

This tool acts as an automated "pattern recognition" assistant, scanning the noise of the market to highlight classic candlestick signals that traders often look for manually.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
ExCandles
//+------------------------------------------------------------------+
//|                                                    ExCandles.mq4 |
//|                           Copyright © 2006, Alex Sidd (Executer) |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Alex Sidd (Executer)"
#property link      "mailto:work_st@mail.ru"
//----
#property indicator_chart_window
#property indicator_buffers 1
#property  indicator_color1  Black
//---- input parameters
int ExPeriod = 10;
//---- buffers
double CCodeBuffer[];
//+------------------------------------------------------------------+
//| initialization function                                          |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   IndicatorBuffers(1);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, CCodeBuffer);
   SetIndexDrawBegin(0, ExPeriod);
   short_name = "ExCandles";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| deinitialization function                                        |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll(0, OBJ_ARROW); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsViselnik(int i1, int i2)
  {
   if((Open[i1] - Close[i1] > 0) && 
      ((High[i1] - Open[i1])*100 / (Open[i1] - Close[i1] + 0.0000001) < 15) && 
      ((Close[i1] - Low[i1])*100 / (Open[i1] - Close[i1] + 0.0000001) > 200) && 
      (Open[i2] - Close[i2] < 0)) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsHummer(int i1, int i2)
  {
   if((Open[i1] - Close[i1] < 0) &&
      ((High[i1] - Close[i1])*100 / (Close[i1] - Open[i1] + 0.0000001) > 200) && 
      ((Open[i1] - Low[i1])*100 / (Close[i1] - Open[i1] + 0.0000001) < 15) && 
      (Open[i2] - Close[i2] > 0)) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsBear(int i1, int i2, int i3)
  {
   if((Open[i2] - Close[i2] > 0) &&
      (Open[i2] >= Close[i3]) && 
      (Close[i2] <= Open[i3]) && 
      (Open[i3] - Close[i3] < 0) && 
      ((Open[i2] - Close[i2]) / (Close[i3] - Open[i3] + 0.0000001) > 1.5)) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsBull(int i1, int i2, int i3)
  {
   if((Open[i2] - Close[i2] < 0) && 
      (Open[i3] - Close[i3] > 0) && 
      (Close[i2] >= Open[i3]) && 
      (Open[i2] <= Close[i3]) && 
      ((Close[i2] - Open[i2]) / (Open[i3] - Close[i3] + 0.0000001) > 1.5)) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool Zavesa_black(int i1, int i2)
  {
   if((Open[i1] - Close[i1] > 0) &&
      (Open[i2] - Close[i2] < 0) && 
      ((Close[i2] - Open[i2]) / (High[i2] - Low[i2]) > 0.6) && 
      (Open[i1] > High[i2]) && 
      (Close[i1] < (Open[i2] + (Close[i2] - Open[i2])/2))) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool Prosvet(int i1, int i2, int i3)
  {
   if((Open[i1] - Close[i1] < 0) &&
      (Open[i2] - Close[i2] > 0) && 
      ((Open[i2] - Close[i2]) / (High[i2] - Low[i2]) > 0.6) && 
      (Open[i1] < Low[i2]) && 
      (Close[i1] > (Close[i2] + (Open[i2] - Close[i2]) / 2))) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool morning_star(int i1, int i2, int i3)
  {
   if((Open[i3] - Close[i3] > 0) && 
      (Close[i2] - Open[i2] > 0) && 
      (Close[i1] - Open[i1] > 0) && 
      (Close[i2] < Close[i3]) && 
      (Open[i1] > Close[i2]) && 
      (((MathAbs(Open[i3] - Close[i1]) + MathAbs(Open[i1] - Close[i3])) / 
      (Open[i3] - Close[i3] + 0.0000001)) < 0.1) && 
      ((Open[i3] - Close[i3]) / (High[i3] - Low[i3]) > 0.8) && 
      ((Close[i2] - Open[i2]) / (High[i2] - Low[i2]) < 0.3) && 
      (Close[i1] - Open[i1]) / (High[i1] - Low[i1]) > 0.8) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool evening_star(int i1, int i2, int i3)
  {
   if((Open[i3] - Close[i3] < 0) && 
      (Close[i2] - Open[i2] < 0) && 
      (Close[i1] - Open[i1] < 0) && 
      (Close[i2] > Close[i3]) && 
      (Open[i1] < Close[i2]) && 
      (((MathAbs(Open[i3] - Close[i1]) + MathAbs(Open[i1] - Close[i3])) / 
      (Close[i3] - Open[i3] + 0.0000001)) < 0.1) && 
      ((Close[i3] - Open[i3]) / (High[i3] - Low[i3]) > 0.8) && 
      ((Open[i2] - Close[i2]) / (High[i2] - Low[i2]) < 0.3) && 
      ((Open[i1] - Close[i1]) / (High[i1] - Low[i1]) > 0.8)) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsEveningDodgiStar(int i1, int i2, int i3)
  {
   if((Open[i3] - Close[i3] < 0) && 
      (Close[i2] - Open[i2] == 0) && 
      (Close[i1] - Open[i1] < 0) && 
      (Close[i2] >= Close[i3]) && 
      (Open[i1] <= Close[i2]) && 
      (((MathAbs(Open[i3] - Close[i1]) + MathAbs(Open[i1] - Close[i3])) / 
      (Open[i3] - Close[i3] + 0.0000001)) < 0.1)) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsMorningDodgiStar(int i1, int i2, int i3)
  {
   if((Open[i3] - Close[i3] > 0) && 
      (Close[i2] - Open[i2] == 0) && 
      (Close[i1] - Open[i1] > 0) && 
      (Close[i2] <= Close[i3]) && 
      (Open[i1] >= Close[i2]) && 
      (((MathAbs(Open[i3] - Close[i1]) + MathAbs(Open[i1] - Close[i3])) / 
      (Open[i3] - Close[i3] + 0.0000001)) < 0.1)) 
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//| Executer Candles Indicator                                       |
//+------------------------------------------------------------------+
int start()
  {
   int    i, counted_bars = IndicatorCounted();
   double negative = 0, positive = 0;
//----
   if(Bars <= ExPeriod) 
       return(0);
   if(counted_bars < 1)
       for(i = 1; i <= ExPeriod; i++) 
           CCodeBuffer[Bars-i] = 0.0;
//----
   i = Bars - ExPeriod - 1;
   if(counted_bars >= ExPeriod) 
       i = Bars - counted_bars - 1;
   while(i >= 0)
     {
       if(IsViselnik(i, i + 1) == true)
         {
           ObjectCreate("Âèñåëüíèê" + i, OBJ_ARROW, 0, Time[i], High[i] + 20*Point);
           ObjectSet("Âèñåëüíèê" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
           ObjectSet("Âèñåëüíèê" + i, OBJPROP_COLOR, Red);
           CCodeBuffer[i] = 1;
         }
       if(IsHummer(i, i + 1) == true)
         {
           ObjectCreate("Ìîëîò" + i, OBJ_ARROW, 0, Time[i], Low[i] - 20*Point);
           ObjectSet("Ìîëîò" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
           ObjectSet("Ìîëîò" + i, OBJPROP_COLOR, Blue);
           CCodeBuffer[i] = 2;
         }
       if(IsBear(i - 1, i, i + 1) == true)
         {
           ObjectCreate("Ìåäâåæüå ïîãëîùåíèå" + i, OBJ_ARROW, 0, Time[i], High[i] + 20*Point);
           ObjectSet("Ìåäâåæüå ïîãëîùåíèå" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
           ObjectSet("Ìåäâåæüå ïîãëîùåíèå" + i, OBJPROP_COLOR, Red);
           CCodeBuffer[i] = 3;
         }
       if(IsBull(i - 1, i, i + 1) == true)
         {
           ObjectCreate("Áû÷üå ïîãëîùåíèå" + i, OBJ_ARROW, 0, Time[i], Low[i] - 20*Point);
           ObjectSet("Áû÷üå ïîãëîùåíèå" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
           ObjectSet("Áû÷üå ïîãëîùåíèå" + i, OBJPROP_COLOR, Blue);
           CCodeBuffer[i] = 4;
         }
       if(Zavesa_black(i, i + 1) == true)
         {
           ObjectCreate("Çàâåñà èç òåìíûõ îáëàêîâ" + i, OBJ_ARROW, 0, Time[i], 
                        High[i] + 20*Point);
           ObjectSet("Çàâåñà èç òåìíûõ îáëàêîâ" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
           ObjectSet("Çàâåñà èç òåìíûõ îáëàêîâ" + i, OBJPROP_COLOR, Red);
           CCodeBuffer[i] = 5;
         }
       if(Prosvet(i - 1, i, i + 1) == true)
         {
           ObjectCreate("Ïðîñâåò â îáëàêàõ" + i, OBJ_ARROW, 0, Time[i], Low[i] - 20*Point);
           ObjectSet("Ïðîñâåò â îáëàêàõ" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
           ObjectSet("Ïðîñâåò â îáëàêàõ" + i, OBJPROP_COLOR, Blue);
           CCodeBuffer[i] = 6;
         }
       if(evening_star(i - 1, i, i + 1) == true)
         {
           ObjectCreate("Âå÷åðíÿÿ çâåçäà" + i, OBJ_ARROW, 0, Time[i], High[i] + 20*Point);
           ObjectSet("Âå÷åðíÿÿ çâåçäà" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
           ObjectSet("Âå÷åðíÿÿ çâåçäà" + i, OBJPROP_COLOR, Red);
           CCodeBuffer[i] = 7;
         }
       if(morning_star(i - 1, i, i + 1) == true)
         {
           ObjectCreate("Óòðåííÿÿ çâåçäà" + i, OBJ_ARROW, 0, Time[i], Low[i] - 20*Point);
           ObjectSet("Óòðåííÿÿ çâåçäà" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
           ObjectSet("Óòðåííÿÿ çâåçäà" + i, OBJPROP_COLOR, Blue);
           CCodeBuffer[i] = 8;
         }
       if(IsEveningDodgiStar(i - 1, i, i + 1) == true)
         {
           ObjectCreate("Âå÷åðíÿÿ äîäæè çâåçäà" + i, OBJ_ARROW, 0, Time[i], High[i] + 20*Point);
           ObjectSet("Âå÷åðíÿÿ äîäæè çâåçäà" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
           ObjectSet("Âå÷åðíÿÿ äîäæè çâåçäà" + i, OBJPROP_COLOR, Red);
           CCodeBuffer[i] = 9;
         }
       if(IsMorningDodgiStar(i - 1, i, i + 1) == true)
         {
           ObjectCreate("Óòðåííÿÿ äîäæè çâåçäà" + i, OBJ_ARROW, 0, Time[i], Low[i] - 20*Point);
           ObjectSet("Óòðåííÿÿ äîäæè çâåçäà" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
           ObjectSet("Óòðåííÿÿ äîäæè çâåçäà" + i, OBJPROP_COLOR, Blue);
           CCodeBuffer[i] = 10;
         }
       i--;
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments