Announcement

Collapse
No announcement yet.

Passing Array as a Source for RSI function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing Array as a Source for RSI function

    The built-in RSI function accepts open, close, high, low, etc., and combinations therein, as "sources" for the function. Is there a way to pass something a little "less uniform" as the source for the RSI function to operate on?... specifcially, I would like to pass (as "source" for the RSI function) an array of, say, 20 values, where that array is built up of the "low" of the current bar and the "close" of the prior 19 bars.
    In simple terms, I would think some kind of code like this would work (but it crashes).

    // First define an array of 20 positions
    var MyArray = new Array(20);

    // Fill positions 0 through -19 with "close" values
    MyArray = close (0,-19);

    // Over-write position "0" with the "Low" value of the current bar
    MyArray(0) = low(0);

    // Now pass MyArraw as "source" to the RSI function, so that can be plotted.
    MyRSI = new RSIStudy(Length, MyArray);
    Last edited by fish7; 04-23-2006, 07:45 PM.

  • #2
    fish7
    You can pass virtually any custom source to the EFS2 builtin RSI study (and to most of the other EFS2 builtin studies) however this needs to be a series. To do this you need to calculate your source in a separate function or efs and then call it using either the efsInternal() or efsExternal() functions which will create the required series.
    Having said this even if you were to return an array in a separate function or efs the efsInternal() and efsExternal() functions will use only the first element of the array so in your specific example you would end up essentially with an RSI of the Low ie of MyArray[0]
    With regards to your sample code MyArray(0) = low(0) is incorrect and should be written as MyArray[0] = low(0). Also if you want to be able to use custom variables with the builtin studies you will need to use the EFS2 versions of those studies so the syntax for the RSI function should be rsi() and not RSIStudy()
    Alex

    Comment


    • #3
      Show-stopper

      Alex,

      Thanks for that very informative, and complete, reply.
      your insight that I would only end up with the RSI of the LOWs is a show-stopper for me -- that's not what I want to do.
      The reason I want to make this, is because, during the day, as price wiggles around, on a daily chart, the rsi wiggles around some range of values -- it is not stationary at the close value, until the mkts close for that day, of course. I want to put some kind of "whisker and tail" (like you have on price bars) on the RSI for each day (or, perhaps a channel around the RSI), showing what the range of its movement was realized for every day.
      In theory, those "whiskers" or "tails" would be captured by using the High or the Low of the zero'th bar, but the close of all prior bars, for every day in the sequence. Hence my figuring that I only needed to pass a custom-made series that consists of the close values, except for the zero-th position, which would have either a low or a high value.
      I'm stumped as to if there is any way to do what I want to do. If you have any suggestions on how it might be achieved, I'd really appreciate it. If it's simply not possible, then, I guess, I will just have to wait until some future date when the technology allows me to do it.
      Thanks, again, for all your help.

      Comment


      • #4
        fish7
        If I understood you correctly you are trying to plot the intrabar excursion of the RSI
        That can easily be done without the need of arrays in which the 0 element is the RSI of the Low or High . Actually if you did that you would probably get incorrect results because the value of the RSI based on the Low is not necessarily the same as the lowest value recorded intrabar by the RSI of the Close.
        Anyhow you can compute the excursion only in real time because on historical bars you have a single data point only and you have no knowledge of what the intrabar excursion (or wiggle to use your definition) was.
        To accomplish what you want create three global variables called for example study, studyH and studyL and set them initally to null. Then in main intialize your study as you would normally ie
        PHP Code:
        if(study==nullstudy rsi(10); 
        Then you need to create a condition that at every new bar will reset the values of studyH and studyL to the value of the RSI study at the beginning of the bar
        PHP Code:
        if(getBarState()==BARSTATE_NEWBAR){
            
        studyH study.getValue(0);
            
        studyL study.getValue(0);

        At that point you can start calculating the excursion by using the Math.max() and Math.min() functions and assigning the results to studyH and studyL
        PHP Code:
        studyH Math.max(studyH,study.getValue(0));
        studyL Math.min(studyL,study.getValue(0)); 
        Lastly use drawLineRelative() to draw the excursion. The start/end coordinates of the line are studyH and studyL
        PHP Code:
        drawLineRelative(0studyH0studyLPS_SOLID,2Color.red"line"+getCurrentBarCount()) 
        In the image enclosed below you can see the result when the script is running in real time. The vertical red line represents the range of the RSI during each bar
        Alex

        Comment

        Working...
        X