Download MetaTrader 5

Short or long only by code

To add comments, please log in or register
Patrick Chalindar
241
Patrick Chalindar  

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
Keith Watford
Moderator
10541
Keith Watford  
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‌

honest_knave
Moderator
2293
honest_knave  

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,... )
Patrick Chalindar
241
Patrick Chalindar  
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.

honest_knave
Moderator
2293
honest_knave  
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
To add comments, please log in or register