| Overall Statistics |
|
Total Orders 1 Average Win 0% Average Loss 0% Compounding Annual Return 3.507% Drawdown 8.100% Expectancy 0 Start Equity 1000000 End Equity 1246667.13 Net Profit 24.667% Sharpe Ratio -0.101 Sortino Ratio -0.109 Probabilistic Sharpe Ratio 13.286% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.023 Beta 0.201 Annual Standard Deviation 0.039 Annual Variance 0.001 Information Ratio -0.716 Tracking Error 0.137 Treynor Ratio -0.019 Total Fees $3.42 Estimated Strategy Capacity $1800000000.00 Lowest Capacity Asset QQQ RIWIV7K5Z9LX Portfolio Turnover 0.00% Drawdown Recovery 715 |
#region imports
from AlgorithmImports import *
#endregion
"""
Here is a conventional QuantConnect example of a **limit buy order** for QQQ.
This example places a limit buy order for QQQ at 1% below the current closing price.
The order will only fill if QQQ trades down to the limit price or lower.
This is conventional because a buy limit order is used when the strategy wants to purchase an asset at a specified price or better, rather than chasing the market higher.
For example, if QQQ closes at $400, the algorithm submits a limit buy order at $396.
The order will not fill unless QQQ trades at $396 or below.
This makes the strategy a simple pullback-entry system rather than a breakout-entry system.
"""
#region imports
from AlgorithmImports import *
#endregion
class ConventionalLimitOrderExample(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 1)
self.SetEndDate(2025, 5, 25)
self.SetCash(1000000)
self.qqq = self.AddEquity("QQQ", Resolution.Daily).Symbol
# Strategy parameters
self.allocation = 0.10 # Invest 10% of portfolio value
self.limit_discount = 0.01 # Buy only if QQQ trades 1% below current close
self.order_ticket = None
def OnData(self, data):
if not data.ContainsKey(self.qqq):
return
price = self.Securities[self.qqq].Close
if price <= 0:
return
# Do not place a new order if already invested or if an order is open
if self.Portfolio[self.qqq].Invested:
return
open_orders = self.Transactions.GetOpenOrders(self.qqq)
if len(open_orders) > 0:
return
# Conventional limit buy:
# Buy QQQ only at this price or better.
# Since this is a buy order, "better" means lower than or equal to the limit price.
limit_price = price * (1 - self.limit_discount)
quantity = int((self.Portfolio.TotalPortfolioValue * self.allocation) / limit_price)
if quantity > 0:
self.order_ticket = self.LimitOrder(
self.qqq,
quantity,
limit_price,
tag=f"Limit buy QQQ at 1% below close: {limit_price:.2f}"
)