hippocritical / strategies

34 stars 12 forks source link

Issue in Stake calculation #3

Open Mandark-droid opened 1 year ago

Mandark-droid commented 1 year ago

Hi,

I have had few trades where the Stake amount being used is more than what is being sent via Telegram notification. Here are few samples.

================== kt_ft_smaoffset_ku, [29-06-2023 20:15] πŸ”΅ Kucoin: Long ARX/USDT (#13) Amount: 505.44015335 Open Rate: 0.00268800 Current Rate: 0.00268800 Total: (1.359 USDT, 1.36 USD)

kt_ft_smaoffset_ku, [29-06-2023 20:15] πŸ”΅ Kucoin: Long ARX/USDT (#13) Amount: 505.44010000 Open Rate: 0.00231700 Current Rate: 0.00231700 Total: (1.359 USDT, 1.36 USD)

kt_ft_smaoffset_ku, [29-06-2023 20:16] πŸ”΅ Kucoin: Long ARX/USDT (#13) Amount: 1091.81180000 Open Rate: 0.00226000 Current Rate: 0.00226000 Total: (2.717 USDT, 2.72 USD)

kt_ft_smaoffset_ku, [29-06-2023 20:17] πŸ”΅ Kucoin: Long ARX/USDT (#13) Amount: 3255.99020000 Open Rate: 0.00198400 Current Rate: 0.00198400 Total: (7.58 USDT, 7.588 USD)

For Above trade if you sum up the Total Stake from the Telegram notifications then its 13.028 but actual on Exchange and in FT UI the stake amount used was much higher than this. image

Similarly I have had one more such trade which has blocked majority of my stake due to these miscalculations. Am running multiple Strategies on the same host using same FT version and config but not seeing such miscalculations for any of the other Strategies.

image

kt_ft_smaoffset_ku, [03-06-2023 21:50] πŸ”΅ Kucoin: Long ACOIN/USDT (#37) Amount: 72.10795578 Open Rate: 0.05981100 Current Rate: 0.05981100 Total: (4.313 USDT, 4.307 USD)

kt_ft_smaoffset_ku, [03-06-2023 21:52] πŸ”΅ Kucoin: Long ACOIN/USDT (#37) Amount: 72.10790000 Open Rate: 0.05503300 Current Rate: 0.05503300 Total: (4.313 USDT, 4.307 USD)

kt_ft_smaoffset_ku, [03-06-2023 22:00] πŸ”΅ Kucoin: Long ACOIN/USDT (#37) Amount: 150.47630000 Open Rate: 0.05397900 Current Rate: 0.05397900 Total: (8.626 USDT, 8.615 USD)

kt_ft_smaoffset_ku, [03-06-2023 22:01] πŸ”΅ Kucoin: Long ACOIN/USDT (#37) Amount: 438.11120000 Open Rate: 0.04694900 Current Rate: 0.04694900 Total: (24.14 USDT, 24.11 USD)

hippocritical commented 1 year ago

you bought 5x this should never have happened, did you change anything in the code?

hippocritical commented 1 year ago

hippocritical commented 1 year ago

the buys above of 4 4 8 24 would only make sense if ...

you posted incomplete trades (trade 4 is missing, you posted trades 1 2 3 5)

and trade 4 only partially filled or freqtrade just bought whatever you had left in the wallet at trade 5 (depends on your configuration and wallet size)

hippocritical commented 1 year ago

are you SURE you use the current version?

The old one might have an error like that

Currently the version on github states the following:

max_so_multiplier_orig = 3
if 1 <= count_of_buys <= self.max_so_multiplier_orig:

This means that the strategy is allowed to buy when it already bought 3x (to get to an overall depth of 4 buys, meaning 1 base order and 3 safety orders).

Please double check if your version is the current one and not something outdated.

batcandoi27 commented 1 year ago

As once mentioned in discord you and here https://github.com/stash86/freqtrade_stuff/issues/2 your code and freqtrade's sample may fail when using ft lev 5x max open trade = 4 ( if 1 then not). This error is not detected in the backtest, when the trade adjustments run only per candle, if run dry/live, the adjustment many times in one candle can occur buying at the 1st dca = vol x 5 (equivalent to 1st dca). equivalent to lev 5x), I guess the code that causes the error when processing in one candle is at actual_initial_stake = filled_buys[0].cost. I solved by disallowing buy and dca in the same candle, and save the first buy stake_amount in another variable or replace it with actual_initial_stake = self.wallets.get_total_stake_amount() / (self.config['max_open_trades'] * self.max_so_multiplier , and no more running out of stakes for a pair !Maybe I'm wrong, but the dry result works like backtest !

cyberjunky commented 1 year ago

@batcandoi27 Hi I'm running into this as well, can you share the code change/snippets please?

hippocritical commented 1 year ago

ah you mean leverage, never tried or tested it for that It seems weird to me, if it bought 2x in the same candle (which mine did several times already too but in spot and without leverage) that it then doesnt register the base order, this goes against any logic and can't be fixed with the strategy itself, but has to be fixed within freqtrade.

My suggestion would be to make a reproducible strategy (which you have) and post that on the freqtrade discord.

From a logic perspective it should not matter how fast it bought for the n'th time and still register the orders count properly. All this strategy does is to call on the variable trades and read how many oders there have been within that trade. https://github.com/hippocritical/strategies/blob/cbc1f24a2a77c235d7a55e1b6e7b95181aa644e5/SMAOffset_Hippocritical_dca/SMAOffset_Hippocritical_dca.py#L149

batcandoi27 commented 1 year ago

@batcandoi27 Hi I'm running into this as well, can you share the code change/snippets please?

Send you the code I edited to not buy and dca the same candle, and prevent buying all the balance in one time, I'm not a coding professional, so the code is not professional, it may be wrong to run. Therefore, you need to check carefully before using.

batcandoi27 commented 1 year ago

@batcandoi27 Hi I'm running into this as well, can you share the code change/snippets please?

''' stake_amount = filled_entries[0].stake_amount''' Problem was fixed by this code in freqtrade new version 2023.7 ! Link https://www.freqtrade.io/en/stable/strategy-callbacks/#adjust-trade-position