Overall Statistics
using QuantConnect.Data.Market;
using QuantConnect.Orders;

namespace QuantConnect.Algorithm.CSharp.PrimatLab
{
    public class Issue1 : QCAlgorithm
    {
        private OrderTicket _orderEntry = null;
        private OrderTicket _orderStopLoss = null;
        private OrderTicket _orderStopLoss2 = null;

        public override void Initialize()
        {
            SetStartDate(2018, 1, 1);
            SetEndDate(2018, 2, 1);
            SetCash(100000);
            AddEquity("SPY", Resolution.Daily);
        }

        public void OnData(TradeBars data)
        {
            foreach (var symbol in data.Keys)
            {
                Debug(data[symbol].Time + " : " + data[symbol].Close);
                if (_orderEntry == null)
                {
                    _orderEntry = MarketOrder(symbol, -100, false, "Entry");
                    //_orderStopLoss2 = StopMarketOrder(symbol, 100, 278.0m, "StopLoss2");
                }
            }
        }

        public override void OnOrderEvent(OrderEvent orderEvent)
        {
            var order = Transactions.GetOrderById(orderEvent.OrderId);
            if (order.Tag == "Entry" && orderEvent.Status == OrderStatus.Filled)
            {
                Debug("Enter short at " + orderEvent.FillPrice + " set STOPLOSS at 275");
                _orderStopLoss = StopMarketOrder(order.Symbol, order.Quantity, 275.0m, "StopLoss");
            }
            if (order.Tag != "Entry")
                Debug(order.Tag + " " + order.Status.ToString());
        }
    }
}