Overall Statistics
Total Trades
5087
Average Win
0.13%
Average Loss
-0.10%
Compounding Annual Return
1535.244%
Drawdown
1.100%
Expectancy
1.063
Net Profit
1543.611%
Sharpe Ratio
13.986
Loss Rate
10%
Win Rate
90%
Profit-Loss Ratio
1.28
Alpha
2.828
Beta
0.04
Annual Standard Deviation
0.202
Annual Variance
0.041
Information Ratio
8.474
Tracking Error
0.347
Treynor Ratio
70.305
Total Fees
$50870.00
//Copyright HardingSoftware.com, granted to the public domain.
//Use entirely at your own risk.
namespace QuantConnect.Algorithm.CSharp
{
    public class M : QCAlgorithm
    {
        string ticker = "AT";
		int holdCount= 5;
		int count=0;
		decimal lowerRatio=0.995m;
		decimal upperRatio=1.005m;
		OrderTicket orderTicket;
		decimal leverage=.99m;
		decimal increment=0.01m;
        public override void Initialize()
        {
            SetStartDate(2017, 9, 26);  //Set Start Date
            SetEndDate(2018, 9, 26);    //Set End Date
            SetCash(7000);             //Set Strategy Cash

            AddEquity(ticker, Resolution.Minute);
            SetBenchmark(ticker);
            
            Securities[ticker].FeeModel = new ConstantFeeModel(10m);
        }
        
        public override void OnData(Slice data)
        {
        	count++;
        	if (count<holdCount)
        	{
        		return;
        	}
        	count=0;
        	
        	if (data[ticker]==null || data.ContainsKey(ticker)==false)
        	{
        		return;
        	}
        	
        	decimal price=data[ticker].Close;
            if (!Portfolio.Invested)
            {
            	if (orderTicket!=null)
            	{
            		orderTicket.Cancel();
            	}
            	//int quantity=(int)(leverage*Portfolio.Cash/price);
            	int quantity=(int)(leverage*7000m/price);
            	decimal buyPrice=FloorToIncrement(lowerRatio*price,increment);
				orderTicket = LimitOrder(ticker, quantity, buyPrice);
            }
            else
            {
            	if (orderTicket!=null)
            	{
            		orderTicket.Cancel();
            	}
            	int quantity=(int)Portfolio[ticker].Quantity;
            	decimal sellPrice=CeilingToIncrement(upperRatio*price,increment);
				orderTicket = LimitOrder(ticker, -quantity, sellPrice);
            }
        }
        
        public decimal RoundToIncrement(decimal roundMe, decimal increment)
        {
        	return (decimal)(Math.Round(roundMe/increment)*increment);
        }
        
        public decimal FloorToIncrement(decimal roundMe, decimal increment)
        {
        	return (decimal)(Math.Floor(roundMe/increment)*increment);
        }
        
        public decimal CeilingToIncrement(decimal roundMe, decimal increment)
        {
        	return (decimal)(Math.Ceiling(roundMe/increment)*increment);
        }
    }
}