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:
// 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;
// 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,
// That is, we want MA1 - MA2 to equal 0.
FTZ = MA(P,Length1) - MA(P,Length2);
// BC is the index of the final bar in the existing
BC = LastValue(BarIndex());
// TF is the temporary array used for the
// 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.
HGuess = 0.0;
while(abs(HGuess - LGuess)>AccuracyTarget)
MGuess = (HGuess + LGuess)/2;
TF[BC] = MGuess;
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.
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.