Announcement

Collapse
No announcement yet.

Function Parameters Not Working

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

  • Function Parameters Not Working

    I have several function parameters in my efs, but only 1 is working. I suspect the problem is that the only one that is working (Signal) is in function main () section of my code. The other parameters are within function myCalcDI() section , which is just before the function main(). The parameters do show up in the Formula Parameters section of the Edit Study window. However, when changing any of the numbers, nothing happens. The code is below.

    I've looked at several of the posts regarding this issue, as well as, other available code. I can't seem to find the issue.

    Any help is greatly appreciated.

    Regards,

    zMendel

    PHP Code:

    var vLastAlert  = -1;

    function 
    preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("Directional Trend Index (DTI) Directonal Oscillator v2.1.1");
        
    setCursorLabelName("DTI"0);
        
    setCursorLabelName("DTIs"1);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarStyle(PS_SOLID1);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1);    
        
    setDefaultBarThickness(40);
        
    setDefaultBarThickness(21);
        
    setPlotType(PLOTTYPE_HISTOGRAM0);
        
    setPlotType(PLOTTYPE_LINE1);   

        var 
    fp3 = new FunctionParameter("EMArN"FunctionParameter.NUMBER);
            
    fp3.setName ("EMArN");
            
    fp3.setLowerLimit (0);
            
    fp3.setDefault (36); 

        var 
    fp4 = new FunctionParameter("EMAsN"FunctionParameter.NUMBER);
            
    fp4.setName ("EMAsN");
            
    fp4.setLowerLimit (0);
            
    fp4.setDefault (8); 

        var 
    fp5 = new FunctionParameter("EMArD"FunctionParameter.NUMBER);
            
    fp5.setName ("EMArD");
            
    fp5.setLowerLimit (0);
            
    fp5.setDefault (36); 

        var 
    fp6 = new FunctionParameter("EMAsD"FunctionParameter.NUMBER);
            
    fp6.setName ("EMAsD");
            
    fp6.setLowerLimit (0);
            
    fp6.setDefault (8);

        var 
    fp7 = new FunctionParameter("Signal"FunctionParameter.NUMBER);
            
    fp7.setName ("Signal");
            
    fp7.setLowerLimit (0);
            
    fp7.setDefault (8); 
            
    }
    function 
    myCalcN() {
        
        if (
    getValue("high"0) - getValue("high", -1) > 0) {
            var 
    HMuN getValue("high"0) - getValue("high", -1);
        }  else { 
            var 
    HMuN 0;
        }

        if (
    getValue("low"0) - getValue("low", -1) < 0) {
            var 
    LMdN = (getValue("low"0) - getValue("low", -1)) * (-1);
        }  else { 
            var 
    LMdN 0;
        }

        return 
    HMuN LMdN;
     }      
    function 
    myCalcD() {
        
        if (
    getValue("high"0) - getValue("high", -1) > 0) {
            var 
    HMuD getValue("high"0) - getValue("high", -1);
        }  else { 
            var 
    HMuD 0
        
    }

        if (
    getValue("low"0) - getValue("low", -1) < 0) {
            var 
    LMdD = (getValue("low"0) - getValue("low", -1)) * (-1);
        }  else { 
            var 
    LMdD 0
        
    }
        
        return 
    Math.abs((HMuD LMdD));
        }

    function 
    myCalcDI(EMArNEMAsNEMArDEMAsDSignal) {
         
        var 
    vDIn    efsInternal("myCalcN");
        var 
    vEMArN  ema(EMArNvDIn);
        var 
    vEMAsN  ema(EMAsNvEMArN);
            
        var 
    vDId    efsInternal("myCalcD");
        var 
    vEMArD  ema(EMArDvDId);
        var 
    vEMAsD  ema(EMAsDvEMArD);
            
        return ((
    vEMAsN/vEMAsD)*100);
            
        }
    function 
    main(EMArNEMAsNEMArDEMAsDSignal) {
        
        var 
    vDI      efsInternal("myCalcDI");
        var 
    vDIs     ema(SignalvDI);
        
        if (
            
    vDI vDIs
            
    onAction1()
        else if (
            
    vDI vDIs
            
    onAction2();
       
        return new Array(
            
    vDI,
            
    vDIs
        
    );

    function 
    onAction1() {

        
    setBarBgColor(Color.RGB(255,255,87));
        
        if (
    vLastAlert != 1
            
    Alert.playSound ("C:\\ProgramFiles\\eSignal Pro\\Sounds\\Ding.wav");

        
    vLastAlert 1;
    }
    function 
    onAction2() {

        
    setBarBgColor(Color.RGB(233,255,255));
        
        if (
    vLastAlert != 2
            
    Alert.playSound ("C:\\ProgramFiles\\eSignal Pro\\Sounds\\Ding.wav");
        
        
    vAsk getMostRecentAsk();
        
    vHigh high() - .3;
           
        
    vLastAlert 2;   


  • #2
    zmendel
    See my reply to you in this thread on the same subject
    Alex

    Comment


    • #3
      Function Parameters Not Working

      Alex:

      Thanks for the response.

      In the prior post that you reference, I was triggering the onAction1() and then passing the Function Parameters on from there. Your suggetions worked well there.

      However, in this scenario, I am not triggering anything into myCalcDI() which is actually before function main() - I use myCalcDI() to do certain claculations. As a result, I am not sure how to pass the Function Parameters onto the myCalcDI() section of my code. How would you suggest doing that?

      Again, thanks for your assistance.

      Regards,
      zMendel

      Comment


      • #4
        Re: Function Parameters Not Working

        zMmendel
        What you are actually doing in the script that is in the post I referenced is calling the onAction() function which in turn executes the logic and the commands contained in it.
        This is exactly the same process that you are implementing in the current script (albeit by means of a different functionality) when you call an external function using the efsInternal() function.
        Similarly if you need to pass to the external function the parameters it requires you need to do that when you call that function. In the case of the current script this would be through the efsInternal() call eg.
        var myVar = efsInternal("myFunction", myParam1, myParam2. etc)
        For the description and the syntax of the efsInternal() function together with examples of its use you may want to review this article in the EFS KnowledgeBase
        Lastly the position of the called function is inconsequential to how the formula works in other words it will work exactly in the same way whether the external function is located before or after main().
        Alex



        Originally posted by zmendel
        Alex:

        Thanks for the response.

        In the prior post that you reference, I was triggering the onAction1() and then passing the Function Parameters on from there. Your suggetions worked well there.

        However, in this scenario, I am not triggering anything into myCalcDI() which is actually before function main() - I use myCalcDI() to do certain claculations. As a result, I am not sure how to pass the Function Parameters onto the myCalcDI() section of my code. How would you suggest doing that?

        Again, thanks for your assistance.

        Regards,
        zMendel

        Comment


        • #5
          Function Parameters Not Working

          Thanks Alex:

          That worked great.

          Regards,
          zMendel

          Comment


          • #6
            zMendel
            You are most welcome
            Alex


            Originally posted by zmendel
            Thanks Alex:

            That worked great.

            Regards,
            zMendel

            Comment

            Working...
            X