There was a small glitch in the OrderSelect function. I typed 1 instead of i while trying to fix it. Even with i, the problem still remains.
int tp = 20*Point;
to
double tp = 20*Point;
Now I'm gettting error 4109 Trade is not Allowed.
The script finds the correct ticket, so that's a big improvement. Any idea why it wouldn't allow a 20 pip sl/tp to be added?
ERR_TRADE_NOT_ALLOWED | 4109 | Trade is not allowed. Enable checkbox "Allow live trading" in the expert properties. |
int tp = 20*Point;
to
double tp = 20*Point;
May someone please take a look at my code.
Trying to implement the same code but trying to modify stop & limit orders as well. The code works with OP_Buy & OP_Sell, but not with any other orders.
Thank you.
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); 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); }
May someone please take a look at my code.
Trying to implement the same code but trying to modify stop & limit orders as well. The code works with OP_Buy & OP_Sell, but not with any other orders.
In your code you need to make sure you comply with the requirements in this document: Requirements and Limitations in Making Trades
Why aren't you printing the error if your OrderModify() fails ? don't you want to know what the error is ? Read this: What are Function return values ? How do I use them ?
In your code you need to make sure you comply with the requirements in this document: Requirements and Limitations in Making Trades
Why aren't you printing the error if your OrderModify() fails ? don't you want to know what the error is ? Read this: What are Function return values ? How do I use them ?
Thank you for your input.
If there is an error it calls:
ReportError();
Which is working fine, I have no problem there. Errors are being printed, alert, and notified.
The EA is opening all the orders with not problem. I have the original version (listed above) of the "ChangeStopsAndTPs()" working and able to modify all OP_BUY & OP_SELL, but it dosen't modify STOP or LIMIT orders. I was trying to also modify STOP & LIMIT orders not just open.
Thank you.
Thank you for your input.
If there is an error it calls:
Which is working fine, I have no problem there. Errors are being printed, alert, and notified.
The EA is opening all the orders with not problem. I have the original version (listed above) of the "ChangeStopsAndTPs()" working and able to modify all OP_BUY & OP_SELL, but it dosen't modify STOP or LIMIT orders. I was trying to also modify STOP & LIMIT orders not just open.
Thank you.
Sorry, read in haste repent at leisure :-)
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 ?
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;
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.
Sorry, read in haste repent at leisure :-)
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.
bool result = false; : if (result>0) break; <====== What does this if test

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Purpose: Add a set stop loss and take profit to all open trades (regardless of currency pair)
Problem:
This script generates error 4105 when placed on a chart. Invalid ticket for OrderModify function. My demo account currently has an open trade with no stops or limits attached.
What causes the invalid ticket selection?