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 TypeMethodDescriptionvoidname()onBar(int index) default SignalonBar(int index, double position) Position-aware variant, called byBacktesterwith the quantity currently held (0 when flat, positive when long).default doubleOptional per-trade stop loss as a fraction (0 = disabled).default doubleOptional per-trade take profit as a fraction (0 = disabled).
-
Method Details
-
name
String name() -
init
-
onBar
-
onBar
Position-aware variant, called byBacktesterwith 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).
-