Ejemplo n.º 1
0
 public MagicBoxCreated(OrderWatcher orderManager, Order buyOrder, Order sellOrder, MagicBoxConfig config)
 {
     this.orderManager = orderManager;
     this.buyOrder = buyOrder;
     this.sellOrder = sellOrder;
     this.mbConfig = config;
 }
Ejemplo n.º 2
0
 public FirstOrderRunningManager(Order runningOrder, Order pendingOrder, HappyDayEA happyDayEA)
 {
     _runningOrder = runningOrder;
     _pendingOrder = pendingOrder;
     _ea = happyDayEA;
     _profitProtector = new ThreeLevelProfitProtector(_runningOrder);
 }
Ejemplo n.º 3
0
        public OrderWatcher(Order buyOrder, Order sellOrder, double expiredTime, MagicBoxConfig config)
        {
            mbConfig = config;
            AddOneCancelAnother(buyOrder, sellOrder);

            this.expiredTime = expiredTime;

            expiracyTimer = new ExpiracyTimer(expiredTime / 2);
            expiracyTimer.Expired += expiracyTimer_Expired;
        }
Ejemplo n.º 4
0
        protected override int Start()
        {
            if (IsNewBar())
            {
                Print("Hei theres a new bar");

                if (IsThereOpenOrder())
                {
                    CloseOpenOrder();
                }

                if (IsPreviouslyBulishCandle())
                {
                    //order = Buy(0.1, BuyClosePrice - stopLoss, BuyClosePrice + 2 * stopLoss);
                    //order = Buy(0.1, BuyClosePrice - (stopLoss * Point), BuyClosePrice + (4 * stopLoss * Point));
                    double buyStopPrice = BuyOpenPrice + 50 * Point;
                    double buyStopClosePrice = BuyClosePrice + 50 * Point;
                    //order = PendingBuy(0.1, buyStopPrice, buyStopClosePrice - (stopLoss * Point), buyStopClosePrice + (4 * stopLoss * Point));
                    order = PendingBuy(lotSize, buyStopPrice, buyStopClosePrice - (stopLoss * Point), buyStopClosePrice + (takeProfit * Point));
                    trailingMethod = new BuyTrailingMethod(order, this);
                    Print("Buy");
                }
                else
                {
                    //order = Sell(0.1, SellClosePrice + stopLoss, SellClosePrice - 2 * stopLoss);
                    //order = Sell(0.1, SellClosePrice + (stopLoss * Point), SellClosePrice - (4 * stopLoss * Point));
                    double sellStopPrice = SellOpenPrice - 50 * Point;
                    double sellStopClosePrice = SellClosePrice - 50 * Point;
                    order = PendingSell(lotSize, sellStopPrice, sellStopClosePrice + (stopLoss * Point), sellStopClosePrice - (takeProfit * Point));
                    //order = PendingSell(0.1, sellStopPrice, sellStopClosePrice + (stopLoss * Point), sellStopClosePrice - (4 * stopLoss * Point));
                    trailingMethod = new SellTrailingMethod(order, this);
                    Print("Sell");
                }
            }
            else
            {
                //if (IsThereOpenOrder())
                //{
                //    trailingMethod.Trail();
                //}

                if (IsThereRunningOrder())
                {
                    trailingMethod.Trail();
                }

                Print("Wait pal");
            }
            return (0);
        }
Ejemplo n.º 5
0
        protected override int Start()
        {
            count++;

            if (order == null)
            {
                Init();
            }
            else
            {
                order.ModifyStopLoss(Ask - (count*100*Point));
            }

            if (order.CloseInProfit())
                order = null;
            return 1;
        }
Ejemplo n.º 6
0
        protected override int Start()
        {
            tickCount++;

            if (tickCount != 10) return 1;

            if (order == null)
            {
                order = Sell(0.1, Bid + 100 * Point, Bid - 500 * Point);
            }
            else
            {
                order.Close();
                order = null;
            }

            tickCount = 0;

            return 1;
        }
Ejemplo n.º 7
0
        protected override int Start()
        {
            if (!isInitialize)
            {
                Init();
            }

            // should introduce event and directly buy or sell
            // should create new object for decision making.

            while (true)
            {
                RefreshRates();

                beat.Add(new Quote(Bid, Ask));

                PrintReport(beat);

                if (beat.LastDelta >= threshold)
                {
                    if (IsNoOpenOrder())
                    {
                        Console.WriteLine("No Open Order");
                        order = Buy(1);

                        order.ChangeStopLossInPoints(100);
                        order.ChangeTakeProfitInPoints(20);
                    }
                    else
                    {
                        if (IsAlreadyOpenBuy()) return 1;

                        order.Close();

                        order = Buy(1);
                        order.ChangeStopLossInPoints(100);
                        order.ChangeTakeProfitInPoints(20);
                    }
                }
                else if (Math.Abs(beat.LastDelta) >= threshold)
                {
                    if (IsNoOpenOrder())
                    {
                        Console.WriteLine("No Open Order");
                        order = Sell(1);
                        order.ChangeStopLossInPoints(100);
                        order.ChangeTakeProfitInPoints(20);
                    }
                    else
                    {
                        if (IsAlreadyOpenSell()) return 1;

                        order.Close();
                        order = Sell(1);
                        order.ChangeStopLossInPoints(100);
                        order.ChangeTakeProfitInPoints(20);
                    }
                }

                Thread.Sleep(500);
            }

            return 1;
        }
Ejemplo n.º 8
0
 public OrderTrailingInfo(Order order)
 {
     _order = order;
 }
Ejemplo n.º 9
0
 internal void ChangeStateToOrderRunning(Order runningOrder, Order pendingOrder)
 {
     _orderManagement = new FirstOrderRunningManager(runningOrder, pendingOrder, this);
 }
Ejemplo n.º 10
0
 private void AddOneCancelAnother(Order buyOrder, Order sellOrder)
 {
     state = new MagicBoxCreated(this, buyOrder, sellOrder, mbConfig);
 }
Ejemplo n.º 11
0
        protected override int Init()
        {
            order = PendingBuy(0.1, Bid + 100 * Point, Bid - 500 * Point, Bid + 500 * Point);

            return 1;
        }
Ejemplo n.º 12
0
        protected override int Init()
        {
            order = Sell(0.1, Bid + 100 * Point, Bid - 500 * Point);

            return 1;
        }
Ejemplo n.º 13
0
 public PendingOrderCreatedManager(PinBarEA pinBarEA, Order order)
 {
     _ea = pinBarEA;
     _order = order;
 }
Ejemplo n.º 14
0
        private bool IsThereOpenOrder()
        {
            if (order == null) return false;

            if (!order.IsOpen)
            {
                order = null;
                return false;
            }

            return true;
        }
Ejemplo n.º 15
0
 public OrderAlreadyRunning(OrderWatcher orderManager, Order order, IProfitProtector trailing)
 {
     this.orderManager = orderManager;
     this.order = order;
     this.trailing = trailing;
 }
Ejemplo n.º 16
0
 public SecondOrderRunningManager(Order runningOrder, HappyDayEA happyDayEA)
 {
     _runningOrder = runningOrder;
     _ea = happyDayEA;
     _profitProtector = new ThreeLevelProfitProtector(_runningOrder);
 }
Ejemplo n.º 17
0
        // we should use event based for this
        internal void OrderRunning(Order order, IProfitProtector trailing)
        {
            ResetExpiracy();

            state = new OrderAlreadyRunning(this, order, trailing);
        }
Ejemplo n.º 18
0
        internal void CreatedMagicBoxFromPreviousCandle()
        {
            double asianSessionHigh = AsianSessionHigh;
            double asianSessionLow = AsianSessionLow;

            double slPoints = (asianSessionHigh - asianSessionLow) / Point + 2 * range;
            var moneyManagement = new MoneyManagement(2, Balance);
            double lotSize = moneyManagement.CalculateLotSize(slPoints);
            double tpPoints = Math.Max(1000 * Point, 2 * slPoints * Point);
            //var tpPoints = 200 * Point;
            // risk reward ratio = 2 * slPoints

            _buyOrder = PendingBuy(Symbol, lotSize, asianSessionHigh + range * Point, asianSessionLow - range * Point, asianSessionHigh + tpPoints);

            _sellOrder = PendingSell(Symbol, lotSize, asianSessionLow - range * Point, asianSessionHigh + range * Point, asianSessionLow - tpPoints);

            this.ObjectsDeleteAll();
        }
Ejemplo n.º 19
0
 internal void ChangeStateToSecondOrderRunning(Order runningOrder)
 {
     _orderManagement = new SecondOrderRunningManager(runningOrder, this);
 }
Ejemplo n.º 20
0
 public BoxAlreadyCreatedManager(Order buyOrder, Order sellOrder, HappyDayEA happyDayEA)
 {
     _buyOrder = buyOrder;
     _sellOrder = sellOrder;
     _ea = happyDayEA;
 }
Ejemplo n.º 21
0
 public SecondOrderPendingManager(Order pendingOrder, HappyDayEA happyDayEA)
 {
     _pendingOrder = pendingOrder;
     _ea = happyDayEA;
     _profitProtector = new ThreeLevelProfitProtector(pendingOrder);
 }
Ejemplo n.º 22
0
        protected override int Init()
        {
            order = Buy(0.1, Bid - 100*Point, Bid + 500*Point);

            return 1;
        }
Ejemplo n.º 23
0
 public ThreeLevelProfitProtector(Order order)
 {
     _order = order;
 }
Ejemplo n.º 24
0
 public SellTrailingMethod(Order order, EExpertAdvisor ea)
 {
     this.order = order;
     this.ea = ea;
 }
Ejemplo n.º 25
0
 private void CloseOpenOrder()
 {
     order.Close();
     order = null;
 }
Ejemplo n.º 26
0
 public OrderAlreadyRunning(OrderWatcher orderManager, Order order, ITrailingMethod trailing)
 {
     this.orderManager = orderManager;
     this.order = order;
     this.trailing = trailing;
 }
Ejemplo n.º 27
0
        // we should use event based for this
        internal void OrderRunning(Order order, ITrailingMethod trailing)
        {
            ResetExpiracy();

            state = new OrderAlreadyRunning(this, order, trailing);
        }
Ejemplo n.º 28
0
 public OrderRunningManager(PinBarEA pinBarEA, Order order)
 {
     _ea = pinBarEA;
     _order = order;
     _profitProtector = new ThreeLevelProfitProtector(order);
 }
Ejemplo n.º 29
0
 internal void FirstOrderCompleted(Order pendingOrder)
 {
     _orderManagement = new SecondOrderPendingManager(pendingOrder, this);
 }