Beispiel #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);
        }
Beispiel #2
0
        public static Tuple <Order, StopLossOrder, TakeProfitOrder> OrderTriple(Market CurrentMarket, TradeAction Action, int ContractId, int StrategyId, PositiveInteger Quantity,
                                                                                decimal TakeProfit, decimal StopLoss, bool TrailingStopLoss)
        {
            decimal         desiredPrice = (Action == TradeAction.Buy ? CurrentMarket.Ask : CurrentMarket.Bid);
            Order           entry        = MarketOrder(CurrentMarket.Timestamp, Action, ContractId, StrategyId, Quantity, desiredPrice);
            StopLossOrder   stoploss     = new StopLossOrder(entry, StopLoss, TrailingStopLoss);
            TakeProfitOrder takeprofit   = new TakeProfitOrder(entry, TakeProfit);

            return(new Tuple <Order, StopLossOrder, TakeProfitOrder>(entry, stoploss, takeprofit));
        }
Beispiel #3
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);
        }