# Pingpong

This page describes how margin trading on Bitmex works with the PingPong strategy. The triggers for trades are slightly different than in the same strategy for regular trading.

## How to work with this strategy <a href="#how-to-work-with-this-strategy" id="how-to-work-with-this-strategy"></a>

**Expected behavior for margin trading**

Gunbot will open one position, either long or short, and close this position when the target is reached. When the stop is hit before profitably closing a trade, Gunbot will place a stop order at loss. After closing a position, Gunbot will again look to open a new long or short position. Gunbot will not add to existing open positions.

Please don't manually add to or reduce positions opened by Gunbot, unless you stop running Gunbot on this trading pair until you've closed this position.

​

The examples below show how the basic triggers for `pp` work. Additionally, you can use confirming indicators and settings like ROE trailing.

### Long (regular: trend following) <a href="#long-regular-trend-following" id="long-regular-trend-following"></a>

![](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-L_Rejuz9K0BDQxSQvUH%2F-LnNyPyp9OHJRHoGx8_P%2F-LnNyQpO1IOjN80xPuxA%2Fimage.png?alt=media\&token=ac9d5ad4-a473-4073-badb-b5c880d2267c)

* A long position is opened when the ask price is equal to or above `PP_BUY`.
* Position is closed when the desired `ROE` (return on equity) is reached. This is a percentage from the entry point, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `ROE`: 1.
* A position is closed at loss when `STOP_BUY` is reached. This is a percentage from the entry point in the opposite direction of your profit target, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `STOP_BUY`: 1.

### Short (regular: trend following) <a href="#short-regular-trend-following" id="short-regular-trend-following"></a>

![](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-L_Rejuz9K0BDQxSQvUH%2F-LnO--kQdJlOMatC1lGT%2F-LnO-0pnbVYMltSBxw72%2Fimage.png?alt=media\&token=41cf5e37-2a7c-4e9f-82a4-abd2f8a5aeb7)

* A short position is opened when the bid price is equal to or below `PP_SELL`.
* Position is closed when the desired `ROE` (return on equity) is reached. This is a percentage from the entry point, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `ROE`: 1.
* A position is closed at loss when `STOP_SELL` is reached. This is a percentage from the entry point in the opposite direction of your profit target, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `STOP_SELL`: 1.

### Long (mean reversion mode) <a href="#long-mean-reversion-mode" id="long-mean-reversion-mode"></a>

In `MEAN_REVERSION` mode the behavior for `PP_BUY` and `PP_SELL` is reversed in this strategy.

![](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-L_Rejuz9K0BDQxSQvUH%2F-LnO-HWWIKL0twLFBKed%2F-LnO-IlvM1KMZHm5to2v%2Fimage.png?alt=media\&token=fad819d5-7b8d-4f89-b9fb-adba10bcc519)

* A long position is opened when the ask price is equal to or below `PP_BUY`.
* Position is closed when the desired `ROE` (return on equity) is reached. This is a percentage from the entry point, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `ROE`: 1.
* A position is closed at loss when `STOP_BUY` is reached. This is a percentage from the entry point in the opposite direction of your profit target, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `STOP_BUY`: 1.

### Short (mean reversion mode) <a href="#short-mean-reversion-mode" id="short-mean-reversion-mode"></a>

In `MEAN_REVERSION` mode the behavior for `PP_BUY` and `PP_SELL` is reversed in this strategy.

![](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-L_Rejuz9K0BDQxSQvUH%2F-LnO-aCu3g4MUu1i2PiH%2F-LnO-beIKPIykywg3mvZ%2Fimage.png?alt=media\&token=727bc821-335c-467c-aff1-1796dec03d75)

* A short position is opened when the bid price is equal to or above `PP_SELL`.
* Position is closed when the desired `ROE` (return on equity) is reached. This is a percentage from the entry point, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `ROE`: 1.
* A position is closed at loss when `STOP_SELL` is reached. This is a percentage from the entry point in the opposite direction of your profit target, not taking leverage into consideration. Regardless what leverage is used, 1% price difference from your entry equals `STOP_SELL`: 1.

## Strategy parameters <a href="#strategy-parameters" id="strategy-parameters"></a>

Following settings options are available for `pp` and can be set in the strategy configurator of the GUI or the strategies section of the config.js file.

These settings are global and apply to all pairs running this strategy. When you want a specific parameter to be different for one or more pairs, use an [override](https://github.com/GuntharDeNiro/BTCT/wiki/Gunbot-settings#overrides) at the pair level.

Using the `BUY_METHOD` and `SELL_METHOD` parameters you can combine different methods for buying and selling. This strategy page assumes both `BUY_METHOD` and `SELL_METHOD` are set to `pp`. Accepted values are all strategy names as listed [here](https://github.com/GuntharDeNiro/BTCT/wiki/About-Gunbot-strategies).

## Margin settings <a href="#margin-settings" id="margin-settings"></a>

Margin settings control settings like leverage and the target for ROE. These parameters are relevant when using `pp` as buy and/or sell method.

### ROE <a href="#roe" id="roe"></a>

This sets the target for closing a position.

ROE is the Return On Equity for a position, the percentage profit and loss on your invested margin. This value is calculated in a similar way to how Bitmex calculates it, it does include leverage and does not include fees.

**Examples:** Long position, 1x leverage. When price moves 1% above the average entry price, 1% ROE is reached.

Long position, 100x leverage (or cross leverage). When price moves 1% above the average entry price, 100% ROE is reached.

Short position, 20x leverage When price moves 1% below the average entry price, 20% ROE is reached.

**Values:** numerical – represent a percentage.

**Default value:** 1

Parameter name in `config.js`: `ROE`

### Leverage <a href="#leverage" id="leverage"></a>

Sets the leverage for opening any position. Setting 0 places the order with cross margin.

**Values:** numerical

**Default value:** 0

Parameter name in `config.js`: `LEVERAGE`

### Stop Buy <a href="#stop-buy" id="stop-buy"></a>

Places a market stop order for a long position, at the same time as the position is opened.

When set to 1 and a long order is opened at a price of 100, a stop market order will be placed at 99.

**Values:** numerical - represents a percentage.

**Default value:** 0

Parameter name in `config.js`: `STOP_BUY`

### Stop Sell <a href="#stop-sell" id="stop-sell"></a>

Places a market stop order for a short position, at the same time as the position is opened.

When set to 1 and a short order is opened at a price of 100, a stop market order will be placed at 101.

**Values:** numerical - represents a percentage.

**Default value:** 0

Parameter name in `config.js`: `STOP_SELL`

### ROE Trailing <a href="#roe-trailing" id="roe-trailing"></a>

Use this to enable tssl-style trailing for ROE.

**Values:** true or false

**Default value:** false

Parameter name in `config.js`: `ROE_TRAILING`

### ROE Limit <a href="#roe-limit" id="roe-limit"></a>

This sets the range for ROE trailing.

Setting a range of 5% at a ROE target of 1 would set an initial range between 0.95 and 1.05.

As long as ROE keeps increasing, the range moves along with ROE. As soon as ROE start decreasing, the lower range gets frozen. A close order is placed when ROE crosses the lower limit.

**Values:** numerical – represent a percentage of ROE.

**Default value:** 1

Parameter name in `config.js`: `ROE_LIMIT`

### Pre Order <a href="#pre-order" id="pre-order"></a>

When set to true, limit orders will placed at a configurable rate beyond the best bid/ask price to get ahead of the order book.

**Values:** true or false

**Default value:** false

Parameter name in `config.js`: `PRE_ORDER`

### Pre Order Gap <a href="#pre-order-gap" id="pre-order-gap"></a>

Sets the gap between the best bid/ask price in the orderbook and the rate at which a limit order gets placed. Long orders are placed at ask + gap. Short orders are placed at bid - gap.

It is possible to use negative values, this will increase the chance of receiving maker fees.

Example when set to 1 and a buy signal occurs at an ask price of 100: a limit order gets placed at a rate of 101. When set to -1 and a buy signal occurs at an ask price of 100: a limit order gets placed at a rate of 99.

Don't use a negative gap together with `STOP_BUY` and/or `STOP_SELL`, as these stops do not combine well with position that do not always fill. Instead use `STOP_LIMIT`.

**Values:** numerical - represents a percentage.

**Default value:** 0

Parameter name in `config.js`: `PRE_ORDER_GAP`

### Mean Reversion <a href="#mean-reversion" id="mean-reversion"></a>

When set to true, the strategy follows a mean reversion way of trading, instead of trend following.

Long and short levels are reversed in this mode, long level is placed below EMA, short level is placed above EMA.

**Values:** true or false

**Default value:** false

Parameter name in `config.js`: `MEAN_REVERSION`

## Buy settings <a href="#buy-settings" id="buy-settings"></a>

Buy settings are the primary trigger for opening long positions. These parameters control the execution of buy orders when using `gain` as buy method.

### Buy enabled <a href="#buy-enabled" id="buy-enabled"></a>

Set this to false to prevent Gunbot from placing buy orders.

**Values:** true or false

**Default value:** true

Parameter name in `config.js`: `BUY_ENABLED`

### PP Buy <a href="#pp-buy" id="pp-buy"></a>

This sets the exact target price for placing a buy order. A buy order will be placed as soon as this price is hit or an even better price is available.

For example: when trading a BTC-x pair with `PP_BUY` set to 0.00123456, a buy order will be placed in the first cycle where the ask price is 0.00123456 or lower.

**Values:** numerical – represents a price in base currency.

**Default value:** 0

Parameter name in `config.js`: `PP_BUY`

### NBA <a href="#nba" id="nba"></a>

"Never Buy Above". Use this to only allow buy orders below the last sell rate.

This sets the minimum percentage difference between the last sell order and the next buy. The default setting of 0 disables this option.

When set to 1, Gunbot will only place a buy order when the strategy buy criteria meet and price is at least 1% below the last sell price.

**Values:** numerical, represents a percentage.

**Default value:** 0

Parameter name in `config.js`: `NBA`

## Sell settings <a href="#sell-settings" id="sell-settings"></a>

Sell settings are the primary trigger for opening short positions. These parameters control the execution of sell orders when using `gain` as sell method.

### Sell enabled <a href="#sell-enabled" id="sell-enabled"></a>

Set this to false to prevent Gunbot from placing sell orders.

**Values:** true or false

**Default value:** true

Parameter name in `config.js`: `SELL_ENABLED`

### PP Sell <a href="#pp-sell" id="pp-sell"></a>

This sets the exact target price for placing a sell order. A sell order will be placed as soon as this price is hit or an even better price is available.

For example: when trading a BTC-x pair with `PP_SELL` set to 0.00123456, a buy order will be placed in the first cycle where the bid price is 0.00123456 or lower.

**Values:** numerical – represents a price in base currency.

**Default value:** 0

Parameter name in `config.js`: `PP_SELL`

## Indicator settings <a href="#indicator-settings" id="indicator-settings"></a>

As `pp` is purely price based, there are no indicators that directly influence trading with `pp`.

## Balance settings <a href="#balance-settings" id="balance-settings"></a>

## **Confirming indicators + advanced indicator settings** <a href="#confirming-indicators-advanced-indicator-settings" id="confirming-indicators-advanced-indicator-settings"></a>

## **Misc settings** <a href="#misc-settings" id="misc-settings"></a>

## Dollar cost avg settings <a href="#dollar-cost-avg-settings" id="dollar-cost-avg-settings"></a>

DCA is not intented to be used for margin trading.

## Reversal trading settings <a href="#reversal-trading-settings" id="reversal-trading-settings"></a>

RT is not intented to be used for margin trading.

## TrailMe settings <a href="#trailme-settings" id="trailme-settings"></a>

With margin trading, additional trailing only works when MEAN\_REVERSION is enabled.

Parameters to configure additional trailing for various types of orders. Trailing works just like it does for the TSSL strategy, the difference being the starting point of trailing.

Orders resulting from trailing are only placed when the main strategy criteria are met, and confirming indicators (if any) allow the order. All these conditions must occur in the same cycle.

## Placeholders <a href="#placeholders" id="placeholders"></a>

The following parameters in `config.js` have no function for this strategy and act as placeholder.
