Hi all,
i am learning mql4 and for this i think that i must code and understand the logic. Well, i am trying to code the searching of previous high from actual+1 bar.
This is the heart of the code. I understand that the code is not correct because i have referenced "1" and i must be referenced each H4 previous bar. When i have referenced this bar, then i have to searchthe previous high in i+2, i+3,...
Then, my question:
i must referenced this bar with
Well i have the index of H4 bar but now, i dont understand how i have to continue. Can someone explain for understand or other code for understand better? I dont want mix apples with oranges.
The propose of code is learn and understand operations in mql4.
Thank you very much!!
Any help please??
int timeFrameIndex = iBarShift(NULL, PERIOD_H4, iTime(NULL,PERIOD_H4,i), true);
- Help you with what? You've already answered your own question.
- Don't mix apples and oranges.
- Help you with what? You've already answered your own question.
- Don't mix apples and oranges.
Sorry whroeder1, i complete with this code but now i am blocked because i dont understand the function of time. For reference to one bar, i have to know the index of this bar and later other loop. I agree with you that i am mixing apples and Oranges.
#property copyright "Copyright © 2017" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red static datetime CurBar; double Arrow[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,Arrow); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,218); IndicatorDigits(Digits+0); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { Comment(""); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i,TimeframeIndex,j,countHighHugePeriod,counthigh; for ( i=1000;i>=0;i--) { TimeframeIndex=iBarShift(NULL,PERIOD_H4,iTime(NULL,PERIOD_H4,i),true); CurBar = iTime(NULL,PERIOD_H4,TimeframeIndex); if(CurBar != iTime(NULL,PERIOD_H4,TimeframeIndex)) { for ( j=100 ;j>1 ;j--) { if ( iHigh(NULL,PERIOD_H4,TimeframeIndex+1) > iHigh(NULL,PERIOD_H4,TimeframeIndex+j) ) { counthigh++; } if ( iHigh(NULL,PERIOD_H4,TimeframeIndex+1) <= iHigh(NULL,PERIOD_H4,TimeframeIndex+j)) { counthigh=0; } countHighHugePeriod = counthigh+1; if(countHighHugePeriod==3) { Arrow[TimeframeIndex+1]=iHigh(NULL, PERIOD_H4,TimeframeIndex+1); } } } } return(0); }Thank you very much!
Sorry whroeder1, i complete with this code but now i am blocked because i dont understand the function of time. For reference to one bar, i have to know the index of this bar and later other loop. I agree with you that i am mixing apples and Oranges.
Sorry again whroeder,
i read the posts of your link, but is not the same. They use the easy way with iHighest, but i want iterate searching the previous high for learn to use well loops. Maybe my logic is wrong. The line :
if(countHighHugePeriod==3) { Arrow[TimeframeIndex+1]=iHigh(NULL, PERIOD_H4,TimeframeIndex+1); }
is only for prove the code.
Thank you very much!!
Hi all again,
i made this code but with some mystake. I dont understand very well function of to see when a bar close with static datetime. Is the logic correct?
Please help!!
#property copyright "Copyright © 2017" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red //static datetime CurBar; double Arrow[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,Arrow); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,218); IndicatorDigits(Digits+0); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { Comment(""); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i,TimeframeIndex,j,countHighHugePeriod,counthigh; for ( i=1000;i>=0;i--) { static datetime lastBar; datetime CurBar = iTime(NULL, PERIOD_H4,i); if(lastBar != CurBar) { lastBar= CurBar; for ( j=100 ;j>1 ;j--) { if ( iHigh(NULL,PERIOD_H4,i+1) > iHigh(NULL,PERIOD_H4,j+1) ) // contador si el high del bar anterior al actual es mayor que los anteriores { counthigh++; } if ( iHigh(NULL,PERIOD_H4,i+1) <= iHigh(NULL,PERIOD_H4,j+1)) // Cuando el high del bar anterior es menor, entonces inicializamos el contador { counthigh=0; } countHighHugePeriod = counthigh+1; if(countHighHugePeriod==3) { Arrow[i+1]=iHigh(NULL, PERIOD_H4,i+1); } } } } return(0); }
for ( i=1000;i>=0;i--){ static datetime lastBar; datetime CurBar = iTime(NULL, PERIOD_H4,i); if(lastBar != CurBar){
- The logic of that new bar code is correct except that it is inside a loop. That if statement will always be true, the time of a bar is always different from the next..
- This is an indicator. There is no need for new bar code. Do it like any other indicator. See How to do your
lookbacks correctly.
- Convert your i to H4 index for all your H4 calls. apples and oranges.
- The logic of that new bar code is correct except that it is inside a loop. That if statement will always be true, the time of a bar is always different from the next..
- This is an indicator. There is no need for new bar code. Do it like any other indicator. See How to do your
lookbacks correctly.
- Convert your i to H4 index for all your H4 calls. apples and oranges.
Hi again whroeder1,
i was studying your links and i made this code but some mystake. When i prove variable "t", i always have the value of 0:
int start() { int j,countHighper,counthigh; int LookBack = 100; int counted=IndicatorCounted(); int t = Bars - 1 - MathMax(LookBack, counted); for(int iBar = t; iBar >= 0; iBar--) { int iTF = iBarShift(Symbol(), PERIOD_H4, iTime(NULL,PERIOD_H4,iBar)); for ( j=100 ;j>2 ;j--) { if ( iHigh(NULL,PERIOD_H4,iTF+1) > iHigh(NULL,PERIOD_H4,iTF+j) ) { counthigh++; } if ( iHigh(NULL,PERIOD_H4,iTF+1) <= iHigh(NULL,PERIOD_H4,iTF+j)) { counthigh=0; } countHighper = counthigh+1; if(countHighper==3) { Arrow[iTF+1]=iHigh(NULL, PERIOD_H4,iTF+1); } } } return(0); }
Well, i use iBar like current bar of period H4, then i calculate the index of that bar with "iTF". Later i have other loop for iterate fixing the iTF+1 bar. I think the logic of indicator is correct but some mystake have me pulling hair.
Thank you very much for your patience, i am learning more!
When i prove variable "t", i always have the value of 0:
Well, i use iBar like current bar of period H4, then i calculate the index of that bar with "iTF". Later i have other loop for iterate fixing the iTF+1 bar. I think the logic of indicator is correct but some mystake have me pulling hair.
int t = Bars - 1 - MathMax(LookBack, counted);
The first time through the loop, counted will be zero and you do all bars. After that it will be zero until a new bar starts.int iTF = iBarShift(Symbol(), PERIOD_H4, iTime(NULL,PERIOD_H4,iBar)); for ( j=100 ;j>1 ;j--){ if ( iHigh(NULL,PERIOD_H4,iTF+1) > iHigh(NULL,PERIOD_H4,iTF+j) )
First you convert iBar to iTF for your H4 calls, good. But then you are looping iTF+100 to iTF. No where do you check if you have iTF+100 bars on the H4. Your lookback is not 100. It is 100 on the H4, 400 on the H1, 800 on the M30, etc.int LookBack = 100 * Period_H4 / _Period;
Arrow[iTF]=iHigh(NULL, PERIOD_H4,iTF);
Your buffer (Arrow) is the current chart. iTF is the H4. You are mixing apples and oranges.
if ( iHigh(NULL,PERIOD_H4,iTF+1) <= iHigh(NULL,PERIOD_H4,iTF+j))
Why is there a +1? iTF is the H4 shift for bar iBar. That is the bar you should be looking at because that is the bar you will draw the arrow on.for ( j=100 ;j>2 ;j--){ if ( iHigh(NULL,PERIOD_H4,iTF+1) > iHigh(NULL,PERIOD_H4,iTF+j) ) counthigh++; if ( iHigh(NULL,PERIOD_H4,iTF+1) <= iHigh(NULL,PERIOD_H4,iTF+j)) counthigh=0; if(countHigh==2)
Why are you looking back 100 bars when you only want to draw an arrow then the current H4 is higher then the previous two?- Where do you ever set the count to zero before the loop.
- The first time through the loop, counted will be zero and you do all bars. After that it will be zero until a new bar starts.
- First you convert iBar to iTF for your H4 calls, good. But then you are looping iTF+100 to iTF. No where do you check if you have iTF+100 bars on the H4. Your lookback is not 100. It is 100 on the H4, 400 on the H1, 800 on the M30, etc.
- Your buffer (Arrow) is the current chart. iTF is the H4. You are mixing apples and oranges.
- Why is there a +1? iTF is the H4 shift for bar iBar. That is the bar you should be looking at because that is the bar you will draw the arrow on.
- Why are you looking back 100 bars when you only want to draw an arrow then the current H4 is higher then the previous two?
- Where do you ever set the count to zero before the loop.
Thank you very much whroeder1, i understand value of "t", the conversion of lookBack to timeframe, the Arrow Buffer. I use "countHigh==3" for prove that really draw arrow in chart. So 100 bars back is random number that i put for see the iteration. I initialize count to 0 before loops...
int start() { int j,countHighHugePeriod=0,counthigh=0; int LookBack = 100 * PERIOD_H4 / _Period; int counted=IndicatorCounted(); int t = Bars - 1 - MathMax(LookBack, counted); for(int iBar=t; iBar >= 0; iBar--) { int iTF = iBarShift(Symbol(), PERIOD_H4, iTime(NULL,PERIOD_H4,iBar)); for ( j=100 ;j>2 ;j--) { if ( iHigh(NULL,PERIOD_H4,iTF) > iHigh(NULL,PERIOD_H4,iTF+j) ) counthigh++; if ( iHigh(NULL,PERIOD_H4,iTF) <= iHigh(NULL,PERIOD_H4,iTF+j)) counthigh=0; countHighHugePeriod = counthigh+1; if(countHighHugePeriod==3) { Arrow[iBar]=iHigh(NULL, PERIOD_H4,iTF); } } } return(0); }
Sorry if i delay in answer but i am reading and studying your links. I want understand all the code! Thank you very much and awesome
- 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 all,
i am learning mql4 and for this i think that i must code and understand the logic. Well, i am trying to code the searching of previous high from actual+1 bar.
This is the heart of the code. I understand that the code is not correct because i have referenced "1" and i must be referenced each H4 previous bar. When i have referenced this bar, then i have to searchthe previous high in i+2, i+3,...
Then, my question:
i must referenced this bar with
Well i have the index of H4 bar but now, i dont understand how i have to continue. Can someone explain for understand or other code for understand better? I dont want mix apples with oranges.
The propose of code is learn and understand operations in mql4.
Thank you very much!!