Download MetaTrader 5

MQL4 Programming Help!!! - Only One Opened Trade Pair, Per Signal.

To add comments, please log in or register
Share links on the Forum. Now they have Rich Content!
Lynn
49
Lynn 2009.06.15 15:48 
Can anyone provide the code to make sure only one trade per pair is opened at time? I have an EA that places market orders, but it places multiple trades as long as the conditions are met. I only want one trade per pair opened at a time. For example, once a short GBPUSD is opened, then as long as that trade is opened, there are no other GBPUSD trades opened (Long or Short) even if the conditions to open a trade are still valid. Can anyone provide the code for this? I have changed my int ticket = -1; to int ticket; and this has not worked. I also have used the OrderSelect() and if (ticket != -1) functions, but the EA continues to try to (and sometimes successfully) open new trades. Please help!!!! Thank you.
Alexander
2441
Alexander 2009.06.15 17:38  

datetime newbar;

int start()

{

if(newbar==Time[0])return(0);

else newbar=Time[0];

//your program

}

Lynn
49
Lynn 2009.06.15 19:51  
Roger:

datetime newbar;

int start()

{

if(newbar==Time[0])return(0);

else newbar=Time[0];

//your program

}

Roger:


Thanks for the quick reply. I was also thinking this might work:


int start()

{

int total;

string symbol;


total = OrdersTotal()

if(total>0 && symbol = Symbol()) return (0); //Abort! A Position For This Pair is Already Open

//the rest of my program code

}


The idea id to make sure that if there is already an opened order for a particular pair, the EA will not open another position for that pair even if trade conditions are met. SO if I have a GBPUSD position open, the EA can still open a EURUSD position, but it will not open another GBPUSD position until the first one is closed. I don't mind if one position is opened and then closed and then another position (same pair) is opened and closed during the same bar. I just don't want 2 positions in the same pair opened at the same time. So do you think the code above will do it? Should I change the return(0); to return; (doesn't return(0); take the program back to int start())?


Alexander
2441
Alexander 2009.06.15 20:00  

Very close. Try this:

int start()

{

int total,ord,i;

string symbol;

total = OrdersTotal();

for(i=0;i<total;i++)

{

OrderSelect(i,SELECT_BY_POS);

if(OrderSymbol() = Symbol())ord++;

}

if(ord>0) return (0); //Abort! A Position For This Pair is Already Open

//the rest of my program code

}

Lynn
49
Lynn 2009.06.15 20:08  
Roger:

Very close. Try this:

int start()

{

int total,ord,i;

string symbol;

total = OrdersTotal();

for(i=0;i<total;i++)

{

OrderSelect(i,SELECT_BY_POS);

if(OrderSymbol() = Symbol())ord++;

}

if(ord>0) return (0); //Abort! A Position For This Pair is Already Open

//the rest of my program code

}

Thanks, Roger. I'll add this code and test it over the next few days. Appreciate your help.

Lynn
49
Lynn 2009.06.16 06:14  
7455 wrote >>

Thanks, Roger. I'll add this code and test it over the next few days. Appreciate your help.

Hey, Roger:

I had another question. Have you heard of client - side pending orders? Essentially, it allows you to hid your entry point, sl, and tp until the order is executed. Do you know the programming code to make standard pending orders client side pending orders? My objective is to be able to place a long and short pending order in the same account with the same currency (my broker no longer allows heding because of the new Anti-Heding Rule). Can you help?

Alexander
2441
Alexander 2009.06.16 08:03  
7455 wrote >>

Hey, Roger:

Can you help?

Actually, not, so sorry. When I had got that problem, I've changed my broker.

Lynn
49
Lynn 2009.06.16 19:32  
Roger:

Actually, not, so sorry. When I had got that problem, I've changed my broker.

Thanks. Roger. Can pick your brain again? What does the function "void" mean? I allowed another programmer to make some changes to my EA, and there is a line that says "void UpDateClosures" with some code follwing in brackets? Can you explain?

Alexander
2441
Alexander 2009.06.16 20:01  

Don't worry, nothing special. It means something matters inside this function (for example print smth) and you don't need to use its result in further.

Lynn
49
Lynn 2009.06.16 20:59  
Roger:

Don't worry, nothing special. It means something matters inside this function (for example print smth) and you don't need to use its result in further.

OK: So whatever is inside the function only occurs once and not every incoming tick? The reason I ask is because I have placed the code to abort placing another when there is already one on in the market, but the EA seems to ignore that and continues to places multiple market orders as long as the conditions are met. I am going to test some changes I made and see if I can get it to behave. If I can't in the next couple of days, can you take a look my code for this function and give me some advice?

Alexander
2441
Alexander 2009.06.16 21:03  
Sure.
12
To add comments, please log in or register