Help coding delete pending after Buy or Sell Execute - page 2

 
FMIC:

Everyone is free to do as they see as best serving their trading (manual or with EA). We are both expressing our opinions based on facts that suit our point-of-view. If you follow the forum and look at all my posts, you will see that this is the first time that I have expressed my opinion about the disadvantages of using Pending Orders in EA's in general. However, I have not been the only one to do so. There is at least one other on this forum, that I know of, that has expressed a similar opinion, but I have never discussed it with him.

Outside, of this forum, I know of a few others that share the same point-of-view as myself, but the vast majority of coders are in favour of using Pending Orders in EA's. Even though, we are a minority, that does not automatically "brand" us as incorrect. As an example of this "minority" vs "majority", is the fact that most of the world drive on the right-hand side of the road. However taking into account that most of the population is "right-handed" (and "right-eyed"), the most appropriate would be to drive on the left-hand side of the road. Yet, only a few countries do that (they are in the minority).

You can of course apply this rule about pendings if it suit your requirements and you are happy with it.

The problem I have is you are claiming that your rule, and so your requirements, are universal and applicable to everyone. That's not the case. Explain the advantages and the inconvenients if you want, but let's people think by themself and choose if they will use pendings or not in their EA.

To all : There is nothing bad to use pendings in your EA if it suits your needs and you are happy with it, there is nothing bad to use NormalizeDouble() is it suits your needs and you are happy with it, there is nothing bad to use an EA builder if it suits your needs and you are happy with it.

 
angevoyageur:

You can of course apply this rule about pendings if it suit your requirements and you are happy with it.

The problem I have is you are claiming that your rule, and so your requirements, are universal and applicable to everyone. That's not the case. Explain the advantages and the inconvenients if you want, but let's people think by themself and choose if they will use pendings or not in their EA.

To all : There is nothing bad to use pendings in your EA if it suits your needs and you are happy with it, there is nothing bad to use NormalizeDouble() is it suits your needs and you are happy with it, there is nothing bad to use an EA builder if it suits your needs and you are happy with it.

As a moderator, you have a higher ethical obligation to set the example. You also hold an "absolute" power over us normal users, as you have the ability to remove a thread or post, if it does not agree with you.

So hopefully you will not delete this, but independently of our diverging opinions on pending orders, I don't think it was very wise or ethical of you to encourage users into following bad habits (such as "Code Builders" and "NormalizeDouble").

These are my last comments on the subject, because these posts are heading towards a flame-war which does not help the OP nor the thread in any way and will only cause even more confusion.

So, I yield the floor to you! You have the "power", I do not! Thank you and Good bye!

 
FMIC:

As a moderator, you have a higher ethical obligation to set the example. You also hold an "absolute" power over us normal users, as you have the ability to remove a thread or post, if it does not agree with you.

So hopefully you will not delete this, but independently of our diverging opinions on pending orders, I don't think it was very wise or ethical of you to encourage users into following bad habits (such as "Code Builders" and "NormalizeDouble").

These are my last comments on the subject, because these posts are heading towards a flame-war which does not help the OP nor the thread in any way and will only cause even more confusion.

So, I yield the floor to you! You have the "power", I do not! Thank you and Good bye!

This discussion has nothing to do with "power", why are you coming with that ? I never removed any message simply because I don't agree with it...some could be offended by your suggestion :-).

I don't encourage anyone to do anything except thinking by themself instead of following blindly any advice (including mine).

 
Hello everyone, I would like a little help with my EA, I am using this code to close open operations and delete pending orders when a certain profit is reached, it is working perfectly.

However, I need a function to delete pending orders if there is no open transaction, since I use the orders as a way to equalize the outstanding balance.

Was it possible and how could I accomplish this?

Thank you for the attention and help of those who can.

//+------------------------------------------------------------------------+
void CloseAllinProfit()
  {
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      OrderSelect(i,SELECT_BY_POS);
      bool result=false;
      if( OrderType() == OP_BUY && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
      if( OrderType() == OP_SELL && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
         if( OrderType()== OP_BUYSTOP)  result = OrderDelete( OrderTicket() );
         if( OrderType()== OP_SELLSTOP)  result = OrderDelete( OrderTicket() );
         if( OrderType()== OP_BUYLIMIT)  result = OrderDelete( OrderTicket() );
         if( OrderType()== OP_SELLLIMIT)  result = OrderDelete( OrderTicket() );
      
      if(UseAlerts) PlaySound("alert.wav");
     }
   return;
  }
//+------------------------------------------------------------------+


So I understand, when calling OrdersTotal it computes all orders, even pending, is there a way to check only open operations?

 I'm a beginner in development and I'm learning a lot, thank you if you can help me. 

 
Fernando Carreiro:

Why do most users insist on using Pending Orders in EA's. Pending Orders are for manual trades executed by humans which cannot be in front of the screen 24/5.

EAs on the other hand can and do work 24/5, so use Market Orders instead and you will not have to worry about updating or closing opposite pending orders.

In your EA, just keep track of 2 variables for your buy and sell prices and when the bid price crosses those thresholds, open a Market Order and clear the two variables! And that is all there is to it!

The added advantage is that you can track and compensate for spread before opening a Market Order while you cannot do that so easily with Pending Orders.

You deserve a medal, I've been racking my brains all day for a solution to this
 
  1. siqalexcg: I need a function to delete pending orders if there is no open transaction, since I use the orders as a way to equalize the outstanding balance.
    1. Go through your OrderSelect loop and count open transactions (write a function.) If zero Go through your OrderSelect loop and delete pending orders (write a function.) Two functions and one if(c()==0) d(); statement. What's the problem?
                Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
    2. You do understand that you can't start your sequence with pending orders?

  2. Fernando Carreiro: Why do most users insist on using Pending Orders in EA's. Pending Orders are for manual trades executed by humans which cannot be in front of the screen 24/5. EAs on the other hand can and do work 24/5, so use Market Orders instead and you will not have to worry about updating or closing opposite pending orders.
    Exactly. Don't code what the Human would do. Totally unnecessary.

  3. John Pringle: You deserve a medal, I've been racking my brains all day for a solution to this
    Don't resurrect (three year) old threads without a very good reason. A lot has changed since Build 600 and Higher. 2014.02.03
Reason: