public void TickInt() { Tick[] tape = TestBarList.SampleData(); BarListTracker blt = new BarListTracker(new[] { 3 }, new BarInterval[] { BarInterval.CustomTicks }); foreach (Tick k in tape) blt.newTick(k); Assert.AreEqual(4,blt[tape[0].symbol].Count); }
public override void Reset() { // enable prompting of system parameters to user, // so they do not have to recompile to change things ParamPrompt.Popup(this, true,_black); // only build bars for user's interval blt = new BarListTracker(Interval); // only calculate on new bars blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar); }
public SMAResponse(bool prompt) { // enable prompting of system parameters to user, // so they do not have to recompile to change things ParamPrompt.Popup(this,!prompt); // only build bars for user's interval blt = new BarListTracker(Interval); // only calculate on new bars blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar); // set our indicator names, in case we import indicators into R // or excel, or we want to view them in gauntlet or kadina Indicators = new string[] { "SMA" }; }
public void DefaultInt() { BarListTracker blt = new BarListTracker(); blt.GotNewBar+=new SymBarIntervalDelegate(blt_GotNewBar); Tick [] tape = TestBarList.SampleData(); // get second tape and change symbol Tick[] tape2 = TestBarList.SampleData(); for (int i = 0; i<tape2.Length; i++) tape2[i].symbol = "TST2"; // add ticks from both tape to tracker for (int i = 0; i<tape.Length; i++) { blt.newTick(tape[i]); blt.newTick(tape2[i]); } //make sure we got two symbols as bar events Assert.AreEqual(2, syms.Count); // make sure our symbols matched barlist count Assert.AreEqual(blt.SymbolCount, syms.Count); int secondcount = 0; string symstring = string.Empty; foreach (string sym in blt) { secondcount++; symstring += sym; } // make sure enumeration equals symbol count Assert.AreEqual(syms.Count, secondcount); // make sure symbols are there Assert.IsTrue(symstring.Contains("TST") && symstring.Contains("TST2")); // change default interval blt.DefaultInterval = BarInterval.Minute; // make sure same on individual bars Assert.AreEqual(blt.DefaultInterval,blt["TST"].DefaultInterval); Assert.AreEqual(9, blt["TST"].IntervalCount(BarInterval.Minute)); Assert.AreEqual(3, blt["TST"].IntervalCount(BarInterval.FiveMin)); }
/// <summary> /// load previous days bar data from tick files located in tradelink tick folder /// </summary> /// <param name="PreviousDay"></param> /// <param name="syms"></param> /// <param name="AttemptToLoadPreviousDayBars"></param> /// <param name="_blt"></param> /// <param name="NewBarEvents"></param> /// <param name="deb"></param> /// <returns></returns> public static bool LoadPreviousBars(int PreviousDay, string[] syms, bool AttemptToLoadPreviousDayBars, ref BarListTracker _blt, SymBarIntervalDelegate NewBarEvents, DebugDelegate deb) { if (AttemptToLoadPreviousDayBars) { bool errors = false; foreach (string sym in syms) { string fn = Util.TLTickDir + "\\" + sym + PreviousDay + TikConst.DOT_EXT; if (System.IO.File.Exists(fn)) { try { BarList test = BarListImpl.FromTIK(fn); _blt[sym] = BarListImpl.FromTIK(fn, true, false, _blt[sym].CustomIntervals, _blt[sym].Intervals); _blt[sym].GotNewBar += NewBarEvents; if (deb != null) deb(sym + " loaded historical bars from: " + fn); } catch (Exception ex) { errors = true; if (deb != null) { deb(sym + " error loading historical bars from: " + fn); deb(ex.Message + ex.StackTrace); } } } else { errors = true; if (deb != null) { deb(sym + " starting from zero, no historical bar data at: " + fn); } } } return !errors; } return true; }
/// <summary> /// fill bars with arbitrary price data for a symbol /// </summary> /// <param name="sym"></param> /// <param name="prices"></param> /// <param name="startdate"></param> /// <param name="blt"></param> /// <param name="interval"></param> /// <param name="debugs"></param> /// <returns></returns> public static bool backfillbars(string sym, decimal[] prices, int startdate, ref BarListTracker blt, int interval, DebugDelegate debugs) { // ensure we have closing data if (prices.Length == 0) { if (debugs != null) debugs(sym + " no price data provided/available, will have to wait until bars are created from market."); return false; } // get start day int date = startdate; // make desired numbers of ticks DateTime n = DateTime.Now; bool ok = true; for (int i = prices.Length - 1; i >= 0; i--) { // get time now - exitlen*60 int nt = Util.ToTLTime(n.Subtract(new TimeSpan(0, i * interval, 0))); Tick k = TickImpl.NewTrade(sym, date, nt, prices[i], 100, string.Empty); ok &= k.isValid && k.isTrade; blt.newTick(k); } if (ok && (debugs != null)) debugs(sym + " bars backfilled using: " + Calc.parray(prices)); return ok; }
public void setup() { //AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (!isserverconok) { server = new TradeLink.Common.TLServer_WM(); con = new IQFeedHelper(server); con.VerboseDebugging = verbosesetting; con.SendDebug += new DebugDelegate(g.d); // get login information var data = Util.getfile(loginfile, g.d); Assert.IsFalse(string.IsNullOrWhiteSpace(data), "no login info"); var li = data.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(3, li.Length, "missing login info"); // attempt to startup connection con.Start(li[userr], li[pwr], li[prodr], Util.TLBuild()); // wait a moment Util.sleep(4000); Assert.IsTrue(isserverconok, "server connection failed"); } if (isserverconok && !isclientconok) { var c = new TLClient_WM("tempiqclient", false); c.VerboseDebugging = verbosesetting; c.SendDebugEvent += new DebugDelegate(g.d); if (c.ProvidersAvailable[0]!= Providers.IQFeed) throw new Exception("unable to find test server"); c.Mode(0, false); client = c; client.gotUnknownMessage += new MessageDelegate(client_gotUnknownMessage); // verify Assert.IsTrue(isclientconok, "client connection failed"); } // reset everything mt = new MessageTracker(); mt.VerboseDebugging = verbosesetting; blt = new BarListTracker(); mt.BLT = blt; mt.SendDebug += new DebugDelegate(g.d); mt.GotNewBar += new SymBarIntervalDelegate(mt_GotNewBar); recvbarcount = 0; msgok = true; g.d("iqfeed started."); // wait a moment Util.sleep(1000); }
string debug_message_from_constructor = ""; // need to store it and show on 1st tick, otherwise debug messages are wiped out when ticks start to arrive public _TS_step_by_step() : base() { System.Diagnostics.Debug.WriteLine("class _TS_step_by_step constructor entry point"); string[] args = MyGlobals.args; // extract main(args) from MyGlobals (we store main(args) in Kadina Program.cs, ASP, etc.) if (args == null) { throw new Exception("you forgot to set MyGlobals.args (in Kadina or asp or in whatever you use)"); } string response_config = ""; //string storage_service_config_jsonfile = ""; string rabbitmq_config_jsonfile = ""; var p = new OptionSet() { { "a|response-config=", "response json configuration file", v => response_config = v }, //{ "c|storage-service-config=", "path to storage_service json configuration file", // v => storage_service_config_jsonfile = v}, {"r|rabbitmq-config=", "path to rabbitmq json configuration file", v => rabbitmq_config_jsonfile = v} }; // parse cmd-line args List<string> extra; try { extra = p.Parse(args); } catch (OptionException e) { System.Diagnostics.Debug.WriteLine(e.Message); System.Diagnostics.Debug.WriteLine("Try `--help' for more information."); return; } // get settings from json file if (response_config != "") { response_parameters_holder = new ResponseParametersHolder(); response_parameters_holder.parse_json_file(response_config); bson = response_parameters_holder.bson; //_ema_bar = Convert.ToInt32(bson["_ema_bar"]); _ema_bar = BsonSerializer.Deserialize<int>(bson["_ema_bar"].ToJson()); _response_barsize_s = BsonSerializer.Deserialize<int>(bson["_response_barsize_s"].ToJson()); _stop_k = BsonSerializer.Deserialize<double>(bson["_stop_k"].ToJson()); _target_price_k = BsonSerializer.Deserialize<double>(bson["_target_price_k"].ToJson()); //_target_price_k = Convert.ToDouble(bson["_target_price_k"]); // Custom name of response set by you Name = BsonSerializer.Deserialize<string>(bson["name"].ToJson()); //debug_message_from_constructor = "parsed json file - OK (set slow_ma=" + _slow_ma_bar + " fast_ma=" + _fast_ma_bar; //D(debug_message_from_constructor); // wtf? why this message never showed up? seems messages are cleaned right before 1st GotTick(); //ResponseParametersHolder storage_service_parameters_holder = new ResponseParametersHolder(); //storage_service_parameters_holder.parse_json_file(storage_service_config_jsonfile); //storage_service_parameters_bson = storage_service_parameters_holder.bson; ResponseParametersHolder rabbitmq_parameters_holder = new ResponseParametersHolder(); rabbitmq_parameters_holder.parse_json_file(rabbitmq_config_jsonfile); rabbitmq_parameters_bson = rabbitmq_parameters_holder.bson; call_me_from_child_constructor(); } // track_symbols_NewTxt() called when new text label is added track_symbols.NewTxt += new TextIdxDelegate(track_symbols_NewTxt); // Names of the indicators used by your response. Length must correspond to // actual indicator values send with SendIndicators event Indicators = GenericTracker.GetIndicatorNames(gens()); //[_response_barsize_s, 22] track_barlists = new BarListTracker(new int[] { _response_barsize_s, 22 }, new BarInterval[] { BarInterval.CustomTime, BarInterval.CustomTime }); track_barlists.GotNewBar += new SymBarIntervalDelegate(GotNewBar); }
public void DefaultIntervalsAndInitilizedFields() { var blt_t300 = new BarListTracker(new int[] { 300 }, new BarInterval[] { BarInterval.CustomTime }); var blt_v10000 = new BarListTracker(new int[] { 10000}, new BarInterval[] { BarInterval.CustomVol}); g.d(blt_v10000.DefaultInterval.ToString()); g.d(blt_t300.DefaultInterval.ToString()); Assert.AreEqual(blt_v10000.Intervals.Length, blt_v10000.CustomIntervals.Length, "vol mismatch custom/intervals"); Assert.AreEqual(10000, blt_v10000.CustomIntervals[0], "vol wrong interval size"); Assert.AreEqual(BarInterval.CustomVol, blt_v10000.Intervals[0], "vol wrong interval type"); Assert.AreEqual(blt_t300.Intervals.Length, blt_t300.CustomIntervals.Length,"mismatch custom/intervals"); Assert.AreEqual(300, blt_t300.CustomIntervals[0], "wrong interval size"); Assert.AreEqual(BarInterval.CustomTime,blt_t300.Intervals[0] , "wrong interval type"); }
public void Initialize() { dailyBarTracker = new BarListTracker(BarInterval.Day); intraBarTracker = new BarListTracker(BarInterval.FiveMin); }
/// <summary> /// fill bars with arbitrary price data for a symbol /// </summary> /// <param name="sym"></param> /// <param name="prices"></param> /// <param name="startdate"></param> /// <param name="blt"></param> /// <param name="interval"></param> /// <param name="debugs"></param> /// <returns></returns> public static bool backfillbars(string sym, decimal[] prices, int startdate, int starttime, ref BarListTracker blt, int interval, DebugDelegate debugs) { // ensure we have closing data if (prices.Length == 0) { if (debugs != null) debugs(sym + " no price data provided/available, will have to wait until bars are created from market."); return false; } // make desired numbers of ticks DateTime n = Util.ToDateTime(startdate, starttime); bool ok = true; List<string> bfd = new List<string>(); for (int i = prices.Length - 1; i >= 0; i--) { // get time now - exitlen*60 var ndt = n.Subtract(new TimeSpan(0, i * interval, 0)); int nt = Util.ToTLTime(ndt); int nd = Util.ToTLDate(ndt); Tick k = TickImpl.NewTrade(sym, nd, nt, prices[i], 100, string.Empty); ok &= k.isValid && k.isTrade; bfd.Add(nd.ToString() + nt.ToString() + "=" + prices[i]); if (i <= 2) debugs(nd + " " + nt); blt.newTick(k); } if (ok && (debugs != null)) debugs(sym + " bars backfilled using: " + Util.join(bfd)); return ok; }