Actions
Actions are elements tied to a user set condition producing a specific effect when the assigned condition is true.
Actions have the structure @keyword(), starting with @, with an identifier, and ().
Some actions can have a condition assigned to them using =. When the assigned condition is true the action will trigger.
Like functions in classical programming languages, actions can have arguments located within (), adding further degrees of control over the action.
Actions used for scripted alerts are also available for scripted strategies, however, this page only lists the actions that are exclusively used for scripted strategies.
To see a list of other actions, see scripted alerts actions
@long
The @long action allows entering a long position when the associated condition is true.
Syntax
@long(limit, stop, alert_message)Arguments
limit (float): Optional. Limit price for the order. Accepts data placeholders as values. If specified, a limit order is created.
stop (float): Optional. Stop price for the order. Accepts data placeholders as values. If specified, a stop order is created.
If both limit and stop are specified, a stop-limit order is created.
alert_message (string): Optional. Alert message sent when the order is opened. Data placeholders can be used within the message, these will be replaced by their corresponding value when the alert triggers.
Examples
// Go long when the price is greater than the opening price
@long() = {close} > {open}// Go long with a limit order at the previous high
@long(limit = {high[1]}) = {close} > {open}// Go long with a stop order at the previous low
@long(stop = {low[1]}) = {close} > {open}// Go long with a stop-limit order
@long(limit = {high[1]}, stop = {low[1]}) = {close} > {open}// Go long with an alert message containing the entry price
@long(alert_message = "Long entry at {close}") = {close} > {open}Remarks
By default a long position is entered at the opening of the next bar. Using "fill on bar close" from the settings in PROPERTIES → FILL ORDERS will open a position at the close of the bar the condition is true.
@short
The @short action allows entering a short position when the associated condition is true.
Syntax
@short(limit, stop, alert_message)Arguments
limit (float): Optional. Limit price for the order. Accepts data placeholders as values. If specified, a limit order is created.
stop (float): Optional. Stop price for the order. Accepts data placeholders as values. If specified, a stop order is created.
If both limit and stop are specified, a stop-limit order is created.
alert_message (string): Optional. Alert message sent when the order is opened. Data placeholders can be used within the message, these will be replaced by their corresponding value when the alert triggers.
Examples
// Go short when the price is lower than the opening price
@short() = {close} < {open}// Go short with a limit order at the previous low
@short(limit = {low[1]}) = {close} < {open}// Go short with a stop order at the previous high
@short(stop = {high[1]}) = {close} < {open}// Go short with a stop-limit order
@short(limit = {low[1]}, stop = {high[1]}) = {close} < {open}// Go short with an alert message containing the entry price
@short(alert_message = "Short entry at {close}") = {close} < {open}Remarks
By default a short position is entered at the opening of the next bar. Using "fill on bar close" from the settings in PROPERTIES -> FILL ORDERS will open a position at the close of the bar the condition is true.
@exit_long
The @exit_long action closes all open long positions when the associated condition is true.
Syntax
@exit_long(qty, alert_message)Arguments
qty (float): Optional. Number of contracts/lots/shares/units to close on exit for a long position. If the character % is present, the specified % of the long position is closed. If not provied the entire position is closed.
alert_message (string): Optional. Alert message sent when the order is closed. Data placeholders can be used within the message, these will be replaced by their corresponding value when the alert triggers.
Examples
// Exit long position when price is below the price 14 bars ago
@exit_long() = {close} < {close[14]}// Exit 50 contracts/lots/shares/units from the long position
// when price is below the price 14 bars ago
@exit_long(50) = {close} < {close[14]}// Exit 50% of the long position
// when price is below the price 14 bars ago
@exit_long(50%) = {close} < {close[14]}// Exit long position with an alert message containing the exit price
@exit_long(alert_message = "Long exit at {close}") = {close} < {close[14]}Remarks
By default, a long position is exited at the opening of the next bar. You can enable "fill on bar close" from PROPERTIES → FILL ORDERS to trigger the exit at the bar close instead.
@exit_short
The @exit_short action closes all open short positions when the associated condition is true.
Syntax
@exit_short(qty, alert_message)Arguments
qty (float): Optional. Number of contracts/lots/shares/units to close on exit for a short position. If the character % is present, the specified % of the short position is closed. If not provied the entire position is closed.
alert_message (string): Optional. Alert message sent when the order is closed. Data placeholders can be used within the message, these will be replaced by their corresponding value when the alert triggers.
Examples
// Exit short position when the high price is above previous low price
@exit_short() = {high} > {low[1]}// Exit 50 contracts/lots/shares/units from the short position
// when the high price is above previous low price
@exit_short(50) = {high} > {low[1]}// Exit 50% of the short position
// when the high price is above previous low price
@exit_short(50%) = {high} > {low[1]}// Exit short position with an alert message containing the exit price
@exit_short(alert_message = "Short exit at {close}") = {high} > {low[1]}Remarks
By default, a short position is exited at the opening of the next bar. To exit at the close of the bar where the condition is true, enable "fill on bar close" from PROPERTIES → FILL ORDERS.
@exit_all
The @exit_all action closes all open positions (long or short and scripted/unscripted) when the associated condition is true.
Syntax
@exit_all()Examples
// Exit all positions when the closing price is above the previous high price
@exit_all() = {close} > {high[1]}Remarks
This exits both scripted long and short positions, but also any other long/short condition you may have set.
By default, the exit occurs at the next bar’s open unless "fill on bar close" is enabled in PROPERTIES → FILL ORDERS.
@start_date
The @start_date action determines the starting date of the scripted strategy evaluation using a Datestring placeholder.
Syntax
@start_date({YYYY-MM-DDThh:mm:ss±hh:mm})Arguments
datestring: Datestring placeholder, must comply with the ISO 8061 standard. The time and timezone are optional.
Examples
@long = {close} > {open}
@short = {close} < {open}
// Only evaluate the strategy starting 2025
@start_date({2025-01-01})Remarks
The Timezone setting does not affect this placeholder. Default timezone for this placeholder is UTC-0.
@end_date
The @end_date action determines the starting date of the scripted strategy evaluation using a Datestring placeholder.
Syntax
@end_date({YYYY-MM-DDThh:mm:ss±hh:mm})Arguments
datestring: Datestring placeholder, must comply with the ISO 8061 standard. The time and timezone are optional.
Examples
@long = {close} > {open}
@short = {close} < {open}
// Only evaluate the strategy prior to 2025
@end_date({2025-01-01})Remarks
The Timezone setting does not affect this placeholder. Default timezone for this placeholder is UTC-0.
@only_scripted
The @only_scripted action determines if only scripted entries/exits should be considered during the backtest. If true it will ignore any other entry condition set in the other Backtester settings.
Syntax
@only_scripted()Examples
// Only use the scripted strategy for the backtest
@only_scripted() = true