[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Predicted Close for RSI crossover



PureBytes Links

Trading Reference Links

The function is good. Thanks a lot. I add another code line for plotting:
Plot(nextClose,"Predicted Close",colorBlack,styleOwnScale);
The result is just a line with one value: the last nextClose. Can it be plot a chart with all values for all data?

gp_sydney <gp.investment@xxxxxxxxx> wrote:
The maths is a bit involved to show you how to calculate it, but
here's a function that does the job:

Function NextRSI(bar, period, nextClose, nrsi)
{
if (bar >= period+1) {
clb = Close[bar];
if (clb == Close[bar-1])
Close[bar] = Close[bar] + 0.0001; // To avoid "0/0" term
rsiArr = RSI(period);
rval = 0;
rs = 100 / (100 - rsiArr[bar]) - 1;
rsp = 100 / (100 - rsiArr[bar-1]) - 1;
cgn = Close[bar] - Close[bar-1];
cls = -cgn;
if (cgn < 0)
cgn = 0;
if (cls < 0)
cls = 0;
alp = 0;
if (rsp - rs)
alp = (cls * rs - cgn) / ((period-1)*(rsp - rs));
agp = rsp * alp;
als = (alp * (period-1) + cls) / period;
agn = (agp * (period-1) + cgn) / period;
if (nextClose >= 0) {
cgn = nextClose - Close[bar];
cls = -cgn;
if (cgn < 0)
cgn = 0;
if (cls < 0)
cls = 0;
rsx = (agn * (period-1) + cgn) / (als * (period-1) + cls);
rval = 100 - (100 / (1+rsx));
}
else {
rsn = 100 / (100 - nrsi) - 1;
if (nrsi < rsiArr[bar])
rval = Close[bar] - (agn * (period-1)) / rsn + als *
(period-1);
else
rval = Close[bar] + als * (period-1) * rsn - agn *
(period-1);
}
Close[bar] = clb; // Restore close array
}
return rval;
}

In this function, "bar" is the index of the bar before the one you
want to calculate (BarCount-1 to calculate for tomorrow's bar),
"period" is the RSI period, "nextClose" is either the next close value
if you want to work out the next RSI value for that close or -1 if you
want to solve for the next close, and "nrsi" is anything to calculate
the next RSI or the desired RSI value to calculate the next close to
give that RSI. Note that it will only work when "bar" is at least the
period plus two bars.

As an example, to calculate tomorrow's close to give an RSI(14) of 25%:

nextClose = NextRSI(BarCount-1, 14, -1, 25);

or to calculate tomorrow's RSI for a close of $1.20:

nrsi = NextRSI(BarCount-1, 14, 1.20, -1);

Note that the function needs a change in the close to calculate the
average loss and gain figures needed to iterate forward. If the close
at "bar" is the same as the close at "bar-1" then it's impossible to
calculate those averages, so the function modifies the Close[bar]
value fractionally to avoid the problem (the difference is not usually
noticeable).

Regards,
GP

--- In amibroker@xxxxxxxxxps.com, "amon_gizeh" <amon_gizeh@...> wrote:
>
> Hello.
> I try to calculate what value for tommorow Close will make a crossover
> with line 25 (oversold level) or line 75 (overbought level). Can
> somebody help me?
> Thanks.
>


__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___