Rsi bands for Amibroker (AFL)
zritesh over 12 years ago Amibroker (AFL)
RSI bands provide an intuitive way of visualizing how the price movement causes RSI to move with in its range (0-100). Upper/Lower bands signify overbought and oversold levels respectively (Default: 70/30). These bands closely match what Constance Brown explains in her book “Technical Analysis for the Trading Professional”.
Indicator / Formula
// RSI Bands use a variation of the RSI calculations to figure
// out what price level a stock should be at to be considered
// overbought/oversold.
//
// This sample code was built off the "BuiltInRSIEquivalent"
// sample RSI calculation code found on the AmiBroker website.
function BuiltInRSIEquivalent_RSI_Band_Version( period, TargetRSILevel )
{
P = N = 0;
result = Null;
for( i = 1; i < BarCount; i++ )
{
// Standard RSI code
diff = C[ i ] - C[ i - 1 ];
W = S = 0;
if( diff > 0 ) W = diff;
if( diff < 0 ) S = -diff;
// Compute the hypothetical price close to reach the
// target RSI level based on yesterday's RSI and close
// Depending on whether we would need the price to
// or decrease, we use a different formula
if(result[i-1] > C[i-1])
HypotheticalCloseToMatchRSITarget = C[i-1]+P-P*period-((N*period)-N)
*TargetRSILevel/(TargetRSILevel -100);
else
HypotheticalCloseToMatchRSITarget = C[i-1]-N-P+N*period+P*period+(100*P)
/TargetRSILevel-(100*P*period)/TargetRSILevel ;
// Optional clamping code
// Uncomment this section if parameters used cause
// too much volatility (generally caused by using a very
// short period) This will keep the RSI Bands within
// roughly 10% of the price
// if( (HypotheticalCloseToMatchRSITarget - C[i]) > 0.1*C[i])
// HypotheticalCloseToMatchRSITarget = C[i]*1.1;
// if( (HypotheticalCloseToMatchRSITarget - C[i]) < - 0.1*C[i])
// HypotheticalCloseToMatchRSITarget = C[i]*0.9;
// Resume standard RSI code to update the
// running P and N averages
P = ( ( period -1 ) * P + W ) / period;
N = ( ( period -1 ) * N + S ) / period;
// Store result
if( i >= period )
result[ i ] = HypotheticalCloseToMatchRSITarget ;
}
return result;
}
Plot( BuiltInRSIEquivalent_RSI_Band_Version(14,80), "RSIB80", colorBlue );
Plot( BuiltInRSIEquivalent_RSI_Band_Version(14,20), "RSIB20", colorBlue );
//--François Bertrand0 comments
Leave Comment
Please login here to leave a comment.