I have been playing with CExpert, CExpertSignal for trying to generate buy/sell signals. I have been able to use different signal classes to generate buy/sell. But I want to add one derived class of either CExpert or CExpertSignal which will either allow or disallow the trades based on other signals.
For example,
- Let's say this new AllowDirection is based on some logic of existing indicators. Say Stochastic. If the current AllowDirection is for Buy then any signal generated for Buy will have to be allowed and any signal for sell has to be rejected.
- The Actual buy/sell signals will be generated by any of the existing signal classes.
The existing code for using signal is written like below. The CSquareExpert class is a class derived from CExpert.
bool CSquareExpert::CheckOpenLong(void)
{
double price=EMPTY_VALUE;
double sl=0.0;
double tp=0.0;
datetime expiration=TimeCurrent();
//-- This is how I think I am considering using the logicbool buy_allowed = AllowDirection.BuyAllowed();
if(!buy_allowed)
returnfalse;
//--End of AllowDirection check code//--- check signal for long enter operationsif(m_signal.CheckOpenLong(price,sl,tp,expiration))
{
if(!m_trade.SetOrderExpiration(expiration))
m_expiration=expiration;
bool openLongResult = OpenLong(price,sl,tp);
if(openLongResult == false)
{
Print("Open Long Position Failed error:", GetLastError());
}
return openLongResult;
}
//--- return without operationsreturn(false);
}
Now I have tried implementing the AllowDirection signal class derived from CExpertSignal, but from the code I can only see it can be added only into the list of m_filters and not as a separate class. If I use this signal as a separate instance without adding into the m_filters array, it does not compute any LongCondition() or ShortCondition() values.
Do any one know how to write such a class to evaluate the condition and use it? Any suggestions appreciated.
Do any one know how to write such a class to evaluate the condition and use it? Any suggestions appreciated.
Thanks in advance!