Overall Statistics
Total Trades
10001
Average Win
0.01%
Average Loss
-0.02%
Compounding Annual Return
0.560%
Drawdown
1.700%
Expectancy
0.017
Net Profit
1.742%
Sharpe Ratio
0.686
Probabilistic Sharpe Ratio
27.052%
Loss Rate
31%
Win Rate
69%
Profit-Loss Ratio
0.47
Alpha
0.005
Beta
-0.002
Annual Standard Deviation
0.007
Annual Variance
0
Information Ratio
-0.841
Tracking Error
0.119
Treynor Ratio
-1.947
Total Fees
$0.00
namespace QuantConnect.Algorithm.CSharp
{
     public class RenkoAlgorithm : QCAlgorithm
    {
    	RenkoBar[] prevDirections=new RenkoBar[1];
    	
    	int	changes=0;
    	int bricks=1, allBricks=0;
    	int noDelta=0;
    	string[] pears=  { "EURUSD"}; 
    	int[] reverse={0};
    	int startAmount=1000000;
    	decimal parcent=0.1m;
    	decimal amount=0;
    	List<ChangeDirectionData> ChangeList=new List<ChangeDirectionData>();
        public override void Initialize() 
        {
            // cash allocation
            SetCash(startAmount);  
            SetStartDate(2013, 01, 01);  
            SetEndDate(2020, 05, 11);
            
            var renkoCloses = new RenkoConsolidator[1];
             for(int i=0;i<pears.Length;i++)
            {
             renkoCloses[i] = new RenkoConsolidator(0.001m);
            }
            

	      
	        
           
            //var renkoATR = ATR("EURUSD",14, MovingAverageType.Simple, Resolution.Daily);
            for(int i=0;i<pears.Length;i++)
            {
            	 renkoCloses[i].DataConsolidated += (sender, consolidated) =>
            {
                // call event handler for renko data

                HandleRenkoCloseRaise(consolidated);   


                
            };
            AddSecurity(SecurityType.Forex, pears[i], Resolution.Minute); //Minute, Second or Tick
             Securities[pears[i]].FeeModel = new ConstantFeeModel(0m);
             SubscriptionManager.AddConsolidator(pears[i], renkoCloses[i]);

            }



		

            
            var stockPlot = new Chart("Renko");
            var buyOrders = new Series("Buy", SeriesType.Bar, 0);
            stockPlot.AddSeries(buyOrders);
            AddChart(stockPlot);
   


        }
        OrderTicket buyTicket=null;
        OrderTicket sellTicket=null;

        private void HandleRenkoCloseRaise(RenkoBar data)
		{
			int index=GetIndexOfPear(data.Symbol);
			bool isReverse=Array.FindIndex(reverse, i=>i==index)!=-1;
			if(prevDirections[index]!=null)
			{
				if(prevDirections[index].Direction==data.Direction)
				{
				bricks++;	
				}
				else 
			    {
				
				changes++;
				ChangeList.Add(new ChangeDirectionData{Date=data.Start,NumChanges=bricks});
				allBricks+=bricks;
				bricks=1;
				
				if(data.Direction==BarDirection.Rising)
				{
                if(!isReverse)
				MarketOrder(data.Symbol,startAmount*parcent*-1 );
				else Liquidate(data.Symbol);

				}
				else 
				{

				 if(isReverse)
				MarketOrder(data.Symbol,startAmount*parcent );
				else Liquidate(data.Symbol);
				}
			
		} 
	
			
			
				 }
			else
			{
			  if(data.Direction==BarDirection.Rising)
			   	MarketOrder(data.Symbol,startAmount*parcent*-1);
			   	//else
			  //	MarketOrder(pear,startAmount*parcent);


		    }
		prevDirections[index]=data;
				 
			}
			
		
			
		
		
        
        public override void OnData(Slice data) 
        {
        	
        	// slice has lots of useful information
        	//if (!data.ContainsKey("EURUSD")) return;
        	//Ticks theticks = data.Ticks;
        	//Plot("Renko", "Buy", data["EURUSD"].Price);
        }
        
        public override void  OnEndOfAlgorithm() 
        { 
         
       Liquidate();	

         int moreThanFive=0;
    	List<ChangeDirectionData> OneChanges=new List<ChangeDirectionData>();
         foreach(var item in ChangeList)
         { if(item.NumChanges==1)
             moreThanFive++;
             else
             {
             if(moreThanFive>=5)
             {
             	OneChanges.Add(new ChangeDirectionData{Date=item.Date,NumChanges=moreThanFive});
             	
             }
             moreThanFive=0;	
             }
         
          Console.WriteLine(String.Format("     {0}       {1}    ",item.NumChanges,item.Date));

         }
         

          Console.WriteLine("More than five!!!!!!!!!!   "+OneChanges.Count );
          
          foreach(var item in OneChanges)
          {
          Console.WriteLine(String.Format("   {0}      {1}  ",item.NumChanges,item.Date));

          }



         
        
        }
        
        public int GetIndexOfPear(Symbol symbol)
        {
        	return Array.FindIndex(pears, p => p == symbol);
        }
        
        
    }



    }
using QuantConnect.Data.Custom.USEnergy;
namespace QuantConnect
{
	public class USEnergyAlphaModel : AlphaModel
	{
		private Symbol _energy;
		
		public USEnergyAlphaModel(QCAlgorithm algorithm)
		{
			_energy = algorithm.AddData<USEnergy>(USEnergy.Petroleum.UnitedStates.WeeklyGrossInputsIntoRefineries).Symbol;
		}
		
		public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
		{
			var insights = new List<Insight>();
			
			if (!data.ContainsKey(_energy))
			{
				return insights;
			}
			
			var energy = data.Get<USEnergy>(_energy);

			// The U.S. Energy Information Administration (EIA) is a principal agency of the U.S. Federal Statistical System
	        // responsible for collecting, analyzing, and disseminating energy information to promote sound policymaking,
	        // efficient markets, and public understanding of energy and its interaction with the economy and the environment.
	        // EIA programs cover data on coal, petroleum, natural gas, electric, renewable and nuclear energy. EIA is part of the U.S. Department of Energy.
	        
	        // Find more categories here: https://github.com/QuantConnect/Lean/blob/master/Common/Data/Custom/USEnergy/USEnergy.Category.cs
	        
	        return insights;
		}
		
		public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
        {
            // For instruction on how to use this method, please visit
            // https://www.quantconnect.com/docs/algorithm-framework/alpha-creation#Alpha-Creation-Good-Design-Patterns
        }
	}
}
namespace QuantConnect {

   
    public class ChangeDirectionData{
     public DateTime Date { get; set; }
     public int NumChanges { get; set; }

 
    }
}