Hello,
I'm looking for an developer to implement a coding strategy to modify any market order positions to beak even when I profit 100 pips, the current code I have so far is below. However, I'm having trouble getting this to actually modify any orders. There are no errors in the journal so there shouldn't be anything wrong specifically with the code, but clearly one or more conditions are not being met without my knowledge.
If any developer could alter the code to so as my market positions move to breakeven,. this would be much appreciated.
for(int s=OrdersTotal()-1;s>=0;s--)
{
if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)==true)
{
double anAskPrice = MarketInfo(Symbol(),MODE_ASK);
double tick = MarketInfo(Symbol(),MODE_TICKSIZE);
double anOpenPrice = OrderOpenPrice();
double aCurrentSL = OrderStopLoss();
double aNewSLPrice = OrderOpenPrice();
double tp = OrderTakeProfit();
int pnlPoints = int((anOpenPrice - anAskPrice)/_Point);
int stopPoints = int((aNewSLPrice - anAskPrice)/_Point);
int stopLevel = int(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD));
int aTicket = OrderTicket();
int breakeven = 100;
if(OrderType()==OP_SELL)
if(pnlPoints>breakeven)
if(stopPoints >stopLevel)
if(pnlPoints>breakeven)
if(anOpenPrice-anAskPrice>breakeven*_Point)
if(aNewSLPrice!=aCurrentSL)
{
SellMod = OrderModify(aTicket,anOpenPrice,anOpenPrice,tp,0,sellcolor);
PrintFormat("OrderOpenPrice %7.5f CurrentPrice %7.5f",anOpenPrice,anAskPrice);
SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
SendNotification("Ticket# "+IntegerToString(aTicket,10)+" has been modified to breakeven");
if(!SellMod)
{
PrintFormat("OrderOpenPrice %7.5f CurrentPrice %7.5f",anOpenPrice,anAskPrice);
PrintFormat("Order modification for ticket %10d has failed to modify the order under the Error Code# %5d. Check MQL4 Documentation",aTicket,GetLastError());
}
}
}
}
for(int b=OrdersTotal()-1;b>=0;b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)==true)
{
double anBidPrice = MarketInfo(Symbol(),MODE_BID);
double anOpenPrice = OrderOpenPrice();
double aCurrentSL = NormalizeDouble(OrderStopLoss(),Digits);
double aNewSLPrice = NormalizeDouble(OrderOpenPrice(),Digits);
double tp = OrderTakeProfit();
int pnlPoints = int((anBidPrice - anOpenPrice)/_Point);
int stopPoints = int((anBidPrice - aNewSLPrice)/_Point);
int stopLevel = int(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD));
int aTicket = OrderTicket();
int breakeven = 100;
if(OrderType()==OP_SELL)
if(pnlPoints>breakeven)
if(stopPoints >stopLevel)
if(pnlPoints > breakeven)
if(anBidPrice-anOpenPrice>breakeven*_Point)
if(aNewSLPrice!=aCurrentSL)
{
SellMod = OrderModify(aTicket,anOpenPrice,aNewSLPrice,tp,0,sellcolor);
SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
SendNotification("Ticket# "+IntegerToString(aTicket,10)+" has been modified to breakeven");
if(!SellMod)
{
PrintFormat("Order modification for ticket %10d has failed to modify the order under the Error Code# %5d. Check MQL4 Documentation",aTicket,GetLastError());
}
}
}
}