Stops trading for the rest of the day once the day's loss reaches a set amount.
strategy.risk.max_intraday_loss(value, type) caps the loss allowed within a single trading day. When the day's loss reaches the limit, the emulator cancels pending orders, closes open positions and places no new orders until the next trading day starts.
The loss is measured against the equity at the start of the day, as a percentage when type is strategy.percent_of_equity and as an amount in the account currency when it is strategy.cash.
Syntax
strategy.risk.max_intraday_loss(value: simple int/float, type: simple string, alert_message: simple string (optional)) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| value | simple int/ | required | The largest loss allowed in one trading day, in the unit chosen by type. Must be positive. |
| type | simple string | required | How value is read: strategy.percent_of_equity for a percentage of equity, or strategy.cash for an amount in the account currency. |
| alert_message | simple string | na | Text sent with the alert when the rule stops the strategy. With na, the alert carries the default message. |
Returns
Nothing. The rule stays in force for the whole run.
Remarks
- Call it once, at the top level of the script. It needs an intraday chart to mean anything; on a daily chart each bar is a whole day.
- Trading resumes on the next day, which is the difference from
strategy.risk.max_drawdown.
Example
//@version=6
strategy("Daily loss cap", overlay = true)
strategy.risk.max_intraday_loss(2, strategy.percent_of_equity)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
bgcolor(session.isfirstbar ? color.new(color.blue, 90) : na)See also
strategy.risk.max_drawdownstrategy.risk.max_intraday_filled_ordersstrategy.risk.max_cons_loss_daysstrategy.percent_of_equitystrategy.cash
Runs on Sidechair