forked from mnbvc188199/Warrior_EA
- Replaced standard library signal modules with custom implementations to allow for named patterns and improved voting. - Added new input parameters for module weights, allowing for optimization of individual signal contributions. - Enhanced the management of trades with new options for breakeven and management cut. - Introduced a mechanism for dynamic ranking of signal weights based on historical performance. - Improved initialization logic to ensure proper registration of filters and handling of trading conditions. - Added detailed logging for trading permissions and account status during initialization.
220 lines
8.7 KiB
MQL5
220 lines
8.7 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| Warrior_EA |
| |
//| AnimateDread |
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "..\Expert\WarriorSignal.mqh"
| |
// wizard description start
| |
//+------------------------------------------------------------------+
| |
//| Description of the class |
| |
//| Title=Signals of oscillator 'Relative Vigor Index' |
| |
//| Type=SignalAdvanced |
| |
//| Name=Relative Vigor Index |
| |
//| ShortName=RVI |
| |
//| Class=CSignalRVI |
| |
//| Page=signal_rvi |
| |
//| Parameter=PeriodRVI,int,14,Period of calculation |
| |
//+------------------------------------------------------------------+
| |
// wizard description end
| |
//+------------------------------------------------------------------+
| |
//| Class CSignalRVI. |
| |
//| Purpose: Class of generator of trade signals based on |
| |
//| the 'Relative Vigor Index' oscillator. |
| |
//| Is derived from the CWarriorSignal class. |
| |
//+------------------------------------------------------------------+
| |
class CSignalRVI : public CWarriorSignal
| |
{
| |
protected:
| |
CiRVI m_rvi; // object-oscillator
| |
//--- adjusted parameters
| |
int m_periodRVI; // the "period of calculation" parameter of the oscillator
| |
//--- "weights" of market models (0-100)
| |
int m_pattern_0; // model 0 "the oscillator has required direction"
| |
int m_pattern_1; // model 1 "crossing of main and signal line"
| |
| |
public:
| |
CSignalRVI(void);
| |
~CSignalRVI(void);
| |
//--- methods of setting adjustable parameters
| |
void PeriodRVI(int value) { m_periodRVI = value; }
| |
//--- methods of adjusting "weights" of market models
| |
void Pattern_0(int value) { m_pattern_0 = value; }
| |
void Pattern_1(int value) { m_pattern_1 = value; }
| |
virtual void ApplyPatternWeight(int patternNumber, int weight);
| |
//--- method of verification of settings
| |
virtual bool ValidationSettings(void);
| |
//--- method of creating the indicator and timeseries
| |
virtual bool InitIndicators(CIndicators *indicators);
| |
//--- methods of checking if the market models are formed
| |
virtual int LongCondition(void);
| |
virtual int ShortCondition(void);
| |
| |
protected:
| |
//--- method of initialization of the oscillator
| |
bool InitRVI(CIndicators *indicators);
| |
//--- methods of getting data
| |
double Main(int ind) { return(m_rvi.Main(ind)); }
| |
double DiffMain(int ind) { return(Main(ind) - Main(ind + 1)); }
| |
double Signal(int ind) { return(m_rvi.Signal(ind)); }
| |
double DiffSignal(int ind) { return(Signal(ind) - Signal(ind + 1)); }
| |
double DiffMainSignal(int ind) { return(Main(ind) - Signal(ind)); }
| |
};
| |
//+------------------------------------------------------------------+
| |
//| Constructor |
| |
//+------------------------------------------------------------------+
| |
CSignalRVI::CSignalRVI(void) : m_periodRVI(10),
| |
m_pattern_0(60),
| |
m_pattern_1(100)
| |
{
| |
m_id = "RVI";
| |
m_pattern_count = 2;
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Destructor |
| |
//+------------------------------------------------------------------+
| |
CSignalRVI::~CSignalRVI(void)
| |
{
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Validation settings protected data. |
| |
//+------------------------------------------------------------------+
| |
bool CSignalRVI::ValidationSettings(void)
| |
{
| |
//--- validation settings of additional filters
| |
if(!CExpertSignal::ValidationSettings())
| |
return(false);
| |
//--- initial data checks
| |
if(m_periodRVI <= 0)
| |
{
| |
printf(__FUNCTION__ + ": the period of calculation of the RVI oscillator must be greater than 0");
| |
return(false);
| |
}
| |
//--- ok
| |
return(true);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Create indicators. |
| |
//+------------------------------------------------------------------+
| |
bool CSignalRVI::InitIndicators(CIndicators *indicators)
| |
{
| |
//--- check pointer
| |
if(indicators == NULL)
| |
return(false);
| |
//--- initialization of indicators and timeseries of additional filters
| |
if(!CExpertSignal::InitIndicators(indicators))
| |
return(false);
| |
//--- create and initialize RVI oscillator
| |
if(!InitRVI(indicators))
| |
return(false);
| |
//--- ok
| |
return(true);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Initialize RVI oscillators. |
| |
//+------------------------------------------------------------------+
| |
bool CSignalRVI::InitRVI(CIndicators *indicators)
| |
{
| |
//--- check pointer
| |
if(indicators == NULL)
| |
return(false);
| |
//--- add object to collection
| |
if(!indicators.Add(GetPointer(m_rvi)))
| |
{
| |
printf(__FUNCTION__ + ": error adding object");
| |
return(false);
| |
}
| |
//--- initialize object
| |
if(!m_rvi.Create(m_symbol.Name(), m_period, m_periodRVI))
| |
{
| |
printf(__FUNCTION__ + ": error initializing object");
| |
return(false);
| |
}
| |
//--- ok
| |
return(true);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| "Voting" that price will grow. |
| |
//+------------------------------------------------------------------+
| |
int CSignalRVI::LongCondition(void)
| |
{
| |
int result = 0;
| |
int idx = StartIndex();
| |
//---
| |
if(DiffMain(idx) > 0.0)
| |
{
| |
//--- the main line of the oscillator is directed upwards confirming the possibility of price growth
| |
if(IS_PATTERN_USAGE(0))
| |
{
| |
result = m_pattern_0;
| |
m_active_pattern = "Pattern_0";
| |
}
| |
//--- if the main line crosses the signal line upwards, this is a signal for buying
| |
if(DiffMainSignal(idx) > 0 && DiffMainSignal(idx + 1) < 0)
| |
{
| |
//--- the main line of the oscillator has crossed the signal line upwards (signal for buying)
| |
if(IS_PATTERN_USAGE(1))
| |
{
| |
result = m_pattern_1;
| |
m_active_pattern = "Pattern_1";
| |
}
| |
}
| |
}
| |
if(result != 0)
| |
{
| |
m_active_direction = "Buy";
| |
}
| |
//--- return the result
| |
return(result);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| "Voting" that price will fall. |
| |
//+------------------------------------------------------------------+
| |
int CSignalRVI::ShortCondition(void)
| |
{
| |
int result = 0;
| |
int idx = StartIndex();
| |
//---
| |
if(DiffMain(idx) < 0.0)
| |
{
| |
//--- the main line of the oscillator is directed downwards confirming the possibility of falling of price
| |
if(IS_PATTERN_USAGE(0))
| |
{
| |
result = m_pattern_0;
| |
m_active_pattern = "Pattern_0";
| |
}
| |
//--- if the main line crosses the signal line from top downwards, this is a signal for selling
| |
if(DiffMainSignal(idx) < 0 && DiffMainSignal(idx + 1) > 0)
| |
{
| |
//--- the main line of the oscillator has crossed the signal line from top downwards (signal for selling)
| |
if(IS_PATTERN_USAGE(1))
| |
{
| |
result = m_pattern_1;
| |
m_active_pattern = "Pattern_1";
| |
}
| |
}
| |
}
| |
if(result != 0)
| |
{
| |
m_active_direction = "Sell";
| |
}
| |
//--- return the result
| |
return(result);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Set the specified pattern's weight to the specified value |
| |
//+------------------------------------------------------------------+
| |
void CSignalRVI::ApplyPatternWeight(int patternNumber, int weight)
| |
{
| |
switch(patternNumber)
| |
{
| |
default:
| |
break;
| |
case 0:
| |
Pattern_0(weight);
| |
break;
| |
case 1:
| |
Pattern_1(weight);
| |
break;
| |
}
| |
}
| |
//+------------------------------------------------------------------+
|