chrisleekr / binance-trading-bot

Automated Binance trading bot - Trade multiple cryptocurrencies. Buy low/sell high with Grid Trading. Integrated with TradingView technical analysis

Home Page:https://binance-trading-bot-chrisleekr.cloud.okteto.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non linear stop price and chase function

Maxoos opened this issue · comments

Is your proposal related to a problem?

I believe there's a way to secure a profit much sooner after buying a coin while still chasing the profit.

Let's assume the following trade:

Buy price: $100
Current price: $103

Ideally, you'd want to place stop order that is buy_price+fee and have the bot chase the order up as the price goes higher. This would mean placing a trigger percentage of say 1.01 and stop price of 0.9811. This would give us a secure sell order of $101.0533.

However, there's a problem. As the stop price is always a percentage of the current price the profit margin is limited by this percentage. It does not matter how much profit you've made, it's always going to take 0.9811 of the current price.

What we really want, is a none linear way to set the stop price.

Describe the solution you'd like

Here is my proposed solution.

image

Blue line: current solution
Red line: proposed solution

With the proposed solution we can set the stop price (and therefor the cancel price) in a none linear way so that when the profit is small the stop order will be closer to the buy price, but when the profit is large the stop price is closer to the current price.

For example from the chart, when current price is $120, 0.99% stop price is $117.6. With the proposed solution stop price will be $110.5 giving us more room to cancel the order and improve sell position. When current price is say $180, stop price will be the same as the current solution giving us more profit.

Solution

# market 
const buyPrice = 100
const currentPrice = 105

# params
const gamma = 1.5 // this param will control the curve of the function. i.e. lower will produce a more linear result.
const stopPricePercentage = 0.99 // same as today

const profit = (currentPrice - buyPrice)/buyPrice
const stopPrice = currentPrice * stopPricePercentage // same as today (I believe)

const gammaFactor = gamma ^ profit

const calculatedStopPrice = Math.min((stopPrice*gammaFactor)+buyPrice, stopPrice)

calculatedStopPrice // new none linear stop price

The gamma factor controls the curve. Here's an example with a lower gamma factor of 1.3:
image

and here's an example of a higher gamma of 2.0:
image

Because we use Math.min, if the curve goes over the stopLimitPercentage it will cancel out and just use the normal percentage, here's an example with stopLimitPercentage of 0.7 and gamma 2.0:

image

The same can apply to the limit price, it will just create a new curve for that.

Let me know what you think.

Interesting.

I will put this feature in the TODO list. I will try to implement this strategy later.

At this point, I am focusing on stabilising the grid trade feature, which required massive refactoring.