Overall Statistics
Total Trades
14
Average Win
0%
Average Loss
-0.01%
Compounding Annual Return
-0.235%
Drawdown
0.100%
Expectancy
-1
Net Profit
-0.078%
Sharpe Ratio
-5.068
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.002
Beta
-0.001
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-3.331
Tracking Error
0.108
Treynor Ratio
2.154
Total Fees
$14.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 (CanOpen() == 1) 
            {
            	MarketOrder(iSymbol, iVolume);
            	LimitOrder(iSymbol, -iVolume, price + 1);
            	StopMarketOrder(iSymbol, -iVolume, price - 1);
                return;
            }
            
            if (CanClose() == 1) 
            {
                Liquidate();
                return;
            }
        }
        
        public override void OnOrderEvent(OrderEvent orderEvent)
        {
        	iOrders[orderEvent.OrderId] = Transactions.GetOrderById(orderEvent.OrderId);
        }
        
        public int CanOpen()
        {
            if (iRsi.IsReady && Portfolio.Invested == false) 
            {
                if (iRsi < 70 && iRsi > 50) 
                {
                	return -1;
                }
                
                if (iRsi > 30 && iRsi < 50)
                {
                	return 1;
                }
            }
            
            return 0;
        }
        
        public int CanClose() 
        {
            return 0;
        }
    }
}