pchannel_system_v1

Author: Copyright © 2014, Nikolay Kositsin
0 Views
0 Downloads
0 Favorites
pchannel_system_v1
ÿþ//+------------------------------------------------------------------+

//|                                              PChannel_System.mq5 |

//|                               Copyright © 2014, Nikolay Kositsin | 

//|                              Khabarovsk,   farria@mail.redcom.ru | 

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

#property copyright "Copyright © 2014, Nikolay Kositsin"

#property link "farria@mail.redcom.ru"

#property description "The breakthrough system using the PChannel indicator"

//--- indicator version

#property version   "1.00"

//--- drawing the indicator in the main window

#property indicator_chart_window

//--- nine buffers are used for the indicator calculation and drawing

#property indicator_buffers 9

//--- four plots are used

#property indicator_plots   4

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

//| Indicator 1 drawing parameters               |

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

//--- drawing the indicator as a one-color cloud

#property indicator_type1   DRAW_FILLING

//--- WhiteSmoke color is used for the indicator

#property indicator_color1  clrWhiteSmoke

//--- displaying the indicator label

#property indicator_label1  "PChannel"

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

//| Indicator 2 drawing parameters               |

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

//--- drawing indicator 2 as a line

#property indicator_type2   DRAW_LINE

//--- LightSeaGreen color is used as the color of the bullish line of the indicator

#property indicator_color2  clrLightSeaGreen

//--- the line of the indicator 2 is a continuous curve

#property indicator_style2  STYLE_SOLID

//--- indicator 2 line width is equal to 2

#property indicator_width2  2

//--- display of the indicator bullish label

#property indicator_label2  "Upper PChannel"

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

//| Indicator 3 drawing parameters               |

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

//--- drawing indicator 3 as a line

#property indicator_type3   DRAW_LINE

//--- DeepPink color is used as the color of the indicator bearish line

#property indicator_color3  clrDeepPink

//--- the line of the indicator 3 is a continuous curve

#property indicator_style3  STYLE_SOLID

//--- indicator 3 line width is equal to 2

#property indicator_width3  2

//--- display of the bearish indicator label

#property indicator_label3  "Lower PChannel"

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

//| Indicator 4 drawing parameters               |

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

//--- drawing the indicator as a sequence of colored candlesticks

#property indicator_type4 DRAW_COLOR_CANDLES

//---- the following colors are used as the indicator colors

#property indicator_color4 clrMagenta,clrPurple,clrGray,clrMediumBlue,clrDodgerBlue

//--- Indicator line is a solid one

#property indicator_style4 STYLE_SOLID

//--- indicator line width is 2

#property indicator_width4 2

//--- displaying the indicator label

#property indicator_label4 "PChannel_BARS"

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

//| Indicator input parameters                   |

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

input uint period=20;       // Extrema finding period

input uint   Shift=2;       // Horizontal shift of the channel in bars 

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

//--- declaration of dynamic arrays that

//--- will be used as indicator buffers

double Up1Buffer[],Dn1Buffer[];

double Up2Buffer[],Dn2Buffer[];

double ExtOpenBuffer[],ExtHighBuffer[],ExtLowBuffer[],ExtCloseBuffer[],ExtColorBuffer[];

//--- declaration of integer variables of data starting point

int min_rates_total;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

//--- initialization of variables of the start of data calculation

   min_rates_total=int(period+1+Shift);

//--- set dynamic array as an indicator buffer

   SetIndexBuffer(0,Up1Buffer,INDICATOR_DATA);

//--- indexing elements in the buffer as in timeseries

   ArraySetAsSeries(Up1Buffer,true);

//--- set dynamic array as an indicator buffer

   SetIndexBuffer(1,Dn1Buffer,INDICATOR_DATA);

//--- indexing elements in the buffer as in timeseries

   ArraySetAsSeries(Dn1Buffer,true);

//--- set dynamic array as an indicator buffer

   SetIndexBuffer(2,Up2Buffer,INDICATOR_DATA);

//--- indexing elements in the buffer as in timeseries

   ArraySetAsSeries(Up2Buffer,true);

//--- set dynamic array as an indicator buffer

   SetIndexBuffer(3,Dn2Buffer,INDICATOR_DATA);

//--- indexing elements in the buffer as in timeseries

   ArraySetAsSeries(Dn2Buffer,true);

//--- Set IndBuffer dynamic array as an indicator buffer

   SetIndexBuffer(4,ExtOpenBuffer,INDICATOR_DATA);

   SetIndexBuffer(5,ExtHighBuffer,INDICATOR_DATA);

   SetIndexBuffer(6,ExtLowBuffer,INDICATOR_DATA);

   SetIndexBuffer(7,ExtCloseBuffer,INDICATOR_DATA);

//--- indexing elements in the buffer as in timeseries

   ArraySetAsSeries(ExtOpenBuffer,true);

   ArraySetAsSeries(ExtHighBuffer,true);

   ArraySetAsSeries(ExtLowBuffer,true);

   ArraySetAsSeries(ExtCloseBuffer,true);

//--- Setting a dynamic array as a color index buffer   

   SetIndexBuffer(8,ExtColorBuffer,INDICATOR_COLOR_INDEX);

//--- indexing elements in the buffer as in timeseries

   ArraySetAsSeries(ExtColorBuffer,true);

//---- shifting the indicator 1 horizontally by Shift

   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);

//--- shifting the starting point for drawing indicator 1 by min_rates_total

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- shifting the indicator 2 horizontally by Shift

   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);

//--- shifting the starting point for drawing indicator 2 by min_rates_total

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

//--- shifting the indicator 3 horizontally by Shift

   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);

//--- shifting the starting point for drawing indicator 3 by min_rates_total

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

//--- shifting the indicator 3 horizontally by Shift

   PlotIndexSetInteger(3,PLOT_SHIFT,0);

//--- shifting the starting point for drawing indicator 4 by min_rates_total

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

//--- setting the indicator values that won't be visible on a chart

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0);

//--- initializations of a variable for the indicator short name

   string shortname;

   StringConcatenate(shortname,"PChannel(",period,")");

//--- creation of the name to be displayed in a separate sub-window and in a pop up help

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//--- determining the accuracy of the indicator values

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,    // number of bars in history at the current tick

                const int prev_calculated,// amount of history in bars at the previous tick

                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[])

  {

//--- checking if the number of bars is enough for the calculation

   if(rates_total<min_rates_total) return(0);

//--- apply timeseries indexing to array elements  

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(close,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

//--- declaration of integer variables

   int limit;

//--- declaration of variables with a floating point  

   double HH,LL;

//--- calculations of the starting number limit for the bar recalculation loop

   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator

     {

      limit=rates_total-min_rates_total; // starting index for the calculation of all bars

     }

   else

     {

      limit=rates_total-prev_calculated; // starting index for the calculation of new bars

     }

//--- main calculation loop of the indicator

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

     {

      HH=high[ArrayMaximum(high,bar,period)];

      LL=low[ArrayMinimum(low,bar,period)];

      Up1Buffer[bar]=HH;

      Dn1Buffer[bar]=LL;

      Up2Buffer[bar]=HH;

      Dn2Buffer[bar]=LL;

     }

//--- calculation of the starting number limit for the bar recalculation loop

   if(prev_calculated>rates_total || prev_calculated<=0) limit-=int(Shift);

//--- the main loop of indicator bar coloring

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

     {

      int clr=2;

      ExtOpenBuffer[bar]=0.0;

      ExtCloseBuffer[bar]=0.0;

      ExtHighBuffer[bar]=0.0;

      ExtLowBuffer[bar]=0.0;

      //---

      if(close[bar]>Up1Buffer[bar+Shift])

        {

         if(open[bar]<=close[bar]) clr=4;

         else clr=3;

         ExtOpenBuffer[bar]=open[bar];

         ExtCloseBuffer[bar]=close[bar];

         ExtHighBuffer[bar]=high[bar];

         ExtLowBuffer[bar]=low[bar];

        }

      //---

      if(close[bar]<Dn1Buffer[bar+Shift])

        {

         if(open[bar]>close[bar]) clr=0;

         else clr=1;

         ExtOpenBuffer[bar]=open[bar];

         ExtCloseBuffer[bar]=close[bar];

         ExtHighBuffer[bar]=high[bar];

         ExtLowBuffer[bar]=low[bar];

        }

      //---

      ExtColorBuffer[bar]=clr;

     }

//---     

   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 ---