Overall Statistics
Total Trades
1
Average Win
65.08%
Average Loss
0%
Compounding Annual Return
26.757%
Drawdown
18.00%
Expectancy
0
Net Profit
65.081%
Sharpe Ratio
1.141
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.069
Beta
0.956
Annual Standard Deviation
0.227
Annual Variance
0.052
Information Ratio
0.304
Tracking Error
0.2
Treynor Ratio
0.271
namespace QuantConnect 
{   
    /*
    *   QuantConnect University - Creating and Updating Limit Orders 
    *
    *   This algorithm walks through an example of creating and updating a limit order.
    *   The orders are stored in the Transactions Manager inside the algorithm.
    *   
    *   For the demonstration we will place a buy limit order for 1 SD below of microsoft's price, 
    *   and every day update it until its filled 
    */ 
    public class QCULimitOrders : QCAlgorithm
    {
        //Access for the order we'll place
        int _limitOrderId = 0;
        LimitOrder _limitOrder;
        string _symbol = "MSFT";
        decimal _price = 0;
        int _rebalancePeriod = 20;
        DateTime _updatedDate;
        
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
            SetStartDate(2013, 1, 1);
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(25000);
            AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute);
        }

        //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
        public void OnData(TradeBars data) 
        {   
            //if (data.Contains("MSFT"))
            _price = data["MSFT"].Close;
            
            //Create the first order
            if (_limitOrderId == 0) 
            {
                //Set our first order to less than MS's price: 
                _limitOrderId = LimitOrder(_symbol, (int)(Portfolio.Cash/_price), (_price * 0.95m));
                _limitOrder = (LimitOrder)Transactions.GetOrderById(_limitOrderId); 
                Debug("Created first limit order with " + _symbol + " Price: " + _price.ToString("C") + " id: " + _limitOrderId);
            }
            
            //Update the limit price once per week:
            if (_updatedDate.Date < Time.Date && !Portfolio.Invested)
            {
                _updatedDate = Time.Date.AddDays(_rebalancePeriod); 
                
                _limitOrder.LimitPrice = (_price * 0.99m); 
                
                Transactions.UpdateOrder(_limitOrder);
            }
        }
        
        /*
        *   For our plotting we can show the limit price and MSFT to check if its hit.
        */
        public override void OnEndOfDay()
        {
            Plot("Limit Plot", "MSFT", _price);
            Plot("Limit Plot", "Limit", _limitOrder.LimitPrice);
        }
    }
}