LongOrdershort and ShortOrdershort will get ticket number after opening first successful long and short orders.
Ticket numbers are integers assigned on the server and they are ordinal numbers of the orders on the server. They are assigned in a sequence for all active accounts on the particular server and/or account type at the broker.
So, they are way bigger than 4 and you can't use them as a number of active orders on your MT4 instance.
But, if you run this EA in the tester, orders will get ticket numbers starting with 1 because those ticket numbers are generated on your computer.
LongOrdershort and ShortOrdershort will get ticket number after opening first successful long and short orders.
Ticket numbers are integers assigned on the server and they are ordinal numbers of the orders on the server. They are assigned in a sequence for all active accounts on the particular server and/or account type at the broker.
So, they are way bigger than 4 and you can't use them as a number of active orders on your MT4 instance.
But, if you run this EA in the tester, orders will get ticket numbers starting with 1 because those ticket numbers are generated on your computer.
Thank you Drazen for your answer, can you tell me how to get this right?
Add two new variables and use them to count the number of successfully opened orders.
int longOrdersCount = 0; int shortOrdersCount = 0; ... //Open Buy Order if(BuySignalshort == true) { while(longOrdersCount<=4) { LongOrdershort = OrderSend(Symbol(),OP_BUY,longTradeLots,Ask,MySlippage,0,0,"MaxingLong",MagicNumber,0,Green); if(LongOrdershort<0) { Print("OrderSend failed with error'",GetLastError()); } else { Print("OrderSend places successfully"); longOrdersCount++; } } }...
Add two new variables and use them to count the number of successfully opened orders.
this works to open as much orders as I defined, but it will open all orders at the same time. How can I define that it opens one order per bar if the condition is fulfilled and the next on a new bar if the condition is fulfilled again? on the other hand, the order modify function will only modify the first order that is sent, how can I select every order to set TP and SL?
Thank you very much for your help!!!
this works to open as much orders as I defined, but it will open all orders at the same time. How can I define that it opens one order per bar if the condition is fulfilled and the next on a new bar if the condition is fulfilled again? on the other hand, the order modify function will only modify the first order that is sent, how can I select every order to set TP and SL?
Thank you very much for your help!!!
- Record time of the last order in a variable or loop through the active orders and find the time of the last order
- Compare with the start time of the current bar
- Be careful to compensate for the eventual timeframe changes and other EA restarts
For the TP and SL
- create a separate money management function(s) that will calculate SL and TP for buy and sell orders respectively
- call money management functions to obtain appropriate SL and TP values before OrderSend()

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey there,
I programmed an EA that is working all in all pretty good. But there is one problem, it only open one short and one long order and then wait until these are closed to open the next orders. But I want this EA to open an order every time my conditions are fulfilled. The broker allows that but I can't figure out where the problem is. Can someone hint me to a solution for that issue?
thank you in advance