I have an order modification code for my open market orders which comes up with Error 130
in the MT4
Journal, I know this is an age-old issue & there are several sources I have looked at, both here & throughout the web - however, nothing seems to work.
1) I have NormalizeDouble()
-cured everything that has double functions on MQL4
i.e prices etc - this is to ensure that the number of digits after the decimal points are consistent with the pair its trading; some are 3 digits, others are 5 digits.
2) The pnlPoints
& stopPoints
are calculated using the _Period
so the number of points are consistent regardless of the number of digits after the decimal point of the chart the EA is dropped on
3) I'm aware of the presence of the MarketInfo( Symbol(), MODE_STOPLEVEL )
& haved added this to the MarketInfo( Symbol(), MODE_SPREAD )
to some to the stoplevel
calculation.
4) I want 100 points "In the money" before the order is modified to breakeven.
5) I'm using a five digit broker but as you will know, some pairs like the EURJPY
will have three digits. This is corrected by the _Period
& the NormalizeDouble()
funtions.
/*Breakeven Order Modification*/
for(int b = OrdersTotal()-1;b>=0;b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)==true)
{
double aBidPrice = MarketInfo(Symbol(),MODE_BID);
double anOpenPrice = OrderOpenPrice();
double aNewTpPrice = OrderTakeProfit();
double aCurrentSL = OrderStopLoss();
double aNewSLPrice = anOpenPrice;
double pnlPoints = NormalizeDouble(aBidPrice - anOpenPrice/_Point,Digits);
double stopPoints = NormalizeDouble(aBidPrice - aNewSLPrice/_Point,Digits);
int stopLevel = int(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD));
int aTicket = OrderTicket();
if(OrderType() == OP_BUY)
if(stopPoints > stopLevel)
if(aTicket > 0)
if(pnlPoints > breakeven)
if(aNewSLPrice == aCurrentSL)continue;
{
BuyMod = OrderModify(OrderTicket(),NormalizeDouble(anOpenPrice,Digits),NormalizeDouble(aNewSLPrice,Digits),NormalizeDouble(aNewTpPrice,Digits),0,buycolor);
SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
if(BuyMod = false || aTicket == 0)
{
Print("Order modification for ticket #"+IntegerToString(aTicket,10)+"Error code",GetLastError());
}
}
}
}
for(int s = OrdersTotal()-1; s>=0; s--)
{
if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)==true)
{
double anAskPrice = MarketInfo(Symbol(),MODE_ASK);
double anOpenPrice = OrderOpenPrice();
double aNewTpPrice = OrderTakeProfit();
double aCurrentSL = OrderStopLoss();
double aNewSLPrice = anOpenPrice;
double pnlPoints = NormalizeDouble(anOpenPrice - anAskPrice/_Point,Digits);
double stopPoints = NormalizeDouble(aNewSLPrice - anAskPrice/_Point,Digits);
int stopLevel = int(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD));
int aTicket = OrderTicket();
if(OrderType()== OP_SELL)
if(stopPoints > stopLevel)
if(aTicket > 0)
if(pnlPoints > breakeven)
if(aNewSLPrice == aCurrentSL)continue;
{
SellMod = OrderModify(OrderTicket(),NormalizeDouble(anOpenPrice,Digits),NormalizeDouble(aNewSLPrice,Digits),NormalizeDouble(aNewTpPrice,Digits),0,sellcolor);
SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
if(SellMod = false || aTicket == 0)
{
Print("Order modification for ticket #"+IntegerToString(aTicket,10)+"Error code",GetLastError());
}
}
}
}
Many thanks & regards.