Multiple OrderSend - page 2

 
doshur:

just to check

OrderSend(Symbol(), OP_BUY, LotSize(Risk), Ask, 3, Ask - StopLoss, 0, "B", 100, 0, Blue);

my slippage is 3 points. but does it work for a 5 decimal broker like alpari?

I've always assumed that the slippage is specified in the broker's terms; i.e. 3 is 0.00003 for Alpari. But the slippage seems unlikely to be the problem, in itself, if you say that one of your orders is succeeding and the other is failing, and you're specifying the same permitted slippage on each order. The problem seems more likely to be the price.

 
doshur wrote >>
i got the error 138 even using my ToTrade function

brokers dont like you to send orders one after another with no delay; so sometimes ppl code a delay inbetween orders sending

err 138 is a requote, so just detect this error and do a resend -> i prefer this than to introduce a delay OR do both

do a search here, this has been tackled many times eg 'Requote 138 - how to solve?'

 

thanks for all the help but im really at my wits end

can check if theres any work around this strategy?

1st order is set will low takeprofit

2nd order will trail the market

 
doshur:

thanks for all the help but im really at my wits end

can check if theres any work around this strategy?

1st order is set will low takeprofit

2nd order will trail the market

incidentally, if u are using a US-based broker, the new NFA rule 2-43 will affect this strategy; the rule says first in first out; so u cannot close yr second order without closing yr first order. i think a lot of EA will be affected by this new rule.

read this https://forum.mql4.com/22047

 
ronaldosim:

incidentally, if u are using a US-based broker, the new NFA rule 2-43 will affect this strategy; the rule says first in first out; so u cannot close yr second order without closing yr first order. i think a lot of EA will be affected by this new rule.

read this https://forum.mql4.com/22047


that is for hedging of the same currency right?


anyway im testing on Alpari - UK

recoding to partial close rather than having 2 buy/sell orders at the same time


cheers

 
doshur wrote >>

that is for hedging of the same currency right?

anyway im testing on Alpari - UK

recoding to partial close rather than having 2 buy/sell orders at the same time

cheers

Hi

I don't want to drive you crazy but I am doing exactly what you want to do. Two differences, I use NormalizeDouble, I don't think that that is your problem, since if it accepts the first order it should accept the second. Also my orders are Buy_Stops or Sell_Stops.

Again I don't see why that would be an issue.

The code works in tester and live demo, have not tried it on a real account yet. Time stamps indicate virtually identical opening time.

Also FWIW I'm testing on FXDD, just in case this is a specific broker issue.

HTH

Keith

 
doshur:

Hi all,


I tried to code 2 ordersend together but only one will be sent


OrderSend(Symbol(), OP_BUY, LotSize(Risk), Ask, 3, Ask - StopLoss, 0, "B", 100, 0, Blue);

OrderSend(Symbol(), OP_BUY, LotSize(Risk), Ask, 3, Ask - StopLoss, Ask + TakeProfit, "B", 200, 0, Blue);


Is there any work ard because my EA will trailing the first one and the second will be based on takeprofit close.


Thanks

you need a function that will check if an order was processed. You run ordersend, then run this check function. The check function will review the live orders, if the order was not opened, send another ordersend function. If the order was opened, then goto to the 2nd ordersend function.


Ordersend(#1); checkorders();

Ordersend(#2); checkorders();

            RefreshRates();
            ticket1=OrderSend(C1,OP_BUY,lot,MarketInfo(C1,MODE_ASK),3,0,0,"Hedge"+C1,MagicNumber1);
            if (ticket1<0){verifyorder(C1,MagicNumber1,"LONG");}Sleep(5000);

            //LONG USDCHF
            RefreshRates();
            ticket2=OrderSend(C2,OP_BUY,lot,MarketInfo(C2,MODE_ASK),3,0,0,"Hedge"+C2,MagicNumber2);
            if (ticket2<0){verifyorder(C2,MagicNumber2,"LONG");}Sleep(5000); 


void verifyorder(string symbol, int MN, string direction)//function which is used to verify that the orders have been placed
{
Sleep(1000);
int ord_cnt=OrdersTotal();
for (int start=0;start<=ord_cnt;start++)   
   {
      OrderSelect(start, SELECT_BY_POS, MODE_TRADES);
      if(OrderMagicNumber()==MN)
         {return;}
   }
if(direction=="LONG"){OrderSend(symbol,OP_BUY,lot,MarketInfo(symbol,MODE_ASK),3,0,0,"Hedge"+symbol,MN);}
if(direction=="SHORT"){OrderSend(symbol,OP_SELL,lot,MarketInfo(symbol,MODE_BID),3,0,0,"Hedge"+symbol,MN);}   
return;
}


I had the same issues before with hedging, and when i implemented this checkorders(), multiple orders open without any problems

 
doshur wrote >>

that is for hedging of the same currency right?

anyway im testing on Alpari - UK

recoding to partial close rather than having 2 buy/sell orders at the same time

cheers

yup, doing a partial close will solve this for a while; but u still have a problem - getting yr orders to be sent reliably be it one or two or more.

u faced this when u try to send two orders one after the other; u may jolly well encounter even with one order; so u need to solve this sooner or later

 

Thanks c0d3

That's a good function

Aside to ronaldosim

I think sending 1 order is much better and less error than 2 and since im still getting error 138 even though I have used refresh rates

Let me test out my partial close

This strategy works wonders when im testing it.

 
doshur wrote >>

Hi all,

I tried to code 2 ordersend together but only one will be sent

OrderSend(Symbol(), OP_BUY, LotSize(Risk), Ask, 3, Ask - StopLoss, 0, "B", 100, 0, Blue);

OrderSend(Symbol(), OP_BUY, LotSize(Risk), Ask, 3, Ask - StopLoss, Ask + TakeProfit, "B", 200, 0, Blue);

Is there any work ard because my EA will trailing the first one and the second will be based on takeprofit close.

Thanks

double Ppoint = Point;

if (Digits == 5 || Digits == 3) Pponit = 10.0 * Point;

OrderSend(Symbol(), OP_BUY, LotSize(Risk), Ask, 3, Ask - StopLoss*Ppoint, 0, "B", 100, 0, Blue);

if (GetLastError()>0) A lert("Order ", OrderTicket(), " failed to Open. Error:", GetLastError() ) Sleep(3000);

OrderSend(Symbol(), OP_BUY, LotSize(Risk), Ask, 3, Ask - StopLoss*Ppoint, Ask + TakeProfit*Ppoint, "B", 200, 0, Blue);