Short or long only by code

 

Hi,

Is it possible to oblige an EA to trade only long or short from code. I know it's possible manualy, but by code?

‌If, yes what command have to use please?

Thanks‌

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Reference on algorithmic/automated trading language for MetaTrader 5
 
neo-13:

Hi,

Is it possible to oblige an EA to trade only long or short from code. I know it's possible manualy, but by code?

‌If, yes what command have to use please?

Thanks‌


If you want it to trade only long then wherever your code would open a short, remove the OrderSend

You could also open the common tab of the EA's inputs window and select which way you want to trade‌

 

You could use a couple of flags‌

bool buy_allowed  = true,
     sell_allowed = false;

if(buy_allowed && /*logic to trigger buy*/) OrderSend(_Symbol,OP_BUY,... )
 
honest_knave:

You could use a couple of flags‌


Thanks so much,

b‌ut I'm sorry I see I haven't ask my question correctly.

T‌hat I have forgot to mention, is to change EA setting in only buy or short, from an other chart/EA.

T‌hank's.

 
neo-13:


Thanks so much,

b‌ut I'm sorry I see I haven't ask my question correctly.

T‌hat I have forgot to mention, is to change EA setting in only buy or short, from an other chart/EA.

T‌hank's.


Same principle, but use Global Variables of the Terminal 
Global Variables of the Terminal - MQL4 Reference
Global Variables of the Terminal - MQL4 Reference
  • docs.mql4.com
Global Variables of the Terminal - MQL4 Reference