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 "../Libraries/x-saherelm.xtrade.lib.mq5"
#include "../Classes/x-saherelm.xalert.class.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.xtd.helper.mq5"
#include "../Helpers/x-saherelm.xhk.helper.mq5" #include "../Helpers/x-saherelm.xhk.helper.mq5"
#include "../Helpers/x-saherelm.xstr.helper.mq5" #include "../Helpers/x-saherelm.xstr.helper.mq5"
@@ -204,6 +206,7 @@ struct X121SetupInputs
// //
// Helpers Inputs ... // Helpers Inputs ...
XPVInputs pvInputs; // XPV Inputs
XTDInputs tdInputs; // XTD Inputs XTDInputs tdInputs; // XTD Inputs
XHKInputs hkInputs; // XHK Inputs XHKInputs hkInputs; // XHK Inputs
XCHEInputs cheInputs; // XCHE Inputs XCHEInputs cheInputs; // XCHE Inputs
@@ -240,6 +243,7 @@ struct X121SetupInputs
bool Init( bool Init(
string _symbol, // Symbol string _symbol, // Symbol
ENUM_TIMEFRAMES _period, // Time Frame ENUM_TIMEFRAMES _period, // Time Frame
XPVInputs &_pvInputs, // XPV Inputs
XTDInputs &_tdInputs, // XTD Inputs XTDInputs &_tdInputs, // XTD Inputs
XHKInputs &_hkInputs, // XHK Inputs XHKInputs &_hkInputs, // XHK Inputs
XCHEInputs &_cheInputs, // XCHE Inputs XCHEInputs &_cheInputs, // XCHE Inputs
@@ -261,6 +265,7 @@ struct X121SetupInputs
// //
// Helpers Inputs ... // Helpers Inputs ...
this.pvInputs = _pvInputs;
this.tdInputs = _tdInputs; this.tdInputs = _tdInputs;
this.hkInputs = _hkInputs; this.hkInputs = _hkInputs;
this.cheInputs = _cheInputs; this.cheInputs = _cheInputs;
@@ -294,6 +299,7 @@ struct X121SetupInputs
period = NULL; period = NULL;
// //
pvInputs.Clean();
tdInputs.Clean(); tdInputs.Clean();
hkInputs.Clean(); hkInputs.Clean();
cheInputs.Clean(); cheInputs.Clean();
@@ -314,6 +320,7 @@ struct X121SetupInputs
void Default() void Default()
{ {
// //
pvInputs.Default();
tdInputs.Default(); tdInputs.Default();
hkInputs.Default(); hkInputs.Default();
cheInputs.Default(); cheInputs.Default();
@@ -355,6 +362,13 @@ struct X121SetupInputs
return result; return result;
} }
//
result = pvInputs.IsValid();
if (!result)
{
return result;
}
// //
result = hkInputs.IsValid(); result = hkInputs.IsValid();
if (!result) if (!result)
@@ -456,6 +470,7 @@ struct X121SetupConditions
// //
// Conditions ... // Conditions ...
XPVConditions pvConditions;
XTDConditions tdConditions; XTDConditions tdConditions;
XHKConditions hkConditions; XHKConditions hkConditions;
XCHEConditions cheConditions; XCHEConditions cheConditions;
@@ -531,6 +546,14 @@ struct X121SetupConditions
bullishScore += tempBullishScore; bullishScore += tempBullishScore;
bearishScore += tempBearishScore; bearishScore += tempBearishScore;
//
pvConditions.GenerateScore(
tempBullishScore,
tempBearishScore //
);
bullishScore += tempBullishScore;
bearishScore += tempBearishScore;
// //
adxtdConditions.GenerateScore( adxtdConditions.GenerateScore(
tempBullishScore, tempBullishScore,
@@ -659,6 +682,7 @@ struct X121SetupConditions
); );
// //
string pvSummary = pvConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
string tdSummary = tdConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string tdSummary = tdConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
string hkSummary = hkConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string hkSummary = hkConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
string strSummary = strConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string strSummary = strConditions.GenerateSummary(false, true, false, ignoreFalseConditions);
@@ -675,6 +699,7 @@ struct X121SetupConditions
// //
string conditionsStr = string conditionsStr =
// //
pvSummary + separator +
tdSummary + separator + tdSummary + separator +
hkSummary + separator + hkSummary + separator +
ichSummary + separator + ichSummary + separator +
@@ -2259,7 +2284,7 @@ struct X121SignalGenerator
// //
bool IsConditionsValidForLong( bool IsConditionsValidForLong(
X121SetupConditions &conditions, // Conditions X121SetupConditions &conditions, // Conditions
int verifications = 4 // Number of Verifications int verifications = 4 // Number of Verifications
) )
{ {
// //
@@ -2515,7 +2540,7 @@ struct X121SignalGenerator
// //
bool IsConditionsValidForShort( bool IsConditionsValidForShort(
X121SetupConditions &conditions, // Conditions X121SetupConditions &conditions, // Conditions
int verifications = 4 // Number of Verifications int verifications = 4 // Number of Verifications
) )
{ {
// //
@@ -2755,6 +2780,22 @@ struct X121SignalGenerator
signal.zones = zones; 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 ... // Generate Support Signals ...
if (_useSupport) if (_useSupport)
@@ -2787,6 +2828,27 @@ struct X121SignalGenerator
// //
bool canUseZones = signal.zones != NULL; 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 ... // Check Signal Has TP and SL ...
@@ -2821,21 +2883,6 @@ struct X121SignalGenerator
// Try to Find a Hot Level based on Signal Direction // Try to Find a Hot Level based on Signal Direction
// as Resistance ... // 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++) for (int i = 0; i < signal.zones.CountZones(); i++)
{ {
@@ -2878,10 +2925,10 @@ struct X121SignalGenerator
// Opposit Support on Resistance Upper ... // Opposit Support on Resistance Upper ...
// //
rTP = signal.sl <= 0 // rTP = signal.sl <= 0
? iZone.high - (onePointValue * 15) // ? iZone.high - (onePointValue * 15)
: signal.sl; // : signal.sl;
rSL = signal.entry; // rSL = signal.entry;
rType = POSITION_TYPE_BUY; rType = POSITION_TYPE_BUY;
rEntry = iZone.high + (onePointValue * 2); rEntry = iZone.high + (onePointValue * 2);
rMode = X_ORDER_MODE_STOP; rMode = X_ORDER_MODE_STOP;
@@ -2920,10 +2967,10 @@ struct X121SignalGenerator
// Support Directional on Resistance Lower ... // Support Directional on Resistance Lower ...
// //
rTP = signal.entry; // rTP = signal.entry;
rSL = signal.sl <= 0 // rSL = signal.sl <= 0
? signal.entry - (onePointValue * 15) // ? signal.entry - (onePointValue * 15)
: signal.sl; // : signal.sl;
rEntry = iZone.low - (onePointValue * 2); rEntry = iZone.low - (onePointValue * 2);
rVolume = signal.volume * 3; rVolume = signal.volume * 3;
rType = POSITION_TYPE_SELL; 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: public:
// //
// Props ... // Props ...
XSCXPVHelper *pvHelper;
XSCXTDHelper *tdHelper; XSCXTDHelper *tdHelper;
XSCXHKHelper *hkHelper; XSCXHKHelper *hkHelper;
XSCXCHEHelper *cheHelper; XSCXCHEHelper *cheHelper;
@@ -3010,6 +3407,7 @@ public:
void ~XSCX121Setup() void ~XSCX121Setup()
{ {
// //
delete pvHelper;
delete tdHelper; delete tdHelper;
delete hkHelper; delete hkHelper;
delete cheHelper; delete cheHelper;
@@ -3064,6 +3462,19 @@ public:
// //
// Initialize Helpers ... // Initialize Helpers ...
//
// XPV ...
pvHelper = new XSCXPVHelper();
result = pvHelper.Init(
inputs.symbol,
inputs.period,
inputs.pvInputs //
);
if (!result)
{
return result;
}
// //
// XTD ... // XTD ...
tdHelper = new XSCXTDHelper(); tdHelper = new XSCXTDHelper();
@@ -3271,6 +3682,17 @@ public:
conditions.period = GetPeriod(); conditions.period = GetPeriod();
conditions.time = TimeCurrent(); conditions.time = TimeCurrent();
//
result = pvHelper.GetConditions(
conditions.pvConditions,
barIndex,
loopback //
);
if (!result)
{
return result;
}
// //
result = tdHelper.GetConditions( result = tdHelper.GetConditions(
conditions.tdConditions, 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 + "_" + result = mSymbol + "_" +
ToString(mPeriod) + ToString(mPeriod) + "_" +
ToFormatString(zBar.time); ToFormatString(zBar.time);
// //
@@ -422,7 +422,10 @@ public:
// //
double support = secondSwingLowBar.low; double support = secondSwingLowBar.low;
datetime supportTime = secondSwingLowBar.time; datetime supportTime =
secondSwingLowBar.time > secondSwingHighBar.time
? secondSwingHighBar.time
: secondSwingLowBar.time;
string supportName = string supportName =
// //
identifier + identifier +
@@ -436,7 +439,11 @@ public:
// //
double resistance = secondSwingHighBar.high; double resistance = secondSwingHighBar.high;
datetime resistanceTime = secondSwingLowBar.time; datetime resistanceTime =
secondSwingLowBar.time > secondSwingHighBar.time
? secondSwingHighBar.time
: secondSwingLowBar.time;
string resistanceName = string resistanceName =
// //
identifier + identifier +
@@ -479,7 +486,7 @@ public:
(IsSpecifiedValid(prefix) (IsSpecifiedValid(prefix)
? "_" + prefix + "_" ? "_" + prefix + "_"
: "") + : "") +
"_" + lowsPrefix + "_" + "_" + highsPrefix + "_" +
"" ""
// //
; ;
@@ -528,6 +535,50 @@ public:
return result; 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; return result;
} }
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -23,8 +23,9 @@
// Imports ... // Imports ...
#include <Trade/Trade.mqh> #include <Trade/Trade.mqh>
#include "../Libraries/x-saherelm.draw.lib.mq5" #include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Classes/x-saherelm.xczone.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5" #include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xsczone.class.mq5"
#include "../Classes/x-saherelm.xsctrend.class.mq5"
// //
// Definitions ... // Definitions ...
@@ -731,6 +732,7 @@ struct XSignal
// //
// Zones for Signal ... // Zones for Signal ...
XSCZones *zones; XSCZones *zones;
XSCTrend *trend;
// //
// Constructor ... // Constructor ...