Announcement

Collapse
No announcement yet.

Price Round Off or Price Arrangement for indicators on MINI S&P

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

  • Price Round Off or Price Arrangement for indicators on MINI S&P

    Hi,

    When I'm making a forumla that puts a Moving Average on a chart for example, I want the price of the Moving Average to be real price.

    For example on the E-MINI S&P, The price can be 1350.33. So in this case I want the forumal to switch the price automatically to 1350.25.

    What line do I need to put in the formula in order to do that ?

    Thank's.

  • #2
    Here is an efs for moving avg that I programed. It allows you to round it to the nearest .25 or .10.
    Attached Files

    Comment


    • #3
      Applying it for more than one Array

      Thank you very much waynecd, This is exactly what I wanted.

      How can I apply that for more than one Array without writing it thousand times for each var ?

      My formula contains alot of vars that need to round off:
      Code:
      return new Array(vPP,MM,MMM,KE,ZZ,DD,BB,vHighT,vHighP,vHighA,vHighB,vHighC,vHighD,vHighE,vHighF,vHighG,vHighH,vHighI,vHighJ,vHighK,vHighL,vHighM,vHighN,PrevLow);
      I can write it like that for each var:
      Code:
      if(vPP%0.50<0.150)
          var vPP = vPP-vPP%0.50
      else
          var vPP = vPP-vPP%0.50+0.50
      
      if(MM%0.50<0.150)
          var MM = MM-MM%0.50
      else
          var MM = MM-MM%0.50+0.50
      
      etcetera.....
      How can I do that in a smarter way ?

      Comment


      • #4
        I'm still a novice and need to study arrays a little more. But will look into it for both our benefits. In the mean time maybe someone else with more expertise might help out. I'll post my solution once I figure it out.

        Good luck.

        Comment


        • #5
          Since each variable has a different name; instead of the same prefix plus a number, i.e. "val1, val2, val3,etc" - a fix without the array follows:
          /*******/
          //(just add the variables you need to the list)
          var aFPArray = new Array();

          function preMain() {
          setPriceStudy(true);
          setStudyTitle("Test Rounding");
          var x=0;
          aFPArray[x] = new FunctionParameter( "vRndTo25", FunctionParameter.BOOLEAN);
          with( aFPArray[x++] ) {
          setName( "Round to 0,25" );
          setDefault( true );
          }
          }
          var vPP = 1.1678;
          var MM = 2.398765;
          var MMM = 3.428765;
          var KE = 4.778765;

          function main(vRndTo25){

          if (!vRndTo25){//put this code right above the "return new Array(vPP...
          vPP = rnd(vPP,2);
          MM = rnd(MM,2);
          MMM = rnd(MMM,2);
          KE = rnd(KE,2);
          }else if (vRndTo25){
          vPP = rnd25(vPP);
          MM = rnd25(MM);
          MMM = rnd25(MMM);
          KE = rnd25(KE);
          }

          debugPrintln(vPP, "vPP = ","\n",MM,"MM = ","\n",MMM,"MMM = ","\n",KE,"KE = ");
          return new Array(vPP,MM,MMM,KE);
          }


          //ROUNDING FUNCTION
          function rnd(value, N) { //N = round to N # of digits
          var n;
          var mult=1;
          for(n=0;n<N;n++) mult*=10;
          value*=mult;
          return Math.round( value,N)/mult;
          }
          function rnd25(yValue){ // Round to nearest 0.25
          if(yValue%0.25<0.125)
          y=yValue-yValue%0.25
          else
          y=(yValue-yValue%0.25+0.25)

          return y;
          }
          /*
          vPP,MM,MMM,KE,ZZ,DD,BB,vHighT,vHighP,vHighA,
          vHighB,vHighC,vHighD,vHighE,vHighF,vHighG,vHighH,v
          HighI,vHighJ,vHighK,vHighL,vHighM,vHighN,PrevLow

          */
          Last edited by waynecd; 04-08-2008, 03:09 PM.

          Comment


          • #6
            ser-E
            To simplify the process of rounding all the variables using the rnd25() function store the variables in an array after you have calculated them eg
            PHP Code:
            var myArray = new  Array(vPPMMMMMKEZZDDBBvHighTvHighPvHighA,
                                         
            vHighBvHighCvHighDvHighEvHighFvHighGvHighH,
                                         
            vHighIvHighJvHighKvHighLvHighMvHighNPrevLow); 
            Then using a for loop pass all the elements of the array to the rnd25() function eg
            PHP Code:
            for (var i=0i<myArray.lengthi++){
                
            myArray[i] = rnd25(myArray[i]);

            Once you have done this you can simply return the variable myArray eg
            PHP Code:
            return myArray
            For a complete description of the for loop including examples on how to use it you may want to review this article of the Core JavaScript Guide which is in the EFS KnowledgeBase. The for loop is also explained in the JavaScript for EFS video series.
            For information on Arrays see instead this article in the EFS KnowledgeBase and this article in the Core JavaScript Guide.
            Hope this helps
            Alex


            Originally posted by ser-E
            Thank you very much waynecd, This is exactly what I wanted.

            How can I apply that for more than one Array without writing it thousand times for each var ?

            My formula contains alot of vars that need to round off:
            Code:
            return new Array(vPP,MM,MMM,KE,ZZ,DD,BB,vHighT,vHighP,vHighA,vHighB,vHighC,vHighD,vHighE,vHighF,vHighG,vHighH,vHighI,vHighJ,vHighK,vHighL,vHighM,vHighN,PrevLow);
            I can write it like that for each var:
            Code:
            if(vPP%0.50<0.150)
                var vPP = vPP-vPP%0.50
            else
                var vPP = vPP-vPP%0.50+0.50
            
            if(MM%0.50<0.150)
                var MM = MM-MM%0.50
            else
                var MM = MM-MM%0.50+0.50
            
            etcetera.....
            How can I do that in a smarter way ?

            Comment


            • #7
              Alexis, Thank you. It's working perfectly. I really appreciate your help.

              Comment


              • #8
                ser-E
                You are most welcome
                Alex


                Originally posted by ser-E
                Alexis, Thank you. It's working perfectly. I really appreciate your help.

                Comment

                Working...
                X