Hi,
I have seen the log file and made some code to try to discover whats the problem and I found out that this appened after some changes in the ModifyOrders function that I show on previous comment. Before changes I was interested in manage just one open order of each type but I think that code it wasn't very reliable... Now I want to work with several orders.
The previous code was:
void ModifyOrders(string sTypeOrder) { int CountOrders = 0, IndexSave = 0, OrderTypeNum = 0; //Converte o tipo de ordem if(!StringCompare(sTypeOrder, "OP_BUY",false)) OrderTypeNum = 0; else if(sTypeOrder == "OP_SELL") OrderTypeNum = 1; else if(sTypeOrder == "OP_BUYLIMIT") OrderTypeNum = 2; else if(sTypeOrder == "OP_SELLLIMIT") OrderTypeNum = 3; else if(sTypeOrder == "OP_BUYSTOP") OrderTypeNum = 4; else if(sTypeOrder == "OP_SELLSTOP") OrderTypeNum = 5; else OrderTypeNum = -1; Print("*** Função Modificação de ordens ***: Order Number = ", OrderTypeNum, " TypeOrder: ", sTypeOrder); for(PositionIndex = OrdersTotal()-1; PositionIndex >= 0; PositionIndex --) // <-- for loop to loop through all Orders . . COUNT DOWN TO ZERO ! { if(!OrderSelect(PositionIndex,SELECT_BY_POS,MODE_TRADES)) continue; // <-- if the OrderSelect fails advance the loop to the next PositionIndex { if( OrderMagicNumber() == iMagicNum && OrderSymbol() == Symbol() && (OrderType() == OrderTypeNum)) { CountOrders = CountOrders + 1; IndexSave = PositionIndex; Print("Posição do índice de ordens: ", IndexSave, "; Nº de ordens do mesmo tipo: ", CountOrders); } } } if (CountOrders == 1) { if(OrderSelect(IndexSave,SELECT_BY_POS,MODE_TRADES)) { Print("Ordem seleccionada - Ticket Correto"); ticket = OrderTicket(); if (sTypeOrder == "OP_BUY" || sTypeOrder == "OP_SELL") // No caso das ordens abertas apenas alteramos o stop loss { PriceValue = OrderClosePrice(); TakeProfitValue = OrderProfit(); } Print("Dados para modificação de ordens: Price: ", PriceValue, " SL: ", StopLossValue, " TP: ", TakeProfitValue); if(OrderModify(ticket,PriceValue,StopLossValue,TakeProfitValue,0,Green)) { Print("Ordem de modificação bem sucedida."); } else Print("Erro: Ordem de modificação mal executada!!"); } else Print("Ordem mal seleccionada - Ticket incorreto"); } if (CountOrders >= 2) Print("#ERRO: Nº de ordens ", sTypeOrder, " superior a 1: ",CountOrders," ordens! "); }
I don't understand what was the change the I made to make such error modify orders... For the same order I have two results:
Previous Code results
0 08:14:17 2006.03.09 00:00 teste3_Fractal_v19-08-2016 EURUSD,Daily: *** Função Modificação de ordens ***: Order Number = 4 TypeOrder: OP_BUYSTOP
0 08:14:17 2006.03.09 00:00 teste3_Fractal_v19-08-2016 EURUSD,Daily: Index Order: 0; Nº de ordens do mesmo tipo: 1
0 08:14:17 2006.03.09 00:00 teste3_Fractal_v19-08-2016 EURUSD,Daily: Ordem seleccionada - Ticket Correto
0 08:14:17 2006.03.09 00:00 teste3_Fractal_v19-08-2016 EURUSD,Daily: Data for order modify: Price: 1.2125 SL: 1.1795 TP: 1.278499999999999
2 08:14:17 2006.03.09 00:00 teste3_Fractal_v19-08-2016 EURUSD,Daily: modify #2 buy stop 0.10 EURUSD at 1.21250 sl: 1.17950 tp: 1.27850 ok
0 08:14:17 2006.03.09 00:00 teste3_Fractal_v19-08-2016 EURUSD,Daily: Ordem de modificação bem sucedida.
Actual Code results (1st comment)
0 07:22:19 2006.03.09 00:00 teste3_Fractal_v20-08-2016 EURUSD,Daily: *** Função Modificação de ordens ***: Order Number = 4 TypeOrder: OP_BUYSTOP
0 07:22:19 2006.03.09 00:00 teste3_Fractal_v20-08-2016 EURUSD,Daily: Ordem seleccionada do tipo pretendido. Ticket: 2 Tipo:4 Price:1.2354 SL:1.201 TP:1.3042
0 07:22:19 2006.03.09 00:00 teste3_Fractal_v20-08-2016 EURUSD,Daily: Data for order modify: Price: 1.2125 SL: 1.1795 TP: 1.278499999999999
3 07:22:19 2006.03.09 00:00 teste3_Fractal_v20-08-2016 EURUSD,Daily: OrderModify error 130
0 07:22:19 2006.03.09 00:00 teste3_Fractal_v20-08-2016 EURUSD,Daily: Erro: Ordem de modificação mal executada!!130
0 07:22:19 2006.03.09 00:00 teste3_Fractal_v20-08-2016 EURUSD,Daily: Index Order: 0; Nº de ordens do mesmo tipo: 1
Why is that for the same values, same index order, same order it gives different results?
- 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 making an EA to work with fractals and each time that appears an upper/lower fractal and its > or < than EMA it should generate new orders or modify the existing ones and in open orders it should change only the SL.
At beginning it puts the buy stop order, change it and after some candles it open the position. When starts to have several orders of the same type it gives some errors when modify orders... I have made some history orders:
After 1st BUY_STOP order closes it changes the index:
At first I was thinking that t was an error on modify order, because it gives Error 130, but I had this working before changing the modify order function... And I think that SL it OK for the order but i maybe selecting the wrong order...
Now I think that the problem is in the manage/modify function but I'm not seeing where it is!!! I don't understand how index order is working for several orders. I need that every time it appears the initial condition it manages the modify orders of the same type. Example: when appears the low fractal in uptrend i want to change ALL BUY or BUY STOP orders to change the SL value.
I specified the OrderType in the ModifyOrders function string:
If it is BUY or SELL I only change the SL, on the pending orders I change all value that come from OnTick()...
Can you help me finding the problem?
One more question: when we modify open orders the change doesn't appear on the graphic like BUYSTOP or SELLSTOP order?
The mql4 goes in attachment. Thanks in advance.