Author: Alexandr Sokolov
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
RIF
ÿþ#property copyright   "Alexandr Sokolov"

#property link        "https://www.mql5.com/en/users/asokolov7"

#property version     "1.00"

#property description "Relative Impulse Force"

#property strict

#property indicator_separate_window

#property indicator_buffers 2

//--- CD5@K --------------------------------------------------------

double RIF_strong[], RIF_weak[];

//--- !B0B8G5A:85 ?5@5<5==K5 ----------------------------------------

static double atr_up,   //;O ?5@540G8 7=0G5=8O A@54=53> @>AB0

              atr_down; //;O ?5@540G8 7=0G5=8O A@54=53> ?045=8O

//--- E>4=K5 ?0@0<5B@K ---------------------------------------------

input int                 period           = 7,           //Period

                          ma_shift         = 0;           //Shift (MA)

input ENUM_MA_METHOD      ma_method        = MODE_EMA;    //Method (MA)

input ENUM_APPLIED_PRICE  ma_applied_price = PRICE_CLOSE; //Applied price (MA)

//-------------------------------------------------------------------------------------------------

int OnInit()

  {

  //--- @>25@:0 =0 :>@@5:B=>ABL 2E>4=KE ?0@0<5B@>2 -----------------

   if(period <= 1) {Print("The period of the indicator can not be less than 2"); return(INIT_FAILED);};

   if(ma_shift < 0) {Print("Indicator shift must be equal to or higher than 0"); return(INIT_FAILED);};

  //--- N0=AK ------------------------------------------------------

   IndicatorDigits(2);                             //>;8G5AB2> 45AOB8G=KE 7=0:>2 ?>A;5 70?OB>9

   IndicatorShortName("RIF ("+(string)period+")"); //8F52>5 8<O 2 >:=5 8=48:0B>@0

  //--- !>740Q< ?5@2>5 3@0D8G5A:>5 ?>AB@>5=85 -----------------------

   SetIndexBuffer(0,RIF_strong);                          //@82O7K205< 1CD5@ : ;8=88 !0

   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,clrLime); //#:07K205< B8?, AB8;L, B>;I8=C 8 F25B 4;O ;8=88 !0

   SetIndexLabel(0,"RIF");                                //@>?8AK205< >?8A0=85 4;O ;8=88 !0

  //--- !>740Q< 2B>@>5 3@0D8G5A:>5 ?>AB@>5=85 -----------------------

   SetIndexBuffer(1,RIF_weak);

   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,clrRed);

   SetIndexLabel(1,"RIF");

  //--- =8F80;870F8 ?@>945=0 CA?5H=> -------------------------------

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

  {

  //--- 1) #AB0=02;8205< ;8<8B --------------------------------------

   int limit = rates_total - prev_calculated - period - 1; if(limit < 0) {limit = 0;};

   double rif0, rif1; //;O ?5@540G8 7=0G5=89 =0 2KAG8BK205<>9 8 ?@54K4CI59 A25G5

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

     {

     //--- 2) KAG8BK205< 7=0G5=8O ATR_UD

      ATR_UD(i);

     //--- 4) KAG8BK205< 7=0G5=8O 8=48:0B>@0 8 ?@8A208205< 53> 3@0D8G5A:><C ?>AB@>5=8N A A>>B25BAB2CNI8< F25B><

      rif1 = (RIF_strong[i+1] != EMPTY_VALUE ? RIF_strong[i+1] : RIF_weak[i+1]);

      if(Close[i] >= iMA(_Symbol,PERIOD_CURRENT,period,ma_shift,ma_method,ma_applied_price,i))

        {

         rif0 = (Close[i] - iMA(_Symbol,PERIOD_CURRENT,period,ma_shift,ma_method,ma_applied_price,i)) / atr_up;

         RIF_strong[i] = (rif0 >= rif1 ? rif0 : EMPTY_VALUE);

         RIF_weak[i] = (rif0 >= rif1 ? EMPTY_VALUE : rif0);

        }

      else

        {

         rif0 = ((iMA(_Symbol,PERIOD_CURRENT,period,ma_shift,ma_method,ma_applied_price,i) - Close[i]) / atr_down) * (-1);

         RIF_strong[i] = (rif0 <= rif1 ? rif0 : EMPTY_VALUE);

         RIF_weak[i] = (rif0 <= rif1 ? EMPTY_VALUE : rif0);

        };

     };

  //-----------------------------------------------------------------

   return(rates_total);

  }

//--- ATR Up and Down -----------------------------------------------------------------------------

void ATR_UD(int i)

  {

  //--- 2) KAG8BK205< 7=0G5=8O ATR Up 8 ATR Down

   atr_up = 0; atr_down = 0;

   int limit = i + period;

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

     {

      atr_up += (High[a] - Open[a] != 0 ? High[a] - Open[a] : 1 / MathPow(10,Digits));

      atr_down += (Open[a] - Low[a] != 0 ? Open[a] - Low[a] : 1 / MathPow(10,Digits));

     };

  //--- 3) 5@540Q< 7=0G5=8O ATR Up 8 ATR Down

   atr_up = atr_up / period;

   atr_down = atr_down / period;

  }

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