Author: © 2020, Alexey Viktorov
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
RAVI_v2
ÿþ//+------------------------------------------------------------------+

//|                                                         RAVI.mq5 |

//|                                          © 2020, Alexey Viktorov |

//|                     https://www.mql5.com/ru/users/alexeyvik/news |

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

#property copyright "© 2020, Alexey Viktorov"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.00"

#property indicator_separate_window



#property indicator_buffers 2

#property indicator_plots   1

#property indicator_type1   DRAW_COLOR_HISTOGRAM

#property indicator_color1  clrDimGray, clrRed, clrGreen

#property indicator_width1  2



input int MAfast  = 7;  //  Period fast MovingAverage

input int MAslow  = 65; //  Period slow MovingAverage



int handleMAfast, handleMAslow;



double ravi[], col[], fastMA[], slowMA[];

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

//|            Custom indicator initialization function              |

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

int OnInit()

 {

//--- indicator buffers mapping

  SetIndexBuffer(0, ravi);

  SetIndexBuffer(0, ravi, INDICATOR_DATA);

  SetIndexBuffer(1, col);

  SetIndexBuffer(1, col, INDICATOR_COLOR_INDEX);

  SetIndexBuffer(2, fastMA);

  SetIndexBuffer(2, fastMA, INDICATOR_CALCULATIONS);

  SetIndexBuffer(3, slowMA);

  SetIndexBuffer(3, slowMA, INDICATOR_CALCULATIONS);

//--- get handles

  handleMAfast = iMA(_Symbol, PERIOD_CURRENT, MAfast, 0, MODE_SMA, PRICE_CLOSE);

  handleMAslow = iMA(_Symbol, PERIOD_CURRENT, MAslow, 0, MODE_SMA, PRICE_CLOSE);

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

 {

  int limit = rates_total-prev_calculated > 1 ? 1 : prev_calculated-1;

  for(int i = limit; i < rates_total; i++)

   {

    if(CopyBuffer(handleMAfast, 0, 0, rates_total, fastMA) <= 0 ||

       CopyBuffer(handleMAslow, 0, 0, rates_total, slowMA) <= 0)

      return 0;

    //--- calculate value

    ravi[i] = ((fastMA[i]-slowMA[i])*100)/slowMA[i];

    col[i] = ravi[i] < 0 && ravi[i] < ravi[i-1] ? 1.0 : ravi[i] > 0 && ravi[i] > ravi[i-1] ? 2.0 : 0.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 ---