Overall Statistics
namespace QuantConnect
{
    public class indicator_res_test : QCAlgorithm
    {
        private OrderTicket EntryOrder { get; set; }
        private Func<QCAlgorithm, string, decimal, OneCancelsOtherTicketSet> OnOrderFilledEvent { get; set; }
        private OneCancelsOtherTicketSet ProfitLossOrders { get; set; }

        public override void Initialize()
        {
            SetStartDate(2011, 6, 9);
            SetEndDate(2011, 7, 1);
            SetCash(10000);

            AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Minute, true, 50.0m, false);

    }


        public void OnData(TradeBars data)
        {
            
            if (!Portfolio.Invested && Time.TimeOfDay.Hours == 08)
            {
                this.OnOrderFilledEvent = (algo, symbol, filledPrice) =>
                {
                    return new OneCancelsOtherTicketSet(
                        algo.LimitOrder(symbol, -45000, filledPrice + 0.00212m, "Profit Target"),
                        algo.StopMarketOrder(symbol, -45000, filledPrice - 0.00212m, "Stop Loss"));
                };
                this.EntryOrder = MarketOrder("EURUSD", 45000, false, "Entry");
            }
        }

        public override void OnOrderEvent(OrderEvent orderEvent)
        {
            if (EntryOrder != null)
            {
                this.EntryOrder = null;
            }

            if (orderEvent.Status == OrderStatus.Filled || orderEvent.Status == OrderStatus.PartiallyFilled)
            {
                if (this.OnOrderFilledEvent != null)
                {
                    this.ProfitLossOrders = OnOrderFilledEvent(this, orderEvent.Symbol, orderEvent.FillPrice);
                    OnOrderFilledEvent = null;
                }
                else if (this.ProfitLossOrders != null)
                {
                    this.ProfitLossOrders.Filled();
                    Log("Profit/Loss Filled" + "Portfolio Invested Check: =" + Portfolio.Invested);
                    this.ProfitLossOrders = null;
                }
            }
        }

    }

}
namespace QuantConnect {

    public class OneCancelsOtherTicketSet
    {
        public OneCancelsOtherTicketSet(params OrderTicket[] orderTickets)
        {
            this.OrderTickets = orderTickets;
        }

        private OrderTicket[] OrderTickets { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTickets)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                    orderTicket.Cancel();
                }
            }
        }
    }

}