You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thank you guys for the quick replies..
I have change the FOR loop to:
v_cnt = OrdersTotal();
And results changed with no errors.. and got the selected order correctly :)
I am wondering if I can use the same for loop for an inner FOR loops inside the Main FOR loop, one FOR loop for buy orders and one FOR loop for sell orders (All inside the main loop)..
So that I can modify the takeprofit level depending on market conditions that I set.
The main issue that I am going to be having, how to identify the closed orders while still going through the main loop?
Let say I have 5 orders open, and by the time the code is going through the second order the 4th order got closed because simply it reached takeprofit level, now the total order has changed to 4 order instead of 5. So the order count is not in sync anymore with the orderselect!
Simply I just want to modify the orders that are still open.
Kind regards,
I have same invalit ticket for OrderModify function : OrderModify erro 4051
Guys anyone can help .....?
OrderSelect(ticket1,SELECT_BY_POS);
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor
A ticket is not a position. Make up your mind how you are selecting orders.
Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014
In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading), while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing and order count:
Loops and Closing or Deleting Orders - MQL4 programming forum
CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1.11
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor
A ticket is not a position. Make up your mind how you are selecting orders.
Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014
In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading), while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing and order count:
Loops and Closing or Deleting Orders - MQL4 programming forum
CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1.11
Hi guys,
I just can´t find why my EA is showing this error when I use the Trailing Stop option.
I am attaching here the code where I call the function Trailing Stop and then the function itself
After that I am showing the messsages from the Alerts That I have inserted in the code
In short, The StopLoss of the Selected Order is the same as the new Stop Loss that the trailing Stop is calculating
If I am right, I have specifically coded that in such case the EA will not run the OrderModify function
But the Error 4051 is happening even though the OrderModify function is not being called
Well, at least that is my deduction
Will someone please check what is wrong with my code?
This is the Trailing Stop function
so, after I check that Modify==false, there is a break instruction, so the EA should get out of the while(true) loop and should NOT execute the OrderModify instruction, but somehow it is beeing called and if my new SL is equal to the OrderStopLoss then error 4051 is understandable. But why is the OrderModify instruction being executed, will someone please explain?
here are the messages when I backtested the EA:
What I see here is that the new SL (variable SL) is 1.3418 and the OrderStopLoss (variable loss) is exactly 1.3418
That is why the condition if(SL<loss-pips2dbl) under the case 1: (sell) is not met.
That is why the message "Modify=false" is being showed
That is why the Answer (A)=false is being showed
So then why is the EA showing "Occurred error 4051"?
Maybe the int Error=GetLastError is not being initialized ? So it is showing this error just because it was the last error and not because this error is happening over and over?
Thanks in advance for your help
Hi I was having this error and commented this line of my code : //OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderTakeProfit(), 0, Blue);.. try I hope this help, I'm Not an expert