This commit is contained in:
2024-07-21 17:37:34 +03:30
parent 608d387a92
commit a996143dd3
11 changed files with 3160 additions and 378 deletions
+42
View File
@@ -56,6 +56,8 @@ public:
bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points
double _tpPoint = 0, // TP As Point double _tpPoint = 0, // TP As Point
double _slPoint = 0, // SL As Point double _slPoint = 0, // SL As Point
bool _ignoreTP = false, // TP set to 0
bool _ignoreSL = false, // SL set to 0
bool _allowLong = true, bool _allowLong = true,
bool _allowShort = true, bool _allowShort = true,
int _maxAllowedLongs = 0, int _maxAllowedLongs = 0,
@@ -70,6 +72,8 @@ public:
mPeriod = _period; mPeriod = _period;
mTPPoint = _tpPoint; mTPPoint = _tpPoint;
mSLPoint = _slPoint; mSLPoint = _slPoint;
mIgnoreTP = _ignoreTP;
mIgnoreSL = _ignoreSL;
mSlippage = _slippage; mSlippage = _slippage;
mAllowLong = _allowLong; mAllowLong = _allowLong;
mAllowShort = _allowShort; mAllowShort = _allowShort;
@@ -343,6 +347,30 @@ public:
mSLPoint = value; mSLPoint = value;
} }
//
bool IgnoreTP()
{
return mIgnoreTP;
}
//
void IgnoreTP(bool value)
{
mIgnoreTP = value;
}
//
bool IgnoreSL()
{
return mIgnoreSL;
}
//
void IgnoreSL(bool value)
{
mIgnoreSL = value;
}
// //
// Virtual Methods ... // Virtual Methods ...
@@ -560,6 +588,18 @@ public:
} }
} }
//
if (mIgnoreTP)
{
signal.tp = 0;
}
//
if (mIgnoreSL)
{
signal.sl = 0;
}
// //
ENUM_X_SIGNAL_EXECUTION_RESULT state; ENUM_X_SIGNAL_EXECUTION_RESULT state;
result = trader.ExecuteSignal( result = trader.ExecuteSignal(
@@ -616,6 +656,8 @@ protected:
bool mForceMaxTPSLAsPoint; // Force Max TP and SL by Provided Points bool mForceMaxTPSLAsPoint; // Force Max TP and SL by Provided Points
double mTPPoint; // TP As Point double mTPPoint; // TP As Point
double mSLPoint; // SL As Point double mSLPoint; // SL As Point
bool mIgnoreTP; // TP set to 0
bool mIgnoreSL; // SL set to 0
// //
string mSymbol; // Trading Symbol ... string mSymbol; // Trading Symbol ...
+924
View File
@@ -5846,3 +5846,927 @@ int pivotsCount = ArraySize(pivots);
// sl = tmpHSW[ArraySize(tmpHSW) - 1].high; // sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
} }
} }
/////////////////////////////////////////////////////////////////////////////////////
// hasLong =
// //
// // Must in Bullish Trend ...
// // isBullishTrend
// // //
// // &&
// //
// // Check Bar Patterns ...
// // (
// // //
// // isHammer
// // //
// // ||
// // //
// // isMorningStar
// // //
// // ||
// // //
// // isBullishMarubozu
// // //
// // ||
// // //
// // isBullishEngulfing
// // //
// // )
// // //
// // &&
// //
// // Fib3 must below mc verifier ...
// pvConditions.fib3s[ppIndex] < mcConditions.verifier[ppIndex] &&
// pvConditions.fib3s[pIndex] < mcConditions.verifier[pIndex]
// //
// &&
// //
// // Sar Must be Bullish ...
// mcConditions.psar[ppIndex] < ppBar.low &&
// mcConditions.psar[pIndex] < pBar.low &&
// mcConditions.isSARBullish
// //
// &&
// //
// // Fib3 Crossed Over Verifier ...
// pvConditions.fib3s[cIndex] > mcConditions.verifier[cIndex] &&
// pvConditions.fib3s[pIndex] <= mcConditions.verifier[pIndex]
// //
// &&
// //
// // Fast Over Slow and Slow Over Verifier ...
// mcConditions.fast[cIndex] > mcConditions.slow[cIndex] &&
// mcConditions.slow[cIndex] > mcConditions.verifier[cIndex]
// //
// &&
// //
// // CBar and PBar Close over Fast ...
// cBar.close > mcConditions.verifier[cIndex] &&
// pBar.close > mcConditions.verifier[pIndex]
// //
// ;
//
// hasLong =
// //
// isBullishTrend
// //
// &&
// //
// mcConditions.fast[cIndex] > mcConditions.fast[pIndex] &&
// mcConditions.slow[cIndex] > mcConditions.slow[pIndex]
// //
// &&
// //
// mcConditions.fast[cIndex] > mcConditions.slow[cIndex] &&
// mcConditions.fast[pIndex] < mcConditions.slow[pIndex]
// //
// &&
// //
// mcConditions.fast[cIndex] > mcConditions.verifier[cIndex] &&
// mcConditions.fast[pIndex] > mcConditions.verifier[pIndex] &&
// mcConditions.slow[cIndex] > mcConditions.verifier[cIndex] &&
// mcConditions.slow[pIndex] > mcConditions.verifier[pIndex]
// //
// &&
// //
// cBar.close > mcConditions.fast[cIndex] &&
// cBar.close > mcConditions.slow[cIndex] &&
// cBar.close > mcConditions.fast[pIndex] &&
// cBar.close > mcConditions.slow[pIndex]
// //
// &&
// //
// mcConditions.psar[cIndex] < cBar.low
// //
// &&
// //
// pvConditions.peaks[cIndex] != EMPTY_VALUE &&
// pvConditions.peaks[pIndex] != EMPTY_VALUE &&
// pvConditions.peaks[cIndex] > pvConditions.peaks[pIndex]
// //
// &&
// //
// pvConditions.fib3s[cIndex] > mcConditions.verifier[cIndex] &&
// pvConditions.fib3s[cIndex] >= pvConditions.fib3s[pIndex]
// //
// ;
// //
// // Check Fib3 Crosses ...
// bool isFib3CrossedUnder = IsValid(fibs3CrossedUnderTime);
// bool isFib3CrossedOver = IsValid(fibs3CrossedOverTime);
// //
// // Check Fib3 Crossed Under ...
// if (!isFib3CrossedUnder)
// {
// //
// isFib3CrossedUnder =
// //
// cBar.high < pvConditions.fib3s[cIndex] &&
// pBar.high > pvConditions.fib3s[pIndex]
// //
// ;
// if (isFib3CrossedUnder)
// {
// fibs3CrossedUnderTime = cBar.time;
// }
// }
// else
// {
// //
// // Check Age ...
// int age = ((int)((int)cBar.time - (int)fibs3CrossedUnderTime) / PeriodSeconds(mPeriod));
// if (age >= 20)
// {
// fibs3CrossedUnderTime = NULL;
// }
// }
// //
// // Check Fib3 Crossed Over ...
// if (!isFib3CrossedOver)
// {
// //
// isFib3CrossedOver =
// //
// cBar.low > pvConditions.fib3s[cIndex] &&
// pBar.low < pvConditions.fib3s[pIndex]
// //
// ;
// if (isFib3CrossedOver)
// {
// fibs3CrossedOverTime = cBar.time;
// }
// }
// else
// {
// //
// // Check Age ...
// int age = ((int)((int)cBar.time - (int)fibs3CrossedOverTime) / PeriodSeconds(mPeriod));
// if (age >= 20)
// {
// fibs3CrossedOverTime = NULL;
// }
// }
// //
// result =
// //
// isFib3CrossedOver
// //
// ||
// //
// isFib3CrossedUnder
// //
// ;
// if (!result)
// {
// return result;
// }
// hasLong =
//
// // isBullishTrend
// // //
// // &&
// //
// hasBullishPattern
// //
// &&
//
// cBar.IsBullishTouched(pvConditions.fib3s[cIndex])
// //
// &&
// //
// cBar.close > mcConditions.verifier[cIndex]
// //
// &&
// //
// mcConditions.psar[cIndex] < cBar.low
// //
// &&
// //
// pvConditions.fib3s[cIndex] > mcConditions.verifier[cIndex]
// //
// &&
// //
// cBar.IsBullish()
//
// ;
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
//
// SaherElm IT Center XTest MQL5 Expert Advisor
// -------------------------------------------------
// Name: XSTestEA
// 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 XSTestEA"
#property strict
//
#define ShortName "XSTestEA"
//
// Imports ...
#include "../Helpers/x-saherelm.xct.helper.mq5"
#include "../Helpers/x-saherelm.xcc.helper.mq5"
//
#include "../Strategies/x-saherelm.xtest.strategy.mq5"
// #include "../Strategies/x-saherelm.xobvg.strategy.mq5"
// #include "../Strategies/x-saherelm.xsrbr.strategy.mq5"
// #include "../Strategies/x-saherelm.xpvfmc.strategy.mq5"
// #include "../Strategies/x-saherelm.xemrng.strategy.mq5"
//
// Inputs ...
long eaMagicNumber = 78692110; // Magic Number
int eaSlippage = 10; // Slippgae
//
double eaVolume = 0.01;
double eaAllowLong = true;
double eaAllowShort = true;
//
int eaMaxAllowedLongs = 0;
int eaMaxAllowedShorts = 0;
//
double eaTPPoint = 200;
double eaSLPoint = 100;
//
bool eaIgnoreTP = false;
bool eaIgnoreSL = false;
//
double eaR2R = 2;
//
// Variables ...
XSCXCTHelper *mCTHelper;
XSCXCCHelper *mCCHelper;
//
XSCBaseStrategy *strategies[];
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitialEA())
{
return INIT_FAILED;
}
//
drawPrefix = ShortName;
//
// 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;
//
bool useEURUSD = true;
bool useUSDCHF = false;
bool useUSDJPY = false;
bool useGBPUSD = false;
bool useXAUUSD = false;
//
bool useXSRBR = false;
bool useXEMRNG = false;
bool useXOBVG = false;
bool useXPVFMC = false;
bool useXTest = true;
//
// EURUSD ...
string eurusdSymbol = "EURUSDb"; // symbolParser.GetEURUSDSymbol();
if (useEURUSD && IsValid(eurusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 1;
//
// XTest ...
if (useXTest)
{
//
XSCXTestStrategy *eurusdTestStrategy;
eurusdTestStrategy = new XSCXTestStrategy(
eurusdSymbol,
PERIOD_M5,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
false, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaIgnoreTP,
eaIgnoreSL,
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts
);
eurusdTestStrategy.SetAlertLogAlerts(true);
eurusdTestStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdTestStrategy);
}
// //
// // XSRBR ...
// if (useXSRBR)
// {
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *eurusdM5SRBRStrategy;
// eurusdM5SRBRStrategy = new XSCXSRBRStrategy(
// eurusdSymbol,
// PERIOD_M5,
// PERIOD_H1,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// 0, // Max Longs
// 0, // Max Shorts
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
// );
// eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
// eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(eurusdM5SRBRStrategy);
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *eurusdM15SRBRStrategy;
// eurusdM15SRBRStrategy = new XSCXSRBRStrategy(
// eurusdSymbol,
// PERIOD_M15,
// PERIOD_M30,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts, // Max Shorts
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
// );
// eurusdM15SRBRStrategy.SetAlertLogAlerts(true);
// eurusdM15SRBRStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(eurusdM15SRBRStrategy);
// }
// //
// // XEMRNG ...
// if (useXEMRNG)
// {
// //
// XSCXEMRNGStrategy *eurusdM5EMRNGStrategy;
// eurusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
// eurusdSymbol,
// PERIOD_M5,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts // Max Shorts
// );
// eurusdM5EMRNGStrategy.SetAlertLogAlerts(true);
// eurusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(eurusdM5EMRNGStrategy);
// }
// //
// // XOBVG ...
// if (useXOBVG)
// {
// //
// XSCXOBVGStrategy *eurusdM5OBVGStrategy;
// eurusdM5OBVGStrategy = new XSCXOBVGStrategy(
// eurusdSymbol,
// PERIOD_M5,
// PERIOD_H2, // Analyzing Period
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// false, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts // Max Shorts
// );
// eurusdM5OBVGStrategy.SetAlertLogAlerts(true);
// eurusdM5OBVGStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(eurusdM5OBVGStrategy);
// }
// //
// // XPVFMC ...
// if (useXPVFMC)
// {
// //
// XSCXPVFMCStrategy *eurusdM5PVFMCStrategy;
// eurusdM5PVFMCStrategy = new XSCXPVFMCStrategy(
// eurusdSymbol,
// PERIOD_M5,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// false, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts // Max Shorts
// );
// eurusdM5PVFMCStrategy.SetAlertLogAlerts(true);
// eurusdM5PVFMCStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(eurusdM5PVFMCStrategy);
// }
}
//
// USDCHF ...
string usdchfSymbol = "USDCHFb";
if (useUSDCHF && IsValid(usdchfSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 2;
// //
// // XSRBR ...
// if (useXSRBR)
// {
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *usdchfM5SRBRStrategy;
// usdchfM5SRBRStrategy = new XSCXSRBRStrategy(
// usdchfSymbol,
// PERIOD_M5,
// PERIOD_H1,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts, // Max Shorts
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
// );
// usdchfM5SRBRStrategy.SetAlertLogAlerts(true);
// usdchfM5SRBRStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(usdchfM5SRBRStrategy);
// }
// //
// // XEMRNG ...
// if (useXEMRNG)
// {
// //
// XSCXEMRNGStrategy *usdchfM5EMRNGStrategy;
// usdchfM5EMRNGStrategy = new XSCXEMRNGStrategy(
// usdchfSymbol,
// PERIOD_M5,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts // Max Shorts
// );
// usdchfM5EMRNGStrategy.SetAlertLogAlerts(true);
// usdchfM5EMRNGStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(usdchfM5EMRNGStrategy);
// }
}
//
// USDJPY ...
string usdjpySymbol = "USDJPYb";
if (useUSDJPY && IsValid(usdjpySymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 3;
// //
// // XSRBR ...
// if (useXSRBR)
// {
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *usdjpyM5SRBRStrategy;
// usdjpyM5SRBRStrategy = new XSCXSRBRStrategy(
// usdjpySymbol,
// PERIOD_M5,
// PERIOD_M30,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts, // Max Shorts
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
// );
// usdjpyM5SRBRStrategy.SetAlertLogAlerts(true);
// usdjpyM5SRBRStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(usdjpyM5SRBRStrategy);
// }
// //
// // XEMRNG ...
// if (useXEMRNG)
// {
// //
// XSCXEMRNGStrategy *usdjpyM5EMRNGStrategy;
// usdjpyM5EMRNGStrategy = new XSCXEMRNGStrategy(
// usdjpySymbol,
// PERIOD_M5,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts // Max Shorts
// );
// usdjpyM5EMRNGStrategy.SetAlertLogAlerts(true);
// usdjpyM5EMRNGStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(usdjpyM5EMRNGStrategy);
// }
}
//
// GBPUSD ...
string gbpusdSymbol = "GBPUSDb";
if (useGBPUSD && IsValid(gbpusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 4;
// //
// // XSRBR ...
// if (useXSRBR)
// {
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *gbpusdM5SRBRStrategy;
// gbpusdM5SRBRStrategy = new XSCXSRBRStrategy(
// gbpusdSymbol,
// PERIOD_M5,
// PERIOD_H1,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts, // Max Shorts
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
// );
// gbpusdM5SRBRStrategy.SetAlertLogAlerts(true);
// gbpusdM5SRBRStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(gbpusdM5SRBRStrategy);
// }
// //
// // XEMRNG ...
// if (useXEMRNG)
// {
// //
// XSCXEMRNGStrategy *gbpusdM5EMRNGStrategy;
// gbpusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
// gbpusdSymbol,
// PERIOD_M5,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts // Max Shorts
// );
// gbpusdM5EMRNGStrategy.SetAlertLogAlerts(true);
// gbpusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(gbpusdM5EMRNGStrategy);
// }
}
//
// XAUUSD ...
string xauusdSymbol = "XAUUSDb";
if (useXAUUSD && IsValid(xauusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 5;
// //
// // XSRBR ...
// if (useXSRBR)
// {
// //
// // Register XSRBR on EURUSD in M5 ...
// XSCXSRBRStrategy *xauusdM5SRBRStrategy;
// xauusdM5SRBRStrategy = new XSCXSRBRStrategy(
// xauusdSymbol,
// PERIOD_M15,
// PERIOD_M30,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts, // Max Shorts
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
// );
// xauusdM5SRBRStrategy.SetAlertLogAlerts(true);
// xauusdM5SRBRStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(xauusdM5SRBRStrategy);
// }
// //
// // XEMRNG ...
// if (useXEMRNG)
// {
// //
// XSCXEMRNGStrategy *xauusdM5EMRNGStrategy;
// xauusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
// xauusdSymbol,
// PERIOD_M5,
// eaVolume,
// eaR2R, // R2R ...
// eaSlippage,
// magicNumber,
// true, // Use TP SL Point
// false, // Use Max
// eaTPPoint, // TP
// eaSLPoint, // SL
// eaAllowLong,
// eaAllowShort,
// eaMaxAllowedLongs, // Max Longs
// eaMaxAllowedShorts // Max Shorts
// );
// xauusdM5EMRNGStrategy.SetAlertLogAlerts(true);
// xauusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
// RegisterStrategy(xauusdM5EMRNGStrategy);
// }
}
//
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 ...
//
+30 -364
View File
@@ -28,9 +28,7 @@
#include "../Helpers/x-saherelm.xcc.helper.mq5" #include "../Helpers/x-saherelm.xcc.helper.mq5"
// //
#include "../Strategies/x-saherelm.xobvg.strategy.mq5" #include "../Strategies/x-saherelm.xtest.strategy.mq5"
#include "../Strategies/x-saherelm.xsrbr.strategy.mq5"
#include "../Strategies/x-saherelm.xemrng.strategy.mq5"
// //
// Inputs ... // Inputs ...
@@ -50,6 +48,10 @@ int eaMaxAllowedShorts = 0;
double eaTPPoint = 200; double eaTPPoint = 200;
double eaSLPoint = 100; double eaSLPoint = 100;
//
bool eaIgnoreTP = false;
bool eaIgnoreSL = false;
// //
double eaR2R = 2; double eaR2R = 2;
@@ -124,7 +126,11 @@ void OnDeinit(const int reason)
// On Tick Handler ... // On Tick Handler ...
void OnTick() void OnTick()
{ {
//
HandleStrategiesOnTick(); HandleStrategiesOnTick();
//
HandleTradeState();
} }
// //
@@ -205,7 +211,9 @@ bool InitialEA()
// //
bool useXSRBR = false; bool useXSRBR = false;
bool useXEMRNG = false; bool useXEMRNG = false;
bool useXOBVG = true; bool useXOBVG = false;
bool useXPVFMC = false;
bool useXTest = true;
// //
// EURUSD ... // EURUSD ...
@@ -217,381 +225,32 @@ bool InitialEA()
long magicNumber = eaMagicNumber + 1; long magicNumber = eaMagicNumber + 1;
// //
// XSRBR ... // XTest ...
if (useXSRBR) if (useXTest)
{ {
// //
// Register XSRBR on EURUSD in M5 ... XSCXTestStrategy *eurusdTestStrategy;
XSCXSRBRStrategy *eurusdM5SRBRStrategy; eurusdTestStrategy = new XSCXTestStrategy(
eurusdM5SRBRStrategy = new XSCXSRBRStrategy(
eurusdSymbol,
PERIOD_M5,
PERIOD_H1,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
0, // Max Longs
0, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdM5SRBRStrategy);
//
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *eurusdM15SRBRStrategy;
eurusdM15SRBRStrategy = new XSCXSRBRStrategy(
eurusdSymbol,
PERIOD_M15,
PERIOD_M30,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
eurusdM15SRBRStrategy.SetAlertLogAlerts(true);
eurusdM15SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdM15SRBRStrategy);
}
//
// XEMRNG ...
if (useXEMRNG)
{
//
XSCXEMRNGStrategy *eurusdM5EMRNGStrategy;
eurusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
eurusdSymbol, eurusdSymbol,
PERIOD_M5, PERIOD_M5,
eaVolume, eaVolume,
eaR2R, // R2R ... eaR2R, // R2R ...
eaSlippage, eaSlippage,
magicNumber, magicNumber,
true, // Use TP SL Point true, // Use TP SL Point
false, // Use Max false, // Use Max
eaTPPoint, // TP 100, // eaTPPoint, // TP
eaSLPoint, // SL eaSLPoint, // SL
eaIgnoreTP,
true, // eaIgnoreSL,
eaAllowLong, eaAllowLong,
eaAllowShort, eaAllowShort,
eaMaxAllowedLongs, // Max Longs eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts eaMaxAllowedShorts // Max Shorts
); );
eurusdM5EMRNGStrategy.SetAlertLogAlerts(true); eurusdTestStrategy.SetAlertLogAlerts(true);
eurusdM5EMRNGStrategy.SetAlertEnableAlerts(true); eurusdTestStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdM5EMRNGStrategy); RegisterStrategy(eurusdTestStrategy);
}
//
// XOBVG ...
if (useXOBVG)
{
//
XSCXOBVGStrategy *eurusdM5OBVGStrategy;
eurusdM5OBVGStrategy = new XSCXOBVGStrategy(
eurusdSymbol,
PERIOD_M5,
PERIOD_H2, // Analyzing Period
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
false, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts
);
eurusdM5OBVGStrategy.SetAlertLogAlerts(true);
eurusdM5OBVGStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdM5OBVGStrategy);
}
}
//
// USDCHF ...
string usdchfSymbol = "USDCHFb";
if (useUSDCHF && IsValid(usdchfSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 2;
//
// XSRBR ...
if (useXSRBR)
{
//
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *usdchfM5SRBRStrategy;
usdchfM5SRBRStrategy = new XSCXSRBRStrategy(
usdchfSymbol,
PERIOD_M5,
PERIOD_H1,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
usdchfM5SRBRStrategy.SetAlertLogAlerts(true);
usdchfM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(usdchfM5SRBRStrategy);
}
//
// XEMRNG ...
if (useXEMRNG)
{
//
XSCXEMRNGStrategy *usdchfM5EMRNGStrategy;
usdchfM5EMRNGStrategy = new XSCXEMRNGStrategy(
usdchfSymbol,
PERIOD_M5,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts
);
usdchfM5EMRNGStrategy.SetAlertLogAlerts(true);
usdchfM5EMRNGStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(usdchfM5EMRNGStrategy);
}
}
//
// USDJPY ...
string usdjpySymbol = "USDJPYb";
if (useUSDJPY && IsValid(usdjpySymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 3;
//
// XSRBR ...
if (useXSRBR)
{
//
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *usdjpyM5SRBRStrategy;
usdjpyM5SRBRStrategy = new XSCXSRBRStrategy(
usdjpySymbol,
PERIOD_M5,
PERIOD_M30,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
usdjpyM5SRBRStrategy.SetAlertLogAlerts(true);
usdjpyM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(usdjpyM5SRBRStrategy);
}
//
// XEMRNG ...
if (useXEMRNG)
{
//
XSCXEMRNGStrategy *usdjpyM5EMRNGStrategy;
usdjpyM5EMRNGStrategy = new XSCXEMRNGStrategy(
usdjpySymbol,
PERIOD_M5,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts
);
usdjpyM5EMRNGStrategy.SetAlertLogAlerts(true);
usdjpyM5EMRNGStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(usdjpyM5EMRNGStrategy);
}
}
//
// GBPUSD ...
string gbpusdSymbol = "GBPUSDb";
if (useGBPUSD && IsValid(gbpusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 4;
//
// XSRBR ...
if (useXSRBR)
{
//
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *gbpusdM5SRBRStrategy;
gbpusdM5SRBRStrategy = new XSCXSRBRStrategy(
gbpusdSymbol,
PERIOD_M5,
PERIOD_H1,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
gbpusdM5SRBRStrategy.SetAlertLogAlerts(true);
gbpusdM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(gbpusdM5SRBRStrategy);
}
//
// XEMRNG ...
if (useXEMRNG)
{
//
XSCXEMRNGStrategy *gbpusdM5EMRNGStrategy;
gbpusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
gbpusdSymbol,
PERIOD_M5,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts
);
gbpusdM5EMRNGStrategy.SetAlertLogAlerts(true);
gbpusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(gbpusdM5EMRNGStrategy);
}
}
//
// XAUUSD ...
string xauusdSymbol = "XAUUSDb";
if (useXAUUSD && IsValid(xauusdSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = eaMagicNumber + 5;
//
// XSRBR ...
if (useXSRBR)
{
//
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *xauusdM5SRBRStrategy;
xauusdM5SRBRStrategy = new XSCXSRBRStrategy(
xauusdSymbol,
PERIOD_M15,
PERIOD_M30,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
xauusdM5SRBRStrategy.SetAlertLogAlerts(true);
xauusdM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(xauusdM5SRBRStrategy);
}
//
// XEMRNG ...
if (useXEMRNG)
{
//
XSCXEMRNGStrategy *xauusdM5EMRNGStrategy;
xauusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
xauusdSymbol,
PERIOD_M5,
eaVolume,
eaR2R, // R2R ...
eaSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
eaTPPoint, // TP
eaSLPoint, // SL
eaAllowLong,
eaAllowShort,
eaMaxAllowedLongs, // Max Longs
eaMaxAllowedShorts // Max Shorts
);
xauusdM5EMRNGStrategy.SetAlertLogAlerts(true);
xauusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(xauusdM5EMRNGStrategy);
} }
} }
@@ -639,6 +298,13 @@ void HandleStrategiesOnTick()
} }
} }
//
void HandleTradeState()
{
//
// Implement All Trade States here ...
}
// //
// Custom Testing Functions ... // Custom Testing Functions ...
+1 -1
View File
@@ -2987,7 +2987,7 @@ public:
bool GetConditions( bool GetConditions(
XCHMAConditions &conditions, // XCHMAConditions &conditions, //
int barIndex = 0, // int barIndex = 0, //
int loopback = 3 // int loopback = 5 //
) )
{ {
// //
+3 -3
View File
@@ -843,16 +843,16 @@ public:
bool GetConditions( bool GetConditions(
XMCConditions &conditions, // XMCConditions &conditions, //
int barIndex = 0, // int barIndex = 0, //
int loopback = 3 // int loopback = 5 //
) )
{ {
// //
bool result = true; bool result = true;
// //
if (loopback < 3) if (loopback < 5)
{ {
loopback = 3; loopback = 5;
} }
// //
+3 -3
View File
@@ -2315,16 +2315,16 @@ public:
bool GetConditions( bool GetConditions(
XPVConditions &conditions, // XPVConditions &conditions, //
int barIndex = 0, // int barIndex = 0, //
int loopback = 3 // int loopback = 5 //
) )
{ {
// //
bool result = true; bool result = true;
// //
if (loopback < 3) if (loopback < 5)
{ {
loopback = 3; loopback = 5;
} }
// //
-6
View File
@@ -507,12 +507,6 @@ int OnCalculate(
// Main Loop ... // Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--) for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{ {
//
// For Improve Indicator Speed ...
if (i > 1000) {
continue;
}
// //
CalculateBuffers(i); CalculateBuffers(i);
} }
+215 -1
View File
@@ -1663,6 +1663,111 @@ struct XOHCL
return result; return result;
} }
//
// Touches ...
//
bool IsBullishTouched(double price)
{
//
bool result = false;
//
result =
//
IsValid()
//
&&
//
price > 0
//
;
if (!result)
{
return result;
}
//
XOHCL pBar;
result = GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
result =
//
(pBar.low <= price ||
pBar.GetDown() <= price)
//
&&
//
(pBar.high > price ||
pBar.GetUp() > price)
//
&&
//
open > price &&
low > price
//
;
//
return result;
}
//
bool IsBearishTouched(double price)
{
//
bool result = false;
//
result =
//
IsValid()
//
&&
//
price > 0
//
;
if (!result)
{
return result;
}
//
XOHCL pBar;
result = GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
result =
//
(pBar.high >= price ||
pBar.GetUp() >= price)
//
&&
//
(pBar.low < price ||
pBar.GetDown() < price)
//
&&
//
open < price &&
high < price
//
;
//
return result;
}
// //
// Candlestic Patterns ... // Candlestic Patterns ...
@@ -2405,6 +2510,60 @@ struct XOHCL
return result; return result;
} }
//
// Find Last Swing High ...
bool FindLastSwingHigh(XOHCL &swing)
{
//
bool result = false;
//
swing.Clean();
//
result = IsValid();
if (!result)
{
return result;
}
//
int totalBars = iBars(
symbol,
period //
);
int maxAllowed = MathMin(100, (totalBars / 100));
//
int idx = Index();
for (int i = idx; i <= idx + maxAllowed; i++)
{
//
swing.Clean();
result = swing.Init(
symbol,
period,
i //
);
if (!result)
{
//
swing.Clean();
break;
}
//
result = swing.IsSwingHigh();
if (result)
{
break;
}
}
//
return result;
}
// //
// Check Swing Low ... // Check Swing Low ...
bool IsSwingLow() bool IsSwingLow()
@@ -2476,6 +2635,60 @@ struct XOHCL
return result; return result;
} }
//
// Find Last Swing Low ...
bool FindLastSwingLow(XOHCL &swing)
{
//
bool result = false;
//
swing.Clean();
//
result = IsValid();
if (!result)
{
return result;
}
//
int totalBars = iBars(
symbol,
period //
);
int maxAllowed = MathMin(100, (totalBars / 100));
//
int idx = Index();
for (int i = idx; i <= idx + maxAllowed; i++)
{
//
swing.Clean();
result = swing.Init(
symbol,
period,
i //
);
if (!result)
{
//
swing.Clean();
break;
}
//
result = swing.IsSwingLow();
if (result)
{
break;
}
}
//
return result;
}
// //
// Check Bullish FVG ... // Check Bullish FVG ...
bool HasBullishFVG( bool HasBullishFVG(
@@ -3479,7 +3692,8 @@ struct XOHCL
period, period,
cIDX // cIDX //
); );
if (!result) { if (!result)
{
break; break;
} }
+196
View File
@@ -46,6 +46,202 @@ string XTLSBearishOrderBlockToken = "XBearishOrderBlock";
// //
// Helper Tools ... // Helper Tools ...
//
bool HasBullishPattern(
XOHCL &bar,
int loopback = 0,
int verifications = 1,
bool checkHammer = true,
bool checkMorningStar = true,
bool checkBullishMarubozu = true,
bool checkBullishEngulfing = true //
)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
if (verifications <= 0)
{
verifications = 1;
}
//
int founded = 0;
//
int idx = bar.Index();
for (int i = idx; i <= idx + loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
bool isHammer =
!checkHammer
? false
: iBar.IsHammer();
if (isHammer)
{
founded++;
}
//
bool isMorningStar =
!checkMorningStar
? false
: iBar.IsMorningStar();
if (isMorningStar)
{
founded++;
}
//
bool isBullishMarubozu =
!checkBullishMarubozu
? false
: iBar.IsBullishMarubozu();
if (isBullishMarubozu)
{
founded++;
}
//
bool isBullishEngulfing =
!checkBullishEngulfing
? false
: iBar.IsBullishEngulfing();
if (isBullishEngulfing)
{
founded++;
}
//
}
//
result =
result &&
founded >= verifications;
//
return result;
}
//
bool HasBearishPattern(
XOHCL &bar,
int loopback = 0,
int verifications = 1,
bool checkShootingStar = true,
bool checkEveningStar = true,
bool checkBearishMarubozu = true,
bool checkBearishEngulfing = true //
)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
if (verifications <= 0)
{
verifications = 1;
}
//
int founded = 0;
//
int idx = bar.Index();
for (int i = idx - 1; i <= idx + loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
bool isShootingStar =
!checkShootingStar
? false
: iBar.IsShootingStar();
if (isShootingStar)
{
founded++;
}
//
bool isEveningStar =
!checkEveningStar
? false
: iBar.IsEveningStar();
if (isEveningStar)
{
founded++;
}
//
bool isBearishMarubozu =
!checkBearishMarubozu
? false
: iBar.IsBearishMarubozu();
if (isBearishMarubozu)
{
founded++;
}
//
bool isBearishEngulfing =
!checkBearishEngulfing
? false
: iBar.IsBearishEngulfing();
if (isBearishEngulfing)
{
founded++;
}
//
}
//
result =
result &&
founded >= verifications;
//
return result;
}
// //
bool IsSupportBreaked( bool IsSupportBreaked(
XOHCL &bar, // Support Bar XOHCL &bar, // Support Bar
+742
View File
@@ -0,0 +1,742 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXPVFMCStrategy
// 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 "../Helpers/x-saherelm.xhk.helper.mq5"
#include "../Helpers/x-saherelm.xmc.helper.mq5"
#include "../Helpers/x-saherelm.xtd.helper.mq5"
#include "../Helpers/x-saherelm.xpv.helper.mq5"
#include "../Helpers/x-saherelm.xvlm.helper.mq5"
#include "../Helpers/x-saherelm.xosc.helper.mq5"
#include "../Classes/x-saherelm.xstrategy.class.mq5"
//
string XPVFMCStartegyToken = "XPVFMC";
//
class XSCXPVFMCStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXPVFMCStrategy(
//
// 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 _useTPSLAsPoint = false, // Converts TP and SL by Provided Points
bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points
double _tpPoint = 0, // TP As Point
double _slPoint = 0, // SL As Point
bool _allowLong = true,
bool _allowShort = true,
int _maxAllowedLongs = 0,
int _maxAllowedShorts = 0 //
) : XSCBaseStrategy(_symbol,
_period,
_volume,
_r2r,
_slippage,
_magicNumber,
_useTPSLAsPoint,
_forceMaxTPSLAsPoint,
_tpPoint,
_slPoint,
_allowLong,
_allowShort,
_maxAllowedLongs,
_maxAllowedShorts //
)
{
//
SetAlertPrefix(GetTag());
//
PrepareRequirements();
}
//
// Deconstructor ...
void ~XSCXPVFMCStrategy()
{
//
delete mcHelper;
delete pvHelper;
delete tdHelper;
delete hkHelper;
delete oscHelper;
delete vlmHelper;
}
//
// Getter / Setter (s) ...
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XPVFMCStartegyToken;
}
//
// 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 = POSITION_TYPE_BUY;
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
//
bool hasLong = false;
bool hasShort = false;
//
// XMC ...
XMCConditions mcConditions;
result = mcHelper.GetConditions(mcConditions);
if (!result)
{
return result;
}
//
// XPV ...
XPVConditions pvConditions;
result = pvHelper.GetConditions(pvConditions);
if (!result)
{
return result;
}
//
// XTD ...
XTDConditions tdConditions;
result = tdHelper.GetConditions(tdConditions);
if (!result)
{
return result;
}
//
// XHK ...
XHKConditions hkConditions;
result = hkHelper.GetConditions(hkConditions);
if (!result)
{
return result;
}
//
// XVLM ...
XVLMConditions vlmConditions;
result = vlmHelper.GetConditions(vlmConditions);
//
double atr = oscHelper.GetATR(1);
//
double rsis[];
ArraySetAsSeries(rsis, true);
oscHelper.CopyRSI(
0,
3,
rsis //
);
//
double points = GetPoints(mSymbol);
//
int zIndex = 0;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
// For Trend ...
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
// For Verifications ...
//
// Bar On Trading Period ...
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
cIndex //
);
if (!result)
{
return result;
}
// //
// // Find Lowest Low and Highest High ...
// double hh3 = cBar.FindHighest(
// 3,
// MODE_HIGH //
// );
// double ll3 = cBar.FindLowest(
// 3,
// MODE_LOW //
// );
//
XOHCL pBar;
result = cBar.GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
bool hasBullishPattern = HasBullishPattern(cBar);
bool isBullishTrend = cBar.HasBullishTrend(
tmpHSW,
tmpLSW,
true //
);
//
bool hasBearishPattern = HasBearishPattern(cBar);
//
bool isBearishTrend = cBar.HasBearishTrend(
tmpHSW,
tmpLSW,
false //
);
//
// Check Support Exists or Find ...
bool hasSupport = support.IsValid();
if (!hasSupport)
{
//
hasSupport =
//
cBar.HasSupport(support)
//
&&
//
MathAbs(pvConditions.fib3s[cIndex] - support.high) <= 10 * points
//
;
}
//
// Check Resistance Exists or Find ...
bool hasResistance = resistance.IsValid();
if (!hasResistance)
{
//
hasResistance =
//
cBar.HasResistance(resistance)
//
&&
//
MathAbs(pvConditions.fib3s[cIndex] - resistance.low) <= 10 * points
//
;
}
//
if (hasSupport)
{
//
DrawSupport(
support,
ChartID() //
);
//
supportTime = cBar.time;
//
// Check Price is Around Support ...
double priceDiff = MathMin(
MathAbs(cBar.low - support.high),
MathAbs(cBar.high - support.high)) /
points;
result =
//
priceDiff <= 50
//
;
if (!result)
{
//
CheckSupportValidation();
return result;
}
//
if (result && !isSupportTested)
{
isSupportTested = true;
}
//
// Long ...
hasLong =
//
(
//
isBullishTrend
//
||
//
hasBullishPattern
//
)
//
&&
//
(
//
(tdConditions.isSwitchedToBullish &&
hkConditions.isSMHKBullish)
//
||
//
(hkConditions.isSMHKSwitchedToBullish &&
tdConditions.isBullish)
//
||
//
(mcConditions.isFastCrossedOverSlow &&
mcConditions.isSlowOverVerifier)
//
)
//
;
//
if (hasLong)
{
//
type = POSITION_TYPE_BUY;
XOHCL swingLow;
bool hasSwing = cBar.FindLastSwingLow(swingLow);
if (!hasSwing)
{
sl = support.high - (50 * points);
}
else
{
//
DrawSwingLow(swingLow, ChartID());
sl = swingLow.low - atr;
RemoveSwingLow(swingLow);
swingLow.Clean();
}
}
}
// //
// if (hasResistance)
// {
// //
// DrawResistance(
// support,
// ChartID() //
// );
// //
// supportTime = cBar.time;
// //
// // Check Price is Around Support ...
// double priceDiff = MathMin(
// MathAbs(cBar.low - support.high),
// MathAbs(cBar.high - support.high)) /
// points;
// result =
// //
// priceDiff <= 50
// //
// ;
// if (!result)
// {
// //
// CheckResistanceValidation();
// return result;
// }
// //
// if (result && !isResistanceTested)
// {
// isResistanceTested = true;
// }
// }
//
result = hasLong || hasShort;
if (!result)
{
//
CheckSupportValidation();
return result;
}
//
if (hasSupport)
{
//
isSupportTested = false;
supportTime = NULL;
RemoveSupport(support);
support.Clean();
}
//
if (hasResistance)
{
//
isResistanceTested = false;
resistanceTime = NULL;
RemoveResistance(resistance);
resistance.Clean();
}
//
entry = GetEntry(mSymbol, type);
CalculateTPSLByPrice(
sl,
tp,
type,
entry,
r2r //
);
//
result = signal.Prepare(
mSymbol,
GetTag(),
mPeriod,
type,
mode,
entry,
mVolume,
sl,
tp //
);
//
return result;
}
//
// Protected ...
protected:
//
// Props ...
//
XOHCL support;
XOHCL resistance;
//
// XMC ...
XMCInputs mcInputs;
XSCXMCHelper *mcHelper;
//
XTDInputs tdInputs;
XSCXTDHelper *tdHelper;
//
// XPV ...
XPVInputs pvInputs;
XSCXPVHelper *pvHelper;
//
// XOSC ...
XOSCInputs oscInputs;
XSCXOSCHelper *oscHelper;
//
// XVLM ...
XVLMInputs vlmInputs;
XSCXVLMHelper *vlmHelper;
//
// XHK ...
XHKInputs hkInputs;
XSCXHKHelper *hkHelper;
//
// Private ...
private:
//
// Props ...
//
void PrepareRequirements()
{
//
support.Clean();
supportTime = NULL;
isSupportTested = false;
//
resistance.Clean();
resistanceTime = NULL;
isResistanceTested = false;
//
// Prepare XTD ...
tdInputs.Default();
//
tdHelper = new XSCXTDHelper();
tdHelper.Init(
mSymbol,
mPeriod,
tdInputs //
);
//
// Preparing XHK ...
hkInputs.Default();
hkInputs.smoothingLength = 14;
//
hkInputs.drawHikenAshi = false;
hkInputs.drawSmoothedHikenAshi = true;
//
hkHelper = new XSCXHKHelper();
hkHelper.Init(
mSymbol,
mPeriod,
hkInputs //
);
//
// Preparing XMC ...
mcInputs.Default();
//
mcInputs.showSar = false;
mcInputs.showFastMa = true;
mcInputs.showSlowMa = true;
mcInputs.showVerifierMa = true;
//
mcHelper = new XSCXMCHelper();
mcHelper.Init(
mSymbol,
mPeriod,
mcInputs //
);
//
// Preparing XPV ...
pvInputs.Default();
//
pvInputs.showPeaksAndVales = true;
pvInputs.showLevels = false;
pvInputs.showConsolidations = false;
pvInputs.showFibo1Levels = false;
pvInputs.showFibo2Levels = false;
pvInputs.showFibo3Levels = true;
pvInputs.showFibo4Levels = false;
pvInputs.showFibo5Levels = false;
//
pvHelper = new XSCXPVHelper();
pvHelper.Init(
mSymbol,
mPeriod,
pvInputs //
);
//
// Preparing XOSC ...
oscInputs.Default();
oscHelper = new XSCXOSCHelper();
oscHelper.Init(
mSymbol,
mPeriod,
oscInputs //
);
//
// Preparing XVLM ...
vlmInputs.Default();
vlmHelper = new XSCXVLMHelper();
vlmHelper.Init(
mSymbol,
mPeriod,
vlmInputs //
);
}
//
bool isSupportTested;
datetime supportTime;
void CheckSupportValidation()
{
//
if (!isSupportTested)
{
//
if (support.IsValid() && IsValid(supportTime))
{
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(supportTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
isSupportTested = false;
supportTime = NULL;
RemoveSupport(support);
support.Clean();
}
}
return;
}
//
XOHCL cBar;
bool isInited = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!isInited)
{
return;
}
//
double points = GetPoints(mSymbol);
//
// Find Price Distance ...
double highDiff = MathAbs(cBar.high - support.high);
double lowDiff = MathAbs(cBar.low - support.high);
//
bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points;
if (!isBreaked)
{
return;
}
//
isSupportTested = false;
RemoveSupport(support);
supportTime = NULL;
support.Clean();
}
//
bool isResistanceTested;
datetime resistanceTime;
void CheckResistanceValidation()
{
//
if (!isResistanceTested)
{
//
if (resistance.IsValid() && IsValid(resistanceTime))
{
//
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(resistanceTime))) / PeriodSeconds(mPeriod));
if (age >= 50)
{
//
isResistanceTested = false;
resistanceTime = NULL;
RemoveResistance(resistance);
resistance.Clean();
}
}
return;
}
//
XOHCL cBar;
bool isInited = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!isInited)
{
return;
}
//
double points = GetPoints(mSymbol);
//
// Find Price Distance ...
double highDiff = MathAbs(cBar.high - resistance.low);
double lowDiff = MathAbs(cBar.low - resistance.low);
//
bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points;
if (!isBreaked)
{
return;
}
//
isResistanceTested = false;
RemoveResistance(resistance);
resistanceTime = NULL;
resistance.Clean();
}
};
//
File diff suppressed because it is too large Load Diff