Automated Trading Examples

Closing any open position

Sometimes you need to close your position. You might be long, you might be short, you might actually not have an open position, but you need to be sure that any position you do have, whatever it's size, is closed.

What you are really says is "I'd like to change my current position size to Zero". By using the position=0 argument available in some order commands, the bot can calculate the desired size and direction of the trade for you.

The examples below assume you are trading on BitMEX on the XBTUSD pair. Change the symbol and use appropriate API keys for other exchanges.

Using market orders

Fast, simple, certain, but possibly costly in fees...
Works out the direction and size of the market order needed to change your position size to Zero, and execute a market order to do that.

myApiKeys(XBTUSD) {
    market(position=0);
}

Using limit orders

Cheaper, but not guaranteed to be filled, and the bot does not wait for the order to be filled. This will place the order close to the top of the order book ($1 from the top actually).

myApiKeys(XBTUSD) {
    limit(position=0, offset=1);
}

Using limit orders, but wait for it to fill

This uses a limit order like before, but constantly monitors it and moves it right to the top of the order book. It will keep doing this until it is 100% filled.

myApiKeys(XBTUSD) {
    aggressiveEntry(position=0);
}

Learn more about the commands used here...

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.