Need help to fix this code.

 

Hi,

i am not a very good programmer, but i somehow managed to write one using a tutorial. 

 The problem is when a buy/Sell order is placed SL and TP price is set to null although i set in the code.

Setup: 

Place the Support_and_Resistance.mql in the indicator folder. and EA1.mql in the Expert folder.

 Strategy:

Entry:-> Once the day is closed, check if the close is above resistance level or below support level. if above go for long and if below go for short.

SL -> Close (+/-) ATR(15)

TP -> Close (+/-) 2 * ATR(15)

 Regards

Sujay 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM - Documentation on MQL5
Files:
 

Your broker may be using market order, therefore you may have to send open buy/sell without SL/TP and later, when your position is opened, you can add SL/TP . However, there are some report in forum, that after open a position, you may have to wait for several milli second before adding SL/TP, and there are other report in forum that no matter how hard we try, the SL/TP will still be null. In later case, your broker may be not accepting SL/TP but accepting opposite pending orders as SL/TP. So, in this case, if you open buy position, send Sell Stop as SL and Sell Limit as TP and vice versa.

I haven't read your codes - so no reviews yet on them. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5