Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-0.534%
Drawdown
8.000%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0.059
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.017
Beta
0.111
Annual Standard Deviation
0.172
Annual Variance
0.03
Information Ratio
0.293
Tracking Error
0.238
Treynor Ratio
0.091
Total Fees
$1.00
namespace QuantConnect 
{   
    
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	//parameters go here
    	private const string Symbol = "SWN";
       int quantity = 0;
        decimal price = 0;
        decimal tolerance = 0m; //0.1% safety margin in prices to avoid bouncing.
        DateTime sampledToday = DateTime.Now;
        SimpleMovingAverage smaShort;
        SimpleMovingAverage smaLong;
        String symbol = "SWN" ;
        private SimpleMovingAverage fast;
        private SimpleMovingAverage slow;
        
        public override void Initialize() 
        {
			// Code Automatically Generated  
			AddSecurity(SecurityType.Equity, "SWN", Resolution.Minute);
			
			//Set backtest dates here
            SetStartDate(2016, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1));
            //Set Backtest cash amount here
            SetCash(5000);
            
            smaShort = SMA(symbol, 100, Resolution.Minute);
            smaLong = SMA(symbol, 200, 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) 
        {   
            // "TradeBars" object holds many "TradeBar" objects: it is a dictionary indexed by the symbol:
            
            
            if (!Portfolio.HoldStock) 
            {
             int quantity = (int)Math.Floor(Portfolio.Cash / data["SWN"].Close);
             if (!smaShort.IsReady) return;
             if(!smaLong.IsReady) return ;
           
           if (smaShort > smaLong && price > smaShort){
           	 Order("SWN",  100); //Order function (Stock,Quantity)
           }
              if (Portfolio.HoldStock && smaShort < smaLong && price < smaShort)
            {
                Liquidate("SWN") ;    
            }
            
          
            
           if (smaShort < smaLong && price < smaShort){
            	Order("SWN", -100);
            }
             if (Portfolio.HoldStock && smaShort > smaLong && price > smaShort)
            {
                Liquidate("SWN") ;    
            }
                //Debug sends messages to the user console: "Time" is the algorithm time keeper object 
                Debug("Purchased SWN on " + Time.ToShortDateString());
                
                //You can also use log to send longer messages to a file. You are capped to 10kb
                //Log("This is a longer message send to log.");
            } 
        }
    }
}