Announcement

Collapse
No announcement yet.

invalid Parameter error on drawShapeRelative

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

  • invalid Parameter error on drawShapeRelative

    Ok, i usually can fix my mistakes, but this one has me baffled.

    I wanted to be able to add the ability to change the Moving Average line colors to my existing code thru the use of Color Parameters.

    So I added a Color Parameter section(lines 133- 140), declared them in function main(), and did an eval(Color) declaration( lines 178-179) under bInit (I copied this straight from an already working code). However , now I get a " Parameter Number 5 of the Function drawShapeRelative is invalid " error on line 336. This line of code actaully draws the "stops" on the chart.

    I use that same drawShape code and the Color Parameters in other programs and it works just fine, so I know the drawshapeRelative parameter is valid. Somewhere , my logic as written, is causing the Color Parameter mixup.

    Any help is appreciated!!
    angelo
    Attached Files
    ang.

  • #2
    Hi Angelo,

    These should fix your coding problems:

    1. Replace "Color" (it is a reserved word in JS) with "Color1" in lines 133, 155 and 178.

    2. Replace "(eval(Color),0)" and "(eval(Color2,1)" in lines 178 & 179 with "(Color1,0)" and "(Color2,1)" respectively.

    3. Add a global variable outside of "function main()" (i.e., line 155) as follows:
    PHP Code:
    var revflag;
    function 
    main(... 
    4. I suggest that instead of using close(), open(), etc to refer to the current value you use close(0), open(0), etc. Otherwise you are calling a series with every tick instead of just the most current value which is very inefficient. For example replace:
    PHP Code:
    if ((high()-StopLevel) > nStopPrice) { 
    with:
    PHP Code:
    if ((high(0)-StopLevel) > nStopPrice) { 
    5. xPDI and xNDI are used in "bInit" to call the "pdi" and "ndi" functions respectively as:

    PHP Code:
    xPDI pdi(Length,DILength,sym(vSymbol));
    xNDI ndi(Length,DILength,sym(vSymbol)); 
    and as local variables to call the current "adx" value as:
    PHP Code:
    var xPDI vADX.getValue(0);
    var 
    xNDI vADX.getValue(0); 
    Both call the same value so the conditions in the code that compare which is greater will never evaluate to true, for example:
    PHP Code:
    if (xNDI xPDI){
    if(
    xPDI xNDI) { 
    If you need the "pdi" and "ndi" functions the variables should be declared as globals
    outside of main and not used again as local varibles or you overwrite their "pdi" and "ndi" series.

    To improve efficiency you may want to remove unused series calls in bInit.
    PHP Code:
    xADX adx(Length,DILength,sym(vSymbol));
    xPDI pdi(Length,DILength,sym(vSymbol));
    xNDI ndi(Length,DILength,sym(vSymbol));
    vCCIcci(14hlc3()); 
    Note: var xCCI = vCCI.getValue(0); is not used in the script.

    Wayne
    Last edited by waynecd; 11-26-2010, 12:51 AM.

    Comment


    • #3
      Hi Angelo,

      I expect you are testing the code so you know about the extra coding suggestions I have made but I added them just in case.

      I was unclear as to what to do with:
      PHP Code:
      var xPDI vADX.getValue(0);
      var 
      xNDI vADX.getValue(0); 
      just rename the varibles so they are different from those used for the "pdi(..." and "ndi(..." functions.

      In several places the code has:
      PHP Code:
      if(Strategy.isInTrade... 
      It should be:
      PHP Code:
      if(Strategy.isInTrade()... 
      Comment out line 210 once you correct the ".isInTrade()":
      PHP Code:
      //  Text for new trailing stop....
              
      if(Strategy.isInTrade == false){
                
      //nStopPrice = null;
              
      }else{... 
      otherwise "nStopPrice" won't plot where this conditional is true.

      Wayne
      Last edited by waynecd; 11-26-2010, 07:50 PM.

      Comment


      • #4
        Hi Angelo,

        From my last post, the last statement seems to be wrong. Please disregard.

        Comment out line 210 once you correct the ".isInTrade()":
        // Text for new trailing stop....
        if(Strategy.isInTrade == false){
        //nStopPrice = null;
        }else{...
        otherwise "nStopPrice" won't plot where this conditional is true.
        Wayne

        Comment


        • #5
          Hi Wayne,

          Thanks for the suggested changes and corrections to the program!! I fiqured that "Color" was a reserved word. I put the program together real quick , late at night with a cut and paste job from other working programs. Rule of thumb, no programming after 3am.

          Now, if I can remember what I did last time to get rid of those connecting lines for the stops.....

          Here's a copy of the corrected code, with some added time constraints. ( another paste and cut job).

          One last note.... it's always great to have moderators and others like yourself to help correct and suggest ways to better code. The forums are a life thread for learning to code and , as always, a big "thank you" to all those who help!!!

          angelo
          Attached Files
          ang.

          Comment


          • #6
            Hi Angelo,

            Your welcome.

            Now, if I can remember what I did last time to get rid of those connecting lines for the stops.....
            The simplest way to remove the connecting lines is by removing "nStopPrice" from the return statement. This will just leave the red and blue triangles to mark the stop level. If you still want to see the stop values in the "Cursor Window" then instead of removing "nStopPrice" from the return statement just add text quotes to it as in:
            PHP Code:
            return new Array (xSWMAxMA,xMA2nStopPrice+""); 
            Wayne
            Last edited by waynecd; 11-29-2010, 08:54 PM.

            Comment


            • #7
              Hi,

              An important correction to one of my posts below which states:
              PHP Code:
              Hi Angelo,

              These should fix your coding problems:
              ....

              4. I suggest that instead of using close(), open(), etc to refer to
              the current value you 
              use close(0), open(0), etcOtherwise you
              are calling a series with every tick instead of just the most 
              current value which is very inefficient
              . For example replace:

              ... 
              Alexis Montenegro stated in thread: http://forum.esignal.com/showthread....threadid=34961
              that a new series isn't recreated with every tick but that the efs engine must check on each iteration to verify whether the series already exists:

              PHP Code:
              shaeffer 
              Case 2 of your examples is more efficient because while you are 
              creating a series in either 
              case in the first one the efs engine has 
              to check on each iteration 
              if that series already exists so as not
              to create another instance of it
              By using the bInit [or similar]
              routine you preempt the efs engine from having to perform those
              checks thereby increasing the efficiency of execution of the script
              Alex 
              Wayne
              Last edited by waynecd; 12-04-2010, 03:45 AM.

              Comment

              Working...
              X