Coder Social home page Coder Social logo

Comments (11)

xmatthias avatar xmatthias commented on May 4, 2024

def ichimoku(dataframe, conversion_line_period=9, base_line_periods=26,
laggin_span=52, displacement=26):
"""
Ichimoku cloud indicator
Note: Do not use chikou_span for backtesting.
It looks into the future, is not printed by most charting platforms.
It is only useful for visual analysis
:param dataframe: Dataframe containing OHLCV data
:param conversion_line_period: Conversion line Period (defaults to 9)
:param base_line_periods: Base line Periods (defaults to 26)
:param laggin_span: Lagging span period
:param displacement: Displacement (shift) - defaults to 26
:return: Dict containing the following keys:
tenkan_sen, kijun_sen, senkou_span_a, senkou_span_b, leading_senkou_span_a,
leading_senkou_span_b, chikou_span, cloud_green, cloud_red
"""

please do not use chikou span ... it's simply the candle's close shifted 26 periods into history.
This means, a strategy using chikou span will look ok on backtesting - but will fail in every live / dry run scenario, as it is not available for the latest 26 candles.

You can insteda simply use dataframe['close'] - which is exactly the same, but without displacement (ichimoku is mainly a visual indicator - good to look at in charts, tricky to use in strategies).

from technical.

Benoth08 avatar Benoth08 commented on May 4, 2024

Thank you very much. Thank you very much.
Yes I agree with you ichimoku is very visual but I'm just testing out of curiosity by comparing with other strategies.
If I understood correctly, is it the same problem with senkou_a and senkou_b? If I do:
dataframe['senkou_a'].shift(-26)), does that return the value to -26?

Apparently in the indicator code you put: senkou_span_a = leading_senkou_span_a.shift(displacement) with "displacement = 26". I should do it instead:

dataframe['leading_senkou_span_a'].shift(-26)), right?

Thanks for your help

from technical.

xmatthias avatar xmatthias commented on May 4, 2024

shifting it back won't work - the "forward-shifted" candles are removed as they fall out of the index.

You should be able to use the leading_ - but look very carefully at the last few candles of the dataframe for which fields have values (and which ones).

I don't use ichimoku myself, so i can't really help you very well.

from technical.

xmatthias avatar xmatthias commented on May 4, 2024

I'll close this as i hope you found what you were looking for.

Feel free to comment below if you're still struggling with ichimoku.

from technical.

shroukkhan avatar shroukkhan commented on May 4, 2024

Hi @xmatthias , looking at the code here

senkou_span_a = leading_senkou_span_a.shift(displacement)

it is simply a displacement 26 candles into future ( or , toward the right hand side the graph as seen in trading view ) .

So , if we were to find out if current close is above green cloud that is about to form in trading view, this should do the trick:

  1. Copy the ichimoku function
    def ichimoku(dataframe, conversion_line_period=9, base_line_periods=26,
    into your own strategy
  2. Remove these two lines in order to avoid dropping them off the index
    senkou_span_a = leading_senkou_span_a.shift(displacement)
    senkou_span_b = leading_senkou_span_b.shift(displacement)
  3. Simulate trading view's comparison of current close above a cloud that is forming 26 candles into the future by doing this:
(dataframe['senkou_span_a'] > dataframe[senkou_span_b]) # green cloud
& (dataframe['close'] > dataframe[senkou_span_a]) # close is above green cloud

Does the above sound right?

from technical.

xmatthias avatar xmatthias commented on May 4, 2024

No it does not.

The "shifted" spans will not be dropped within the ichimoku function, but when you merge/assign them to the original dataframe.
The function returns leading_senkou_span_a and leading_senkou_span_b as seperate columns - which are the ones that are not displaced, so comparing them directly will tell you exactly what you're looking for in your screenshot.

from technical.

shroukkhan avatar shroukkhan commented on May 4, 2024

Thankyou, that makes sense. Is there a way I can access ichimoku within populate_buy_trend without using dataframe merging?

from technical.

shroukkhan avatar shroukkhan commented on May 4, 2024

Alternatively, i think we can do the comparison within the populate_indicators function and store only the result.

from technical.

xmatthias avatar xmatthias commented on May 4, 2024

You get the non-shifted indicator.
For "machine" comparison, that will suffice (it's actually exactly what you want).
While it may not look that nice on charts - it's exactly what you needed.
The shift of the original indicator may look nice on charts - but is unusable as is for machine comparisons.

Not merging will fail as the dataframes are then of different length (or will be shifted).

from technical.

matiman86 avatar matiman86 commented on May 4, 2024

Hello, there may now be any way to occupy chikou in a real time trading strategy with freqtrade? I would like to try to use the indicator but I can only do it through backtesting. @xmatthias @berlinguyinca @shroukkhan

from technical.

xmatthias avatar xmatthias commented on May 4, 2024

@matiman86

There is nothing more to say than the comment in the docstring:

def ichimoku(
dataframe, conversion_line_period=9, base_line_periods=26, laggin_span=52, displacement=26
):
"""
Ichimoku cloud indicator
Note: Do not use chikou_span for backtesting.
It looks into the future, is not printed by most charting platforms.
It is only useful for visual analysis

Which also explains why you "can" use it in backtesting (and probably get good results) - but not in live.

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.