Overall Statistics
Total Trades
19
Average Win
0.00%
Average Loss
-0.01%
Compounding Annual Return
-0.153%
Drawdown
0.100%
Expectancy
-0.567
Net Profit
-0.050%
Sharpe Ratio
-3.327
Loss Rate
67%
Win Rate
33%
Profit-Loss Ratio
0.30
Alpha
-0.002
Beta
0.002
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-3.334
Tracking Error
0.107
Treynor Ratio
-0.735
Total Fees
$19.00
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;
        }
        */
    }
}