Files
MQL5Data/XSTRCCI/Signals/xstrcci.signaller.class.mq5
T
2025-04-13 11:46:41 +03:30

523 lines
11 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: XCXSTRCCISignaller ...
// Description: Class for XSTRCCI Signaller ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm Class for XSTRCCI Signaller"
#property strict
//
// Imports ...
#include "../../Classes/x-saherelm.base.class.mq5"
#include "../../Classes/x-saherelm.x-cobject.class.mq5"
#include "../Helpers/xstrcci.helper.mq5"
#include "../Libraries/xstrcci.signaller.lib.mq5"
//
// Definitions ...
class XCXSTRCCISignaller : XCBase
{
//
// Public ...
public:
//
// Props ...
bool useGuards;
double rfReward;
bool isPassedBoxes;
XSTRCCIInputs inputs;
XBarTracker barTraker;
XCXSTRCCIHelper *helper;
bool continuesRFTillTarget;
XSTRCCIStrategyConditions mConditions;
XSTRCCIStrategyConditions mConditionsCollection[];
//
// Constructor ...
XCXSTRCCISignaller(
string _symbol,
ENUM_TIMEFRAMES _period //
)
{
//
symbol = _symbol;
period = _period;
Init();
}
//
// Deconstructor ...
~XCXSTRCCISignaller()
{
DeInit();
}
//
// Properties ...
string GetSymbol()
{
return symbol;
}
ENUM_TIMEFRAMES GetPeriod()
{
return period;
}
//
// Signaller Tools ...
/**
* Detect Setup Conditions based on Signalling ...
*
* @param maxAllowedSLDistanceInPoint: int, Max Allowed SL Distance in Points (if Bigger thn Zero Provided) ...
*
* @return ( bool )
*/
bool DetectSignalSetup(
double tpReward = 3,
double maxAllowedSLDistanceInPoint = 300 //
)
{
//
bool result = false;
//
// Check Bar Processing ...
if (!barTraker.CanProcessBar())
{
return result;
}
//
bool isBullish = false;
bool isBearish = false;
//
int zIndex = 0;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
int loopback = 10;
//
double ask = GetAsk(symbol);
double bid = GetBid(symbol);
datetime cTime = TimeCurrent();
double points = GetPoints(symbol);
//
mConditions.symbol = symbol;
mConditions.period = period;
//
XOHCL zBar;
XOHCL cBar;
XOHCL pBar;
XOHCL pPBar;
result = zBar.Init(
symbol,
period,
zIndex //
);
result =
result &&
zBar.GetPreviousBar(cBar);
result =
result &&
cBar.GetPreviousBar(pBar);
result =
result &&
pBar.GetPreviousBar(pPBar);
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
pPBar.Clean();
//
return result;
}
//
// Setup Conditions ...
double sls[];
double sl = 0;
double pivot = 0;
double point = 0;
double targets[];
XBoxZone signalBox;
bool hasSignalBox = false;
ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE;
//
// Checking Conditions ...
//
hasSignalBox = DetectXSTRCCIConditions(
signalBox,
signalBoxDir,
helper,
zIndex,
loopback //
);
//
isBullish = hasSignalBox &&
IsBullish(signalBoxDir);
//
isBearish = hasSignalBox &&
IsBearish(signalBoxDir);
//
result = isBullish ||
isBearish;
if (result)
{
//
// Do What we Want ...
barTraker.Waits();
}
//
// Cleanup Resource ...
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
pPBar.Clean();
//
return result;
}
/**
* Detect Trigger Conditions for Specified Signal ...
*
* @param conditions: XSTRCCIStrategyConditions instance Reference, Specified Signal Conditions ...
* @param maxAllowedSetupAge: specified Setup Age for Expiration (if bigger than Zero) ...
*
* @return ( bool )
*/
bool DetectSignalTrigger(
XSTRCCIStrategyConditions &conditions,
int maxAllowedSetupAge = 60 //
)
{
//
bool result = false;
//
result = conditions.IsSetuped();
if (!result)
{
return result;
}
//
datetime setupTime = conditions.setupTime;
ENUM_X_DIRECTION setupDir = conditions.dir;
//
bool isBullish = IsBullish(setupDir);
bool isBearish = IsBearish(setupDir);
//
int zIndex = 0;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
int loopback = 10;
//
double ask = GetAsk(symbol);
double bid = GetBid(symbol);
datetime cTime = TimeCurrent();
double points = GetPoints(symbol);
//
// Check Signal Validation ...
// IMPORTANT: since all Validations done in SetUp Process ...
// here we only Execute Signal ...
//
result = isBullish ||
isBearish;
//
if (result)
{
//
conditions.triggerTime = cTime;
conditions.type = isBullish
? X_POSITION_TYPE_LONG
: X_POSITION_TYPE_SHORT;
//
}
//
// Cleanup ...
//
return result;
}
/**
* Detect Guards bsed on Signalling Class ...
*
* @param guards: XSTRCCIGuard instance Collection, Holds Provided Guards ...
* @param positions: XPosition instance Collection, Provides Signalling Based Positions for Apply Guards on them ...
* @param provider: X121SMCStrategySignalProviderData instance Reference, Specified Data for Cycles ...
*
* @return ( bool )
*/
bool DetectGuards(
XSTRCCIGuard &guards[],
const XPosition &positions[] //
)
{
//
bool result = false;
//
return result;
}
/**
* Add Conditions to Conditions Collection if not Exists ...
*
* @param maxAllowed: int, Specified Max Allowed Holding Conditions ...
*
* @return ( int )
*/
int AddConditionsIfNotExists(
int maxAllowed = 10 //
)
{
//
int result = 0;
//
bool isSetuped = IsValid(mConditions.setupTime) &&
HasDirection(mConditions.dir);
if (!isSetuped)
{
return result;
}
//
int count = ArraySize(mConditionsCollection);
if (IsValidSize(count))
{
//
// Copy Original Items ...
XSTRCCIStrategyConditions tmpItems[];
Copy(
mConditionsCollection,
tmpItems //
);
//
// Prese Item Data ...
bool isBullish = IsBullish(mConditions.dir);
//
for (int i = 0; i < count; i++)
{
//
XSTRCCIStrategyConditions iItem = tmpItems[i];
//
bool canRemove = mConditions.dir == iItem.dir &&
mConditions.pivot == iItem.pivot;
if (canRemove)
{
//
ArrayRemove(
mConditionsCollection,
i,
1 //
);
}
}
//
Clean(tmpItems);
}
//
AddRef(
mConditions,
mConditionsCollection //
);
//
// Remove Olds ...
CleanupArray(
mConditionsCollection,
maxAllowed //
);
//
result = ArraySize(mConditionsCollection);
//
return result;
}
//
// Protected ...
protected:
//
//
// Private ...
private:
//
// Props ...
string symbol;
ENUM_TIMEFRAMES period;
CArrayObj mObjects;
CArrayObj mBarObjects;
/**
* Initialize ...
*/
void Init()
{
//
rfReward = 2;
useGuards = false;
isPassedBoxes = false;
continuesRFTillTarget = true;
//
barTraker.Init(
symbol,
period //
);
//
inputs.Default();
//
// Configure Indicators ...
//
// XCC ...
inputs.ccInputs.showCandles = true;
//
// XCT ...
inputs.ctInputs.showCandleTime = true;
//
// XPV ...
inputs.pvInputs.showSar = false;
inputs.pvInputs.showPeaks = false;
inputs.pvInputs.showVales = false;
inputs.pvInputs.showTrend = false;
inputs.pvInputs.showSwingLows = false;
inputs.pvInputs.showSwingHighs = false;
inputs.pvInputs.showGoldenZones = false;
inputs.pvInputs.showSupports = false;
inputs.pvInputs.showResistances = false;
//
// XSTR ...
inputs.strInputs.showStr = false;
inputs.strInputs.showVidya = false;
inputs.strInputs.showStrUpper = false;
inputs.strInputs.showStrLower = false;
inputs.strInputs.showStrSMLow = false;
inputs.strInputs.showStrSMHigh = false;
//
// X3MA ...
inputs.ma3Inputs.showX3MaFast = false;
inputs.ma3Inputs.showX3MaMid = false;
inputs.ma3Inputs.showX3MaSlow = true;
//
// XICH ...
inputs.ichInputs.showKumo = false;
inputs.ichInputs.showKijunSen = true;
inputs.ichInputs.showTenkanSen = true;
inputs.ichInputs.showChikouSpan = false;
inputs.ichInputs.showSenkouSpanA = false;
inputs.ichInputs.showSenkouSpanB = false;
//
// XOSCS ...
// inputs.oscsInputs.rsiLength = 5;
// inputs.oscsInputs.mfiLength = 5;
// inputs.oscsInputs.rviLength = 5;
// inputs.oscsInputs.cciLength = 5;
//
// Oscillators Views ...
inputs.showCCI = false;
inputs.showRSI = false;
inputs.showMFI = false;
inputs.showRVI = false;
inputs.showMACD = false;
//
// XSTRCCI Helper ...
helper = new XCXSTRCCIHelper();
helper.Init(
symbol,
period,
inputs //
);
}
/**
* DeInitialize ...
*/
void DeInit()
{
//
inputs.Clean();
ZeroMemory(helper);
//
mConditions.Clean();
Clean(mConditionsCollection);
//
mObjects.Clear();
mBarObjects.Clear();
//
barTraker.Clean();
}
//
};
//