Multiple Orders with one EA - different opening - different close

 

Hi

I would need to open 3 different Positions in the same Pair and to close them all differntly (eg.: differnet TakeProfit Level). I believe the Problem has to do with the Tickets. I have tired but with Problems with the Close. I posted the original Code below. I hope anyone can help me.

Many thanks.

Cu

Ope


//+------------------------------------------------------------------+
//|                                                       Sample.mq4 |
//|                                                                  |
//|                                                 http://www...com |
//+------------------------------------------------------------------+
 
extern double TakeProfit = 60;
extern double StopLoss = 60;
extern double Lots = 0.1;
extern double TrailingStop = 70;

 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

 
 
int start()
  {

   int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<1)
     {
      Print("TakeProfit less than 1");
      return(0);  // check TakeProfit
     }
// to simplify the coding and speed up access
// data are put into internal variables




double rsi0 = iRSI(NULL,0,14,PRICE_CLOSE,0);
double rsi1 = iRSI(NULL,0,14,PRICE_CLOSE,1);



   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(rsi1<50)
         {
//----
            
//----
         ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(rsi1>50) 
        {
//----
            
//----
         ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
//----
        
//----
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
            if((rsi0<70 && rsi1>70))
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            if((rsi0>30 && rsi1<30))
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
// the end.
 

No idea?


Thx

Ope

 
Ope:

No idea?


Thx

Ope

The reason you haven't had any help yet is that you haven't provided enough details on:

- what the desired behaviour is

- what is going wrong

 

Nothing special

3 different opening. e.g.: 1 with MA Period 20, 1 with MA Period 50, 1 with MA Period 5,

and

3 different closes. e.g.: 3 different TakeProfit Levels



2 positions were opened, but closed not rigthly


If you need any further information, please ask me.


Thank you very much for help

Ciao

Ope

 
I'm sure it is possible to manage all trades in 1 ea but I think the simple solution would be to have an ea managing each of your trade strategies separately. So you would create 3 separate ea's each with a different magic number and attach them to 3 different charts. Then you can be as creative as you like with each the system design without the complexity of managing it all in 1 ea.