And results changed with no errors.. and got the selected order correctly :)
2014.12.0916:31:23.6402014.03.2800:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 42014.12.0916:31:23.6402014.03.2800:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 42014.12.0916:31:23.6402014.03.2800:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 2 Total Trades : 42014.12.0916:31:23.6402014.03.2800:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 3 Total Trades : 42014.12.0916:31:23.6402014.03.2800:00 TESTIN~1 EURGBP-,Daily: open #9buy 0.10 EURGBP- at 0.82709 tp: 0.83184 ok
2014.12.0916:31:23.6402014.03.2800:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (DOWN) -- ### : 52014.12.0916:31:23.3752014.03.2700:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 32014.12.0916:31:23.3752014.03.2700:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 32014.12.0916:31:23.3752014.03.2700:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 2 Total Trades : 32014.12.0916:31:23.3752014.03.2700:00 TESTIN~1 EURGBP-,Daily: open #8buy 0.10 EURGBP- at 0.83115 tp: 0.83627 ok
2014.12.0916:31:23.3752014.03.2700:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (DOWN) -- ### : 42014.12.0916:31:23.1252014.03.2600:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 22014.12.0916:31:23.1252014.03.2600:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 22014.12.0916:31:23.1252014.03.2600:00 TESTIN~1 EURGBP-,Daily: open #7buy 0.10 EURGBP- at 0.83639 tp: 0.83903 ok
2014.12.0916:31:23.1252014.03.2600:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (DOWN) -- ### : 32014.12.0916:31:22.9842014.03.2516:12 Tester: take profit #5at 0.83421 (0.83415 / 0.83421)
2014.12.0916:31:22.9842014.03.2516:11 Tester: take profit #6at 0.83429 (0.83423 / 0.83429)
2014.12.0916:31:22.7962014.03.2500:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 32014.12.0916:31:22.7962014.03.2500:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 1 Total Trades : 32014.12.0916:31:22.7962014.03.2500:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 2 Total Trades : 32014.12.0916:31:22.7962014.03.2500:00 TESTIN~1 EURGBP-,Daily: open #6sell 0.10 EURGBP- at 0.83859 tp: 0.83429 ok
2014.12.0916:31:22.7962014.03.2500:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (UP) -- ### : 42014.12.0916:31:22.5152014.03.2400:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 22014.12.0916:31:22.5152014.03.2400:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 1 Total Trades : 22014.12.0916:31:22.5152014.03.2400:00 TESTIN~1 EURGBP-,Daily: open #5sell 0.10 EURGBP- at 0.83601 tp: 0.83421 ok
2014.12.0916:31:22.5152014.03.2400:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (UP) -- ### : 32014.12.0916:31:22.3282014.03.2110:38 Tester: take profit #4at 0.83649 (0.83649 / 0.83655)
2014.12.0916:31:22.2652014.03.2100:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 22014.12.0916:31:22.2652014.03.2100:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 22014.12.0916:31:22.2652014.03.2100:00 TESTIN~1 EURGBP-,Daily: open #4buy 0.10 EURGBP- at 0.83474 tp: 0.83649 ok
2014.12.0916:31:22.2652014.03.2100:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (DOWN) -- ### : 22014.12.0916:31:22.0782014.03.2013:47 Tester: take profit #1at 0.83415 (0.83409 / 0.83415)
2014.12.0916:31:21.9212014.03.2000:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 0 Total Trades : 22014.12.0916:31:21.9212014.03.2000:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 22014.12.0916:31:21.9212014.03.2000:00 TESTIN~1 EURGBP-,Daily: open #3buy 0.10 EURGBP- at 0.83624 tp: 0.83968 ok
2014.12.0916:31:21.9212014.03.2000:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (DOWN) -- ### : 12014.12.0916:31:21.8752014.03.1922:26 Tester: take profit #2at 0.83607 (0.83601 / 0.83607)
2014.12.0916:31:21.5462014.03.1900:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 0 Total Trades : 22014.12.0916:31:21.5462014.03.1900:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 1 Total Trades : 22014.12.0916:31:21.5462014.03.1900:00 TESTIN~1 EURGBP-,Daily: open #2sell 0.10 EURGBP- at 0.83967 tp: 0.83607 ok
2014.12.0916:31:21.5462014.03.1900:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (UP) -- ### : 22014.12.0916:28:48.1092014.03.1800:00 TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 0 Total Trades : 12014.12.0916:28:48.1092014.03.1800:00 TESTIN~1 EURGBP-,Daily: open #1sell 0.10 EURGBP- at 0.83672 tp: 0.83415 ok
2014.12.0916:28:48.1092014.03.1800:00 TESTIN~1 EURGBP-,Daily: Alert: ### -- New BAR (UP) -- ### : 12014.12.0916:28:48.093 TESTIN~1 inputs: BuyLots=0.1; SellLots=0.1; Barsize_min=20; Barsize_max=60; Spread=10; Take_profit_level=100; high_low=1;
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.
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:
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:
For non-FIFO (non-US brokers), (or the EA only opens one order per symbol), you cansimply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 programming forum
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
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