| Overall Statistics |
|
Total Orders 180 Average Win 1.01% Average Loss -0.94% Compounding Annual Return -3.781% Drawdown 15.200% Expectancy -0.057 Start Equity 200000.00 End Equity 185128.42 Net Profit -7.436% Sharpe Ratio -0.588 Sortino Ratio -0.423 Probabilistic Sharpe Ratio 1.790% Loss Rate 54% Win Rate 46% Profit-Loss Ratio 1.07 Alpha -0.045 Beta 0.034 Annual Standard Deviation 0.077 Annual Variance 0.006 Information Ratio -0.027 Tracking Error 0.713 Treynor Ratio -1.352 Total Fees $3015.74 Estimated Strategy Capacity $44000000.00 Lowest Capacity Asset BTCBUSD 18R Portfolio Turnover 5.91% |
from AlgorithmImports import *
class BinanceCryptoFutureDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2021, 1, 1)
self.set_end_date(2023, 1, 1)
self.set_cash("BUSD", 100000)
self.set_brokerage_model(BrokerageName.BINANCE_FUTURES, AccountType.MARGIN)
crypto_future = self.add_crypto_future("BTCBUSD", Resolution.DAILY)
self.btcbusd = crypto_future.symbol
self.fast_ma = self.SMA(self.btcbusd, 10, Resolution.DAILY)
self.slow_ma = self.SMA(self.btcbusd, 50, Resolution.DAILY)
# Historical data
history = self.history(self.btcbusd, 10, Resolution.DAILY)
# Order variables
self.stop_loss_percentage = 0.01
self.take_profit_percentage = 0.02
self.current_position = None
def on_data(self, slice: Slice) -> None:
if not slice.bars.contains_key(self.btcbusd) or not slice.quote_bars.contains_key(self.btcbusd):
return
if not self.fast_ma.IsReady or not self.slow_ma.IsReady:
return
# monitor price scale manually
current_price = slice.bars[self.btcbusd].price
if self.current_position is None and self.fast_ma.Current.Value > self.slow_ma.Current.Value:
# Place a long trade
self.current_position = self.MarketOrder(self.btcbusd, 1)
entry_price = slice.bars[self.btcbusd].price
self.entry_price = current_price
self.Debug(f"Entered Long at {self.entry_price}")
# Exit conditions: Stop-loss or take-profit for long position
elif self.current_position is not None:
stop_loss_price = self.entry_price * (1 - self.stop_loss_percentage)
take_profit_price = self.entry_price * (1 + self.take_profit_percentage)
if current_price <= stop_loss_price:
self.Liquidate(self.btcbusd)
self.current_position = None
self.Debug(f"Exited Long for Stop Loss at {current_price}")
elif current_price >= take_profit_price:
self.Liquidate(self.btcbusd)
self.current_position = None
self.Debug(f"Exited Long for Take Profit at {current_price}")
# Additional condition to exit on trend reversal
if self.current_position is not None and self.fast_ma.Current.Value < self.slow_ma.Current.Value:
self.Liquidate(self.btcbusd)
self.current_position = None
self.Debug(f"Exited Long on Trend Reversal at {current_price}")