PinInsideCombination

Author: Kosuke Sakaguchi
0 Views
0 Downloads
0 Favorites
PinInsideCombination
//+------------------------------------------------------------------+
//|                                               PinInsideCombo.mq5 |
//|                                                 Kosuke Sakaguchi |
//|                       https://www.mql5.com/ja/users/pehb727qrc3m |
//+------------------------------------------------------------------+
//--- properties
#property copyright "Kosuke Sakaguchi"
#property link      "https://www.mql5.com/ja/users/pehb727qrc3m"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Bullish
#property indicator_label1  "Bullish"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Bearish
#property indicator_label2  "Bearish"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input double   MinTail=0.667;    // Minimum size of the pinbar's tail (relative to whole pinbar)
input double   MaxInside=0.75;   // Maximum size of the child bar (relative to the parent bar)
//--- indicator buffers
double         BullishBuffer[];
double         BearishBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BullishBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,BearishBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,241);
   PlotIndexSetInteger(1,PLOT_ARROW,242);
//--- set buffers as time series
   ArraySetAsSeries(BullishBuffer, true);
   ArraySetAsSeries(BearishBuffer, true);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration 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[])
  {
//--- set series as time series
   ArraySetAsSeries(time, true);
   ArraySetAsSeries(open, true);
   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   ArraySetAsSeries(close, true);
//--- calculate limit of iteration
   int limit;
   if(prev_calculated == 0)
     {
      limit = rates_total - 3;
     }
   else
     {
      limit = rates_total - prev_calculated;
     }
//--- search price patterns over time series
   for(int i=limit; i>=0; i--)
     {
      //--- get prices
      double open_parent   = open[i+2];
      double open_child    = open[i+1];
      double high_parent   = high[i+2];
      double high_child    = high[i+1];
      double low_parent    = low[i+2];
      double low_child     = low[i+1];
      double close_parent  = close[i+2];
      double close_child   = close[i+1];
      //--- calculate candles' size, child-to-parent ratio and length of wicks (a, b and c correspond to Figure 2)
      double size_parent         = high_parent - low_parent;                           // a
      double size_child          = high_child - low_child;                             // c
      double child_parent_ratio  = size_child / size_parent;                           // c/a
      double upper_wick_parent   = high_parent - MathMax(open_parent, close_parent);   // b in bearish pin bar
      double lower_wick_parent   = MathMin(open_parent, close_parent) - low_parent;    // b in bullish pin bar
      //--- check pinbar (whether b/a is bigger than MinTail)
      bool parent_bullish_pinbar = lower_wick_parent / size_parent >= MinTail;
      bool parent_bearish_pinbar = upper_wick_parent / size_parent >= MinTail;
      //--- check insidebar (whether parent bar engulfs child bar and c/a is smaller than MaxInside)
      bool insidebar             = high_parent > high_child && low_parent < low_child && child_parent_ratio <= MaxInside;
      //--- check conditions and plot signals
      if(parent_bullish_pinbar && insidebar)
        {
         BullishBuffer[i] = low[i] - 100 * _Point;
        }
      else
        {
         BullishBuffer[i] = EMPTY_VALUE;
        }
      if(parent_bearish_pinbar && insidebar)
        {
         BearishBuffer[i] = high[i] + 100 * _Point;
        }
      else
        {
         BearishBuffer[i] = EMPTY_VALUE;
        }
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---