The HyperSniper Backtester & Live Predictor is an advanced analytical tool written in Delphi 12, designed for algorithmic trading in the cryptocurrency market (Binance Futures).
The main goals of the program are:
- Strategy Verification (Backtesting): Allowing for the testing of trading strategies on historical data . This enables a quick assessment of Profitability (PnL) and Efficiency (Hit Rate) before committing real capital.
- Live Prediction: Providing real-time buy/sell signals (LONG/SHORT) along with analytical justification (Score) and information on blocking filters.
- Analytics Automation: Automatically fetching market data (OHLCV), investor activity (Open Interest), and position holding costs (Funding Rates).
This document describes the architecture and logic of the three key modules of the HyperSniper system in the Delphi 12 version.
This module is responsible for all decision-making logic and technical indicator calculations.
The system does not rely on a single indicator but on a sum of points (Score) generated by multiple components:
- EMA Stack (+2 / -2 pts): Analysis of moving average alignment (9, 21, 50, 200).
- MACD (+2 / -2 pts): Histogram direction and its change relative to the previous candle.
- RSI (+/- pts): Points for exiting overbought/oversold areas.
- MTF Sync (+2 / -2 pts): Trend synchronization from 4H and D1 timeframes.
- Session (+1 pt): Bonus for activity during liquid hours (defined in the session).
- FVG (Fair Value Gap): Points for detecting liquidity gaps and their direction.
The algorithm recognizes the state of the market using the ADX indicator:
- ADX > 30:
TRENDmode (priority given to moving averages and Supertrend). - ADX <= 30:
RANGEmode (priority given to RSI, oscillators, and liquidity levels).
Before an entry decision (LONG/SHORT) is made, it must pass through a filter system:
- ATR_SILENCE_BLOCK: Blocking during extremely low volatility.
- LOW_VOLUME: Blocking when there is no volume.
- SUPERTREND_MISMATCH: Prohibition of trading against the main Supertrend direction.
- MTF_D1_BLOCK: Prohibition of trading against the trend from the daily timeframe.
- BTC_CORRELATION_VETO: Blocking if the coin's direction conflicts with the global BTC trend.
To get a prediction, you must call the TradingDecision function, passing arrays of historical data (OHLCV) for three timeframes (1H, 4H, Daily).
var
Decision: Integer;
Details: TDecisionDetails;
begin
// Call the main decision function
Decision := uHyperSniper.TradingDecision(
Closes1H, Highs1H, Lows1H, Volumes1H, // 1H Data
Closes4H, Highs4H, Lows4H, // 4H Data
ClosesD, HighsD, LowsD, // Daily Data
Details, // out: decision details
60, // MinutesTo4hClose
True // ReturnDetails
);
// Result interpretation:
// Decision = 0 (NO_OPEN) -> Wait (WAIT)
// Decision = 1 (LONG_POS) -> Buy (LONG)
// Decision = 2 (SHORT_POS) -> Sell (SHORT)
Writeln('Numerical Score: ', Details.Score);
if Decision = 0 then
Writeln('Reason for waiting: ', Details.Filters[0]);
end;The Details record provides deep insights into the model's reasoning:
- Details.Score: The final numerical value calculated by the points system. Positive for bullish, negative for bearish.
- Details.Filters: An array of strings containing the "Veto" filters that blocked the trade (e.g.,
ATR_SILENCE_BLOCK). - Details.Flags: An array of technical observations detected by the model (e.g.,
BULL_DIV,MS_HIGHER_LOW). - Details.EMA / Details.MACD / Details.RSI: Structured records containing the raw values of the underlying indicators used for the decision.
The module responsible for API communication and data storage.
The system uses the TDataFetchManager class, which handles:
- Binance Futures API: Fetching OHLCV candles (1H interval).
- Derivative Data: Fetching Open Interest and Funding Rates parameters.
- NetHTTPClient: Utilizing native Delphi libraries for asynchronous and secure HTTPS connections.
- TFDMemTable: All operational data is stored in RAM within FireDAC structures, ensuring lightning-fast access.
- Local Cache: Data is cached in the
cache_data/folder in CSV or JSON format to minimize the number of API queries during program restarts. - Unix Timestamp: The system operates on milliseconds (Unix MS).
The module implementing historical simulation.
- Resampling: The
ResampleTFfunction converts base 1H candles to higher timeframes (4H, D1) in real-time. - Warmup: The engine skips the first
210candles so that indicators (especially the 200-period moving average) can "warm up" properly. - Iterative Loop: The program steps through history, imitating candle closure and making a
TradingDecisionfor the next opening (Open[i+1]). - PnL Calculation: Profit/Loss is calculated based on the price movement between
Open[i+1]andClose[i+1].
- Parity Synchronization: Implementation of the
minutes_to_4h_close, ensuring 100% reproducibility of results. - Memory Management: Automatic clearing of signal lists and temporary tables to avoid memory leaks during long tests.