Hi All!
Maybe somebody have this afl:
- I suppose price and would like to know RSI for this price.
thnaks ??
Hi All!
Maybe somebody have this afl:
- I suppose price and would like to know RSI for this price.
thnaks ??
There is no prediction in the RSI indicator.
You want the AMI Code for RSI?
I use metastock so cant help with that.
What are you trying to do?
Hi Cor, is this what you're after?
http://mysimplequant.blogspot.com.au...amibroker.html
Hi Tech/a !
Thanks, but I need AFL.
Hi Captain!
Thanks, but this is not what I want.
I would like to find RSI if I supousse Close price tomorrow will be for example 100.
maybe somebody know how to re-coding Captain's link or this :
function BuiltInRSIEquivalent( period )
{
P = N = 0;
result = Null;
for( i = 1; i < BarCount; i++ )
{
diff = C[ i ] - C[ i - 1 ];
W = S = 0;
if( diff > 0 ) W = diff;
if( diff < 0 ) S = -diff;
P = ( ( period -1 ) * P + W ) / period;
N = ( ( period -1 ) * N + S ) / period;
if( i >= period )
result[ i ] = 100 * P / ( P + N );
}
return result;
}
Plot( BuiltInRSIEquivalent( 14 ), "RSI 1", colorRed );
Plot( RSI( 14 ), "RSI 2", colorBlue );
Hi Cor --
You can use root finding techniques to find the price at which some indicator will be at some level on the next bar. I describe the technique and give AmiBroker code in my book "Quantitative Trading Systems." For those of you who have the book, it is Figure 13.13, pages 192 and 193. That example finds the price at which a moving average crossover occurs. You will need to replace the code defining the moving average crossover with whatever code you want for the RSI.
There are limitations using the root finding method. The value sought must be a function of a single variable and must be unique. If your RSI is based on Close, then the first condition is satisfied. But RSI is a bounded indicator. You can find the (only) closing price at which RSI tomorrow will be 10. But if you want to know what price will produce an RSI of 0, any of several prices satisfy the relationship.
The code, as published in QTS, follows:
///////////////////////////
// GenericBinarySearch.afl
//
// This routine uses a binary search to find the
// value that sets the function defined in
// "ZeroToFind" to 0.
//
// Set any global values before the function definition.
//
Length1 = 1;
Length2 = 36;
AccuracyTarget = 0.0001;
function ZeroToFind(P)
// Code whatever you want to find a zero for
// into this function.
// In this example, we are looking for the
// value of a closing price that makes the
// two moving averages, call them MA1 and MA2,
// equal.
// That is, we want MA1 - MA2 to equal 0.
{
FTZ = MA(P,Length1) - MA(P,Length2);
return FTZ;
}
// BC is the index of the final bar in the existing
// array.
BC = LastValue(BarIndex());
// TF is the temporary array used for the
// calculations.
// Extend TF by one artificial value.
// TF does not look into the future,
// this is just a convenient way to put
// the value being tested at the end
// of a known array.
// This code assumes that the variable being
// searched is the Closing price.
// If it is something else, use that
// instead of "C" in the following line.
TF = Ref(C,1);
// Set HGuess to 10 times the previous
// final value.
TF[BC] = HGuess = TF[BC-1] * 10.0;
// Find the sign associated with HGuess.
// It could be either positive or negative,
// depending on the function definition.
// We do not care which, we just remember it.
HSign = IIf(LastValue(ZeroToFind(TF))>0,1,-1);
// Set LGuess to 0.1 times the previous
// final value.
TF[BC] = LGuess = TF[BC-1] * 0.1;
// Find the sign associated with LGuess.
LSign = IIf(LastValue(ZeroToFind(TF))>0,1,-1);
// If the signs are the same, there is no
// zero in between them.
// Set the return value to zero and return.
// Otherwise loop through the binary search.
if (HSign==LSign)
{
HGuess = 0.0;
}
else
{
while(abs(HGuess - LGuess)>AccuracyTarget)
{
MGuess = (HGuess + LGuess)/2;
TF[BC] = MGuess;
MSign = IIf(LastValue(ZeroToFind(TF))>0,1,-1);
HGuess = IIf(HSign == MSign, MGuess,HGuess);
LGuess = IIf(LSign == MSign, MGuess,LGuess);
}
}
// When the loop finishes, HGuess and LGuess
// will be very close together. Either one
// is an acceptable value for our purposes.
Filter = 1; //BarIndex() == BC;
AddColumn(HGuess,"Zero if Close is:",1.9);
//Figure 13.13 Generic Binary Search
//////////////////////////
Readers interested in this thread might be interested in my next book, "Mean Reversion Trading Systems," which will go to the printer in a few weeks.
Regards,
Howard
I think I understand what you're after, it's not really prediction is it? It's just a decision table, at least that's how I do this sort of thing?
For example, if todays close is $50 and I want tomorrows RSI value then an algorithm will feed in a range of tomorrows closing price values between $45 and $55 and generate a table of RSI values based on those potential closing price values. So I don't have a "prediction", but I know 1 day in advance exactly what to do for any given closing price.
Is that what you mean?
Disclosure: Long cash, gold, stocks.
Hi Sinner --
It is not clear which posting you are referring to. I'll answer as if it is mine.
The code I posted does not predict a price -- it calculates the price at which some condition will be true.
Howard
Dear Sinner, Dear Howard,
Thank you for your interest, but I need easier way
Hi,
Several years ago, there were some posts about "reverse engineering" the RSI. I believe the AFL-file can be found via the AB website --- perhaps the members area (TASC articles).
Hi Ruth --
It is easy to reverse engineer some indicators -- the crossover of two simple moving averages, for example. Others are much more difficult -- such as those that depend on more than one input variable, and those that have unusual calculations.
RSI is of medium difficulty. It accepts a single array argument, usually the closing price series, and a single numeric argument, the "length" of the lookback. The reverse calculation for RSI is made complex by the separation of winning and losing days into two series, each is smoothed using the Wilder moving average, before being combined into the RSI value. Wilder moving average uses precisely the same algorithm as exponential moving average, but the lookback parameter is scaled differently. A wilder moving average of length n is identical to an exponential moving average of length (2n-1).
The combination of the ratio of up days to down days is given by a unnecessarily obscure algebraic formula. After a few simple manipulations, it reduces to:
RSI = (100 * ups)/(ups + downs)
where ups is the smoothed winning series and downs is the smoothed losing series.
Really, it is much easier to use the root finding method I posted. That works for any function that:
1. depends on one array argument.
2. has a unique solution.
Note that whether the RSI is reverse engineered or root-found, it is important to search for an RSI value that is unique. Since RSI is a bounded indicator, many closing prices map to RSI == 0 and RSI == 100, and any reverse process fails to find a unique closing price that produces those boundary RSI values. Fortunately, any RSI value between 1 and 99 does correspond to a unique new closing price.
I hope this helps.
Regards,
Howard
Bookmarks