Avoid open Sell or Buy orders if there is already one openned

 
Hi, Mi EA works opening one Sell and one Buy orders at the same time, and when one of those are closed by TP or SL then it opens another Sell and Buy orders. What i want to do is avoid EA to open an order if same is already openned.
I attach the EA for you to help, im really new on this. THANKS!!!
Files:
 
xamr88: What i want
  1. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help
              urgent help.

    Or pay someone. Top of every page is the link Freelance.

  2. CustomSpread = (MarketInfo(Symbol(),MODE_SPREAD))  / PipFactor;
    MI(spread) returns it in points, not pips.

  3. TakeProfitPrice = PriceToOpen + (TakeProfit * Point * PipFactor);
    Your stops have StopLoss/Takeprofit Points minus spread for buys and that plus spread for sells.) Don't you want the same/specified amount for either direction?

    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer.
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)

  4.       TakeProfitPrice = NormalizeDouble(TakeProfitPrice,Digits);
    
    You used NormalizeDouble, It's use is usually wrong, as it is in your case.
    1. Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
                Double-precision floating-point format - Wikipedia, the free encyclopedia

      See also The == operand. - MQL4 programming forum

    2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

    3. SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
    4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum
    5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
    6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
                MT4:NormalizeDouble - General - MQL5 programming forum
                How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum

  5.    int total = OrdersTotal();
       if (total > 1)
    
    Unnecessary check, if total is zero, your for loop exits immediately.

  6. int start()
    Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference

Reason: