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
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, 31);
			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));
            }
            
            SetWarmUp(TimeSpan.FromDays(_WarmUpPeriod));
            SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin);
            
        }
        
        
        
		//****************************************************************************************************************************************
        // ONDATA BLOCK
		//****************************************************************************************************************************************
        public override void OnData(Slice data)
        {
        	//Loop through our dictionary
        	foreach (var symbolData in DataDico.Values)
        	{
        		if(!data.ContainsKey(symbolData.Symbol)) { return; }

				//Check if algorithm is warming up and if indicators are ready, if not break
				if(IsWarmingUp) { return; }
				if(!symbolData.IsReady()) { return; }
				if(!symbolData.ConsolidatorFlag) { return; }
				symbolData.ConsolidatorFlag = false;
				
        		symbolData.Price = symbolData.TickBarsWin[0].Close;
	       		symbolData.TickBarStartTime = symbolData.TickBarsWin[0].Time;		/// UNCOMMENT TO GET THE ERROR 
        		symbolData.TickBarEndTime = symbolData.TickBarsWin[0].EndTime;	/// UNCOMMENT TO GET THE ERROR 
        		Debug($"TickBar start time: {symbolData.TickBarStartTime.ToString()} | TickBar end time: {symbolData.TickBarEndTime.ToString()}");

        	}
        }

    }
}
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",
		};
		
		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 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;

			//***Tick Bar parameters***
			public DateTime TickBarStartTime;
			public DateTime TickBarEndTime;

	    	//***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;
	    		
	    		TickConsolidator = new TickQuoteBarConsolidator (tickBarPeriod);
	    	
	    		TickBarsWin = new RollingWindow<IBaseDataBar>(windowSize);
	    		
	    		TickConsolidator.DataConsolidated += (sender, baseData) =>
				{
        			var _tickBar = (IBaseDataBar)baseData;
        			TickBarsWin.Add(_tickBar);
        			ConsolidatorFlag = true;
				};
				
            	algorithm.SubscriptionManager.AddConsolidator(symbol, TickConsolidator);
	    		
	    	}
	    		
	    	//***Returns true if all the data in this instance is ready***
	    	public bool IsReady()
	    	{
	    		return TickBarsWin.IsReady;
	    	}
	    }
	}
}