Overall Statistics
Total Trades
315
Average Win
0%
Average Loss
-0.04%
Compounding Annual Return
-31.869%
Drawdown
10.700%
Expectancy
-1
Net Profit
-6.920%
Sharpe Ratio
-1.324
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.304
Beta
-0.104
Annual Standard Deviation
0.225
Annual Variance
0.05
Information Ratio
-0.783
Tracking Error
0.304
Treynor Ratio
2.859
Total Fees
$315.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;
        private Identity yesterdayClose;
        
        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);
           
            // this will get us an indicator that represents our symbol's closing price
            yesterdayClose = Identity(Symbol, Resolution.Daily, Field.Close);
        }

        //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:
            
            // set price based on previous minute bar
            price = data["SWN"].Close;
            // set price based on yesterday's close
            // price = yesterdayClose;
            
            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.");
            } 
        }
    }
}