EA not placing trades as I intend

 

I'm developing an EA to place trades at certain points relative to an indicator. It places the trades only sometimes at those certain points. I have the EA setup to trade according to certain buffers in an indicator. According to the data window in the indicator those dots only appear when they have values attached to them. Here is my code relative to my problem. I don't know why it is only trading at certain dots and not others. 

void OnTick() {


//--- Execute strategy



double buysignal  = signalvalue(0,0); // Buffer (0 is buy signal, 1 is sell signal, 2 is buy line, 3 is sell line) and candle 

double sellsignal = signalvalue(1,0);

if (buysignal != EMPTY_VALUE)  { if (OrderSend(Symbol(), OP_BUY, initiallots, Ask, 0, Ask-sl, Ask+tp, NULL, magicnumber, 0, clrGold) > -1) Print ("placed buy order");   }

    if (sellsignal != EMPTY_VALUE) { if (OrderSend(Symbol(), OP_SELL, initiallots, Bid, 0, Bid+sl, Bid-tp, NULL, magicnumber, 0, clrGold) > -1) Print ("placed sell order"); }

                     }

//--- Function for signal value



double signalvalue(int buffer, int bar) {



   double value = iCustom(Symbol(), Period(), indicatorname, information, period, buffer, bar);

   

      if (value==0) value = EMPTY_VALUE; // Just in case third party creator uses empty value instead of 0

      return value;                                }

 
Did you ensure that indicator is not repainting the dots? 
 
  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. if (OrderSend(Symbol(), OP_BUY, initiallots, Ask, 0, Ask-sl, Ask+tp, NULL, magicnumber, 0, clrGold) > -1) Print ("placed buy order");   }

    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. There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file. We have no idea what sl and tp are. 

    1. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies. 
    2. PIP, Point, or Tick are all different in general.
                What is a TICK? - MQL4 programming forum (2014)

 
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. 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. There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file. We have no idea what sl and tp are. 

    1. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies. 
    2. PIP, Point, or Tick are all different in general.
                What is a TICK? - MQL4 programming forum (2014

      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. 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. There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file. We have no idea what sl and tp are. 

        1. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies. 
        2. PIP, Point, or Tick are all different in general.
                    What is a TICK? - MQL4 programming forum (2014)


Thanks for the tip with the spread. This is just on a paper account for now as I just want to get this EA working properly first.