Navigation:Home > Content >

VIP_Range_Factor.mq4

Time: 2015-10-01 | Download file:VIP_Range_Factor.mq4

//+------------------------------------------------------------------+
//|                                              VIP_RangeFactor.mq4 |
//|                                       Copyright © 2010, KingLion |
//|                                     http://www.metastock.org.ua/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, KingLion"
#property link      "http://www.metastock.org.ua/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Fuchsia
#property indicator_color2 DodgerBlue
#property indicator_color3 DodgerBlue
//--- input parameters
extern string Custom_Indicator = "VIP Range Factor";
extern string Copyright = "Copyright © 2010, KingLion";
extern string Web_Address = "www.metastock.org.ua";
extern double MyRange = 0.0;
extern string MyRange_Help = "If MyRange = 0.0 - defaults used (M1=0.01,M5=0.02,M15=0.04,M30=0.06,H1=0.08,H4=0.14,D1=0.4)";
//--- buffers
double RF_RangeLevel;
double RF_LinearValue[];
double RF_LowerLimit[];
double RF_UpperLimit[];
int counted_bars = 0;
int init()
  {
      switch (Period()) {
      case PERIOD_MN1:
         RF_RangeLevel = 0.5;
         break;
      case PERIOD_W1:
         RF_RangeLevel = 0.5;
         break;
      case PERIOD_D1:
         RF_RangeLevel = 0.4;
         break;
      case PERIOD_H4:
         RF_RangeLevel = 0.14;
         break;
      case PERIOD_H1:
         RF_RangeLevel = 0.08;
         break;
      case PERIOD_M30:
         RF_RangeLevel = 0.05;
         break;
      case PERIOD_M15:
         RF_RangeLevel = 0.04;
         break;
      case PERIOD_M5:
         RF_RangeLevel = 0.02;
         break;
      case PERIOD_M1:
         RF_RangeLevel = 0.01;
      }
      if (MyRange != 0.0) RF_RangeLevel = MyRange;

      IndicatorBuffers(3);
      SetIndexStyle(0, DRAW_LINE);
      SetIndexStyle(1, DRAW_LINE);
      SetIndexStyle(2, DRAW_LINE);
      SetIndexBuffer(0, RF_LinearValue);
      SetIndexBuffer(1, RF_UpperLimit);
      SetIndexBuffer(2, RF_LowerLimit);
      SetIndexLabel(0, "RF Linear Value");
      SetIndexLabel(1, "RF Upper Limit");
      SetIndexLabel(2, "RF Lower Limit");
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   counted_bars = IndicatorCounted();
   double RF_MA1 = 0;
   double RF_MA2 = 0;
   double RF_Exp = 0;
   if (counted_bars < 0) return (-1);
   int RF_count = Bars - counted_bars;
   if (RF_count > Bars - 34 - 1) RF_count = Bars - 34 - 1;
   for (int i = 0; i <= RF_count; i++) {
      RF_MA1 = 100.0 * (iMA(NULL, 0, 3, 0, MODE_LWMA, PRICE_CLOSE, i) - iMA(NULL, 0, 34, 0, MODE_LWMA, PRICE_CLOSE, i)) * iATR(NULL, 0, 3, i) + 0.00001;
      RF_MA2 = RF_MA1 / iMA(NULL, 0, 34, 0, MODE_LWMA, PRICE_CLOSE, i) / iATR(NULL, 0, 34, i);
      RF_Exp = (MathExp(2.0 * RF_MA2) - 1.0) / (MathExp(2.0 * RF_MA2) + 1.0);
      RF_LinearValue[i] = RF_Exp;
      RF_LowerLimit[i] = -RF_RangeLevel;
      RF_UpperLimit[i] = RF_RangeLevel;
   }
   return(0);
  }

Recommend