freqtrade / technical

Various indicators developed or collected for the Freqtrade
GNU General Public License v3.0
758 stars 218 forks source link

Ichimoku strategy: use of chikou #93

Closed Benoth08 closed 3 years ago

Benoth08 commented 4 years ago

Good morning, everyone,

I hope you're all right. I'm turning to you to answer a quick question about the use of the ichimoku package. I would like to integrate the ichimoku into my Freqtrade trading strategy, but I'm a bit of a beginner. I would like to see how I can use chikou span in my strategy and compare it to senkou_a and senkou_b 26 periods backwards.

In ichimoku's basic strategy, for a buy signal, the price at time T or chikou must be higher than the value of senkou_a and senkou_b 26 periods backwards. I would like to know how I can incorporate this into my strategy.

Is this correct?

(dataframe['chikou']>dataframe['senkou_a'].shift(-26)) & (dataframe['chikou']>dataframe['senkou_b'].shift(-26))

Thanks

xmatthias commented 4 years ago

https://github.com/freqtrade/technical/blob/9924ee42a46811ce33bd46ab760d00a6cd0e48b0/technical/indicators.py#L245-L260

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).

Benoth08 commented 4 years ago

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

xmatthias commented 4 years ago

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.

xmatthias commented 3 years ago

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.

shroukkhan commented 2 years ago

Hi @xmatthias , looking at the code here https://github.com/freqtrade/technical/blob/9924ee42a46811ce33bd46ab760d00a6cd0e48b0/technical/indicators.py#L273

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 https://github.com/freqtrade/technical/blob/9924ee42a46811ce33bd46ab760d00a6cd0e48b0/technical/indicators.py#L245 into your own strategy
  2. Remove these two lines in order to avoid dropping them off the index https://github.com/freqtrade/technical/blob/9924ee42a46811ce33bd46ab760d00a6cd0e48b0/technical/indicators.py#L273-L275
  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?

xmatthias commented 2 years ago

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.

shroukkhan commented 2 years ago

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

shroukkhan commented 2 years ago

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

xmatthias commented 2 years ago

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).

matiman86 commented 2 years ago

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

xmatthias commented 2 years ago

@matiman86

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

https://github.com/freqtrade/technical/blob/367142a8a0c61d93a5498b85040138e8c835393a/technical/indicators/indicators.py#L26-L33

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