MQL4 - automated forex trading   /  

Forum

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

Back to topics list  | 1 2 To post a new topic, please log in or register

avatar
12
7455 2009.06.16 23:14 
Roger wrote >>
Sure.

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


avatar
12
7455 2009.06.29 16:48 
Roger wrote >>
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.


avatar
42
spacechimp 2009.06.29 20:25 

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


avatar
12
7455 2009.06.29 22:17 
spacechimp wrote >>

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?


avatar
42
spacechimp 2009.07.02 21:19 
Roger wrote >>

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


avatar
8
bredin 2009.07.03 11:05 
7455 wrote >>
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);
}

Back to topics list   | 1 2  

To add comments, please log in or register