ta4j icon indicating copy to clipboard operation
ta4j copied to clipboard

Ichimoku Chikou Span Indicator Calculation Incorrect?

Open Andre0711er opened this issue 4 years ago • 8 comments

Hi.

Just evaluating Ichimoku Cloud and i dont know, but might be calculation from Chikou Span is not correct. If i check your underlying link https://school.stockcharts.com/doku.php?id=technical_indicators:ichimoku_cloud i see the calculation must be 26 Days in the past. So, 26 bars back. In IchimokuChikouSpanIndicator Class i see, calculation is done by "index + timeDelay". So this mean index (now) plus 26 in Front. Is this right?

File: core/indicators/ichimoku/IchimokuChikouSpanIndicator.java Line: 74

protected Num calculate(int index) { int spanIndex = index + timeDelay; if (spanIndex <= getBarSeries().getEndIndex()) { return closePriceIndicator.getValue(spanIndex); } else { return NaN.NaN; } }

Andre0711er avatar Mar 24 '21 15:03 Andre0711er

hi @Andre0711er thanks for reporting, I will have a closer look

team172011 avatar Apr 20 '21 20:04 team172011

Here is a fix and a complete ichimoku strategy:

https://github.com/MarcDahlem/ta4j/blob/test/test-my-strategies/ta4j-examples/src/test/java/ta4jexamples/strategies/IntelligentTa4jOhlcBenchmarks.java#L442

As trade-dependent indicators https://github.com/ta4j/ta4j/pull/757 , before rules https://github.com/ta4j/ta4j/pull/773 and positive delay indicators https://github.com/ta4j/ta4j/pull/772 are not accepted to be merged here, I can hardly create a PR for the corrected Ichimoku indicators and a complete corresponding example strategy to show its usage :-/

Feel free to use the corrected versions from my fork, or create own PRs and strategies from them.

grafik

MarcDahlem avatar May 18 '21 16:05 MarcDahlem

@MarcDahlem If you need those (so far) not accepted PR's to solve this issue then we should discuss it. If @team172011 is not able to provide a suitable solution then we should accept the solution from @MarcDahlem. And if the solution needs those rules ("trade dependent rule", "before rule", "delay indicator"), then create a PR packaged with all of those which fixex this issue.

nimo23 avatar May 18 '21 17:05 nimo23

@MarcDahlem I am happy to see that there is a possible fix. I remember that there were discussions about this indicator years ago..

We should definitely fix it in ta4j as well. But we should try to follow the established format:

  • As far as I know, all the indicators of the Ichimoku Cloud are not depending on the executed trades/positions (like all other indicators). So in general a trade-dependent #757 indicator should not be a requirement for the Ichimoku Cloud.

  • Also if there is a need for functionalities like in before rule #773 or in a positive delay indicator #772 adding this functionality in a scope of a dedicated rule or indicator to this lib is another question.

team172011 avatar May 18 '21 18:05 team172011

References to already existing issues/solutions:

  • https://github.com/ta4j/ta4j/pull/495
  • https://github.com/ta4j/ta4j/issues/448
  • https://github.com/ta4j/ta4j/pull/452
  • https://github.com/ta4j/ta4j/issues/374
  • https://github.com/ta4j/ta4j/issues/614

MarcDahlem avatar May 18 '21 20:05 MarcDahlem

@MarcDahlem I am happy to see that there is a possible fix. I remember that there were discussions about this indicator years ago..

Yes I saw that it was often part of discussions. For getting an overview, I linked them all in the previous post.

We should definitely fix it in ta4j as well. But we should try to follow the established format:

* As far as I know, all the indicators of the _Ichimoku Cloud_ are not depending on the executed trades/positions (like all other indicators). So in general a _trade-dependent_ #757 indicator should not be a requirement for the _Ichimoku Cloud_.

Yes and no. The indicators themselves do not need it. True. But the problem is that we want to show how to use the indicators with an example strategy.

But as soon as you want to use those Ichimoku indicators in (usefull) rules/strategy, you cannot avoid it. The main point is, that in the most definitions of Ichimoku, the entry conditions (close price did cross the cloud --> close price > cloud) are still satisfied if the exit criteria (gain reached, or lagging span crossed close price) are met.

In order to avoid this. the indicator must be "reset" (say "crossing up the cloud never happened") as soon as a position exit happened.

* Also if there is a need for functionalities like in  _before rule_ #773 or in a _positive delay indicator_ #772 adding this functionality in a scope of a dedicated rule or indicator to this lib is another question.

The delay indicator is just a helper, not directly needed, but increases readability.

The before rule is needed because:

  1. Check if the close price completely crossed the cloud
  • cross of the cloud's lower line will never appear at the same time as the crossing of the upper line. Here, you need cross lower BEFORE cross upper.
  • you cannot simply "hack" it with UnderIndicatorRule( lowestValue(closePrice, X) , cloudLowerLineAtY)), becuase you dont know the time Y of the lowest price. And also at that time Y it is not said, that lowest price is also the lowest time slot of the cloud at that position Y.
  1. Wait for a) the crossing of the laggingSpan up the past cloud + b) crossing of the ask price up the current cloud. They will likely never happen at the same time. Also here, you need crossingCurrent BEFORE crossing laggingSpan. And also here, the LowestPriceIn does not help

MarcDahlem avatar May 18 '21 20:05 MarcDahlem

I added the corrected ichimoku indicators without the need of the other rules. I just created another, simpler strategy as example

MarcDahlem avatar May 21 '21 18:05 MarcDahlem