MQL4 - automated forex trading   /  

Forum

Instant close problem

Back to topics list To post a new topic, please log in or register

avatar
14
kaleb 2009.07.02 18:24 

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

article

Interview with Jimmy Tirtawangsa (fireflies)

Gorez does a good job by predicting that GBPJPY will go south for many weeks.


avatar
364
Ruptor 2009.07.02 21:03 

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.



avatar
14
kaleb 2009.07.02 22:38 
Ruptor wrote >>

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
}
}

}


avatar
364
Ruptor 2009.07.02 22:53 

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.


avatar
1
radovedni9 2009.08.27 17:20 
kaleb wrote >>

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?

Back to topics list  

To add comments, please log in or register