I am great at copying, but not at scritting... It was part of another EA which was applying the case. here is a copy:
int l_Try = 0;
int l_MaxTry = 10;
switch (aCmd) {
case OP_BUY:
case OP_BUYLIMIT:
case OP_BUYSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++)
{
if(aCmd==OP_BUY) { RefreshRates(); aPrice=Ask; aPrice2=Bid; }
order_ticket = OrderSend(Symbol(), aCmd, aLots, aPrice, aSlipPage, 0, 0, aComment, aMagic, aExpiration, aColor);
if (order_ticket > 0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
Print("Error Code= ", err);
break;
}
}
break;
case OP_SELL:
case OP_SELLLIMIT:
case OP_SELLSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++) {
if(aCmd==OP_SELL) { RefreshRates(); aPrice=Bid; aPrice2=Ask; }
order_ticket = OrderSend(Symbol(), aCmd, aLots, aPrice, aSlipPage, 0, 0, aComment, aMagic, aExpiration, aColor);
if (order_ticket > 0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
Print("Error Code= ", err);
break;
}
}
}
Also my appology, my code was missing the OrderSymbol & OrderMagicNumber.
here is what I am working with.
void ChangeStopsAndTPs()
{
int total = OrdersTotal();
int l_Try = 0;
int l_MaxTry = 10;
for(int i=0;i<total;i++)
{
OrderSelect(i, SELECT_BY_POS,MODE_TRADES)
if (OrderSymbol() == Symbol() && OrderMagicNumber()==MagicNumber)
{
int type = OrderType();
double sl = StopLoss*Point;
double tp = TakeProfit*Point;
bool result = false;
switch(type)
{
case OP_BUY:
case OP_BUYLIMIT:
case OP_BUYSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++)
{
if(type==OP_BUY)
//modify opened long positions
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sl,OrderOpenPrice()+tp,0,NULL);
if (result>0) break;
}
break;
case OP_SELL:
case OP_SELLLIMIT:
case OP_SELLSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++) {
if(type==OP_SELL)
//modify opened short positions
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sl,OrderOpenPrice()-tp,0,NULL);
if (result>0) break;
}
if(result == false)
{
ReportError();
Sleep(3000);
}
}
}
}
return(0);
}
I_Need_Money: I grabed the idea from another EA, where it was opening orders based on the (switch(type) & CASE) and was trying to apply the same principle here. Yes, I could out line each type of order, but was thrying to get the same result with the (switch & case).
OK, carry on then . . . are you saying you have no idea of how to do it and you need someone to do it for you ?
Yes it would do . . . you removed the line of code I mentioned.
RaptorUK:
If I understand correctly your OP_BUY and OP_SELL Order are being modified but not your limit orders, isn't this causing the issue ?
and similar for the code that modifies the Buy orders.
if(type==OP_SELL) // <-- only executes the following code (the OrderModify() ) for a OP_SELL//modify opened short positions
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sl,OrderOpenPrice()-tp,0,NULL);
if (result>0) break;
For a Sell Limit (OP_SELLLIMIT) or Sell Stop (OP_SELLSTOP) the OrderModify() will not be called but the lines that follow will, result will be false even though no error has been generated.
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.
I am great at copying, but not at scritting... It was part of another EA which was applying the case. here is a copy:
Also my appology, my code was missing the OrderSymbol & OrderMagicNumber.
here is what I am working with.
I grabed the idea from another EA, where it was opening orders based on the (switch(type) & CASE) and was trying to apply the same principle here. Yes, I could out line each type of order, but was thrying to get the same result with the (switch & case).
RaptorUK:
OK, carry on then . . . are you saying you have no idea of how to do it and you need someone to do it for you ?
I don't know how, but this code is working now.
Thank you.
I don't know how, but this code is working now.
Yes it would do . . . you removed the line of code I mentioned.
If I understand correctly your OP_BUY and OP_SELL Order are being modified but not your limit orders, isn't this causing the issue ?
and similar for the code that modifies the Buy orders.
For a Sell Limit (OP_SELLLIMIT) or Sell Stop (OP_SELLSTOP) the OrderModify() will not be called but the lines that follow will, result will be false even though no error has been generated.
Yes it would do . . . you removed the line of code I mentioned.
Thank you,
Now I understand.