Overall Statistics
Total Trades
1055
Average Win
0.84%
Average Loss
-0.48%
Compounding Annual Return
-87.310%
Drawdown
100.000%
Expectancy
0.816
Net Profit
-99.842%
Sharpe Ratio
-0.847
Loss Rate
34%
Win Rate
66%
Profit-Loss Ratio
1.76
Alpha
-0.845
Beta
-0.342
Annual Standard Deviation
1.02
Annual Variance
1.041
Information Ratio
-0.894
Tracking Error
1.03
Treynor Ratio
2.525
Total Fees
$36939.09
using System;
using System.Collections.Generic;
using QuantConnect.Data.Consolidators;
using QuantConnect.Indicators;
using QuantConnect.Data.Market;

namespace QuantConnect 
{   
    public class BasicTemplateAlgorithm : QCAlgorithm
    {	
    	TradeBar _eurusdHourly;
        int warmupCount = 0;
        string symbol = "EURUSD";
        int state;
        
        private RollingWindow<TEMAState> _win;
        private TripleExponentialMovingAverage _tema;
        
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize() 
        {
        	//0 = default, -1 = short, 1 = long
        	int state = 0;
        	//Start and End Date range for the backtest:
            SetStartDate(2014, 1, 1);  
            SetEndDate(DateTime.Now.Date.AddDays(-1));
            
            //add security
			AddSecurity(SecurityType.Forex, symbol, Resolution.Hour);
			_win = new RollingWindow<TEMAState>(3);
            _tema = TEMA(symbol, 20);
			
            //Cash allocation
            SetCash(25000);
            
            //set brokerage model
            SetBrokerageModel(BrokerageName.OandaBrokerage);
        }
		
		//hourly data handler
		public void OnData(TradeBars data)
        {
        	Debug("test");
        	if (_tema.IsReady) _win.Add(new TEMAState(_tema));
        	if (!_win.IsReady) return;
        	//warm up some more hours of good data
        	if(warmupCount != 4){
        		warmupCount++;
        		Debug("still warming up");
        		return;
        	}
            decimal current  = _win[0].Value;
            decimal previous = _win[2].Value;
            
            if(current > previous){
            	goLong(data);
            	return;
            }else if(current < previous){
            	goShort(data);
            	return;
            }else{
            	return;
            }
        }
		
        
        public void goLong(TradeBars data){
        	//check if it's already going long
        	if(state == 1){
        		return;
        	}
        	state = 1;
        	Debug("Going long!");
			decimal current  = _win[0].Value;
            decimal previous = _win[2].Value;
            //Debug("Current: " + current + " Previous: " + previous);
            
			SetHoldings(symbol, -25.0);
        }
        
        public void goShort(TradeBars data){
        	//check if it's already going short
        	if(state == -1){
        		return;
        	}
        	state = -1;
        	Debug("Going short!");
			decimal current  = _win[0].Value;
            decimal previous = _win[2].Value;
            //Debug("Current: " + current + " Previous: " + previous);
			SetHoldings(symbol, 25.0);
        }
        
        
        public class TEMAState
        {
            public readonly decimal Value;
            public TEMAState(TripleExponentialMovingAverage tema)
    		{
        		Value = tema.Current;
    		}
		}
   
    }
}