Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello,
I am new to the world of expert advisors. For last 2 days, I am working on an EA, and something doesn't seem to be right.
I open a BUYSTOP or SELLSTOP order using following code.
SetOrder(OP_BUYSTOP,EntryPrice,0,0); // Entry price is 10 pips above close of last BUY order
SetOrder(OP_SELLSTOP,EntryPrice,0,0); // Entry price is 10 pips below close of last SELL order.
void SetOrder(int op, double pp, double ldStop, double ldTake)
{
string lsComm = "Krrish.mq4";
if (op == OP_BUYSTOP)
ldStop = pp - 100* Point;
if (op == OP_SELLSTOP)
ldStop = pp + 100 * Point;
OrderSend(Symbol(),op,Lots,pp,Slippage,ldStop,ldTake,lsComm,MAGIC,0,Blue);
int err = GetLastError();
if(err != ERR_NO_ERROR)
Print("Error in Sending Order: ",ErrorDescription(err));
}
Now, as the price moves down, I want to modify BUYSTOP order. As the price moves up, I want to modify my SELLSTOP order.
//check open order type.
case OP_BUYSTOP:
Print("Modifying OP_BUYSTOP order", OrderTicket());
if (Bid < OrderOpenPrice() - 10 * Point) // if BID is moving down, revise BUYSTOP order. New Entry price should be 10 pips above BID.
{
EntryPrice = Bid + 10 * Point;
OrderModify(OrderTicket(),EntryPrice,OrderStopLoss(),OrderTakeProfit(),0,Yellow);
}
break;
case OP_SELLSTOP:
Print("Modifying OP_SELLSTOP order", OrderTicket());
if (Ask > OrderOpenPrice() + 10 * Point) // if ASK is moving up, revise SELLSTOP order. New Entry Price should be 10 pips below ASK.
{
EntryPrice = Ask - 10 * Point;
OrderModify(OrderTicket(),EntryPrice,OrderStopLoss(),OrderTakeProfit(),0,Yellow);
}
break;
Both these Modify orders give 130 error code. (invalid stops). When I modify orders, I don't want to specify any stoploss or takeprofit.
Your help is deeply appreciated.
Thanks,
Jay.
jay.p.narayan@gmail.com