Hello all,
I'm trying to write up this indicator which will plot channels for the previous day/week/month and year. So far i have got the day/week/month all working but I am having some troubles with the yearly channel.
To do this for the previous 12 months doesn't seem too difficult but I would like to make the channel for the high/low of the past calander month (Jan-Dec) for all years in the chart history.
In it's present form it currently marks the high/low of the previous year but seems to be off by a month or two for some reason. Then after a couple of years the indi just runs flat.
Any ideas. Code Below:
if(prev_year!=cur_year) { last_year_high= iHigh(NULL,PERIOD_MN1,iHighest(NULL,PERIOD_MN1,MODE_HIGH,12,MONTHshift+1)); last_year_low = iLow(NULL,PERIOD_MN1,iLowest(NULL,PERIOD_MN1,MODE_LOW,12,MONTHshift+1)); prev_year=cur_year; }The +1 may make a difference
The +1 may make a difference
Thanks for the reply GumRai.
I would have thought it would definitely solve the problem but unfortunately it doesn't seem to make any major difference the to problem described above.
Do you (or anyone else) have any suggestions?
Sorry for the hassle
Thanks for the reply GumRai.
I would have thought it would definitely solve the problem but unfortunately it doesn't seem to make any major difference the to problem described above.
Do you (or anyone else) have any suggestions?
Sorry for the hassle
I stand corrected. It does fix the issue.
I was looking at MN1 and forgot to check the other timeframes.
The yearly channel plots fine now on everything but the monthly chart. Any ideas why this may be. I have data all the way back to 1995 on my chart so it's not like there is a shortage of bars.
Is it because I use PERIOD_MN1 in my calculations rather than the number of bars in a year for what ever period chart I am viewing at any given time?
It is because
TimeDay(Time[cnt])
will always return 1 on the monthly chart
so
if(prev_day!=cur_day)
will never be true.
Move this out of the if condition and add the extra line to calculate MONTHshift
if(prev_year!=cur_year) { MONTHshift=iBarShift(Symbol(),PERIOD_MN1,Time[cnt]); last_year_high= iHigh(NULL,PERIOD_MN1,iHighest(NULL,PERIOD_MN1,MODE_HIGH,12,MONTHshift+1)); last_year_low = iLow(NULL,PERIOD_MN1,iLowest(NULL,PERIOD_MN1,MODE_LOW,12,MONTHshift+1)); prev_year=cur_year; }
GumRai!!
I'm sorry I missed your reply to this.
Thank you for your clear explanation. Your fix worked perfectly :)
It's folks like you that make this forum that much more enjoyable.
Cheers,
SteepCurve

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I'm trying to write up this indicator which will plot channels for the previous day/week/month and year. So far i have got the day/week/month all working but I am having some troubles with the yearly channel.
To do this for the previous 12 months doesn't seem too difficult but I would like to make the channel for the high/low of the past calander month (Jan-Dec) for all years in the chart history.
In it's present form it currently marks the high/low of the previous year but seems to be off by a month or two for some reason. Then after a couple of years the indi just runs flat.
Any ideas. Code Below: