Announcement

Collapse
No announcement yet.

Historical values of an Indicator

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

  • Historical values of an Indicator

    I have written a LoLag Moving Average Indicator LLMA that uses your BuiltIn MAStudy , both vMA and vMAofMA.

    I would like to retrieve the value of my LLMA from a few days ago. After some searching I thought that the "offset" parameter in MAStudy would do it. It seems to work correctly on previous bars, but returns 'null' for current ticks on every other tick - or something like that - in-other-words it doesn't seem to work right.

    QUESTION #1:
    How do you retrieve historical values of your built-in studies or custom written studies?

    On a similar topic, when I'm backtesting an indicator I want to bring in - say 10 years of daily SPY data. I drag and drag the chart back, but a fairly large fraction of the time, eSig 7.5 stops responding 'Not responding', and I have to re-start everything.

    QUESTION #2:
    How do I tell eSig 7.5 that I want to retrieve a certain number of bars?

    PS:
    I routinely specify starting and ending dates in the MetaStock Downloader, so I know there must be some command to request a certain number of bars.

    Ed Hoopes
    [email protected]
    #549584

  • #2
    Ed

    #1 It depends. With the builtin studies you can use the following syntax
    vMA.getValue(MAStudy.MA,-nn)
    where -nn is the number of bars back
    With non builtin studies you need to create an array or use ref().

    #2 To bring in the desired amount of data create a Time Template, set the Type to User Defined then D (for Daily) as the Interval and insert the desired number of Days/Bars (approximately 2200 bars for 10 years)

    Alex

    Comment


    • #3
      Historical values of an Indicator

      Alex,

      As you can see below I put the # of bars in as you said, but I got

      "Eds Formulas/AMA-LLMA.ers, linee 38; TypeError
      vMA.getValue(MAStudy.MA, -7) has no properties."

      error returned

      Ed Hoopes

      **********************


      function main(MA1Length, vPers, MA2Length) {

      if (vMA == null) vMA = new MAStudy(MA1Length, 0, "close", MAStudy.EXPONENTIAL);

      if (vMA == null) vMAofMA = new MAStudy(MA2Length, 0, vMA, MAStudy.MA, MAStudy.SIMPLE);

      debugPrintln("vMA = " + vMA.getValue(MAStudy.MA) + "\n");
      // debugPrintln("vMAofMA = " + vMAofMA.getValue(MAStudy.MA) + "\n");
      ******==> vMADiff = vMA.getValue(MAStudy.MA,-07) - vMAofMA.getValue(MAStudy.MA);

      vLoLagPrev = vMA.getValue(MAStudy.MA) + vMADiff;

      //debugPrintln("vLoLagPrev = " + vLoLagPrev + "\n");

      return vLoLagPrev;

      Comment


      • #4
        Hello Ed,

        The main thing missing from your code is a null check for vMA.getValue(MAStudy.MA, -07). The formula starts executing at the oldest bar in the chart. On the first execution of the formula, the study value for -07 bars prior to the oldest bar does not exist yet. Therefore, the getValue statement returns null. It's a good habit to perform null checks like in the example code below to avoid the error you are getting. Incorporate the code below into your formula and you should be good to go.

        PHP Code:
        function main(MA1LengthvPersMA2Length) {

            if (
        vMA == nullvMA = new MAStudy(MA1Length0"close"MAStudy.EXPONENTIAL);
            if (
        vMAofMA == nullvMAofMA = new MAStudy(MA2Length0vMAMAStudy.MAMAStudy.SIMPLE);

            
        //debugPrintln("vMA = " + vMA.getValue(MAStudy.MA) + "\n");
            // debugPrintln("vMAofMA = " + vMAofMA.getValue(MAStudy.MA) + "\n");
            
            
        var MA1a vMA.getValue(MAStudy.MA,-07);
            var 
        MA1b vMA.getValue(MAStudy.MA);
            var 
        MA2 vMAofMA.getValue(MAStudy.MA);
            
            
        // Exit main until we get valid returns for all the
            // required inputs.
            
        if (MA1a == null || MA1b == null || MA2 == null) return;
            
            
        vMADiff MA1a MA2;

            
        vLoLagPrev MA1b vMADiff;
            
        //debugPrintln("vLoLagPrev = " + vLoLagPrev + "\n");

            
        return vLoLagPrev;

        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Just wanted to thank you for the information you supplied. It was very clear and to the point. I was pulling my hair out on a similar problem and your information led to the fix. Thanks again.

          Comment

          Working...
          X