Need help me mql4 guru add take profit to this EA

 
extern double    Lots=0.1;
datetime NewTime=0;
int start()
  {
    if(NewTime!=Time[0])
    {
      NewTime=Time[0];
      if(Close[1]>=Open[1])
        OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,NULL,0,0,Blue);
      else
        OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,NULL,0,0,Red);        
    }
    return(0);
  }
//+------------------------------------------------------------------+

 

Tell me how to add take profit 

 
gayathri k:

Tell me how to add take profit 

This is the simplest way, but it leaves a lot to be desired, does not work with ECN brokers.


extern double    Lots=0.1;
extern int TakeProfit=30; // Take profit value in points
datetime NewTime=0;
int start()
  {
   if(NewTime!=Time[0])
     {
      NewTime=Time[0];
      if(Close[1]>=Open[1])
         OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+(TakeProfit*_Point),NULL,0,0,Blue);
      else
         OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-(TakeProfit*_Point),NULL,0,0,Red);
     }
   return(0);
  }
//+------------------------------------------------------------------+
 
John Davis:

This is the simplest way, but it leaves a lot to be desired, does not work with ECN brokers.


Dear John Davis

 

its ok  i will use normal broker

 
John Davis:

This is the simplest way, but it leaves a lot to be desired, does not work with ECN brokers.


but why it won't work in ECN brokers?!
 
Mohammad Soubra:
but why it won't work in ECN brokers?!

Because in ECN you have to open position without TP and SL in the ordersend function and then after the position is opened you use ordermodify function to set TP and SL.

gayathri k:

Tell me how to add take profit 

Please dont double post.

 
Marco vd Heijden:

Because in ECN you have to open position without TP and SL in the ordersend function and then after the position is opened you use ordermodify function to set TP and SL.


But i tried in one ecn and it was working fine!
 
Mohammad Soubra:
But i tried in one ecn and it was working fine!

Fake ECN !

Haha.

No maybe it's just some broker i dont know but it does cause problem sometimes or most of the time.

 

Marco vd Heijden: Because in ECN you have to open position without TP and SL in the ordersend function and then after the position is opened you use ordermodify function to set TP and SL.

Fake ECN !

Haha.

No maybe it's just some broker i dont know but it does cause problem sometimes or most of the time.

I too was once under that assumption, but @Alain Verleyen informed me that it is no longer the case since many builds ago (a few years back). Now ALL account types or brokers, will accept the S/L and T/P on the OrderSend().

I did not believe him at first, so I did some research and testing and can confirm that he is correct. There is no longer a need to split the operation into two parts.

The discussion was heated due to my ignorance but he was (and is) correct:

Forum on trading, automated trading systems and testing trading strategies

stop loss order not being placed

Fernando Carreiro, 2016.11.08 19:03

Even when I show you proof (via the screen-shots)? Well, it seems you have never traded with a decent ECN broker then!

Forum on trading, automated trading systems and testing trading strategies

stop loss order not being placed

Alain Verleyen, 2016.11.08 19:06

You really don't know what you are talking about.

  • Where in the documentation do you see some restrictions about placing SL/TP on Market execution ? Via GUI or code.
  • Here a screenshot from a real account, ECN broker :


  • Here is the log from an order placed with SL/TP at once :

2016.11.08 19:18:17.430    'XXXXXX': order was opened : #11987283 sell 0.01 EURUSD at 1.10248 sl: 1.10258 tp: 1.10237
2016.11.08 19:18:16.996    'XXXXXX': order sell market 0.01 EURUSD sl: 1.10258 tp: 1.10237

  • On the MT4 GUI it was available later, but I don't remember from which build.

  • P.S: I found the announcement about MT4 GUI, it was on build 710.
  • Terminal: Allowed specification of Stop Loss and Take Profit when opening a position for a Market Execution type symbol.

 
gayathri k: Tell me how to add take profit 
  1. Don't double post
  2. #2 gave you your answer.
 
Fernando Carreiro:

I too was once under that assumption, but @Alain Verleyen informed me that it is no longer the case since many builds ago (a few years back). Now ALL account types or brokers, will accept the S/L and T/P on the OrderSend().

I did not believe him at first, so I did some research and testing and can confirm that he is correct. There is no longer a need to split the operation into two parts.

The discussion was heated due to my ignorance but he was (and is) correct:


I followed your threads and learned something new today, thanks. The above code should work on ECN brokers also! Great.

Reason: