101

I'm baffled by this problem, and after trying everything I can think of I realise I need some help!

Basically my EA will happily open buy orders but refuses to open sell orders, i can't work out why..

Here's the SC

int StopLossPriceB = StopLossPips1;
int TakeProfitPriceB = TakeProfitPips;
OpenPriceB = NormalizeDouble(OpenPriceB, Digits);
StopLossPriceB = NormalizeDouble(StopLossPriceB, Digits);
TakeProfitPriceB = NormalizeDouble(TakeProfitPriceB,Digits);

int StopLossPriceS = StopLossPips1;
int TakeProfitPriceS = TakeProfitPips;
double OpenPriceS = Bid;
OpenPriceS = NormalizeDouble(OpenPriceS,Digits);
StopLossPriceS = NormalizeDouble(StopLossPriceS, Digits);
TakeProfitPriceS = NormalizeDouble(TakeProfitPriceS,Digits);

while ((M_0 && S_0)> 80.0)
{

if (crosseddowni = true)

{

int Order_Magic1 = 5;
//---- open a SELL position-----------------------------------------------------------------------
if ( OrderSend( Symbol(), OP_SELL, LotSize, OpenPriceS, 13,(Bid+StopLossPriceS*Point()),(Bid-TakeProfitPriceS*Point()), "XSFEA",
Order_Magic1, 0, Red ))
{
Sleep(1800000);
crosseddowni = false;
break;
}
else
{
_GetLastError = GetLastError();
Alert( "Error OrderSend S1# ", _GetLastError );
return(-1);
}
//  return(0);
}// end of crosseddown i = true

else continue;
}

while ((M_0) && (S_0 )< 20.0)
{
if (crossedupi = true)

{

Order_Magic1, 0, Green ))
{
Sleep(1800000);
crossedupi = false;
break;
}
else
{
_GetLastError = GetLastError();
Alert( "Error OrderSend B1# ", _GetLastError );
return(-1);
}

//   return(0);
}
else continue;
}

Moderator
31186

What is the error message in the log ?
101

xanderhinds:

I'm baffled by this problem, and after trying everything I can think of I realise I need some help!

Basically my EA will happily open buy orders but refuses to open sell orders, i can't work out why..

Here's the SC

int StopLossPriceB = StopLossPips1;
int TakeProfitPriceB = TakeProfitPips;
OpenPriceB = NormalizeDouble(OpenPriceB, Digits);
StopLossPriceB = NormalizeDouble(StopLossPriceB, Digits);
TakeProfitPriceB = NormalizeDouble(TakeProfitPriceB,Digits);

int StopLossPriceS = StopLossPips1;
int TakeProfitPriceS = TakeProfitPips;
double OpenPriceS = Bid;
OpenPriceS = NormalizeDouble(OpenPriceS,Digits);
StopLossPriceS = NormalizeDouble(StopLossPriceS, Digits);
TakeProfitPriceS = NormalizeDouble(TakeProfitPriceS,Digits);

while ((M_0 && S_0)> 80.0)
{

if (crosseddowni = true)

{

int Order_Magic1 = 5;
//---- open a SELL position-----------------------------------------------------------------------
if ( OrderSend( Symbol(), OP_SELL, LotSize, OpenPriceS, 13,(Bid+StopLossPriceS*Point()),(Bid-TakeProfitPriceS*Point()), "XSFEA",
Order_Magic1, 0, Red ))
{
Sleep(1800000);
crosseddowni = false;
break;
}
else
{
_GetLastError = GetLastError();
Alert( "Error OrderSend S1# ", _GetLastError );
return(-1);
}
//  return(0);
}// end of crosseddown i = true

else continue;
}

while ((M_0) && (S_0 )< 20.0)
{
if (crossedupi = true)

{

Order_Magic1, 0, Green ))
{
Sleep(1800000);
crossedupi = false;
break;
}
else
{
_GetLastError = GetLastError();
Alert( "Error OrderSend B1# ", _GetLastError );
return(-1);
}

//   return(0);
}
else continue;
}

There is none, that's part of the trouble.. the EA compiles fine, but when backtesting it will only open long trades (or when set to only open short positions wont open any positions at all)..
Moderator
9641

while ((M_0 && S_0)> 80.0)

This will never be true so there will not be any sell orders opened.

Maybe you intended

while (M_0> 80.0 && S_0> 80.0)
?
14781

if ( OrderSend( Symbol(), OP_SELL, LotSize, OpenPriceS, 13,(Bid+StopLossPriceS*Point()),(Bid-TakeProfitPriceS*Point()), "XSFEA",
Order_Magic1, 0, Red ))
{
1. OrderSend returns a ticket number. If(ticket number) makes no sense. Check for a failure.
2. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles