What is the error message in the log ?
xanderhinds:
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)..
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;
double OpenPriceB = Ask;
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;
Alert ("Sell MN 5 successful");
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)
{
//------- open a BUY position for 1h stochastic reader---------------------------------------------------------------------
if ( OrderSend( Symbol(), OP_BUY, LotSize, OpenPriceB, 13,(Ask-StopLossPriceB*Point()),(Ask+TakeProfitPriceB*Point()), "XFSEA",
Order_Magic1, 0, Green ))
{
Sleep(1800000);
crossedupi = false;
Alert ("Buy MN 5 successful");
break;
}
else
{
_GetLastError = GetLastError();
Alert( "Error OrderSend B1# ", _GetLastError );
return(-1);
}
// return(0);
}
else continue;
}
int TakeProfitPriceB = TakeProfitPips;
double OpenPriceB = Ask;
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;
Alert ("Sell MN 5 successful");
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)
{
//------- open a BUY position for 1h stochastic reader---------------------------------------------------------------------
if ( OrderSend( Symbol(), OP_BUY, LotSize, OpenPriceB, 13,(Ask-StopLossPriceB*Point()),(Ask+TakeProfitPriceB*Point()), "XFSEA",
Order_Magic1, 0, Green ))
{
Sleep(1800000);
crossedupi = false;
Alert ("Buy MN 5 successful");
break;
}
else
{
_GetLastError = GetLastError();
Alert( "Error OrderSend B1# ", _GetLastError );
return(-1);
}
// return(0);
}
else continue;
}
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)
if ( OrderSend( Symbol(), OP_SELL, LotSize, OpenPriceS, 13,(Bid+StopLossPriceS*Point()),(Bid-TakeProfitPriceS*Point()), "XSFEA",
Order_Magic1, 0, Red ))
{
Order_Magic1, 0, Red ))
{
- OrderSend returns a ticket number. If(ticket number) makes no sense. Check for a failure.
- 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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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 TakeProfitPriceB = TakeProfitPips;
double OpenPriceB = Ask;
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;
Alert ("Sell MN 5 successful");
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)
{
//------- open a BUY position for 1h stochastic reader---------------------------------------------------------------------
if ( OrderSend( Symbol(), OP_BUY, LotSize, OpenPriceB, 13,(Ask-StopLossPriceB*Point()),(Ask+TakeProfitPriceB*Point()), "XFSEA",
Order_Magic1, 0, Green ))
{
Sleep(1800000);
crossedupi = false;
Alert ("Buy MN 5 successful");
break;
}
else
{
_GetLastError = GetLastError();
Alert( "Error OrderSend B1# ", _GetLastError );
return(-1);
}
// return(0);
}
else continue;
}