Need some help with this EA

 
I'm trying to code an EA (using some already made codes) which does the following:
  • Opens two pending orders, a sell stop and a buy stop, at a specific time (in this case 23:00), both with an SL and a TP.
  • Expires the pending order at a certain time (for example at 10:00).
  • If two trades are opened and one reaches the SL, the other has its TP increased (I think an OrderModify will solve something like this).
So far I have this:

//+------------------------------------------------------------------+
//|                                                  TimeBasedEA.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
//changed by:       "forex4capital@yahoo.ca"
//change again by: madmax3

// Time frame: M5 and higher

extern int     MagicNumber = 20080122;
extern double DistancefromAsk;
extern double DistancefromBid;
extern double  TakeProfit  = 34;
extern double  StopLoss    = 55;
extern double  Lots        = 0.1;
extern int     StartHour   = 2300;      // Open Trade time
extern bool    OpenBuy     = true;
extern bool    OpenSell    = true;
extern int     NumBuys     = 1;
extern int     NumSells    = 1;
extern int     Slippage    = 2;

//+------------------------------------------------------------------+
//|                        S T A R T                                 |
//+------------------------------------------------------------------+
int start()
  {
   int cnt, ticket, total;
   int ct;
//-------------------------------------+
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
//-------------------------------------+
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
//-------------------------------------+
   ct = Hour() * 100 + Minute();
   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(ct == StartHour && Close[1]>Open[1] && OpenBuy)
      //if(ct == StartHour && High[1]<Open[0] && OpenBuy)
        {
         for ( cnt = 0; cnt < NumBuys; cnt++)
         {
           ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+(DistancefromAsk*Point),Slippage,Bid-(StopLoss*Point),Ask+(TakeProfit*Point),"",MagicNumber,TimeCurrent()+39600,CLR_NONE);
           ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-(DistancefromBid*Point),Slippage,Ask+(StopLoss*Point),Bid-(TakeProfit*Point),"",MagicNumber,TimeCurrent()+39600,CLR_NONE); 
           if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
           else Print("Error opening BUY order : ",GetLastError()); 
         }
         return; 
        }
      // check for short position (SELL) possibility
      if(ct == StartHour && Close[1]<Open[1] && OpenSell)
      //if(ct == StartHour && Low[1]>Open[0] && OpenSell)
        {
         for ( cnt = 0; cnt < NumSells; cnt++)
         {
           ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-(DistancefromAsk*Point),Slippage,Ask+(StopLoss*Point),Bid-(TakeProfit*Point),"",MagicNumber,TimeCurrent()+39600,CLR_NONE);
           ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+(DistancefromBid*Point),Slippage,Bid-(StopLoss*Point),Ask+(TakeProfit*Point),"",MagicNumber,TimeCurrent()+39600,CLR_NONE);
           if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
           else Print("Error opening SELL order : ",GetLastError());
         } 
         return; 
        }
     }
   return(0);
  }
// the end.


I have the following issue,

I need the code required for the modifying order part, i.e. if two trades are open and one hits the stop loss, the other will have it's take profit changed.

If anyone can help me it would be greatly appreciated as I think this EA is nearing completion as it is so it might as well get done
Thanks,

madmax3
 
madmax3:
I'm trying to code an EA (using some already made codes) which does the following:
  • Opens two pending orders, a sell stop and a buy stop, at a specific time (in this case 23:00), both with an SL and a TP.
  • Expires the pending order at a certain time (for example at 10:00).
  • If two trades are opened and one reaches the SL, the other has its TP increased (I think an OrderModify will solve something like this).
So far I have this:

I have the following issue,

I need the code required for the modifying order part, i.e. if two trades are open and one hits the stop loss, the other will have it's take profit changed.

If anyone can help me it would be greatly appreciated as I think this EA is nearing completion as it is so it might as well get done
Thanks,
madmax3

nearing completion ==>> Begin what needed first.....

   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified

This is a wrong way for detecting if there are open trades

On accounts trading you can have orders opened with another Symbol or with other magicnumbers..

total is then >0 So the EA can't open new trades Trie to fix this first

So Check your open trades with selecting right Symbol and MagicNumber

 
There is a MagicNumber for the trades I believe, the code you mentioned was part of the coding before I did any changes to it so I'm not sure what it's for. I'm also noob at coding MQL just so anyone reading knows.