Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
namespace QuantConnect.Algorithm.CSharp
{
	public partial class TestAlgo : QCAlgorithm
	{
		//****************************************************************************************************************************************
		//USER VARIABLES
		//****************************************************************************************************************************************
		
		private static string _AccountCurrency = "USD";
    	Resolution _Res = Resolution.Tick;		// Reference resolution for our custom TradeBar
    	private int  _WarmUpPeriod = 10;
    	public decimal _PctRisk = 0.10m;
		private decimal _StopLossPct = 0.05m;
		
		
    	//***Symbol List***
		Dictionary <string, SymbolData> DataDico = new Dictionary <string, SymbolData>();
		List <string> _MySymbolList = new List <string>
		{
			"EURUSD",
			"USDJPY",
			"AUDUSD",
		};
		
		private decimal _TotalEquity;
	}

}
namespace QuantConnect.Algorithm.CSharp
{
	public partial class TestAlgo : QCAlgorithm
	{
		public class SymbolData
	    {	
        	//***Consolidator parameters***
			public static int barPerTimeSpan = 24;											// Number of block of data per custum TradeBar
    		public readonly TimeSpan barPeriod = TimeSpan.FromHours(barPerTimeSpan);		// Set the size of our custum TradeBar
			
			public TickQuoteBarConsolidator TickConsolidator;
			public static int tickBarPeriod = 1000;
			public static TimeSpan tickBarLength = TimeSpan.FromHours(1);
	    	public bool ConsolidatorFlag = false;	// Flag whether a new custom TradeBar has been fully consolidated; used to prevent ONDATA block code to be executed otherwise

        	//***General***
	    	public readonly QCAlgorithm algorithm;
	        public readonly Symbol Symbol;
	        public readonly string BaseSymbol;
	        public readonly string AccountSymbol;
	        
	        public readonly RollingWindow<IBaseDataBar> TickBarsWin;
    		public readonly int windowSize = 5;	
	   		public decimal Holding;
	     	public decimal Price;
	    	public decimal Price_P1;
			public int number_of_ticks;
			
			//***Tick Bar parameters***
			public DateTime TickBarStartTime;
			public DateTime TickBarEndTime;
			public ExponentialMovingAverage numTicksEMAfast;
			public ExponentialMovingAverage numTicksEMAslow;

	    	//***SymbolData class constructor which initializes a new instance of SymbolData***
	    	public SymbolData(QCAlgorithm algorithm, Symbol symbol, string baseSymbol)
	    	{	
	    		this.algorithm = algorithm;
	    		Symbol = symbol;
	    		BaseSymbol = baseSymbol;
	    		number_of_ticks = 0;
	    		TickConsolidator = new TickQuoteBarConsolidator (tickBarLength);
	    		TickBarsWin = new RollingWindow<IBaseDataBar>(windowSize);
	    		numTicksEMAfast = new ExponentialMovingAverage(7);
	    		numTicksEMAslow = new ExponentialMovingAverage(20);
	    		
	    		TickConsolidator.DataConsolidated += (sender, baseData) =>
				{
        			var _tickBar = (IBaseDataBar)baseData;
        			TickBarsWin.Add(_tickBar);
        			ConsolidatorFlag = true;
        			algorithm.Debug($"TickQuoteBar for {Symbol} emitted at {algorithm.Time} with {number_of_ticks} ticks");
        			//numTicksEMAfast.Update(number_of_ticks);
        			//numTicksEMAslow.Update(number_of_ticks);
        			number_of_ticks = 0;
				};
	    		
	    	}
	    
	    		
	    	//***Returns true if all the data in this instance is ready***
	    	public bool IsReady()
	    	{
	    		return TickBarsWin.IsReady;
	    	}
	    }
	}
}
using QuantConnect.Indicators.CandlestickPatterns;

namespace QuantConnect.Algorithm.CSharp
{

    public partial class TestAlgo : QCAlgorithm
    {

		//****************************************************************************************************************************************
		// INITIALIASE BLOCK
		//****************************************************************************************************************************************
        public override void Initialize()
        {
        	SetStartDate(2017, 1, 1);
            SetEndDate(2017, 1, 2);
			SetAccountCurrency(_AccountCurrency);
            SetCash(100000);

			// Loop through our list of symbols and add them to our subscription manager
            foreach (var _symbol in _MySymbolList)
            {
            	var _Forex = AddForex(_symbol, _Res, Market.Oanda, true, 20m);
            	//var _ForexTick = AddForex(_symbol, Resolution.Tick, Market.Oanda, true, 20m);		/// UNCOMMENT TO GET THE ERROR 
            	DataDico.Add(_symbol, new SymbolData(this, _Forex.Symbol, _Forex.BaseCurrencySymbol));
            	Debug($"{_symbol} added");
            }
            
            //SetWarmUp(TimeSpan.FromDays(_WarmUpPeriod));
            SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin);
            
        }
        
        
        
		//****************************************************************************************************************************************
        // ONDATA BLOCK
		//****************************************************************************************************************************************
        public override void OnData(Slice data)
        {
        	//Loop through our dictionary
        	
        	
        	
        	foreach (var ticker in DataDico.Keys)
        	{
        		var symbolData = DataDico[ticker];
        	
        		if(!data.ContainsKey(ticker)){
        			continue;
        		} 
        		
        		if(!data.Ticks.ContainsKey(ticker)){
        			continue;
        		}
        	
				var ticks = data.Ticks[symbolData.Symbol];
				var current_number_of_ticks = ticks.Count;
				symbolData.number_of_ticks += current_number_of_ticks;
				
				foreach(var tick in ticks){
					symbolData.TickConsolidator.Update(tick);
				}
				
				//Check if algorithm is warming up and if indicators are ready, if not break
				if(IsWarmingUp) { continue; }
				if(!symbolData.IsReady()) { continue; }
				if(!symbolData.ConsolidatorFlag) { continue; }
				symbolData.ConsolidatorFlag = false;
				
        		
        	}
        }

    }
}