SRVI@3
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
SRVI@3
//+------------------------------------------------------------------+
//|                                   Super Relative Vigor Index.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Black
#property  indicator_color2  Black
#property  indicator_color3  Yellow
#property  indicator_color4  Red
//---- indicator parameters
extern int ExtRVIPeriod=10;
//---- indicator buffers
double     ExtRVIBuffer[];
double     ExtRVISignalBuffer[];
double     ExtRVIValue[];
double     ExtRVIValue2[];
//-------------------------------------------------------------------------------------
double Rozdiel;
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
  int Window=1,TimePart=0; double MinValue=-0.007978,MaxValue=0.086278; int Color=Blue;
//int Window=1,TimePart=0; double MinValue=0.000331,MaxValue=0.086278; 
//-------------------------------------------------------------------------------------

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtRVIBuffer);
   SetIndexBuffer(1,ExtRVISignalBuffer);
   SetIndexBuffer(2,ExtRVIValue);
   SetIndexBuffer(3,ExtRVIValue2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
//---- drawing settings   
   SetIndexDrawBegin(0,ExtRVIPeriod+3);   
   SetIndexDrawBegin(1,ExtRVIPeriod+7);     
   SetIndexDrawBegin(2,ExtRVIPeriod);     
   SetIndexDrawBegin(3,ExtRVIPeriod);     
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("RVI("+ExtRVIPeriod+")");
   SetIndexLabel(0,"RVI");
   SetIndexLabel(1,"RVIS");
   SetIndexLabel(2,"Value");
   SetIndexLabel(3,"Value2");
//---- initialization done
   DrawBasic();
   return(0);
  }
//+------------------------------------------------------------------+
//| Relativ Vigor Index                                              |
//+------------------------------------------------------------------+
int start()
  {
   int i,j,nLimit,nCountedBars;
   double dValueUp,dValueDown,dNum,dDeNum;
//----
   if(Bars<=ExtRVIPeriod+8) return(0);
//----
   nCountedBars=IndicatorCounted();
//---- check for possible errors
   if(nCountedBars<0) return(-1);
//---- last counted bar will be recounted
   nLimit=Bars-ExtRVIPeriod-4;
   if(nCountedBars>ExtRVIPeriod+4)
      nLimit=Bars-nCountedBars;
//---- RVI counted in the 1-st buffer
   for(i=0; i<=nLimit; i++)
     {
      dNum=0.0; 
      dDeNum=0.0;
      for(j=i; j<i+ExtRVIPeriod; j++)
        {
         dValueUp=((Close[j]-Open[j])+2*(Close[j+1]-Open[j+1])+2*(Close[j+2]-Open[j+2])+(Close[j+3]-Open[j+3]))/6;
         dValueDown=((High[j]-Low[j])+2*(High[j+1]-Low[j+1])+2*(High[j+2]-Low[j+2])+(High[j+3]-Low[j+3]))/6;
         dNum+=dValueUp;
         dDeNum+=dValueDown;
        }
      if(dDeNum!=0.0)
         ExtRVIBuffer[i]=dNum/dDeNum;
      else
         ExtRVIBuffer[i]=dNum;   
      //==----==//
      ExtRVIValue[i]=ExtRVISignalBuffer[i]+ExtRVIBuffer[i]*4;
      if(ExtRVISignalBuffer[i]>ExtRVIBuffer[i])
       {
        Rozdiel=ExtRVISignalBuffer[i]-ExtRVIBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVIBuffer[i]+Rozdiel;
       }      
      if(ExtRVIBuffer[i]>ExtRVISignalBuffer[i])
       {
        Rozdiel=ExtRVIBuffer[i]-ExtRVISignalBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVISignalBuffer[i]+Rozdiel;
       }      
      //==----==//
     }
//---- signal line counted in the 2-nd buffer
   nLimit=Bars-ExtRVIPeriod-7;
   if(nCountedBars>ExtRVIPeriod+8)
      nLimit=Bars-nCountedBars+1;
   for(i=0; i<=nLimit; i++)
      ExtRVISignalBuffer[i]=(ExtRVIBuffer[i]+2*ExtRVIBuffer[i+1]+2*ExtRVIBuffer[i+2]+ExtRVIBuffer[i+3])/6;
      //==----==//
      ExtRVIValue[i]=ExtRVISignalBuffer[i]+ExtRVIBuffer[i]*4;
      if(ExtRVISignalBuffer[i]>ExtRVIBuffer[i])
       {
        Rozdiel=ExtRVISignalBuffer[i]-ExtRVIBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVIBuffer[i]+Rozdiel;
       }      
      if(ExtRVIBuffer[i]>ExtRVISignalBuffer[i])
       {
        Rozdiel=ExtRVIBuffer[i]-ExtRVISignalBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVISignalBuffer[i]+Rozdiel;
       }      
      //==----==//
//----
   return(0);
  }
//+------------------------------------------------------------------+
double DrawBasic()
  {
   ObjectDelete("MaxMiddle");
   ObjectDelete("MinMiddle");
   ObjectCreate("MaxMiddle",OBJ_HLINE,Window,TimePart,MaxValue);      
   ObjectCreate("MinMiddle",OBJ_HLINE,Window,TimePart,MinValue);
   ObjectSet("MaxMiddle",OBJPROP_COLOR,Color);
   ObjectSet("MinMiddle",OBJPROP_COLOR,Color);
  }
//+------------------------------------------------------------------+
  
   

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