RSI(3lines)

Author: Copyright 2020,fxMeter
0 Views
0 Downloads
0 Favorites
RSI(3lines)
ÿþ//+------------------------------------------------------------------+

//|                                                  RSI(3lines).mq4 |

//|                                           Copyright 2020,fxMeter |

//|                            https://www.mql5.com/zh/users/fxmeter |

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

//2020-3-2 12:53:57 9hnc¾áOlQ_9e

//MT4Hr,g: https://www.mql5.com/zh/code/28132

//MT5Hr,gÿhttps://www.mql5.com/zh/code/28133

/*

¾áOlQ_,ÂSpeN1=6,N2=12,N3=24

LC:=REF(CLOSE,1);

RSI1:SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;

RSI2:SMA(MAX(CLOSE-LC,0),N2,1)/SMA(ABS(CLOSE-LC),N2,1)*100;

RSI3:SMA(MAX(CLOSE-LC,0),N3,1)/SMA(ABS(CLOSE-LC),N3,1)*100;



(uÕl:

1.RSI>80:N…pNÿRSI<20:N…VSÿ

2.RSIåN50:N-NLu¿~ÿ'YŽN50Ɖ:NY4YLˆÅ`ÿ\ŽN50Ɖ:Nzz4YLˆÅ`ÿ

3.RSI(W80åN
Nb_b-ÿ4Yb4Y©€v˜b_`öeÿƉ:NTNÍSláO÷Sÿ

4.RSI(W20åNNb_b7ÿ•^b4Y©€•^b_`öeÿƉ:NT
NÍSláO÷Sÿ

5.RSIT
Nz4xvQؚ¹pޏ¿~öeÿpNۏÿRSITN̍4xvQNO¹pޏ¿~öeÿVSúQ0

*/

#property copyright "Copyright 2020,fxMeter"

#property link      "https://www.mql5.com/zh/users/fxmeter"

#property version   "1.00"

#property strict

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_maximum 100

#property indicator_buffers 3

#property indicator_plots   3

//--- plot R

#property indicator_label1  "R"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrLavender

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot S

#property indicator_label2  "S"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrGold

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot I

#property indicator_label3  "I"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrFuchsia

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- input parameters

input int      N1=6;

input int      N2=12;

input int      N3=24;

//--- indicator buffers

double         RBuffer[];

double         SBuffer[];

double         IBuffer[];

//--- …©R¡‹—{ buffer

double max[],abs[];

double smax1[],sabs1[];

double smax2[],sabs2[];

double smax3[],sabs3[];

double a,a1,b,b1,c,c1;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   IndicatorBuffers(11);

   SetIndexBuffer(0,RBuffer);

   SetIndexBuffer(1,SBuffer);

   SetIndexBuffer(2,IBuffer);

   SetIndexBuffer(3,max,INDICATOR_CALCULATIONS);

   SetIndexBuffer(4,abs,INDICATOR_CALCULATIONS);

   SetIndexBuffer(5,smax1,INDICATOR_CALCULATIONS);

   SetIndexBuffer(6,sabs1,INDICATOR_CALCULATIONS);

   SetIndexBuffer(7,smax2,INDICATOR_CALCULATIONS);

   SetIndexBuffer(8,sabs2,INDICATOR_CALCULATIONS);

   SetIndexBuffer(9,smax3,INDICATOR_CALCULATIONS);

   SetIndexBuffer(10,sabs3,INDICATOR_CALCULATIONS);



   for(int i=0; i<3; i++)

     {

      SetIndexDrawBegin(i,N1+N1+N3);

      SetIndexEmptyValue(i,-1);

     }



   SetLevelValue(0,20);

   SetLevelValue(1,50);

   SetLevelValue(2,80);



   string name = "RSI("+ (string)N1+","+(string)N2+","+(string)N3+")";

   IndicatorShortName(name);



   IndicatorDigits(2);



   if(N1<=0||N2<=0||N3<=0)return(INIT_FAILED);

   a = 1.0/N1;   a1 = 1-a;

   b = 1.0/N2;   b1 = 1-b;

   c = 1.0/N3;   c1 = 1-c;



//---

   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 i,limit=0;

   if(rates_total<=0)return(0);

   if(prev_calculated<=0)limit=rates_total-1;

   else

      limit = rates_total - prev_calculated +1;



//--- MAX,ABS

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

     {

      if(i>=rates_total-1) max[i]=0;

      else

        {

         max[i] = close[i]-close[i+1]>0 ? close[i]-close[i+1]:0;

        }

     }

     

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

     {

      if(i>=rates_total-1)abs[i]=0;

      else

      abs[i] = MathAbs(close[i]-close[i+1]);         

     }  



//--- S(MAX),S(ABS) 

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

     {

      if(i>=rates_total-1){smax1[i] = smax2[i] = smax3[i] = max[i];}

      else

       {

         smax1[i] = a*max[i] + a1*smax1[i+1];

         smax2[i] = b*max[i] + b1*smax2[i+1];

         smax3[i] = c*max[i] + c1*smax3[i+1];

       }  

     }

        

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

     {

      if(i>=rates_total-1){sabs1[i]= sabs2[i] = sabs3[i]= abs[i];}

      else

      {

       sabs1[i] = a*abs[i] + a1*sabs1[i+1];

       sabs2[i] = b*abs[i] + b1*sabs2[i+1];

       sabs3[i] = c*abs[i] + c1*sabs3[i+1];

      }

     }      

     

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

     {

        if(i>=rates_total-1){RBuffer[i]=SBuffer[i]=IBuffer[i]=0.0;continue;}

        //...

        if(sabs1[i]!=0)RBuffer[i]=smax1[i]/sabs1[i]*100;else RBuffer[i]=-1;

        if(sabs2[i]!=0)SBuffer[i]=smax2[i]/sabs2[i]*100;else SBuffer[i]=-1;

        if(sabs3[i]!=0)IBuffer[i]=smax3[i]/sabs3[i]*100;else IBuffer[i]=-1;

     }



//--- return value of prev_calculated for next call

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