I have been running this EA on demo account but I notice that the trail feature doesn't work all the time causing it have more losses. I pasted the part of the code here cuz I have very little experience with programming: could someone please look at it this part of the code and see if there might be any possible problems. Any help or feedback will be appreciated. Thanks in advance
}
void TrailStop() {
bool bres;
double StopLoss;
if ( TrailingStop > 2 ) {
for (int i = 0; i < OrdersTotal(); i++) {
if ( OrderSelect (i, SELECT_BY_POS) == false ) continue;
if ( OrderSymbol() != Symbol() || OrderMagicNumber() != expertId ) continue;
if ( OrderType() == OP_BUY ) {
if ( Ask < OrderOpenPrice()+TrailingStop*Point ) continue;
StopLoss = Ask-TrailingStop*Point;
if ( StopLoss > OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White);
if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError()));
}
}
if ( OrderType() == OP_SELL ) {
if ( Bid > OrderOpenPrice()-TrailingStop*Point ) continue;
StopLoss = Bid+TrailingStop*Point;
if ( StopLoss < OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, Gold);
if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError()));
}
}
}
}
return;
}
}
void TrailStop() {
bool bres;
double StopLoss;
if ( TrailingStop > 2 ) {
for (int i = 0; i < OrdersTotal(); i++) {
if ( OrderSelect (i, SELECT_BY_POS) == false ) continue;
if ( OrderSymbol() != Symbol() || OrderMagicNumber() != expertId ) continue;
if ( OrderType() == OP_BUY ) {
if ( Ask < OrderOpenPrice()+TrailingStop*Point ) continue;
StopLoss = Ask-TrailingStop*Point;
if ( StopLoss > OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White);
if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError()));
}
}
if ( OrderType() == OP_SELL ) {
if ( Bid > OrderOpenPrice()-TrailingStop*Point ) continue;
StopLoss = Bid+TrailingStop*Point;
if ( StopLoss < OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, Gold);
if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError()));
}
}
}
}
return;
}
Move Money !!!