Announcement

Collapse
No announcement yet.

Any symbol table lookup/storing variables in external file. coding example request

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

  • Any symbol table lookup/storing variables in external file. coding example request

    One issue I'm facing when moving forward with a generalized automated strategy is that the specific Function Parameters Option selected prior to running a backtest (or realtime execution ) is based on the specific symbol and I now do manually via the Edit Chart Options.

    For example:

    SymPre.......Size

    ES..................1
    GBP................25000


    Function parameters are an great feature but unless separate symbol specific strategy EFS's are maintained require manual selection of the parameter option via Chart option Edit Studies each time the study unloaded/reloaded.

    Right now I'm doing some rudimentary "hardcoding":
    PHP Code:
     if (getSymbol() === GBP@FXCM A0-FXvSize 25000;
     if (
    getSymbol() === GBP A0-FXvSize 25000;
     if (
    getSumbol() === EF #F) vSize = 1; 


    I'd like to be able to do a string compare for the first 3 characters and extract values based on that prefix.

    There are several methods and functions available, I was just wondering what others might recommend considering the possible performance implications tick by tick processing.

    If anyone also has an example of storing variables, ie., Position flags, size etc. to an external file for the purpose of being able to synchronize a realtime efs strategy study with the last known position...in the event of a computer failure or running the strategy on another PC that would also be appreciated,,

    Thanks,

    Glen
    Last edited by demarcog; 08-13-2007, 03:29 PM.
    Glen Demarco
    [email protected]

  • #2
    read from CSV files.

    Here ya go.. It's pretty simple.

    Pick a name, create the file in excel (saved as "CSV" type files) and load this type of code in your efs. I normally call this function at the end of preMain().

    Remember, you have to setup the global variables that are read from the file OUTSIDE of MAIN so they are available in global scope.


    PHP Code:

    function ReadCSVData() {
         
    SymbolFound false;
         var 
    = new File("yourCSV.CSV");     
           
    f.open("rt");           
           
         var 
    line;            
         var 
    Pos 0;
         var 
    LastPos;
         var 
    PosCount;
         while((!
    f.eof()) && (!SymbolFound)) {                  
            
    line f.readln();  
        
    //    debugPrintln(line);
           
    if (line) {
            
    PosCount line.split(",");
    //         debugPrintln(PosCount[0]+" : "+PosCount[1]+" : "+PosCount[2]);
           
             // if the symbol matches our current chart symbol && valid line.

            
    if ((PosCount[3] == tsymbol) && (line.length 3)) {
             var 
    tmp = new Object;
             
    tmp.HA_TrdActive PosCount[0];
             
    tmp.HA_TrdShares PosCount[1];
             
    DefEntryContracts Math.floor(tmp.HA_TrdShares.toFixed(0));
             
    tmp.HA_TrdDate PosCount[2];
    // item #3 is the SYMBOL
             
    tmp.HA_Direction PosCount[4];
             
    tmp.HA_Price parseFloat(PosCount[5]);
             
    tmp.HA_Disction parseFloat(PosCount[6]);
             
    tmp.HA_TStopP parseFloat(PosCount[7]);
             
    tmp.HA_ValidUntil parseFloat(PosCount[8]);
             
    tmp.HA_YClose parseFloat(PosCount[9]);
             
    tmp.HA_StartTime parseFloat(PosCount[10]);
             
    tmp.HA_EndTime parseFloat(PosCount[11]);
             
    tmp.HA_EODClose parseFloat(PosCount[12]);
             
    tmp.HA_StopP parseFloat(PosCount[13]);
             
    tmp.HA_SellEOD parseFloat(PosCount[14]);
                
    HA_Array.push(tmp);
                
                
    debugPrintln("Symbol Found! @"+tmp.HA_Price);
                
    SymbolFound true;
            }
           }
         }

    this is how I generate the "tsymbol" variable (which is nothing more than the root symbol.

    PHP Code:
                var tsymbol null;
      
    tsymbol getSymbol();
       
    PosCount tsymbol.split(" ");
        if (
    PosCount[0]) { tsymbol PosCount[0]; } 
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Brad,

      Thanks very much for posting the example it's greatly appreciated and was just what I needed.

      I'm already running the root extract portion and working on storing variables to an external file.

      Here is the code I based on your example, which I'm sure is not the best, but got the job done and feel free to let me know how bad! I wasn't sure of the sequence of altering the contents of the string within the .replace and .split methods, whether it could be done "in-place" using the same variable name for source and target string.

      PHP Code:
                  var sSymbol getSymbol().toUpperCase;
                  var 
      sSymbolroot;
                  
      temproot getSymbol();
                  
      temproot temproot.replace("@"," ");
                  
      temproot temproot.split(" ");
                  
                  
      nDollarPoint 100;        // default $100 per full point 
                  
      if (temproot[0]) {sSymbolroot temproot[0]; }
                  
                  if (
      sSymbolroot === "EUR" || sSymbolroot === "GBP"|| sSymbolroot === "AUD" || sSymbolroot === "CHF" ||
                      
      sSymbolroot === "CAD" || sSymbolroot === "NZD" ||  sSymbolroot === "EURGBP" ||  sSymbolroot === "EURCHF" ||
                      
      sSymbolroot === "GBPCHF") {
                      
      nDollarPoint 100000;
                      
                  }        
                  if (
      sSymbolroot === "JPY" || sSymbolroot === "EURJPY"|| sSymbolroot === "GBPJPY")  {
                      
      nDollarPoint 1000;
                      
                  }    
                  if (
      sSymbolroot === "AB" )  {
                      
      nDollarPoint 100;
                      
                  }                
                  if (
      sSymbolroot === "ES" )  {
                      
      nDollarPoint 50;
                      
                  } 
                   if (
      sSymbolroot === "NQ" )  {
                      
      nDollarPoint 20;
                      
                  }  
                  if (
      sSymbolroot === "YM" )  {
                      
      nDollarPoint 5;
                      
                  } 
      I'm in the process of creating a large table of all the non-equity symbol roots: symbol, decimal places, point value, ticksize, trading hours, etc. It would be great to have a function for example: getSymbolSpecs() that returned an array of the data.
      But not being a "programmer" it would take me a week to do it.

      Thanks again Brad.

      Glen
      Last edited by demarcog; 08-14-2007, 01:46 PM.
      Glen Demarco
      [email protected]

      Comment


      • #4
        Glen,

        That is what my code did. Notice the "object" declaration? that creates an array object that could easily be returned to MAIN.

        Hope you enjoy.
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment

        Working...
        X