- When you post code please use the CODE button (Alt-S)!
(For large amounts of code,
attach it.)
Please edit
your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Your code has no context, like using OrderOpenPrice(), OrderLots() but we can't know if you even selected an order.
- Your code sets CurrentPrice to Bid and then, in the loop, tests if Bid > CurrentPrice. That will never be true.
- Your code sets CurrentPrice to Bid and then, after the loop, tests if CurrentPrice-Bid > some nonzero value. That will never be true.
- Your code tries to close an order using Bid, but we can't no that the order can only be a buy. You can use OrderClosePrice() instead of Bid/Ask.
www.mql5.com/en/forum/158890/page3#comment_3812636 - Use the debugger or print out your variables, including _LastError and find out why. There are no mind readers here.
Thank you for your response!!! My EA works
right when I change that part of code to a
normal close. I know that the problem is in
the while loop. The program crashed in the
infinite loop for "if(Bid > CurrentPrice)" is
never happened, because "Bid" is not got
updated, Bid is always = to CurrentPrice.
I just do not know how to fix it. thx
right when I change that part of code to a
normal close. I know that the problem is in
the while loop. The program crashed in the
infinite loop for "if(Bid > CurrentPrice)" is
never happened, because "Bid" is not got
updated, Bid is always = to CurrentPrice.
I just do not know how to fix it. thx
fwan18210: I just do not know how to fix it. thx
Neither do we. Your code is totally bogus. Delete that code. Do not look at it again. Write down what you want the EA to do, in concrete terms, and then code that.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
while((Bid-OrderOpenPrice())/_Point > TakeP*3/4){
if(Bid > CurrentPrice){
CurrentPrice = Bid;
TakeP = (CurrentPrice-OrderOpenPrice())/_Point;
}
}
if((CurrentPrice-Bid)/_Point > TakeP/4){
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error + ",GetLastError());
}