Automated Trading Stop or Take Profit Order

stopOrTakeProfit()

side, amount, tp, sl, tag

Places a Take Profit order and a Stop Loss order at the same time. It then waits for either order to be filled and cancels the other one.

Arguments
side required text, one of buy, sell. defaults to buy

Is this a buy or sell order.
Required if you don't use position.

amount required number, defaults to 0

The size of the order. The units depend on the symbol and exchange. Can be given as an absolute amount, percentage of your balance or percentage of your available balance.

Example Meaning (if on BitMEX XBTUSD)
amount=1000 Uses an amount of 1000 contracts
amount=50% Will calculate the amount as a percentage of your balance/equity. For example, if your balance is 1 BTC and the current price is $10,000, 50% of 1 btc is 0.5 btc. 0.5 btc is worth $5,000. At $1 per contract, the order will be for 5,000 contracts.
amount=50%% Similar to above, only will use 50% of your available balance/equity. Equity already locked up in positions and pending orders will not be considered.
amount=50%p Will work out 50% of your position size and use that as the amount. The p stands for Position Size
amount=50%b Same as 50% - the b stands for Balance
amount=50%a Same as 50%% - the a stands for Available Balance

Percentage amounts are supported on all exchanges. On BitMEX they are supported on most (but not all) symbols. XBTUSD is supported and all symbols against XBT (eg ETHXBT), but not on symbols backed against other currencies (eg ETHUSD, XBTJPY etc can not use % amounts and must use fixed amounts - this is because we need live price information for additional symbols to complete the calculation, which are not tracked to by default).

Required if you don't use position.

tp required number, defaults to 100

The offset to the Take Profit order. The Take Profit order will be a regular post only, reduce only limit order.

Example Meaning (assuming asset priced in USD)
tp=50 Take profit after a $50 move into profit.
tp=1% Take profit after a 1% price move into profit.
tp=@950 Take profit at the price of $950, regardless of our entry.
tp=e50 With an open position, offset will be relative to average entry. With no open position, offset will be relative to current price
tp=e1% With an open position, offset will be relative to average entry. With no open position, offset will be relative to current price
sl required number, defaults to 100

The offset to the Stop Loss order. The stop loss order with be a normal stop market order.

Example Meaning (assuming asset priced in USD)
sl=50 Stop loss order will trigger after a $50 move into loss.
sl=1% Stop loss order will trigger after a 1% price move into loss.
sl=@950 Stop loss order will be triggered at the price of $950, regardless of our entry.
sl=e50 With an open position, offset will be relative to average entry. With no open position, offset will be relative to current price
sl=e1% With an open position, offset will be relative to average entry. With no open position, offset will be relative to current price
tag optional boolean, one of true, false. defaults to false

Tags the order with the value given. This allows you can cancel the order using it's tag. See cancel() for more details.

Example: Buy 100 contracts, take profit $100 up and stop loss at $50 down

myApiKeys(XBTUSD) {
    aggressiveEntry(side=buy, amount=100);
    stopOrTakeProfit(side=sell, amount=100, tp=100, sl=50);
}

Buys 100 contracts of XBTUSD, then places both a Take Profit order and a Stop Loss order to close the position. This will keep going until one of the TP or SL orders has been filled. Which ever order was not used to automatically cancelled.

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.