Hello, I have a problem with my code
Somtimes it missed the opportunity,
I have 3 accounts in the same broker and I put the same robot in those 3 accounts but Sometimes, 2accounts place an order but the another one does not place an order(it missed the opportunity)
This is my code: (I can not put it in Alt+S because the code is too long so I will put the attached file of the robot)
Thanks in advance for replying:
Check the leverage of those 3 accounts, check if they are using the same leverage.
Check the money balance on the 3 acounts, different balance can make the EA act different
etc,,-
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum?
Next time, post in the correct place. The moderators will likely move this thread there soon. -
//--- return orders volume if(buys>0) buys++; else sells++; }
CalculateCurrentOrders does not return a value. Why are you incrementing your count extra? You would know that had you used strict.
Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
-
if(Volume[0]>1) return;
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 2014.04.04I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum 2011.05.06 -
if (_sl == 0){ SL = 0;} else{SL = Ask - _sl*Point;} if (_sl == 0){ TP = 0;} else{TP = Ask + _tp*Point;} lots=Lots; res=OrderSend(Symbol(),OP_SELL,NormalizeLots(lots,Symbol()),Bid,3,SL,TP,EA_Comment,MAGICMA,0,Red); OrderSend(Symbol(),OP_SELL,NormalizeLots(lots,Symbol()),Bid,3,SL,TP,EA_Comment,MAGICMA,0,Red);
SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies. (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
Lot size must also be adjusted to a multiple of Lo @Tolotra Ny tStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
-
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 - Your CalculateCurrentOrders filters by Symbol. Shouldn't your closeall and Trailing_SL?
-
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 can simply 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 - For In First Out (FIFO rules — US brokers), and you (potentially) process multiple orders per symbol, you must find the earliest order (count up), close it, and on a successful operation, reprocess all positions.
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
- For non-FIFO (non-US brokers), (or the EA only opens one order per symbol), you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
-
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum?
Next time, post in the correct place. The moderators will likely move this thread there soon. -
CalculateCurrentOrders does not return a value. Why are you incrementing your count extra? You would know that had you used strict.
Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
-
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 2014.04.04I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum 2011.05.06 -
SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies. (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
Lot size must also be adjusted to a multiple of Lo @Tolotra Ny tStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
-
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 - Your CalculateCurrentOrders filters by Symbol. Shouldn't your closeall and Trailing_SL?
-
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 can simply 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 - For In First Out (FIFO rules — US brokers), and you (potentially) process multiple orders per symbol, you must find the earliest order (count up), close it, and on a successful operation, reprocess all positions.
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
- For non-FIFO (non-US brokers), (or the EA only opens one order per symbol), you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
Thanks so much
I will recode it following your help :-)

- 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, I have a problem with my code
Somtimes it missed the opportunity,
I have 3 accounts in the same broker and I put the same robot in those 3 accounts but Sometimes, 2accounts place an order but the another one does not place an order(it missed the opportunity)
This is my code: (I can not put it in Alt+S because the code is too long so I will put the attached file of the robot)
Thanks in advance for replying: