I love the EA, Great job!
I think I may have found errors in the checkForBreakEven function which cause those 1 pip stoploss gains.
In the original line:
if(Bid-OrderOpenPrice()>((point*BreakEven) + setToBEafterPips))
Bid or Ask is pulling the value only from the current chart the EA is attached to, so the comparison values are incorrect.
The fix is:
if(MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice()>BreakEven + setToBEafterPips)
Also, I changed:
point*=multiplier;
BreakEven*=multiplier;
setToBEafterPips*=multiplier;
To:
point*=multiplier;
BreakEven*=point;
setToBEafterPips*=point;
Other changes needed earlier in code:
extern double BreakEvenPips = 5;
extern double setToBEafterPips = 10;
if (setToBreakEven == true) checkForBreakEven(pairs[c],magic,BreakEvenPips,setToBEafterPips);
The complete revised function is below, changes in bold:
I think I may have found errors in the checkForBreakEven function which cause those 1 pip stoploss gains.
In the original line:
if(Bid-OrderOpenPrice()>((point*BreakEven) + setToBEafterPips))
Bid or Ask is pulling the value only from the current chart the EA is attached to, so the comparison values are incorrect.
The fix is:
if(MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice()>BreakEven + setToBEafterPips)
Also, I changed:
point*=multiplier;
BreakEven*=multiplier;
setToBEafterPips*=multiplier;
To:
point*=multiplier;
BreakEven*=point;
setToBEafterPips*=point;
Other changes needed earlier in code:
extern double BreakEvenPips = 5;
extern double setToBEafterPips = 10;
if (setToBreakEven == true) checkForBreakEven(pairs[c],magic,BreakEvenPips,setToBEafterPips);
The complete revised function is below, changes in bold:
Inserted Code
//+------------------------------------------------------------------+
//| Expert checkForBreakEven function |
//+------------------------------------------------------------------+
int checkForBreakEven(string symbol,int magicNumber, [b]double BreakEven, double setToBEafterPips[/b])
{
RefreshRates();
int cnt;
int total = OrdersTotal();
int ticket;
double point = MarketInfo(symbol,MODE_POINT);
double digit = MarketInfo(symbol,MODE_DIGITS);
double spread = MarketInfo(symbol,MODE_SPREAD);
double multiplier;
if(digit == 2 || digit == 4) multiplier = 1;
if(digit == 3 || digit == 5) multiplier = 10;
if(digit == 6) multiplier = 100;
if(digit == 7) multiplier = 1000;
[b]point*=multiplier;[/b]
[b] BreakEven*=point;[/b]
[b] setToBEafterPips*=point;[/b]
// end adjust for 5 digit brokers
for (cnt = 0 ; cnt <= total ; cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == magicNumber && OrderSymbol() == symbol)
{
/* set BreakEven if set for OP_BUY */
if (OrderType()==OP_BUY && BreakEven>0)
{
[b] if(MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice()>BreakEven + setToBEafterPips)[/b]
{
if(OrderStopLoss()<OrderOpenPrice())
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+point*1,OrderTakeProfit(),0,Gray);
}
}
} // end BE for OP_BUY
/* set BreakEven if set for OP_SELL */
if (OrderType()==OP_SELL && BreakEven>0)
{
[b]if(OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK)>BreakEven + setToBEafterPips)[/b]
{
if(OrderStopLoss()>OrderOpenPrice())
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-point*1,OrderTakeProfit(),0,Gray);
}
}
} // end BE for OP_SELL
}
}
}