TopicTrading Software
Backtesting, broker APIs and market-data tooling. Engineering only, never advice.
Short answer: To resample tick data to OHLCV in pandas, sort trades by time, set a UTC DatetimeIndex, then join price.resample('1min', label='left', closed='left').ohlc() with size.resample('1min').sum(). Bars are stamped at their start, so shift them before use.
Read the full answer
Short answer: A backtest that looks too good after resample almost always leaks the future: a bar stamped at its start is forward-filled onto lower-timeframe rows, so every minute already knows the bar's close. Shift the signal one bar, then re-test.
Read the full answer
Short answer: Pandas RSI is different from TradingView because most code uses rolling().mean() or ewm(span=n) instead of Wilder smoothing, which is ewm(alpha=1/n, adjust=False), and because seeds differ. After about 10n bars, correct versions agree.
Read the full answer
Short answer: ibapi error 10089 means the API request needs a market data subscription that the API session cannot use yet, usually a missing Market Data API Acknowledgement. Delayed data is still available through reqMarketDataType(3).
Read the full answer
Short answer: IBKR error 10197 market data means the same username has a competing live session on another TWS, Gateway, Client Portal or mobile login. Close it or use a separate data username. Errors 354 and 10167 are subscription issues.
Read the full answer
Short answer: Walk forward validation in Python means repeatedly optimizing parameters on a training window, testing them on the next unseen block, advancing the window, and judging only the stitched out-of-sample returns.
Read the full answer
Short answer: In a market vs limit vs stop vs stop-limit order API, market has no price, limit sets a worst acceptable price, stop uses stop_price only as a trigger that becomes a market order, and stop-limit triggers into a limit order.
Read the full answer
Short answer: Fix intraday market data time zone and daylight saving problems by storing everything as tz-aware UTC, localizing naive vendor timestamps with an IANA zone, and converting to the exchange zone only for session logic.
Read the full answer
Short answer: Continuous futures contract backtesting needs a stitched series: use additive (Panama) back-adjustment for point-based P&L and point-distance indicators, ratio adjustment for percentage returns, unadjusted data for price levels, and roll on the prior day's volume or open interest.
Read the full answer
Short answer: OHLCV data differs between providers mostly because of feed scope (consolidated vs single venue), time labelling, session boundaries and trade filtering, not code bugs. Diagnose by joining both feeds on UTC timestamps and bucketing the gaps.
Read the full answer
Short answer: To make Backtrader close position at the end of a backtest, send self.close() on the second-to-last bar (len(data) == data.buflen() - 1) or enable cheat-on-close. stop() runs too late, because no more bars are processed.
Read the full answer
Short answer: A vectorized backtest in pandas computes the signal, a one-bar-lagged position, returns, costs and the equity curve as whole-column operations instead of a row loop, often 100x or more faster than iterrows, as long as you use position = signal.shift(1).
Read the full answer