- The word is spelled multiple.
- You are not checking if you already have an open order.
As William wrote - you're not checking what's already open.
Try this one out
void OnTick() { if(CheckForExistingOrder()==0)//Example to call the function,check and if no orders exists and do stuff.... { //...do stuff here } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int CheckForExistingOrder() { int check=0; for(int x = OrdersTotal() - 1; x >= 0; x--) { if(!OrderSelect(x, SELECT_BY_POS)) break; if(OrderSymbol()!=Symbol() && OrderMagicNumber()!=MagicNumber) continue; if((OrderCloseTime() == 0) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType() == OP_BUY||OrderType() == OP_SELL) check = 1; if(!(OrderType() == OP_BUY||OrderType() == OP_SELL)) check = -1; } } return(check); }
Okay, thank you very much.
Do I have to check the magic number? I only want to open one trade in each symbol. So I assume that I only need to check if there is an open trade in the corresponding symbol and I don't need to check the magic number? Or is there an advantage if I check the magic number?
Okay, thank you very much.
Do I have to check the magic number? I only want to open one trade in each symbol. So I assume that I only need to check if there is an open trade in the corresponding symbol and I don't need to check the magic number? Or is there an advantage if I check the magic number?
Magic number is the actual orders identification number and should absolutely be used. The code i gave you checks and identify your order and what symbol it's placed on plus it makes it not interfere with other robots you may use. Simply make an external setting in your ea with a magic number input;
extern int MagicNumber= 1234567;
and now this work with the function itself i gave you...you don't need to change the magic for each chart you trade,not necessary at all!
Hi everybody,
Could I ask if this code work for mt4? In the case I am on right forum.
I think I have the same problem: I have to run Multi EAs on different pairs, the same EA on different pairs or more EAs on the same pair (the same timeframe or different ones)
Regarding the code that Kenneth Parling suggested where I have to write this part of code:
void OnTick() { if(CheckForExistingOrder()==0)//Example to call the function,check and if no orders exists and do stuff.... { //...do stuff here } }
and where this one:
int CheckForExistingOrder() { int check=0; for(int x = OrdersTotal() - 1; x >= 0; x--) { if(!OrderSelect(x, SELECT_BY_POS)) break; if(OrderSymbol()!=Symbol() && OrderMagicNumber()!=MagicNumber) continue; if((OrderCloseTime() == 0) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType() == OP_BUY||OrderType() == OP_SELL) check = 1; if(!(OrderType() == OP_BUY||OrderType() == OP_SELL)) check = -1; } } return(check); }
Finally, Do I need to specify before OrderSend condition example MA1>MA2&&ect... also something else?
Thanks a lot
Magic number is the actual orders identification number and should absolutely be used. The code i gave you checks and identify your order and what symbol it's placed on plus it makes it not interfere with other robots you may use. Simply make an external setting in your ea with a magic number input;
and now this work with the function itself i gave you...you don't need to change the magic for each chart you trade,not necessary at all!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all
My EA should open one trade if the ADX crosses a level from below. Most time it works fine but sometimes it opens multible Trades. All at the same time in same symbol. I think the problem occours in this part of code. This part should just watch if the adx crossed the adx_low_level from below and return a TRUE or FALSE. If there was a TRUE then a trade would be openend and the already_sent bool would turn to true. This boolean should help to send just one "TRUE" to caller if there's fluctuation in adx calculation. The boolean would be resettet when the adx value is +3 to the low level. In my opionon +3 should not be possible to acchive by just fluctuation. Therefore it should not open new trades but this happens.
What am I doing wrong?
Thanks for input.
Best regards
Remu