Announcement

Collapse
No announcement yet.

How to define "Whole Number Value" ???

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

  • How to define "Whole Number Value" ???

    Below is my efs made with the wizard:

    The problem is that the condition I'm looking for can NEVER be met as long as the values are provided in a decimal form.

    All I want to compare in the condition is the value LEFT of the decimal point. (just the whole number)

    Example:

    Navy = 93.55
    Goat = 93.64
    Navy2 = 93.71

    I want the the efs to give me a yellow background when all 3 whole numbers (93) are equal and disregard the fractional part to the right of the decimal point.

    The ideal condition would be if all 3 were within a half point of each other (highest value minus lowest value <= 0.50 and remaining value between the high and low value) but all 3 whole numbers equal is OK for my purpose.

    I hope someone can advise me on how to do this.

    Thanks,

    OpaBert
    [email protected]


    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description 7532


    //{{EFSWizard_Declarations

    var vSMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
    var vSMA30 = new MAStudy(30, 0, "Close", MAStudy.SIMPLE);
    var vSMA10_of_vSMA30 = new MAStudy(10, 0, vSMA30, MAStudy.MA, MAStudy.SIMPLE);
    var vSMA5_of_vSMA5 = new MAStudy(5, 0, vSMA5, MAStudy.MA, MAStudy.SIMPLE);
    var vEMA30 = new MAStudy(30, 0, "Close", MAStudy.EXPONENTIAL);
    var vSMA10_of_High = new MAStudy(10, 0, "High", MAStudy.SIMPLE);
    var vSMA10_of_Low = new MAStudy(10, 0, "Low", MAStudy.SIMPLE);
    var vLastAlert = -1;

    //}}EFSWizard_Declarations 59283


    function preMain() {
    setComputeOnClose(true);
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setComputeOnClose(true);
    setPriceStudy(true);
    setStudyTitle("NavyBG3");
    setCursorLabelName("Navy", 0);
    setCursorLabelName("Goat", 1);
    setCursorLabelName("Navy2", 2);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarStyle(PS_SOLID, 2);
    setDefaultBarFgColor(Color.navy, 0);
    setDefaultBarFgColor(Color.magenta, 1);
    setDefaultBarFgColor(Color.red, 2);
    setDefaultBarThickness(3, 0);
    setDefaultBarThickness(3, 1);
    setDefaultBarThickness(2, 2);
    setPlotType(PLOTTYPE_LINE, 0);
    setPlotType(PLOTTYPE_LINE, 1);
    setPlotType(PLOTTYPE_LINE, 2);
    //}}EFSWizard_PreMain 74754

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    vSMA10_of_vSMA30.getValue(MAStudy.MA) == vSMA5_of_vSMA5.getValue(MAStudy.MA) &&
    vSMA10_of_vSMA30.getValue(MAStudy.MA) == vEMA30.getValue(MAStudy.MA)
    ) onAction1();
    //}}EFSWizard_Expression_1 22898

    //}}EFSWizard_Expressions 34020


    //{{EFSWizard_Return
    return new Array(
    vSMA10_of_vSMA30.getValue(MAStudy.MA),
    vSMA5_of_vSMA5.getValue(MAStudy.MA),
    vEMA30.getValue(MAStudy.MA)
    );
    //}}EFSWizard_Return 17893

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    setBarBgColor(Color.RGB(255,255,0));
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1 10615

    //}}EFSWizard_Actions 19508
    OpaBert

  • #2
    Hi OpaBert,

    Try this link for some methods http://forum.esignalcentral.com/show...2183#post62183

    Comment


    • #3
      When I want to get the digits to the left side of a number I use

      y = x-x%1

      if x=93.778, y=93

      Comment


      • #4
        OpaBert
        In addition to Steve's and David's suggestions and assuming you want to maintain the ability to use the Fornmula Wizard then you could use the parseInt() function in your conditions (see revised efs enclosed below)
        Alex

        PHP Code:
        //{{EFSWizard_Description
        //
        // This formula was generated by the Alert Wizard
        //
        //}}EFSWizard_Description 7532


        //{{EFSWizard_Declarations
        var vSMA5 = new MAStudy(50"Close"MAStudy.SIMPLE);
        var 
        vSMA30 = new MAStudy(300"Close"MAStudy.SIMPLE);
        var 
        vSMA10_of_vSMA30 = new MAStudy(100vSMA30MAStudy.MAMAStudy.SIMPLE);
        var 
        vSMA5_of_vSMA5 = new MAStudy(50vSMA5MAStudy.MAMAStudy.SIMPLE);
        var 
        vEMA30 = new MAStudy(300"Close"MAStudy.EXPONENTIAL);
        var 
        vSMA10_of_High = new MAStudy(100"High"MAStudy.SIMPLE);
        var 
        vSMA10_of_Low = new MAStudy(100"Low"MAStudy.SIMPLE);
        var 
        vLastAlert = -1;
        //}}EFSWizard_Declarations


        function preMain() {
        setComputeOnClose(true);
        /**
        * This function is called only once, before any of the bars are loaded.
        * Place any study or EFS configuration commands here.
        */
        //{{EFSWizard_PreMain
            
        setPriceStudy(true);
            
        setStudyTitle("NavyBG3");
            
        setCursorLabelName("Navy"0);
            
        setCursorLabelName("Goat"1);
            
        setCursorLabelName("Navy2"2);
            
        setDefaultBarStyle(PS_SOLID0);
            
        setDefaultBarStyle(PS_SOLID1);
            
        setDefaultBarStyle(PS_SOLID2);
            
        setDefaultBarFgColor(Color.navy0);
            
        setDefaultBarFgColor(Color.magenta1);
            
        setDefaultBarFgColor(Color.red2);
            
        setDefaultBarThickness(30);
            
        setDefaultBarThickness(31);
            
        setDefaultBarThickness(22);
            
        setPlotType(PLOTTYPE_LINE0);
            
        setPlotType(PLOTTYPE_LINE1);
            
        setPlotType(PLOTTYPE_LINE2);
        //}}EFSWizard_PreMain

        }

        function 
        main() {
        /**
        * The main() function is called once per bar on all previous bars, once per
        * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
        * in your preMain(), it is also called on every tick.
        */

        //{{EFSWizard_Expressions
            //{{EFSWizard_Expression_1
                
        if (
                    
        parseInt(vSMA10_of_vSMA30.getValue(MAStudy.MA)) == parseInt(vSMA5_of_vSMA5.getValue(MAStudy.MA)) &&
                    
        parseInt(vSMA10_of_vSMA30.getValue(MAStudy.MA)) == parseInt(vEMA30.getValue(MAStudy.MA))
                ) 
        onAction1();
            
        //}}EFSWizard_Expression_1
            
        //}}EFSWizard_Expressions


        //{{EFSWizard_Return
            
        return new Array(
                
        vSMA10_of_vSMA30.getValue(MAStudy.MA),
                
        vSMA5_of_vSMA5.getValue(MAStudy.MA),
                
        vEMA30.getValue(MAStudy.MA)
            );
        //}}EFSWizard_Return

        }

        function 
        postMain() {
        /**
        * The postMain() function is called only once, when the EFS is no longer used for
        * the current symbol (ie, symbol change, chart closing, or application shutdown).
        */
        }

        //{{EFSWizard_Actions
            //{{EFSWizard_Action_1
            
        function onAction1() {
                
        setBarBgColor(Color.RGB(255,255,0));
                
        vLastAlert 1;
            }
            
        //}}EFSWizard_Action_1
            
        //}}EFSWizard_Actions 

        Comment


        • #5
          Alexis Thank You!

          That is exactly what I was looking for.

          As a follow up, Is there any way within the wizard to define a variable?

          The whole number works for a high price index, but for stocks I need to be able to change the values easily.

          I wrote an efs that has 6 possible conditions to cover all possibilities. For example:

          For Lines A, B, & C:

          Condition 1, if (A - C) <= 0.5 and
          B<=A and B>=C then Color BG Yellow.

          Condition 2, if (A - B) <= 0.5 and
          C<=A and C>=B then Color BG Yellow.

          Etc....

          What I need is a way to make the 0.5 value a variable so that I can quickly change it in "Edit Studies..."

          I'm guessing that in the Declarations section it should be something like: var vInput = 0.5

          And that in the Expressions section I should replace 0.5 with vInput

          I just don't know the correct way to do it. Any additional help would be appreciated.

          Thanks Again,
          OpaBert
          OpaBert

          Comment


          • #6
            OpaBert
            You cannot create user defined variables using the Formula Wizard.
            To do that you will need to modify the efs using the Editor. However once you do that you will no longer be able to view/edit the efs with the Formula Wizard
            Alex

            Comment


            • #7
              I understand.

              I am generally familiar with the editor.

              Can you tell me what changes I should make to make entering a variable possible?

              Thanks
              OpaBert

              Comment


              • #8
                OpaBert
                First thing change function main() { to function main(Value) {.
                Then as the first line in main add the following if(Value==null) Value=0.5;
                This will add a user defined variable called Value which you can then use throughout your conditions and that you can change through Edit Studies.
                You will need to Remove the efs from the chart and load it again after you have made these changes else the parameter will not show up in Edit Studies
                Alex

                Comment


                • #9
                  Thanks Alexis

                  It works just the way I had anticipated!

                  Opa
                  OpaBert

                  Comment

                  Working...
                  X