Attachments forums

List of attachments posted on this forum.


All files on forums: 159928

Clarification regarding Random Walk Index indicator

slava, Thu Mar 16, 2017 9:21 am

Hello all,

I am in the process of converting a VSA indicator I found from AFL to MT4 and am looking for a little bit of help. I have successfully converted most of the code however I became confused when I got to the trend analysis portion that uses the Random Walk Index. Specifically the following code:

Code: Select all

 minperiodsRWIst = Param ( "Short term Min Periods", 2, 1, 9, 1); 
 maxperiodsRWIst = Param ( "Short term Max Periods", 8, 1, 9, 1); 
 minperiodsRWIlt = Param ( "Long Term Min Periods", 10, 1, 32, 1); 
 maxperiodsRWIlt = Param ( "Long term Max Periods", 40, 1, 64, 1);  
 
Ground = RWIHi (minperiodsRWIst, maxperiodsRWIst); 
 Sky    = RWILo (minperiodsRWIst, maxperiodsRWIst);  
 j      = RWI(minperiodsRWIlt, maxperiodsRWIlt);
 k      =  RWI(minperiodsRWIst, maxperiodsRWIst);
 j2     = RWIHi (minperiodsRWIlt, maxperiodsRWIlt); 
 k2     = RWILo (minperiodsRWIlt, maxperiodsRWIlt); 
I am unsure if this means that minperiodsRWIst, maxperiodsRWIst, minperiodsRWIlt, maxperiodsRWIlt are the bounding conditions of the RWI calculation so that the short term RWI is measuring price movement between periods 2 and 8 while long term is between periods 10 and 40. If this is the case I would have to make the following changes (in bold) to mladen's random_index_indicator and make an iCustom call.

Code: Select all

extern int minPeriod = 2;
extern int maxPeriod = 8;

double RWIUp[];
double RWIDown[];

//...........................................

for (i=limit, r=Bars-i-1; i>=0; i--,r++)
   {  
      ranges[r] = MathMax(High[i+1],Close[i+2])-MathMin(Low[i+1],Close[i+2]);
         double rwiUp = 0;
         double rwiDo = 0;
         double atr   = ranges[r];
         
         for (int k = minPeriod; k < maxPeriod; k++)
         {
            atr += ranges[r-k];  
            
            //
            //
            //
            //
            //
            
            double denominator  = (atr/(k+1.0))*MathSqrt(k+1);
               if (denominator != 0)
               {
                  rwiUp = MathMax(rwiUp,(High[i] - Low[i+k]) / denominator);
                  rwiDo = MathMax(rwiDo,(High[i+k] - Low[i]) / denominator);
               }
         }
         RWIUp[i]   = rwiUp;
         RWIDown[i] = rwiDo;
         Zline[i]   = 1.00;
   }         
whereas the initial code snippet would then become:

Code: Select all

 Ground[i] = iCustom(NULL,0,"random_walk_index",minperiodsRWIst, maxperiodsRWIst,0,i); 
 Sky[i] = iCustom(NULL,0,"random_walk_index",minperiodsRWIst, maxperiodsRWIst,1,i);   
 j2[i] = iCustom(NULL,0,"random_walk_index",minperiodsRWIlt, maxperiodsRWIlt,0,i); 
 k2[i] = iCustom(NULL,0,"random_walk_index",minperiodsRWIlt, maxperiodsRWIlt,1,i);
 j[i] = j2[i] - k2[i];
 k[i] = Ground[i] - Sky[i];
OR is it meant to measure the differences between a:
2 period RWIHi and an 8 period RWIHi
2 period RWILo and an 8 period RWILo
10 period RWIHi and a 40 period RWIHi
10 period RWILo and a 40 period RWILo

which would mean that no changes to the random_walk_index indicator would be needed and the iCustom call would look like:

Code: Select all

Ground[i] = iCustom(NULL,0,"random_walk_index",maxperiodsRWIst, 0,i) - iCustom(NULL,0,"random_walk_index",minperiodsRWIst, 0,i);
 Sky[i] = iCustom(NULL,0,"random_walk_index",maxperiodsRWIst,1,i) - iCustom(NULL,0,"random_walk_index",minperiodsRWIst,1,i);  
 j2[i] = iCustom(NULL,0,"random_walk_index",maxperiodsRWIlt,0,i) - Custom(NULL,0,"random_walk_index",minperiodsRWIlt,0,i);
 k2[i] = iCustom(NULL,0,"random_walk_index", maxperiodsRWIlt,1,i) - iCustom(NULL,0,"random_walk_index", minperiodsRWIlt,1,i);
 j[i] = j2[i] - k2[i];
 k[i] = Ground[i] - Sky[i];
Are either of these correct?

I am assuming the second way is the correct way but this is the first time I have dealt with the RWI and just want to make sure I am using it correctly.

Thanks for any help and sorry for all the code.
All files in topic