Modify Stoploss and Takeprofit of open orders

 

Hi everyone. I need help. I am trying to create a ea that will look through the open orders pool and if there is an open order it will modify the order to add both a take profit and stoploss. If there isn't an order it will just keep looking the time of the day is over. This is what I did so far. Its not working when I add it to my chart. Can someone help me or tell me why please?


#property copyright  

#property link   


extern double TakeProfit    =50;

extern double StopLoss      =140;
extern double TrailingStop  =30;

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

int start(){  
if(OrdersTotal()>=1)// start modifying 
     {
      for (int i=0; i<OrdersTotal(); i++)
         {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) // check for a opened position
               if(OrderStopLoss()== 0 && OrderTakeProfit()==0)
                  if (OrderSymbol()==Symbol())
                     if(OrderType()== OP_SELL)  // check if short position is open on symbol
                        bool res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-pips*StopLoss,OrderOpenPrice()+TakeProfit*pips,0,Green); //modify sell order
                           if(!res) // not a short position check if its a buy position
                              if(OrderType()==OP_BUY && OrderSymbol()==Symbol()) 
                                 bool ress=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+pips*StopLoss,OrderOpenPrice()-TakeProfit*pips,0,Red);  //modify buy order
         }
    }
  return(false);
}               
//-- end 

DashNex Pages - High Conversions Out of the Box
DashNex Pages - High Conversions Out of the Box
  • dashnexpages.com
Designed for Affiliates, Online Marketers, Small Businesses and other Creators, DashNex Pages is the fastest way to high converting lead generation campaign. Start now!
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Reason: