Hi,
I am new at coding, but i am learning very fast te last 2/3 weeks. At this moment, I have a problem that I can't solve (I think it is a very stupid en easy problem :-).
Above code works just fine when all the bool closeSellOrders = (closeSell1 || closeSell2 || closeSell3 || closeSell4) and bool closeBuyOrders = (closeBuy1 || closeBuy2 || closeBuy3 || closeBuy4 are true. But when I set 1 of the 4 close posibilities on false, the EA doesn't work anymore. It opens an order and close it at the same time.
What I am doing wrong? I think it ca't be so difficult.
Thanks in advanced,
Smika
I am new at coding, but i am learning very fast te last 2/3 weeks. At this moment, I have a problem that I can't solve (I think it is a very stupid en easy problem :-).
Inserted Code
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//+------------------------------------------------------------------+
//| SL Management |
//+------------------------------------------------------------------+
void Slmanagement()
{
double ema3open, ema5open, ema3, ema15;
double curTdiGreen, curTdiRed, prevTdiGreen, prevTdiRed, curTdiBlueUp, curTdiBlueDown, prevTdiBlueUp, prevTdiBlueDown;
ema3open = iMA(NULL, 0, 3, 0, MODE_EMA, PRICE_OPEN, 0);
ema5open = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_OPEN, 0);
ema3 = iMA(NULL, 0, 3, 0, MODE_EMA, PRICE_CLOSE, 0);
ema15 = iMA(NULL, 0, 15, 0, MODE_EMA, PRICE_CLOSE, 0);
curTdiBlueUp = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,1,0);
prevTdiBlueUp = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,1,1);
curTdiBlueDown = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,3,0);
prevTdiBlueDown = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,3,1);
curTdiGreen = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,4,0);
prevTdiGreen = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,4,1);
curTdiRed = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,5,0);
prevTdiRed = iCustom(NULL,0,"TDI Red Green.ex4",10,5,34,2,1,7,0,5,1);
bool closeBuy1 = (!ema3over5 || (ema3open < ema5open));
bool closeBuy2 = (!ema3over15 || (ema3 < ema15));
bool closeBuy3 = (!tdicrossrg || ((curTdiGreen<curTdiRed) && (prevTdiGreen>prevTdiRed)));
bool closeBuy4 = (!tdicrossgb || ((curTdiGreen<curTdiBlueUp) && (prevTdiGreen>prevTdiBlueUp)));
bool closeBuyOrders = (closeBuy1 || closeBuy2 || closeBuy3 || closeBuy4);
bool closeSell1 = (!ema3over5 || (ema3open > ema5open));
bool closeSell2 = (!ema3over15 || (ema3 > ema15));
bool closeSell3 = (!tdicrossrg || ((curTdiGreen>curTdiRed) && (prevTdiGreen<prevTdiRed)));
bool closeSell4 = (!tdicrossgb || ((curTdiGreen>curTdiBlueUp) && (prevTdiGreen<prevTdiBlueUp)));
bool closeSellOrders = (closeSell1 || closeSell2 || closeSell3 || closeSell4);
for(int i = 0;i < OrdersTotal();i++)
{
bool Os = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == Symbol() && (MagicNumber == 0 || OrderMagicNumber() == MagicNumber))
{
if(OrderType() == OP_BUY && closeBuyOrders)
{
bool Oc = OrderClose(OrderTicket(),OrderLots(),Bid,slippage_close,Blue); // close buy order
if(!OrderClose(OrderTicket(),OrderLots(),Bid,slippage_close,Blue))
Alert("The order isn't close because Err no. ", GetLastError());
else
Alert("Order closed succesfully");
}
if(OrderType() == OP_SELL && closeSellOrders)
{
bool Oc = OrderClose(OrderTicket(),OrderLots(),Ask,slippage_close,Red); // close sell order
if(!OrderClose(OrderTicket(),OrderLots(),Ask,slippage_close,Red))
Alert("The order isn't close because Err no. ", GetLastError());
else
Alert("Order closed succesfully");
}
}
}} Above code works just fine when all the bool closeSellOrders = (closeSell1 || closeSell2 || closeSell3 || closeSell4) and bool closeBuyOrders = (closeBuy1 || closeBuy2 || closeBuy3 || closeBuy4 are true. But when I set 1 of the 4 close posibilities on false, the EA doesn't work anymore. It opens an order and close it at the same time.
What I am doing wrong? I think it ca't be so difficult.
Thanks in advanced,
Smika