iBankCoin
Joined Nov 11, 2007
1,458 Blog Posts

PercentRank Function for AmiBroker

Friend of the blog, Ramon Cummins has graciously agreed to share his PercentRank function for AmiBroker language. This is a really useful function. It returns the rank of a value in a set of values as a percentage of the set. In other words, if an indicator produces a raw value, this function allows one to rank the raw value as a percentage of previous values.

//PercentRank Function
//As Coded by Ramon Cummins
function PercentRank( Data, Periods )
{
Count = 0;
for ( i = 1; i < Periods + 1 ; i++ )
{
Count = Count + IIf ( Ref( Data, 0 ) > Ref( Data, -i ), 1, 0 );
}
return 100 * Count / Periods;
}

//Now, lets use the function to rank  Average True Range in percentage terms relative to previous ATRs.
//Define ATR as a percentage
ATR_Percentage=(ATR(10)/C)*100;
//Here we define the lookback period (30 days) to compare current to previous ATR%
RankPeriods = Param( “PercentRank Lookback Periods”, 30,5,252,5 );
//Here we use the PercentRank function to rank the ATR% relative to previous ATR%s
ATR_Bounded = PercentRank( ATR_Percentage, RankPeriods );
if ( ParamToggle( “Show ATR_Bounded”, “No|Yes”, 1 ) == 1  )
{
Plot( ATR_Bounded, _DEFAULT_NAME(), ParamColor( “Color”, colorCycle ), ParamStyle( “Style” ) );
}

And below is a screenshot showing the ATR_Bounded applied to the Qs.
atr_bounded_percentrank-function

If you enjoy the content at iBankCoin, please follow us on Twitter

3 comments

  1. bhh

    sweet

    • 0
    • 0
    • 0 Deem this to be "Fake News"
  2. bill

    thanks a lot , really appreciate that.

    Woody,

    have u thought about improving power dip based on fundamental screening/ranking.

    • 0
    • 0
    • 0 Deem this to be "Fake News"
    • Woodshedder

      Bill, yes, re:fundamentals.

      You should be hearing something about this very soon.

      I told you the PercentRank function was easy…:)

      • 0
      • 0
      • 0 Deem this to be "Fake News"