title: How to continuously export data from Amibroker
body: <p>Need to test an algotrading tool to be used for day trading. To get the intra-day live data from <a href="http://www.nseindia.com/index_nse.htm" rel="nofollow">NSE</a>, some <a href="http://www.jetlivedata.com/Aboutus.aspx" rel="nofollow">vendors</a> are selling data plugins for <a href="http://www.amibroker.com/devlog/2006/12/15/amibroker-development-kit-adk-for-cc-now-available-to-everyone/" rel="nofollow"><strong>Amibroker</strong></a>. To get the data out of <kbd>Amibroker</kbd> I intend to use <strong><code>AFL</code></strong> ( Amibroker Formula Language ). The following <a href="http://www.amibroker.com/library/detail.php?id=1129" rel="nofollow">code</a> in <code>AFL</code> creates the <strong><code>.csv</code></strong> files for each symbol once. But to use the live data I need to append incoming data to the <code>.csv</code> file continuously throughout the day. How can this be done without crashing / overloading <kbd>Amibroker</kbd>?</p>
  
  <pre><code>// created a directory on your C drive named AmiBroker data backup
  dayhours = paramtoggle("Day hours only", "No|Yes");
  fmkdir("c:\\AmiBackup\\");
  setbarsrequired(100000,100000);
  lname = Name(); // gets the name of the symbol
  // note: if you have names with invalid characters like / you must rename the
  file before you try to create a name 
  // add an IF line for each symbol you need to rename
  if (lname == "ER2U8-GLOBEX-FUT") lname = "ER2U8";
  
  fh = fopen( "c:\\AmiBackup\\" + lname + ".csv", "w"); 
  if( fh ) 
  { 
      if(interval() == inDaily OR interval() == inMonthly OR interval() == inweekly)
      {
          fputs( "Ticker,Date,Open,High,Low,Close,Volume \n", fh ); 
          for( i = 0; i &lt; BarCount; i++ ) 
          { 
              y = Year(); 
              m = Month(); 
              d = Day(); 
              fputs( Name() + "," , fh );
              ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ i ] ); 
              fputs( ds, fh ); 
              qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
  ],V[ i ] ); 
              fputs( qs, fh ); 
              if(i == 65500 or i == 130000 or i == 196500 or i == 262000)
              {
                  fclose( fh ); 
                  if(i == 65500  ) fh = fopen( "c:\\AmiBackup\\" + lname + " A.csv", "w"); 
                  if(i == 130000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " B.csv", "w"); 
                  if(i == 196500 ) fh = fopen( "c:\\AmiBackup\\" + lname + " C.csv", "w"); 
                  if(i == 262000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " D.csv", "w"); 
              }
          }
      }
      else // intraday so add time field
      {
          fputs( "Ticker,Date,Time,Open,High,Low,Close,Volume \n", fh ); 
          y = Year(); 
          m = Month(); 
          d = Day(); 
          r = Hour();
          e = Minute();
          n = Second();
  
          for( i = 1; i &lt; BarCount; i++ ) 
          { 
              if (dayhours and lastvalue(timenum()) &gt;= 92900 and lastvalue(timenum()) &lt;=
  161500)
              { 
                  fputs( Name() + "," , fh );
                  ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ i ] ); 
                  fputs( ds, fh ); 
  
                  ts = StrFormat("%02.0f:%02.0f:%02.0f,", r[ i ],e[ i ],n[ i ] ); 
                  fputs( ts, fh ); 
  
                  qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
  ],V[ i ] ); 
                  fputs( qs, fh ); 
              }
              else
              { 
                  fputs( Name() + "," , fh );
                  ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ i ] ); 
                  fputs( ds, fh ); 
  
                  ts = StrFormat("%02.0f:%02.0f:%02.0f,", r[ i ],e[ i ],n[ i ] ); 
                  fputs( ts, fh ); 
  
                  qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
  ],V[ i ] ); 
                  fputs( qs, fh ); 
              }
              if(i == 65500 or i == 130000 or i == 196500 or i == 262000)
              {
                  fclose( fh ); 
                  if(i == 65500  ) fh = fopen( "c:\\AmiBackup\\" + lname + " A.csv", "w"); 
                  if(i == 130000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " B.csv", "w"); 
                  if(i == 196500 ) fh = fopen( "c:\\AmiBackup\\" + lname + " C.csv", "w"); 
                  if(i == 262000 ) fh = fopen( "c:\\AmiBackup\\" + lname + " D.csv", "w"); 
              }
          } 
      }
      fclose( fh ); 
  } 
  
  Buy = 1;
  </code></pre>