Risk
9 entries. What each one takes, what it returns, and a working example.
Does not return a value; sets the backtest commission rate to this value.
Applied separately to each of entry and exit. "percent" value is a percent of the trade size; "cash_per_order" is a fixed cash amount per order; "cash_per_contract" is a cash amount per contract (unit). Give a value close to your real trading cost to keep results realistic.
commission(0.1) enterLong(crossover(close, sma(close, 20))) exit(crossunder(close, sma(close, 20))) plot(close)
Backtests a simple crossover strategy with 0.1% commission per trade.
commission(2, "cash_per_order") enterLong(crossover(close, sma(close, 20))) exit(crossunder(close, sma(close, 20))) plot(close)
A fixed 2-unit cash commission per order (not a percent) — a flat-fee broker model.
Does not return a value; sets the backtest's starting capital (the equity scale).
Sets the scale of the equity curve and the absolute profit/loss figures; it does not affect percentage results.
initialCapital(100000) enterLong(crossover(close, sma(close, 20))) exit(crossunder(close, sma(close, 20))) plot(close)
Backtests the strategy with 100000 of starting capital.
Does not return a value; sets isolated margin mode.
Liquidation only takes the allocated margin, not the entire account. It limits risk; it does not create an advantage on its own.
leverage(kaldıraç, shortKaldıraç?)
Does not return a value; sets the futures (cross) leverage.
Return and cost are multiplied by x. Warning: liquidation can wipe out the entire account on a single bad bar; use it moderately in a validated setup.
Does not return a value; halts opening new positions once drawdown exceeds this percent.
A protective gate: once the drop from peak equity crosses the limit, new entries are blocked. It does not close an open position, it only stops new risk.
maxDrawdown(20) enterLong(crossover(close, sma(close, 20))) exit(crossunder(close, sma(close, 20))) plot(close)
Backtests the strategy with a guard that takes no new entries once drawdown exceeds 20%.
Returns no value; it sets the cap on multi-entry scaled entries.
The default is 1 (a single entry portion). When n>1, a repeated entry signal in the same direction adds a new entry portion; once the cap is reached, no more are added.
pyramiding(3) enterLong(rsi(close,14) < 40, id='L') exit(rsi(close,14) > 60)
Scaled entry of up to 3 entry legs while RSI is weak; positionSize +1→+2→+3.
pyramiding(2) enterLong(crossover(close, sma(close,10))) exit(crossunder(close, sma(close,10)))
On the second cross within the same trend a second entry part is added (at most 2).
Returns nothing. When called, sizing switches from the default %equity to cash-based; quantity taken = amount / price.
If never called, the default %equity sizing is kept. defaultEntryQty takes a fixed quantity; sizeByCash instead divides a fixed amount by price to set the quantity. If margin is insufficient the trade is skipped.
sizeByCash(1000) enterLong(crossover(close, sma(close, 20))) exit(crossunder(close, sma(close, 20))) plot(close)
Uses 1000 of cash on each trade (quantity = 1000 / price).
Does not return a value; ties the position size to this fraction of equity.
The value is clamped to 0-100. To trade with a set percent of the account instead of a fixed lot — profit/loss scales by this fraction.
sizeByEquity(50) enterLong(crossover(close, sma(close, 20))) exit(crossunder(close, sma(close, 20))) plot(close)
Backtests the strategy using 50% of equity on each trade.
Does not return a value; sets slippage to this value (added to the trade cost).
Models the order filling slightly worse than the expected price. Makes results more realistic in thin or fast markets.
slippage(0.05) enterLong(crossover(close, sma(close, 20))) exit(crossunder(close, sma(close, 20))) plot(close)
Backtests the strategy with 0.05% slippage per trade.