last works ...

This commit is contained in:
2024-07-15 17:11:50 +03:30
parent af6685f523
commit 6d7f366f73
11 changed files with 1919 additions and 922 deletions
+2
View File
@@ -40,6 +40,8 @@ public:
// Retrieve Class Token ...
virtual string GetToken();
//
// Protected
protected:
//
// Private ...
+106
View File
@@ -0,0 +1,106 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXMan
// Description: Market Analyzer ...
//
//
// 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.draw.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Definitions ...
//
// Class ...
class XSCXMan : public XSCBase
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXMan(
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period // Trading Timeframe
)
{
//
mSymbol = _symbol;
mPeriod = _period;
}
//
// Deconstructor ...
void ~XSCXMan() {}
//
// Override(s) ...
//
// Represent Basic Unique Tag ...
string GetTag() override
{
//
string result = NULL;
//
result = GetTypeName(this);
//
return result;
}
//
// Retrieve Class Token ...
string GetToken() override
{
//
string result = NULL;
//
result = GetSpecificToken(this);
//
return result;
}
//
// Protected ...
protected:
//
// Props ...
//
string mSymbol; // Trading Symbol
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame
//
// Configurations ...
int _maxNumberOfHoldingItems;
//
// Private ...
private:
//
};
//
+12 -6
View File
@@ -21,10 +21,21 @@
//
/// Imports ...
#include "../Libraries/x-saherelm.tools.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
#include "../Classes/x-saherelm.xalert.class.mq5"
//
// Definitions ...
//
enum ENUM_X_SIGNALLING_DIRECTION
{
X_SIGNALLING_NONE = 0,
X_SIGNALLING_BOTH_DIRECTIONS = 1,
X_SIGNALLING_TREND_DIRECTION = 2,
X_SIGNALIING_TREND_REVERSAL_DIRECTION = 3
};
//
class XSCBaseStrategy : public XSCBaseAlert
{
@@ -479,9 +490,6 @@ protected:
int mRequiredPivots; // Required Pivots For Trend Detecting ...
int mRequiredShoulders; // Required Pivots Shoulders ...
//
XTrendDetector trendDetector; // Trend Detector ...
//
XSCTrade *trader;
@@ -491,9 +499,7 @@ protected:
//
void Reset()
{
//
barTracker.Clean();
trendDetector.Clean();
}
//
@@ -0,0 +1,792 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXSRBRStrategy
// Description: provides all based classes for use ...
//
//
// 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.xstrategy.class.mq5"
//
string XSRBRStartegyToken = "XSRBR";
//
class XSCXSRBRStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXSRBRStrategy(
//
// Base ...
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period, // Trading TimeFrame
double _volume, // Voluem
double _r2r, // Risk/Reward Ratio
int _slippage, // Trader Slippage
long _magicNumber, // Trader Magic Number
bool _allowLong = true,
bool _allowShort = true,
int _maxAllowedLongs = 0,
int _maxAllowedShorts = 0 //
) : XSCBaseStrategy(_symbol,
_period,
_volume,
_r2r,
_slippage,
_magicNumber,
_allowLong,
_allowShort,
_maxAllowedLongs,
_maxAllowedShorts //
)
{
//
mThreshold = 5;
mVerificationsStep = 21;
mConditionsValidationAge = 20;
//
SetAlertPrefix(XSRBRStartegyToken);
}
//
// Getter / Setter (s) ...
//
double Treshold()
{
return mThreshold;
}
//
void Treshold(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mThreshold = value;
}
//
int VerificationsStep()
{
return mVerificationsStep;
}
//
void VerificationsStep(int value)
{
//
if (value < 5)
{
value = 5;
}
//
mVerificationsStep = value;
}
//
int ConditionsValidationAge()
{
return mConditionsValidationAge;
}
//
void ConditionsValidationAge(int value)
{
//
if (value < 0)
{
value = 0;
}
//
mConditionsValidationAge = value;
}
//
bool DarwSupportAndResistances()
{
return mDarwSupportAndResistances;
}
//
void DarwSupportAndResistances(bool value)
{
//
mDarwSupportAndResistances = value;
//
if (!value)
{
//
supportPivot.Remove();
resistancePivot.Remove();
}
}
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XSRBRStartegyToken;
}
//
// Check Conditions For Signal ...
bool HasSignal(
XSignal &signal //
) override
{
//
bool result = false;
//
// Try to Detect Trend ...
result = trendDetector.HasTrend();
if (!result)
{
//
result = trendDetector.FindTrend(
mSymbol,
mPeriod //
);
//
if (!result ||
(!trendDetector.isUpTrend && !trendDetector.isDownTrend))
{
//
trendDetector.Clean();
return result;
}
}
//
// Check Resistance Exists or not ...
// if Not, Try to Find One ...
if (!resistancePivot.isResistance)
{
//
result = resistancePivot.FindLastResistance(
mSymbol,
mPeriod //
);
//
if (!result)
{
//
resistancePivot.Clean();
return result;
}
else
{
//
if (DarwSupportAndResistances())
{
resistancePivot.Draw(ChartID());
}
}
}
//
// Check Support Exists or not ...
// if Not, try to Find One ...
if (!supportPivot.isSupport)
{
//
result = supportPivot.FindLastSupport(
mSymbol,
mPeriod //
);
//
if (!result)
{
//
supportPivot.Clean();
return result;
}
else
{
//
if (DarwSupportAndResistances())
{
supportPivot.Draw(ChartID());
}
}
}
//
// Retrieve Bar 1 ...
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!result)
{
//
CheckConditionLife();
return result;
}
//
signal.Clean();
//
double sl = 0;
double tp = 0;
double risk = 0;
double entry = 0;
double reward = 0;
double r2r = R2R();
ENUM_POSITION_TYPE type;
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
//
bool isSupportBreaked = supportPivot.IsBreaked();
bool isSupportRejected = supportPivot.IsRejected();
//
bool isResistancetBreaked = resistancePivot.IsBreaked();
bool isResistancetRejected = resistancePivot.IsRejected();
//
bool isBarBullishPattern =
//
cBar.IsBullish() &&
cBar.HasStrongBody() &&
(cBar.IsHammer() ||
cBar.IsBullishEngulf())
//
;
//
bool isBarBearishPattern =
//
cBar.IsBearish() &&
cBar.HasStrongBody() &&
(cBar.IsShootingStar() ||
cBar.IsBearishEngulf())
//
;
//
// Up Trend ...
if (trendDetector.isUpTrend)
{
//
// During Up Trend ...
// Supports Must Rejected ...
// Resistance Must Breaked ...
//
// Check Trend Trading ...
// Check Based Support ...
bool hasSupportLong =
//
isSupportRejected &&
isBarBullishPattern
//
;
//
// Check Trend Trading ...
// Check Based On Resistance ...
bool hasResistanceLong =
//
isResistancetBreaked &&
isBarBullishPattern
//
;
//
// Check Trend Reversal Trading ...
// Check Based Support ...
bool hasSupportShort =
//
isSupportBreaked &&
isBarBearishPattern
//
;
//
// Check Trend Reversal Trading ...
// Check Based On Resistance ...
bool hasResistanceShort =
//
isResistancetRejected &&
isBarBearishPattern
//
;
//
// Check Trend Trading ...
bool hasLong =
//
hasSupportLong ||
hasResistanceLong
//
;
//
// Check Trend Reversal Trading ...
bool hasShort =
//
hasSupportShort ||
hasResistanceShort
//
;
//
// Filling Signal ...
if (hasLong)
{
//
type = POSITION_TYPE_BUY;
entry = GetEntry(
_Symbol,
type //
);
//
if (hasSupportLong)
{
//
sl = supportPivot.price;
if (supportPivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * supportPivot._threshold;
sl -= threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
else if (hasResistanceLong)
{
//
sl = resistancePivot.price;
if (resistancePivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * resistancePivot._threshold;
sl -= threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
//
result = signal.Prepare(
_Symbol,
"XSUPRES",
_Period,
type,
mode,
entry,
mVolume,
sl,
tp //
);
}
else if (hasShort)
{
//
type = POSITION_TYPE_SELL;
entry = GetEntry(
_Symbol,
type //
);
//
if (hasSupportShort)
{
//
sl = supportPivot.price;
if (supportPivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * supportPivot._threshold;
sl += threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
else if (hasResistanceShort)
{
//
sl = resistancePivot.price;
if (resistancePivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * resistancePivot._threshold;
sl += threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
//
result = signal.Prepare(
_Symbol,
"XSUPRES",
_Period,
type,
mode,
entry,
mVolume,
sl,
tp //
);
}
else
{
result = false;
}
}
//
// Down Trend ...
else if (trendDetector.isDownTrend)
{
//
// During Down Trend ...
// Supports Must Breaked ...
// Resistance Must Rejected ...
//
// Check Trend Reversal Trading ...
// Check Based Support ...
bool hasSupportLong =
//
isSupportRejected &&
isBarBullishPattern
//
;
//
// Check Trend Reversal Trading ...
// Check Based On Resistance ...
bool hasResistanceLong =
//
isResistancetBreaked &&
isBarBullishPattern
//
;
//
// Check Trend Trading ...
// Check Based Support ...
bool hasSupportShort =
//
isSupportBreaked &&
isBarBearishPattern
//
;
//
// Check Trend Trading ...
// Check Based On Resistance ...
bool hasResistanceShort =
//
isResistancetRejected &&
isBarBearishPattern
//
;
//
// Check Trend Reversal Trading ...
bool hasLong =
//
hasSupportLong ||
hasResistanceLong
//
;
//
// Check Trend Trading ...
bool hasShort =
//
hasSupportShort ||
hasResistanceShort
//
;
//
// Filling Signal ...
if (hasLong)
{
//
type = POSITION_TYPE_BUY;
entry = GetEntry(
_Symbol,
type //
);
//
if (hasSupportLong)
{
//
sl = supportPivot.price;
if (supportPivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * supportPivot._threshold;
sl -= threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
else if (hasResistanceLong)
{
//
sl = resistancePivot.price;
if (resistancePivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * resistancePivot._threshold;
sl -= threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
//
result = signal.Prepare(
_Symbol,
"XSUPRES",
_Period,
type,
mode,
entry,
mVolume,
sl,
tp //
);
}
else if (hasShort)
{
//
type = POSITION_TYPE_SELL;
entry = GetEntry(
_Symbol,
type //
);
//
if (hasSupportShort)
{
//
sl = supportPivot.price;
if (supportPivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * supportPivot._threshold;
sl += threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
else if (hasResistanceShort)
{
//
sl = resistancePivot.price;
if (resistancePivot._threshold > 0)
{
//
double threshold = GetPoints(_Symbol) * resistancePivot._threshold;
sl += threshold;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
}
//
result = signal.Prepare(
_Symbol,
"XSUPRES",
_Period,
type,
mode,
entry,
mVolume,
sl,
tp //
);
}
else
{
result = false;
}
}
//
if (!result)
{
CheckConditionLife();
}
//
return result;
}
//
// Notify Signal Execution ...
void OnSignalExecuted(XSignal &signal) override
{
ResetConditions();
}
//
// Protected ...
protected:
//
// Pivots Detecting ...
double mThreshold; // Pivots Edge's Threshold ...
int mVerificationsStep; // Pivots Verification Steps ...
int mConditionsValidationAge; // How Many Bars a Support or Resistance is Valid ...
//
XPivot supportPivot;
XPivot resistancePivot;
//
bool mDarwSupportAndResistances; // Draw Last Found Support and Resistance
//
// Private ...
private:
//
// Check Conditions Time Life ...
void CheckConditionLife()
{
//
datetime cTime = TimeCurrent();
datetime lTime =
//
supportPivot.time < resistancePivot.time
? supportPivot.time
: resistancePivot.time
//
;
//
bool canReset =
//
(
//
(((int)cTime - (int)lTime) / PeriodSeconds(mPeriod)) > mConditionsValidationAge
//
)
//
;
if (canReset)
{
ResetConditions();
}
}
//
// Reset Conditions ...
void ResetConditions()
{
//
trendDetector.Clean();
//
supportPivot.Remove();
supportPivot.Clean();
//
resistancePivot.Remove();
resistancePivot.Clean();
}
};
//
+387
View File
@@ -0,0 +1,387 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XTest MQL5 Expert Advisor
// -------------------------------------------------
// Name: XTestPivotsEA
// Description: an Exper Advisor which used XTestSetup
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XTestPivotsEA"
#property strict
//
#define ShortName "XTestPivotsEA"
//
// Imports ...
#include "../Helpers/x-saherelm.xct.helper.mq5"
#include "../Helpers/x-saherelm.xcc.helper.mq5"
#include "../Strategies/x-saherelm.xsrbr.strategy.mq5"
//
// Inputs ...
long mMagicNumber = 78692110; // Magic Number
int mSlippage = 10; // Slippgae
//
double eaVolume = 0.01;
double eaAllowLong = true;
double eaAllowShort = true;
//
// Variables ...
XSCXCTHelper *mCTHelper;
XSCXCCHelper *mCCHelper;
//
XSCBaseStrategy *strategies[];
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitialEA())
{
return INIT_FAILED;
}
//
// EventSetTimer(1);
// EventSetMillisecondTimer(100);
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// De Initialize XSampleEA Providers ...
delete mCTHelper;
delete mCCHelper;
//
// EventKillTimer();
//
Clean(strategies);
}
//
// On Tick Handler ...
void OnTick()
{
HandleStrategiesOnTick();
}
//
// On Timer ...
void OnTimer()
{
//
// HandleStrategiesOnTick();
}
//
// Custom Functions ...
//
// Validate Inputs ...
bool ValidateInputs()
{
//
bool result = false;
//
result = true;
//
return result;
}
//
// Initialize all Requirements ...
bool InitialEA()
{
//
bool result = false;
//
// Bar Timer ...
XCTInputs ctInputs;
ctInputs.Default();
mCTHelper = new XSCXCTHelper();
result = mCTHelper.Init(
_Symbol,
_Period,
ctInputs //
);
if (!result)
{
return result;
}
//
// Bar Styles ...
XCCInputs ccInputs;
ccInputs.Default();
mCCHelper = new XSCXCCHelper();
result = mCCHelper.Init(
_Symbol,
_Period,
ccInputs //
);
if (!result)
{
return result;
}
//
XSymbolParser symbolParser;
//
bool drawAreas = false;
//
// EURUSD ...
string eurusdSymbol = "EURUSDb"; // symbolParser.GetEURUSDSymbol();
if (IsValid(eurusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = mMagicNumber + 1;
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *eurusdM5SRBRStrategy;
// eurusdM5SRBRStrategy = new XSCXSRBRStrategy(
// eurusdSymbol,
// PERIOD_M5,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
// eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
// eurusdM5SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(eurusdM5SRBRStrategy);
// //
// // Register XSRBR on EURUSD in M10 ...
// XSCXSRBRStrategy *eurusdM10SRBRStrategy;
// eurusdM10SRBRStrategy = new XSCXSRBRStrategy(
// eurusdSymbol,
// PERIOD_M10,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// eurusdM10SRBRStrategy.SetAlertLogAlerts(true);
// eurusdM10SRBRStrategy.SetAlertEnableAlerts(true);
// eurusdM10SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(eurusdM10SRBRStrategy);
}
// //
// // XAUUSD ...
// string xauusdSymbol = "XAUUSDb";
// if (IsValid(xauusdSymbol))
// {
// //
// // MAGIC NUMBER ...
// long magicNumber = mMagicNumber + 2;
// //
// // Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *xauusdM5SRBRStrategy;
// xauusdM5SRBRStrategy = new XSCXSRBRStrategy(
// xauusdSymbol,
// PERIOD_M15,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// xauusdM5SRBRStrategy.SetAlertLogAlerts(true);
// xauusdM5SRBRStrategy.SetAlertEnableAlerts(true);
// xauusdM5SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(xauusdM5SRBRStrategy);
// }
//
// GBPUSD ...
string gbpusdSymbol = "GBPUSDb";
if (IsValid(gbpusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = mMagicNumber + 3;
// //
// // Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *gbpusdM15SRBRStrategy;
// gbpusdM15SRBRStrategy = new XSCXSRBRStrategy(
// gbpusdSymbol,
// PERIOD_M15,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// gbpusdM15SRBRStrategy.SetAlertLogAlerts(true);
// gbpusdM15SRBRStrategy.SetAlertEnableAlerts(true);
// gbpusdM15SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(gbpusdM15SRBRStrategy);
//
// Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *gbpusdM30SRBRStrategy;
// gbpusdM30SRBRStrategy = new XSCXSRBRStrategy(
// gbpusdSymbol,
// PERIOD_M30,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// gbpusdM30SRBRStrategy.SetAlertLogAlerts(true);
// gbpusdM30SRBRStrategy.SetAlertEnableAlerts(true);
// gbpusdM30SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(gbpusdM30SRBRStrategy);
}
//
// USDJPY ...
string usdjpySymbol = "USDJPYb";
if (IsValid(usdjpySymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = mMagicNumber + 3;
// //
// // Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *usdjpyM5SRBRStrategy;
// usdjpyM5SRBRStrategy = new XSCXSRBRStrategy(
// usdjpySymbol,
// PERIOD_M5,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// usdjpyM5SRBRStrategy.SetAlertLogAlerts(true);
// usdjpyM5SRBRStrategy.SetAlertEnableAlerts(true);
// usdjpyM5SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(usdjpyM5SRBRStrategy);
}
//
return result;
}
//
// Register Strategy ...
void RegisterStrategy(XSCBaseStrategy *strategy)
{
//
if (strategy == NULL)
{
return;
}
//
ArrayResize(
strategies,
ArraySize(strategies) + 1 //
);
//
strategies[ArraySize(strategies) - 1] = strategy;
}
//
// Call All Registered Strategis Tick Handler Functions ...
void HandleStrategiesOnTick()
{
//
int count = ArraySize(strategies);
if (!IsValidSize(count))
{
return;
}
//
for (int i = 0; i < count; i++)
{
//
// Call Tick Handler Function ...
strategies[i].HandleTick();
}
}
//
// Custom Testing Functions ...
//
@@ -0,0 +1,191 @@
//
// Check Conditions For Signal ...
bool HasSignal(
XSignal &signal //
) override
{
//
bool result = false;
//
signal.Clean();
//
double sl = 0;
double tp = 0;
double risk = 0;
double entry = 0;
double reward = 0;
double r2r = R2R();
ENUM_POSITION_TYPE type;
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
//
// Check Signalling Direction ...
result = mSignallingDirection != X_SIGNALLING_NONE;
if (!result)
{
return result;
}
//
// Check Conditions Exists ...
result = HasRequirements();
if (!result)
{
//
// Prepare Conditions ...
result = PrepareRequirements();
if (!result)
{
return result;
}
}
//
// Implement Signalling Conditions ...
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
1 //
);
//
// Check Analyzing Period Contains a Trend or not ...
//
// Detecting Trend ...
bool isInBullishTrend = false;
bool isInBearishTrend = false;
//
isInBullishTrend = bar.HasBullishTrend(
highSwingBars,
lowSwingBars //
);
if (!isInBullishTrend)
{
//
isInBearishTrend = bar.HasBearishTrend(
highSwingBars,
lowSwingBars //
);
}
//
// Only Looks For Signals if aTrend Detected ...
result = isInBullishTrend || isInBearishTrend;
if (!result)
{
return result;
}
//
// Here We have to Decide Trend or Reversal Act ...
//
// Check Trend Direction Signal ...
if (mSignallingDirection == X_SIGNALLING_BOTH_DIRECTIONS ||
mSignallingDirection == X_SIGNALLING_TREND_DIRECTION)
{
//
if (isInBullishTrend)
{
//
// Find Long Signals ...
// since we are in Bullish Trend and
// we must do Trend Trading ...
//
result =
//
false
//
;
}
else if (isInBearishTrend)
{
//
// Find Short Signals ...
// since we are in Bearish Trend and
// we must do Trend Trading ...
//
result =
//
false
//
;
}
}
//
// Check Trend Reversal Direction Signal ...
if (!result &&
(mSignallingDirection == X_SIGNALLING_BOTH_DIRECTIONS ||
mSignallingDirection == X_SIGNALIING_TREND_REVERSAL_DIRECTION))
{
//
if (isInBullishTrend)
{
//
// Find Short Signals ...
// since we are in Bullish Trend and
// we must do Trend Reversal Trading ...
//
result =
//
false
//
;
}
else if (isInBearishTrend)
{
//
// Find Long Signals ...
// since we are in Bearish Trend and
// we must do Trend Reversal Trading ...
//
result =
//
false
//
;
}
}
//
// Make Sure Signal Exists ...
if (!result)
{
return result;
}
//
CalculateTPSLBtPrice(
sl,
tp,
type,
entry,
r2r //
);
//
result = signal.Prepare(
mSymbol,
GetTag(),
mPeriod,
type,
mode,
entry,
mVolume,
sl,
tp //
);
//
return result;
}
+1 -1
View File
@@ -24,7 +24,7 @@
//
// Imports ...
#include "../Libraries/x-saherelm.tools.mq5"
#include "../Libraries/x-saherelm.tools.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
+19 -148
View File
@@ -186,155 +186,26 @@ bool InitialEA()
// MAGIC NUMBER ...
long magicNumber = mMagicNumber + 1;
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *eurusdM5SRBRStrategy;
// eurusdM5SRBRStrategy = new XSCXSRBRStrategy(
// eurusdSymbol,
// PERIOD_M5,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
// eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
// eurusdM5SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(eurusdM5SRBRStrategy);
// //
// // Register XSRBR on EURUSD in M10 ...
// XSCXSRBRStrategy *eurusdM10SRBRStrategy;
// eurusdM10SRBRStrategy = new XSCXSRBRStrategy(
// eurusdSymbol,
// PERIOD_M10,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// eurusdM10SRBRStrategy.SetAlertLogAlerts(true);
// eurusdM10SRBRStrategy.SetAlertEnableAlerts(true);
// eurusdM10SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(eurusdM10SRBRStrategy);
}
// //
// // XAUUSD ...
// string xauusdSymbol = "XAUUSDb";
// if (IsValid(xauusdSymbol))
// {
// //
// // MAGIC NUMBER ...
// long magicNumber = mMagicNumber + 2;
// //
// // Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *xauusdM5SRBRStrategy;
// xauusdM5SRBRStrategy = new XSCXSRBRStrategy(
// xauusdSymbol,
// PERIOD_M15,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// xauusdM5SRBRStrategy.SetAlertLogAlerts(true);
// xauusdM5SRBRStrategy.SetAlertEnableAlerts(true);
// xauusdM5SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(xauusdM5SRBRStrategy);
// }
//
// GBPUSD ...
string gbpusdSymbol = "GBPUSDb";
if (IsValid(gbpusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = mMagicNumber + 3;
// //
// // Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *gbpusdM15SRBRStrategy;
// gbpusdM15SRBRStrategy = new XSCXSRBRStrategy(
// gbpusdSymbol,
// PERIOD_M15,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// gbpusdM15SRBRStrategy.SetAlertLogAlerts(true);
// gbpusdM15SRBRStrategy.SetAlertEnableAlerts(true);
// gbpusdM15SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(gbpusdM15SRBRStrategy);
//
// Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *gbpusdM30SRBRStrategy;
// gbpusdM30SRBRStrategy = new XSCXSRBRStrategy(
// gbpusdSymbol,
// PERIOD_M30,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// gbpusdM30SRBRStrategy.SetAlertLogAlerts(true);
// gbpusdM30SRBRStrategy.SetAlertEnableAlerts(true);
// gbpusdM30SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(gbpusdM30SRBRStrategy);
}
//
// USDJPY ...
string usdjpySymbol = "USDJPYb";
if (IsValid(usdjpySymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = mMagicNumber + 3;
// //
// // Register XSRBR on XAUUSD in M5 ...
// XSCXSRBRStrategy *usdjpyM5SRBRStrategy;
// usdjpyM5SRBRStrategy = new XSCXSRBRStrategy(
// usdjpySymbol,
// PERIOD_M5,
// eaVolume,
// 1.5, // R2R ...
// mSlippage,
// magicNumber,
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0 // Max Shorts
// );
// usdjpyM5SRBRStrategy.SetAlertLogAlerts(true);
// usdjpyM5SRBRStrategy.SetAlertEnableAlerts(true);
// usdjpyM5SRBRStrategy.DarwSupportAndResistances(drawAreas);
// RegisterStrategy(usdjpyM5SRBRStrategy);
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *eurusdM5SRBRStrategy;
eurusdM5SRBRStrategy = new XSCXSRBRStrategy(
eurusdSymbol,
PERIOD_M5,
PERIOD_H1,
eaVolume,
1.5, // R2R ...
mSlippage,
magicNumber,
eaAllowLong,
eaAllowShort,
0, // Max Longs
0, // Max Shorts
X_SIGNALLING_TREND_DIRECTION //
);
eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdM5SRBRStrategy);
}
//
+46 -112
View File
@@ -2623,8 +2623,7 @@ struct XOHCL
//
// Find Support ...
bool HasSupport(
double &support,
datetime &at,
XOHCL &bar,
ENUM_X_PRICE type = X_PRICE_CLOSE,
int loopback = 21,
int tries = 100 //
@@ -2634,8 +2633,7 @@ struct XOHCL
bool result = false;
//
at = NULL;
support = 0;
bar.Clean();
//
if (loopback < 0)
@@ -2697,8 +2695,7 @@ struct XOHCL
if (result)
{
//
at = iLBar.time;
support = iLBar.high;
bar = iLBar;
break;
}
}
@@ -2710,8 +2707,7 @@ struct XOHCL
//
// Find Resistance ...
bool HasResistance(
double &resistance,
datetime &at,
XOHCL &bar,
ENUM_X_PRICE type = X_PRICE_CLOSE,
int loopback = 21,
int tries = 100 //
@@ -2721,8 +2717,7 @@ struct XOHCL
bool result = false;
//
at = NULL;
resistance = 0;
bar.Clean();
//
if (loopback < 0)
@@ -2784,8 +2779,7 @@ struct XOHCL
if (result)
{
//
at = iHBar.time;
resistance = iHBar.high;
bar = iHBar;
break;
}
}
@@ -2800,10 +2794,8 @@ struct XOHCL
//
// Find Bullish Trend ...
bool HasBullishTrend(
double &highSwings[],
datetime &highSwingTimes[],
double &lowSwings[],
datetime &lowSwingTimes[],
XOHCL &highSwingBars[],
XOHCL &lowSwingBars[],
bool forceMethod2 = false,
int loopback = 3,
int tries = 3,
@@ -2814,10 +2806,8 @@ struct XOHCL
bool result = false;
//
Clean(lowSwings);
Clean(lowSwingTimes);
Clean(highSwings);
Clean(highSwingTimes);
Clean(lowSwingBars);
Clean(highSwingBars);
//
result = IsValid();
@@ -2882,15 +2872,9 @@ struct XOHCL
if (isIHAccepted)
{
//
Add(
iH,
highSwings //
);
//
Add(
iHBar.time,
highSwingTimes //
AddRef(
iHBar,
highSwingBars //
);
//
@@ -2941,15 +2925,9 @@ struct XOHCL
if (isILAccepted)
{
//
Add(
iL,
lowSwings //
);
//
Add(
iLBar.time,
lowSwingTimes //
AddRef(
iLBar,
lowSwingBars //
);
//
@@ -3014,15 +2992,9 @@ struct XOHCL
if (isIHAccepted)
{
//
Add(
iH,
highSwings //
);
//
Add(
iHBar.time,
highSwingTimes //
AddRef(
iHBar,
highSwingBars //
);
//
@@ -3073,15 +3045,9 @@ struct XOHCL
if (isILAccepted)
{
//
Add(
iL,
lowSwings //
);
//
Add(
iLBar.time,
lowSwingTimes //
AddRef(
iLBar,
lowSwingBars //
);
//
@@ -3097,8 +3063,8 @@ struct XOHCL
//
result =
//
ArraySize(lowSwings) == tries &&
ArraySize(highSwings) == tries
ArraySize(lowSwingBars) == tries &&
ArraySize(highSwingBars) == tries
//
;
}
@@ -3107,10 +3073,8 @@ struct XOHCL
if (!result)
{
//
Clean(lowSwings);
Clean(lowSwingTimes);
Clean(highSwings);
Clean(highSwingTimes);
Clean(lowSwingBars);
Clean(highSwingBars);
}
//
@@ -3120,10 +3084,8 @@ struct XOHCL
//
// Find Bearish Trend ...
bool HasBearishTrend(
double &highSwings[],
datetime &highSwingTimes[],
double &lowSwings[],
datetime &lowSwingTimes[],
XOHCL &highSwingBars[],
XOHCL &lowSwingBars[],
bool forceMethod2 = false,
int loopback = 3,
int tries = 3,
@@ -3134,10 +3096,8 @@ struct XOHCL
bool result = false;
//
Clean(lowSwings);
Clean(lowSwingTimes);
Clean(highSwings);
Clean(highSwingTimes);
Clean(lowSwingBars);
Clean(highSwingBars);
//
result = IsValid();
@@ -3202,15 +3162,9 @@ struct XOHCL
if (isIHAccepted)
{
//
Add(
iH,
highSwings //
);
//
Add(
iHBar.time,
highSwingTimes //
AddRef(
iHBar,
highSwingBars //
);
//
@@ -3261,15 +3215,9 @@ struct XOHCL
if (isILAccepted)
{
//
Add(
iL,
lowSwings //
);
//
Add(
iLBar.time,
lowSwingTimes //
AddRef(
iLBar,
lowSwingBars //
);
//
@@ -3334,15 +3282,9 @@ struct XOHCL
if (isIHAccepted)
{
//
Add(
iH,
highSwings //
);
//
Add(
iHBar.time,
highSwingTimes //
AddRef(
iHBar,
highSwingBars //
);
//
@@ -3393,15 +3335,9 @@ struct XOHCL
if (isILAccepted)
{
//
Add(
iL,
lowSwings //
);
//
Add(
iLBar.time,
lowSwingTimes //
AddRef(
iLBar,
lowSwingBars //
);
//
@@ -3417,8 +3353,8 @@ struct XOHCL
//
result =
//
ArraySize(lowSwings) == tries &&
ArraySize(highSwings) == tries
ArraySize(lowSwingBars) == tries &&
ArraySize(highSwingBars) == tries
//
;
}
@@ -3427,10 +3363,8 @@ struct XOHCL
if (!result)
{
//
Clean(lowSwings);
Clean(lowSwingTimes);
Clean(highSwings);
Clean(highSwingTimes);
Clean(lowSwingBars);
Clean(highSwingBars);
}
//
File diff suppressed because it is too large Load Diff