enarjord / passivbot

Trading bot running on Bybit, Bitget, OKX, GateIO, Binance and Hyperliquid
https://www.passivbot.com
Other
1.12k stars 420 forks source link

Stop Loss function #4

Closed eugjr closed 3 years ago

eugjr commented 3 years ago

Hi, thanks for the bot. I'm trying it on binance. It is possible to implement a stop loss function, based on a % from the actual position price? I've made a simple bot using ccxt, and could be able to implement the stop loss on it, but the code for the passivbot is way more sophisticaed, I cannot edit it properly.

enarjord commented 3 years ago

hi there

thanks for your suggestion

yes, it is possible to implement a stop loss

as the bot is now, it will keep reentering and doubling the position as long as there are funds for it

as an example of a possible stop loss, instead of doubling down the last time, it could take a market exit at a loss

this bot is high risk high gain

i'm uncertain whether a stop loss makes sense with it

it would have to be backtested to find out whether or not it is worthwhile

in the last couple of days, the bot has had trouble keeping up with the extremes of the markets

dangerous waters for this bot

please use caution if you use it!

eugjr commented 3 years ago

Thanks for the reply, and for the reminder about the extreme volatility of the market. The market exit at a loss option would require a heavy code change?

I'm trying it now with ETHUSDT and BTCUSDT on different accounts, tweaking and trying some changes on settings file.

The EMA settings ([38935, 99848], by default), are the number of the last trades, fetched real time, from the exchange?

enarjord commented 3 years ago

at startup the bot fetches max(ema_spans) number of aggregated trades from binance, and updates its emas on each websocket tick thereafter

the market exit at a loss option wouldn't require that much code change no

for binance, it would be something like

if position_size * last_price / leverage > total_equity / 2: create_market_order(qty=position_size)

but i would not recommend this as of now, at least not without some simulations of performance

i suspect this kind of stop loss would lose you more than it would save you

while high number of double downs is where it is most dangerous, the bot also stands to make the most profit when it doubles down the most

i have seen it double down 9 times, even 10 times, liquidation very close

11 double downs with initial entry_qty of 0.001 is 0.001 * 2**11 == 2.048

another kind of stop loss would be to simply never put more funds in the usdt futures wallet than you are willing to lose. this is also risky tho, because the more funds it has, the more times it can double down and recover

enarjord commented 3 years ago

i'm working on a new version of the bot now, with more adjustable settings

instead of doubling down with 2x every time, it can reenter with less than pos_size, and spread out many, many more orders

it's under development i've put it on github under branch "grid_style"

eugjr commented 3 years ago

Thanks for your reply. I'll test the grid_style version too and create another topic of issue for it if I get any trouble

eugjr commented 3 years ago

Hello, I'm trying some modifications on settings file, and didn't get yet which variable sets the first grid position. I'm testing with 5 grid lines.

enarjord commented 3 years ago

i have made a major update to the grid_style branch of the bot

it now no longer uses emas at all

it includes a grid_spacing_coefficient, the which purpose is to increase grid spacing in proportion to pos_size. this serves as a kind of stop loss, by reentering at greater intervals when pos_size approaches equity pos_price leverage

please make use of the backtester to get a feel for how the bot works over time

eugjr commented 3 years ago

Thanks for the update. I've tryied to run on Binance and get the following error: AttributeError: 'BinanceBot' object has no attribute 'calc_entry_qty'

It was able to create the first order, but didn't created the grid ones. I"ve tweaked the settings file to work with Binance (BTCUSDT) and min position 0.001

enarjord commented 3 years ago

i haven't finished porting it to binance yet

only bybit as of now

enarjord commented 3 years ago

soft stop loss is implemented in branch dynamic_grid

if difference between last price and liq price is less than 2% (default), reduce position at a loss with 2% (default)