Skip to main content

RSI Closing value by Alvarez for Amibroker (AFL)

c62 over 6 years ago Amibroker (AFL)

  • Rating:
    5 / 5 (Votes 1)
  • Tags:
    amibroker, oscillator, rsi

Determines the closing value of a stock need to reach a particular RSI value
function ReverseRSI(nLen, rsiTarget)

Indicator / Formula

Copy & Paste Friendly
// Provided as is by www.AlvarezQuantTrading.com 

///////////////////  Reverse RSI Calculator  ////////////////////////
// Determines the closing value of a stock need to reach a particular RSI value
function ReverseRSI(nLen, rsiTarget)
{
	gain = Max(C-Ref(C,-1), 0);     
	loss = -Min(C-Ref(C,-1), 0);
	
	rsGain = IIf(BarIndex() < nLen-1,Null,   
				IIf(BarIndex()==nLen-1, MA(gain, nLen), gain));
	rsLoss = IIf(BarIndex() < nLen-1,Null,  
				IIf(BarIndex()==nLen-1, MA(Loss,nLen), Loss));
				
	rsGain = AMA(rsGain, 1/nLen); 
	rsLoss = AMA(rsLoss, 1/nLen);  
	
	RSIcalc = IIf(BarIndex()<nLen-1, Null, 100*rsGain/(rsGain+rsLoss));

	targetPrice = IIf( (rsiTarget < RSI(nLen)),
						C-100*(((nLen-1)*rsGain)/rsiTarget)+((nLen-1)*rsGain)+((nLen-1)*rsLoss),
						C+((rsiTarget/(100-rsiTarget)*((nLen-1)*rsLoss))-((nLen-1)*rsGain)) 
					 );
					 
	return targetPrice;
}
 
	
Filter = TRUE ;
AddColumn(C,"Close");
AddColumn(RSI(2), "RSI2");
AddColumn(ReverseRSI(2, 30),"RSI30-Next Day Price",1.3);
AddColumn(ReverseRSI(2, 70),"RSI70-Next Day Price",1.3);

4 comments

about 6 years ago

Hello c62
This AFL shows nothing. All blank.
Would you please tell how to use it.
Thanks.

3. ujjwal
about 6 years ago

hey man thanks for the code.. can you guide me how to plot the rsi using this formula and can we apply the range of rsi here ?

Leave Comment

Please login here to leave a comment.