Overall Statistics |
Total Trades 3912 Average Win 0.08% Average Loss -0.01% Compounding Annual Return 103.844% Drawdown 1.200% Expectancy 0.921 Net Profit 20.131% Sharpe Ratio 8.031 Loss Rate 74% Win Rate 26% Profit-Loss Ratio 6.29 Alpha 0.482 Beta 0.098 Annual Standard Deviation 0.061 Annual Variance 0.004 Information Ratio 5.064 Tracking Error 0.082 Treynor Ratio 4.965 Total Fees $8.30 |
namespace QuantConnect.Algorithm.CSharp { public class TestRenkoConsolidator : QCAlgorithm { private double renkoSize = 0.25; private string symString = "LTCUSD"; private double startingCash = 100; private decimal risk = 0.01m; private BarDirection currentBarDirection = BarDirection.NoDelta; private RenkoBar currentBar; public override void Initialize() { SetStartDate(2017, 06, 01); SetEndDate(2017, 09, 02); SetCash(startingCash); AddCrypto(symString, Resolution.Second, Market.GDAX); SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash); var renko = new RenkoConsolidator((decimal)renkoSize, RenkoType.Wicked); renko.DataConsolidated += OnRenkoBar; SubscriptionManager.AddConsolidator(symString, renko); Debug("RenkoSize: " + renkoSize + " | Risk: " + risk); } public override void OnData(Slice data) { } public void OnRenkoBar(object sender, RenkoBar bar) { currentBar = bar; currentBarDirection = currentBar.Direction; CheckForExitCondition(); CheckForEntryCondition(); } private void CheckForExitCondition() { if(currentBarDirection == BarDirection.Falling) { Liquidate(symString); } } private void CheckForEntryCondition() { Transactions.CancelOpenOrders(symString); if(currentBarDirection == BarDirection.Rising) { decimal units = UnitsToBuy(); decimal limitPrice = currentBar.Close; LimitOrder(symString, units, limitPrice); } } private decimal UnitsToBuy() { decimal dollarsAtRisk = Portfolio.Cash * risk; decimal riskPerUnit = currentBar.Close - (decimal)(2 * renkoSize); decimal unitsToBuy = dollarsAtRisk / riskPerUnit; return unitsToBuy; } } }