Page 1 of 1

Clarification regarding Random Walk Index indicator

Posted: Thu Mar 16, 2017 9:25 am
by slava
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.

Re: Clarification regarding Random Walk Index indicator

Posted: Thu Mar 16, 2017 10:24 am
by mntiwana
May be these Random Walk MT4 code help you.

Re: Clarification regarding Random Walk Index indicator

Posted: Thu Mar 16, 2017 4:40 pm
by mladen
slava wrote: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
Slava

Do you have the exact code of all the functions used in that code? Since all those functions must be coded as in the original, or else the difference might be inexplicable

Re: Clarification regarding Random Walk Index indicator

Posted: Thu Mar 16, 2017 5:45 pm
by slava
mladen wrote:
Slava

Do you have the exact code of all the functions used in that code? Since all those functions must be coded as in the original, or else the difference might be inexplicable
Do you mean all of the functions within VSA afl file or the RWI, RWILo, RWIHi functions. The latter uses the built-in RWI functions from Amibroker which are :

Code: Select all

RWILo = IIf(i==minperiods,(Ref(High,-(i-1))-Low)/ (ref(ATR(i),-1)*sqrt(i)),Max((Ref(High,-(i-1))-Low)/ (ref(ATR(i),-1)*sqrt(i)),RWILo));
RWIHi = IIf(i==minperiods,(High-Ref(Low,-(i-1)))/ (ref(ATR(i),-1)*sqrt(i)),Max((High-Ref(Low,-(i-1)))/ (ref(ATR(i),-1)*sqrt(i)),RWIHi)); 
I did just find the two functions above being explained inside a for loop of

Code: Select all

for( i = minperiods; i <= maxperiods ; i++ ) 
which would make the first guess of my initial post the correct way, I think.

Re: Clarification regarding Random Walk Index indicator

Posted: Thu Mar 16, 2017 7:03 pm
by mladen
slava wrote:
Do you mean all of the functions within VSA afl file or the RWI, RWILo, RWIHi functions. The latter uses the built-in RWI functions from Amibroker which are :

Code: Select all

 RWILo = IIf(i==minperiods,(Ref(High,-(i-1))-Low)/ (ref(ATR(i),-1)*sqrt(i)),Max((Ref(High,-(i-1))-Low)/ (ref(ATR(i),-1)*sqrt(i)),RWILo)); RWIHi = IIf(i==minperiods,(High-Ref(Low,-(i-1)))/ (ref(ATR(i),-1)*sqrt(i)),Max((High-Ref(Low,-(i-1)))/ (ref(ATR(i),-1)*sqrt(i)),RWIHi)); 
I did just find the two functions above being explained inside a for loop of

Code: Select all

 for( i = minperiods; i <= maxperiods ; i++ ) 
which would make the first guess of my initial post the correct way, I think.

Then it seems that you converted the code correctly

Re: Clarification regarding Random Walk Index indicator

Posted: Fri Mar 17, 2017 5:35 am
by slava
Ok, thanks mladen!

Re: Clarification regarding Random Walk Index indicator

Posted: Fri Mar 17, 2017 7:29 pm
by mladen
slava wrote:Ok, thanks mladen!
Happy trading :)