combination of 2 indicator - page 2

 

here all the code...


//+------------------------------------------------------------------+
//|                                                     StochRVI.mq4 |
//|                                             Copyright 2012, Abu. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Abu."
#property link      "http://www.metaquotes.net"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_minimum 0
#property  indicator_maximum 100
#property  indicator_buffers 4
#property  indicator_color1  LightSeaGreen
#property  indicator_color2  Yellow
#property  indicator_color3  Green
#property  indicator_color4  Red
//---- indicator parameters
extern int ExtRVIPeriod=10;
extern int KPeriod=5;
extern int DPeriod=2;
extern int Slowing=3;
//---- indicator buffers
double     ExtRVIBuffer[];
double     ExtRVISignalBuffer[];
double     MainBuffer[];
double     SignalBuffer[];
double     HighesBuffer[];
double     LowesBuffer[];
//---- drawbegin
int draw_begin1=0;
int draw_begin2=0;
int draw_begin3=0;
int draw_begin4=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  string short_name;
//---- indicators buffer counting mapping
   IndicatorBuffers(6);
   SetIndexBuffer(0,ExtRVIBuffer);
   SetIndexBuffer(1,ExtRVISignalBuffer);
   SetIndexBuffer(2,HighesBuffer);
   SetIndexBuffer(3,LowesBuffer);
//---- indicator lines
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MainBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,SignalBuffer)
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,SignalBuffer)
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,SignalBuffer)
//---- name for DataWindow and indicator subwindow label
   short_name="StochRVI("+KPeriod+","+DPeriod+","+Slowing+","+ExtRVIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"Signal1");
   SetIndexLabel(2,"Signal2");
   SetIndexLabel(3,"Signal3");
   SetIndexLabel(4,"Signal4"); 
//---- StochRVI drawing setting
   SetIndexDrawBegin draw_begin1=KPeriod+Slowing;
   SetIndexDrawBegin draw_begin2=draw_begin1+DPeriod;
   SetIndexDrawBegin(0,draw_begin1);
   SetIndexDrawBegin(1,draw_begin2);
   SetIndexDrawBegin(2,ExtRVIPeriod+3);   
   SetIndexDrawBegin(3,ExtRVIPeriod+7);  
   return(0);
  }
//+------------------------------------------------------------------+
//|  StochRVI deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   int    a,b,nLimit,nCountedBars,counted_bars=IndicatorCounted();
   double dValueUp,dValueDown,dNum,dDeNum;
//----
   if(Bars<=draw_begin2);
   if(Bars<=ExtRVIPeriod+8);
   return(0);
//----initial zero
   if(counted_bars<1);
   nCountedBars=IndicatorCounted();
     {
      for(a=1;a<=draw_begin1;a++) MainBuffer[Bars-a]=0;
      for(a=1;a<=draw_begin2;a++) SignalBuffer[Bars-a]=0;
     }
//---- 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;
   return(0);
  }
//---- minimums counting
   a=Bars-KPeriod;
   if(counted_bars>KPeriod) a=Bars-counted_bars-1;
   while(a>=0)
      for(a=0; a<=nLimit; a++); 
      && (j=a; j<a+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;
         dNum=0.0; 
         dDeNum=0.0;
        }
      if(dDeNum!=0.0)
         ExtRVIBuffer[a]=dNum/dDeNum;
      else
         ExtRVIBuffer[a]=dNum;   
     }
   if(counted_bars>KPeriod) a=Bars-counted_bars-1;
   while(a>=0)
     {
      double min=1000000;
      k=a+KPeriod-1;
      while(k>=a)
        {
         price=Low[k];
         if(min>price) min=price;
         k--;
        }
      LowesBuffer[a]=min;
      a--;
     }
//---- maximums counting
   a=Bars-KPeriod;
   if(counted_bars>KPeriod) a=Bars-counted_bars-1;
   while(i>=0)
     {
      double max=-1000000;
      k=a+KPeriod-1;
      while(k>=a)
        {
         price=High[k];
         if(max<price) max=price;
         k--;
        }
      HighesBuffer[a]=max;
      a--;
     }
//---- %K line
   a=Bars-draw_begin1;
   if(counted_bars>draw_begin1) a=Bars-counted_bars-1;
   while(a>=0)
     {
      double sumlow=0.0;
      double sumhigh=0.0;
      for(k=(a+Slowing-1);k>=a;k--)
        {
         sumlow+=Close[k]-LowesBuffer[k];
         sumhigh+=HighesBuffer[k]-LowesBuffer[k];
        }
      if(sumhigh==0.0) MainBuffer[a]=100.0;
      else MainBuffer[a]=sumlow/sumhigh*100;
      i--;
     }
     //---- signal line counted in the 2-nd buffer
   nLimit=Bars-ExtRVIPeriod-7;
   if(nCountedBars>ExtRVIPeriod+8)
      nLimit=Bars-nCountedBars+1;
   for(a=0; a<=nLimit; a++)
      ExtRVISignalBuffer[a]=(ExtRVIBuffer[a]+2*ExtRVIBuffer[a+1]+2*ExtRVIBuffer[a+2]+ExtRVIBuffer[a+3])/6;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
      nLimit=Bars-ExtRVIPeriod-7;
   if(nCountedBars>ExtRVIPeriod+8)
      nLimit=Bars-nCountedBars+1;
//---- signal line is simple movimg average
   for(a=0; a<limit; a++)
      SignalBuffer[a]=iMAOnArray(MainBuffer,Bars,DPeriod,0,MODE_SMA,i);
      ExtRVISignalBuffer[a]=(ExtRVIBuffer[a]+2*ExtRVIBuffer[a+1]+2*ExtRVIBuffer[a+2]+ExtRVIBuffer[a+3])/6;
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Oh you again. You're the guy with a lot of ideas. You should know we can't help you with only partial code

:)

 

yea, is me ...

please help me to done my first work...


why the global scope not allowed ??

 
can i just copy and paste and just change some word to make it ?
 

I think RaptorUK told you not just to copy paste and should learning first. But still, you learning by copy pasting without any idea how things work. Would you please be so kind to read the book first (click here) before even asking a question here in the forum.

For a starter, you writing the code in deinit() which will never get executed !!!

 
albert_lim83:
can i just copy and paste and just change some word to make it ?
Not literaly copy paste, but yes if you know how it works and do it in the right way. I did/do that too.
 

ok...

i learning from there, then ask again next week...

 
albert_lim83:

ok...

i learning from there, then ask again next week...

This is the end of deinit(), and still you write the code outside deinit(), and that's why you get [expression on global scope not allowed]

   return(0);
  } ?? <<======================= the end of deinit()
//---- minimums counting
   a=Bars-KPeriod;
 

I see no sense making it the separate indicators are giving same value as put togheter if it is rvi on stochastic or stochastic on rvi

It just make no difference.....

 

i just try to combine it,

just for practice.....

Reason: