Or maybe this:
bool OpenOrderRangeBuyHigh () { for(int b= OrdersTotal()-1; b >= 0; b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) if(OrderMagicNumber() == MagicNumber) if(OrderSymbol() == Symbol()) if(OrderType()==OP_BUY) if(OrderOpenPrice()< Ask-OpenOrderPipDiff*pips) { return(true); } } return(false); }
Seems like the last return(true); for each function is not needed you already have a return for these functions
Not so.
If there are no open orders or no orders that meet the criteria, the returns in the loop will not be executed
So if I have 5 open positions. The EA is not opening a trade at the same position as the previous trades
Your loops return true or false based on the first order checked
I don't know for sure what you are doing with the result, but maybe use a continue instead of return?
bool OpenOrderRangeBuyHigh () { for(int b= OrdersTotal()-1; b >= 0; b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) if(OrderMagicNumber() == MagicNumber) if(OrderSymbol() == Symbol()) if(OrderType()==OP_BUY) if(OrderOpenPrice()< Ask-OpenOrderPipDiff*pips) continue; else return(false); } return(true);
Not so.
If there are no open orders or no orders that meet the criteria, the returns in the loop will not be executed
My last return(false) is outside of the for loop, so if the for loop simply exits with no value then it gives control to the next statement in the functions which is return(false) then exits the function execution with it's bool value
Do I have this wrong ?
Are you sure ?
My last return(false) is outside of the for loop, so if the for loop simply exits with no value then it gives control to the next statement in the functions which is returns(false)
Do I have this wrong ?
You were referring to Jtubbs code,so it was that code that I was referring to.
I was replying to your unedited post that only said
Seems like the last return(true); for each function is not needed you already have a return for these functions
You had not added the code at that time
You were referring to Jtubbs code,so it was that code that I was referring to.
I was replying to your unedited post that only said
You had not added the code at that time
AHHH got it thanks, scared me for a min. there thought I was way off for min. there
return(true);
else return(false);
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- If you find any orders that opened below your pip difference, you return true, i.e. open a new one. What you asked for is open only if you don't find any. Your test is reversed. Either
GumRai version or this equivalent:
bool OpenOrderRangeBuyHigh (){ for(int iPos= OrdersTotal()-1; iPos >= 0; --iPos) if( OrderSelect(iPos, SELECT_BY_POS) && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && OrderType() == OP_BUY ){ if(OrderOpenPrice() > Ask-OpenOrderPipDiff*pips) return false; } // for return true; }
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- If you find any orders that opened below your pip difference, you return true, i.e. open a new one. What you asked for is open only if you don't find any. Your test is reversed. EitherGumRai version or this equivalent:

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am having a issue with some coding for an EA. I am wanting it to Not open another trade at the same positions. So if I have 5 open positions. The EA is not opening a trade at the same position as the previous trades, but the EA is opening trades at the same position as the others. I need a way to code the EA Not to open trades at the other open positions. This is how far I have gotten. Thanks for any help in advance
bool OpenOrderRangeBuyHigh ()
{
for(int b= OrdersTotal()-1; b >= 0; b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber() == MagicNumber)
if(OrderSymbol() == Symbol())
if(OrderType()==OP_BUY)
if(OrderOpenPrice()< Ask-OpenOrderPipDiff*pips)
return(true);
else return(false);
}
return(true);
}
bool OpenOrderRangeBuyLow ()
{
for(int b= OrdersTotal()-1; b >= 0; b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber() == MagicNumber)
if(OrderSymbol() == Symbol())
if(OrderType()==OP_BUY)
if(OrderOpenPrice()> Ask+OpenOrderPipDiff*pips)
return(true);
else return(false);
}
return(true);
}