please help how to pass comment from signal module into the following method to see comments in trade history?
bool CExpertTrade::Buy(double volume,double price,double sl,double tp,const string comment="")
Please elaborate about the question. Do you mean you want to pass string into "comment" field to this function?
Yes, comment based on the signal type from the signal (or money / trailing) module. For example:
- when the signal = 100 -> comment = "reversal buy trade"
- when the signal = 50 -> comment = "buy trade"
- when stoploss is executed -> comment = "S/L"
I am not experienced OOP programmer, so my idea was to have COMMENT variable and pass its value somehow into COMMENT parameter in the BUY method....
Or is there any better solution for this (override virtual function etc.)?
The quick but dirty way is to modify Expert.mqh file function:
bool CExpert::OpenLong(double price, double sl, double tp)
to accept your comment then pass into m_trade.Buy function:
bool CExpert::OpenLong(double price, double sl, double tp, string comment)
return (m_trade.Buy(lot, price, sl, tp, comment));
More elegant way might be to create new class by inherited from CExpert class, then override this OpenLong function.
Then also you need to override all function that calling OpenLong to use the new OpenLong you have been overridden.
IMO, if you want to messing up with the class, it's better to do it on CExpert class instead of CExpertTrade. But just to be aware that everything that you have modified might be replaced back to the original codes if there is a new update to metatrader.
Btw if I were you I will prefer to do the first quick and dirty way :)
I would prefer not to use dirty way exactly because of future Metatrader Wizard code updates.
But you are saying that even with more elegant way using overriding functions I must modify original Metatrader Wizard classes?
It is not possible to override it from my Signal class only? This 'comment' issue is just an example, I would like to learn and use these OOP procedures at general.
I received advice to use inheritance and create myExpert class with OpenLong function including 'comment' parameter. But it also means I must inherit all classes where the 'comment' parameter is missing:(
It seems to me like a big mess, where I will have basic Metatrader classes, Wizard classes and myWizard classes. So I am asking again, isn't it possible to use more convenient way using mySignal class only?
Can you give me efficient example?