Interface TradingStrategy


public interface TradingStrategy
A bar-driven trading strategy. init(BarSeries) is called once by the backtester (or live engine) to precompute indicators; onBar(int) is then invoked for each bar in order and must be allocation-free for low-latency execution.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    init(BarSeries series)
     
     
    onBar(int index)
     
    default Signal
    onBar(int index, double position)
    Position-aware variant, called by Backtester with the quantity currently held (0 when flat, positive when long).
    default double
    Optional per-trade stop loss as a fraction (0 = disabled).
    default double
    Optional per-trade take profit as a fraction (0 = disabled).
  • Method Details

    • name

      String name()
    • init

      void init(BarSeries series)
    • onBar

      Signal onBar(int index)
    • onBar

      default Signal onBar(int index, double position)
      Position-aware variant, called by Backtester with the quantity currently held (0 when flat, positive when long). Strategies whose entry and exit conditions can both hold on the same bar should override it and evaluate the exit first while long; otherwise a level-type entry rule masks every exit. The default ignores the position.
    • stopLossPct

      default double stopLossPct()
      Optional per-trade stop loss as a fraction (0 = disabled).
    • takeProfitPct

      default double takeProfitPct()
      Optional per-trade take profit as a fraction (0 = disabled).