buy order not place with USA30, but working with OilUsd

 

Hi, 


I have a very strange situation, the following code mt4 didn't place buy order with USA30, but did with oilusd or gold.

pls help... thanks


void OnTick()

{

if(OrdersTotal()<1)
         {
            int buyticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-100*_Point,Ask+100*_Point,NULL,0,  0, Green);  
         }
}
 
Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

//   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
//preferably also print the open price, TP, SL.
   int ticket=OrderSend(_Symbol,OP_BUY,0.1,Ask,20,0,0,NULL,12345,0,clrNONE);
   if(ticket==-1)
      {
      Print("OrderSend for Buy order failed with error code ",GetLastError());
      }
 
Keith Watford:
Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

Hi, Keith


Thanks for your reminder, and the sample of code


i will try it out.

 
zeeye: I have a very strange situation, the following code mt4 didn't place buy order with USA30, but did with oilusd or gold. pls help... thanks


You are hard-coding the Volume (Lots) and your Stops (S/L & T/P) irrespective of the symbol used. You are totally ignoring and not checking the symbol's contract specifications and trading conditions, such as:

  • Volume:
    • minimum size
    • maximum size
    • stepping size
    • margin requirements
  • Stops:
    • stops level
    • freeze level
    • spread
    • tick size
  • Trading sessions and other conditions
    • trading enabled/disabled
 
int buyticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-100*_Point,Ask+100*_Point,NULL,0,  0, Green);  

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).