Hello everyone,
i've been having an issue with this function: what i'm basically trying to do is placing a stop loss on the opposite bollinger band when the OnTimer event occurs. The function works perfectly, except for the fact that the stop loss is placed on the wrong instrument when multiple positions are open. Can someone help? Here's the code of the function:
I have no idea why this happens and i've even tried reaching out MQL5 for possible assistance. Any suggestions?
This line here:
if(!OrderModify(OrderTicket(),Bid,BBLow,OrderTakeProfit(),0,clrGreen))
On your OnTimer event, every required ticket should have its SL modified in this code segment?
So do a print of your parameters of OrderModify(), for each ticket. That should give you a list of OrderTicket()s, SL etc and then work backwards from there if they are not correct.
This line here:
On your OnTimer event, every required ticket should have its SL modified in this code segment?
So do a print of your parameters of OrderModify(), for each ticket. That should give you a list of OrderTicket()s, SL etc and then work backwards from there if they are not correct.
I did try, and by doing the debugging, it returns all parameters correctly, then it does this .
It basically places the stops on the other change... I'm desperate, can't figure this out...
I tried also to make it print the TICKET of the selected order, and it's correct. I have no idea why this is happening.
Seems like the expert plugged to a chart modifies the order of another chart. How's this even possible if everything is called by Symbol????
-
if(OrderType() == OP_SELL) ⋮ if(!OrderModify(OrderTicket(),Ask,BBHi,OrderTakeProfit(),0,clrGreen))
You have an open order. You can't modify the open price after the fact.
-
if(OrderStopLoss() != BBLow)
Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum
-
You have an open order. You can't modify the open price after the fact.
- Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum
Ok so, the Ask paramether in the Price section of OrderModify() is an error and in order to fix the doubles error i might want to put a range around the doubles i need. Yet, this does not explain why one instance of the Expert which selects the order by Symbol and Magicnumber, edits orders belonging to another symbol :\
Ok so, the Ask paramether in the Price section of OrderModify() is an error and in order to fix the doubles error i might want to put a range around the doubles i need. Yet, this does not explain why one instance of the Expert which selects the order by Symbol and Magicnumber, edits orders belonging to another symbol :\
Probably we don't know enough about your code logic to solve, but what might benefit is some rewriting of the code to simplify and help identify the bug: working out how you might solve the problem.....
It looks like you're doing a similar thing for both buy and sell, so why not have one function?
for(int i=0; i<OrdersTotal(); i++){ if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=_Symbol||OrderMagicNumber()!=...)continue; if(OrderType()==OP_SELL&&OrderStopLoss()>BBHi) // OrderModify... if(OrderType()==OP_BUY&&OrderStopLoss()<BBLow) // OrderModify... }
But for debugging, instead of OrderModify inside the code fragment, I might save the modify parameters into a separate array of orders, and read back the values, outside the loop.....
===
loop orders
select the orders for modification
write ticket, SL etc into array of orders
end
loop
read array of orders
===
- www.mql5.com
Probably we don't know enough about your code logic to solve, but what might benefit is some rewriting of the code to simplify and help identify the bug: working out how you might solve the problem.....
It looks like you're doing a similar thing for both buy and sell, so why not have one function?
But for debugging, instead of OrderModify inside the code fragment, I might save the modify parameters into a separate array of orders, and read back the values, outside the loop.....
===
loop orders
select the orders for modification
write ticket, SL etc into array of orders
end
loop
read array of orders
===
Tried, but always getting the same bug.
try this one - not tested!
for(int i=0; i<OrdersTotal(); i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; if(OrderSymbol()!=_Symbol && OrderMagicNumber()!=...) continue; if(OrderSymbol()==_Symbol && OrderMagicNumber()==...) { if(OrderType()==OP_SELL&&OrderStopLoss()>BBHi) { if(!OrderModify...)) { Print("Error modifying"); return; } } if(OrderType()==OP_BUY&&OrderStopLoss()<BBLow) { if(!OrderModify...)) { Print("Error modifying"); return; } } } }
try this one - not tested!
I will test this and give you response
don't forget to fill in the OrderModify with details...as for now they are empty
don't forget to fill in the OrderModify with details...as for now they are empty
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
i've been having an issue with this function: what i'm basically trying to do is placing a stop loss on the opposite bollinger band when the OnTimer event occurs. The function works perfectly, except for the fact that the stop loss is placed on the wrong instrument when multiple positions are open. Can someone help? Here's the code of the function:
I have no idea why this happens and i've even tried reaching out MQL5 for possible assistance. Any suggestions?