Announcement

Collapse
No announcement yet.

Open file function failing in build 635

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

  • Open file function failing in build 635

    I upgraded over the weekend to build 635, from I think it was 455. The function below worked fine in the older build, now I get an error:

    "Line type has no properties"

    This is pertaining to my variable "line". Can someone tell me what I am doing wrong?

    // REMOTE COMMAND VARIABLES (READ ON EACH TICK)
    var cmd = new File("stops_tick.txt");
    var line=0;
    var levels=0;
    var version=0;
    var version_in=0;
    var stop_norm_long_in=0;
    var stop_norm_short_in=0;
    var tick_live_fl_in=0;
    var scalp_fl_in=0;
    var line_ctr=0;

    // GET REMOTE COMMANDS
    cmd.open("rt");

    line_ctr=0;
    while(!cmd.eof()) {
    if (line_ctr==0) {
    line = cmd.readln();
    levels = line.split(",",8);
    version_in=levels[1];
    trade_stop_long_in=levels[3];
    trade_stop_short_in=levels[5];
    tick_live_fl_in=levels[7];
    line_ctr=1;
    }
    if (line_ctr==1) {
    line = cmd.readln();
    levels = line.split(",",2);
    scalp_fl_in=levels[1];
    }
    }

    cmd.close();

    if (version_in!=version) {
    version=version_in;
    trade_stop_long=trade_stop_long_in;
    trade_stop_long_intra=trade_stop_long_in;
    trade_stop_short=trade_stop_short_in;
    trade_stop_short_intra=trade_stop_short_in;
    tick_live_fl=tick_live_fl_in;
    scalp_fl=scalp_fl_in;
    f2.writeln("*** STOP CHANGE FROM INPUT FILE *** HAPPENED AT " + timestamp);
    }

    Thanks as always . . .

    Thomas.

  • #2
    Thomas:

    The only thing I can think of is to check the value of "line" for a null value before attempting the "line.split()" calls. If it is null (e.g., because of a blank line in the input file), that would definitely cause that kind of error.

    Chris

    Comment


    • #3
      Thomas,

      I modified your code slightly to output troubleshooting info to a file.

      Replace your code section with the modified code. Declare the proper globals that are identified. Place the function either before premain or after main.

      Run the efs. All pertinant information before your error will be saved in the file in your formula output directory. This should identify what is causing your error. The file name will be Trace Thomas.txt. Please let me know if there are any problems with how it runs, and what you find.

      PHP Code:
      //############ global variables required above premain #############
      var tracedata = new Array();
      var 
      traceon true;//tracefile is only created if it is called, this is a flag to create file
      var nStudy "Thomas";
      var    
      tracefile = new File("Trace "+nStudy+".txt");
      //############ global variables required above premain ############



      // REMOTE COMMAND VARIABLES (READ ON EACH TICK)
      var cmd = new File("stops_tick.txt");trace("0: cmd =  "+cmd);trace("save");
      var 
      line=0;
      var 
      levels=0;
      var 
      version=0;
      var 
      version_in=0;
      var 
      stop_norm_long_in=0;
      var 
      stop_norm_short_in=0;
      var 
      tick_live_fl_in=0;
      var 
      scalp_fl_in=0;
      var 
      line_ctr=0;

      // GET REMOTE COMMANDS
      var cmd.open("rt");    trace("1: did file open correctly? "+a);trace("save");

      line_ctr=0
      while(!
      cmd.eof()) {    trace("2: end of file? "+cmd.eof());trace("save");
      if (
      line_ctr==0) {trace("3: line_ctr = "+line_ctr);trace("save");
      line cmd.readln();trace("4: line = "+line);trace("save");
      levels line.split(",",8);trace("5: levels = "+levels);trace("save");
      version_in=levels[1];trace("6: version_in = "+version_in);trace("save");
      trade_stop_long_in=levels[3];trace("7: trade_stop_long_in = "+trade_stop_long_in);trace("save");
      trade_stop_short_in=levels[5];trace("8: trade_stop_short_in = "+trade_stop_short_in);trace("save");
      tick_live_fl_in=levels[7];trace("9: tick_live_fl_in = "+tick_live_fl_in);trace("save");
      line_ctr=1trace("10: line_ctr = "+line_ctr);trace("save");
      }
      if (
      line_ctr==1) {trace("11: line_ctr = "+levels);trace("save");
      line cmd.readln();trace("12: line = "+line);trace("save");
      levels line.split(",",2);trace("13: levels = "+levels);trace("save");
      scalp_fl_in=levels[1];trace("14: scalp_fl_in = "+scalp_fl_in);trace("save");

      }

      var 
      cmd.close();trace("15: did file close correctly? "+b);trace("save");


      if (
      version_in!=version) {
      version=version_in;
      trade_stop_long=trade_stop_long_in;
      trade_stop_long_intra=trade_stop_long_in;
      trade_stop_short=trade_stop_short_in;
      trade_stop_short_intra=trade_stop_short_in;
      tick_live_fl=tick_live_fl_in;
      scalp_fl=scalp_fl_in;
      f2.writeln("*** STOP CHANGE FROM INPUT FILE *** HAPPENED AT " timestamp);
      }


      //place before premain or after main
      //########### function required to be copied complete ##############
      function trace(data1){//routine that saves the data
          
      if(data1==null){return;}
          
      tracedata.push(data1);//adds datapoint to array
          
      if(data1 == "save"){//section saves data to a file
              
      if (traceon){//first use is true, creates file only if feature is used
                  
      traceon false;
                  
      tracefile.open("wt+");tracefile.close();//opens and overwrites previous file
              
      }
              
      tracedata.pop();//removes "save" from array
              
      tracefile.open("at+");tracefile.writeln(tracedata);tracefile.close();
              while (
      tracedata.length0){tracedata.pop();}//removes all data from array
          
      }
      }
      //########## function required to be copied complete ################ 

      Comment


      • #4
        cool, will do . . .

        Thanks Steve, I will check this out tonight . . . .

        T

        Comment

        Working...
        X