Our plans and pricing are changing on 1st November. Learn more...

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

Where value is used, it can be one of the following:-

  • A number (eg 100)
  • A percentage value (eg 5%, 5%%, 5%b, 5%a, 5%p) - these are treated the same as percentages in the amount property of most order types.
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=positionOpen true if you have an open position (any amount, long or short). 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.
if=positionEq true if your current open position is exactly the same value as value. Note that long positions will be a positive value and short positions will be a negative value

Absolute Position Size - The size of your current open position, ignoring if you are long or short. For example, if you are long 100 contracts, position size would be considered to be 100. If you were short 50 contracts, position size for the following conditions would be considered to be 50

Value can be any of the values supported by the Position options above.

Condition Meaning
if=positionSizeGreaterThan true if your current absolute open position size is greater than value.
if=positionSizeGreaterThanEq true if your current absolute open position size is greater than or equal to value.
if=positionSizeLessThan true if your current absolute open position size is less than value.
if=positionSizeLessThanEq true if your current absolute open position size is less than or equal to value.
if=positionSizeEq true if your current open absolute position size is exactly the same size as value. Note that an absolute position size of 100 could be 100 long or 100 short.

Price - Compare with the current price. The current price is calculated as the mid point between the current top bid and ask in the order book. Value can be:-

  • A number (eg 9200)
  • A percentage (eg 5%) treated as an offset from the price. Positive values, like 5%, calculate a value that is 5% higher than the current price. Negative values, like -5%, calculate a value lower than the current price.
  • An offset from the average entry price (eg, e50 or e10%). Current price is used when there is no open position. Positive values offset higher than the average entry, negative values offset lower than the average entry.
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.

Fixed Value tests - Compare the value with a fixed value. This is useful for adding conditions from a TradingView indicator via the placeholder features.

Condition Meaning
if=valueIsOne true if the value given is equal to 1.
if=valueIsZero true if the value given is equal to 0.
if=valueIsTrue true if the value is either 1 or 'true'.
if=valueIsFalse true if the value is either 0 or 'false'
if=valueIsPositive true if the value is a number greater than zero.
if=valueIsNegative true if the value is a number less than zero.
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.