Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
0.330%
Drawdown
0.000%
Expectancy
0
Net Profit
0.029%
Sharpe Ratio
3.877
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.002
Beta
0.001
Annual Standard Deviation
0.001
Annual Variance
0
Information Ratio
-4.973
Tracking Error
0.043
Treynor Ratio
3.822
Total Fees
$1.00
namespace QuantConnect 
{ 
    public partial class QCUMartingalePositionSizing : QCAlgorithm 
    {
        public override void Initialize()
        {
        	SetCash(25000);
            SetStartDate(2017, 10, 1);
            SetEndDate(2017, 11, 1); 
            SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage);
            AddSecurity(SecurityType.Equity, "MSFT", Resolution.Hour, true, 4m, false);
        }

        public void OnData(TradeBars data) 
        {
        	if (Transactions.OrdersCount == 0)
        	{
        		Action(1);		// Long
        		//Action(-1);	// Short
        	}
        }

        protected void Action(int direction)
        {
        	var price = Securities["MSFT"].Price;

    		MarketOrder("MSFT", direction);
    		StopMarketOrder("MSFT", -direction, price - 20m * direction);
    		LimitOrder("MSFT", -direction, price + 20m * direction);
        }
    }
}