CODESCRIPT

Risk

9 entries. What each one takes, what it returns, and a working example.

commission(değer, tip?)

Does not return a value; sets the backtest commission rate to this value.

değer
number
Commission value. Percent when type="percent"; a cash amount for the cash types.
tip
string
Optional. "percent" (default, percent × trade size) / "cash_per_order" (fixed cash/order) / "cash_per_contract" (cash/contract).
NOTE

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.

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

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

initialCapital(amount)

Does not return a value; sets the backtest's starting capital (the equity scale).

amount
number
The starting capital (account size).
NOTE

Sets the scale of the equity curve and the absolute profit/loss figures; it does not affect percentage results.

CODESCRIPT
initialCapital(100000)
enterLong(crossover(close, sma(close, 20)))
exit(crossunder(close, sma(close, 20)))
plot(close)

Backtests the strategy with 100000 of starting capital.

isolated(leverage, marginPct)

Does not return a value; sets isolated margin mode.

leverage
number
Leverage multiplier.
marginPct
number
Percent of equity set aside as margin on each trade.
NOTE

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.

x
number
Leverage multiplier (e.g. 3).
NOTE

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.

maxDrawdown(pct)

Does not return a value; halts opening new positions once drawdown exceeds this percent.

pct
number
The maximum allowed drawdown percent.
NOTE

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.

CODESCRIPT
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%.

pyramiding(n)

Returns no value; it sets the cap on multi-entry scaled entries.

n
number
Maximum number of open entry parts allowed in the same direction.
NOTE

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.

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

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

sizeByCash(tutar)

Returns nothing. When called, sizing switches from the default %equity to cash-based; quantity taken = amount / price.

tutar
number
Fixed cash amount to use on each trade.
NOTE

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.

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

sizeByEquity(pct)

Does not return a value; ties the position size to this fraction of equity.

pct
number
The percent of equity to use on each trade (0-100).
NOTE

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.

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

slippage(pct)

Does not return a value; sets slippage to this value (added to the trade cost).

pct
number
Slippage per trade (one side, percent).
NOTE

Models the order filling slightly worse than the expected price. Makes results more realistic in thin or fast markets.

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