Announcement

Collapse
No announcement yet.

FunctionParameter Question

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

  • FunctionParameter Question

    I did the following by accident, but it works. When I think about it that makes sense. However, it doesn't agree with the example in Help. Actually, it would seem that not only could you reuse the variable name, but you only need one variable name and shouldn't have to re-declare the variable for each FunctionParameter.

    Has anyone explored this issue?

    Thanks


    var FP3 = new FunctionParameter("pClrFlt", FunctionParameter.COLOR);
    FP3.setName("Flat Color");
    FP3.setDefault(Color.RGB(125,158,192)); // light blue
    var FP4 = new FunctionParameter("pClrSig", FunctionParameter.COLOR);
    FP4.setName("Signal Color");
    FP4.setDefault(Color.RGB(255,255,255)); // white
    var FP4 = new FunctionParameter("pClrBkG", FunctionParameter.COLOR);
    FP4.setName("Chart Background");
    FP4.setDefault(Color.RGB(0,0,0)); // black
    Last edited by Gavishti; 02-02-2004, 11:21 AM.

  • #2
    I tried this as an experiment and it works. Guess this means that you only need one variable declaration. Perhaps someone that understands more about JavaScript and the FunctionParameter Class can validate that this form is okay. In theory it would be more efficient, but I don't know enough about the inner workings to say that with any certainty.

    function preMain()
    {
    setPriceStudy(true);
    setShowTitleParameters(false);
    setStudyTitle("Experiment");
    setShowCursorLabel(false);

    var fp = new FunctionParameter("pMkSz", FunctionParameter.NUMBER);
    fp.setName("Marker Size");
    fp.setLowerLimit(1);
    fp.setUpperLimit(20);
    fp.setDefault(10);

    fp = new FunctionParameter("pClrH", FunctionParameter.COLOR);
    fp.setName("High Pivot");
    fp.setDefault(Color.RGB(0,255,0)); // green

    fp = new FunctionParameter("pClrL", FunctionParameter.COLOR);
    fp.setName("Low Pivot");
    fp.setDefault(Color.RGB(255,0,0)); // red
    }

    Comment


    • #3
      Have you tried going in and changing the variables for the different function parameters? My experience with sharing variable names is that the later ones overwrite the earlier ones. I am amazed that this works. Who'd a thunk?

      Comment


      • #4
        I doubt very much that it will work as expected.

        G
        Garth

        Comment


        • #5
          The colors are working okay, but the number is acting funky. I'll mess around with it a bit to try to figure out what is going on. Was hoping someone that understands what is going on with the class and how JS deals with it could shed some light on the subject.

          Would also like to know how this class interfaces with the arguments array.

          Thanks for any light you can shed on this subject.

          Comment


          • #6
            So you are getting LowPivot and HighPivot colored correctly even when you edit the study to change the colors? This surprises me.

            I don't think the FunctionParameter class is a standard part of JS (at least not that I ever ran into). All I can tell you that whenever I had duplicate function numbers that whenever I also had duplicate names it caused problems. Also when the number of parameters didn't match the FunctionParameter definition it caused problems.

            Sorry I don't have any details on how the interface works exactly.

            G
            Garth

            Comment


            • #7
              All three parameters are working just fine. I'm able to change them in Edit Studies without problems.

              I suspect the key is that each parameter gets a "new" assignment and that the parameterName is unique. The FunctionParameter Class must be assigning to the arguments array based upon each parameterName. That is all I can come up with for an explanation.

              Maybe someone from eSignal that knows how the class is constructed can elaborate.

              Comment


              • #8
                Hello Gavishti,

                Interesting discovery. I'm not sure I can provide the details you're looking for from a development perspective but I do have some insights for you. I initially was in agreement with Steve and Garth about this causing some problems. After testing this recycling method you're using I found that simply recycling the FP object name as you are seems to work just fine. I think the reason for this is because the FP objects are used only as local objects for preMain(). When the formula is being initialized, preMain() is processed first and in a linear fashion from top to bottom and adds a new FP to the array of formula parameters used for the gui in the edit studies dialog for each instance of “new FunctionParameter().” Since we won't ever need to reference the properties of the FP objects again later in the formula we can recycle the same FP object name. Here's some code I used for testing.

                PHP Code:
                function preMain() {
                    
                setStudyTitle("test");
                    
                setCursorLabelName("Stoch K"0);
                    
                setCursorLabelName("Stoch D"1);
                    
                setDefaultBarFgColor(Color.blue0);
                    
                setDefaultBarFgColor(Color.red1);
                    
                addBand(50PS_SOLID2Color.black"zero");
                    
                setStudyMax(100);
                    
                setStudyMin(0);
                    
                    var 
                fp = new FunctionParameter("Klen"FunctionParameter.NUMBER);
                    
                fp.setName("K Length");
                    
                fp.setLowerLimit(1);
                    
                fp.setDefault(14);

                    
                fp = new FunctionParameter("Ksm"FunctionParameter.NUMBER);
                    
                fp.setName("K Smooth");
                    
                fp.setLowerLimit(1);
                    
                fp.setDefault(1);

                    
                fp = new FunctionParameter("Dlen"FunctionParameter.NUMBER);
                    
                fp.setName("D Length");
                    
                fp.setLowerLimit(1);
                    
                fp.setDefault(3);
                    
                    
                fp = new FunctionParameter("vKColor"FunctionParameter.COLOR);
                    
                fp.setName("K Color");
                    
                fp.setDefault(Color.blue);    

                    
                fp = new FunctionParameter("vDColor"FunctionParameter.COLOR);
                    
                fp.setName("D Color");
                    
                fp.setDefault(Color.red);    
                }

                var 
                study null;
                var 
                bEdit true;

                function 
                main(KlenKsmDlenvKColorvDColor) {
                    if (
                Klen == nullKlen 14;
                    if (
                Ksm == nullKsm 1;
                    if (
                Dlen == nullDlen 3;
                    if (
                study == nullstudy = new StochStudy(KlenKsmDlen);

                    if (
                bEdit == true) {
                        
                setDefaultBarFgColor(vKColor0);
                        
                setDefaultBarFgColor(vDColor1);
                        
                bEdit false;
                    }
                    
                    var 
                vK study.getValue(StochStudy.FAST);
                    var 
                vD study.getValue(StochStudy.SLOW);
                    if (
                vK == null || vD == null) return;
                    
                    return new Array(
                vKvD);

                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

                Working...
                X