EA opens Many Trades, How to Open 1 buy & 1 sell? - page 2

 
Jack Buda:

Thanks for advice /tip i appreciate it a lot.

As i said in my previous post, that i started last January to program. Some functions were easy & simple, some were complex & difficult to understand. I know as i made this post i was at fault & i learn from it.

Thank You

I started last 2018 December 1 month before you. 
mql4 was my first ever language. 

 

Create Boolean Functions ExistBuyPos() and ExistSellPos() inside those functions write codes to check for the existance of buy and sell trade respectively....then call them in the OnTick() function....as 

Void OnTick()
{
 if (ExistBuyPos()==false)
  {
   trade.Buy(); //write your buy code here
  }
 else if ( ExistSellPos()==false)
  {
   trade.sell(); //write your sell trade code here
  }
//this code will Allow only one Pos direction 
}
//---
 bool ExistBuyPos() {
   for (int i=0; i<PositionsTotal(); i++) {
      if (PositionSelect(Symbol())) {
        if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY ) {
            return(true);
         }
      } 
   } 
   return(false);
}
//---
bool ExistSellPos() {
   for (int i=0; i<PositionsTotal(); i++) {
      if (PositionSelect(Symbol())) {
        if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL ) {
            return(true);
         }
      } 
   } 
   return(false);
}
//---

 

hi all


please want help on this ea i want 

first if price go up place order with 20 points profit an only one order will be placed if take profit will place another one for stop loos in case 30 points loos 

opposite if price go down will place a sell order the same take profit at 20 points and stop loos at 30 points also will place only one sell order 

second all this should be in loop functions   

thanks to all in advance 


thanks

Khalid Amin