Skip to content

gecko-71/HyperSniper

Repository files navigation

HyperSniper D12 V7.3 Technical Documentation

Project Goal and Program Overview

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:

  1. 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.
  2. Live Prediction: Providing real-time buy/sell signals (LONG/SHORT) along with analytical justification (Score) and information on blocking filters.
  3. 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.


1. uHyperSniper.pas - The Heart of the Algorithm

This module is responsible for all decision-making logic and technical indicator calculations.

Scoring Algorithm (Point System)

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.

Market Regimes

The algorithm recognizes the state of the market using the ADX indicator:

  • ADX > 30: TREND mode (priority given to moving averages and Supertrend).
  • ADX <= 30: RANGE mode (priority given to RSI, oscillators, and liquidity levels).

Security Filters (Veto)

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.

Example Usage (Delphi)

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;

Detailed Response Structure (TDecisionDetails)

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.

2. uDataManager.pas - Data Management

The module responsible for API communication and data storage.

Data Fetching

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.

Storage Architecture

  • 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).

3. uBacktestEngine.pas - Testing Engine

The module implementing historical simulation.

Backtesting Process

  1. Resampling: The ResampleTF function converts base 1H candles to higher timeframes (4H, D1) in real-time.
  2. Warmup: The engine skips the first 210 candles so that indicators (especially the 200-period moving average) can "warm up" properly.
  3. Iterative Loop: The program steps through history, imitating candle closure and making a TradingDecision for the next opening (Open[i+1]).
  4. PnL Calculation: Profit/Loss is calculated based on the price movement between Open[i+1] and Close[i+1].

Key Elements

  • 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.

About

The HyperSniper Backtester & Live Predictor is an advanced analytical tool written in Delphi 12, designed for algorithmic trading in the cryptocurrency market (Binance Futures).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages