Announcement

Collapse
No announcement yet.

Is there a function that will translate price value to hard money value..

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

  • Is there a function that will translate price value to hard money value..

    I was wondering if there was a function that would translate price value to hard money such that you could track (for instance) 2% of account equity...say as a moving horizontal line that would move in tandem of the H+L/2 of the current bar on the current chart. So you would have to update the script (daily?) with your account equity as it ebbs and flows but you could have this line that would follow the price action a given % distance away from it - giving you a 'visual' sense of risk.

    Is there such an animal?

    Any help is much appreciated,

    gg

  • #2
    Nope. Not that I'm aware of. You have to build your own.

    I'm posting some functions to help you out. This set of code allows you to create a file in the FormulaOutput folder where you can setup symbols and have it automatically load specific values depeneding on the esignal symbol.

    Thus, you could load MINTICK & DOLLARPERPOINT values for any symbol and calculate your own net values from these.

    PHP Code:

    var      MTSSymbol tsymbol;  
    var     
    MTSExchange "SMART";
    var     
    MTSExpiration "";
    var     
    MTSType "stock";
    var     
    MTSDollarMult 1;
    var     
    MTSMinTick 0.01;
    var     
    HiddenOrder 0;
    var     
    FAAccount ""
    var     
    FAGroup "";  
    var     
    FAProfile "";
    var     
    FAMethod "";
    var     
    FAPercentage "";
    var     
    IBCurrency "USD";
    var              
    Rnd2 0.01;

    var 
    bInit false;

    function 
    main() {

      if (!
    bInit ) {

        
    setupMTSVars() ;
        
    debugPrintln(" Symbol Setup MinTick"+MTSMinTick +" Rnd2"+Rnd2+" PointValue"+MTSDollarMult  );
        
    bInit true;
      }

    }




    function 
    setupMTSVars() {
    var 
    line "";
    var 
    PosCount;
    var 
    tsymbol null;
      
    tsymbol getSymbol();
       
    PosCount tsymbol.split(" ");
        if (
    PosCount[0]) { tsymbol PosCount[0]; }


    //  Default all setting to US STOCKS with IB.
    //     debugPrintln("PRE SETUP VARS "+tsymbol);
         
    MTSSymbol tsymbol;  
         
    MTSExchange "SMART";
         
    MTSExpiration "";
         
    MTSType "stock";
         
    MTSDollarMult 1;
         
    MTSMinTick 0.01;
         
    HiddenOrder 0;
         
    FAAccount ""
         
    FAGroup "";  
         
    FAProfile "";
         
    FAMethod "";
         
    FAPercentage "";
         
    IBCurrency "USD";

        var 
    = new File("MENT_CT/MTSSymbolDef.CT");
        if (
    f.exists()) {
          
    f.open("rt");
          while (!
    f.eof()) {
            
    line f.readln();
            if (
    line) {
               
    PosCount line.split(",");
    //           debugPrintln("Checking Symbol :"+PosCount[0]);
               
    if ((tsymbol == PosCount[0])) {  //  Found Symbol
                 
    debugPrintln("Symbol Found "+tsymbol);
                 
    DefaultContracts parseFloat(PosCount[1]);
                 
    MTSSymbol PosCount[2];  
                 
    MTSExchange PosCount[3];
                 
    MTSExpiration PosCount[4];
                 
    MTSType PosCount[5];
                 
    MTSDollarMult parseFloat(PosCount[6]);
                 
    MTSMinTick parseFloat(PosCount[7]);
                 
    IBCurrency PosCount[8];
                 
    Rnd2 parseFloat(PosCount[9]);
    //             HiddenOrder = 0;
    /*             FAAccount = ""; 
                 FAGroup = "";  
                 FAProfile = "";
                 FAMethod = "";
                 FAPercentage = "";*/
               
    }
            }
          }
          
    f.close();
        } 

    }


    function 
    RndQTR(DirectionPriceOffset) {

      var 
    Whole Math.floor(Price);
      var 
    Fraction Price-Whole;

     if (
    Rnd2 == 0.25) {
      if (
    Direction 0) {
        if (
    Fraction 0.76) {  Fraction 1.0
        } else if (
    Fraction 0.51) {  Fraction 0.75
        } else if (
    Fraction 0.26) {  Fraction 0.5
        } else if (
    Fraction >= 0.0) {  Fraction 0.25;  }
       return ((
    Whole+Fraction)+Offset);
      }
      if (
    Direction 0) {
        if (
    Fraction 0.24) {  Fraction 0.0
        } else if (
    Fraction 0.49) {  Fraction 0.25
        } else if (
    Fraction 0.74) {  Fraction 0.5
        } else if (
    Fraction <= 0.99) {  Fraction 0.75;  }
       return ((
    Whole+Fraction)+Offset);
      }

     } else if (
    Rnd2 == 1.0) {
      if (
    Direction 0) {
        return ((
    Whole+1)+Offset);
      }
      if (
    Direction 0) {
        return ((
    Whole)+Offset);
      }

     } else if (
    Rnd2 == 0.1) {
      if (
    Direction 0) {
        
    Fraction Math.floor( ((Fraction 0.05)*10) ) /10 
       return ((
    Whole+Fraction)+Offset);
      }
      if (
    Direction 0) {
        
    Fraction Math.floor( ((Fraction 0.05)*10) ) /10 
       return ((
    Whole+Fraction)+Offset);
      }    
     } else {
       return 
    Price;
     }

    I'll attach the data file in another post.
    Last edited by Doji3333; 08-13-2009, 04:44 PM.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Here is the Data file. In the code, it has to be stored in the C:\programfiles\esignal\formulaoutput\MENT_CT folder.

      SYMBOL,DefContracts,IBSymbol,IBExchange,IBExpirati on,IBType,DollarMult,MinTick,IBCurrency,Rnd2,TimeF ileName
      ES,1,ESU9,GLOBEX,20090918,future,50.0,0.25,USD,0.2 5, PST
      YM,1,YM SEP 09,ECBOT,20090918,future,5.0,1.0,USD,1.0, PST
      NQ,1,NQU9,GLOBEX,20090918,future,20.0,0.25,USD,0.2 5,0.25, PST
      MC,1,EMDU9,GLOBEX,20090918,future,100.0,0.1,USD,0. 1,0.25, PST
      GBP,1,GBP.USD,IDEALPRO,,CASH,100000.0,0.0001,USD,0 .0001,0.25, PST
      EUR,1,EUR.USD,IDEALPRO,,CASH,100000.0,0.0001,USD,0 .0001,0.25, PST
      AUD,1,AUD.USD,IDEALPRO,,CASH,100000.0,0.0001,USD,0 .0001,0.25, PST
      JPY,1,USD.JPY,IDEALPRO,,CASH,10.0,0.0001,JPY,0.000 1,0.25, PST
      HKD,1,USD.HKD,IDEAL,,CASH,1.0,0.0001,HKD,0.0001,0. 25, PST
      CHF,1,USD.CHF,IDEALPRO,,CASH,100000.0,0.0001,CHF,0 .0001,0.25, PST
      CAD,1,USD.CAD,IDEALPRO,,CASH,100000.0,0.0001,CAD,0 .0001,0.25, PST
      EST,1,ESTX50,DTB,20090320,future,10.0,1.0,EUR,1.0, 0.25, PST
      DAX,1,DAX,DTB,20090320,future,25.0,0.50,EUR,0.50,0 .25, PST
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Thanks Doji,

        Where are the Direction and Offset parameters of the RndQTR function getting their values from?

        I'm successfully sourcing the data file...very cool.

        gg

        Comment


        • #5
          Direction and offset are passed with each call to the function. These allow you to round up/down and include a positive or negative offset value.

          Have fun.
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Doji - thanks for all your help thus far...I would not have come up with this stuff on my own (no doubt)...if I could bug you with just a couple of more questions...

            Would you send along an example call to your function?:

            function RndQTR(Direction, Price, Offset)

            I'm not quite clear on what a negative 'Offset' parameter would look like. And 'Direction' - is that just a positive or negative integer (i.e. +1 or -1) - see your latest reply to the thread.

            I apologize for all the questions...I always get turned around when trying to figure the math of points to dollars.

            To that end...in your opinion - was this function (RndQTR) meant to account for the figuring of the real dollar values for all futures/commodities or were you thinking specifically of S&P 500? I mean as is...would it be capable of accurately figuring the dollar value of something like Bonds or T-Bills?...as long as the point value and dollar values were correctly entered into the supporting *.ct file?

            Any help is greatly greatly appreciated,

            Best,

            gg

            Comment


            • #7
              I grabbed this out of one of my projects. You can alter it all you like to address different symbols and rounding needs.

              The variable "Rnd2" originates from the symbol definition file and is use to determine how to round a price value.

              I use this for all order functions, mouse click functions and generally anything that can product a "non-valid" price value.

              Good luck.

              B


              PHP Code:
              function RndQTR(DirectionPriceOffset) {

                var 
              Whole Math.floor(Price);
                var 
              Fraction Price-Whole;

               if (
              Rnd2 == 0.25) {
                if (
              Direction 0) {
                  if (
              Fraction 0.76) {  Fraction 1.0
                  } else if (
              Fraction 0.51) {  Fraction 0.75
                  } else if (
              Fraction 0.26) {  Fraction 0.5
                  } else if (
              Fraction >= 0.0) {  Fraction 0.25;  }
                 return ((
              Whole+Fraction)+Offset);
                }
                if (
              Direction 0) {
                  if (
              Fraction 0.24) {  Fraction 0.0
                  } else if (
              Fraction 0.49) {  Fraction 0.25
                  } else if (
              Fraction 0.74) {  Fraction 0.5
                  } else if (
              Fraction <= 0.99) {  Fraction 0.75;  }
                 return ((
              Whole+Fraction)-Offset);
                }

               } else if (
              Rnd2 == 1.0) {
                if (
              Direction 0) {
                  return ((
              Whole)+Offset);
                }
                if (
              Direction 0) {
                  return ((
              Whole)-Offset);
                }

               } else if (
              Rnd2 == 0.1) {
                if (
              Direction 0) {
                  
              Fraction Math.floor( (Fraction*10) ) /10 
                 return ((
              Whole+Fraction)+Offset);
                }
                if (
              Direction 0) {
                  
              Fraction Math.floor( (Fraction*10) ) /10 
                 return ((
              Whole+Fraction)-Offset);
                }    
               } else {
                 return 
              Price;
               }

              Brad Matheny
              eSignal Solution Provider since 2000

              Comment

              Working...
              X