Set sell order with wrong sl and tp instead of each other

 

hi friends. I have wrote an expert . when I test it buy order was okay . buy EA set sell order takeprofit with input stoploss instead of input takeprofit and it sets stoploss with input input takeprofit instead of input stoploss !!! what I did wrong ?

Files:
testbaho.mq4  3 kb
 
  1. bohaira: it sets stoploss with input input takeprofit instead of input stoploss !!! what I did wrong ?

    That is almost unintelligible. If you are using mechanical translation, you must use simple language structure. And based on № 4, you are lying; you can't be opening orders with that code.

  2.     double stopLossPrice = price - StopLoss * Point;
        double takeProfitPrice = price + TakeProfit * Point;
        int ticket = OrderSend(_Symbol, OP_BUY, LotSize, price, 0, stopLossPrice, takeProfitPrice);

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close 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.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  3. // Expert Advisor start function
    int start()
    

    You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

    Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.

  4.     double buyOrderPrice = highestHigh - 2100 * Point;
        PlaceBuyOrder(buyOrderPrice);
    

    You can only buy/sell at the market. Never elsewhere.  You could place buystop/sellstops there, but 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.

  5. bohaira: I have wrote an expert 

    After you place an order, what happens on the next tick? Think!

 
William Roeder #:
  1. That is almost unintelligible. If you are using mechanical translation, you must use simple language structure. And based on № 4, you are lying; you can't be opening orders with that code.

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close 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.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  3. You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

    Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.

  4. You can only buy/sell at the market. Never elsewhere.  You could place buystop/sellstops there, but 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.

  5. After you place an order, what happens on the next tick? Think!

thank you .i am new in mql so I should take time for change it as you said. I will back with result .