Instant close problem

 

Hi coders,


I have a problem with a EA that i just coded and i hope you can help me:

The problem seems to happen only in ECN 5-digits brokers and only in some pairs. The issue is that i have coded a hidden TP which works good on 4-digits and 5-digits brokers, but when i'm going to test in ECN 5-digits brokers it opens a trade and it closes instantly with little loss. That puzzles me because works good on other pairs of the same ECN 5-digits Broker. For example, works good on EURGBP but doesnt do on EURCHF and it's the same broker.

Could be some bad data-feed on the bad-working pairs?

I appreciate your assistance.

Thank you

 

Hi Kaleb

Have you checked the values that cause the close condition using a print statment. It could be a coding bug like if the same value of price came in on two consecutive ticks your close condition might be met. With more decimal places the broker plays with the spread so only one price might move so check the bid and ask prices of the dodgy closes.

 
Ruptor:

Hi Kaleb

Have you checked the values that cause the close condition using a print statment. It could be a coding bug like if the same value of price came in on two consecutive ticks your close condition might be met. With more decimal places the broker plays with the spread so only one price might move so check the bid and ask prices of the dodgy closes.


Hi ruptor,


Thanks for your reply.

this is the code


FOR LONGS

if (OrderType() == OP_BUY)
{
if(OrderMagicNumber() == magic1)
{
if (Bid >= OrderOpenPrice() + TakeProfit * multiplier)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Bid, Slipagge, Orange);
Print("Close BUY 1= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}
else if(OrderMagicNumber() == magic2)
{
if (Bid >= OrderOpenPrice() + (TakeProfit - 2) * multiplier) //i have some doubt here
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Bid, Slipagge, Orange);
Print("Close BUY 2= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}


FOR SHORYS (the inverse)


if (OrderType() == OP_SELL)
{
if(OrderMagicNumber() == magic1)
{
if (Ask <= OrderOpenPrice() - TakeProfit * multiplier)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Ask, Slipagge, Orange);
Print("Close SELL 1= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}

else if (OrderMagicNumber() == magic2)
{
if (Ask <= OrderOpenPrice() - (TakeProfit - 2) * multiplier)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Ask, Slipagge, Orange);
Print("Close SELL 2= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}

}

 

Hi Kaleb

The only suggestion for the code would be to RefreshRates before checking the Ask or Bid price. The print does not tell you the close price so you can check if it was at a valid stoploss or takeprofit.

 
kaleb:

Hi ruptor,


Thanks for your reply.

this is the code


FOR LONGS

if (OrderType() == OP_BUY)
{
if(OrderMagicNumber() == magic1)
{
if (Bid >= OrderOpenPrice() + TakeProfit * multiplier)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Bid, Slipagge, Orange);
Print("Close BUY 1= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}
else if(OrderMagicNumber() == magic2)
{
if (Bid >= OrderOpenPrice() + (TakeProfit - 2) * multiplier) //i have some doubt here
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Bid, Slipagge, Orange);
Print("Close BUY 2= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}


FOR SHORYS (the inverse)


if (OrderType() == OP_SELL)
{
if(OrderMagicNumber() == magic1)
{
if (Ask <= OrderOpenPrice() - TakeProfit * multiplier)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Ask, Slipagge, Orange);
Print("Close SELL 1= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}

else if (OrderMagicNumber() == magic2)
{
if (Ask <= OrderOpenPrice() - (TakeProfit - 2) * multiplier)
{
RefreshRates();
OrderClose(OrderTicket(), OrderLots(), Ask, Slipagge, Orange);
Print("Close SELL 2= ",DoubleToStr(TakeProfit*multiplier,5)); //just to check
}
}

}

Have you solved the problem by now? How did you solve it?