MQL4 - automated forex trading   /  

Forum

EA to convert limit order(s) to market

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

avatar
5
seattlerust 2011.01.25 20:37 

I occasionally have a number of limit buy or sell orders in place (multiple lots so I can scale out) that bog down just before reaching execution level and I would like to execute all of them at one time at market. Is there an EA available that does this?

Thanks,

SR

How to Enrich Information You Present? Use Videos!

How to Enrich Information You Present? Use Videos!

How to get more information over to the viewers? There is a very simple method to prepare a video to be published on the MQL4.community website using new technologies.


avatar
1675
qjol 2011.01.25 22:48 

not AFAIK simple to do this

1) for ()  // loop all the orders


2) OrderSelect() // select_tham_one_by_one


3) if ()  // find if it's the order u loocking for by OrderType (& or whatever)


4) OrderDelete() // this order


5) OrderSend()  // a new one at market price


6) mission accomplished


7) It was so hard ??


avatar
5
seattlerust 2011.01.25 23:23 
qjol:

not AFAIK simple to do this


Hard? No, of course not, if you are an experienced coder in this language and are current. My coding days were over many years ago and they spanned from Fortran through VB. My beard is very grey and we won't speak of the hair that used to be elsewhere; so I do not have the interest to learn new things.

But thanks for this. I will try to make use of it.

SR


avatar
1131
sxTed 2011.01.26 01:26 

seattlerust, please try the following untested code:


double dPP, dSL, dTP;
for (int i=OrdersTotal()-1; i>=0; i--) {
   if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
      if (OrderType() >= OP_BUYLIMIT && OrderType() <= OP_SELLSTOP) {
         if (OrderType()%2 == OP_BUY) dPP = MarketInfo(OrderSymbol(),MODE_ASK);
         else                         dPP = MarketInfo(OrderSymbol(),MODE_BID);
         dSL = OrderStopLoss();
         dTP = OrderTakeProfit();
         if (dSL!=0) dSL=dPP-(OrderOpenPrice()-dSL);
         if (dTP!=0) dTP=dPP+(dTP-OrderOpendPrice());
         if (OrderSend(OrderSymbol(),OrderType()%2,OrderLots(),dPP,5,dSL,dTP,OrderComment(),OrderMagicNumber()) == false) {
            Print("OrderTicket ",OrderTicket()," modify error ",GetLastError());
            return;
         }
         if (OrderDelete(OrderTicket()) == false) {
            Print("OrderTicket ",OrderTicket()," delete error ",GetLastError());
            return;
         }
      }
   }
}

avatar
5
seattlerust 2011.02.01 07:42 
sxTed:

seattlerust, please try the following untested code:



Thank you, sxTed

I'll give it a try.

SR

Back to topics list  

To add comments, please log in or register