last works ...

This commit is contained in:
2024-08-01 02:18:31 +03:30
parent 5403a46aa5
commit 49a52f54d4
6 changed files with 1316 additions and 252 deletions
@@ -2,7 +2,7 @@
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXCHKMStrategy
// Name: XSCXCHStrategy
// Description: provides all based classes for use ...
//
//
@@ -36,20 +36,320 @@
// Base Classes ...
#include "../Classes/x-saherelm.xstrategy.class.mq5"
//
// Definitions ...
//
// Specific Identifier(s) of XStrategy ...
string XCHKMStartegyToken = "XCHKM";
string XCHStartegyToken = "XCH";
//
struct XCHStrategyConditions
{
//
// Props ...
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Helper Conditions ...
XPVConditions pvConditions;
XCHMConditions chmConditions;
XCHHKConditions chhkConditions;
XCHTDConditions chtdConditions;
XCHCHEConditions chcheConditions;
XCHSTRConditions chstrConditions;
XCHVLMConditions chvlmConditions;
//
// Constructor ...
void XCHStrategyConditions()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
symbol = NULL;
period = NULL;
time = NULL;
//
pvConditions.Clean();
chmConditions.Clean();
chhkConditions.Clean();
chtdConditions.Clean();
chcheConditions.Clean();
chstrConditions.Clean();
chvlmConditions.Clean();
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
IsValid(time) &&
IsValid(symbol) &&
IsValid(period)
//
;
//
return result;
}
//
// Generate Provided Scores ...
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
if (!IsValid())
{
return;
}
//
double bullScore = 0;
double bearScore = 0;
//
// XPV ...
pvConditions.GenerateScore(
bullScore,
bearScore //
);
bullishScore += bullScore;
bearishScore += bearScore;
//
// XCHM ...
chmConditions.GenerateScore(
bullScore,
bearScore //
);
bullishScore += bullScore;
bearishScore += bearScore;
//
// XCHHK ...
chhkConditions.GenerateScore(
bullScore,
bearScore //
);
bullishScore += bullScore;
bearishScore += bearScore;
//
// XCHTD ...
chtdConditions.GenerateScore(
bullScore,
bearScore //
);
bullishScore += bullScore;
bearishScore += bearScore;
//
// XCHCHE ...
chcheConditions.GenerateScore(
bullScore,
bearScore //
);
bullishScore += bullScore;
bearishScore += bearScore;
//
// XCHSTR ...
chstrConditions.GenerateScore(
bullScore,
bearScore //
);
bullishScore += bullScore;
bearishScore += bearScore;
//
// XCHVLM ...
chvlmConditions.GenerateScore(
bullScore,
bearScore //
);
bullishScore += bullScore;
bearishScore += bearScore;
}
//
// Generate Summary ...
string GenerateSummary(
bool onlyCommons = false,
bool onlyConditions = false,
bool includeScores = true,
bool ignoreFalseConditions = true,
string separator = "\n" //
)
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
GenerateScore(
bullishScore,
bearishScore //
);
//
string commonStr = GenerateSpecifiedCommonSummary(
this,
separator,
includeScores,
true //
);
//
// XPV ...
string pvStr = pvConditions.GenerateSummary(
false,
true,
false,
ignoreFalseConditions //
);
//
// XCHM ...
string chmStr = chmConditions.GenerateSummary(
false,
true,
false,
ignoreFalseConditions //
);
//
// XCHHK ...
string chhkStr = chhkConditions.GenerateSummary(
false,
true,
false,
ignoreFalseConditions //
);
//
// XCHTD ...
string chtdStr = chtdConditions.GenerateSummary(
false,
true,
false,
ignoreFalseConditions //
);
//
// XCHCHE ...
string chcheStr = chcheConditions.GenerateSummary(
false,
true,
false,
ignoreFalseConditions //
);
//
// XCHSTR ...
string chstrStr = chstrConditions.GenerateSummary(
false,
true,
false,
ignoreFalseConditions //
);
//
// XCHVLM ...
string chvlmStr = chvlmConditions.GenerateSummary(
false,
true,
false,
ignoreFalseConditions //
);
//
string conditionsStr =
//
pvStr + separator +
chmStr + separator +
chhkStr + separator +
chtdStr + separator +
chcheStr + separator +
chstrStr + separator +
chvlmStr + separator +
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
"----------" + separator +
(onlyConditions
? ""
: commonStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag()
{
return XCHStartegyToken;
}
//
};
//
typedef void (*TOnXCHSignal)(
XSignal &signal,
XCHStrategyConditions &conditions //
);
//
// XStrategy Class Implementation(s) ...
class XSCXCHKMStrategy : public XSCBaseStrategy
class XSCXCHStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXCHKMStrategy(
void XSCXCHStrategy(
//
// Base ...
string _symbol, // Trading Symbol
@@ -99,7 +399,7 @@ public:
//
// Deconstructor ...
void ~XSCXCHKMStrategy()
void ~XSCXCHStrategy()
{
//
delete pvHelper;
@@ -162,6 +462,20 @@ public:
mEnableXCHSTR = value;
}
//
// Event Handlers ...
//
// On Signal Handlers ...
void AddXCHSignalEventHandler(TOnXCHSignal handler)
{
//
Add(
handler,
mOnXCHSignalEventHandlers //
);
}
//
// Overrides ...
@@ -169,7 +483,7 @@ public:
// Customize Strategy Identifier ...
string GetTag() override
{
return XCHKMStartegyToken;
return XCHStartegyToken;
}
//
@@ -228,6 +542,15 @@ public:
return result;
}
//
// XCHTD ...
XCHTDConditions chtdConditions;
result = chtdHelper.GetConditions(chtdConditions);
if (!result)
{
return result;
}
//
// XCHSTR ...
XCHSTRConditions chstrConditions;
@@ -246,6 +569,15 @@ public:
return result;
}
//
// XCHVLM ...
XCHVLMConditions chvlmConditions;
result = chvlmHelper.GetConditions(chvlmConditions);
if (!result)
{
return result;
}
//
// Start Calculations ...
@@ -382,6 +714,13 @@ public:
double chhkMaxBullishLow = chhkHelper.GetMaxBullishLow(cIndex);
double chhkMinBullishLow = chhkHelper.GetMinBullishLow(cIndex);
//
// XCHTD ...
//
double chtdBullishPower = chtdHelper.GetBullishPower(cIndex);
double chtdBearishPower = chtdHelper.GetBearishPower(cIndex);
//
// XCHSTR ...
@@ -408,6 +747,50 @@ public:
double chcheMaxBearish = chcheHelper.GetBearishMax(cIndex);
double chcheMinBearish = chcheHelper.GetBearishMin(cIndex);
//
// Change XCHCHE Current State ...
if (chcheConditions.cLE1[pIndex] > 0 &&
chcheConditions.cLE2[pIndex] > 0 &&
chcheConditions.cLE1[pIndex] != EMPTY_VALUE &&
chcheConditions.cLE2[pIndex] != EMPTY_VALUE &&
!chcheConditions.isCStrongBullish)
{
//
chcheCLastLongExitTime = pBar.time;
chcheCLastLongExit1 = chcheConditions.cLE1[pIndex];
chcheCLastLongExit2 = chcheConditions.cLE2[pIndex];
}
//
if (chcheConditions.cSE1[pIndex] > 0 &&
chcheConditions.cSE2[pIndex] > 0 &&
chcheConditions.cSE1[pIndex] != EMPTY_VALUE &&
chcheConditions.cSE2[pIndex] != EMPTY_VALUE &&
!chcheConditions.isCStrongBearish)
{
//
chcheCLastShortExitTime = pBar.time;
chcheCLastShortExit1 = chcheConditions.cSE1[pIndex];
chcheCLastShortExit2 = chcheConditions.cSE2[pIndex];
}
//
double chcheMinCBullish = chcheHelper.GetCycleBullishMin(
cIndex,
X_MARKET_CYCLE_UNKNOWN // Current ...
);
double chcheMaxCBearish = chcheHelper.GetCycleBearishMax(
cIndex,
X_MARKET_CYCLE_UNKNOWN // Current ...
);
//
// XCHVLM ...
//
double chvlmBullishPower = chvlmHelper.GetBullishPower(cIndex);
double chvlmBearishPower = chvlmHelper.GetBearishPower(cIndex);
//
DetectImportantAreas();
@@ -657,19 +1040,20 @@ public:
if (mEnableXCHCHE)
{
//
if (chcheConditions.isBullishPowerUp)
if (chcheConditions.isCStrongBullish)
{
//
bool chcheHasLong =
//
hasBullishPower &&
HasCHCHECLast() &&
cBar.IsBullish() &&
cBar.low > chcheMinBullish &&
chcheConditions.isBullishPowerUp &&
chcheConditions.isCStrongBearish &&
(chmConditions.hasBullishPower ||
chhkConditions.hasBullishPower ||
chstrConditions.hasBullishPower)
chcheMinCBullish > 0 &&
hasBullishPattern &&
hasBullishPressure &&
chcheConditions.hasBullishPower &&
chcheConditions.isCStrongBullish &&
chcheMinCBullish > GetMaxCHCHECLast()
//
;
@@ -695,19 +1079,20 @@ public:
}
//
if (chcheConditions.isBearishPowerUp)
if (chcheConditions.isCStrongBearish)
{
//
bool chcheHasShort =
//
hasBearishPower &&
HasCHCHECLast() &&
cBar.IsBearish() &&
cBar.high < chcheMaxBearish &&
chcheConditions.isBearishPowerUp &&
chcheMaxCBearish > 0 &&
hasBearishPattern &&
hasBearishPressure &&
chcheConditions.hasBearishPower &&
chcheConditions.isCStrongBearish &&
(chmConditions.hasBearishPower ||
chhkConditions.hasBearishPower ||
chstrConditions.hasBearishPower)
chcheMaxCBearish > GetMaxCHCHECLast()
//
;
@@ -852,12 +1237,49 @@ protected:
XCHVLMInputs chvlmInputs;
XSCXCHVLMHelper *chvlmHelper;
//
//
// Private ...
private:
//
// Props ...
//
// On XCH Signal Recieved Event Handler(s) ...
TOnXCHSignal mOnXCHSignalEventHandlers[];
//
// Notified Signal Event Handler(s) ...
void NotifyOnXCHSignalEventHandlers(
XSignal &signal,
XCHStrategyConditions &conditions //
)
{
//
if (!signal.IsValid() || !conditions.IsValid())
{
return;
}
//
int count = ArraySize(mOnXCHSignalEventHandlers);
if (!IsValidSize(count))
{
return;
}
//
for (int i = 0; i < count; i++)
{
//
mOnXCHSignalEventHandlers[i](
signal,
conditions //
);
}
}
//
// Install all Helpers and Prepare all
// Configurations for required Indicators ...
@@ -1146,6 +1568,114 @@ private:
}
//
// XCHE Custom Data ...
//
double chcheCLastLongExit1;
double chcheCLastLongExit2;
datetime chcheCLastLongExitTime;
double GetMaxCHCHECLastLong()
{
//
return MathMax(
chcheCLastLongExit1,
chcheCLastLongExit2 //
);
}
double GetMinCHCHECLastLong()
{
//
return MathMin(
chcheCLastLongExit1,
chcheCLastLongExit2 //
);
}
//
double chcheCLastShortExit1;
double chcheCLastShortExit2;
datetime chcheCLastShortExitTime;
double GetMaxCHCHECLastShort()
{
//
return MathMax(
chcheCLastShortExit1,
chcheCLastShortExit2 //
);
}
double GetMinCHCHECLastShort()
{
//
return MathMin(
chcheCLastShortExit1,
chcheCLastShortExit2 //
);
}
//
double GetMaxCHCHECLast()
{
//
return MathMax(
GetMaxCHCHECLastLong(),
GetMaxCHCHECLastShort() //
);
}
double GetMinCHCHECLast()
{
//
return MathMin(
GetMinCHCHECLastLong(),
GetMinCHCHECLastShort() //
);
}
//
bool HasCHCHECLast()
{
//
bool result = false;
//
result =
IsValid(chcheCLastLongExitTime) ||
IsValid(chcheCLastShortExitTime);
//
return result;
}
//
};
//
// Conditions Parser ...
struct XCHStartegyConditionsParser
{
//
string _version;
//
bool IsFiltered(
XSignal &signal, // Provided Signal
XCHStrategyConditions &conditions // Market Conditions
)
{
//
bool result = false;
//
// Validate Args ...
if (!signal.IsValid() || !conditions.IsValid())
{
//
result = true;
return result;
}
//
return result;
}
};
//