There is a problem about "if() OrderSend()".

Fa Cao
1141
Fa Cao  

The code is as below:

if(Close[0]>=1.3096)
OrderSend(Symbol(),OP_BUYSTOP,2,Bid,3,Bid-7*Point,0,0,0,0,Red);
if(Close[0]<=1.3089)
OrderSend(Symbol(),OP_SELLSTOP,0.5,Ask,3,Ask-5*Point,Ask+2*Point,0,0,0,Green);

 

I want made EA which will send new order to  buy "2" lots when the price reaches 1.3096 or sell "0.5" lots when the price reaches 1.3089 and also set the "stoploss" and "takeprofit".

But I find this EA never works after I have execute it when the price reaches 1.3096 or 1.3089, why? is there some problem about it?

In addition, when I attach a correct EA to the chart and set "EA" open, and then I close MT4 sofeware; now the correct EA still work?

Thank you. 

Ubzen
5300
Ubzen  

 What error message do you get? Error_Codes.  The_Book.

NoTomatoes
40
NoTomatoes  

Dear vx,

Close[0] is always the Bid portion of the price. Are you sure, that this is what you want?

What is the value of GetLastError() after the failure? What's in your logs regarding this EA?

Fa Cao
1141
Fa Cao  
NoTomatoes:

Dear vx,

Close[0] is always the Bid portion of the price. Are you sure, that this is what you want?

What is the value of GetLastError() after the failure? What's in your logs regarding this EA?


Dear NoTomatoes:

Thank you for your reply.

1. Close[0] here, I just want to  send the order once the price reaches 1.3096.maybe i can get this by the code"OrderSend(Symbol(),OP_BUYSTOP,0.5,1.3096,3,1.3096-7*Point,0,"OP_BUYSTOP",1,0,Green)",yes?

2.  GetLastError() returns 129 which means "invalid price".

Fa Cao
1141
Fa Cao  
ubzen:

 What error message do you get? Error_Codes.  The_Book.



Thank you for your guide.

Error message is 129 which means "Invalid price". 

Ubzen
5300
Ubzen  
vx0532:



Thank you for your guide.

Error message is 129 which means "Invalid price". 

You cannot place pending orders at current prices.
Simon Gniadkowski
17393
Simon Gniadkowski  
ubzen:
You cannot place pending orders at current prices.

You can't place a BUYSTOP at Bid unless the Spread is 0.0 but you can place a BUYSTOP at Ask if your STOPLEVEL is 0.0

 

To vx0532  please read, understand and absorb this:   Requirements and Limitations in Making Trades

William Roeder
25092
William Roeder  
vx0532:

The code is as below:

if(Close[0]>=1.3096)
OrderSend(Symbol(),OP_BUYSTOP,2,Bid,3,Bid-7*Point,0,0,0,0,Red);
if(Close[0]<=1.3089)
OrderSend(Symbol(),OP_SELLSTOP,0.5,Ask,3,Ask-5*Point,Ask+2*Point,0,0,0,Green);
 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. What are Function return values ? How do I use them ? - MQL4 forum
  3. Not adjusting for 4/5 digit brokers, not adjusting for ECN brokers
  4. Not checking trade limits
  5. Wrong number of arguments in the BuyStop
  6. Using market price for Stops/limits (See #4)
Fa Cao
1141
Fa Cao  
Thanks alll