1 #region Using statements 2 using System; 3 //using System.Drawing; 4 using System.Collections.Generic; 5 using System.IO; // StreamWriter 6 using System.Text; // StringBuilder 7 using System.Globalization; // CultureInfo 8 using RightEdge.Common; 9 #endregion 10 11 #region System class 12 public class MySystem : MySystemBase 13 { 14 public string destFolder = @"D:\data\nick\ascii"; // Destination Folder 15 public string dateFormat = "yyyy-MM-dd"; 16 public char separator = ';'; 17 // stats 18 public int numFiles = 0; 19 public int numBars = 0; 20 public override void Startup() 21 { } 22 23 public override void Shutdown() 24 { 25 foreach(MySymbolScript mySymScr in this.SymbolScripts) 26 { 27 mySymScr.Shutdown(); 28 } 29 Console.WriteLine(numBars.ToString() 30 + " bars written to " 31 + numFiles 32 + " files in Folder " 33 + destFolder); 34 } 35 } 36 #endregion 37 38 public class MySymbolScript : MySymbolScriptBase 39 { 40 StreamWriter sw = null; 41 char sep; 42 43 public override void Startup() 44 { 45 sep = TradingSystem.separator; 46 string path = Path.Combine(TradingSystem.destFolder, 47 Symbol.Name + ".csv"); 48 sw = new StreamWriter(path); 49 TradingSystem.numFiles++; 50 sw.WriteLine("Date{0}Open{0}High{0}Low{0}Close{0}Volume{0}", sep); 51 } 52 53 public override void NewBar() 54 { 55 BarData bar = Bars.Current; 56 if(bar.EmptyBar) return; 57 58 StringBuilder line = new StringBuilder(); 59 60 line.Append(bar.PriceDateTime.ToString(TradingSystem.dateFormat)); 61 line.Append(sep); 62 line.Append(bar.Open.ToString("f4", CultureInfo.InvariantCulture)); 63 line.Append(';'); 64 line.Append(bar.High.ToString("f4", CultureInfo.InvariantCulture)); 65 line.Append(';'); 66 line.Append(bar.Low.ToString("f4", CultureInfo.InvariantCulture)); 67 line.Append(';'); 68 line.Append(bar.Close.ToString("f4", CultureInfo.InvariantCulture)); 69 line.Append(';'); 70 line.Append(bar.Volume.ToString("f4", CultureInfo.InvariantCulture)); 71 line.Append(';'); 72 sw.WriteLine(line.ToString()); 73 TradingSystem.numBars++; 74 } 75 76 public void Shutdown() 77 { 78 if(sw != null) sw.Close(); 79 } 80 } 81