Exemple #1
0
        public bool Test(Market CurrentMarket)
        {
            decimal executablePrice = (Action == TradeAction.Buy ? CurrentMarket.Ask : CurrentMarket.Bid);

            if (Purpose == Purpose.TakeProfit)
            {
                // We want to buy (action == 1) do it if executablePrice < targetprice
                // We want to sell (action == -1) do it if executablePrice > targetprice
                if (Math.Sign(DesiredPrice - executablePrice) == Math.Sign((int)Action))
                {
                    Timestamp = CurrentMarket.Timestamp;                                  // CRUCIAL!
                    Purpose   = Purpose.TrailingTakeProfit;

                    // We've hit the original take-profit level, so now we switch to being a trailing
                    // take-profit (ie, a very tight stop-loss).
                    TrailingTakeProfit        = new StopLossOrder(this, 10 * CurrentMarket.Spread, true);
                    TrailingTakeProfit.Action = Action;
                }
            }
            else
            {
                if (TrailingTakeProfit.Test(CurrentMarket))
                {
                    return(true);
                }
                else
                {
                    TrailingTakeProfit.Update(CurrentMarket);
                }
            }

            return(false);
        }
Exemple #2
0
        public static Order TestExitOrders(Market CurrentMarket, StopLossOrder StopLossOrder, TakeProfitOrder TakeProfitOrder)
        {
            if (StopLossOrder != null && StopLossOrder.Test(CurrentMarket))
            {
                return(StopLossOrder);
            }

            if (TakeProfitOrder != null && TakeProfitOrder.Test(CurrentMarket))
            {
                return(TakeProfitOrder);
            }

            return(null);
        }