I wish the people who write the Ichimoku books were more explicit in their instructions in the calculations. Looking at the code above I'm assuming the following:
- tenkan-sen: (9 period max high + 9 period min low)/2
Pick a date. Look the for maximum high price over the previous nine periods.
Look for the minimum low price over the same nine periods. Add the two prices
together and divide by two. Plot the result on the date's Y-axis.
- kiju-sen: (26 period max high + 26 period min low)/2
Use the same date as for the tenkan-sen. Look for the maximum high price over
the previous twenty-six periods. Look for the minimum low price over the same
twenty-six periods. Add the two prices and divide by two. Plot the result on
the date's Y-axis.
- chikou span: Plot on the Y-axis the date's closing price twenty-six periods
to the left of the chosen date.
- senkou span A: (tenkan-sen + kiju-sen)/2 shifted twenty-six periods to right.
Start at the extreme left most date of the plot. Add the values of the
tenkan-sen and kiju-sen. Divide the sum by 2. Plot the resulting value on the
the date twenty-six periods to the right. Continue this until you get to
today's date.
- senkou span B: (52 period maximum high price + 52 period minimum low price)/2
shifted 26 periods to the right.
Again start at the extreme left most date of the plot. Find the maximum high
price of the previous 52 periods. Find the minimum low price of the same 52
periods. Divide the sum by 2. Plot the resulting value on the
the date twenty-six periods to the right. Continue this until you get to
today's date.
Plotting the first three from a chosen date to today's date results in three lines. The last two give a plot area ("cloud") along with two possible support/resistance lines defining the upper/lower "cloud" bounds. All this assumes the 'periods' are dates (they might be 15 minute periods for day traders as an example of other periods). Also, some books have senkou plan B shift 26 periods and some shift it 22 periods. I understand the original book by Goichi Hosoda had it twenty-six periods, so I used that value.
Thank you for writing the program. While I thought I understood what the authors of the books on this subject meant, I was never sure until I saw the code. Obviously the authors were not programmers or mathematicians doing proofs. I guess I'm just too linear!