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

 
Roger:
Sure.

Thanks, Roger. We'll be in touch one way or the other. Thanks again.

 
Roger:
Sure.

The code is working fine. Thanks again for your help. Can I impose one more time? I have an EA I am developing with a entry based on the first four candles of the trading day (candle 0:00 GMT - 4:00 GMT). What is the code I can use to determine the highest high and lowest low for that specific period each trading day? Essentially, I am trying to make a breakout tunnel. Thanks for your help again.

 

I tried for a LONG time on several brokers(demo accounts) to get an EA to open 2 ORDERS, 1 with a TP and one without ..and ONLY 2 orders at a time.

WHen conditions reverse, CLOSE any open positions and open 2 in opposite direction.

NEVER fully successful...as it opened 2 orders sometimes, then only 1 order, then sometimes 4 orders and I have no idea why.

I did try some of the code tips in this thread before.


Seems like there should be an easy way to have this work 100% of the time.


I basically had this to check for 0,1 or 2 orders open

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++;

 
spacechimp:

I tried for a LONG time on several brokers(demo accounts) to get an EA to open 2 ORDERS, 1 with a TP and one without ..and ONLY 2 orders at a time.

WHen conditions reverse, CLOSE any open positions and open 2 in opposite direction.

NEVER fully successful...as it opened 2 orders sometimes, then only 1 order, then sometimes 4 orders and I have no idea why.

I did try some of the code tips in this thread before.


Seems like there should be an easy way to have this work 100% of the time.


I basically had this to check for 0,1 or 2 orders open

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++;

Thanks, spacechimps. Can you also chime in on the determing the Highest and Lowest for a specified time period? I need to determine those prices for the period 0:00 GMT - 4:00 GMT each day. But it seems to be a moving target. Any thoughts?

 
Roger:

datetime newbar;

int start()

{

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

else newbar=Time[0];

//your program

}


I see the posts about checking for open positions BUT what if your position had a Take Profit and it closed but you do NOT want another position opened in the same direction?

I don't want another 'BUY' to execute if i had a buy open and it hit the TP. I want it to wait until the MA's cross down and open a SELL and repeat the whole thing over again.


THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 
7455:
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.


I use magicnumbers for this process, especially when trading multiple pairs simultaneously, each pair (or trade condition) uses a unique magicnumber. this code can be stripped down if you only use one condition and pair.


if (OrderExist(magicnumber) == false) ..test for trade conditions.. obviously if an open position exists the code never checks for a new trade possibiliy


if you use code to close/modify an order please note that the OrderExist function selects your order. and the code i use looks something like this

if (OrderExist(magicnumber)) ModifyTrade(); // function checks if trade needs modifying or closing


bool OrderExist(int m)
{
int i;
int total = OrdersTotal();
for (i=0;i<total;i++)
{
if(OrderSelect(i,SELECT_BY_POS)==false) continue;
if(OrderSelect(i,SELECT_BY_POS)==true)
{
if (OrderMagicNumber() == m) return(true);
}
}
return(false);
}

 

hai..please can someone fix this, i really newbie,and dont know how to fix this,when i compile is alwasy come up the errors....

please help me to fix this EA.

Files:
myfirstea.mq4  10 kb
 
gunawan200:

hai..please can someone fix this, i really newbie,and dont know how to fix this,when i compile is alwasy come up the errors....

please help me to fix this EA.

No . . .

//| This MQL is generated by Expert Advisor Builder                  |

EA Builder creates bad code


Please do not dredge up 4 year old threads unless you have a very good reason, you do not . . .


Thread start date - 2009.06.15

 
Lynn:

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


 

May God bless you massively in a special way. 

I was searching for a solution to an issue to which the code you have already wrote years ago (2009.06.15 19:00) about allowing the placing of one position instead of the normal multiple position EAs opens when it reachs the conditions. 

********************************************************** 
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 


****************************************************************** 
It has really impacted my trading massively to a positive returns. 

May God bless you wherever you are.

Reason: