Announcement

Collapse
No announcement yet.

Testing on real time RSI values

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

  • Testing on real time RSI values

    Hi,

    I wonder if anyone can help me with the attached efs. I am trying to read rsi values into an array and then test these values for further processing. In the example efs, I am simply drawing labels to previous bars and returning the values of the array to the Formula Outut window.

    What I find is that when I first load the efs into a chart, everything lines up nicely. But the I get different rsi values when applying on a live real time chart e.g. one-minute.

    Thanks.
    Hamid.
    Attached Files

  • #2
    Hamid
    The reason that is happening in real time is because you are retrieving (and storing in the array) the current value of the RSI on the first tick of each new bar. However that bar is yet incomplete and the value of the RSI will be different once that bar is completed. When you then reload the efs the script is instead looking at completed bars hence the discrepancy.
    To correct this issue you need to replace var nRSI = study.getValue(0); with var nRSI = study.getValue(-1);
    You also need to replace low(0) and high(0) with low(-1) and high(-1) in the drawTextRelative() commands
    That said you do not need to use an array to retrieve prior values of the RSI. You can do that using the getValue(-n) method where n is the bar index [ie x.getValue(-1) is the prior bar , x.getValue(-2) is two bars back, etc]
    Alex

    Comment


    • #3
      Hi Alex,

      Thank you very much for the prompt response. I did as you suggested, and it works like a dream.

      I figured the problem revolved around reading the first tick of the new bar, but just could not find a workaround. I think I may have tried the getValue(-n) along the way but I may have made some other errors that prevented me getting the desired results.

      I also noted the redundancy of maintaining the array and have eliminate that part of the code.

      Thanks again. I have only just begun coding efs and your posts in this forum have been a tremendous help.

      Regards,
      Hamid.

      Comment


      • #4
        Hamid
        You are most welcome
        Alex

        Comment


        • #5
          Alex,

          As a follow-up question, what is the difference between these two statements:

          study = new RSIStudy(7, "Close");
          study = rsi(7, "Close");

          In an earlier version of my efs, I was using the first statement and could not use the getValue(-n) to work.

          Thanks again.
          Hamid.

          Comment


          • #6
            Hamid
            The first one is the EFS1 function for the RSI while the second one is the EFS2 function for the same study. However the syntax you used in the second example is incorrect and should be
            PHP Code:
            var study rsi(7close()); 
            For the syntax and examples of the EFS2 functions you may want to go through the Function Reference folder in the EFS KnowledgeBase
            With the EFS1 functions the method to retrieve the value is slightly different. In the case of your example you would use
            PHP Code:
            var study = new RSIStudy(7"Close");
             
            function 
            main(){
             
                var 
            CurrRSI study.getValue(RSIStudy.RSI0);//value of the RSI study on current bar
                
            var PrevRSI study.getValue(RSIStudy.RSI, -1);//value of RSI at prior bar
                //etc 
            For examples of the syntax required with the EFS1 built-in studies see the scripts contained in the Builtin folder of Formulas
            Alex

            Comment


            • #7
              Alex,

              Thank you again.

              I see now that I got the first statement (study = new RSIStudy(7, "Close") from an older post in the forum as I was searching for code on rsi.

              I will be sure to check out the syntax for all EFS2 functions. Although I note that I used an incorrect syntax in that second satement, it is strange that it worked anyway. But I will change to the correct syntax, so as to get into the habit.

              Regards,
              Hamid.

              Comment


              • #8
                Hamid
                The reason it works is because the EFS2 engine ignores that parameter since it is not in the format it expects for the source and uses the default data series which is close(). In fact you could also write your function as follows and it will return the same result
                PHP Code:
                var study rsi(7);//since no source parameter is passed the function uses its default ie close() 
                You may also want to see the EFS2 syntax examples which I posted here
                Alex

                Comment


                • #9
                  Alex,

                  Okay, I see now. Thanks for the explanations.

                  I have printed saved the EFS2 syntax eamples you provided and they will definitely help in my further education.

                  Thank you and have a great weekend.
                  Hamid.

                  Comment

                  Working...
                  X