Author: © mladen, 2018
Indicators Used
Relative strength index
0 Views
0 Downloads
0 Favorites
Simple RPC
ÿþ//+------------------------------------------------------------------

#property copyright   "© mladen, 2018"

#property link        "mladenfx@gmail.com"

#property version     "1.00"

#property description "Relative Price Channel"

#property indicator_separate_window

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

#property indicator_buffers 5

#property indicator_plots   5

//---

#property indicator_type1   DRAW_LINE

#property indicator_style1  STYLE_DASH 

#property indicator_color1  clrDarkBlue

#property indicator_width1  2

//---

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrDarkRed

//---

#property indicator_type3   DRAW_LINE

#property indicator_style3  STYLE_DASH 

#property indicator_color3  clrSilver

//---

#property indicator_type4   DRAW_LINE

#property indicator_style4  STYLE_DASH 

#property indicator_color4  clrSilver

//---

#property indicator_type5   DRAW_LINE

#property indicator_color5  clrDarkGreen

//

//--- input parameters

//

input int                inpRsiPeriod        = 14;          // RSI period

input ENUM_APPLIED_PRICE inpPrice            = PRICE_CLOSE; // RSI price 

input int                inpSmoothing        = 14;          // Smoothing period for RSI

input double             inpOverbought       = 70;          // Overbought level %

input double             inpOversold         = 30;          // Oversold level %

input double             inpUpperNeutral     = 55;          // Upper neutral level %

input double             inpLowerNeutral     = 45;          // Lower neutral level %

                                                            //

//--- buffers declarations

//

double pu[],pd[],nu[],nd[],rsi[];

//

//--- indicator handles

//

int rsi_handle;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,rsi,INDICATOR_DATA);

   SetIndexBuffer(1,nu,INDICATOR_DATA);

   SetIndexBuffer(2,nd,INDICATOR_DATA);

   SetIndexBuffer(3,pd,INDICATOR_DATA);

   SetIndexBuffer(4,pu,INDICATOR_DATA);

//---

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

      PlotIndexSetInteger(i,PLOT_SHOW_DATA,false);

//--- indicator short name assignment

   rsi_handle=iRSI(_Symbol,0,inpRsiPeriod,inpPrice);



   if(rsi_handle==INVALID_HANDLE) return(INIT_FAILED);



   IndicatorSetString(INDICATOR_SHORTNAME,"Simple RPC ("+

                      (string)inpRsiPeriod+","+

                      (string)inpSmoothing+")");

//---

   return (INIT_SUCCEEDED);

  }

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

//| Custom indicator de-initialization function                      |

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

void OnDeinit(const int reason)

  {

  }

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

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

  {

   if(BarsCalculated(rsi_handle)<rates_total)

      return(prev_calculated);



//---



   int copied=MathMin(rates_total-prev_calculated+1,rates_total);

   if(CopyBuffer(rsi_handle,0,0,copied,rsi)!=copied)

      return(prev_calculated);



//---



   int i=(int)MathMax(prev_calculated-1,0);



//---



   for(; i<rates_total && !_StopFlag; i++)

     {

      double si = (rsi[i]!=EMPTY_VALUE) ? rsi[i] : 0;

      double ob = iEma(si-inpOverbought  ,inpSmoothing,i,0);

      double os = iEma(si-inpOversold    ,inpSmoothing,i,1);

      double zu = iEma(si-inpUpperNeutral,inpSmoothing,i,2);

      double zd = iEma(si-inpLowerNeutral,inpSmoothing,i,3);



      pu[i] = ob;

      pd[i] = zu;

      nu[i] = os;

      nd[i] = zd;

      rsi[i]-=50;

     }



//---

   return (i);

  }

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

//| Custom functions                                                 |

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

#define instances 4

#define ringcount 6

double ema[ringcount][instances];

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

double iEma(double price,double period,int i,int t=0)

  {

   int c = (i  )%ringcount;

   int p = (i-1)%ringcount;



   if(i>0 && period>1)

      ema[c][t]=ema[p][t]+(2.0/(1.0+period))*(price-ema[p][t]);

   else ema[c][t]=price;

//---

   return(ema[c][t]);

  }

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

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