Announcement

Collapse
No announcement yet.

xRSI = rsi( 14, inv(5)) returns wrong? values in real-time or tick-replay mode

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

  • xRSI = rsi( 14, inv(5)) returns wrong? values in real-time or tick-replay mode

    I hope I'm missing something because I'd really like to get this to work such that my 1min and 5min charts return matching rsi values.

    When I first load or re-load my efs study on a 1min chart, the following (edited) code snippet:

    if( bInit == false ) {
    xRSI = rsi( 14, inv( 5 ));
    bInit = true;
    }

    nRSI = xRSI.getValue(0);

    returns rsi values which correspond exactly to those on a 5min chart which uses a simple rsi(14) with no inv() function.

    That is to say that the xRSI = rsi( 14, inv(5)) function on the 1 min chart returns a constant RSI across each group of 5 bars; and this value exactly matches the single corresponding rsi value on the 5min chart. Sounds right to me.

    So far, so good, but when I then run this same pair of charts in real-time or tick replay mode then the 1min chart's rsi( 14, inv(5)) function begins to do two things I don't understand.

    1) It begins to plot an rsi which changes each bar instead of every 5 bars. (If I then reload the 1min chart these new rsi values clean up like those from before the chart was last reloaded.)

    2) None of the bars have an rsi which matches the rsi of the 5min chart.

    I think I can code around (1) using a global value (declared outside main & pre-main) for nRSI and controlling when I update it.

    But (2) has me stuck completely since it never returns an nRSI value which matches the 5min chart.

    Help is much appreciated, thanks.

  • #2
    twasson
    What you are seeing happens because you are returning a value ie xRSI.getValue(0). For a detailed description of this you may want to read this post.
    If you want the formula engine to maintain the plot synchronized in real time across all the lower interval bars that make up the higher interval then you need to return the series ie nRSI = getSeries(xRSI);
    Alex

    Comment


    • #3
      Hi Alex,

      Using the getSeries() function indeed cleared up what I was seeing in real-time and tick-replay.

      Thank you!

      If I may post a follow on question, how can I access the previous RSI value so I can do colorization based on increasing and decreasing RSI? Again, this is on a 1min chart which is plotting 5min RSI values.

      This much works (based on your suggestion):
      if ( nState == BARSTATE_NEWBAR ) {
      nRSI = getSeries( xRSI, 0 );
      }

      but using a non-zero offset like -1 or -5 returns a null value.
      i.e.
      nRSIp1 = getSeries( xRSI, -5 );
      --- returns null

      Comment


      • #4
        Oops. I see your correct first name is Alexis, not Alex.
        My apologies.

        Comment


        • #5
          twasson
          To retrieve a value from a series you use the .getValue() method specifying the bar index you want to reference.
          For example to retrieve the value of the RSI at the current bar you would use nRSIp0 = nRSI.getValue(0). For the value at the prior bar you would use [i]nRSIp1 = nRSI.getValue(-1), for two bars ago it will be nRSIp2 = nRSI.getValue(-2) etc. You then use these values in the conditions that color the plot of the RSI.
          Note that if these conditions reference in real time the current value of a study which is based on an external interval then you will need to maintain the synchronization of the colors and/or graphic objects yourself (the reason for this is explained in the thread I linked in my prior reply)
          For an example of how to do this complete with detailed comments and explanations see the efs attached to this post. You may also want to review the two posts that follow that one for examples on how to paint the background or apply and color graphic objects.
          If instead the conditions are based solely on completed bars of the external interval then you can apply colors and/or graphic objects as you would under normal conditions because those values remain constant.
          Alex

          PS. No apology necessary regarding my name since I sign myself as Alex in the first place. Thank you never the less.

          Comment


          • #6
            Hi Alex,

            I've applied your suggestions and my studies now plot correct colors when I use inv() in tick replay mode. For instance, I can plot and colorize a 15min RSI or MACD and plot it on a 1min chart.

            Thank you for the assistance.

            I now have only one remaining study that has issues with tick replay, and could use a little more help.

            My goal is to draw each previous day's OHLC levels on each current day's chart.
            My efs draws no lines in tick replay mode, but works otherwise (including real-time, as I recall).

            Using a 15min chart, I get null values for (for instance) yOpen_1 in the following code fragments:

            if ( yOpen ==null) yOpen = open( inv( "D" )); // initialize the study

            if ( getBarState() == BARSTATE_NEWBAR ) { // skip ticks

            if ( getDay(0) != yesterday ) { // find the first bar of the day
            var yOpen_1 = yOpen.getValue( -1); // yesterday's open
            yesterday = getDay(0);
            }
            }

            ------------------------
            I also investigated the OHLC.efs file located at:
            FileShare of Alexis C. Montenegro/ Formulas/ Formulas-EFS2

            but discovered that this file also does not plot in tick replay, though is it overall more sophisticated than mine, and I learned a few things by examining it. (FYI, I set Lookback to 1 to emulate my file.)

            Thanks again for taking a look.

            - Tim

            Comment


            • #7
              Tim
              Daily (or higher) bars are not available in Tick Replay.
              This is one of the reasons why I wrote the prevday-ohlc.efs and pivotpoints.efs posted in this thread which will compute the previous day's OHLC and pivots using only the data plotted in the chart .
              Alex

              Comment


              • #8
                Thanks again, Alex.

                I've already started to morph prevday-ohlc.efs into what I need. Things are looking up!

                - Tim

                Comment


                • #9
                  Tim
                  You are most welcome.
                  I should clarify that when I said that the daily bars are not available in Tick Replay I was referring to the symbol $PLAYBACK. You can access the daily bars of any symbol (even in Tick Replay) by calling it with the sym() function,
                  For example if you were running the data for ES #F in Tick Replay and you wanted to plot the daily Open then you could call it with the following command
                  var OpenD = open(sym("ES #F,D"));
                  This will retrieve the daily data for the specific symbol and will synchronize it to the data being plotted in Tick Replay
                  As an example see the following image. In the main chart I am plotting an old Tick Replay file for IBM and using the pivotpointsall2.efs which is posted here This efs allows you to base the pivots on a symbol that is different from the one being charted and in this case I input IBM as the symbol. As you can see the formula calculates the pivots based on the daily data for that symbol which it retrieves directly from the servers. To confirm this I added the same formula to a daily chart for IBM which is shown in the inset chart
                  Alex

                  Comment

                  Working...
                  X