Warrior_EA/Signals/SignalIB.mqh
super.admin 0a527b0cf9 convert
2025-05-30 16:35:54 +02:00

140 lines
5.8 KiB
MQL5

//+------------------------------------------------------------------+
//| SignalIB.mqh |
//+------------------------------------------------------------------+
#property copyright "AnimateDread"
#property version "1.0"
#property description "Inside Bar Signal"
//+------------------------------------------------------------------+
//| include files |
//+------------------------------------------------------------------+
#include "..\Expert\ExpertSignalCustom.mqh"
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class |
//| Title=Signal of candle pattern 'Inside Bar' |
//| Type=SignalAdvanced |
//| Name=Inside Bar Pattern |
//| ShortName=IB |
//| Class=CSignalIB |
//| Page= |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| CSignalIB class. |
//| Purpose: Class of trading signal Inside Bar Pattern |
//| It is derived from the CExpertSignalCustom class. |
//+------------------------------------------------------------------+
class CSignalIB : public CExpertSignalCustom
{
protected:
//--- Pattern weights
int m_pattern_0;
public:
CSignalIB();
~CSignalIB();
//--- methods of adjusting "weights" of market models
void Pattern_0(int value) { m_pattern_0 = value; }
virtual void ApplyPatternWeight(int patternNumber, int weight);
//--- Methods to generate signals to enter the market
virtual int LongCondition(void);
virtual int ShortCondition(void);
};
//+------------------------------------------------------------------+
//| Constructor. |
//+------------------------------------------------------------------+
CSignalIB::CSignalIB() : m_pattern_0(10)
{
m_id = "IB";
m_pattern_count = 1;
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CSignalIB::~CSignalIB(void)
{
}
//+------------------------------------------------------------------+
//| "Voting" that price will grow. |
//+------------------------------------------------------------------+
int CSignalIB::LongCondition(void)
{
int result = 0;
int idx = StartIndex();
int prevIdx = idx + 1;
if(IS_PATTERN_USAGE(0))
{
// Get the high and low of the mother bar (prevIdx)
double motherBarHigh = High(prevIdx);
double motherBarLow = Low(prevIdx);
// Get the high and low of the inside bar (idx)
double insideBarHigh = High(idx);
double insideBarLow = Low(idx);
// Check if the inside bar is within the range of the mother bar
bool isInsideBar = (insideBarHigh < motherBarHigh) && (insideBarLow > motherBarLow);
// Check if the inside bar is towards the top of the mother bar
bool isConsolidationAtTop = (insideBarHigh > (motherBarLow + (motherBarHigh - motherBarLow) / 2));
// Determine the pattern result based on the conditions
if(isInsideBar && isConsolidationAtTop)
{
result = m_pattern_0;
m_active_pattern = "Pattern_0";
}
}
if(result != 0)
{
m_active_direction = "Buy";
}
// Return the result
return result;
}
//+------------------------------------------------------------------+
//| "Voting" that price will fall. |
//+------------------------------------------------------------------+
int CSignalIB::ShortCondition(void)
{
int result = 0;
int idx = StartIndex();
int prevIdx = idx + 1;
if(IS_PATTERN_USAGE(0))
{
// Get the high and low of the mother bar (prevIdx)
double motherBarHigh = High(prevIdx);
double motherBarLow = Low(prevIdx);
// Get the high and low of the inside bar (idx)
double insideBarHigh = High(idx);
double insideBarLow = Low(idx);
// Check if the inside bar is within the range of the mother bar
bool isInsideBar = (insideBarHigh < motherBarHigh) && (insideBarLow > motherBarLow);
// Check if the inside bar is towards the bottom of the mother bar
bool isConsolidationAtBottom = (insideBarLow < (motherBarHigh - (motherBarHigh - motherBarLow) / 2));
// Determine the pattern result based on the conditions
if(isInsideBar && isConsolidationAtBottom)
{
result = m_pattern_0;
m_active_pattern = "Pattern_0";
}
}
if(result != 0)
{
m_active_direction = "Sell";
}
// Return the result
return result;
}
//+------------------------------------------------------------------+
//| Set the specified pattern's weight to the specified value |
//+------------------------------------------------------------------+
void CSignalIB::ApplyPatternWeight(int patternNumber, int weight)
{
switch(patternNumber)
{
default:
break;
case 0:
Pattern_0(weight);
break;
}
}
//+------------------------------------------------------------------+