How to prevent multiple trades from ea

 
i need help please. im trying to prevent the ea from making multiple trades at the same time. i have tried it with a for loop but had no luck.can someone please help me to solve the problem. my code look like this. its the buy section
//-------------------------------- Buy -------------------------------------------------           
            
         }else if(bar[2].open < HighZone && bar[1].close > HighZone && openTimeBuy != iTime(_Symbol,PERIOD_CURRENT,0)){  
             
               for(int i = PositionsTotal()-1; i >= 0; i--){
           CPositionInfo pos;
             if(pos.SelectByIndex(i) && pos.Symbol() == _Symbol && pos.Magic() ==  MagicMA){
               isPosOpen = true;
        //---------------------------------------------------------------------------------       
                //Get the ticket number
                ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
        //------------------------------------------------------------------------------------       
                 if(pos.PositionType() == POSITION_TYPE_BUY)break;{
                 
            trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,ask,slb,0,"Cross EA");
            Print("Magic Number:",MagicMA);
            Print("Position Buy Price : ",BuyPrice);
            Print("Price above High Zone Buy: ",bar[0].close);
            } 
         } 
                   
      }   
    }
 
Niel05otto:
i need help please. im trying to prevent the ea from making multiple trades at the same time. i have tried it with a for loop but had no luck.can someone please help me to solve the problem. my code look like this. its the buy section

There is many ways to limit 1 trade to open. I urge you to look in codebase for many eas with many examples.

 
Thank you Michael. I've been searching on Google and could not find exactly what I need but did found one article where they use a for loop but mine doesn't work. Could you maybe shere a link of a video please 
 
Niel05otto #:
Thank you Michael. I've been searching on Google and could not find exactly what I need but did found one article where they use a for loop but mine doesn't work. Could you maybe shere a link of a video please 

look on codebase, There is a link at top of this website. There are hundreds of examples.

 

the most simplest way:

if there are currently no open positions, you may open a position


if(PositionsTotal() == 0){

 // Trade execution logic only within this condition
}


Currently you're opening a position inside a loop, don't do that. You only need to loop through open positions when you want to modify positions, or check prices or profit information about the positions that are open

 
Thank you Conor. I'll go and change it tonight.