I was having some 130 errors, so I made two modifies, put alerts on them to see if it was the take profit or stop lose
ok, figured out the src thing, thought it was something in the meta trader program, not this board...
{ OrderSend(Symbol(),OP_BUY,1,Ask,5,0,0,"opening long one bar",12345,0,White); Alert("opening long"); Alert ("long Error: ",GetLastError()); if (OrdersTotal() > 0) { Alert ("selecting order to modify"); OrderSelect(OrderTicket(),SELECT_BY_POS); Alert ("selecting order to modify error: ",GetLastError()); OrderModify(OrderTicket(),OrderOpenPrice(),0,LTakeProfit,0,Blue); Alert ("order modified "); Alert ("modify order error: ",GetLastError()); } if (OrdersTotal() > 0) { Alert ("selecting order to modify 2"); OrderSelect(OrderTicket(),SELECT_BY_POS); Alert ("selecting ordre to modify error 2: ",GetLastError()); Alert ("modifying order 2"); OrderModify(OrderTicket(),OrderOpenPrice(),LStopLose,0,0,Blue); Alert ("order modified 2 "); Alert ("modify order error 2: ",GetLastError()); } }
First, use SRC button to format your source PLEASE!
Second. Wat can be it mean?
OrderSelect(OrderTicket(),SELECT_BY_POS);
Please read documentation. OrderTicket returns ticket number for the currently selected order.
Note: The order must be previously selected by the OrderSelect() function. I.e. you can use OrderTicket function only after OrderSelect!
Ok, you get ticket number (for example returned from OrderSend). For example this ticket number is 10002345. What do You mean using SELECT_BY_POS value?
In other words.
1. You must call OrderSelect function before using OrderTicket
2. In your case ticket number is useless because you use SELECT_BY_POS parameter
BTW your code is still unformatted just colorized
ok, so i look at this code from a sample EA that comes with the meta trader program...
how does the int cnt get assigned at the ticket number?
for(cnt=0;cnt>total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
also with this bit
with 'ticket' being defined as the OrderSend line, how does that get defined as the ordernumber?
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError());
Terminal keeps a list of orders:
If 5 open positions or pending orders are active the list looks like
A B C D E -- lets just give the orders names in this example
0 1 2 3 4 -- position number
OrdersTotal() is 5
for(index = OrdersTotal()-1; i >= 0; i--){
OrderSelect(index, SEL_BY_POSITON); --- first time through selects order #4,which is ticket E
int ticket = OrderTicket(); ---- returns the ticket number of ticket E -- the "selected" ticket
double price = OrderOpenPrice(); -- returns the opening price for ticket E -- the "selected" ticket
----
next time through the loop, ticket D at postion 3 will be selected, and so on
so phy,
if I were to say that any given open or pending order's OrderTicket is equal to its place in line, when using the SELECT_BY_POS, would that be correct?
now, if I were to use the SELECT_BY_TICKET option...
this is the code example given in the metaeditor for OrderSelect()
to give an order a ticket number like this, would I have to open the order, select it with the SELECT_BY_POS, then assign it this number?
if(OrderSelect(12470, SELECT_BY_TICKET)==true) { Print("order #12470 open price is ", OrderOpenPrice()); Print("order #12470 close price is ", OrderClosePrice()); } else Print("OrderSelect returned the error of ",GetLastError());

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
HI
I'm getting a error 4051 with this code when I use it with a OrderModify function, but only on the take profit part. the stoplose modifies correctly. Any ideas as to why?
double LStopLose = iOpen(NULL, 0,0) - (iATR(NULL, 0, 5, 1) * 2);
double SStopLose = iOpen(NULL, 0,0) + (iATR(NULL, 0, 5, 1) * 2);
double LTakeProfit = iOpen(NULL, 0,0) + (iATR(NULL, 0, 5, 1) * 3);
double STakeProfit = iOpen(NULL, 0,0) - (iATR( NULL, 0, 5, 1) * 3);
i've also used bid/ask in place of iOpen with no change in results
tia