# Problem with unexpected EA stop

48

Hi,

i´m new to programming but trying my best. Currently i´m trying to program EA which will trade after predefined set of points e.g. open order after last trade +/- x points. My EA is working fine until one moment, When i open a trade pending order will be set +/- points only if tick will take place. That is fine but when that tick will go other directions (not pending direction) it won´t place pending order and when the first order hit SL it should place opposite market order but in this scenario (when pending order is not set) it won´t open opposite trade and EA stops. Please can anybody help me identify the problem ? Thanks in advance

``` if (BuyTrend == true)
{
if (OrderSelect(0,SELECT_BY_POS)!= true) Print("Problem selecting start order", GetLastError());
double OOP1=OrderOpenPrice();

double SL = StopLoss * Point;
double range = next * Point;

for ( int MaxCount = 1; OrdersTotal() >= MaxCount; MaxCount++ )
{
double price = (OOP1 + (range * count));
double sl = (price - SL);

RefreshRates();
if (Ask >= price - (next * Point))
{

//  if (Ask >= price - range)
//   {
RefreshRates();
//     }
//  else
//    {
//     RefreshRates();
//   }

{
count++;
Print("Problem s vyberom obchodu na sl modifikaciu ",GetLastError());
double slfa=OrderStopLoss();

for (int crt=OrdersTotal()-3; crt >=0;crt--)
{
Print("Problem s vyberom obchodu na sl modifikaciu no.2 ",GetLastError());
if (OrderModify(OrderTicket(),OrderOpenPrice(),slfa,NULL,NULL,clrNONE)!= true)
Print("Problem s modifikaciou SL ",GetLastError());
}
}
else
{
}
}

{
{
if(OrderSymbol()==Symbol() && OrderClosePrice()==OrderStopLoss())
{
RefreshRates();
Print("Problem s otvorenim protipozicie",GetLastError());
else
{
count = 1;
SellTrend=true;
}
//  if (OrderSelect(OrdersTotal()-1,SELECT_BY_POS)!= true) Print("Problem s vyberom sell stopu ",GetLastError());
//  int type = OrderType();
//  {
if (OrderDelete(orderbuy,clrNONE)!= true) Print("Problem s deletovanim cakacky ",GetLastError());
// }
}
}
}
}
}```