Announcement

Collapse
No announcement yet.

Why doesn't this work?

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

  • Why doesn't this work?

    I've read through this post, and but i can't get the getValue function to work in the code posted below. It tells me the call function is undefined. Any ideas?

    debugClear();
    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Daily Drummond");
    setCursorLabelName("D",0);
    setCursorLabelName("D",1);
    setCursorLabelName("D",2);
    setCursorLabelName("D",3);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),0);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),1);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),2);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),3);
    setPlotType(PLOTTYPE_FLATLINES,0);
    setPlotType(PLOTTYPE_FLATLINES,1);
    setPlotType(PLOTTYPE_FLATLINES,2);
    setPlotType(PLOTTYPE_FLATLINES,3);
    setDefaultBarThickness(2,0);
    setDefaultBarThickness(2,1);
    setDefaultBarThickness(2,2);
    setDefaultBarThickness(2,3);
    }

    var prevH = null;
    var prevL = null;
    var prev2H = null;
    var prev2L = null;
    var H2H = null;
    var H2L = null;
    var L2H = null;
    var L2L = null;
    var bInit = false;
    var xHigh = null;
    var xLow = null;

    function main() {
    if(bInit == false){
    xHigh = high(inv("D"));
    xLow = low(inv("D"));
    bInit = true;
    }

    var prevH = xHigh.getValue(-1);
    var prevL = xLow.getValue(-1);
    var prev2H = xHigh.getValue(-2);
    var prev2L = xLow.getValue(-2);
    if(prev2H == null)
    if(prev2L == null)
    if(prevH == null)
    if(prevL == null)
    return;

    H2H = (prevH - prev2H) + prevH;
    H2L = (prevL - prev2H) + prevL;
    L2H = (prevH - prev2L) + prevH;
    L2L = (prevL - prev2L) + prevL;
    return;

    return new Array(H2H.getValue(0),H2L.getValue(0),L2H.getValue (0),L2L.getValue(0));
    }

    I've tried different variations on this theme, including trying to define another set of variables and then calling the function (i.e., newvar = H2H.getValue(0);...
    return new Array(newvar...);
    Same result.

    Any help woul dbe appreciated.

  • #2
    Try this ( I commented the corrections):

    Wayne

    PHP Code:
    debugClear();
    function 
    preMain() {
    setPriceStudy(true);
    setStudyTitle("Daily Drummond");
    setCursorLabelName("D",0);
    setCursorLabelName("D",1);
    setCursorLabelName("D",2);
    setCursorLabelName("D",3);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),0);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),1);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),2);
    setDefaultBarFgColor(Color.RGB(0xFF,0xFF,0x00),3);
    setPlotType(PLOTTYPE_FLATLINES,0);
    setPlotType(PLOTTYPE_FLATLINES,1);
    setPlotType(PLOTTYPE_FLATLINES,2);
    setPlotType(PLOTTYPE_FLATLINES,3);
    setDefaultBarThickness(2,0);
    setDefaultBarThickness(2,1);
    setDefaultBarThickness(2,2);
    setDefaultBarThickness(2,3);
    }

    var 
    prevH null;
    var 
    prevL null;
    var 
    prev2H null;
    var 
    prev2L null;
    var 
    H2H null;
    var 
    H2L null;
    var 
    L2H null;
    var 
    L2L null;
    var 
    bInit false;
    var 
    xHigh null;
    var 
    xLow null;

    function 
    main() {
    if(
    bInit == false){
        
    xHigh high(inv("D")); 
        
    xLow low(inv("D"));
        
    bInit true;
    }

    var 
    prevH xHigh.getValue(-1); 
    var 
    prevL xLow.getValue(-1);
    var 
    prev2H xHigh.getValue(-2);
    var 
    prev2L xLow.getValue(-2); 
    if(
    prev2H == null) return;//added "return" after each "if" statement otherwise only the last "if" would execute "return" if true.
    if(prev2L == null) return;
    if(
    prevH == null) return;
    if(
    prevL == null) return;


    H2H = (prevH prev2H) + prevH;
    H2L = (prevL prev2H) + prevL;
    L2H = (prevH prev2L) + prevH;
    L2L = (prevL prev2L) + prevL;
    //return;//commented out since this return stope execution every iteration

    return new Array(H2H,H2L,L2H,L2L);//removed ".getValue(0)" since each is a value not a series

    Last edited by waynecd; 03-11-2011, 12:07 PM.

    Comment


    • #3
      I should have been more clear in my post. I can get the series to pull up. What I'm trying to do is have it pull up only the last value returned. That's why i was playing around with the getValue(0) command. I'm not on the machine that has the script file, but with the changes you put in above, would the getValue(0) command now work?

      Comment


      • #4
        No.

        PHP Code:
        H2H = (prevH prev2H) + prevH;
        H2L = (prevL prev2H) + prevL;
        L2H = (prevH prev2L) + prevH;
        L2L = (prevL prev2L) + prevL
        are not a series, they are a value. Each is the last calculated individual value based on it's respective formula. So, "H2L" is the last calculation, etc. It is returning the last value for "H2L", "L2H", & "L2L".

        *.getValue(#) only works with a series and series identified in the knowledgebase.

        Wayne

        Comment


        • #5
          so then is there a way to limit how far this goes back? I only want to show the last one on the chart.

          Comment

          Working...
          X