Download MetaTrader 5
To add comments, please log in or register
Follow the news. View our company's official channel!
ddude78
10
ddude78 2014.04.04 21:00 

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?

Alain Verleyen
Moderator
29647
Alain Verleyen 2014.04.04 21:46  

Hello,

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


Daniel Petrovai
440
Daniel Petrovai 2014.04.06 05:39  
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.

/
To add comments, please log in or register