VR Donchian Lite MT5 Arrows

Author: Copyright © 2019, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
VR Donchian Lite MT5 Arrows
ÿþ//+------------------------------------------------------------------+

//|                                  VR Donchian Lite MT5 Arrows.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.000"

#property description "A simple standard Donchian indicator plus arrows"

/* 

   Created from

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

//|                                  VR Donchian Lite MT5 Arrows.mq5 |                                  

//|                              Copyright 2018, Trading-go Project. |                            

//|Author: Voldemar, Version: 12.09.2018, Site https://trading-go.ru |              

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

*/

#property indicator_chart_window

#property indicator_buffers 5

#property indicator_plots   5

//--- input parameters

input int          Period_      = 24;         // Period Donchian

input color        UpperLine    = clrBlue;    // Color Upper Line

input color        LowerLine    = clrRed;     // Color Lower Line

input color        AverageLine  = clrGreen;   // Color Average Line 

//--- indicator buffers

double upper_line[],lower_line[],awera_line[],up_trend[],down_trend[];

//---

datetime last_up_trend=0,last_down_trend=0;   // "0" -> D'1970.01.01 00:00';

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   Comment("");

   IndicatorSetString(INDICATOR_SHORTNAME,"VR Donchian Lite Arrows("+(string)Period_+")");

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);



   SetIndexBuffer(0,upper_line,INDICATOR_DATA); ArraySetAsSeries(upper_line,true);

   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);

   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID);

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,UpperLine);

   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,2);

   PlotIndexSetString(0,PLOT_LABEL,"Upper Line");



   SetIndexBuffer(1,lower_line,INDICATOR_DATA); ArraySetAsSeries(lower_line,true);

   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);

   PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_SOLID);

   PlotIndexSetInteger(1,PLOT_LINE_COLOR,LowerLine);

   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,2);

   PlotIndexSetString(1,PLOT_LABEL,"Lower Line");



   SetIndexBuffer(2,awera_line,INDICATOR_DATA); ArraySetAsSeries(awera_line,true);

   PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_LINE);

   PlotIndexSetInteger(2,PLOT_LINE_STYLE,STYLE_DOT);

   PlotIndexSetInteger(2,PLOT_LINE_COLOR,AverageLine);

   PlotIndexSetInteger(2,PLOT_LINE_WIDTH,1);

   PlotIndexSetString(2,PLOT_LABEL,"Average Line");



   SetIndexBuffer(3,up_trend,INDICATOR_DATA); ArraySetAsSeries(up_trend,true);

   PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_ARROW);

   PlotIndexSetInteger(3,PLOT_LINE_COLOR,UpperLine);

   PlotIndexSetInteger(3,PLOT_LINE_WIDTH,1);

   PlotIndexSetString(3,PLOT_LABEL,"Up trend");

   PlotIndexSetInteger(3,PLOT_ARROW,174);       // define the symbol code for drawing in PLOT_ARROW 

   PlotIndexSetInteger(3,PLOT_ARROW_SHIFT,-5);  // set the vertical shift of arrows in pixels 

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0);    // set as an empty value 0 



   SetIndexBuffer(4,down_trend,INDICATOR_DATA); ArraySetAsSeries(down_trend,true);

   PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_ARROW);

   PlotIndexSetInteger(4,PLOT_LINE_COLOR,LowerLine);

   PlotIndexSetInteger(4,PLOT_LINE_WIDTH,1);

   PlotIndexSetString(4,PLOT_LABEL,"Down trend");

   PlotIndexSetInteger(4,PLOT_ARROW,174);       // define the symbol code for drawing in PLOT_ARROW 

   PlotIndexSetInteger(4,PLOT_ARROW_SHIFT,5);   // set the vertical shift of arrows in pixels 

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0.0);    // set as an empty value 0 



   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate (const int rates_total,      // the size of the input timeseries 

                 const int prev_calculated,  // bars processed at the previous call 

                 const datetime& time[],     // Time 

                 const double& open[],       // Open 

                 const double& high[],       // High 

                 const double& low[],        // Low 

                 const double& close[],      // Close 

                 const long& tick_volume[],  // Tick Volume 

                 const long& volume[],       // Real Volume 

                 const int& spread[]         // Spread 

                 )

  {

   ArraySetAsSeries(time,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);



   if(rates_total<=Period_ || Period_<=0)

      return(0);



   int limit=rates_total-prev_calculated-1;

   if(limit<0) limit=0;



   for(int i=limit;i>=0;i--)

     {

      upper_line[i]=high[iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,Period_,i)];

      lower_line[i]=low[iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,Period_,i)];

      awera_line[i]=(upper_line[i]+lower_line[i])/2;

      if(i<rates_total-1)

        {

         if(close[i]>high[i+1] && close[i]>awera_line[i])

           {

            if(last_up_trend==D'1970.01.01 00:00')

               last_up_trend=time[i];

            if(time[i]==last_up_trend)

               up_trend[i]=high[i];

            last_down_trend=0;

           }

         if(close[i]<low[i+1] && close[i]<awera_line[i])

           {

            if(last_down_trend==D'1970.01.01 00:00')

               last_down_trend=time[i];

            if(time[i]==last_down_trend)

               down_trend[i]=low[i];

            last_up_trend=0;

           }

        }

      else

        {

         up_trend[i]=0.0;

         down_trend[i]=0.0;

        }

     }



   return(rates_total);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {



  }

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

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