Giter Site home page Giter Site logo

Comments (10)

xmatthias avatar xmatthias commented on August 14, 2024 1

You will also need to be rather carefull with this - this indicator is using the FULL timerange you're passing in - so in backtesting, it's looking at the whole range and has therefore a lookahead bias (it'll know at all times what the last point in the series was).

You'll need to use it carefully - and apply it in a loop of "smallish" steps to get this right ...

from technical.

xmatthias avatar xmatthias commented on August 14, 2024

i'm ... not quite sure what you are using (and how).
Are you able to share a bit more of the implementation you're using? maybe this will allow us to help you better.

from technical.

valex91 avatar valex91 commented on August 14, 2024

I'm attempting to use:

def gentrends(dataframe, field='close', window=1 / 3.0, charts=False):

and

def fibonacci_retracements(df, field='close') -> DataFrame:

for the trendline indicator I'm attempting to use it in the following manner:

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=9)
        dataframe_long = resample_to_interval(dataframe, 30)

        # Bollinger Bands
        bollinger3std = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3)
        dataframe['bb3std_lowerband'] = bollinger3std['lower']
        dataframe['bb3std_middleband'] = bollinger3std['mid']
        dataframe['bb3std_upperband'] = bollinger3std['upper']

        # trendline
        trend = segtrends(dataframe_long, field='close')
        dataframe_long['trend'] = trend
        # Combine the 2 dataframes
        dataframe = resampled_merge(dataframe, dataframe_long, fill_na=True)

        return dataframe

and to populate the buy indicator:

 def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame:
        dataframe.loc[
            (
                    self.good_deal_buy_signal(dataframe) & (
                    dataframe['close'] > dataframe['resample_30_trend']['Min Line'])), 'buy'] = 1

        return dataframe

but also tried to populate the indicator in the following manner as a dataframe is returned:


  trend = segtrends(dataframe_long, field='close')
        result = dataframe.merge(trend, how='cross')
        
        return result

but then the script seems to hang, I suspect because the merge is quite heavy on performance.

from technical.

xmatthias avatar xmatthias commented on August 14, 2024

a merge is (usually) not heavy on performance - unless you use rather complex conditions.

I've never seen a cross merge though, and i'm not sure that'll work for timeseries.

that result can be rather big (with probably limited benefits, considering that it will combine every row with every other row - i also think that this will lead to a lookahead bias, considering how cross merges work (and you can't really use it anyway as it'll multiply your rows).

What's good_deal_buy_signal() do? it must return a boolean series (of the correct length!), otherwise this will fail.

from technical.

valex91 avatar valex91 commented on August 14, 2024

this is the good_deal_buy function:

    def good_deal_buy_signal(self, dataframe):
        return dataframe['close'] < dataframe['bb3std_lowerband']

but that alone is working as it should, the fact that I'm trying to figure out is for those indicator that return a dataframe of their own how do you pick the relevant row which hold the information to the row that I'm looking into.

In pseudo code what I'm trying to do is
trend_lines = segtrends(dataframe_long, field='close') dataframe['support'] = trend_lines['Min Line'] dataframe['resistence'] = trend_lines['Max Line']

to then use that information as a guard in the buy signal as
dataframe['close'] > dataframe['support']

from technical.

xmatthias avatar xmatthias commented on August 14, 2024

well - this is not pseudo code, but code how you should actually use it 😆

from technical.

valex91 avatar valex91 commented on August 14, 2024

with that code the result of print(dataframe.tail()) is:

image

with the following populate_indicators function

   def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=9)
        dataframe_long = resample_to_interval(dataframe, 30)

        # Bollinger Bands
        bollinger3std = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3)
        dataframe['bb3std_lowerband'] = bollinger3std['lower']
        dataframe['bb3std_middleband'] = bollinger3std['mid']
        dataframe['bb3std_upperband'] = bollinger3std['upper']

        trend_lines = segtrends(dataframe_long, field='close')
        dataframe_long['support'] = trend_lines['Min Line']
        dataframe_long['resistence'] = trend_lines['Max Line']

        dataframe = resampled_merge(dataframe, dataframe_long, fill_na=True)

        return dataframe

from technical.

xmatthias avatar xmatthias commented on August 14, 2024

i never used trendlines / seglines - maybe it's not supposed to "always" give you value?

try it in a "simple" setup, maybe? without resampling, directly plotting the "dataframe_long" dataframe.

from technical.

ronmegini avatar ronmegini commented on August 14, 2024

with that code the result of print(dataframe.tail()) is:

image

with the following populate_indicators function

   def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=9)
        dataframe_long = resample_to_interval(dataframe, 30)

        # Bollinger Bands
        bollinger3std = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3)
        dataframe['bb3std_lowerband'] = bollinger3std['lower']
        dataframe['bb3std_middleband'] = bollinger3std['mid']
        dataframe['bb3std_upperband'] = bollinger3std['upper']

        trend_lines = segtrends(dataframe_long, field='close')
        dataframe_long['support'] = trend_lines['Min Line']
        dataframe_long['resistence'] = trend_lines['Max Line']

        dataframe = resampled_merge(dataframe, dataframe_long, fill_na=True)

        return dataframe

Hey, how are you print the indicators dataframe table?

from technical.

xmatthias avatar xmatthias commented on August 14, 2024

well - print(dataframe.tail()) (as specified above).

I'll now also close this issue as i think the topic has been resolved.

from technical.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.