freqtrade / freqtrade

Free, open source crypto trading bot
https://www.freqtrade.io
GNU General Public License v3.0
28.12k stars 6.03k forks source link

Dry run trades not following my buy triggers #3077

Closed Jaydyn99 closed 4 years ago

Jaydyn99 commented 4 years ago

Step 1: Have you search for this issue before posting it?

Yes

Step 2: Describe your environment

Step 3: Describe the problem:

My libs are

from freqtrade.strategy.interface import IStrategy
from typing import Dict, List
from functools import reduce
from pandas import DataFrame
# --------------------------------

import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
import numpy

My populate indicators is

stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

My populate buy trend is

(dataframe['fastk'] > dataframe['fastd']) &
                (dataframe['fastk'] > 20)&
                (dataframe['fastk'] < 50)&
                (dataframe['rsi'] > 30) &
                (dataframe['rsi'] < 50)

When i compare the trades it makes on dry run, only about 1 out of 10 follow these parameters. Making seemingly random trades. The only rule it always adheres to is rsi parameters.. >30&<50. Most trades are entered well below <20 fastk...

I have run

def helper(df):
        df_buy = df[df['buy'] == 1]
        for index, row in df_buy.iterrows():
            if ~((row['fastk'] > row['fastd']) &
                (row['fastk'] > 20) &
                (row['fastk'] < 50) &
                (row['rsi'] > 30) &
                (row['rsi'] < 50)):
                print('Wrong!!')
                break

            df_buy = df[df['buy'] == 1]

and getting no 'Wrong!!' message.

I have a trading background with very minimal coding experience. Forgive me if I'm missing something very simple here. Are the values in the libraries possibly not lining up the values I'm looking at in trading view charts? Am I using the wrong libraries somehow?

Thanks

  // paste your log here
xmatthias commented 4 years ago

Your best bet is to plot the data (freqtrade plot-dataframe --indicators2 fastk fastd <...> ) with the indicators and compare the values to tradingview.

Ta-lib is known to "sometimes" differ from tradingview. It's not always the fault of ta-lib, as tradingview does not implement all indicators according to the original specs either.

Now i'm not certain about stochF as i don't use that personally - but it's very well possible that different default-parameters are used (best specify these manually / explicitly)- or that the startup of the indicator is calculated differently, leading to slightly different results.

StochRSI for example is known to differ (wildly) between tradingview and ta-lib, maybe something similar happens with stochf.

For most indicators, there's other libraries (finta, bta-lib, ...) which provide a similar implementation - however unfortunately, for these the same potential problem applies - noone can guarantee if all indicators of these libraries align 100% to tradingview or not.

This is unfortunately something we're suffering from,but don't really have a solution other than pointing to different libraries, or sometimes implement an indicator ourselfs.

The real problem is - tradingview is seen as "the standard" - but what if they got it wrong - should all other libraries change their (formally correct) implementations ... that's going to break other stuff, so will result in different problems.

Jaydyn99 commented 4 years ago

Would you happen to know how to change values of fastk and fastd? I have just noticed the TA-Lib is saying their values are 5 and 3.. whereas the default on my charting programs is 14 and 3... That might be my problem.

xmatthias commented 4 years ago

well - something around the below probably:

        stoch_fast = ta.STOCHF(dataframe, fastk_period=5, fastd_period=3, fastd_matype=0)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

source (search for STOCHF)

Jaydyn99 commented 4 years ago

Thank you for your help sir.. Turns out the problem was just the default being different to charting platforms.