Announcement

Collapse
No announcement yet.

Why won't this work

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

  • Why won't this work

    Can anyone tell me why this doesn’t return the high-low? It currently returns nothing? If I make xADR=vHigh I get the high displayed. If I make xADR=vLow the low is displated. But if I do vHigh-vLow I get nothing!

    function main(Length,Source,Symbol,Interval,Upper,Lower,Par ams) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    var vHigh = high(vSymbol);
    var vLow = low(vSymbol);
    xADR = vHigh-vLow;
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    return getSeries(xADR);
    }

    Any ideas?

    I'm trying to work out the daily range i.e. each day's high-low and then I want to work out a moving average of that range. Please help!!

  • #2
    Re: Why won't this work

    BerkoBob
    There are a number of reasons why it is not working.
    The first one is that you are declaring your vHigh and vLow as local variables inside the bInit routine which means that they will be calculated once only when that routine is executed for the first time. These should instead be global variables so that they persist on subsequent iterations of the efs
    Also if your intention is to base these values on external symbols and/or intervals then you are using the incorrect syntax. For the syntax required by these functions and examples on their usage see this and this article in the EFS KnowledgeBase
    The second problem is that you are calculating the xADR within that same routine so as per the above reason this is done only once. Also any expressions calculated using a series will not return a series but a value so you will not be able to then calculate a moving average of it using the efs2 moving average functions
    Lastly you are using the getSeries() function in your return statement to retrieve xADR which is not a series
    See the example posted in this thread on how to calculate the range and also base it on an external symbol and./or interval
    Also try searching the forums for keywords such as daily range and you will find many examples as this has been covered at length before
    Alex


    Originally posted by BerkoBob
    Can anyone tell me why this doesn’t return the high-low? It currently returns nothing? If I make xADR=vHigh I get the high displayed. If I make xADR=vLow the low is displated. But if I do vHigh-vLow I get nothing!

    function main(Length,Source,Symbol,Interval,Upper,Lower,Par ams) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    var vHigh = high(vSymbol);
    var vLow = low(vSymbol);
    xADR = vHigh-vLow;
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    return getSeries(xADR);
    }

    Any ideas?

    I'm trying to work out the daily range i.e. each day's high-low and then I want to work out a moving average of that range. Please help!!

    Comment


    • #3
      Thank you and...

      Thank you so much for taking the time to help me out. I really apprecaite it.

      I have modified the code as per your instructions as follows:

      function main() {
      var vDR = efsInternal("DailyRange");
      return ema(7, vDR);
      }

      function DailyRange() {

      // Returns the daily range
      return (high(inv("D"))-low(inv("D")));

      I really don't understand why I need a separate function to calculate the range but it works.

      On a daily chart (and it's only the average daily range I am interested in) I get sensible results but on an intra-day chart the results don't look right. From the code fragment above, can you tell why it isn't working properly intra-day?

      Again, thank you very much.

      Comment


      • #4
        Re: Thank you and...

        BerkoBob
        You are not running the DailyRange function in the context of the external interval but in that of the chart’s interval which then causes the average to be calculated on each bar of the chart's interval values rather than on the daily interval.
        As I show in the example I linked to my previous reply you need to pass the desired interval as the last parameter of the efsInternal() or efsExternal() call. This will create the proper synchronization between intervals
        In the case of your script just calculate the difference between the values of the high(0) and low(0) in the DailyRange function and then pass the interval [through the efsInternal() call] to the DailyRange function using the the inv() function. For the complete description, syntax and examples of the usage of the inv() function see this article in the EFS KnowledgeBase
        Again please reference the example I indicated
        Alex


        Originally posted by BerkoBob
        Thank you so much for taking the time to help me out. I really apprecaite it.

        I have modified the code as per your instructions as follows:

        function main() {
        var vDR = efsInternal("DailyRange");
        return ema(7, vDR);
        }

        function DailyRange() {

        // Returns the daily range
        return (high(inv("D"))-low(inv("D")));

        I really don't understand why I need a separate function to calculate the range but it works.

        On a daily chart (and it's only the average daily range I am interested in) I get sensible results but on an intra-day chart the results don't look right. From the code fragment above, can you tell why it isn't working properly intra-day?

        Again, thank you very much.

        Comment


        • #5
          Hello Alex,

          It works! I have no idea why, but it works. Thank you!

          Here is the code:

          function main() {
          var vDR = efsInternal("DailyRange",inv("D"));
          return ema(7, vDR);
          }

          function DailyRange(interval) {

          // Returns the daily range
          return (high(0)-low(0));

          }

          I don't understand how you can pass a function a parameter that it doesn't reference yet it affects the result.

          I notice in your code that you have a preMain routine and you sometimes also have code within main than only runs once. What's the difference between the two?

          Last question, can I display the value of vADR(0) somewhere on the chart other than the quote window such as within the study title?

          Again, thank for you help.

          Comment


          • #6
            BerkoBob

            I notice in your code that you have a preMain routine and you sometimes also have code within main than only runs once. What's the difference between the two?
            Broadly speaking there is no difference in as much as both will run only once when a script is first loaded [or reloaded].
            That said many [if not most] functions can only be used in main() hence the need to have some routine to initialize them once only. Equally there are some functions that can only be used in preMain()
            For the basic differences between main() and preMain() you may want to review the Beginners Tutorials that are provided in the Help Guides and Tutorials folder of the EFS KnowledgeBase

            I don't understand how you can pass a function a parameter that it doesn't reference yet it affects the result.
            That is a feature specific to the efsInternal() and efsExternal() functions where they control the context in which the called function is running if the inv() or sym() are passed as the last parameter without necessarily including that parameter in the arguments of the called function [or efs]

            Last question, can I display the value of vADR(0) somewhere on the chart other than the quote window such as within the study title?
            You can do that using the drawTextXxx() functions. See the EFS KnowledgeBase for the list of available functions and their syntax
            Alex


            Originally posted by BerkoBob
            Hello Alex,

            It works! I have no idea why, but it works. Thank you!

            Here is the code:

            function main() {
            var vDR = efsInternal("DailyRange",inv("D"));
            return ema(7, vDR);
            }

            function DailyRange(interval) {

            // Returns the daily range
            return (high(0)-low(0));

            }

            I don't understand how you can pass a function a parameter that it doesn't reference yet it affects the result.

            I notice in your code that you have a preMain routine and you sometimes also have code within main than only runs once. What's the difference between the two?

            Last question, can I display the value of vADR(0) somewhere on the chart other than the quote window such as within the study title?

            Again, thank for you help.

            Comment


            • #7
              I've done it (with a little help from Alex)!

              Alex,

              Again, thank you very much.

              I found the efs knowledge base MUCH harder to find than you may think as there are a number of broken links along the way. Even when I did find it I couldn't bookmark it because my session details were mangled into the URL. If anyone else is reading this then you can find the knowledge base here: http://www.esignalcentral.com/support/kb/efs/

              Now that I have found it I have managed to answer my remaining questions so, once again, thanks for your help.

              Comment


              • #8
                Re: I've done it (with a little help from Alex)!

                BerkoBob
                FWIW you can easily access the EFS KnowledgeBase by clicking on the yellow question mark in the EFS Editor
                Also if you select Support-> Product Support-> eSignal from the main menu of eSignal's site available at the top of the forum you will be taken to a page which provides links to the EFS KB, EFS library, Tutorials, etc
                Alex


                Originally posted by BerkoBob
                Alex,

                Again, thank you very much.

                I found the efs knowledge base MUCH harder to find than you may think as there are a number of broken links along the way. Even when I did find it I couldn't bookmark it because my session details were mangled into the URL. If anyone else is reading this then you can find the knowledge base here: http://www.esignalcentral.com/support/kb/efs/

                Now that I have found it I have managed to answer my remaining questions so, once again, thanks for your help.

                Comment

                Working...
                X