Overall Statistics
namespace QuantConnect 
{ 
    public partial class QCUMartingalePositionSizing : QCAlgorithm 
    {
    	int iPeriod = 15;
        //decimal iTP = 0.02m;
        //decimal iSL = 0.02m;
        decimal iLeverage = 4m;
        decimal iVolume = 1m;
        string iSymbol = "MSFT";
        
        RelativeStrengthIndex iRsi = null;
        Dictionary<int, Order> iOrders = new Dictionary<int, Order>();
        
        public override void Initialize()
        {
        	var resolution = Resolution.Minute;
        	
        	SetCash(25000);
            SetStartDate(2017, 1, 1);
            SetEndDate(2017, 5, 1); 
            SetBenchmark(iSymbol);
            SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage);
            AddSecurity(SecurityType.Equity, iSymbol, resolution, true, iLeverage, false);
            
            iRsi = RSI(iSymbol, iPeriod, MovingAverageType.Simple, resolution);
        }
        
        public void OnData(TradeBars data) 
        {
            var price = data[iSymbol].Close;
            
            if (Portfolio.Invested == false) 
            {
            	MarketOrder(iSymbol, iVolume);
            	LimitOrder(iSymbol, -iVolume, price + 3);
            	StopMarketOrder(iSymbol, -iVolume, price - 1);
                return;
            }
            /*
            if (Portfolio.TotalUnrealisedProfit) 
            {
                ScanForExit(SPY);
                return;
            }
            */
        }
        
        public override void OnOrderEvent(OrderEvent orderEvent)
        {
        	iOrders[orderEvent.OrderId] = Transactions.GetOrderById(orderEvent.OrderId);
        }
        
        /*
        public void ScanForEntry(TradeBar SPY)
        {
            //Once we have enough data, start the Entry detection.
            if (rsi.Ready) 
            {
                if (rsi.RSI > 70) {
                    magnitudeDirection = -0.2m;
                    SetHoldings(symbol, -magnitudeDirection);   //Over bought
                    Log("Entry-Short: " + magnitudeDirection + " Holdings: " + Portfolio[symbol].Quantity);
                }
                else if (rsi.RSI < 30)
                {
                    magnitudeDirection = 0.2m;
                    SetHoldings(symbol, magnitudeDirection);    //Over sold
                    Log("Entry-Long: " + magnitudeDirection + " Holdings: " + Portfolio[symbol].Quantity);
                }
            }
        }
        
        public void ScanForExit(TradeBar SPY) 
        {
            Log("Exit: " + magnitudeDirection + " Realized Profit/Loss: " + UnrealizedTradeStringProfit.ToString("C"));
            Liquidate();
            tradeStringProfit = 0;
            magnitudeDirection = 0.2m; 
            exitDate = Time.Date;
            return;
        }
        */
    }
}