I am trying to get you right.
I have copied High / Low prices in array for bars with specified time start and stop. So the copyXXXX() should always return the same bars within the specified time range on each call at different times.
Within this array highest and lowest bar index should remain same.
I will highly appreciate, if you can show me alternate way to get these data.
Regards.
I think I have got your point and have tried using the following change:
CopyHigh(mSymbol,PERIOD_M1,TimeCurrent(),aTimeM01[bars-1],aHighM01); CopyLow(mSymbol,PERIOD_M1,TimeCurrent(),aTimeM01[bars-1],aLowM01); //+---------------------------------------------------------------------------------------------------------------------------+ //| STEP[B] Calculate CPR/Support/Resistance levels //+---------------------------------------------------------------------------------------------------------------------------+ mCurrOpen = iOpen(mSymbol,PERIOD_M1,iBarShift(mSymbol,PERIOD_M1,aTimeM01[0])); // Open price at current Bar mPrevOpen = iOpen(mSymbol,PERIOD_M1,iBarShift(mSymbol,PERIOD_M1,aTimeM01[bars-1])); // Open price at CPR Start Bar mPrevClose = iClose(mSymbol,PERIOD_M1,iBarShift(mSymbol,PERIOD_M1,aTimeM01[1])); // Close price at previous Bar int idxStart = iBarShift(mSymbol,PERIOD_M1,aTimeM01[0]); int barCount = iBarShift(mSymbol,PERIOD_M1,aTimeM01[bars-1]) - idxStart; int idxHigh = ArrayMaximum(aHighM01,idxStart,barCount); int idxLow = ArrayMinimum(aLowM01,idxStart,barCount);
However prices are still changing.
2024.05.24 14:06:49.591 2024.03.08 01:01:20 day[3] bars[1374] From[2024.03.01 15:00] to [2024.03.04 14:59] | CurrOpen[2082.64] PrevOpen[2052.42] PrevHigh[ 5514][2083.98] PrevLow[ 4811][2083.45] PrevClose[2082.64] 2024.05.24 14:06:49.591 2024.03.08 01:01:20 day[2] bars[1378] From[2024.03.04 15:00] to [2024.03.05 14:59] | CurrOpen[2124.33] PrevOpen[2082.55] PrevHigh[ 4140][2115.23] PrevLow[ 3437][2124.06] PrevClose[2124.33] 2024.05.24 14:06:49.591 2024.03.08 01:01:20 day[1] bars[1378] From[2024.03.05 15:00] to [2024.03.06 14:59] | CurrOpen[2134.06] PrevOpen[2124.45] PrevHigh[ 2762][2127.93] PrevLow[ 2059][2126.48] PrevClose[2134.09] 2024.05.24 14:06:49.591 2024.03.08 01:01:20 day[0] bars[1378] From[2024.03.06 15:00] to [2024.03.07 14:59] | CurrOpen[2158.58] PrevOpen[2134.15] PrevHigh[ 1384][2148.81] PrevLow[ 681][2156.36] PrevClose[2158.60] 2024.05.24 14:07:00.733 2024.03.08 02:00:00 day[3] bars[1374] From[2024.03.01 15:00] to [2024.03.04 14:59] | CurrOpen[2082.64] PrevOpen[2052.42] PrevHigh[ 5514][2083.42] PrevLow[ 4811][2082.69] PrevClose[2082.64] 2024.05.24 14:07:00.733 2024.03.08 02:00:00 day[2] bars[1378] From[2024.03.04 15:00] to [2024.03.05 14:59] | CurrOpen[2124.33] PrevOpen[2082.55] PrevHigh[ 4140][2115.30] PrevLow[ 3437][2125.58] PrevClose[2124.33] 2024.05.24 14:07:00.733 2024.03.08 02:00:00 day[1] bars[1378] From[2024.03.05 15:00] to [2024.03.06 14:59] | CurrOpen[2134.06] PrevOpen[2124.45] PrevHigh[ 2762][2127.98] PrevLow[ 2059][2128.51] PrevClose[2134.09] 2024.05.24 14:07:00.733 2024.03.08 02:00:00 day[0] bars[1378] From[2024.03.06 15:00] to [2024.03.07 14:59] | CurrOpen[2158.58] PrevOpen[2134.15] PrevHigh[ 1384][2147.32] PrevLow[ 681][2155.29] PrevClose[2158.60] 2024.05.24 14:07:01.632 2024.03.08 03:00:00 day[3] bars[1374] From[2024.03.01 15:00] to [2024.03.04 14:59] | CurrOpen[2082.64] PrevOpen[2052.42] PrevHigh[ 5514][2082.58] PrevLow[ 4811][2082.60] PrevClose[2082.64] 2024.05.24 14:07:01.632 2024.03.08 03:00:00 day[2] bars[1378] From[2024.03.04 15:00] to [2024.03.05 14:59] | CurrOpen[2124.33] PrevOpen[2082.55] PrevHigh[ 4140][2115.60] PrevLow[ 3437][2122.38] PrevClose[2124.33] 2024.05.24 14:07:01.632 2024.03.08 03:00:00 day[1] bars[1378] From[2024.03.05 15:00] to [2024.03.06 14:59] | CurrOpen[2134.06] PrevOpen[2124.45] PrevHigh[ 2762][2126.82] PrevLow[ 2059][2132.97] PrevClose[2134.09] 2024.05.24 14:07:01.632 2024.03.08 03:00:00 day[0] bars[1378] From[2024.03.06 15:00] to [2024.03.07 14:59] | CurrOpen[2158.58] PrevOpen[2134.15] PrevHigh[ 1384][2148.68] PrevLow[ 681][2154.38] PrevClose[2158.60] 2024.05.24 14:08:35.773 2024.03.08 04:00:00 day[3] bars[1374] From[2024.03.01 15:00] to [2024.03.04 14:59] | CurrOpen[2082.64] PrevOpen[2052.42] PrevHigh[ 5514][2079.77] PrevLow[ 4860][2082.70] PrevClose[2082.64] 2024.05.24 14:08:35.773 2024.03.08 04:00:00 day[2] bars[1378] From[2024.03.04 15:00] to [2024.03.05 14:59] | CurrOpen[2124.33] PrevOpen[2082.55] PrevHigh[ 4140][2112.19] PrevLow[ 3486][2122.99] PrevClose[2124.33] 2024.05.24 14:08:35.773 2024.03.08 04:00:00 day[1] bars[1378] From[2024.03.05 15:00] to [2024.03.06 14:59] | CurrOpen[2134.06] PrevOpen[2124.45] PrevHigh[ 2762][2125.68] PrevLow[ 2108][2132.86] PrevClose[2134.09] 2024.05.24 14:08:35.773 2024.03.08 04:00:00 day[0] bars[1378] From[2024.03.06 15:00] to [2024.03.07 14:59] | CurrOpen[2158.58] PrevOpen[2134.15] PrevHigh[ 1384][2145.79] PrevLow[ 730][2155.98] PrevClose[2158.60]
Hi
I think iHighest andiLowest functions are not compatible for mt5 (just like iBarShift), you need to use your own version of this function – which would work for mt5, something like this:
int iHighestMQL4(string symbol, int tf, int type, int count=WHOLE_ARRAY, int start=0) { if(start<0) return(-1); ENUM_TIMEFRAMES timeframe=TFMigrate(tf); if(count<=0) count=Bars(symbol,timeframe); if(type<=MODE_OPEN) { double Open[]; ArraySetAsSeries(Open,true); CopyOpen(symbol,timeframe,start,count,Open); return(ArrayMaximum(Open,0,count)+start); } if(type==MODE_LOW) { double Low[]; ArraySetAsSeries(Low,true); CopyLow(symbol,timeframe,start,count,Low); return(ArrayMaximum(Low,0,count)+start); } if(type==MODE_HIGH) { double High[]; ArraySetAsSeries(High,true); CopyHigh(symbol,timeframe,start,count,High); return(ArrayMaximum(High,0,count)+start); } if(type==MODE_CLOSE) { double Close[]; ArraySetAsSeries(Close,true); CopyClose(symbol,timeframe,start,count,Close); return(ArrayMaximum(Close,0,count)+start); } if(type==MODE_VOLUME) { long Volume[]; ArraySetAsSeries(Volume,true); CopyTickVolume(symbol,timeframe,start,count,Volume); return(ArrayMaximum(Volume,0,count)+start); } if(type>=MODE_TIME) { datetime Time[]; ArraySetAsSeries(Time,true); CopyTime(symbol,timeframe,start,count,Time); return(ArrayMaximum(Time,0,count)+start); //--- } return(0); }
Have a nice weekend
Hi
I think iHighest andiLowest functions are not compatible for mt5 (just like iBarShift), you need to use your own version of this function – which would work for mt5, something like this:
Have a nice weekend
Hi
This is a new piece of information for me :)
Happy weekend to you too.
UPDATE :
I have been able to resolve this with the following code.
CopyHigh(mSymbol,PERIOD_M1,TimeCurrent(),aTimeM01[bars-1],aHighM01); CopyLow(mSymbol,PERIOD_M1,TimeCurrent(),aTimeM01[bars-1],aLowM01); int idxStart = iBarShift(mSymbol,PERIOD_M1,aTimeM01[0]); int idxLast = iBarShift(mSymbol,PERIOD_M1,aTimeM01[bars-1]); int idxHigh = ArrayMaximum(aHighM01,idxStart,idxLast-idxStart+1); int idxLow = ArrayMinimum(aLowM01,idxStart,idxLast-idxStart+1); mPrevHigh = iHigh(mSymbol,PERIOD_M1,idxHigh); mPrevLow = iLow(mSymbol,PERIOD_M1,idxLow);
Thanks and wish all happy weekend.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
Please help me out to debug problem/error in my code.
I am getting different values for Highest and Lowest prices, though the data set is for the same period.
The CurrOpen, PrevOpen and PrevClose are calculated correctly on each NewH01 bar, but Highest/Lowest prices are changed.
Relevant section of the code is highlighted where the error occurring.
Your help to identify cause of error will be highly appreciated.
Regards.