William,
Could you perhaps be a little more explicit?
I would really appreciate it!
int y = iBarShift(NULL,timeFrame,Time[shift]); double cci = iCCI(NULL,timeFrame,Length,Price,y);
Using the above example from a multi-timeframe CCI indicator, you need to substitute the 'shift' variable occurances with 'y' variable to get the chart timeframe offset correctly.
You can research iBarShift function. It finds the right bar time offset for it to align with another timeframe.
Using the above example from a multi-timeframe CCI indicator, you need to substitute the 'shift' variable occurances with 'y' variable to get the chart timeframe offset correctly.
You can research iBarShift function. It finds the right bar time offset for it to align with another timeframe.
Thank you so much!
Greatly appreciated!
William sorry about not seeing the links - I guess the oranges and apples words made me think you were only referring to a well known saying.
I have in my ignorant state tried to adapt the code with the info you and gave me.
Unfortunately I am still doing something wrong.
If you can help me to fix this code properly I am prepared to pay the fee you may charge me in USD.
This is what the code looks like at the moment:
#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_width1 2 #property indicator_color2 Red #property indicator_width2 2 //+------------------------------------------------------------------+ extern int CCI = 50; extern int ATR = 5; extern ENUM_TIMEFRAMES TF = PERIOD_H1; //+------------------------------------------------------------------+ double bufferUp[]; double bufferDn[]; //+------------------------------------------------------------------+ int init() { SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(0, bufferUp); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(1, bufferDn); return (0); } //+------------------------------------------------------------------+ int deinit() { return (0); } //+------------------------------------------------------------------+ int start() { double thisCCI; double lastCCI; int counted_bars = IndicatorCounted(); if (counted_bars < 0) return (-1); if (counted_bars > 0) counted_bars--; int limit = Bars - counted_bars; for (int i = limit; i >= 0; i--) { int y = iBarShift(NULL,TF,Time[i]); thisCCI = iCCI(NULL, TF, CCI, PRICE_TYPICAL, y); lastCCI = iCCI(NULL, TF, CCI, PRICE_TYPICAL, y + 1); if (thisCCI >= 0 && lastCCI < 0) bufferUp[y + 1] = bufferDn[y + 1]; if (thisCCI <= 0 && lastCCI > 0) bufferDn[y + 1] = bufferUp[y + 1]; if (thisCCI >= 0) { bufferUp[y] = Low[y] - iATR(NULL, TF, ATR, y); if (bufferUp[y] < bufferUp[y + 1]) bufferUp[y] = bufferUp[y + 1]; } else { if (thisCCI <= 0) { bufferDn[y] = High[y] + iATR(NULL, TF, ATR, y); if (bufferDn[y] > bufferDn[y + 1]) bufferDn[y] = bufferDn[y + 1]; } } } return (0); }
int y = iBarShift(NULL,TF,Time[i]); thisCCI = iCCI(NULL, TF, CCI, PRICE_TYPICAL, y); lastCCI = iCCI(NULL, TF, CCI, PRICE_TYPICAL, y + 1); if (thisCCI >= 0 && lastCCI < 0) bufferUp[y + 1] = bufferDn[y + 1]; if (thisCCI <= 0 && lastCCI > 0) bufferDn[y + 1] = bufferUp[y + 1]; if (thisCCI >= 0) { bufferUp[y] = Low[y] - iATR(NULL, TF, ATR, y);
"y" is now the other timeframe (TF) index. Your buffers (bufferUp), and predefined arrays (Low) are the chart's timeframe. You are still mixing.
Seems like the code below is still mixing things up! I give up!
#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_width1 2 #property indicator_color2 Red #property indicator_width2 2 //+------------------------------------------------------------------+ extern int CCI = 50; extern int ATR = 5; extern ENUM_TIMEFRAMES TF = PERIOD_H1; //+------------------------------------------------------------------+ double bufferUp[]; double bufferDn[]; //+------------------------------------------------------------------+ int init() { SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(0, bufferUp); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(1, bufferDn); return (0); } //+------------------------------------------------------------------+ int deinit() { return (0); } //+------------------------------------------------------------------+ int start() { double thisCCI; double lastCCI; int counted_bars = IndicatorCounted(); if (counted_bars < 0) return (-1); if (counted_bars > 0) counted_bars--; int limit = Bars - counted_bars; for (int i = limit; i >= 0; i--) { datetime time = Time[i]; int y = iBarShift(NULL, TF, time); thisCCI = iCCI(NULL, TF, CCI, PRICE_TYPICAL, y); lastCCI = iCCI(NULL, TF, CCI, PRICE_TYPICAL, y + 1); if (thisCCI >= 0 && lastCCI < 0) bufferUp[y + 1] = bufferDn[y + 1]; if (thisCCI <= 0 && lastCCI > 0) bufferDn[y + 1] = bufferUp[y + 1]; if (thisCCI >= 0) { bufferUp[y] = Low[y] - iATR(NULL, TF, ATR, y); if (bufferUp[y] < bufferUp[y + 1]) bufferUp[y] = bufferUp[y + 1]; } else { if (thisCCI <= 0) { bufferDn[y] = High[y] + iATR(NULL, TF, ATR, y); if (bufferDn[y] > bufferDn[y + 1]) bufferDn[y] = bufferDn[y + 1]; } } } return (0); }
Your new code | datetime time = Time[i]; int y = iBarShift(NULL, TF, time); |
It is exactly the same as what you had. It changes nothing. | int y = iBarShift(NULL,TF,Time[i]); |
I previously said “Your buffers (bufferUp), and predefined arrays (Low) are the chart's timeframe.” Did you ignore it, not understand it, or was it not clear? Go back and read the links provided.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I tried to convert the trend-magic indicator to a MTF indicator but it does not work correcty.
I know a little about coding EA's but nothing about coding Indicators so I need a little help.
Here is the code below: