int CheckCount() { static datetime AlertTime=Time[1]; double check; bool result = false; int count; count = 0; check = iBarShift("EURAUD",PERIOD_M5,Time[1],1); if(Time[0] > AlertTime) for(int i = 1; i <= 10 ; i ++){ if(iClose(_Symbol,PERIOD_M5,i) < iOpen(_Symbol,PERIOD_M5,i) && check == 1) break; count++; AlertTime = Time[0];} if(count == 0) ; // code is missing here otherwise I could be completely wrong about the code return(count); }
Sorry here is the code.
try lining things up properly and things become easier to see...
did you intend the highlighted sections to be like that?
int CheckCount() { static datetime AlertTime=Time[1]; double check; bool result = false; int count; count = 0; check = iBarShift("EURAUD",PERIOD_M5,Time[1],1); if(Time[0] > AlertTime) for(int i = 1; i <= 10 ; i ++) { if(iClose(_Symbol,PERIOD_M5,i) < iOpen(_Symbol,PERIOD_M5,i) && check == 1) break; <== run if the IF is true count++; <== always run every loop AlertTime = Time[0]; <== always run every loop } if(count == 0) ; <== this does nothing // code is missing here otherwise I could be completely wrong about the code return(count); }
int checkcount() { { static datetime AlertTime=Time[1]; double count; count = 0; bool result = false; if(Time[0] > AlertTime) for(int i = 1; i <= 10 ; i ++){ if(MN() == 1 && symbol() == 1) if(iClose(_Symbol,PERIOD_M5,i) < iOpen(_Symbol,PERIOD_M5,i)) result = true; if(result == true) break; <----- this allows the loop to not flood through and stack when green } AlertTime = Time[0]; if(count == 0) < -------- Missing a code or function that returns the value of the previous result so that the value doesnt return 0 but stays constant after. eg. 1,2,3,(red candle)3,4,5, return(count); } }
Hey thank you for the response, yes I did. Below I have attempted another piece of code. I have another mq4 file with different code that prints the same results. I have tried functions that lookback to the previous result so that the current one if condition is not met stays the same.
You are over complicating the solution.
If you call your function and it is not a new bar then it will return 0, how will you know if that is a count or simply a new bar.
So you should check for new bar before you call the function that way you know the returned count is actually a count.
If all you need is a count of green bars excluding the current bar then this will do...
int CheckCount() { int count=0; for(count=0; count<=10; count++) { if(iClose(_Symbol,_Period,count+1) < iOpen(_Symbol,_Period,count+1)) break; } return(count); }
First of all thank you for your help, I think you have done enough. My code prints the same exact information as does your code. Unfortunately there doesn't seem to be a solution to this. You see Its not about my function or the way I am writing it, its about the next step in order to keep the value the same instead of resetting the value. To be honest I dont think that there is something that could stop the count from being reset.
The difference:
When you want to check your previous losses using the in built functions offered by MQL4, you can stack those results (i.e. 1,2,3,4,5) you want until infinite, if there is another condition that resets the loop (1,2,3, 0! == 3,4,5), that re-setter is invalid and continues to stack along until you call another condition for it to stop (if "" > 1000) Sleep();.
Just to reiterate.
Basically I have developed a counting system where the ea counts green bars, the trouble comes by when the candle value resets itself back to 0 when the red candle appears.
The difference:
When you want to check your previous losses using the in built functions offered by MQL4, you can stack those results (i.e. 1,2,3,4,5) you want until infinite, if there is another condition that resets the loop (1,2,3, 0! == 3,4,5), that re-setter is invalid and continues to stack along until you call another condition for it to stop (if "" > 1000) Sleep();.
What you have said is not clear, there is always a way but your requirements are not clear at the moment why not show a chart with your expected count(s)
If you want a count stored for every bar then you need an array to store the values in, or use an indicator buffer.
At the moment all you are doing is getting a count of continuous green bars from bar index 1 through to bar index 9
exactly, hence why I am developing the code into a more defined way to capture and add consecutively all the green bars in total.
so I have now seen this line from your previous post which was off screen as it was a single long line
Missing a code or function that returns the value of the previous result so that the value doesnt return 0 but stays constant after. eg. 1,2,3,(red candle)3,4,5,
so you need to stop breaking the loop if want the count of green bars. Also, a green bar has a close > open not <
int CheckCount() { int count=0; int X=0; for(X=1; X<=10; X++) { if(iClose(_Symbol,_Period,X) > iOpen(_Symbol,_Period,X)) count++; } return(count); }
so I have now seen this line from your previous poast which was off screen as it was a single line
so you need to stop breaking the loop if want the count of green bars. Also, a green bar has a close > open not <
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey coders, I have been in quite a dilema for the past day or so scratching my head on what is actually missing. Basically I have developed a counting system where the ea counts green bars, the trouble comes by when the candle resets itself back to 0 when the green candle is not shown on the prev bar. Some guidance will be good.