CExpertSignal close position

 

Hello all, 

I'm writing my first EA based on Standard Library.  I was able to write my custom signal class inherited from CExpertSignal, it works fine in opening long and short position. Now I want to add the ability to close that position when the signals say so, just I fail to see to implement it. 

 I tried to customize the functions CheckCloseLong and CheckCloseShort without success. The examples provided with MT5 (folder include\expert\signal), as far i can understand them, show only how to open the position.

Could anyone give some info or just the link to example pages.

 Thanks 

 

you open another order but in opposite direction and with same lot size then it will cancel out/ close the first position.

or you double the lot size and it will open a new orders in opposite direction with same amount of lots.

 
albino15:

Hello all, 

I'm writing my first EA based on Standard Library.  I was able to write my custom signal class inherited from CExpertSignal, it works fine in opening long and short position. Now I want to add the ability to close that position when the signals say so, just I fail to see to implement it. 

 I tried to customize the functions CheckCloseLong and CheckCloseShort without success. The examples provided with MT5 (folder include\expert\signal), as far i can understand them, show only how to open the position.

Could anyone give some info or just the link to example pages.

 Thanks 

You have to code your close conditions in the same way as your open condition, in your custome signal module LongCondition() and ShortCondition(). See an example in this code.

See also

All about MQL5 Wizard : create robots without programming.
All about MQL5 Wizard : create robots without programming.
  • www.mql5.com
What is MQL5 Wizard :The MetaTrader 5 Trading Platform includes the MQL5 Wizard, which allows to quickly generate code of an Expert Advisor (Expert Advisor builder). - - Category: general
 
Alain Verleyen:

You have to code your close conditions in the same way as your open condition, in your custome signal module LongCondition() and ShortCondition(). See an example in this code.

See also

It is exactly what i was looking for. Thanks
Reason: