Overall Statistics Total Trades0Average Win0%Average Loss0%Compounding Annual Return0%Drawdown0%Expectancy0Net Profit0%Sharpe Ratio0Probabilistic Sharpe Ratio0%Loss Rate0%Win Rate0%Profit-Loss Ratio0Alpha0Beta0Annual Standard Deviation0Annual Variance0Information Ratio-19.258Tracking Error0.158Treynor Ratio0Total Fees$0.00Estimated Strategy Capacity$0
class FocusedBlueMosquito(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2020, 11, 6)  # Set Start Date
self.SetEndDate(2020, 11, 10)
self.SetCash(100000)  # Set Strategy Cash
self.gap_finder = GapFinder(self, self.symbol, 10)
self.Log(f"Gap finder log:\n{self.gap_finder.log.to_string()}")

class GapFinder:
def __init__(self, algorithm, symbol, days):
# Warm up history
history = algorithm.History(symbol, days + 1, Resolution.Daily)
if history.empty:
self.log = pd.DataFrame()
return
history = history.loc[symbol].drop('volume', axis=1)

# Calculate gaps
history['yesterdays_close'] = history['close'].shift(1)
history['gap'] = history.open - history.yesterdays_close
history = history.dropna()

# Check which gaps have filled
for time, row in history.iterrows():
if row.gap == 0:
continue

filled = False
for future_time, future_row in history.loc[time:].iterrows():
gap_up_filled = row.gap > 0 and future_row.low <= row.close
gap_down_filled = row.gap < 0 and future_row.high >= row.close
if gap_up_filled or gap_down_filled:
filled = True
break
history.loc[time, 'filled'] = filled

# Save gap log
self.log = history