for (int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol() == symbol && OrderMagicNumber() == magicnumber && OrderType() == ordertype) { RefreshRates(); int TK = OrderTicket(); double TP = OrderTakeProfit(); double SL = OrderStopLoss(); double OP = OrderOpenPrice(); double newtakeprofit = 0; double medianprice = GetMedianPrice(ordertype,magicnumber,symbol);//my median price color cor; bool modify = false; //flag to change tp switch(OrderType())
You are inside a orderSelect loop. But then GetMedianPrice does a orderSelect loop (two including GetOrdersTotal,) so switch( orderType() ) no longer refers to the same order as TKif(modify && OrderTakeProfit() != newtakeprofit){ //bug OrderModify(TK,OP,SL,newtakeprofit,0,cor);
OrderTakeProfit can refer to any order here, definitely not TKdouble GetMedianPrice(int ordertype, int magicnumber, string symbol){ int total = GetOrdersTotal(ordertype,magicnumber,symbol); double medianprice = 0; double count = 0; int index = 0; if(total<1) { return (0); } else { for(index = total - 1; index >= 0 ; index--) { if(OrderSelect(index,SELECT_BY_POS,MODE_TRADES)) {
GetOrdersTotal returns the total count of orders matching the type, mn, symbol. Then you go through just that count, not all orders, so the result could be zero (the matching order(s) was beyond total.)medianprice += OrderOpenPrice() * OrderLots(); count += OrderLots();
You're not computing the median price, your computing a lots weighted average price.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi Guys, i tried to correct the error, I did not succeed.
Iam wait for help...
CODE:
start error on the SyncProfit()
if(modify && OrderTakeProfit() != newtakeprofit){
OrderModify(TK,OP,SL,newtakeprofit,0,cor);
Print("Sync(" + OrderTicket() + ") TP from:" + OrderTakeProfit() + " to:" + newtakeprofit);
break;
}
It is not logical to write the log.
The log:
2013.06.05 21:30:05 2010.01.05 18:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45687000 to:1.45687000
2013.06.05 21:30:05 2010.01.05 18:00 Buy 1.1.5 EURUSD,H1: OrderModify error 1
2013.06.05 21:30:05 2010.01.05 17:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45687000 to:1.45687000
2013.06.05 21:30:05 2010.01.05 17:00 Buy 1.1.5 EURUSD,H1: OrderModify error 1
2013.06.05 21:30:05 2010.01.05 16:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45687000 to:1.45687000
2013.06.05 21:30:05 2010.01.05 16:00 Buy 1.1.5 EURUSD,H1: OrderModify error 1
2013.06.05 21:30:05 2010.01.05 15:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45764000 to:1.45687000
2013.06.05 21:30:05 2010.01.05 15:00 Buy 1.1.5 EURUSD,H1: modify #5 buy 0.10 EURUSD at 1.44337 sl: 0.00000 tp: 1.45687 ok
2013.06.05 21:30:05 2010.01.05 15:00 Buy 1.1.5 EURUSD,H1: open #7 buy 0.12 EURUSD at 1.44052 ok
2013.06.05 21:30:05 2010.01.05 14:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45764000 to:1.45764000
2013.06.05 21:30:05 2010.01.05 14:00 Buy 1.1.5 EURUSD,H1: OrderModify error 1
2013.06.05 21:30:05 2010.01.05 13:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45764000 to:1.45764000
2013.06.05 21:30:05 2010.01.05 13:00 Buy 1.1.5 EURUSD,H1: OrderModify error 1
2013.06.05 21:30:05 2010.01.05 12:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45764000 to:1.45764000
2013.06.05 21:30:05 2010.01.05 12:00 Buy 1.1.5 EURUSD,H1: OrderModify error 1
2013.06.05 21:30:05 2010.01.05 11:00 Buy 1.1.5 EURUSD,H1: Sync(5) TP from:1.45837000 to:1.45764000
2013.06.05 21:30:05 2010.01.05 11:00 Buy 1.1.5 EURUSD,H1: modify #5 buy 0.10 EURUSD at 1.44337 sl: 0.00000 tp: 1.45764 ok