Announcement

Collapse
No announcement yet.

RangeError: invalid array length

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

  • RangeError: invalid array length

    Need some help with this. I keep getting this "RangeError: invalid array length" error message when I attempt to plot the data. I will use RSI and Momentum for examples as I get the same Error Message as I get with my self developed Indicators. The RSI and Momentum plots appear to be correct when plotted seperately. But when I try to combine the two values is when I get the error message. Values being 1 for Upward Movement and -1 for downward movement.

    Any suggestions?

    PHP Code:
    function preMain() {

        
    setPriceStudy(false);
        
    setStudyTitle("Test");
         
    setCursorLabelName("Test"0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setPlotType(PLOTTYPE_HISTOGRAM ,0);
        
    setDefaultBarThickness(15,0);
        
    addBand0.0PLOTTYPE_LINE 3Color.black, -10 ); 
    }
        


    var 
    test_Dir null;

    function 
    main(Base) {
    var 
    vExt_MOM efsInternal("MOM");
    var 
    vDir_MOM getSeries(vExt_MOM,0);

    var 
    vExt_RSI efsInternal("RSI");
    var 
    vDir_RSI getSeries(vExt_RSI,0);

    //--------------THIS LINE APPEARS TO BE THE ISSUE -------------------------------

    var test_Dir vDir_RSI vDir_MOM;

    //--------------------------------------------------------------------------------

      
    debugPrint"The current test_Dir value is: " test_Dir "\n" );

    Total_Direction test_Dir   ;

        if ( 
    Total_Direction ) { 
          
    setBarFgColorColor.green); 
       } 
       else { 
          
    setBarFgColorColor.red); 
       }

    return new Array(
    Total_Direction);
    }

    function 
    MOM () {
     var 
    MOMDirection;
        if ((
    sma(2,mom(20) )) >  (sma(20,  mom(20)  ) )   ) { 
          
    MOMDirection 1;
        } 
        else { 
          
    MOMDirection = -1;
        } 
      return (
    MOMDirection);
     }

    function 
    RSI () {
     var 
    RSIDirection;
        if ((
    sma(2,rsi(20) )) >  (sma(20,  rsi(20)  ) )   ) { 
          
    RSIDirection 1;
        } 
        else { 
          
    RSIDirection = -1;
        } 
      return (
    RSIDirection);
     } 

  • #2
    Re: RangeError: invalid array length

    TJTradesAB
    The invalid array length error message is because the return statement is set to return an array ie
    return new Array(Total_Direction);
    whereas you are returning only a single value. Replace that line with the following
    return (Total_Direction);
    and the script should work
    Alex



    Originally posted by TJTradesAB
    Need some help with this. I keep getting this "RangeError: invalid array length" error message when I attempt to plot the data. I will use RSI and Momentum for examples as I get the same Error Message as I get with my self developed Indicators. The RSI and Momentum plots appear to be correct when plotted seperately. But when I try to combine the two values is when I get the error message. Values being 1 for Upward Movement and -1 for downward movement.

    Any suggestions?

    PHP Code:
    function preMain() {

        
    setPriceStudy(false);
        
    setStudyTitle("Test");
         
    setCursorLabelName("Test"0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setPlotType(PLOTTYPE_HISTOGRAM ,0);
        
    setDefaultBarThickness(15,0);
        
    addBand0.0PLOTTYPE_LINE 3Color.black, -10 ); 
    }
        


    var 
    test_Dir null;

    function 
    main(Base) {
    var 
    vExt_MOM efsInternal("MOM");
    var 
    vDir_MOM getSeries(vExt_MOM,0);

    var 
    vExt_RSI efsInternal("RSI");
    var 
    vDir_RSI getSeries(vExt_RSI,0);

    //--------------THIS LINE APPEARS TO BE THE ISSUE -------------------------------

    var test_Dir vDir_RSI vDir_MOM;

    //--------------------------------------------------------------------------------

      
    debugPrint"The current test_Dir value is: " test_Dir "\n" );

    Total_Direction test_Dir   ;

        if ( 
    Total_Direction ) { 
          
    setBarFgColorColor.green); 
       } 
       else { 
          
    setBarFgColorColor.red); 
       }

    return new Array(
    Total_Direction);
    }

    function 
    MOM () {
     var 
    MOMDirection;
        if ((
    sma(2,mom(20) )) >  (sma(20,  mom(20)  ) )   ) { 
          
    MOMDirection 1;
        } 
        else { 
          
    MOMDirection = -1;
        } 
      return (
    MOMDirection);
     }

    function 
    RSI () {
     var 
    RSIDirection;
        if ((
    sma(2,rsi(20) )) >  (sma(20,  rsi(20)  ) )   ) { 
          
    RSIDirection 1;
        } 
        else { 
          
    RSIDirection = -1;
        } 
      return (
    RSIDirection);
     } 

    Comment


    • #3
      Alexis,

      Thanks!

      I spent 3 days trying to make it work. Going to take SELF out back and smack him upside the head for not figuring it out. LOL

      Comment


      • #4
        TJTradesAB
        You are most welcome
        Alex


        Originally posted by TJTradesAB
        Alexis,

        Thanks!

        I spent 3 days trying to make it work. Going to take SELF out back and smack him upside the head for not figuring it out. LOL

        Comment

        Working...
        X