Example #1
0
        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);

            Int32 numOfInterval = 1;

            BarInterval[] intervaltypes  = new BarInterval[numOfInterval];
            Int32[]       intervalValues = new Int32[numOfInterval];
            for (Int32 i = 0; i < numOfInterval; i++)
            {
                intervaltypes[i]  = BarType;
                intervalValues[i] = NumItemPerBar;
            }

            _blt = new BarListTracker(intervalValues, intervaltypes);

            _blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar);

            GenericParamUpdateHelper.updateParam(this, GenericParameter, false);

            Hashtable TD_combinationInputParamTmp = new Hashtable();

            TD_combinationInputParamTmp["lookbackperiod"]     = _barsback;
            TD_combinationInputParamTmp["minmumsignallength"] = _barsback;
            _TD_combinationFromATSGlobalIndicator             = new ATSGlobalIndicatorPersonal.TD_combination();
            _TD_combinationFromATSGlobalIndicator.Param       = TD_combinationInputParamTmp;
            _TD_combinationFromATSGlobalIndicator.Initializatin();
            _isShutDown = false;
            TotalProfit = 0m;
            _pt.Clear();
        }
Example #2
0
        public override void Reset(bool popup = true)
        {
            // one day bar
            _barlisttracker            = new BarListTracker(_symbols.ToArray(), 86400);
            _barlisttracker.GotNewBar += _barlisttracker_GotNewBar;

            emailsent_ = 0;
        }
Example #3
0
        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);

            Int32 numOfInterval = 1;

            BarInterval[] intervaltypes  = new BarInterval[numOfInterval];
            Int32[]       intervalValues = new Int32[numOfInterval];
            for (Int32 i = 0; i < numOfInterval; i++)
            {
                intervaltypes[i]  = BarType;
                intervalValues[i] = NumItemPerBar;
            }

            _blt = new BarListTracker(intervalValues, intervaltypes);

            _blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar);

            #region <在策略中实现从外部文件读取参数>
            //传递优化参数或系统参数
            GenericParamUpdateHelper.updateParam(this, GenericParameter, false);
            if (File.Exists(SMAExternalParam))
            {
                DataTable    paramTableInput = null;
                StreamReader sr = new StreamReader(SMAExternalParam, Encoding.GetEncoding("GB18030"));
                paramTableInput = CsvParser.Parse(sr, true);
                sr.Close();
                foreach (DataRow dr in paramTableInput.Rows)
                {
                    if (paramTableInput.Columns.Contains("key") && paramTableInput.Columns.Contains("value"))
                    {
                        string tmpKey   = dr["key"].ToString();
                        string tmpValue = dr["value"].ToString();
                        if (tmpKey == "genericparam")
                        {
                            GenericParameter = tmpValue;
                        }
                        //传递外部参数
                        GenericParamUpdateHelper.updateParam(this, GenericParameter, false);
                    }
                }
            }
            #endregion

            Hashtable SMAInputParamTmp = new Hashtable();
            SMAInputParamTmp["lookbackperiod"]     = _barsback;
            SMAInputParamTmp["minmumsignallength"] = 1;
            _SMAFromATSGlobalIndicator             = new ATSGlobalIndicatorPersonal.SMA();
            _SMAFromATSGlobalIndicator.Param       = SMAInputParamTmp;
            _SMAFromATSGlobalIndicator.Initializatin();
            _isShutDown = false;
            TotalProfit = 0m;
            _pt.Clear();
        }
Example #4
0
        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);
        }
Example #5
0
        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 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);

            Int32 numOfInterval = 1;

            BarInterval[] intervaltypes  = new BarInterval[numOfInterval];
            Int32[]       intervalValues = new Int32[numOfInterval];
            for (Int32 i = 0; i < numOfInterval; i++)
            {
                intervaltypes[i]  = BarType;
                intervalValues[i] = NumItemPerBar;
            }

            _blt = new BarListTracker(intervalValues, intervaltypes);

            _blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar);

            GenericParamUpdateHelper.updateParam(this, GenericParameter, false);

            Hashtable ShortSMAInputParamTmp = new Hashtable();   //对于SMA indicator进行更新,用今天重新计算的SMA,而不用昨天
            Hashtable LongSMAInputParamTmp  = new Hashtable();

            ShortSMAInputParamTmp["lookbackperiod"]     = _shortbarsback;
            LongSMAInputParamTmp["lookbackperiod"]      = _shortbarsback + _incrementbarsback;
            ShortSMAInputParamTmp["minmumsignallength"] = _shortbarsback;
            LongSMAInputParamTmp["minmumsignallength"]  = _shortbarsback + _incrementbarsback;
            _ShortSMAFromATSGlobalIndicator             = new ATSGlobalIndicatorPersonal.SMA();
            _LongSMAFromATSGlobalIndicator        = new ATSGlobalIndicatorPersonal.SMA();
            _ShortSMAFromATSGlobalIndicator.Param = ShortSMAInputParamTmp;
            _LongSMAFromATSGlobalIndicator.Param  = LongSMAInputParamTmp;
            _ShortSMAFromATSGlobalIndicator.Initializatin();
            _LongSMAFromATSGlobalIndicator.Initializatin();
            // reset the parameters of ATR
            Hashtable ATRInputParamTmp = new Hashtable();

            ATRInputParamTmp["lookbackperiod"]     = _shortbarsback;
            ATRInputParamTmp["minmumsignallength"] = 14;
            _ATRFromATSGlobalIndicator             = new ATSGlobalIndicatorPersonal.ATR();
            _ATRFromATSGlobalIndicator.Param       = ATRInputParamTmp;
            _ATRFromATSGlobalIndicator.Initializatin();
            //---------------------------------------------------------
            _isShutDown = false;
            TotalProfit = 0m;
            _pt.Clear();
            if (_shortbarsback != 34 || _incrementbarsback != 84)
            {
                Console.WriteLine("yo hey");
            }
        }
Example #8
0
        /// <summary>
        /// This is called after StrategySetter updates _symbol list
        /// </summary>
        /// <param name="popup"></param>
        public override void Reset(bool popup = true)
        {
            _positiontracker           = new PositionTracker(_symbols.Count);
            _barlisttracker            = new BarListTracker(_symbols.ToArray(), _barinterval);
            _barlisttracker.GotNewBar += _barlisttracker_GotNewBar;

            // all are active
            _issymbolactive = Enumerable.Repeat <bool>(true, _symbols.Count).ToArray();
            // none are filled
            _waittobefilled = Enumerable.Repeat <bool>(false, _symbols.Count).ToArray();

            _transactions = 0;
        }
        /// <summary>
        /// Initialize "_blt", the bar list tracker
        /// </summary>
        void Initialize_blt()
        {
            Int32 numOfInterval = 1;

            BarInterval[] intervaltypes  = new BarInterval[numOfInterval];
            Int32[]       intervalValues = new Int32[numOfInterval];
            for (Int32 i = 0; i < numOfInterval; i++)
            {
                intervaltypes[i]  = BarType;
                intervalValues[i] = NumItemPerBar;
            }
            _blt = new BarListTracker(intervalValues, intervaltypes);
            // Delegate handler when we got new bar
            _blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar);
        }
        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));
        }
        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");
        }
        private void Setup()
        {
            _time = 0;

            var _colors = PlottingUtilities.GetLegacyColorList(_symbols.Count);

            for (int i = 0; i < _symbols.Count; i++)
            {
                _symbolColorMap.Add(_symbols[i], _colors[i]);
            }

            _barListTracker            = new BarListTracker();
            _barListTracker            = new BarListTracker(_intervalValues, _intervalTypes);
            _barListTracker.GotNewBar += _barListTracker_GotNewBar;
            isValid = true;
        }
Example #13
0
        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" };
        }
Example #14
0
/*
 *      // these variables "hold" the parameters set by the user above
 *      // also they are the defaults that show up first
 *      int _barsback = 2;
 *      BarInterval _barinterval = BarInterval.FiveMin;
 *      int _entrysize = 100;
 *      decimal _totalprofit = 200;
 *      int _shutdowntime = 155000;
 */

        void initialize()
        {
            // wait for fill
            _wait = new GenericTracker <bool>();
            // track whether shutdown
            _active = new GenericTracker <bool>();
            // hold last ma
            _sma = new GenericTracker <decimal>();

            // turn on bar tracking
            blt            = new BarListTracker(Interval);
            blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar);

            // turn on position tracking
            pt = new PositionTracker();
            // keep track of time for use in other functions
            time = 0;

            _active.NewTxt += new TextIdxDelegate(_active_NewTxt);
        }
        public override void Reset(bool popup = true)
        {
            _positiontracker           = new PositionTracker(_symbols.Count);
            _barlisttracker            = new BarListTracker(_symbols.ToArray(), new int[] { _higherbarinterval, _lowerbarinterval });
            _barlisttracker.GotNewBar += _barlisttracker_GotNewBar;
            _ordertracker              = new OrderTracker(10000);

            // in the none zone
            _isOBOSZone = Enumerable.Repeat <OBOSZone>(OBOSZone.None, _symbols.Count).ToArray();
            // neither bull or bear
            _isHigherTimeFrameBullBear = Enumerable.Repeat <BullBearTrend>(BullBearTrend.None, _symbols.Count).ToArray();
            // all are active
            _issymbolactive = Enumerable.Repeat <bool>(true, _symbols.Count).ToArray();
            // none are filled
            _waittobefilled = Enumerable.Repeat <bool>(false, _symbols.Count).ToArray();

            _currentorderids = Enumerable.Repeat <long>(0L, _symbols.Count).ToArray();
            _entrylevel      = Enumerable.Repeat <decimal>(0m, _symbols.Count).ToArray();
            _exitlevel       = Enumerable.Repeat <decimal>(0m, _symbols.Count).ToArray();

            _transactions = 0;
            _currenttime  = 0;
        }
Example #16
0
 public void Initialize()
 {
     dailyBarTracker = new BarListTracker(BarInterval.Day);
     intraBarTracker = new BarListTracker(BarInterval.FiveMin);
 }
        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);
        }