Announcement

Collapse
No announcement yet.

Changing the filename

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

  • Changing the filename

    Hello,

    How do I change the file name in the code instead of the variable declaration?

    Here is my code:
    var f = new File( "newsymbol.txt" );
    var counter = 0;
    var newDateObject = new Date(year, month, day);

    function main()
    {
    var nNumberBars;
    var nBarIndex = getCurrentBarIndex();
    var nBarState = getBarState();

    nNumberBars = getNumBars();



    if ((nBarIndex==0) && (nNumberBars != 0) )
    {
    f = sym + ".txt";
    f.open( "wt" );
    counter = 0;
    while (counter != nNumberBars)
    {
    // debugPrintln("open2=",newDateObject);
    f.writeln(getYear(counter)+ "/" + getMonth(counter) + "/" + getDay(counter)+","+open(counter).toFixed(4) +",",high(counter).toFixed(4)+","+low(counter).toF ixed(4)+","+close(counter).toFixed(4));
    counter = counter - 1;
    }
    }
    f.close;
    return(0);

  • #2
    Hi,

    I didn't test it but this should work:
    PHP Code:
    var f;
     var 
    counter 0;
     var 
    newDateObject = new Date(yearmonthday);

     function 
    main() 
     {
     var 
    nNumberBars;
     var 
    nBarIndex getCurrentBarIndex(); 
     var 
    nBarState getBarState(); 

     
    nNumberBars getNumBars();



     if ((
    nBarIndex==0) && (nNumberBars != 0) )
     {
     
    = new Filesym ".txt" );
     
    f.open"wt" ); 
     
    counter 0
     while (
    counter != nNumberBars)
     {
     
    // debugPrintln("open2=",newDateObject);
     
    f.writeln(getYear(counter)+ "/" getMonth(counter) + "/" getDay(counter)+","+open(counter).toFixed(4) +",",high(counter).toFixed(4)+","+low(counter).toF ixed(4)+","+close(counter).toFixed(4));
     
    counter counter 1;
     } 
     } 
     
    f.close;
     return(
    0); 
    Wayne

    Comment


    • #3
      Says f is undefined

      Comment


      • #4
        Thus the need for testing. Since I didn't change the original script other than code specific to your question: creating the file object, the syntax error +",", wasn't addressed and the variable "sym" was never defined, one of your ...toFixed(... had a space as in: ...toF ixed(..., and last corrected the newDateObject equality functions. See http://kb.esignalcentral.com/article...ticle=1206&p=4 and KB for explanation and syntax for these functions.
        PHP Code:
        var counter 0;

        function 
        main() {
            var 
        f;
            var 
        newDateObject = new Date(year(0), month(0), day(0));
            var 
        nNumberBars;
            var 
        nBarIndex getCurrentBarIndex();
            var 
        nBarState getBarState();

            
        nNumberBars getNumBars();



            if ((
        nBarIndex == 0) && (nNumberBars != 0)) {
                
        = new File(getSymbol() + ".txt");
                if(!
        f.isOpen()) f.open("wt");
                
        counter 0;
                while (
        counter != nNumberBars) {
                    
        //debugPrintln("open2= ",newDateObject);
                    
        f.writeln(getYear(counter) + "/" getMonth(counter) + "/" getDay(counter) + "," open(counter).toFixed(4) + "," high(counter).toFixed(4) + "," low(counter).toFixed(4) + "," close(counter).toFixed(4));
                    
        counter counter 1;
                }
                
        f.close;
            }
             return (
        0);

        Last edited by waynecd; 05-13-2013, 07:23 PM.

        Comment


        • #5
          FWIW: to avoid the while loop from executing on every tick I added a flag to allow only one iteration of the if... while... loop and since (I assume) it should only run on a daily interval I added an interval check.

          PHP Code:
          var counter 0;
          var 
          bInit=false;;
          var 
          stopFlag=0;//added to stop execution once the file is created
          function main() {
              if (!
          isDaily()) {//code from http://forum.esignal.com/showthread.php?38596-Working-with-Futures-Volume-data
                  
          if(!bInit) {//added since it requires a daily interval
                      
          addEntitlement("DailyValues""This study requires a dialy interval");
                      
          bInit true;
                  }
                  return;
              }
              var 
          f;
              var 
          newDateObject = new Date(year(0), month(0), day(0));
              var 
          nNumberBars;
              var 
          nBarIndex getCurrentBarIndex();
              var 
          nBarState getBarState();
              
          nNumberBars getNumBars();

              if (
          nBarIndex == && nNumberBars != && stopFlag != 1) {
                  
          = new File(getSymbol() + ".txt");
                  if(!
          f.isOpen()) f.open("wt");
                  
          counter 0;
                  while (
          counter != -nNumberBars) {
                      
          //debugPrintln("open2= ",newDateObject);
                      
          f.writeln(getYear(counter) + "/" getMonth(counter) + "/" getDay(counter) + "," open(counter).toFixed(4) + "," high(counter).toFixed(4) + "," low(counter).toFixed(4) + "," close(counter).toFixed(4));
                      
          counter counter 1;
                  }
                  
          f.close();
                  
          stopFlag=1;
              }
              return (
          0);

          Comment

          Working...
          X