Example #1
0
        public void OpenPL()
        {
            decimal pl = .98m;

            Assert.That(BoxMath.OpenPT(last, entry, Long) == pl);
            Assert.That(BoxMath.OpenPT(last, entry, Short) == -pl);
            Assert.That(BoxMath.OpenPT(last, entry, lsize) == pl);
            Assert.That(BoxMath.OpenPT(last, entry, ssize) == -pl);
            Assert.That(BoxMath.OpenPT(last, lp) == pl);
            Assert.That(BoxMath.OpenPT(last, sp) == -pl);
            Assert.That(BoxMath.OpenPL(last, lp) == lp.Size * pl);
            Assert.That(BoxMath.OpenPL(last, sp) == sp.Size * pl);
        }
Example #2
0
        const decimal s = -.11m; // stop loss

        // here are the trading rules that implement our strategy's intention
        protected override int Read(Tick tick, BarList bl, BoxInfo bi)
        {
            // indicator setup
            bars = bl;
            if (!bl.Has(2))
            {
                return(0);            // must have at least one one bar
            }
            // asymmetry tests
            if (((h - o) > a) && ((o - l) > a))
            {
                Shutdown("Not enough Asymetry to trade."); return(0);
            }
            if ((h - l) < r)
            {
                return(0);             // must have the range
            }
            if (((h - o) <= a) && ((h - tick.trade) > e))
            {
                return(MaxSize);
            }
            if (((o - l) <= a) && ((tick.trade - l) > e))
            {
                return(MaxSize * -1);
            }

            // profit and loss tests
            decimal PL = BoxMath.OpenPT(tick.trade, AvgPrice, PosSize);

            if (PL > p)
            {
                return(Flat);
            }
            if (PL < s)
            {
                return(Flat);
            }

            return(0);
        }