I created the variables you didn't provide. If they're wrong the correct them below. The program gets to "Here==1" however it does not get to "Here==2" and thats where your order-modify is located. Any ideas why?
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int movingStopLoss=20; double pt; void init(){pt=Point;} //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void start(){ while(OrdersTotal()!=3){int Magic=7; OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"",Magic,0,Blue); } //check position, close or move stop loss if(OrdersTotal() != 0) { /*if(OrdersTotal() != 3)//close all position { CloseAll();//close all }*/ MoveStopLoss(movingStopLoss);//move stop loss } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void MoveStopLoss(int movingStopLoss) { int SLcnt; if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS)==false)//chose current trades and orders return(0); if(OrdersTotal()>0) { for(SLcnt=OrdersTotal();SLcnt>=0;SLcnt--) { if(OrderSelect(SLcnt, SELECT_BY_POS)==false) continue; else { Alert("Here===1"); if(OrderType()==OP_BUY && ((Close[0]-OrderStopLoss())>movingStopLoss)){ //long positions modify stop loss Alert("Here===2"); OrderModify(OrderTicket(), OrderOpenPrice(), Bid-movingStopLoss*pt, 0, 0); } if(OrderType()==OP_SELL && ((OrderStopLoss()-Close[0])>movingStopLoss)){ //short positions modify stop loss OrderModify(OrderTicket(), OrderOpenPrice(), Ask+movingStopLoss*pt, 0, 0); } } } } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23:19:28 Helping: loaded successfully 23:19:32 Helping test started 23:19:32 2012.01.02 06:01 Helping EURUSD,M5: open #1 buy 1.00 EURUSD at 1.2930 ok 23:19:32 2012.01.02 06:01 Helping EURUSD,M5: open #2 buy 1.00 EURUSD at 1.2930 ok 23:19:32 2012.01.02 06:01 Helping EURUSD,M5: open #3 buy 1.00 EURUSD at 1.2930 ok 23:19:32 2012.01.02 06:01 Helping EURUSD,M5: Alert: Here===1 23:19:32 2012.01.02 06:01 Helping EURUSD,M5: Alert: Here===1 23:19:32 2012.01.02 06:01 Helping EURUSD,M5: Alert: Here===1 23:19:43 2012.01.02 06:01 Helping EURUSD,M5: Alert: Here===1
I created the variables you didn't provide. If they're wrong the correct them below. The program gets to "Here==1" however it does not get to "Here==2" and thats where your order-modify is located. Any ideas why?
I had PM to you, thank you!!
The reason your ordermodify is not working is because
Close[0]-OrderStopLoss())>movingStopLoss
close - orderstoploss ... would never be greater than movingStopLoss
movingStopLoss is 30 [within your codes]. where-as close is usually like 1.54321 and orderstoploss is also a price like 1.43210.
therefore something like 1.5 cannot be> than 30.0
Ps> I responded to your PM with additional info.The reason your ordermodify is not working is because
close - orderstoploss ... would never be greater than movingStopLoss
movingStopLoss is 30 [within your codes]. where-as close is usually like 1.54321 and orderstoploss is also a price like 1.43210.
therefore something like 1.5 cannot be> than 30.0
Ps> I responded to your PM with additional info.thanks again. it's a stupid bug................

- 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 everybody,
I'm a newbie about MT4
I wrote a EA, it work fine, but the part of "moving stop" isn't work, and I can't find out what's wrong.
anyone can help me? please!!! thank you!!!