Automated Trading Stop

stop()

if, value

Evaluates a condition and will abort execution if that condition is true.

If the condition is not met, then this command will do nothing, and execution will move on to the next command in the block. Typically you would place these at the start of the command sequence to prevent the orders executing if certain conditions were met.

See also continue which is the same, but with inverted logic.

Arguments
if required string, defaults to always

The name of the condition to check...

Basic Conditions

Condition Meaning
if=always Will always be true - value is ignored.
if=never Will always be false - value is ignored.

Position Size - The size of your current open position. Positive values are long positions, negative values are short positions. On spot exchanges, the position will be considered to be the amount of the asset in your wallet (so will always be >= 0)

Condition Meaning
if=positionLessThan true if your current open position size is less than value.
if=positionLessThanEq true if your current open position size is less than or equal to value.
if=positionGreaterThan true if your current open position size is greater than value.
if=positionGreaterThanEq true if your current open position size is greater than or equal to value.
if=positionLong true if your current open position is long (positive). value is ignored.
if=positionShort true if your current open position is short (negative). value is ignored.
if=positionNone true if you do not have an open position. value is ignored.
if=positionInProfit true if you have open position that is currently in profit. Only meaningful on margin exchanges. value is ignored.
if=positionInLoss true if you have open position that is currently in loss. Only meaningful on margin exchanges. value is ignored.
if=positionIsFlat true if your current position has a PnL of close to zero. Only meaningful on margin exchanges. value is ignored.

Last Price - The last price is calculated as the mid point between the current top bid and ask in the order book.

Condition Meaning
if=priceLessThan true if the current price is less than value.
if=priceLessThanEq true if the current price is less than or equal to value.
if=priceGreaterThan true if the current price is greater than value.
if=priceGreaterThanEq true if the current price is greater than or equal to value.

Date and Time Conditions - All date and time conditions use UTC time only. Dates should be given in the format YYYY-MM-DD and times in the format HH:MM. Times are assumed to be using the 24 hour clock.

Condition Meaning
if=isAfterDate true if the current date is after the date given in value.
if=isOnOrAfterDate true if the current date is on or after the date given in value.
if=isBeforeDate true if the current date is before the date given in value.
if=isOnOrBeforeDate true if the current date is on or before the date given in value.
if=isSameDate true if the current date is the same as the date given in value.
if=isAfterTime true if the current time is after the time given in value.
if=isBeforeTime true if the current time is before the time given in value.
value optional string,

The value to compare against, if needed. It's value will depend on the condition being tested.

Example: Should I place a new limit order?

myApiKeys(XBTUSD) {
    stop(if=positionGreaterThan, value=1000);
    limit(side=buy, amount=500, offset=10);
}

First, check the current position size. If it greater than 1000 contracts, then abort and don't place the limit order.

You can use this approach for basic management of pyramiding orders.

Some images from Unsplash

About Alertatron.com

Your TradingView alerts, with charts, PM'd to you.

Get all your alerts from TradingView, sent to Telegram, Discord, Slack, Email or webhooks, with a chart snapshot attached.

Capture Charts

See a high quality chart with every alert, captured at the moment the alert was triggered. See exactly what the market was doing and make informed decisions.

Automate Trading

Trigger orders on popular cryptocurrency exchanges and trade 24/7. Access powerful algorithmic orders to maximise your profits.

Integrations

Connect your alerts to Telegram (channels, groups and private chats), Discord, Slack, email or send push notifications to other services with webhooks.

Easy To Setup

Nothing to install and no browser extensions. Captures alerts 24/7, even with your computer switched off. Be up and running in seconds.