Percentage_Price_Follower_X_Pips_Channel

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
0 Views
0 Downloads
0 Favorites
Percentage_Price_Follower_X_Pips_Channel
ÿþ//+------------------------------------------------------------------+

//|                     Percentage_Price_Follower_X_Pips_Channel.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                                 https://mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://mql5.com"

#property version   "1.00"

#property description "Percentage Price Follower Channel indicator."

#property description "There are two modes:"

#property description "One"

#property description "The indicator follows the price, indicator is always trying to be equated with a price."

#property description "Defined percentage of the High-Low Range is the maximum shift."

#property description "Two"

#property description "The indicator follows the daily changes in price, in both directions,"

#property description "but only for a defined percentage of Open-Close Range."

#property description "Channel lines are aded X pip Up / Down from the Percentage Price Follower Line."

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_plots   3

//--- plot PPF

#property indicator_label1  "PPF Channel"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrDodgerBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Top

#property indicator_label2  "Top"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot Bottom

#property indicator_label3  "Bottom"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrGreen

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- enums

enum ENUM_FOLLOW_TYPE

  {

   TYPE_FOLLOW_PRICE,      // Follows the price 

   TYPE_FOLLOW_DAY_CHANGE  // Follows the daily changes

  };

//--- input parameters

input ENUM_FOLLOW_TYPE  InpTypeFollow     =  TYPE_FOLLOW_PRICE;   // Type of following

input uint              InpPercentRange1  =  10;                  // High-Low Range (Follows the price)

input int               InpPercentRange2  =  90;                  // Open-Close Range (Follows the daily changes)

input uint              InpChannelDelta   =  100;                 // Channel Delta (in points)

//--- indicator buffers

double         BufferPPF[];

double         BufferTop[];

double         BufferBottom[];

//--- global variables

double         delta;

int            range1;

int            range2;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- set global variables

   range1=int(InpPercentRange1<1 ? 1 : InpPercentRange1);

   range2=(InpPercentRange2==0 ? 1 : InpPercentRange2);

   delta=InpChannelDelta*Point();

//--- indicator buffers mapping

   SetIndexBuffer(0,BufferPPF,INDICATOR_DATA);

   SetIndexBuffer(1,BufferTop,INDICATOR_DATA);

   SetIndexBuffer(2,BufferBottom,INDICATOR_DATA);

//--- setting indicator parameters

   IndicatorSetString(INDICATOR_SHORTNAME,"PPrice Follower Channel ("+FollowType(InpTypeFollow)+", "+(InpTypeFollow==TYPE_FOLLOW_PRICE ?(string)range1 :(string)range2)+"%, delta "+(string)InpChannelDelta+")");

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferPPF,true);

   ArraySetAsSeries(BufferTop,true);

   ArraySetAsSeries(BufferBottom,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[])

  {

//--- #AB0=>2:0 <0AA82>2 1CD5@>2 :0: B09<A5@89

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

//--- @>25@:0 :>;8G5AB20 4>ABC?=KE 10@>2

   if(rates_total<4) return 0;

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-2;

      ArrayInitialize(BufferPPF,0);

      ArrayInitialize(BufferTop,EMPTY_VALUE);

      ArrayInitialize(BufferBottom,EMPTY_VALUE);

     }



//---  0AGQB 8=48:0B>@0

   for(int i=limit; i>=0 && !IsStopped(); i--)

     {

      if(i>rates_total-4)

        {

         BufferPPF[i]=close[i];

        }

      else

        {

         if(InpTypeFollow==TYPE_FOLLOW_PRICE)

           {

            if(BufferPPF[i+1]<close[i])

               BufferPPF[i]=BufferPPF[i+1]+(high[i]-low[i])*range1/100.0;

            else

              {

               if(BufferPPF[i+1]>close[i])

                  BufferPPF[i]=BufferPPF[i+1]-(high[i]-low[i])*range1/100.0;

               else

                  BufferPPF[i]=BufferPPF[i+1];

              }

           }

         else

            BufferPPF[i]=BufferPPF[i+1]+(close[i]-open[i])*range2/100.0;

        }

      BufferTop[i]=BufferPPF[i]+delta;

      BufferBottom[i]=BufferPPF[i]-delta;

     }



//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

//| >72@0I05B >?8A0=85 B8?0 A;54>20=8O                              |

//+------------------------------------------------------------------+

string FollowType(const ENUM_FOLLOW_TYPE type)

  {

   return(type==TYPE_FOLLOW_PRICE ? "Follows the price" : "Follows the daily changes");

  }

//+------------------------------------------------------------------+

Comments