add support for XPV inside Market Cycles ...

This commit is contained in:
2024-06-19 11:40:05 +03:30
parent 160dc7fcc0
commit 7bae4c6723
6 changed files with 1721 additions and 31 deletions
+448 -26
View File
@@ -26,9 +26,11 @@
//
#include "../Libraries/x-saherelm.xtrade.lib.mq5"
#include "../Classes/x-saherelm.xalert.class.mq5"
#include "../Classes/x-saherelm.xczone.class.mq5"
#include "../Classes/x-saherelm.xsczone.class.mq5"
#include "../Classes/x-saherelm.xsctrend.class.mq5"
//
#include "../Helpers/x-saherelm.xpv.helper.mq5"
#include "../Helpers/x-saherelm.xtd.helper.mq5"
#include "../Helpers/x-saherelm.xhk.helper.mq5"
#include "../Helpers/x-saherelm.xstr.helper.mq5"
@@ -204,6 +206,7 @@ struct X121SetupInputs
//
// Helpers Inputs ...
XPVInputs pvInputs; // XPV Inputs
XTDInputs tdInputs; // XTD Inputs
XHKInputs hkInputs; // XHK Inputs
XCHEInputs cheInputs; // XCHE Inputs
@@ -240,6 +243,7 @@ struct X121SetupInputs
bool Init(
string _symbol, // Symbol
ENUM_TIMEFRAMES _period, // Time Frame
XPVInputs &_pvInputs, // XPV Inputs
XTDInputs &_tdInputs, // XTD Inputs
XHKInputs &_hkInputs, // XHK Inputs
XCHEInputs &_cheInputs, // XCHE Inputs
@@ -261,6 +265,7 @@ struct X121SetupInputs
//
// Helpers Inputs ...
this.pvInputs = _pvInputs;
this.tdInputs = _tdInputs;
this.hkInputs = _hkInputs;
this.cheInputs = _cheInputs;
@@ -294,6 +299,7 @@ struct X121SetupInputs
period = NULL;
//
pvInputs.Clean();
tdInputs.Clean();
hkInputs.Clean();
cheInputs.Clean();
@@ -314,6 +320,7 @@ struct X121SetupInputs
void Default()
{
//
pvInputs.Default();
tdInputs.Default();
hkInputs.Default();
cheInputs.Default();
@@ -355,6 +362,13 @@ struct X121SetupInputs
return result;
}
//
result = pvInputs.IsValid();
if (!result)
{
return result;
}
//
result = hkInputs.IsValid();
if (!result)
@@ -456,6 +470,7 @@ struct X121SetupConditions
//
// Conditions ...
XPVConditions pvConditions;
XTDConditions tdConditions;
XHKConditions hkConditions;
XCHEConditions cheConditions;
@@ -531,6 +546,14 @@ struct X121SetupConditions
bullishScore += tempBullishScore;
bearishScore += tempBearishScore;
//
pvConditions.GenerateScore(
tempBullishScore,
tempBearishScore //
);
bullishScore += tempBullishScore;
bearishScore += tempBearishScore;
//
adxtdConditions.GenerateScore(
tempBullishScore,
@@ -659,6 +682,7 @@ struct X121SetupConditions
);
//
string pvSummary = pvConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
string tdSummary = tdConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
string hkSummary = hkConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
string strSummary = strConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
@@ -675,6 +699,7 @@ struct X121SetupConditions
//
string conditionsStr =
//
pvSummary + separator +
tdSummary + separator +
hkSummary + separator +
ichSummary + separator +
@@ -2259,7 +2284,7 @@ struct X121SignalGenerator
//
bool IsConditionsValidForLong(
X121SetupConditions &conditions, // Conditions
int verifications = 4 // Number of Verifications
int verifications = 4 // Number of Verifications
)
{
//
@@ -2515,7 +2540,7 @@ struct X121SignalGenerator
//
bool IsConditionsValidForShort(
X121SetupConditions &conditions, // Conditions
int verifications = 4 // Number of Verifications
int verifications = 4 // Number of Verifications
)
{
//
@@ -2755,6 +2780,22 @@ struct X121SignalGenerator
signal.zones = zones;
}
//
// Calculate Trend ...
XSCTrend *trend = new XSCTrend(
signal.symbol,
signal.period //
);
//
XSCTrendInput tInputs;
tInputs.Default();
bool canUseTrend = trend.Init(tInputs);
if (canUseTrend)
{
signal.trend = trend;
}
//
// Generate Support Signals ...
if (_useSupport)
@@ -2787,6 +2828,27 @@ struct X121SignalGenerator
//
bool canUseZones = signal.zones != NULL;
bool canUseTrend = signal.trend != NULL &&
signal.trend.IsValid();
//
XSignal rSignal; // Recovery Signal ...
//
double rSL = 0; // Recovery Stop Loss ...
double rTP = 0; // Recovery Take Profit ...
double rEntry = 0; // Recovery Entry Point ...
double rVolume = signal.volume * 2; // Recovery Volume ...
ENUM_POSITION_TYPE rType; // Recovery Signal Type ...
ENUM_X_ORDER_MODES rMode; // Recovery Signal Mode ...
bool isSignalPrepared = false; // Check Signal Preparation Succeed ...
//
double exitPrice = GetExit(signal.symbol, signal.type);
double entryPrice = GetEntry(signal.symbol, signal.type);
//
double onePointValue = PointToPrice(1, signal.symbol);
//
// Check Signal Has TP and SL ...
@@ -2821,21 +2883,6 @@ struct X121SignalGenerator
// Try to Find a Hot Level based on Signal Direction
// as Resistance ...
//
XSignal rSignal; // Recovery Signal ...
//
double rSL = 0; // Recovery Stop Loss ...
double rTP = 0; // Recovery Take Profit ...
double rEntry = 0; // Recovery Entry Point ...
double rVolume = signal.volume * 2; // Recovery Volume ...
ENUM_POSITION_TYPE rType; // Recovery Signal Type ...
ENUM_X_ORDER_MODES rMode; // Recovery Signal Mode ...
bool isSignalPrepared = false; // Check Signal Preparation Succeed ...
//
double onePointValue = PointToPrice(1, signal.symbol);
//
for (int i = 0; i < signal.zones.CountZones(); i++)
{
@@ -2878,10 +2925,10 @@ struct X121SignalGenerator
// Opposit Support on Resistance Upper ...
//
rTP = signal.sl <= 0
? iZone.high - (onePointValue * 15)
: signal.sl;
rSL = signal.entry;
// rTP = signal.sl <= 0
// ? iZone.high - (onePointValue * 15)
// : signal.sl;
// rSL = signal.entry;
rType = POSITION_TYPE_BUY;
rEntry = iZone.high + (onePointValue * 2);
rMode = X_ORDER_MODE_STOP;
@@ -2920,10 +2967,10 @@ struct X121SignalGenerator
// Support Directional on Resistance Lower ...
//
rTP = signal.entry;
rSL = signal.sl <= 0
? signal.entry - (onePointValue * 15)
: signal.sl;
// rTP = signal.entry;
// rSL = signal.sl <= 0
// ? signal.entry - (onePointValue * 15)
// : signal.sl;
rEntry = iZone.low - (onePointValue * 2);
rVolume = signal.volume * 3;
rType = POSITION_TYPE_SELL;
@@ -2969,6 +3016,355 @@ struct X121SignalGenerator
}
}
}
//
if (canUseTrend)
{
//
// Check Ask and Bid Price ...
//
XOHCL fHighBar = signal.trend.GetFirstSwingHighBar();
XOHCL sHighBar = signal.trend.GetSecondSwingHighBar();
//
XOHCL fLowBar = signal.trend.GetFirstSwingLowBar();
XOHCL sLowBar = signal.trend.GetSecondSwingLowBar();
//
double twoPoint = onePointValue * 2;
double fiftyPoint = onePointValue * 15;
//
// add resistance ...
bool canAdd =
isLong &&
entryPrice < (sHighBar.high - fiftyPoint);
if (canAdd)
{
//
rSignal.Clean();
//
rEntry = sHighBar.high - fiftyPoint;
rType = POSITION_TYPE_BUY;
rMode = X_ORDER_MODE_STOP;
rVolume = signal.volume * 2;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
//
rEntry = sHighBar.high - fiftyPoint;
rType = POSITION_TYPE_SELL;
rMode = X_ORDER_MODE_LIMIT;
rVolume = signal.volume * 3;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
}
//
canAdd =
isLong &&
entryPrice > (sLowBar.low + fiftyPoint);
if (canAdd)
{
//
rSignal.Clean();
//
rEntry = (sLowBar.low + fiftyPoint);
rType = POSITION_TYPE_SELL;
rMode = X_ORDER_MODE_STOP;
rVolume = signal.volume * 2;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
//
rEntry = (sLowBar.low - fiftyPoint);
rType = POSITION_TYPE_BUY;
rMode = X_ORDER_MODE_LIMIT;
rVolume = signal.volume * 3;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
}
//
// add support ...
canAdd =
!isLong &&
entryPrice > (sLowBar.low + fiftyPoint);
if (canAdd)
{
//
rSignal.Clean();
//
rEntry = sLowBar.low + fiftyPoint;
rType = POSITION_TYPE_SELL;
rMode = X_ORDER_MODE_STOP;
rVolume = signal.volume * 2;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
//
rEntry = sLowBar.low + fiftyPoint;
rType = POSITION_TYPE_BUY;
rMode = X_ORDER_MODE_LIMIT;
rVolume = signal.volume * 3;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
}
//
canAdd =
!isLong &&
entryPrice < (sHighBar.high - fiftyPoint);
if (canAdd)
{
//
rSignal.Clean();
//
rEntry = (sHighBar.high - fiftyPoint);
rType = POSITION_TYPE_BUY;
rMode = X_ORDER_MODE_STOP;
rVolume = signal.volume * 2;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
//
rEntry = (sHighBar.high - fiftyPoint);
rType = POSITION_TYPE_SELL;
rMode = X_ORDER_MODE_LIMIT;
rVolume = signal.volume * 3;
//
isSignalPrepared = rSignal.Prepare(
signal.symbol,
signal.provider,
signal.period,
rType,
rMode,
rEntry,
rVolume,
rSL,
rTP //
);
if (isSignalPrepared)
{
//
AddRef(
rSignal,
signal.supports //
);
//
rSignal.Clean();
//
rSL = 0;
rTP = 0;
rEntry = 0;
isSignalPrepared = false;
}
}
}
}
//
@@ -2987,6 +3383,7 @@ class XSCX121Setup : public XSCBaseAlert
public:
//
// Props ...
XSCXPVHelper *pvHelper;
XSCXTDHelper *tdHelper;
XSCXHKHelper *hkHelper;
XSCXCHEHelper *cheHelper;
@@ -3010,6 +3407,7 @@ public:
void ~XSCX121Setup()
{
//
delete pvHelper;
delete tdHelper;
delete hkHelper;
delete cheHelper;
@@ -3064,6 +3462,19 @@ public:
//
// Initialize Helpers ...
//
// XPV ...
pvHelper = new XSCXPVHelper();
result = pvHelper.Init(
inputs.symbol,
inputs.period,
inputs.pvInputs //
);
if (!result)
{
return result;
}
//
// XTD ...
tdHelper = new XSCXTDHelper();
@@ -3271,6 +3682,17 @@ public:
conditions.period = GetPeriod();
conditions.time = TimeCurrent();
//
result = pvHelper.GetConditions(
conditions.pvConditions,
barIndex,
loopback //
);
if (!result)
{
return result;
}
//
result = tdHelper.GetConditions(
conditions.tdConditions,
+55
View File
@@ -0,0 +1,55 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCRange
// Description: provides all Range requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.xtrade.lib.mq5"
#include "../Classes/x-saherelm.xaccount.class.mq5"
//
// Definitions ...
//
enum ENUM_XSCRANGE_CALCULATION_MODE {
//
XSCRANGE_CALCULATE_MANUALLY = 0,
XSCRANGE_CALCULATE_DAILY = 1,
XSCRANGE_CALCULATE_HALFDAY = 2,
XSCRANGE_CALCULATE_4H = 3,
};
//
struct XSCRangeInput
{
//
// Props ...
//
datetime startTime; // Range Start Time
datetime endTime; // Range End Time
//
int lifetime; // Range Live Time (Secconds)
//
};
@@ -321,7 +321,7 @@ public:
//
result = mSymbol + "_" +
ToString(mPeriod) +
ToString(mPeriod) + "_" +
ToFormatString(zBar.time);
//
@@ -422,7 +422,10 @@ public:
//
double support = secondSwingLowBar.low;
datetime supportTime = secondSwingLowBar.time;
datetime supportTime =
secondSwingLowBar.time > secondSwingHighBar.time
? secondSwingHighBar.time
: secondSwingLowBar.time;
string supportName =
//
identifier +
@@ -436,7 +439,11 @@ public:
//
double resistance = secondSwingHighBar.high;
datetime resistanceTime = secondSwingLowBar.time;
datetime resistanceTime =
secondSwingLowBar.time > secondSwingHighBar.time
? secondSwingHighBar.time
: secondSwingLowBar.time;
string resistanceName =
//
identifier +
@@ -479,7 +486,7 @@ public:
(IsSpecifiedValid(prefix)
? "_" + prefix + "_"
: "") +
"_" + lowsPrefix + "_" +
"_" + highsPrefix + "_" +
""
//
;
@@ -528,6 +535,50 @@ public:
return result;
}
//
// Draw Highs ...
result = DrawTrendLine(
chartId,
highsName,
subWindow,
oldHighTime,
oldHigh,
newHighTime,
newHigh,
mInputs.clrHighs,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
// Draw Lows ...
result = DrawTrendLine(
chartId,
lowsName,
subWindow,
oldLowTime,
oldLow,
newLowTime,
newLow,
mInputs.clrLows,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
return result;
}