How to Limit Duplicate orders, based on price and symbol

 

Hello,

I developed an EA, it creates duplicate orders based on price and symbol. I am looking for advice on the best way to introduce a function "MaxDuplicateOrders" that will limit the amount of duplicate orders initiated. I ordered freelance work but the code is not successfully enabling me to input a value. I am sharing the code for this function, with hopes you can tell me how to get it working, thank you for reading this.

bool    check_max_orders(void)

        {

                // initialize the counter

                int total_orders = 0;

                

                // loop through the pool to count the orders

                for(int i = 0; i < OrdersTotal(); i ++)

                    {

                            if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){ continue; }

                            if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())

                               {

                                        if(OrderType() >= 2){ total_orders ++; }

                               }

                    }

                // check if the total orders exceed the max input

                return(total_orders >= MaxPendingOrders);

        }
 
Fareed Alston: that will limit the amount of duplicate orders initiated.

  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Before you open an order, see if there is already one within x PIPs. Counting does nothing for you.

  3. There is no need to create pending orders in code.

    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

      Don't worry about it unless you're scalping M1 or trading news.

    2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.

 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Before you open an order, see if there is already one within x PIPs. Counting does nothing for you.

  3. There is no need to create pending orders in code.

    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

      Don't worry about it unless you're scalping M1 or trading news.

    2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.

William Roeder, thank you for replying. 

1. To edit my post, I am having difficulty locating the "edit" option at the bottom right. What reads is "pocket" "complain" "reply" only.

2. The nature of this strategy involves pending orders, so I want to limit the amount of orders based on external int. or "MaxDuplicateOrders"

for example, the EA triggers 1000 pending orders with the same symbol and price, which is desired, I need to enable limiting these to 1-1000. Thank you for reading this.

 
  1. Fareed Alston #: 1. To edit my post, I am having difficulty locating the "edit" option at the bottom right. What reads is "pocket" "complain" "reply" only.

    You lost the option; only available for the first several days.-

  2. Fareed Alston #: 2. The nature of this strategy involves pending orders, 

    No strategy depends on pending orders. If you can do Buy Stop at pending price, then you can do if market >= price then open.

 
Fareed Alston #:

1. To edit my post, I am having difficulty locating the "edit" option at the bottom right. What reads is "pocket" "complain" "reply" only.

I have edited it for you.

 
Keith Watford #:

I have edited it for you.

Thank You, 


 
William Roeder #:
  1. You lost the option; only available for the first several days.-

  2. No strategy depends on pending orders. If you can do Buy Stop at pending price, then you can do if market >= price then open.

Thank you. In your opinion, Is the code appropriate for this function?

 
Fareed Alston #:

Thank you. In your opinion, Is the code appropriate for this function?

I can see nothing wrong with the code.

I will move this topic to the MQL4 section.

 
Keith Watford #:

I can see nothing wrong with the code.

I will move this topic to the MQL4 section.

I need the function to be an "maxduplicates" and as an external input, should simply change the title "MaxPendingOrders" and add external int for this?