Overall Statistics
Total Trades
3121
Average Win
0.06%
Average Loss
-0.04%
Compounding Annual Return
-4.445%
Drawdown
15.900%
Expectancy
-0.261
Net Profit
-15.650%
Sharpe Ratio
-1.633
Loss Rate
71%
Win Rate
29%
Profit-Loss Ratio
1.56
Alpha
-0.031
Beta
0.002
Annual Standard Deviation
0.019
Annual Variance
0
Information Ratio
-0.88
Tracking Error
0.106
Treynor Ratio
-20.128
Total Fees
$0.00
namespace QuantConnect 
{   
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	private  List<string>  tickers = new List<string>();
    	private Dictionary<string, RelativeStrengthIndex> rsiDict = new Dictionary<string, RelativeStrengthIndex>();
    	private Dictionary<string, StandardDeviation> stdevDict = new Dictionary<string, StandardDeviation>();
    	private RelativeStrengthIndex rsi;
    	private StandardDeviation stdev;
    	
    	public Resolution resolution = Resolution.Hour;
    	//private decimal takeProfit = 0.00035m;
    	private decimal leverage = 0.9m;
    	private decimal shock = 2m;
    	
        public override void Initialize() 
        {
			 tickers.Add("EURUSD"); 
        	 tickers.Add("GBPUSD"); 
        	 tickers.Add("USDJPY"); 
        	 tickers.Add("AUDUSD"); 
        	 //tickers.Add("EURJPY"); 
        	 //tickers.Add("USDCAD"); 
        	 //tickers.Add("EURGBP"); 
        	 //tickers.Add("USDCHF"); 
        	 //tickers.Add("USDMXN"); 
        	 //tickers.Add("NZDUSD"); 
        	 //tickers.Add("EURCHF"); 
        	 //tickers.Add("USDRUB"); 
        	 //tickers.Add("USDZAR"); 
        	 //tickers.Add("USDSGD"); 
        	 //tickers.Add("USDTRY"); 
        	 //tickers.Add("EURSEK"); 
        	 //tickers.Add("GBPJPY"); 
        	 //tickers.Add("EURAUD"); 
        	 //tickers.Add("EURNOK"); 
        	 //tickers.Add("USDINR"); 
        	 //tickers.Add("USDPLN"); 
        	 //tickers.Add("USDCNY");
        	
        	SetStartDate(2014, 1, 1);
        	SetCash(100000);
        	SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Cash);
        	
        	foreach (String fxPair in tickers){
            	AddForex(fxPair, resolution, Market.Oanda);
            	Securities[fxPair].FeeModel = new OandaTransactionModel();
            	rsiDict[fxPair] = RSI(fxPair, 14);
            	stdevDict[fxPair] = STD(fxPair, 14);
            	
            	var history = History<QuoteBar>(fxPair, 125);
            	foreach (var quoteBar in history)
            	{
            		rsiDict[fxPair].Update(quoteBar.EndTime, quoteBar.Close);
            		stdevDict[fxPair].Update(quoteBar.EndTime, quoteBar.Close);
            	}
            }
            
            
			
        }

        public void OnData(QuoteBars data) 
        {
        	int toTrade = 0;
        	List<string> longs = new List<string>();
    		List<string> shorts = new List<string>();
    		
			foreach(String fxPair in tickers){
				if(data.ContainsKey(fxPair) == false){
            		Log("not there");
            		break;
            	}
            	
            	Transactions.CancelOpenOrders(fxPair);
    			SetHoldings(fxPair,0);
    			
            	
            	rsi = rsiDict[fxPair];
            	stdev = stdevDict[fxPair];
            	if (!rsi.IsReady || !stdev.IsReady) return;
            	
            	decimal close = data[fxPair].Close;
            	decimal open = data[fxPair].Open;
            	
            	bool greenBar = close > open;
            	bool redBar   = close < open;
            	
            	bool overBought = rsi.Current > 70;
            	bool overSold	= rsi.Current < 30;
            	
            	bool overShock = Math.Abs(close - open) > (shock*stdevDict[fxPair].Current);
            	
            	if((greenBar && overBought && overShock) && (Portfolio[fxPair].Quantity == 0)){
            		toTrade +=1;
            		longs.Add(fxPair);
            	}
            	if((redBar && overSold && overShock) && (Portfolio[fxPair].Quantity == 0)){
            		toTrade +=1;
            		shorts.Add(fxPair);
            	}
			}
			
			if(toTrade == 0){ return; }
			
			decimal cash = (Portfolio.Cash * leverage) / toTrade;
			
			foreach(String fxPair in longs){
				int shares = (int)(cash/data[fxPair].Price);
				MarketOrder(fxPair,shares);
				//LimitOrder(fxPair,-shares,data[fxPair].Price*(1+takeProfit));
			}
			foreach(String fxPair in shorts){
				int shares = (int)(cash/data[fxPair].Price);
				MarketOrder(fxPair,-shares);
				//StopMarketOrder(fxPair,shares,data[fxPair].Price*(1-takeProfit));
			}
        }
    }
}