Edit Your Comment
Position Modifier not working correctly
Sep 09, 2015 at 05:59
เป็นสมาชิกตั้งแต่ Sep 08, 2015
1 โพสต์
I've been working on an EA for a while and part of it adjusts the stop loss on positions based on other criteria. The opening conditions allow it to open up to 4 positions at a time, all the buy orders are set with the magic index of 4 and sells are 3.
For some reason the stop loss adjuster is working fine but only on the first position, the other 3 are not being modified at all.
This is probably me with smoke kind of rookie error but if anyone has any ideas that might be able to solve this issue that would be amazing.
Thanks
Tom
For some reason the stop loss adjuster is working fine but only on the first position, the other 3 are not being modified at all.
This is probably me with smoke kind of rookie error but if anyone has any ideas that might be able to solve this issue that would be amazing.
Thanks
Tom

forex_trader_25447
เป็นสมาชิกตั้งแต่ Dec 21, 2010
127 โพสต์
Sep 09, 2015 at 13:33
เป็นสมาชิกตั้งแต่ Dec 21, 2010
127 โพสต์
Is there any Error code ?
Are you sure your value for SL are correct ? It must be :
StopLoss_BUY = OrderOpenPrice() - Distance;
StopLoss_SELL= OrderOpenPrice() + Distance;
Where Order must be Selected before,
and Distance must be greater (>) than
MathMax( MarketInfo(_Symbol,MODE_STOPLEVEL), MarketInfo(_Symbol,MODE_FREEZELEVEL))*_Point;
Are you sure your value for SL are correct ? It must be :
StopLoss_BUY = OrderOpenPrice() - Distance;
StopLoss_SELL= OrderOpenPrice() + Distance;
Where Order must be Selected before,
and Distance must be greater (>) than
MathMax( MarketInfo(_Symbol,MODE_STOPLEVEL), MarketInfo(_Symbol,MODE_FREEZELEVEL))*_Point;
เป็นสมาชิกตั้งแต่ Jun 04, 2015
29 โพสต์
Sep 15, 2015 at 10:01
เป็นสมาชิกตั้งแต่ Jun 04, 2015
29 โพสต์
Here we go, all orders with magic xxx are modified - similar tp.
void PairLossModify(){
bool modifypairloss;
for(cnt=OrdersTotal();cnt>=0;cnt--){
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic){
if(OrderType()==OP_BUY){
if(OrderStopLoss()==0 && MaxPairLoss!=0){
RefreshRates();
modifypairloss=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+MaxPairLoss*pt,Digits),OrderTakeProfit(),0,Red);
}
}
if(OrderType()==OP_SELL){
if(OrderStopLoss()==0 && MaxPairLoss!=0){
RefreshRates();
modifypairloss=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-MaxPairLoss*pt,Digits),OrderTakeProfit(),0,Red);
}
}
}
}
}
void PairLossModify(){
bool modifypairloss;
for(cnt=OrdersTotal();cnt>=0;cnt--){
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic){
if(OrderType()==OP_BUY){
if(OrderStopLoss()==0 && MaxPairLoss!=0){
RefreshRates();
modifypairloss=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+MaxPairLoss*pt,Digits),OrderTakeProfit(),0,Red);
}
}
if(OrderType()==OP_SELL){
if(OrderStopLoss()==0 && MaxPairLoss!=0){
RefreshRates();
modifypairloss=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-MaxPairLoss*pt,Digits),OrderTakeProfit(),0,Red);
}
}
}
}
}

forex_trader_25447
เป็นสมาชิกตั้งแต่ Dec 21, 2010
127 โพสต์
Sep 15, 2015 at 13:24
เป็นสมาชิกตั้งแต่ Dec 21, 2010
127 โพสต์
As I understand , You have 2 different MAGIC for BUY and SELL.
So the lines :
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{ if(OrderType()==OP_BUY) { /*Your code*/ }
if(OrderType()==OP_SELL) { /*Your code*/ }
}
Must be like this :
if(OrderSymbol()==Symbol())
{ if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBUY) { /*Your code*/ }
if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSELL) { /*Your code*/ }
}
So the lines :
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{ if(OrderType()==OP_BUY) { /*Your code*/ }
if(OrderType()==OP_SELL) { /*Your code*/ }
}
Must be like this :
if(OrderSymbol()==Symbol())
{ if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBUY) { /*Your code*/ }
if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSELL) { /*Your code*/ }
}

*การใช้งานเชิงพาณิชย์และสแปมจะไม่ได้รับการยอมรับ และอาจส่งผลให้บัญชีถูกยกเลิก
เคล็ดลับ: การโพสต์รูปภาพ/youtube url จะฝังลงในโพสต์ของคุณโดยอัตโนมัติ!
เคล็ดลับ: พิมพ์เครื่องหมาย @ เพื่อป้อนชื่อผู้ใช้ที่เข้าร่วมการสนทนานี้โดยอัตโนมัติ