Ind_DeviationThreeMA

Author: Developer: Andrey Minaev
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Ind_DeviationThreeMA
ÿþ//+-----------------------------------------------------------------------------------------------+

//| Developer: Andrey Minaev                                                                      |

//| Indicator: Ind_DeviationThreeMA                                                               |

//| MQL5:      mql5.com/ru/users/id.scorpion                                                      |

//| Mail:      id.scorpion@mail.ru                                                                |

//| Skype:     id.scorpion                                                                        |

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

#property copyright "Developer: Andrey Minaev"

#property link      "http://www.mql5.com/ru/users/id.scorpion"

#property strict

#property indicator_chart_window

#property indicator_buffers 2



extern string             MASettings  = "";            // Moving Average Settings

extern int                MADeviation = 20;            // Deviation

extern int                MAPeriod    = 10;            // Period

extern ENUM_MA_METHOD     MAMethod    = MODE_SMA;      // Method

extern ENUM_APPLIED_PRICE MAPrice     = PRICE_CLOSE;   // Price



datetime newCandle;

double   upMA[];

double   dnMA[];

bool     drawArrowUp;

bool     drawArrowDn;



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

int OnInit()

{

   //--- ?@>25@8< :>;8G5AB2> A25G59

   if(MAPeriod*4 > Bars)

   {

      Print("54>AB0B>G=> A25G59 4;O @0AG5B0 8=48:0B>@0");

      return INIT_FAILED;

   }

   drawArrowUp = true;

   drawArrowDn = true;

   IndicatorShortName("Ind_DeviationThreeMA");

   IndicatorBuffers(3);

   SetIndexBuffer(0, upMA);

   SetIndexBuffer(1, dnMA);

   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1, clrGreen);

   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1, clrRed);

   SetIndexArrow(0, 233);

   SetIndexArrow(1, 234);

   SetIndexLabel(0, "Up");

   SetIndexLabel(1, "Dn");

   

   return INIT_SUCCEEDED;

}

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

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

{

   //--- @0AG8B05< =0 8AB>@88

   if(prev_calculated == 0)

   {

      int limit = Bars-MAPeriod*4;

      

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

      {

         double MAValue1 = NormalizeDouble(iMA(_Symbol, PERIOD_CURRENT, MAPeriod,   0, MAMethod, MAPrice, i), _Digits);

         double MAValue2 = NormalizeDouble(iMA(_Symbol, PERIOD_CURRENT, MAPeriod*2, 0, MAMethod, MAPrice, i), _Digits);

         double MAValue3 = NormalizeDouble(iMA(_Symbol, PERIOD_CURRENT, MAPeriod*4, 0, MAMethod, MAPrice, i), _Digits);

         //--- up

         if(drawArrowUp && (int)((MAValue1-MAValue2)/_Point) >= MADeviation && (int)((MAValue2-MAValue3)/_Point) >= MADeviation)

         {

            upMA[i] = low[i];

            drawArrowUp = false;

            drawArrowDn = true;

            continue;

         }

         //-- dn

         if(drawArrowDn && (int)((MAValue2-MAValue1)/_Point) >= MADeviation && (int)((MAValue3-MAValue2)/_Point) >= MADeviation)

         {

            dnMA[i] = high[i];

            drawArrowDn = false;

            drawArrowUp = true;

            continue;

         }

      }

   }

   if(prev_calculated > 0)

   {

      if(newCandle != time[0])

      {

         double MAValue1 = NormalizeDouble(iMA(_Symbol, PERIOD_CURRENT, MAPeriod,   0, MAMethod, MAPrice, 1), _Digits);

         double MAValue2 = NormalizeDouble(iMA(_Symbol, PERIOD_CURRENT, MAPeriod*2, 0, MAMethod, MAPrice, 1), _Digits);

         double MAValue3 = NormalizeDouble(iMA(_Symbol, PERIOD_CURRENT, MAPeriod*4, 0, MAMethod, MAPrice, 1), _Digits);

         //--- up

         if(drawArrowUp && (int)((MAValue1-MAValue2)/_Point) >= MADeviation && (int)((MAValue2-MAValue3)/_Point) >= MADeviation)

         {

            upMA[1] = low[1];

            drawArrowUp = false;

            drawArrowDn = true;

         }

         //-- dn

         if(drawArrowDn && (int)((MAValue2-MAValue1)/_Point) >= MADeviation && (int)((MAValue3-MAValue2)/_Point) >= MADeviation)

         {

            dnMA[1] = high[1];

            drawArrowDn = false;

            drawArrowUp = true;

         }

      }

      newCandle = time[0];

   }

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