Announcement

Collapse
No announcement yet.

f.write() writes too many lines

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

  • f.write() writes too many lines

    Hi,

    I would expect the following code to write only one line to the csv file but it writes 600 lines on a 55T chart and more on a 1min chart (ES #F). The above is measured as soon as the efs is loaded and since it was run about 3 AM a new bar was never created. So, 600 lines were written just by loading the efs even though there is a counter limit of 1 iteration.

    I'm testing this method so when a real time buy, sell, stop, etc signal is triggered it writes pertinent trade information into one line in the csv file.

    Attached is the csv file from efs running the code below on a 55T chart of ES #F.

    Any help is appreciated.

    Wayne

    PHP Code:

    //http://forum.esignalcentral.com/showthread.php?s=&postid=110331#post110331
    debugClear();
    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("file creation test");
        
    setShowCursorLabel(false); 
    }

    var 
    bInit false;
    var 
    vToday = new Date();
    var 
    AuditTrailFile "writetxtfiletest.txt";
    var 
    CSVFile "writecsvfiletest.csv";
    var 
    vCounter 0;

    function 
    main(){
        if (!
    bInit){

        }
        if (
    getBarState()==BARSTATE_ALLBARS) return;
        if (
    getBarState()==BARSTATE_NEWBAR){
            if(
    vCounter <=0){
                
    vText = (vToday.getFullYear(0)+"/"+vToday.getMonth(0)+"/"+vToday.getDate(0)+" - "+
                            
    hour(0)*100+minute(0)+":"+vToday.getSeconds(0)+
                            
    " Ask- "+getMostRecentAsk()+" Bid- "+getMostRecentBid()+" Price- "+getMostRecentTrade());
                
    efsInternal"fWriteAuditTrail"vText ); 
                
    efsInternal"fWriteCSVFile"vText,close(0) ); 
                
    vCounter++
    debugPrintln(vCounter);
            }
        }
    }

    function 
    fWriteAuditTrail(vText) {
            var 
    = new File(AuditTrailFile);
            
    f.open("at");
            
    f.write(vText+"\n");
            
    f.close();
    }

    function 
    fWriteCSVFile(vTextAmount) {
            var 
    = new File(CSVFile);
            
    f.open("at");
            
    f.write(vText+" Close("+Amount+")"+"\n");
            
    f.close();

    Attached Files
    Last edited by waynecd; 12-05-2008, 01:42 AM.

  • #2
    Hi Wayne, your use of efsInternal() looks odd to me. efsInternal() creates a series and it does so for EVERY different set of arguments you pass (you change the arguments at every call I think), as it thinks each set of different arguments represents a different series that needs creating (like say "rsi(14)", "rsi(15)", rsi(16)" ...). And for each series you thus create the function is called for every historic bar and every tick to create the actual returned data. Thus your function gets called a lot. Been there, done that, if only eSignal had some real documentation.

    ps: and you don't update your vToday - you won't get current time unless you do. And unless your PC is very well time-synced and you don't mind about transmission delays, don't you want to use the actual data time stamps? If so create a series like "mxOneSecondSeries = inv("1S")" so that you can access one-second candle time stamps from the actual data (and I would then use rawtime(0,mxOneSecondSeries) rather than getSecond(0,mxOneSecondSeries) etc and stick to UTC but that's a matter of european taste perhaps).
    Last edited by Dave180; 12-05-2008, 03:13 AM.

    Comment


    • #3
      Hi Dave,

      I think then, I should put the file calls in the function main() where I want it executed using the rawtime(0) series for a time stamp.

      Hopefully I understood your suggestions correctly.

      Thanks for the info.

      Wayne

      Comment


      • #4
        Wayne, not sure I understand the reply. I don't think you need to put anything in main(), just lose the efsInternal() - what purpose do you think it serves?

        Leave the timestamps until you have sorted the writes.

        Comment


        • #5
          Hi Dave,

          I do need to understand better how to use the efsinternals and what the expected outcomes should be. eSignal is my first real attempt at programing, so I have no background to lean on. I suffer from alot of trial and error.

          I used the efsInternal because I would write a line to the csv file every time a buy, sell, stop, trailing stop adjustment, etc is triggered by the efs. So, I thought that by putting the file write code in an efsInternal() it would be more efficient than writing the file write code for each instance a trade or trade modification is triggered. I'm trying to write an efs for testing trading strategies real time.

          This is what I meant (and as you stated it prints only one line):

          PHP Code:
          //http://forum.esignalcentral.com/showthread.php?s=&postid=110331#post110331
          debugClear();
          function 
          preMain() {
              
          setPriceStudy(true);
              
          setStudyTitle("file creation test");
              
          setShowCursorLabel(false); 
          }

          var 
          bInit false;
          var 
          vToday = new Date();
          var 
          AuditTrailFile "writetxtfiletest.txt";
          var 
          CSVFile "writecsvfiletest.csv";
          var 
          vCounter 0;

          function 
          main(){
              if (!
          bInit){

              }
              if (
          getBarState()==BARSTATE_ALLBARS) return;
              if (
          getBarState()==BARSTATE_NEWBAR){
                  if(
          vCounter <=0){
                      
          vText = (vToday.getFullYear(0)+"/"+vToday.getMonth(0)+"/"+vToday.getDate(0)+" - "+
                                  
          hour(0)*100+minute(0)+":"+vToday.getSeconds(0)+
                                  
          " Ask- "+getMostRecentAsk()+" Bid- "+getMostRecentBid()+" Price- "+getMostRecentTrade());
          //placing the file write calls here in main()
                  
          var = new File(AuditTrailFile);
                  
          f.open("at");
                  
          f.write(vText+"\n");
                  
          f.close();
                  var 
          = new File(CSVFile);
                  
          f.open("at");
                  
          f.write(vText+" Close("+close(0)+")"+"\n");
                  
          f.close();
                      
          vCounter++
          debugPrintln(vCounter);
                  }
              }

          Last edited by waynecd; 12-05-2008, 11:04 AM.

          Comment


          • #6
            Wayne, two things
            If I was asked "What language should I use to learn to program?" then eSignal EFS would be the LAST recommendation. If you need to learn you need a nice "IDE" - an Integrated Development Environment - you need an editor with better hints and an integrated debugger is essential. Well, there are still some of us who managed with paper tape and the punched cards, but the languages and environment were simpler. The JS language in the efs environment is complex and one of the worst documented (in terms of real world and complex usage).

            I don't know the MS .Net, but the old VB6 with integrated edit & debug is a great tool for fast "learn and design on the fly" development (no arguments about inheritance etc please from other programmers, that's 2nd-order in this discussion!). There may be other languages better suited for learning.

            As for your code - well it has more chance of working, but because you moved from using a function accessed via efsInternal() to inline code shows you really haven't got the hang of this.

            If you want to continue to learn using efs I suggest you write it virtually one line at a time with a debug statement to check each one does exactly what you suspect. Develop and test short sections one by one. Run with a fixed, short time template (or consider tick replay, but that can cause other probs).

            Comment


            • #7
              Hi Dave,

              Thanks for the info. That would be a good way to learn to program efs code better. It will take some time.

              I meant to move the "var vToday = new Date();" back into main()/inline (just a correction to the code I posted before).

              As for your code - well it has more chance of working, but because you
              moved from using a function accessed via efsInternal() to inline code shows
              you really haven't got the hang of this.
              To understand the above:
              Is there a different way to use the function other than inline or via efsInternal()/efsExternal()?
              Last edited by waynecd; 12-05-2008, 03:35 PM.

              Comment


              • #8
                Hi Dave,

                If you need to learn you need a nice "IDE" - an Integrated Development Environment - you
                need an editor with better hints and an integrated debugger is essential.
                Well, there are still some of us who managed with paper tape and the punched
                cards, but the languages and environment were simpler. The JS language in the
                efs environment is complex and one of the worst documented (in terms of real
                world and complex usage).
                Any recommendations?
                Also, which of the IDEs would be compatible with JS for efs coding or are they all incompatible?

                Thanks for your time.

                Wayne
                Last edited by waynecd; 12-05-2008, 03:33 PM.

                Comment


                • #9
                  Wayne,
                  IDE - I don't do JS except in EFS, so there will be some tools for learning JS bit I don't know them, and they won't help with the EFS side of things.

                  Re efsInternal(). The question is better put - "Why do you think that inline or efsInternal() are the only alternatives?". This is not an easy medium to sort this out, the point is that you just write a fuction and call it, efsInternal() turns your function (if appropriately written) into a series object (in EFS speak), like a built-in series such as rsi(), it is not used in normal function calling, you shoudn't be thinking about using it at all yet. You have to sort that out before you can progress.

                  I suggest you download some samples from the file library thing, or from attachments to posts. The stuff Jason writes is usually pretty good, and most stuff posted works, but there are some terrible examples of bad practice in terms of inefficiency that might lead you to pick up bad habits, so beware.

                  Comment


                  • #10
                    Dave thanks.

                    I think I finally get what you are saying.

                    Instead of using efsInternal() for say:

                    PHP Code:
                    function main(){
                    var 
                    xx efsInternal("sumit",5,6);
                    }

                    function 
                    sumit(a,b){
                       return 
                    a+b;

                    Just call it by:

                    PHP Code:
                    function main(){
                    var 
                    xx sumit(5,6);
                    }

                    function 
                    sumit(a,b){
                       return 
                    a+b;

                    So easy yet it escaped me before for some reason.
                    Great help, thanks
                    Last edited by waynecd; 12-05-2008, 03:44 PM.

                    Comment


                    • #11
                      good, proceed with caution, remember efs and js are full of surprises, use copious debugPrint()s, possibly with a few buttons that allow you to switch a debug flag or two on and off to help manage the verbose output. There is some tutorial stuff somewhere which might be worth a read/ watch. Unfortunately I think it covers the "obvious" but skips the awkward. And Steve who posts writes good code, have a look at his perhaps, and there are others of course.

                      Comment


                      • #12
                        Thanks,

                        You are right, Steve is a geat help and writes excellent code. So is Alexis.
                        Last edited by waynecd; 12-05-2008, 06:25 PM.

                        Comment

                        Working...
                        X