anything wrong with this code?

 

Hi. I had a freelancer create this EA for me and it is not doing something that it should be doing. It uses the an alligator indicator. It will not turn off trades when the lips or jaws are in the middle. Here is a part of the code. I think that this is the part that has the error somewhere in it:

if(aLips>aTeeth && aTeeth>aJaws)

{

if(CountOpenOrders(OP_BUY)==0)

{

CloseSellOrders(Symbol(),MagicNumber);

double sl=Ask-StopLoss*pip;

if (StopLoss==0) sl=0;

double tp=Ask+TakeProfit*pip;

if (TakeProfit==0) tp=0;

OpenBuy(Symbol(),lotSize,sl,tp,"");

}

}else if(aLips<aTeeth && aTeeth<aJaws){

if(CountOpenOrders(OP_SELL)==0)

{

CloseBuyOrders(Symbol(),MagicNumber);

double sl=Bid+StopLoss*pip;

if (StopLoss==0) sl=0;

double tp=Bid-TakeProfit*pip;

if (TakeProfit==0) tp=0;

OpenSell(Symbol(),lotSize,sl,tp,"");

}

}else{

CloseBuyOrders(Symbol(),MagicNumber);

CloseSellOrders(Symbol(),MagicNumber);

}

I think the last part is supposed to stop the orders when the 3 lines are not arranged right, but it will not do it. How do I modify this to work correctly?

 

Hello,

Please use the SRC button when you post code. Thank you.


 
digitdude78:

Hi. I had a freelancer create this EA for me and it is not doing something that it should be doing. It uses the an alligator indicator. It will not turn off trades when the lips or jaws are in the middle. Here is a part of the code. I think that this is the part that has the error somewhere in it

I think the last part is supposed to stop the orders when the 3 lines are not arranged right, but it will not do it. How do I modify this to work correctly?

if(aLips>aTeeth && aTeeth>aJaws)
   {
   if(CountOpenOrders(OP_BUY)==0)
      {
      CloseSellOrders(Symbol(),MagicNumber);
      double sl=Ask-StopLoss*pip;
      if (StopLoss==0) sl=0;
      double tp=Ask+TakeProfit*pip;
      if (TakeProfit==0) tp=0;
      OpenBuy(Symbol(),lotSize,sl,tp,"");
      }
   }
else if(aLips<aTeeth && aTeeth<aJaws)
   {
   if(CountOpenOrders(OP_SELL)==0)
      {
      CloseBuyOrders(Symbol(),MagicNumber);
      double sl=Bid+StopLoss*pip;
      if (StopLoss==0) sl=0;
      double tp=Bid-TakeProfit*pip;
      if (TakeProfit==0) tp=0;
      OpenSell(Symbol(),lotSize,sl,tp,"");
      }
   }
else
   {
   CloseBuyOrders(Symbol(),MagicNumber);
   CloseSellOrders(Symbol(),MagicNumber);
   }

You are right, the last two lines ask for orders to be closed but you need to post more code if you want an answer to why doesn't it close the orders ? question.

The code says basically that if the indicators are up and you don't have a buy order, close sell and place buy, same routine for sell orders and then if the indicator is mixed, close everything.

The call is there for closing orders but the function that does it it's not there.

Also, we may need to have a look at when is the indicator checked to get the right signals.

Sorry, partial code, partial answer. I know it's not much help but there's not much info either.

Reason: