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