示例#1
0
        public void MultiFire()
        {
            // setup trail tracker
            TrailTracker tt = new TrailTracker();
            tt.VerboseDebugging = true;
            tt.SendOrder += new OrderDelegate(tt_SendOrder);
            tt.SendDebug += new DebugDelegate(tt_SendDebug);
            // set 15c trailing stop
            tt.DefaultTrail = new OffsetInfo(0, .15m,0,.5m);
            // verify it's set
            Assert.AreEqual(.15m, tt.DefaultTrail.StopDist);
            // get feed
            Tick[] tape = MultiFireSampleData();
            // test broker
            Broker b = new Broker();
            b.Reset();
            // get fills over to trail tracker
            b.GotFill += new FillDelegate(tt.Adjust);
            // take initial position
            b.SendOrderStatus(new MarketOrder(SYM, 400));
            // get orders from trail tracker
            tt.SendOrder += new OrderDelegate(b.SendOrder);
            // no orders to start
            oc = 0;
            // iterate through feed
            for (int i = 0; i < tape.Length; i++)
            {
                Tick k = tape[i];
                // set a date and time
                k.date = 20070926;
                k.time = 95500;
                // execute orders, nothing to do on first two ticks
                b.Execute(k);
                // pass every tick to tracker
                tt.newTick(k);

            }
            // get position
            Position p = b.GetOpenPosition(SYM);
            // verify position is flat
            Assert.AreEqual(200,p.UnsignedSize, "position is not flat: " + p.ToString());
            // one retrace sent at the end
            Assert.AreEqual(1, oc,"too many fires");
        }
示例#2
0
        public void Basics()
        {
            // setup trail tracker
            TrailTracker tt = new TrailTracker();
            tt.SendOrder += new OrderDelegate(tt_SendOrder);
            // set 15c trailing stop
            tt.DefaultTrail = new OffsetInfo(0,.15m);
            // verify it's set
            Assert.AreEqual(.15m,tt.DefaultTrail.StopDist);
            // get feed
            Tick [] tape = SampleData();
            // test broker
            Broker b = new Broker();
            // get fills over to trail tracker
            b.GotFill += new FillDelegate(tt.Adjust);
            // take initial position
            b.SendOrderStatus(new MarketOrder(SYM, 100));
            // get orders from trail tracker
            tt.SendOrder += new OrderDelegate(b.SendOrder);
            // no orders to start
            oc = 0;
            // iterate through feed
            for (int i = 0; i < tape.Length; i++ )
            {
                Tick k = tape[i];
                // set a date and time
                k.date = 20070926;
                k.time = 95500;
                // execute orders, nothing to do on first two ticks
                b.Execute(k);
                // pass every tick to tracker
                tt.newTick(k);

            }
            // get position
            Position p = b.GetOpenPosition(SYM);
            // verify position is flat
            Assert.IsTrue(p.isFlat,p.ToString());
            // one retrace sent at the end
            Assert.AreEqual(1, oc);
            
        }
示例#3
0
        public void Basics()
        {
            // setup trail tracker
            TrailTracker tt = new TrailTracker();
            tt.SendOrder += new OrderDelegate(tt_SendOrder);
            // set 15c trailing stop
            tt.DefaultTrail = new OffsetInfo(0,.15m);
            // verify it's set
            Assert.AreEqual(.15m,tt.DefaultTrail.StopDist);
            // get feed
            Tick [] tape = SampleData();
            // test position
            Position tp = new PositionImpl(SYM, 10, 100);
            // no orders to start
            oc = 0;
            // iterate through feed
            for (int i = 0; i < tape.Length; i++ )
            {
                Tick k = tape[i];
                // nothing to do on first two ticks
                if (i==2)
                {
                    // position established on third tick
                    tt.Adjust(tp);
                }
                // no orders sent until retrace happens
                Assert.AreEqual(0, oc);

                // pass every tick to tracker
                tt.GotTick(k);

            }
            // one retrace sent at the end
            Assert.AreEqual(1, oc);
            // verify it offsets position
            Assert.AreEqual(trail.UnsignedSize,tp.UnsignedSize);
            Assert.AreEqual(trail.side, !tp.isLong);
            
        }
示例#4
0
        public void TrailStartedAfterFirePoint()
        {
            // setup trail tracker
            TrailTracker tt = new TrailTracker();
            tt.isValid = true;
            const string acct = "DEFAULT";
            tt.pt.DefaultAccount = acct;
            tt.SendOrder += new OrderDelegate(tt_SendOrder);
            //tt.SendDebug += new DebugFullDelegate(tt_SendDebug);
            // set 15c trailing stop
            tt.DefaultTrail = new OffsetInfo(0, .15m);
            // verify it's set
            Assert.AreEqual(.15m, tt.DefaultTrail.StopDist);
            //
            tt.TrailByDefault = true;
            // put in a position to track
            tt.Adjust(new PositionImpl(SYM, 11.00m, 100, 0m,acct));
            // check position in tt-pt
            Assert.AreEqual(1, tt.pt.Count);
            // manually enter a trail
            tt[SYM] = new OffsetInfo(0m, .25m);
            // check if trail entered for symbol
            Assert.AreEqual(.25m, tt[SYM].StopDist);

            // get feed
            Tick[] tape = SampleData();
            // test broker
            Broker b = new Broker();
            // get fills over to trail tracker
            b.GotFill += new FillDelegate(tt.Adjust);
            // get orders from trail tracker
            tt.SendOrder += new OrderDelegate(b.SendOrder);
            // no orders to start
            oc = 0;
            // iterate through feed
            for (int i = 0; i < tape.Length; i++)
            {
                Tick k = tape[i];
                // set a date and time
                k.date = 20070926;
                k.time = 95500;
                // execute orders, nothing to do on first two ticks
                b.Execute(k);
                // pass every tick to tracker
                tt.newTick(k);

            }

            Assert.AreEqual(1, oc);
        }