Announcement

Collapse
No announcement yet.

MACD_Values

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

  • MACD_Values

    I am trying to get the previous values of MACD, HIST and SIGNAL on this formula, it keeps getting this error: TypeError: vHist has no properties. I

    t was working fine on the Stochastic study.

    Any modification that let this formula work will be appreciated.

    Thanx,
    Safa


    var study = new MACDStudy(12, 26, 9, "C");

    function preMain() {

    setDefaultBarFgColor(Color.yellow, 0);
    setDefaultBarFgColor(Color.lime, 1);
    setDefaultBarFgColor(Color.red, 2);

    setPlotType(PLOTTYPE_HISTOGRAM, 0 );
    setCursorLabelName("Hist", 0);
    setCursorLabelName("Sig", 1);
    setCursorLabelName("Macd", 2);
    addBand(0.0, PLOTTYPE_LINE, 3, Color.blue);
    }

    function main() {
    var vMACD = study.getValue(MACDStudy.MACD, 0,-5 );
    var vSignal = study.getValue(MACDStudy.SIGNAL,0,-5);
    var vHist = study.getValue(MACDStudy.HIST,-5);

    return new Array(vHist[3], vMACD[3], vSignal[3]);
    }

  • #2
    var vSignal = study.getValue(MACDStudy.SIGNAL,0,-5);
    var vHist = study.getValue(MACDStudy.HIST,0,-5);
    ^

    Is there a missing 0 in the HIST definition as shown above

    Comment


    • #3
      May be I mistyped here.

      Still I have the same error:

      TypeError: vHist has no properties.
      TypeError: vMACD has no properties.
      TypeError: vSignal has no properties.

      Thank you,
      Safa

      Comment


      • #4
        var study = new MACDStudy(12, 26, 9, "Close", false);

        is the correct format according to the Formula Wizard

        Comment


        • #5
          Hello Safa,

          The problem is that the data from -5 bars does not exist until you have at least 5 bars loaded in the chart. All you need to do is perform a null check after each getValue() statement. There was also a parameter missing from your vHist getValue() statement.

          Try the following:

          PHP Code:
          var study = new MACDStudy(12269"C");

          function 
          preMain() {

          setDefaultBarFgColor(Color.yellow0); 
          setDefaultBarFgColor(Color.lime1); 
          setDefaultBarFgColor(Color.red2); 

          setPlotType(PLOTTYPE_HISTOGRAM);
          setCursorLabelName("Hist"0); 
          setCursorLabelName("Sig"1); 
          setCursorLabelName("Macd"2);
          addBand(0.0PLOTTYPE_LINE3Color.blue); 
          }

          function 
          main() {
          var 
          vMACD study.getValue(MACDStudy.MACD0, -5);
          if (
          vMACD == null) return;
          var 
          vSignal study.getValue(MACDStudy.SIGNAL0, -5);
          if (
          vSignal == null) return;
          var 
          vHist study.getValue(MACDStudy.HIST0, -5); 
          if (
          vHist == null) return;

          return new Array(
          vHist[3], vMACD[3], vSignal[3]);

          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


          • #6
            Thank you Jason,

            Now it works, little changes make a diffrent.

            Safa

            Comment

            Working...
            X