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

[amibroker] Re: Predicted Close for RSI crossover



PureBytes Links

Trading Reference Links

Are you saying you want the Close value at every bar that would make
the RSI 25% (or whatever) on that bar?

You could do that in a loop by calling this function for every bar,
but it might be a bit slow (make the RSI array calculation external,
so that it's not repeated at every bar). Alternatively calculate the
whole RSI array yourself in a loop, using the last part of the
function to calculate the required closes at each bar (that would save
having to calculate the average gain and loss at every bar, since
those values would be tracked in variables from the first bar).

Try just calling the function in a loop first, after making the RSI
array calculation external, and see if that's fast enough (to make the
RSI calculation external, move the statement "rsiArr = RSI(period);"
back into the main code and make the variable "rsiArr" global).
Iterate the loop from period+1 to BarCount-1.

One small thing in that function too is that the statement "rval = 0"
should be the very first statement, before the "if" statement.

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, Amon Ra <amon_gizeh@xxx> wrote:
>
> 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@xxx> 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@xxxxxxxxxxxxxxx, "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
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/