- How do I check if a trade was opened during the current bar
- basic question : Exit on close
- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
- Derrick Mutange: but the max value it returns is 3 how can I fix this?
You start with two and if condition1 add one, else if condition2 add one. Your code can only return two or three. Why does this surprise you? Fix what? You haven't explained what you want.
- Derrick Mutange: check the the other bar till it returns the number of the correct bar,
You only check the current bar vs. shift bar. You don't check other bars. What do you mean by “the number of the correct bar?” Bar index?
-
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.
-
You start with two and if condition1 add one, else if condition2 add one. Your code can only return two or three. Why does this surprise you? Fix what? You haven't explained what you want.
-
You only check the current bar vs. shift bar. You don't check other bars. What do you mean by “the number of the correct bar?” Bar index?
-
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.
Hey William thanks for the reply.
How would you suggest I go about checking the current bar vs the next bar if the bar 2 fails it checks 3 if 3 fails then 4 etc... till the bar that satisfies the conditions is reached?
2, 3, 4, … is called a loop.
Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)
Hi guys I have a question, the code below is supposed to check if current open price of the current bar opened between open and close prices of the previous bar, if not its supposed to add +1 and check the the other bar till it returns the number of the correct bar, but the max value it returns is 3 how can I fix this?
don't use NormalizeDouble it is not needed
use a loop to go through how many bars you want to check in the example below that is 99
current bar is index zero so start checking at 1
simplify the condition checking
return the number of true conditions counted
Is this really what you want though because it will check all the bars and return a count, you talk about a correct bar but that is not defined.
int shift_value(string symbol, ENUM_TIMEFRAMES period) { int iCounted = 0; double current_open= iOpen(symbol,period,0); for(int iShift=1; iShift<100; iShift++) { double shift_open = iOpen(symbol,period,iShift); double shift_close = iClose(symbol,period,iShift); if(current_open < MathMin(shift_open, shift_close) || current_open > MathMax(shift_open, shift_close)) iCounted++; } return iCounted; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use