This simple code isnt working

 
void OnStart()
  {
      while (1==1)
        {
            OrderSend(_Symbol,OP_BUY,0.001,Bid,0,0,Bid+0.09);
            OrderSend(_Symbol,OP_BUYSTOP,0.001,Bid+1.60,0,0,Bid+0.09);
            Sleep(10000);
        }
  }

Can anyone help me

 
            OrderSend(_Symbol,OP_BUY,0.001,Bid,0,0,Bid+0.09);
            OrderSend(_Symbol,OP_BUYSTOP,0.001,Bid+1.60,0,0,Bid+0.09);
  1. Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at 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 to 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 (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  3. You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers the value might be zero (the broker doesn't know). Use a minimum of two (2) PIPs.

    The checks a trading robot must pass before publication in the Market - MQL5 Articles 1 August 2016

  4. What is your broker's minimum lot size?
 
Jaisal Francis:

Can anyone help me

bool OrderSendResult;
                       
          OrderSendResult=OrderSend(_Symbol,OP_BUY,0.01,Ask,3,0,Bid+900*Point,"Buy Market Order",123,0,clrAliceBlue);
          
          OrderSendResult=OrderSend(_Symbol,OP_BUYSTOP,0.01,Bid+160*Point,3,0,Bid+900*Point,"Buy Stop Order",123,0,clrAliceBlue);
   
    ExpertRemove();
 

Mehmet Bastem:

bool OrderSendResult;
                       
          OrderSendResult=OrderSend(_Symbol,OP_BUY,0.01,Ask,3,0,Bid+900*Point,"Buy Market Order",123,0,clrAliceBlue);
          
          OrderSendResult=OrderSend(_Symbol,OP_BUYSTOP,0.01,Bid+160*Point,3,0,Bid+900*Point,"Buy Stop Order",123,0,clrAliceBlue);

Ideally any Buy orders' prices should be related to Ask, not Bid (see William's reply above yours).


OrderSend() returns, the ticket number, an int, not a bool. Please check the documentation.

If the compiler issues a warning don't ignore it, fix it.

OrderSend(); may give you the error that the return value of OrderSend should be checked. The minimum that should be done is to print the error if it fails.

You have already been told this.

https://www.mql5.com/en/forum/369489#comment_22388880

MQL4 Simple Open Order Script
MQL4 Simple Open Order Script
  • 2021.05.17
  • www.mql5.com
Just trying to place a buy market order. I am following this https://book.mql4.com/trading/ordersend documentation These are the errors I get...
 
Jaisal Francis:

Can anyone help me

void OnStart()
  {
      while (1==1)
        {
            OrderSend(_Symbol,OP_BUY,0.001,Bid,0,0,Bid+0.09);
            OrderSend(_Symbol,OP_BUYSTOP,0.001,Bid+1.60,0,0,Bid+0.09);
            Sleep(10000);
        }
  }

Your code will get stuck in a permanent loop.

Reason: