Automated trading extension package.

This package contains these new strategies: Spread and EMA, a new parameter for all

strategies allowing the realization of the idea of creating a customized filter

based on price comparison and parameters enhancing the MoonShot strategy.

This extension package can be activated in addition to the main product, using credits.

To open the credits menu, click on **PRO Version** in the bottom right corner or click on "MoonCredits" in the Settings menu (PRO tab) (available only if you own credits). Without activation, the functions of this package are only available in emulation mode, that can be enabled in MoonBot.

**Spread strategy**

The spread consists of active trades within a frame determined by time and price fluctuation.

**Examples of using the Spread strategy during the listing of DODO coin.**

Strategy parameters:

**TimeInterval:** The width of the time zone in seconds used for calculations.

**TradesDensity:** The density of trades, in time, expressed in percent. For calculations, the interval is divided into bits of 200ms and the ratio of bits containing at least 2 trades at different price levels to bits without trades is calculated. i.e. a 100% density means that trades with different price levels have happened every 200ms.

**TradesDensityPrev:** The trade density prior to the detect. Helps determine coins that are flat. For pumps, this parameter should be set to 0 ! (as we are specifically looking for flat coins).

**TradesCountMin: **Every 200ms, within the entire detect interval, there are at least this many trades. Default value = 0. This parameter will strongly constrict detects, it will allow for only high trade density.

**PriceIntervals:** Number of equal intervals TimeInterval should be divided into to determine the fluctuation of the price. The total interval will be divided into a number of PriceIntervals, for every slice, the max, min and their delta (difference) is calculated.

**PriceSpread:** Spread (in percent) used for the detect. The detect will occur if for every slice of the parameter described above, if the price fluctuation was higher than the PriceSpread.

**IntervalsForBuySpread:** How many of the last slices of PriceIntervals are to be used for calculating the min and max prices within the spread. If 0, the entire TimeInterval is used.

**BuyPriceInSpread:** at how many percent within the spread should the buy order be placed. If long – this percentage is calculated upwards of the min price; if short – downward of the max price. Example: 0% long will place an order on the min price within the spread; 50% will place the order in the middle; -100% short will place the order at two times the spread distance.

**Attention!** The BuyPrice parameter from the general BuyOrder section will also affect the buying price. BuyPriceInSpread in this case will determine the “base price” used to calculate the BuyPrice.

**SellPriceInSpread:** Similar to BuyPriceInSpread, a predetermined sell price based on the spread. Unlike BuyPriceInSpread, the sell price **is made up of the maximum SellPrice and the spread sell price.** i.e. if the SellPrice is lower than the spread (for example SellPrice=0) – the sell order will be placed within the spread. If higher – the sell is placed according to the SellPrice. (modifiers also affect the sell price).

**BuyOrderReduce:** sets the interval (in ms) used to calculate the average trade volume. The strategy will place an order of size not larger than the average volume. By default = 100ms. Volume calculation: sum of all trades (buy and sell) over the TimeInterval interval, divided by BuyOrderReduce. Examlple: if TimeInterval = 5 sec (5000 ms), BuyOrderReduce = 100ms, the volume over 5 sec was 10 000$, the average volume over 100ms will equal 10000/5000ms*100ms=200$. In this case the strategy will place an order not larger than 200$.

**Alternatively, knowing the average volume over 100 / 10/ 5 ms, this will be the maximum order size of the strategy**

BuyOrderReduce=0 – parameter is turned offThe work of the order reduction function can be seen in the following inscription:IOTA: [1] (40) Buy order reduced: 1000.00$ => 23.32$ (Vol: 23.32$)In this log, the OrderSize in the strategy was 1000$, but the average volume over 100ms was just 23$, thus, the strategy has placed an order of 23$.

**SpreadRepeatIfProfit: **The repeated placement of buy orders during 1 sec after the detect (not later). The repeated order is placed if the current price has approached the sell price by more than the SpreadRepeatIfProfit percent. If 0, repeated orders are not placed. If 100, is placed only after selling the sell order (not more than 5 repeated orders, based on internal limitations).

**SpreadFlat:** if YES, the bot will try to determine the spread in a horizontal channel.

**Spread_BV_SV_Time: **time in terval (in milliseconds) for analysis. If 0 — parameter is ignored

**Spread_BV_SV_Max:** buys to sells ratio not greater than this value. If 0 — parameter is ignored

**Spread_BV_SV_Min:** buys to sells ratio not smaller than this value.

If the strategy contains a short, the relationship is inversed automatically! (i.e. the short calculates the ratio of sells to buys).

Example: Spread_BV_SV_Time = 1500 (1.5 seconds)

Over the last 1.5 seconds, 500$ worth of buy trades and 1000$ worth of sell trades were recorded. The ratio bv/sv will equal 500/1000 = 0.5 for longs and 1000/500 = 2 for shorts

Example

TimeInterval =5 sec.

TradesDensity=100

PriceIntervals = 5

PriceSpread = 0.3%

IntervalsForBuySpread=2

BuyPriceInSpread=5

SellPriceInSpread=100

BuyOrderReduce = 100

This means that over the last 5 seconds, every second a price variation of 0.3% (or higher) was recorded. To calculate the buy and sell orders we use the last 2 intervals (IntervalsForBuySpread=2), we set the buy order at +5% from the minimum value, and the sell order at max(100%). Yet if volume over 100ms is smaller than the OrderSize strategy, an order equal to the volume will be placed.

**Attention! The Spread strategy implies a very high level of risk. Use it without auto-buying, as a detect, to understand the way it works. Once you have a good grip on how it works, use it for real trading.**

**Note: **

- It is VERY important to use Latency filters in the strategy, because the value of prices used for the detecting the spread are taken from the trades (ticks on the chart). If the prices will arrive with a delay, the detect might work when the price is no longer available!
- When a buy order is partially filled the strategy will remove it and the entire executed volume is sold, similar to MoonShots.
- The detect conditions calculations are made once every ½ second.
- The strategy takes into account the detect modifiers (the modifiers affect the PriceSpread).
- It is recommended to use this strategy with the EMA filter, short (for example EMA(30,2) to determine the increase or decrease and placing a high sell on a short or long (setting up EMA is described further).
- Reading the detect parameters from the chart: Settings – Special, check the box Extended Debug.
- If you have several "Spread" strategies running, the detect and order will work for each of them (unlike other types of strategies where the detect works works for the first one on the list).

Definitions:

**TD:** trade densityd

**P:** price fluctuation on the entire interval TimeInterval

**Vol:** volume

**Spread:** actual spread, percent

**N:** number of slices showing the spread (the last two appear on the chart only at detect time)

These values can also be found in the detect report:

EMA filter and strategy

The new CustomEMA parameter in the strategy allows the creation of a custom filter based on price comparison.

The parameter takes a string of functions for comparison as shown here:

EMA(X,Y) > A AND EMA(p,q) < B AND …. any number of formulae separated by the words "AND" or "OR" (with algebraic order: first AND, then OR. **Example: **A AND B OR C AND D means that either (A AND B) or (C AND D))

Formulae:

**EMA(X,Y) >** or **< A:** compares the prices for EMA X seconds, minutes or hours ago and EMA Y seconds, minutes or hours ago

**MAX(X,Y) >** or **< A:** Compares the maximum price for X minutes or hours ago and EMA Y seconds ago

**MIN(X,Y) >** or **< A: **Compare the minimum price X minutes or hours ago and EMA Y seconds ago

**BTC(X, Y) >** or **< A:** Compares the BTC/USDT prices for EMA X seconds, minutes or hours ago and EMA Y seconds, minutes or hours ago

Every formula EMA(X, Y) > or < A means:

1) X,Y – time: date followed by the letters s, m or h (seconds, minutes, hours) or no letters (the date is then calculated in seconds)

2) the greater than or less than sign (<,>)

3) A – what to compare with (in percent )

Calculation principle: average price Y seconds ago compared to the average price X seconds ago:

Price(Y) / Price(X) > 1 + A / 100

Alternatively, Price(Y) greater than Price(X) by A percent (or less, if the formula contains the < symbol)

Calculation methods and limitations:

Because it is impossible to keep all possible combinations in memory, the bot calculates the prices as follows:

- A set of per second averages from the current price(1 sec) to 300 sec. age. Calculated as the classic EMA (Pnext = (Pprev * N + Pcurr) ./ (N + 1)
- Minute averages from 2 to 90 minutes ago. Calculated simply as the average price per minute
- Hourly averages from 1 to 42 hours ago (exchange limitations exist) (is calculated as the average price of the 5м candles) Thus, the X,Y parameters in the EMA formula may be: 1..300 or 2m..90m or 1h..42h
- If Y is 1s the comparison will be made with the current price

These prices can be displayed on the chart using the control panel as shown bellow ,

**ATTENTION! This is not an indicator,** rather just a demonstration of how the new EMA filter is calculated. For reasons, presented above, the blue price line may have ruptures – these are the places where 300s end and the 2m starts and the 90m ends.

The CustomEMA filter will work when all conditions from the formula are met. Thus, various entry conditions can be set, specifically trailing buy: the price decrease over a long period with the later increase for a short period etc.

**Examples of values in the CustomEMA field:**

**1) EMA(15m,3)< -1 and EMA(5,1) > 0.1**

EMA(15m,3)< -1 = means that there was a decrease: the price 3 seconds ago -1% less than the price 15 minutes ago.

EMA(5,1) > 0.1 = means the price increased: the current price is 0.1% higher than it was 5 seconds ago.

Together, these conditions mean that the detect will take place after a fall that is followed by an increase.

**2) Max(1h, 1s) > 0.1** = denotes an over-high: the current price has gone higher than the max of the last hour

**3) Max(1h, 1s) < -5** = denotes a 5% fall from the high of the last hour

**4) Max(1h, 1s) < -5 AND Min(1h, 1s) < 0.1 AND Min(1h, 1s) > -0.1** = denotes a 5% fall from the high and are currently located near the bottom

For ease of testing, a new EMA strategy is added, that doesn’t contain parameters, it is built exclusively for detecting the conditions of CustomEMA filter. Thus, the detect will take place the moment when the filter conditions are met, so use it with caution! Unlimited buys are possible, set a NextDetect penalty.

**Note:**

- It is important to use Latency filters in the strategy because the EMA prices depend on the trade prices, if the trades arrive with a delay the EMA calculations will be erroneous.
- The EMA lines are saved in the reports at the moment of the detect. For moonshots – at the moment the buy orders are executed (if the strategy had the EMA filter enabled).

Additional parameters for the MoonShot strategy

In addition to the basic parameters, a few new ones are added that will broaden the MoonShot algorithm possibilities. Now the strategy can repeatedly place a shot on the same coin before the sell of the previous sell order:

**MShotRepeatAfterBuy:** Place a repeated MoonShot after buying and placing the sell

**MShotRepeatIfProfit: **%, a condition for the current price for the repeated shot: the price should be higher than the buy price by this value

**MShotRepeatWait: **time in seconds, during which the repeated shot may be placed if the condition of MshotRepeatIfProfit is met

**MShotRepeatDelay:** await time in seconds, before placing a repeated shot

The repeated shot is only placed if the current price is higher than the price of MShotRepeatIfProfit percent value during MShotRepeatWait seconds.

The default value of MShotRepeatIfProfit = 0, MShotRepeatWait = 5 mean:

"Place a repeated shot if the current price went higher than the buy price within 5 seconds from the buy"