Hello, I'm trying to develop an indicator that analyzes on the M30 chart when two MAs cross and then shows it on the H1 chart, but it doesn't work for me.
There are some issues with this block:
if(MovingAverageBuffer12_Period30[i]>MovingAverageBuffer22_Period30[i] && MovingAverageBuffer12_Period30[i+1]<MovingAverageBuffer22_Period30[i+1]) { datetime CandleTime=iTime(_Symbol,PERIOD_M30,i); int Bar=iBarShift(_Symbol,_Period,CandleTime,true); UpBuffer_Period30[Bar]=low[Bar]-0.00030; } else if(MovingAverageBuffer12_Period30[i]<MovingAverageBuffer22_Period30[i] && MovingAverageBuffer12_Period30[i+1]>MovingAverageBuffer22_Period30[i+1]) { datetime CandleTime=iTime(_Symbol,PERIOD_M30,i); int Bar=iBarShift(_Symbol,_Period,CandleTime,true); DownBuffer_Period30[Bar]=high[Bar]+0.00030; }
(1) Your i is based on _Period (since it is based on rates_total and prev_calculated), and your MovingAverageBuffers and iTime() for PERIOD_M30 uses i - the same i for different periods will give you different times and your result will be garbage.
(2) You need to check the return values of iBarShift(), because if the time is outside of all the available candles, iBarShift() returns -1, and will cause the next line to fail (array out of range).
Honestly, I don't get it.
Then look at this table that illustrates my two points above - assuming current time is 1200 hrs:
i | Time (T60) at Bar i on H1 Chart (i.e. iTime(_Symbol,_Period,i) | Time (T30) at Bar i on M30 Chart (i.e. iTime(_Symbol,PERIOD_M30,i) | Bar (i.e. iBarShift(_Symbol,_Period,T30,true)) |
---|---|---|---|
0 | 1200 | 1200 | 0 |
1 | 1100 | 1130 | -1 (out of range) |
2 | 1000 | 1100 | 1 |
3 | 0900 | 1030 | -1 (out of range) |
4 | 0800 | 1000 | 2 |
5 | 0700 | 0930 | -1 (out of range) |
6 | 0600 | 0900 | 3 |
: | : | : | : |
10 | 0200 | 0700 | 5 |
Notice that T60 and T30 are not the same for the same bar number i.
- Seng Joo Thio:Correct
Then look at this table that illustrates my two points above - assuming current time is 1200 hrs: …
Notice that T60 and T30 are not the same for the same bar number i.
- If you pass 1130 to iBarShift(H1) you will get -1 with true. So stop using true, use the default and you'll get the H1 shift for the bar containing 1130. M30 shift one is 1130, H1 shift one is 1100. M30 shift 3 is 1030, H1 shift 2 is 1000.
- Not, in general.
- If you pass 1130 to iBarShift(H1) you will get -1 with true. So stop using true, use the default and you'll get the H1 shift for the bar containing 1130. M30 shift one is 1130, H1 shift one is 1100. M30 shift 3 is 1030, H1 shift 2 is 1000.
- Baxter9311: Honestly, I don't get it.Don't mix apples and oranges.
- 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, I'm trying to develop an indicator that analyzes on the M30 chart when two MAs cross and then shows it on the H1 chart, but it doesn't work for me.