Overall Statistics
Total Trades
87
Average Win
0.39%
Average Loss
-0.18%
Compounding Annual Return
5.130%
Drawdown
2.600%
Expectancy
0.007
Net Profit
0.770%
Sharpe Ratio
0.544
Loss Rate
69%
Win Rate
31%
Profit-Loss Ratio
2.21
Alpha
0.04
Beta
-0.009
Annual Standard Deviation
0.072
Annual Variance
0.005
Information Ratio
-1.138
Tracking Error
0.085
Treynor Ratio
-4.272
Total Fees
$174.00
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(2016, 12, 17);  
            SetEndDate(2017, 2, 10);  
            
            //add security
			AddSecurity(SecurityType.Forex, symbol, Resolution.Hour);
			_win = new RollingWindow<TEMAState>(4);
            _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 != 10){
        		warmupCount++;
        		Debug("still warming up");
        		return;
        	}
            decimal current  = _win[0].Value;
            decimal previous = _win[3].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[3].Value;
            Debug("Current: " + current + "Previous: " + previous);
            
			SetHoldings(symbol, 1.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[3].Value;
            Debug("Current: " + current + "Previous: " + previous);
			SetHoldings(symbol, -1.0);
        }
        
        
        public class TEMAState
        {
            public readonly decimal Value;
            public TEMAState(TripleExponentialMovingAverage tema)
    		{
        		Value = tema.Current;
    		}
		}
   
    }
}