Only 1 position open and only this position close.. Help me for Magic Number Please... :/

 

I'm new and I'm trying to move forward. Please help me.

1) I want to open only 1 position for this signal using "void " but I couldn't. :(  
2) I have more than one signal. and I have a separate close signal for each signal. So I think I need to record the magic number and I need to use this magic number to close but I couldn't :(

Can you write me an example that makes a simple AL and CLOSE operation with Signal = 1 and Signal = 0?

So it will be much more comfortable for me to understand. Thank you very much in advance.

I hope I can find a master who will make me happy.

I use MT5 and MQL5.

Sorry for the following nonsense. Can you edit it the way I want ?

if(signal==1)
{
int ordercount()                        
{
   total=0;                         
   int i;                               
   for(i=0; i<OrdersTotal(); i++)       
   {
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
       if(OrderSymbol()!=Symbol() ||    
       OrderMagicNumber()!=MagicNumber) 
       continue;                        
       total++;                         
   }
   return(total);                       
}
}

if(ordercount()==0  && signal==1)
     {  
   trade.Buy(0.01,NULL,Ask,0,0,NULL);        
 }
 
 signal=0;
 
if (signal==0)
{
Close()
}

//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void Close()
  {

//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if("your closing buy condition here")
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if("your closing Sell condition here")
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
 
don't have a helpful friend?
 
if(signal==1)
{
    int ordercount(){ … }
}

if(ordercount()==0  && signal==1)
  1. Don't post code that will not even compile. You can't define a function inside other code.
  2. What do you want signal==1 to do?
 
William Roeder:
  1. Don't post code that will not even compile. You can't define a function inside other code.
  2. What do you want signal==1 to do?

Can you write me an example that makes a simple AL and CLOSE operation with Signal = 1 and Signal = 0?

signal==1 (open any buy position)

signal==0 (close only this position with magic number)

I know it's simple for you, but I haven't done it yet. I will be very glad if you help. :/

Reason: