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

 
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.
 

datetime newbar;

int start()

{

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

else newbar=Time[0];

//your program

}

 
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())?


 

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

}

 
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.

 
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?

 
7455 wrote >>

Hey, Roger:

Can you help?

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

 
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?

 

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.

 
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?

 
Sure.
Reason: