Hello Everyone,
Old wine (question) in new bottle (forum).
Puns apart, we have three inbuilt functions in this regard:
Objective is to replicate the inbuilt functions, to be able to experiment with other price-derived arrays instead of using the default Highs and Lows. Interestingly, a similar request was posted a decade back - Random Walk Index -- raw AFL code request. And feel the same way as asked here RWIHI question.
Let me show you what I have done to unveil RwIHI() function but the values do not match with the inbuilt one.
Inbuilt RwIHI():
minperiods = Param( "Min Periods", 9, 1, 200, 1 );
maxperiods = Param( "Max Periods", 40, 1, 200, 1 );
Plot( RwIHI( minperiods, maxperiods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
Custom raw RWH:
_SECTION_BEGIN( "Unveil RWIHi()" );
mthd = ParamList( "Select Method", "Method 1|Method 2", 0 );
pMin = Param( "Min Periods", 9, 1, 200, 1 );
pMax = Param( "Max Periods", 40, 1, 200, 1 );
switch( mthd )
{
case "Method 1":
// https://www.mail-archive.com/amibroker@yahoogroups.com/msg30080.html
RWHmin = ( H - Ref( L, -pMin ) ) / ( Max( ATR( 1 ), ATR( pMin ) ) * sqrt( pMin ) );
RWHmax = ( H - Ref( L, -pMax ) ) / ( Max( ATR( 1 ), ATR( pMax ) ) * sqrt( pMax ) );
RWH = Max( RWHmin, RWHmax );
break;
case "Method 2":
// http://www.amibroker.com/members/library/detail.php?id=924&hilite=RWIHi
VarMaxHi = 0;
for( i = 5; i <= BarCount - 1; i++ )
{
VarMaxHi[ i ] = Max( ( H[ i ] - L[ i - 1 ] ) / ( ( H[ i ] - L[ i ] ) * sqrt( i - 4 ) ), ( H[ i ] - L[ i - 2 ] ) / ( ( H[ i ] - L[ i ] ) * sqrt( i - 3 ) ) );
RWH[ i ] = Max( VarMaxHi[ i ], VarMaxHi[ i - 1 ] );
}
break;
}
Title = "RWH: " + RWH;
Plot( RWH, "RWH", ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();