Automated Trading Ping Pong Order

pingPong()

side, amount, from, to, orderCount, pongDistance, endless, pingAmount, pongAmount, varyAmount, varyPrice, easing, tag

This algorithmic order starts off identical to a scaled() order. It places a series of limit orders. However, once the orders are placed, the bot waits for them to be filled. As soon as one of the limit orders is filled, a new limit order is placed, pongDistance away from the original on the other side of the book.

The order completes when all the original ping orders have been filled and all the resulting pong orders have also been filled. However, if endless is true, then the pong orders will create new ping orders as they are filled and the whole process starts again.

When in endless mode the order will never complete. If you want to cancel it, you can either manually cancel all the open orders on the exchange, or call cancel(which=tagged, tag=tagname) using the tag you gave this. The tag defaults to pingpong for this order, but can be anything you like.

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.

from required number, defaults to 0

Used to define part of a price range from from to to. The price is calculated as an offset from the current live price.

For an asset quoted in USD (eg BTCUSD), offset can be given in the following ways:-

Example Meaning (assuming asset priced in USD)
from=50 offset $50 from the current price (below for buys, above for sells).
from=1% from is calculated as a percentage of the current price. If the price is $10,000, and from is 1%, then 1% of 10,000 is 100. An offset of $100 will be used.
from=@950 The @ at the start of the value indicates this should be treated as an absolute price of $950, regardless of what the current price is.
from=e50 With an open position, offset will be relative to average entry. With no open position, offset will be relative to current price
from=e1% With an open position, offset will be relative to average entry. With no open position, offset will be relative to current price
to required number, defaults to 100

Used to define part of a price range from from to to. The price is calculated as an offset from the current live price.

Possible values are the same as for from.

orderCount required number, defaults to 10

The number of limit orders to place between from and to.

Can be any whole number from 2 to 100.

Note: Most exchanges will limit how many open orders you can have at any time. If you attempt to exceed these limits, then some of your orders may fail to create.

pongDistance required number, defaults to 20

Once a ping pong order has been filled, a new order is placed pongDistance away on the other side of the book.

endless optional boolean, one of true, false. defaults to false

The Ping Pong order normally completes after the original ping order is filled and the following pong order is also filled. If endless is true, then the pong order will generate a new ping order and the process will continue forever.

pingAmount optional number, defaults to 0

The size of each of the individual ping orders. This will be used in preference to amount. The total amount needed is pingAmount * orderCount.

pongAmount optional number, defaults to 0

The size of each of the individual pong orders. This will be used in preference to amount. The total amount needed is pongAmount * orderCount.

varyAmount optional percentage, defaults to 0

How much, as a percentage, should the amount of individual orders be randomised by.

Can accept numbers, like 0.1, or percentages like 10%. Should be in the range 0 to 1 or 0% to 100%.

For example, with a total amount of 1000, and an orderCount of 10, each order will be for 100 units. With a 10% varyAmount, each order will be between 90 and 110 units.

Even if the amounts are randomised, the sum of the amounts will equal the total amount given in amount or calculated from position (within some rounding tolerance).

varyPrice optional percentage, defaults to 0

How much, as a percentage, should the price of individual orders be randomised by, where 0% means don't randomise the price at all, and 100% means anywhere between the previous and next order.

Can accept numbers, like 0.1, or percentages like 10%. Should be in the range 0 to 1 or 0% to 100%.

Even if price is randomised, all orders will still be between from and to.

easing optional number, one of linear, ease-in, ease-out, ease-in-out. defaults to linear

The easing method to use when spacing the orders out in the range between from and to.

Method What it does
easing=linear will place all the orders evenly spaced out between from and to.
easing=ease-in will bunch the orders up closer to from.
easing=ease-out will bunch up the orders closer to to.
easing=ease-in-out will bunch the orders up closer to from and to, away from the middle of the range.
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: Start a ping pong order with 1000 contracts.

myApiKeys(XBTUSD) {
  pingPong(side=buy, amount=1000, from=0, to=20, orderCount=40,  pongDistance=30, endless=false);

}

Place a scaled order to buy 1000 contracts, spread over 40 orders from the current price to $20 below the current price. As each oder fills, open a sell order $30 above it. Once all the buys and their child sells have completed, stop.

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.