backup all works even x121 ...

This commit is contained in:
2024-07-30 03:03:28 +03:30
parent ca11ce988a
commit d0820387a5
249 changed files with 165974 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,444 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXEMRNGStrategy
// 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.xtm.helper.mq5"
#include "../Helpers/x-saherelm.xstr.helper.mq5"
#include "../Classes/x-saherelm.xstrategy.class.mq5"
//
string XEMRNGStartegyToken = "XEMRNG";
//
class XSCXEMRNGStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXEMRNGStrategy(
//
// 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 //
)
{
//
ConfigureRequirements();
//
SetAlertPrefix(GetTag());
}
//
// Deconstructor ...
void ~XSCXEMRNGStrategy()
{
delete mTMHelper;
delete mSTRHelper;
}
//
// Getter / Setter (s) ...
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XEMRNGStartegyToken;
}
//
// 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;
//
int start = 0;
int count = 5;
//
double tms[];
ArraySetAsSeries(tms, true);
mTMHelper.CopyMain(
start,
count,
tms //
);
//
XSTRConditions strConditions;
result = mSTRHelper.GetConditions(
strConditions,
start,
count //
);
if (!result)
{
return result;
}
//
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!result)
{
return result;
}
//
double hh5 = cBar.FindHighest(
5,
MODE_HIGH //
);
double ll5 = cBar.FindLowest(
5,
MODE_LOW //
);
//
XOHCL pBar;
result = cBar.GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
bool hasLong = false;
bool hasShort = false;
//
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
bool useHammer = true;
bool useMorningStar = false;
bool useBullishEngulfing = true;
bool useBullishMaurubozu = true;
//
bool useShootingStar = true;
bool useEveningStar = false;
bool useBearishEngulfing = true;
bool useBearishMaurubozu = true;
//
// Long ...
//
bool isHammer = !useHammer
? false
: cBar.IsHammer();
bool isMorningStar = !useMorningStar
? false
: cBar.IsMorningStar();
bool isBullishMarubozu = !useBullishEngulfing
? false
: cBar.IsBullishMarubozu();
bool isBullishEngulfing = !useBullishMaurubozu
? false
: cBar.IsBullishEngulfing();
//
bool isBullishTrend = cBar.HasBullishTrend(
tmpHSW,
tmpLSW,
true //
);
//
// Find Swing Low Above of EMA ...
// Find Swing High Above of EMA ...
// Fins Swing Low Below of EMA ...
// Detect Bullish Pattern ...
hasLong =
//
cBar.IsBullish()
//
&&
//
isBullishTrend
//
&&
//
cBar.close > tms[1]
//
&&
//
ll5 < tms[1]
//
&&
//
strConditions.isTrendSwitchedToBullish
//
&&
//
(
//
isHammer
//
||
//
isMorningStar
//
||
//
isBullishMarubozu
//
||
//
isBullishEngulfing
//
)
//
;
if (hasLong)
{
//
type = POSITION_TYPE_BUY;
//
sl = tmpLSW[ArraySize(tmpLSW) - 1].low;
}
//
// Short ...
bool isShootingStar = !useShootingStar
? false
: cBar.IsShootingStar();
bool isEveningStar = !useEveningStar
? false
: cBar.IsEveningStar();
bool isBearishEngulfing = !useBearishEngulfing
? false
: cBar.IsBearishEngulfing();
bool isBearishMaurubozu = !useBearishMaurubozu
? false
: cBar.IsBearishMarubozu();
//
bool isBearishTrend = cBar.HasBearishTrend(
tmpHSW,
tmpLSW,
true //
);
//
hasShort =
//
cBar.IsBearish()
//
&&
//
isBearishTrend
//
&&
//
cBar.close < tms[1]
//
&&
//
hh5 > tms[1]
//
&&
//
strConditions.isTrendSwitchedToBearish
//
&&
//
(
//
isShootingStar
//
||
//
isEveningStar
//
||
//
isBearishEngulfing
//
||
//
isBearishMaurubozu
//
)
//
;
if (hasShort)
{
//
type = POSITION_TYPE_SELL;
//
sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
}
//
result = hasLong || hasShort;
if (!result)
{
return result;
}
//
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 ...
//
XTMInputs mTMInputs; // Tren Magic Inputs ...
XSCXTMHelper *mTMHelper; // Trend Magic Helper Class ...
//
XSTRInputs mSTRInputs; // Super Trend Inputs ...
XSCXSTRHelper *mSTRHelper; // Super Trend Helper Class ...
//
// Private ...
private:
//
//
// Set Default TM Inputs ...
void ConfigureRequirements()
{
//
mTMInputs.maShift = 0;
mTMInputs.maPeriod = 100;
mTMInputs.maMethod = MODE_EMA;
mTMInputs.maAppliedTo = PRICE_CLOSE;
//
mTMInputs.showLine = true;
//
mTMHelper = new XSCXTMHelper();
//
mTMHelper.Init(
mSymbol,
mPeriod,
mTMInputs //
);
//
mSTRInputs.length = 14;
mSTRInputs.multiplier = 3.5;
mSTRInputs.appliedTo = PRICE_CLOSE;
//
mSTRInputs.showTrends = true;
mSTRInputs.fillTrends = false;
//
mSTRHelper = new XSCXSTRHelper();
mSTRHelper.Init(
mSymbol,
mPeriod,
mSTRInputs //
);
}
};
//
@@ -0,0 +1,823 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXOBVGStrategy
// 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.xosc.helper.mq5"
#include "../Classes/x-saherelm.xstrategy.class.mq5"
//
string XOBVGStartegyToken = "XOBVG";
//
class XSCXOBVGStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXOBVGStrategy(
//
// Base ...
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period, // Trading TimeFrame
ENUM_TIMEFRAMES _analyzingPeriod, // Analyzing Period
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 //
)
{
//
mAnalyzingPeriod = _analyzingPeriod;
//
SetAlertPrefix(GetTag());
//
PrepareRequirements();
//
fvgUpper = 0;
fvgLower = 0;
isFVGTouched = false;
//
oBar.Clean();
oBullishOrderBlock.Clean();
oBearishOrderBlock.Clean();
}
//
// Deconstructor ...
void ~XSCXOBVGStrategy()
{
delete oscHelper;
}
//
// Getter / Setter (s) ...
//
ENUM_TIMEFRAMES AnalyzingPeriod()
{
return mAnalyzingPeriod;
}
//
void AnalyzingPeriod(ENUM_TIMEFRAMES value)
{
mAnalyzingPeriod = value;
}
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XOBVGStartegyToken;
}
//
// 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;
//
// For Trend ...
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
// For Verifications ...
//
bool useHammer = true;
bool useMorningStar = false;
bool useBullishEngulfing = true;
bool useBullishMaurubozu = true;
//
bool useShootingStar = true;
bool useEveningStar = false;
bool useBearishEngulfing = true;
bool useBearishMaurubozu = true;
//
// Bar On Trading Period ...
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!result)
{
return result;
}
//
// 3 Bar LL and HH ...
double ll3 = cBar.FindLowest(
3,
MODE_LOW //
);
double hh3 = cBar.FindHighest(
3,
MODE_HIGH //
);
//
double atr = oscHelper.GetATR(1);
//
// Check OB Finder Bar ...
result = oBar.IsValid();
if (!result)
{
//
// Init OB Finder Bar ...
result = oBar.Init(
mSymbol,
mAnalyzingPeriod,
1 //
);
if (!result)
{
return result;
}
}
//
bool hasBullishOrderBlock = oBullishOrderBlock.IsValid();
bool hasBearishOrderBlock = oBearishOrderBlock.IsValid();
//
// Here we Have to Check Order Block Age ...
//
if (hasBullishOrderBlock)
{
//
int age = oBullishOrderBlock.Index();
result = age <= 26;
if (!result)
{
//
oBar.Clean();
oBullishOrderBlock.Clean();
fvgUpper = 0;
fvgLower = 0;
fvgTouchDate = NULL;
isFVGTouched = false;
//
RemoveDraws();
//
return result;
}
}
//
if (hasBearishOrderBlock)
{
//
int age = oBearishOrderBlock.Index();
result = age <= 26;
if (!result)
{
//
oBar.Clean();
oBearishOrderBlock.Clean();
fvgUpper = 0;
fvgLower = 0;
fvgTouchDate = NULL;
isFVGTouched = false;
//
RemoveDraws();
//
return result;
}
}
//
hasBullishOrderBlock = oBullishOrderBlock.IsValid();
hasBearishOrderBlock = oBearishOrderBlock.IsValid();
result =
//
hasBullishOrderBlock
//
||
//
hasBearishOrderBlock
//
;
if (!result)
{
//
// Detect Order Blocks ...
hasBullishOrderBlock = oBar.HasBullishOrderBlock(oBullishOrderBlock);
hasBearishOrderBlock = oBar.HasBearishOrderBlock(oBearishOrderBlock);
//
// Check OB Detected ...
result =
//
hasBullishOrderBlock
//
||
//
hasBearishOrderBlock
//
;
if (!result)
{
//
oBar.Clean();
oBullishOrderBlock.Clean();
oBearishOrderBlock.Clean();
//
fvgUpper = 0;
fvgLower = 0;
fvgTouchDate = NULL;
isFVGTouched = false;
//
return result;
}
}
//
// Long ...
if (hasBullishOrderBlock)
{
//
DrawBullishOrderBlock(
oBullishOrderBlock,
ChartID() //
);
//
// Detect an FVG Inside Order Block in Trading Period ...
result = FindBullishFVGInsideOrderBlock();
if (!result)
{
//
oBar.Clean();
oBullishOrderBlock.Clean();
fvgUpper = 0;
fvgLower = 0;
fvgTouchDate = NULL;
isFVGTouched = false;
//
RemoveDraws();
//
return result;
}
//
// Now We Have to Waits Until Price reached the FVG ...
if (!isFVGTouched)
{
//
isFVGTouched = ll3 < fvgUpper;
fvgTouchDate = TimeCurrent();
}
//
result = isFVGTouched;
if (!result)
{
return result;
}
//
// Now we Have to Wait for Pressure ...
//
bool isHammer = !useHammer
? false
: cBar.IsHammer();
bool isMorningStar = !useMorningStar
? false
: cBar.IsMorningStar();
bool isBullishMarubozu = !useBullishEngulfing
? false
: cBar.IsBullishMarubozu();
bool isBullishEngulfing = !useBullishMaurubozu
? false
: cBar.IsBullishEngulfing();
//
bool isBullishTrend = oBar.HasBullishTrend(
tmpHSW,
tmpLSW,
false //
);
//
hasLong =
//
true // isBullishTrend
//
&&
//
(
//
isHammer
//
||
//
isMorningStar
//
||
//
isBullishMarubozu
//
||
//
isBullishEngulfing
//
)
//
;
result = hasLong;
if (!result)
{
//
// Check FVG Touch Date ...
int cTimeSec = (int)TimeCurrent();
int tTimeSec = (int)fvgTouchDate;
int periodSec = PeriodSeconds(mPeriod);
int touchAge = (cTimeSec - tTimeSec) / periodSec;
if (touchAge >= 10)
{
//
oBar.Clean();
oBullishOrderBlock.Clean();
fvgUpper = 0;
fvgLower = 0;
fvgTouchDate = NULL;
isFVGTouched = false;
//
RemoveDraws();
}
//
return result;
}
//
type = POSITION_TYPE_BUY;
sl = cBar.low - atr;
}
//
// Short ...
if (hasBearishOrderBlock)
{
//
DrawBearishOrderBlock(
oBearishOrderBlock,
ChartID() //
);
//
// Detect an FVG Inside Order Block in Trading Period ...
result = FindBearishFVGInsideOrderBlock();
if (!result)
{
//
oBar.Clean();
oBearishOrderBlock.Clean();
fvgUpper = 0;
fvgLower = 0;
fvgTouchDate = NULL;
isFVGTouched = false;
//
RemoveDraws();
//
return result;
}
//
// Now We Have to Waits Until Price reached the FVG ...
if (!isFVGTouched)
{
//
isFVGTouched = hh3 > fvgLower;
fvgTouchDate = TimeCurrent();
}
//
result = isFVGTouched;
if (!result)
{
return result;
}
//
// Now we Have to Wait for Pressure ...
//
// Short ...
bool isShootingStar = !useShootingStar
? false
: cBar.IsShootingStar();
bool isEveningStar = !useEveningStar
? false
: cBar.IsEveningStar();
bool isBearishEngulfing = !useBearishEngulfing
? false
: cBar.IsBearishEngulfing();
bool isBearishMaurubozu = !useBearishMaurubozu
? false
: cBar.IsBearishMarubozu();
//
bool isBearishTrend = oBar.HasBearishTrend(
tmpHSW,
tmpLSW,
false //
);
//
hasShort =
//
true // isBearishTrend
//
&&
//
(
//
isShootingStar
//
||
//
isEveningStar
//
||
//
isBearishEngulfing
//
||
//
isBearishMaurubozu
//
)
//
;
result = hasShort;
if (!result)
{
//
// Check FVG Touch Date ...
int cTimeSec = (int)TimeCurrent();
int tTimeSec = (int)fvgTouchDate;
int periodSec = PeriodSeconds(mPeriod);
int touchAge = (cTimeSec - tTimeSec) / periodSec;
if (touchAge >= 10)
{
//
oBar.Clean();
oBearishOrderBlock.Clean();
fvgUpper = 0;
fvgLower = 0;
fvgTouchDate = NULL;
isFVGTouched = false;
//
RemoveDraws();
}
//
return result;
}
//
type = POSITION_TYPE_SELL;
sl = cBar.high + atr;
}
//
result = hasLong || hasShort;
if (!result)
{
return result;
}
//
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 ...
//
ENUM_TIMEFRAMES mAnalyzingPeriod; // Analyzing Period
//
XOSCInputs oscInputs;
XSCXOSCHelper *oscHelper;
//
// Private ...
private:
//
// Props ...
//
XOHCL oBar;
XOHCL oBullishOrderBlock;
XOHCL oBearishOrderBlock;
//
double fvgUpper;
double fvgLower;
bool isFVGTouched;
datetime fvgTouchDate;
//
void PrepareRequirements()
{
//
oscInputs.Default();
oscHelper = new XSCXOSCHelper();
oscHelper.Init(
mSymbol,
mPeriod,
oscInputs //
);
}
//
bool FindBullishFVGInsideOrderBlock()
{
//
bool result = false;
//
result = oBullishOrderBlock.IsValid();
if (!result)
{
return result;
}
//
int totalBars = iBars(
mSymbol,
mPeriod //
);
int maxAllowed = totalBars / 10;
//
for (int i = 0; i < maxAllowed; i++)
{
//
XOHCL iBar;
result = iBar.Init(
mSymbol,
mPeriod,
i //
);
if (!result)
{
break;
}
//
result = iBar.HasBullishFVG(
fvgUpper,
fvgLower //
);
if (!result)
{
continue;
}
//
// Check FVG has Correlation by OB ...
result =
//
// Full Inside ...
(fvgUpper <= oBullishOrderBlock.high &&
fvgLower >= oBullishOrderBlock.low)
//
||
//
(fvgUpper > oBullishOrderBlock.high &&
fvgLower >= oBullishOrderBlock.low &&
fvgLower <= oBullishOrderBlock.high)
//
||
//
(fvgUpper > oBullishOrderBlock.low &&
fvgUpper <= oBullishOrderBlock.high &&
fvgLower < oBullishOrderBlock.low)
//
;
if (result)
{
//
DrawBullishFVG(
iBar,
fvgUpper,
fvgLower,
ChartID() //
);
//
break;
}
}
//
return result;
}
//
bool FindBearishFVGInsideOrderBlock()
{
//
bool result = false;
//
result = oBearishOrderBlock.IsValid();
if (!result)
{
return result;
}
//
int totalBars = iBars(
mSymbol,
mPeriod //
);
int maxAllowed = totalBars / 10;
//
for (int i = 0; i < maxAllowed; i++)
{
//
XOHCL iBar;
result = iBar.Init(
mSymbol,
mPeriod,
i //
);
if (!result)
{
break;
}
//
result = iBar.HasBearishFVG(
fvgUpper,
fvgLower //
);
if (!result)
{
continue;
}
//
// Check FVG has Correlation by OB ...
result =
//
// Full Inside ...
(fvgUpper <= oBearishOrderBlock.high &&
fvgLower >= oBearishOrderBlock.low)
//
||
//
(fvgUpper > oBearishOrderBlock.high &&
fvgLower >= oBearishOrderBlock.low &&
fvgLower <= oBearishOrderBlock.high)
//
||
//
(fvgUpper > oBearishOrderBlock.low &&
fvgUpper <= oBearishOrderBlock.high &&
fvgLower < oBearishOrderBlock.low)
//
;
if (result)
{
//
DrawBearishFVG(
iBar,
fvgUpper,
fvgLower,
ChartID() //
);
//
break;
}
}
//
return result;
}
};
//
@@ -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();
}
};
//
@@ -0,0 +1,723 @@
///////////////////////////////////////////////////////
//
// 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
ENUM_TIMEFRAMES _analyzingPeriod, // Analyzing 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,
ENUM_X_SIGNALLING_DIRECTION _signallingDirection = X_SIGNALLING_TREND_DIRECTION // Signalling in Which Direction
) : XSCBaseStrategy(_symbol,
_period,
_volume,
_r2r,
_slippage,
_magicNumber,
_useTPSLAsPoint,
_forceMaxTPSLAsPoint,
_tpPoint,
_slPoint,
_allowLong,
_allowShort,
_maxAllowedLongs,
_maxAllowedShorts //
)
{
//
mAnalyzingPeriod = _analyzingPeriod;
mSignallingDirection = _signallingDirection;
//
SetAlertPrefix(GetTag());
}
//
// Getter / Setter (s) ...
//
ENUM_X_SIGNALLING_DIRECTION SignallingDirection()
{
return mSignallingDirection;
}
//
void SignallingDirection(ENUM_X_SIGNALLING_DIRECTION value)
{
mSignallingDirection = value;
}
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XSRBRStartegyToken;
}
//
// Check Conditions For Signal ...
bool HasSignal(
XSignal &signal //
) override
{
//
bool result = false;
//
double _threshold = 5;
double threshold = GetPoints(mSymbol) * _threshold;
//
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;
//
// 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;
//
// Verify Pressure for Signals ...
bool verifyPressure = true;
bool checkTrensByMethod2 = false;
//
bool checkHammer = false;
bool checkMorningStar = false;
bool checkBullishEngulfing = true;
//
bool checkShootingStar = false;
bool checkEveningStar = false;
bool checkBearishEngulfing = true;
//
isInBullishTrend = bar.HasBullishTrend(
highSwingBars,
lowSwingBars,
checkTrensByMethod2 //
);
if (!isInBullishTrend)
{
//
isInBearishTrend = bar.HasBearishTrend(
highSwingBars,
lowSwingBars,
checkTrensByMethod2 //
);
}
//
// Only Looks For Signals if aTrend Detected ...
result = isInBullishTrend || isInBearishTrend;
if (!result)
{
//
ResetRequirements();
return result;
}
//
if (isInBullishTrend)
{
//
DrawBullishTrend(
cBar,
highSwingBars,
lowSwingBars,
ChartID(),
true,
true //
);
}
else
{
//
DrawBearishTrend(
cBar,
highSwingBars,
lowSwingBars,
ChartID(),
true,
true //
);
}
//
// 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 ...
//
// In Trend Trading we must Waits for :
// - Support Rejection;
//
// Support Rejecting Hppens when Price Go Down of Support area and
// Go Up or
// Price Recive a Candlestic Pattern ...
//
// this Moving Up Make us Ready for Reciving a
// Candlestick Pattern which Prove us Buyers Pressure ...
// - Hammer;
// - Morning Star;
// - Bullish Engulfing;
//
XOHCL tmpSWH[];
XOHCL tmpSWL[];
//
bool isSupportRejected = IsSupportRejected(support, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
bool isResistanceBreaked = IsResistanceBreaked(resistance, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
//
bool isBullishTrend = cBar.HasBullishTrend(
tmpSWH,
tmpSWL,
true //
);
//
result =
//
isBullishTrend
//
&&
//
(
//
isSupportRejected
//
||
//
isResistanceBreaked
//
)
//
;
//
if (result)
{
//
type = POSITION_TYPE_BUY;
//
if (isSupportRejected)
{
//
sl = support.low - threshold;
RemoveSupport(support);
support.Clean();
}
//
if (isResistanceBreaked)
{
//
sl = resistance.low - threshold;
RemoveResistance(resistance);
resistance.Clean();
}
//
RemoveDraws(XTLSBullishTrendToken);
RemoveDraws(XTLSBearishTrendToken);
}
}
else if (isInBearishTrend)
{
//
// Find Short Signals ...
// since we are in Bearish Trend and
// we must do Trend Trading ...
//
XOHCL tmpSWH[];
XOHCL tmpSWL[];
//
bool isSupportBreaked = IsSupportBreaked(support, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
bool isResistanceRejected = IsResistanceRejected(resistance, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
//
bool isBearishTrend = cBar.HasBearishTrend(
tmpSWH,
tmpSWL,
true //
);
//
result =
//
isBearishTrend
//
&&
//
(
//
isSupportBreaked
//
||
//
isResistanceRejected
//
)
//
;
//
if (result)
{
//
type = POSITION_TYPE_SELL;
//
if (isSupportBreaked)
{
//
sl = support.high + threshold;
RemoveSupport(support);
support.Clean();
}
//
if (isResistanceRejected)
{
//
sl = resistance.high + threshold;
RemoveResistance(resistance);
resistance.Clean();
}
//
RemoveDraws(XTLSBullishTrendToken);
RemoveDraws(XTLSBearishTrendToken);
}
}
}
else
{
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 ...
//
XOHCL tmpSWH[];
XOHCL tmpSWL[];
//
bool isSupportBreaked = IsSupportBreaked(support, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
bool isResistanceRejected = IsResistanceRejected(resistance, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
//
bool isBearishTrend = cBar.HasBearishTrend(
tmpSWH,
tmpSWL,
true //
);
//
result =
//
true // isBearishTrend
//
&&
//
(
//
isSupportBreaked
//
||
//
isResistanceRejected
//
)
//
;
//
if (result)
{
//
type = POSITION_TYPE_SELL;
//
if (isSupportBreaked)
{
//
sl = support.high + threshold;
RemoveSupport(support);
support.Clean();
}
//
if (isResistanceRejected)
{
//
sl = resistance.high + threshold;
RemoveResistance(resistance);
resistance.Clean();
}
//
RemoveDraws(XTLSBullishTrendToken);
RemoveDraws(XTLSBearishTrendToken);
}
}
else if (isInBearishTrend)
{
//
// Find Long Signals ...
// since we are in Bearish Trend and
// we must do Trend Reversal Trading ...
//
XOHCL tmpSWH[];
XOHCL tmpSWL[];
//
bool isSupportRejected = IsSupportRejected(support, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
bool isResistanceBreaked = IsResistanceBreaked(resistance, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
//
bool isBullishTrend = cBar.HasBullishTrend(
tmpSWH,
tmpSWL,
true //
);
//
result =
//
true // isBullishTrend
//
&&
//
(
//
isSupportRejected
//
||
//
isResistanceBreaked
//
)
//
;
//
if (result)
{
//
type = POSITION_TYPE_BUY;
//
if (isSupportRejected)
{
//
sl = support.low - threshold;
RemoveSupport(support);
support.Clean();
}
//
if (isResistanceBreaked)
{
//
sl = resistance.low - threshold;
RemoveResistance(resistance);
resistance.Clean();
}
//
RemoveDraws(XTLSBullishTrendToken);
RemoveDraws(XTLSBearishTrendToken);
}
}
}
//
// Make Sure Signal Exists ...
if (!result)
{
//
RemoveDraws(XTLSBullishTrendToken);
RemoveDraws(XTLSBearishTrendToken);
//
ResetRequirements();
return result;
}
//
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 ...
//
ENUM_TIMEFRAMES mAnalyzingPeriod; // Analyzing Period
ENUM_X_SIGNALLING_DIRECTION mSignallingDirection; // Signalling Direction
//
XOHCL bar;
//
// Pivots ...
XOHCL support;
XOHCL resistance;
//
XOHCL lowSwingBars[];
XOHCL highSwingBars[];
//
// Private ...
private:
//
//
// Check Requirements Exists or not ...
bool HasRequirements()
{
//
bool result = false;
//
result =
//
bar.IsValid() &&
support.IsValid() &&
resistance.IsValid()
//
;
//
return result;
}
//
// Prepare Requirements ...
bool PrepareRequirements()
{
//
bool result = false;
//
if (support.IsValid())
{
RemoveSupport(support);
}
//
// Finding Analyzing Bar ...
result = bar.Init(
mSymbol,
mAnalyzingPeriod,
1 //
);
if (!result)
{
return result;
}
//
// Find Support Bar based on Analyzing Bar ...
result = bar.HasSupport(
support //
);
if (!result)
{
return result;
}
//
DrawSupport(support, ChartID(), 5);
//
if (resistance.IsValid())
{
RemoveResistance(resistance);
}
//
// Find Resistance Bar based on Analyzing Bar ...
result = bar.HasResistance(
resistance //
);
//
DrawResistance(resistance, ChartID(), 5);
//
return result;
}
//
// Reset Reqirements ...
void ResetRequirements()
{
//
if (IsSupportBreaked(support, false))
{
//
RemoveSupport(support);
support.Clean();
}
//
if (IsResistanceBreaked(resistance, false))
{
//
RemoveResistance(resistance);
resistance.Clean();
}
}
};
//
@@ -0,0 +1,446 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXEMRNGStrategy
// 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
//
// TODO: Complete this ...
//
/// Imports ...
#include "../Helpers/x-saherelm.xtm.helper.mq5"
#include "../Helpers/x-saherelm.xstr.helper.mq5"
#include "../Classes/x-saherelm.xstrategy.class.mq5"
//
string XEMRNGStartegyToken = "XEMRNG";
//
class XSCXEMRNGStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXEMRNGStrategy(
//
// 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 //
)
{
//
ConfigureRequirements();
//
SetAlertPrefix(GetTag());
}
//
// Deconstructor ...
void ~XSCXEMRNGStrategy()
{
delete mTMHelper;
}
//
// Getter / Setter (s) ...
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XEMRNGStartegyToken;
}
//
// 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;
//
int start = 0;
int count = 5;
//
double tms[];
ArraySetAsSeries(tms, true);
mTMHelper.CopyMain(
start,
count,
tms //
);
//
XSTRConditions strConditions;
result = mSTRHelper.GetConditions(
strConditions,
start,
count //
);
if (!result)
{
return result;
}
//
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!result)
{
return result;
}
//
double hh5 = cBar.FindHighest(
5,
MODE_HIGH //
);
double ll5 = cBar.FindLowest(
5,
MODE_LOW //
);
//
XOHCL pBar;
result = cBar.GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
bool hasLong = false;
bool hasShort = false;
//
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
bool useHammer = true;
bool useMorningStar = false;
bool useBullishEngulfing = true;
bool useBullishMaurubozu = true;
//
bool useShootingStar = true;
bool useEveningStar = false;
bool useBearishEngulfing = true;
bool useBearishMaurubozu = true;
//
// Long ...
//
bool isHammer = !useHammer
? false
: cBar.IsHammer();
bool isMorningStar = !useMorningStar
? false
: cBar.IsMorningStar();
bool isBullishMarubozu = !useBullishEngulfing
? false
: cBar.IsBullishMarubozu();
bool isBullishEngulfing = !useBullishMaurubozu
? false
: cBar.IsBullishEngulfing();
//
bool isBullishTrend = cBar.HasBullishTrend(
tmpHSW,
tmpLSW,
true //
);
//
// Find Swing Low Above of EMA ...
// Find Swing High Above of EMA ...
// Fins Swing Low Below of EMA ...
// Detect Bullish Pattern ...
hasLong =
//
cBar.IsBullish()
//
&&
//
isBullishTrend
//
&&
//
cBar.close > tms[1]
//
&&
//
ll5 < tms[1]
//
&&
//
strConditions.isTrendSwitchedToBullish
//
&&
//
(
//
isHammer
//
||
//
isMorningStar
//
||
//
isBullishMarubozu
//
||
//
isBullishEngulfing
//
)
//
;
if (hasLong)
{
//
type = POSITION_TYPE_BUY;
//
sl = tmpLSW[ArraySize(tmpLSW) - 1].low;
}
//
// Short ...
bool isShootingStar = !useShootingStar
? false
: cBar.IsShootingStar();
bool isEveningStar = !useEveningStar
? false
: cBar.IsEveningStar();
bool isBearishEngulfing = !useBearishEngulfing
? false
: cBar.IsBearishEngulfing();
bool isBearishMaurubozu = !useBearishMaurubozu
? false
: cBar.IsBearishMarubozu();
//
bool isBearishTrend = cBar.HasBearishTrend(
tmpHSW,
tmpLSW,
true //
);
//
hasShort =
//
cBar.IsBearish()
//
&&
//
isBearishTrend
//
&&
//
cBar.close < tms[1]
//
&&
//
hh5 > tms[1]
//
&&
//
strConditions.isTrendSwitchedToBearish
//
&&
//
(
//
isShootingStar
//
||
//
isEveningStar
//
||
//
isBearishEngulfing
//
||
//
isBearishMaurubozu
//
)
//
;
if (hasShort)
{
//
type = POSITION_TYPE_SELL;
//
sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
}
//
result = hasLong || hasShort;
if (!result)
{
return result;
}
//
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 ...
//
XTMInputs mTMInputs; // Tren Magic Inputs ...
XSCXTMHelper *mTMHelper; // Trend Magic Helper Class ...
//
XSTRInputs mSTRInputs; // Super Trend Inputs ...
XSCXSTRHelper *mSTRHelper; // Super Trend Helper Class ...
//
// Private ...
private:
//
//
// Set Default TM Inputs ...
void ConfigureRequirements()
{
//
mTMInputs.maShift = 0;
mTMInputs.maPeriod = 100;
mTMInputs.maMethod = MODE_EMA;
mTMInputs.maAppliedTo = PRICE_CLOSE;
//
mTMInputs.showLine = true;
//
mTMHelper = new XSCXTMHelper();
//
mTMHelper.Init(
mSymbol,
mPeriod,
mTMInputs //
);
//
mSTRInputs.length = 14;
mSTRInputs.multiplier = 3.5;
mSTRInputs.appliedTo = PRICE_CLOSE;
//
mSTRInputs.showTrends = true;
mSTRInputs.fillTrends = false;
//
mSTRHelper = new XSCXSTRHelper();
mSTRHelper.Init(
mSymbol,
mPeriod,
mSTRInputs //
);
}
};
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,384 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XNNTest MQL5 Expert Advisor
// -------------------------------------------------
// Name: XNNTest
// Description: an Exper Advisor which used RSI and MA
// 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 XNNTest"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.xtrade.class.mq5"
//
#define ShortName "XNNTest"
//
// Inputs ...
input group "Weights";
input double w0 = 0.5;
input double w1 = 0.5;
input double w2 = 0.5;
input double w3 = 0.5;
input double w4 = 0.5;
input double w5 = 0.5;
input double w6 = 0.5;
input double w7 = 0.5;
input double w8 = 0.5;
input double w9 = 0.5;
//
input double eaVolume = 0.01;
//
// Variables ...
int barsTotal;
//
string eaSymbol;
ENUM_TIMEFRAMES eaPeriod;
//
// This is our Data Provider ...
int rsiHandler = INVALID_HANDLE;
double rsi[];
//
double nnInputs[]; // Storing Inputs
double nnWeights[]; // Storing Weights;
//
double nnOutput; // Output Neuron Value
//
XSCTrade *mTrader;
//
// Initialization ...
int OnInit()
{
//
if (!InitialEA())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
IndicatorRelease(rsiHandler);
ArrayFree(rsi);
ArrayFree(nnInputs);
ArrayFree(nnWeights);
}
//
// On Tick Handler ...
void OnTick()
{
//
XPosition positions[];
//
XPosition longs[];
int longsCount = 0;
//
XPosition shorts[];
int shortsCount = 0;
//
int positionsCount = mTrader.GetPositions(
positions //
);
if (IsValidSize(positionsCount))
{
//
ExtractPositions(
positions,
longs,
shorts //
);
//
longsCount = ArraySize(longs);
shortsCount = ArraySize(shorts);
}
//
if (longsCount == 0 && shortsCount == 0)
{
//
double longEntry = GetEntry(eaSymbol, POSITION_TYPE_BUY);
mTrader.Buy(
eaSymbol,
eaPeriod,
eaVolume,
longEntry //
);
//
double shortEntry = GetEntry(eaSymbol, POSITION_TYPE_SELL);
mTrader.Sell(
eaSymbol,
eaPeriod,
eaVolume,
shortEntry //
);
}
//
return;
// int rsiCopiedData = CopyBuffer(
// rsiHandler,
// 0, // Line Index
// 1, // BarIndex
// 10, // Count
// rsi // Buffer
// );
// if (rsiCopiedData < 0)
// {
// //
// // Ignore Moving Forward when there isn't any Copied Data ...
// return;
// }
// //
// // Normalize Input Data ...
// double lower = 0;
// double upper = 1;
// //
// double max = rsi[ArrayMaximum(rsi)];
// double min = rsi[ArrayMinimum(rsi)];
// //
// ArrayFree(nnInputs);
// ArrayResize(nnInputs, 10);
// //
// for (int i = 0; i < ArraySize(rsi); i++)
// {
// nnInputs[i] = ((rsi[i] - min) * (upper - lower) / (max - min)) + lower;
// }
// //
// // Calculating Output ...
// nnOutput = CalculateNeuron(
// nnInputs,
// nnWeights //
// );
// //
// // Now we Can Use NN Output for Placing Trades ...
// //
// bool canBuy = nnOutput < 0.5;
// bool canSell = nnOutput >= 0.5;
// //
// XPosition positions[];
// XPosition longs[];
// XPosition shorts[];
// int positionsCount = mTrader.GetPositions(
// positions //
// );
// if (IsValidSize(positionsCount))
// {
// //
// ExtractPositions(
// positions,
// longs,
// shorts //
// );
// //
// if (canBuy)
// {
// //
// mTrader.Close(shorts, "Opposit");
// //
// if (ArraySize(longs) > 0)
// {
// return;
// }
// }
// else if (canSell)
// {
// //
// mTrader.Close(longs, "Opposit");
// //
// if (ArraySize(shorts) > 0)
// {
// return;
// }
// }
// }
// //
// double mEntry =
// canBuy
// ? GetEntry(eaSymbol, POSITION_TYPE_BUY)
// : GetEntry(eaSymbol, POSITION_TYPE_SELL);
// //
// if (canBuy)
// {
// //
// mTrader.Buy(
// eaSymbol,
// eaPeriod,
// eaVolume,
// mEntry //
// );
// }
// else if (canSell)
// {
// //
// mTrader.Sell(
// eaSymbol,
// eaPeriod,
// eaVolume,
// mEntry //
// );
// }
}
//
// Custom Functions ...
//
bool InitialEA()
{
//
bool result = false;
//
eaSymbol = _Symbol;
eaPeriod = _Period;
//
// Initialize RSI Handler ...
rsiHandler = iRSI(
eaSymbol,
eaPeriod,
14,
PRICE_CLOSE //
);
result = rsiHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
mTrader = new XSCTrade(
1,
78692110 //
);
//
ArraySetAsSeries(rsi, true);
//
ArrayResize(nnWeights, 10);
//
// Filling Weights Buffer ...
nnWeights[0] = w0;
nnWeights[1] = w1;
nnWeights[2] = w2;
nnWeights[3] = w3;
nnWeights[4] = w4;
nnWeights[5] = w5;
nnWeights[6] = w6;
nnWeights[7] = w7;
nnWeights[8] = w8;
nnWeights[9] = w9;
//
result = true;
//
return result;
}
//
// Activation Function ...
double Activate(double neuron)
{
//
double result = 0;
//
result = 1 / (1 + exp(-neuron));
//
return result;
}
//
// Calculating Neuron ...
// NET Inputs ...
double CalculateNeuron(
double &x[], // Inputs
double &w[] // Weights
)
{
//
double result = 0;
//
double netInput = 0;
for (int i = 0; i < ArraySize(x); i++)
{
//
netInput += x[i] * w[i];
}
//
// Change The Shape of Sigmoid Graph for Smoothing ...
netInput *= 0.4;
//
// Calculate Activated Result ...
result = Activate(netInput);
//
return result;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,678 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XADXTD
// Description: provides Indicator implementation
// 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"
//
// Indicator Buffers ...
enum ENUM_XADXTD_BUFFERS
{
XADXTD_STRENGTH_LINE = 0, // Strenght Buffer ...
XADXTD_BULL_LINE = 1, // Bull Buffer ...
XADXTD_BEAR_LINE = 2, // Bear Buffer ...
};
//
string GetTitle(ENUM_XADXTD_BUFFERS bufferLine)
{
//
string result = NULL;
//
switch (bufferLine)
{
//
case XADXTD_STRENGTH_LINE:
result = "XStrength";
break;
//
case XADXTD_BULL_LINE:
result = "XBull";
break;
//
case XADXTD_BEAR_LINE:
result = "XBear";
break;
}
//
return result;
}
//
// XADXTD Indicator Inputs ...
struct XADXTDInputs
{
//
// Props ...
string version;
//
// Market ...
//
int length; // Length
//
// Constructor ...
XADXTDInputs()
{
Clean();
}
//
// Tools ...
//
// Initial Inputs ...
bool Init(
int _length = 21 // Length
)
{
//
bool result = false;
//
this.length = _length;
//
result = IsValid();
//
return result;
}
//
// Cleanup ...
void Clean()
{
//
length = 0;
}
//
// Default ...
void Default()
{
//
length = 21;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length > 0
//
;
//
return result;
}
//
// Retrieve Max Length ...
int Max()
{
//
int result = 0;
//
int values[1] = {
length //
};
//
result = GetMax(values);
//
return result;
}
};
//
// Define Conditions ...
struct XADXTDConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
double strength[];
double bullp[];
double bearp[];
//
// Conditions ...
//
bool isStrong;
bool isBullish;
bool isBearish;
bool isSwitchedToBullish;
bool isSwitchedToBearish;
bool isStrongSwitchedToBullish;
bool isStrongSwitchedToBearish;
//
void Clean()
{
//
Clean(strength);
Clean(bullp);
Clean(bearp);
//
ArraySetAsSeries(strength, true);
ArraySetAsSeries(bullp, true);
ArraySetAsSeries(bearp, true);
//
isStrong = false;
isBullish = false;
isBearish = false;
isSwitchedToBullish = false;
isSwitchedToBearish = false;
isStrongSwitchedToBullish = false;
isStrongSwitchedToBearish = false;
}
//
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
if (isBullish)
{
//
bullishScore++;
if (isStrong)
{
bullishScore++;
}
}
if (isBearish)
{
bearishScore++;
if (isStrong)
{
bearishScore++;
}
}
if (isSwitchedToBullish)
{
bullishScore++;
if (isStrong)
{
bullishScore++;
}
}
if (isSwitchedToBearish)
{
bearishScore++;
if (isStrong)
{
bearishScore++;
}
}
if (isStrongSwitchedToBullish)
{
bullishScore++;
}
if (isStrongSwitchedToBearish)
{
bearishScore++;
}
}
//
string GenerateSummary(
bool onlyCommons = false,
bool onlyConditions = false,
bool includeScores = true,
bool ignoreFalseConditions = true,
string separator = "\n" //
)
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
GenerateScore(
bullishScore,
bearishScore //
);
//
string scoresStr =
//
"Scores: " + separator +
"---------------" + separator +
"Bullish: " + ToString(bullishScore) + separator +
"Bearish: " + ToString(bearishScore) + separator +
""
//
;
//
string commonStr = GenerateSpecifiedCommonSummary(
this,
separator,
includeScores //
);
//
string conditionsStr =
//
ToString("isStrong", isStrong, ignoreFalseConditions, separator) +
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
ToString("isStrongSwitchedToBullish", isStrongSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isStrongSwitchedToBearish", isStrongSwitchedToBearish, ignoreFalseConditions, separator) +
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag()
{
return "XADXTD";
}
};
//
// Indicator Class ...
class XSCXADXTDHelper : public XSCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor(s) ...
void XSCXADXTDHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading TimeFrame
)
{
//
mSymbol = symbol;
mPeriod = period;
}
//
// Deconstructor ...
void ~XSCXADXTDHelper() {}
//
// Initialize Indicator ...
bool Init(
XADXTDInputs &inputs // Indicator Properties
)
{
//
bool result = false;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
// Set Inputs ...
this.mInputs = inputs;
//
// Validate Indicator State ...
result = this.IsValid();
if (!result)
{
return result;
}
//
result = DefineBuffers();
if (!result)
{
return result;
}
//
handler = iADX(
mSymbol,
mPeriod,
mInputs.length //
);
result = handler != INVALID_HANDLE;
//
return result;
}
//
XADXTDInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XADXTDInputs &inputs // Indicator Properties
)
{
return Init(inputs);
}
//
// Get Tag ...
string GetTag()
{
//
string result = NULL;
//
result = GetToken();
//
return result;
}
//
// Get Token ...
string GetToken()
{
//
string result = NULL;
//
result = GetSpecificToken(this);
//
return result;
}
//
string GetSymbol()
{
return mSymbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
mInputs.IsValid() &&
IsSpecifiedValid(mPeriod) &&
IsSpecifiedValid(mSymbol)
//
;
//
return result;
}
//
// De Initialize Class ...
void DeInit(int reason)
{
//
IndicatorRelease(handler);
}
//
// Tools ...
int CopyData(
ENUM_XADXTD_BUFFERS line,
double &dest[],
int start = 0,
int count = 1 //
)
{
//
int result = 0;
//
int mLine = -1;
switch (line)
{
//
case XADXTD_STRENGTH_LINE:
mLine = MAIN_LINE;
break;
//
case XADXTD_BULL_LINE:
mLine = PLUSDI_LINE;
break;
//
case XADXTD_BEAR_LINE:
mLine = MINUSDI_LINE;
break;
}
//
if (mLine == -1 || handler == INVALID_HANDLE)
{
return result;
}
//
result = CopyBuffer(
handler,
mLine,
start,
count,
dest //
);
//
return result;
}
//
bool GetConditions(
XADXTDConditions &conditions, //
int barIndex = 0, //
int loopback = 3 //
)
{
//
bool result = true;
//
if (loopback < 3)
{
loopback = 3;
}
//
conditions.Clean();
//
conditions.symbol = mSymbol;
conditions.period = mPeriod;
conditions.time = TimeCurrent();
//
int zIndex = barIndex;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
CopyData(
XADXTD_STRENGTH_LINE,
conditions.strength,
zIndex,
loopback //
);
CopyData(
XADXTD_BULL_LINE,
conditions.bullp,
zIndex,
loopback //
);
CopyData(
XADXTD_BEAR_LINE,
conditions.bearp,
zIndex,
loopback //
);
//
// Calculate Conditions ...
//
bool isStrong = conditions.strength[cIndex] >= 20;
//
bool isBullish = conditions.bullp[cIndex] > conditions.bearp[cIndex];
bool isBearish = conditions.bearp[cIndex] > conditions.bullp[cIndex];
//
bool isBullishPrev = conditions.bullp[pIndex] > conditions.bearp[pIndex];
bool isBearishPrev = conditions.bearp[pIndex] > conditions.bullp[pIndex];
//
bool isSwitchedToBullish = isBullish &&
!isBullishPrev;
bool isSwitchedToBearish = isBearish &&
!isBearishPrev;
//
bool isStrongSwitchedToBullish = isStrong &&
isSwitchedToBullish;
bool isStrongSwitchedToBearish = isStrong &&
isSwitchedToBearish;
//
conditions.isStrong = isStrong;
conditions.isBullish = isBullish;
conditions.isBearish = isBearish;
conditions.isSwitchedToBullish = isSwitchedToBullish;
conditions.isSwitchedToBearish = isSwitchedToBearish;
conditions.isStrongSwitchedToBullish = isStrongSwitchedToBullish;
conditions.isStrongSwitchedToBearish = isStrongSwitchedToBearish;
//
return result;
}
//
// Protected ...
protected:
//
// Props ...
int handler;
//
// Tools ...
bool DefineBuffers()
{
//
bool result = false;
//
result = true;
//
return result;
}
//
// Private ...
private:
//
// Props ...
//
string mSymbol; // Symbol
ENUM_TIMEFRAMES mPeriod; // TimeFrame
//
XADXTDInputs mInputs; // Properties
};
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,766 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSCXOBVGStrategy
// 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.xtm.helper.mq5"
#include "../Helpers/x-saherelm.xstr.helper.mq5"
#include "../Classes/x-saherelm.xstrategy.class.mq5"
//
string XOBVGStartegyToken = "XOBVG";
//
class XSCXOBVGStrategy : public XSCBaseStrategy
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCXOBVGStrategy(
//
// Base ...
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period, // Trading TimeFrame
ENUM_TIMEFRAMES _hindPeriod, // Hind Period
ENUM_TIMEFRAMES _mediestPeriod, // Mediest Period
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 //
)
{
//
mHindPeriod = _hindPeriod;
mMediestPeriod = _mediestPeriod;
//
SetAlertPrefix(GetTag());
//
hindBar.Clean();
hindBullishOrderBlock.Clean();
hindBearishOrderBlock.Clean();
//
medBar.Clean();
medBullishOrderBlock.Clean();
medBearishOrderBlock.Clean();
}
//
// Deconstructor ...
void ~XSCXOBVGStrategy()
{
}
//
// Getter / Setter (s) ...
//
ENUM_TIMEFRAMES HindPeriod()
{
return mHindPeriod;
}
//
void HindPeriod(ENUM_TIMEFRAMES value)
{
mHindPeriod = value;
}
//
ENUM_TIMEFRAMES MediestPeriod()
{
return mMediestPeriod;
}
//
void MediestPeriod(ENUM_TIMEFRAMES value)
{
mMediestPeriod = value;
}
//
// Overrides ...
//
// Customize Strategy Identifier ...
string GetTag() override
{
return XOBVGStartegyToken;
}
//
// 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;
//
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
bool useHammer = true;
bool useMorningStar = false;
bool useBullishEngulfing = true;
bool useBullishMaurubozu = true;
//
bool useShootingStar = true;
bool useEveningStar = false;
bool useBearishEngulfing = true;
bool useBearishMaurubozu = true;
//
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
1 //
);
if (!result)
{
return result;
}
//
double ll3 = cBar.FindLowest(
3,
MODE_LOW //
);
double hh3 = cBar.FindHighest(
3,
MODE_HIGH //
);
//
result = hindBar.IsValid();
if (!result)
{
//
result = hindBar.Init(
mSymbol,
mHindPeriod,
1 //
);
if (!result)
{
return result;
}
}
//
bool hasBullishOrderBlock = hindBullishOrderBlock.IsValid();
bool hasBearishOrderBlock = hindBearishOrderBlock.IsValid();
result =
//
hasBullishOrderBlock
//
||
//
hasBearishOrderBlock
//
;
if (!result)
{
//
hasBullishOrderBlock = hindBar.HasBullishOrderBlock(hindBullishOrderBlock);
hasBearishOrderBlock = hindBar.HasBearishOrderBlock(hindBearishOrderBlock);
//
result =
//
hasBullishOrderBlock
//
||
//
hasBearishOrderBlock
//
;
if (!result)
{
//
hindBar.Clean();
return result;
}
}
//
if (hasBullishOrderBlock)
{
//
DrawBullishOrderBlock(
hindBullishOrderBlock,
ChartID() //
);
//
// Try to Detect and Order Block Inside this ...
// in Mediest ...
result = medBar.IsValid();
if (!result)
{
//
result = medBar.Init(
mSymbol,
mMediestPeriod,
1 //
);
if (!result)
{
//
medBar.Clean();
return result;
}
}
//
result = medBar.HasBullishOrderBlock(medBullishOrderBlock);
if (!result)
{
//
medBar.Clean();
return result;
}
//
DrawBullishOrderBlock(
medBullishOrderBlock,
ChartID() //
);
//
// Check Order Block Is Inside HINDOB ...
result =
//
(medBullishOrderBlock.low >= hindBullishOrderBlock.low &&
medBullishOrderBlock.low <= hindBullishOrderBlock.high)
//
||
//
(medBullishOrderBlock.high <= hindBullishOrderBlock.high &&
medBullishOrderBlock.high >= hindBullishOrderBlock.low)
//
;
//
if (result)
{
//
// Check Price ...
result =
//
ll3 < medBullishOrderBlock.high &&
ll3 > hindBullishOrderBlock.low
//
;
if (!result)
{
//
hindBar.Clean();
hindBullishOrderBlock.Clean();
hindBearishOrderBlock.Clean();
//
medBar.Clean();
medBullishOrderBlock.Clean();
medBearishOrderBlock.Clean();
//
fvgUpper = 0;
fvgLower = 0;
//
RemoveDraws();
//
return result;
}
//
hasLong = result;
}
else
{
//
// Detect and FVG Inside ...
result = medBar.HasBullishFVG(
fvgUpper,
fvgLower //
);
if (!result)
{
//
hindBar.Clean();
hindBullishOrderBlock.Clean();
hindBearishOrderBlock.Clean();
//
medBar.Clean();
medBullishOrderBlock.Clean();
medBearishOrderBlock.Clean();
//
fvgUpper = 0;
fvgLower = 0;
//
RemoveDraws();
//
return result;
}
//
DrawBullishFVG(
medBar,
fvgUpper,
fvgLower,
ChartID() //
);
//
result =
//
(fvgLower >= hindBullishOrderBlock.low &&
fvgLower <= hindBullishOrderBlock.high)
//
||
//
(fvgUpper <= hindBullishOrderBlock.high &&
fvgUpper >= hindBullishOrderBlock.low)
//
;
//
// Check Price ...
result =
//
ll3 < fvgUpper &&
ll3 > hindBullishOrderBlock.low
//
;
if (!result)
{
//
hindBar.Clean();
hindBullishOrderBlock.Clean();
hindBearishOrderBlock.Clean();
//
medBar.Clean();
medBullishOrderBlock.Clean();
medBearishOrderBlock.Clean();
//
fvgUpper = 0;
fvgLower = 0;
//
RemoveDraws();
//
return result;
}
//
hasLong = result;
}
}
//
if (hasBearishOrderBlock)
{
//
DrawBearishOrderBlock(
hindBearishOrderBlock,
ChartID() //
);
//
// Try to Detect and Order Block Inside this ...
// in Mediest ...
result = medBar.IsValid();
if (!result)
{
//
result = medBar.Init(
mSymbol,
mMediestPeriod,
1 //
);
if (!result)
{
//
medBar.Clean();
return result;
}
}
//
result = medBar.HasBearishOrderBlock(medBearishOrderBlock);
if (!result)
{
//
medBar.Clean();
return result;
}
//
DrawBearishOrderBlock(
medBearishOrderBlock,
ChartID() //
);
//
// Check Order Block Is Inside HINDOB ...
result =
//
(medBullishOrderBlock.low >= hindBearishOrderBlock.low &&
medBearishOrderBlock.low <= hindBearishOrderBlock.high)
//
||
//
(medBearishOrderBlock.high <= hindBearishOrderBlock.high &&
medBearishOrderBlock.high >= hindBearishOrderBlock.low)
//
;
if (!result)
{
//
// Detect and FVG Inside ...
result = medBar.HasBearishFVG(
fvgUpper,
fvgLower //
);
if (!result)
{
//
hindBar.Clean();
hindBullishOrderBlock.Clean();
hindBearishOrderBlock.Clean();
//
medBar.Clean();
medBullishOrderBlock.Clean();
medBearishOrderBlock.Clean();
//
fvgUpper = 0;
fvgLower = 0;
//
RemoveDraws();
//
return result;
}
//
DrawBearishFVG(
medBar,
fvgUpper,
fvgLower,
ChartID() //
);
//
result =
//
(fvgLower >= hindBearishOrderBlock.low &&
fvgLower <= hindBearishOrderBlock.high)
//
||
//
(fvgUpper <= hindBearishOrderBlock.high &&
fvgUpper >= hindBearishOrderBlock.low)
//
;
if (!result)
{
//
hindBar.Clean();
hindBullishOrderBlock.Clean();
hindBearishOrderBlock.Clean();
//
medBar.Clean();
medBullishOrderBlock.Clean();
medBearishOrderBlock.Clean();
//
fvgUpper = 0;
fvgLower = 0;
//
RemoveDraws();
//
return result;
}
}
}
//
result = hasLong || hasShort;
if (!result)
{
return result;
}
//
if (hasLong)
{
//
// Long ...
//
bool isHammer = !useHammer
? false
: cBar.IsHammer();
bool isMorningStar = !useMorningStar
? false
: cBar.IsMorningStar();
bool isBullishMarubozu = !useBullishEngulfing
? false
: cBar.IsBullishMarubozu();
bool isBullishEngulfing = !useBullishMaurubozu
? false
: cBar.IsBullishEngulfing();
//
bool isBullishTrend = cBar.HasBullishTrend(
tmpHSW,
tmpLSW,
true //
);
//
// Find Swing Low Above of EMA ...
// Find Swing High Above of EMA ...
// Fins Swing Low Below of EMA ...
// Detect Bullish Pattern ...
hasLong =
//
true
//
&&
//
(
//
isHammer
//
||
//
isMorningStar
//
||
//
isBullishMarubozu
//
||
//
isBullishEngulfing
//
)
//
;
if (hasLong)
{
//
type = POSITION_TYPE_BUY;
//
// sl = tmpLSW[ArraySize(tmpLSW) - 1].low;
}
}
//
if (hasShort)
{
//
// Short ...
bool isShootingStar = !useShootingStar
? false
: cBar.IsShootingStar();
bool isEveningStar = !useEveningStar
? false
: cBar.IsEveningStar();
bool isBearishEngulfing = !useBearishEngulfing
? false
: cBar.IsBearishEngulfing();
bool isBearishMaurubozu = !useBearishMaurubozu
? false
: cBar.IsBearishMarubozu();
//
bool isBearishTrend = cBar.HasBearishTrend(
tmpHSW,
tmpLSW,
true //
);
//
hasShort =
//
false
//
&&
//
(
//
isShootingStar
//
||
//
isEveningStar
//
||
//
isBearishEngulfing
//
||
//
isBearishMaurubozu
//
)
//
;
if (hasShort)
{
//
type = POSITION_TYPE_SELL;
//
// sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
}
}
//
result = hasLong || hasShort;
if (!result)
{
return result;
}
//
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 ...
//
ENUM_TIMEFRAMES mHindPeriod; // Hind Period
ENUM_TIMEFRAMES mMediestPeriod; // Mediest Period
//
// Private ...
private:
//
// Props ...
//
XOHCL hindBar;
XOHCL hindBullishOrderBlock;
XOHCL hindBearishOrderBlock;
//
XOHCL medBar;
XOHCL medBullishOrderBlock;
XOHCL medBearishOrderBlock;
//
double fvgUpper;
double fvgLower;
};
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -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();
}
};
//
@@ -0,0 +1,619 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XSAMPLE MQL5 Expert Advisor
// -------------------------------------------------
// Name: XSAMPLE
// Description: an Exper Advisor which used RSI and MA
// 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 XSAMPLE"
#property strict
//
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Classes/x-saherelm.xalert.class.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
#define ShortName "XSAMPLE"
//
int pivotLifeTime = 20;
int pivotBreakoutsLifeTime = 10;
ENUM_TIMEFRAMES destPEriod = PERIOD_H4;
//
int xAge = 0;
//
double lastHH = 0;
double lastUpper = 0;
double lastDestHH = 0;
//
double lastLL = 0;
double lastLower = 0;
double lastDestLL = 0;
//
datetime lastTime = NULL;
datetime lastDestTime = NULL;
//
XSCAlert *mAlert;
XSCTrade *mTrader;
//
XBarTracker xBarTracker;
XMarketCycle xDestCycle;
//
// Initialization ...
int OnInit()
{
//
drawPrefix = ShortName;
//
if (!InitialEA())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
}
//
// On Tick Handler ...
void OnTick()
{
//
if (!xBarTracker.IsNewBar())
{
return;
}
//
xDestCycle.Update(0);
//
Analyze();
//
ManxAge();
}
//
//
//
bool InitialEA()
{
//
bool result = false;
//
mAlert = new XSCAlert();
mAlert.SetLogAlerts(true);
mAlert.SetPrefix(ShortName);
mAlert.SetEnableAlerts(true);
mAlert.SetPushAlerts(false);
mAlert.SetMailAlerts(false);
mAlert.SetTerminalAlerts(false);
//
mTrader = new XSCTrade(
10,
78692110,
0,
0,
0 //
);
//
result = xBarTracker.Init(
_Symbol,
_Period //
);
if (!result)
{
return result;
}
//
result = xDestCycle.Init(
_Symbol,
_Period,
X_MARKET_CYCLE_MEDIUM,
X_PERIOD_MANUALLY,
destPEriod,
"DEST" //
);
if (!result)
{
return result;
}
//
result = true;
//
return result;
}
//
void Analyze()
{
//
XOHCL cBar;
cBar.Init(
_Symbol,
_Period,
1 //
);
//
if (IsLookingForBoundary())
{
FindBoundary();
return;
}
//
double longSLPrice = 0;
double shortSLPrice = 0;
// //
// xAge = 0;
// if (IsValid(lastTime))
// {
// //
// xAge = iBarShift(
// _Symbol,
// _Period,
// lastTime //
// );
// }
// //
// if (xAge > pivotBreakoutsLifeTime)
// {
// //
// lastHH = cBar.FindHighest(
// xAge - 1,
// MODE_HIGH //
// );
// //
// lastLL = cBar.FindLowest(
// xAge - 1,
// MODE_LOW //
// );
// //
// DrawPivot(lastLL, clrAqua, "PVB_L_", true);
// DrawPivot(lastHH, clrMagenta, "PVB_H_", true);
// }
//
// Detect Breakouts for Long ...
// - Upper Must Breaked as Resistance ...
// - Lower Must Rejects as Support ...
// //
// bool isSupRejected = cBar.IsSupportRejected(lastLower);
// bool isResBreaked = cBar.IsResistanceBreaked(lastUpper);
// bool isLastLLRejectedAsSupport = cBar.IsSupportRejected(lastDestLL);
// bool isLastHHBreakedAsResistance = cBar.IsResistanceBreaked(lastDestHH);
// //
// bool hasLong =
// //
// cBar.HasStrongBody() &&
// (
// //
// (isLastLLRejectedAsSupport
// //
// ||
// //
// isLastHHBreakedAsResistance)
// //
// ||
// //
// (cBar.GetMid() > MathMax(lastLower, lastUpper) &&
// (isResBreaked
// //
// ||
// //
// isSupRejected))
// //
// )
// //
// ;
// //
// if (hasLong)
// {
// //
// longSLPrice = isResBreaked
// ? lastUpper
// : isLastHHBreakedAsResistance
// ? lastDestHH
// : isSupRejected
// ? lastLower
// : lastDestLL;
// }
//
// Detect Breakouts for Long ...
// - Upper Must Rejects as Resistance ...
// - Lower Must Breaked as Support ...
// //
// bool isResRejected = cBar.IsResistanceRejected(lastUpper);
// bool isSupBreaked = cBar.IsSupportBreaked(lastLower);
// bool isLastLLBreadedAsSupport = cBar.IsSupportBreaked(lastDestLL);
// bool isLastHHRejectedAsResistance = cBar.IsResistanceRejected(lastDestHH);
// //
// bool hasShort =
// //
// cBar.HasStrongBody() &&
// (
// //
// (isLastLLBreadedAsSupport
// //
// ||
// //
// isLastHHRejectedAsResistance)
// //
// ||
// //
// (cBar.GetMid() < MathMin(lastLower, lastUpper) &&
// (isSupBreaked
// //
// ||
// //
// isResRejected))
// //
// )
// //
// ;
// //
// if (hasShort)
// {
// //
// shortSLPrice = isSupBreaked
// ? lastLower
// : isLastLLBreadedAsSupport
// ? lastDestLL
// : isResRejected
// ? lastUpper
// : lastDestHH;
// }
//
//
bool hasLong = false;
bool hasShort = false;
//
bool hasSignal = hasLong || hasShort;
if (hasSignal)
{
//
double slPrice =
hasLong
? longSLPrice
: shortSLPrice;
// double slPrice =
// hasLong
// ? shortSLPrice
// : longSLPrice;
//
ENUM_POSITION_TYPE mType =
hasLong
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL
//
;
// ENUM_POSITION_TYPE mType =
// hasLong
// ? POSITION_TYPE_BUY
// : POSITION_TYPE_SELL
// //
// ;
//
double mEntry = GetEntry(
_Symbol,
mType //
);
//
double priceToRisk = PointToPrice(30, _Symbol);
double priceToReward = PointToPrice(30, _Symbol);
//
double mSL = 0;
double mTP = 0;
CalculateTPSL(
mSL,
mTP,
mType,
mEntry,
1,
slPrice,
0,
priceToRisk,
priceToReward //
);
//
// Ignore Zero TP SL ...
if (mTP > 0 && mSL > 0)
{
//
XSignal signal;
bool isPrepared = signal.Prepare(
_Symbol,
"X92",
_Period,
mType,
X_ORDER_MODE_MARKET,
mEntry,
0.01,
mSL,
mTP //
);
//
if (isPrepared)
{
//
ENUM_X_SIGNAL_EXECUTION_RESULT state;
bool isExecuted = mTrader.ExecuteSignal(
signal,
state //
);
}
}
}
//
bool resetLast =
xAge > pivotLifeTime || hasSignal;
//
if (resetLast)
{
//
lastUpper = 0;
lastLower = 0;
//
RemoveDraws();
}
}
//
void ManxAge()
{
//
return;
double profit = mTrader.Profit();
if (profit > 50 || profit < -100)
{
//
string comment = "EQM Hedge: " + ToString(profit);
//
int numberOfClosed = mTrader.Close(comment);
if (numberOfClosed > 0)
{
mAlert.Alert(comment);
}
}
}
//
bool IsLookingForBoundary()
{
//
bool result = lastUpper == 0 && lastLower == 0;
return result;
}
//
void FindBoundary()
{
//
int zIndex = 0;
int cIndex = 1;
int pIndex = 2;
int ppIndex = 3;
//
// Detect Inside Bar ...
XOHCL cBar;
cBar.Init(
_Symbol,
_Period,
1 //
);
//
XOHCL cDestBar = xDestCycle.GetBar(1);
//
if (cDestBar.time != lastDestTime) {
//
lastDestLL = cDestBar.low;
lastDestHH = cDestBar.high;
//
lastDestTime = cDestBar.time;
//
DrawPivot(lastUpper, clrOrangeRed, "Pvt_");
DrawPivot(lastLower, clrLimeGreen, "Pvt_");
}
//
// if (cDestBar.IsInsideBar())
// {
// //
// lastUpper = cDestBar.high;
// lastLower = cDestBar.low;
// //
// lastTime = TimeCurrent();
// //
// DrawPivot(lastUpper, clrOrangeRed, "Pvt_");
// DrawPivot(lastLower, clrLimeGreen, "Pvt_");
// }
// //
// if (lastUpper != cDestBar.high && lastLower != cDestBar.low)
// {
// //
// lastDestHH = cDestBar.high;
// lastDestLL = cDestBar.low;
// //
// DrawPivot(lastDestLL, clrYellow, "LDST_LL_", true);
// DrawPivot(lastDestHH, clrYellow, "LDST_HH_", true);
// //
// lastDestTime = TimeCurrent();
// }
//
DrawFibo();
}
//
void DrawPivot(
double price,
color clr,
string prefix,
bool forceRemove = false //
)
{
//
long chartID = ChartID();
datetime time1 = iTime(
_Symbol,
_Period,
2 //
);
datetime time = iTime(
_Symbol,
_Period,
0 //
);
//
string pPrefix = prefix + "P_" +
ToString(price);
//
if (IsDrawExists(prefix) && forceRemove)
{
RemoveDraws(prefix);
}
//
if (IsDrawExists(pPrefix))
{
return;
}
//
DrawTrendLine(
chartID,
pPrefix,
0,
time1,
price,
time,
price,
clr,
STYLE_SOLID,
2,
false,
false,
true //
);
}
//
void DrawFibo()
{
//
if (!IsValid(lastDestTime) || lastDestHH == 0 || lastDestLL == 0)
{
return;
}
//
string name = "LDST_FIb";
//
datetime time1 = TimeCurrent();
datetime time0 = lastDestTime;
//
RemoveDraw(name);
//
DrawFibonacci(
ChartID(),
name,
0,
time0,
lastDestHH,
time1,
lastDestLL,
clrAquamarine,
STYLE_DOT //
);
}
//
@@ -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,263 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XZoneTest MQL5 Expert Advisor
// -------------------------------------------------
// Name: XZoneTest
// Description: an Exper Advisor which used RSI and MA
// 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 XZoneTest"
#property strict
//
#include "../Classes/x-saherelm.xczone.class.mq5"
//
#define ShortName "XZoneTest"
//
// Inputs ...
input int zoneRange = 21;
input ENUM_TIMEFRAMES zonePeriod = PERIOD_M1;
//
// Variables ...
int barsTotal;
//
// Initialization ...
int OnInit()
{
//
if (!InitialEA())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
}
//
// On Tick Handler ...
void OnTick()
{
//
int bars = iBars(
_Symbol,
zonePeriod //
);
if (barsTotal == bars)
{
return;
}
//
barsTotal = bars;
//
datetime startTime = iTime(
_Symbol,
zonePeriod,
zoneRange + 1 //
);
datetime endTime = iTime(
_Symbol,
zonePeriod,
1 //
);
//
MqlTick ticks[];
CopyTicksRange(
_Symbol,
ticks,
COPY_TICKS_ALL,
startTime * 1000,
endTime * 1000 //
);
//
double highs[];
CopyHigh(
_Symbol,
zonePeriod,
startTime,
endTime,
highs //
);
double iHigh = highs[ArrayMaximum(highs)];
//
double lows[];
CopyLow(
_Symbol,
zonePeriod,
startTime,
endTime,
lows //
);
double iLow = lows[ArrayMinimum(lows)];
//
double iSize = iHigh - iLow;
//
CArrayObj zones;
int zCount = 10;
for (int i = 0; i < zCount; i++)
{
//
double iH = iHigh - iSize * i / zCount;
double iL = iHigh - iSize * (i + 1) / zCount;
//
XSCZone *iZone = new XSCZone();
iZone.high = iH;
iZone.low = iL;
//
zones.Add(iZone);
}
//
// Fill Ticks ...
for (int i = 0; i < ArraySize(ticks); i++)
{
//
MqlTick iTick = ticks[i];
//
for (int j = 0; j < zones.Total(); j++)
{
//
XSCZone *jZone = zones.At(j);
//
bool isInRange = iTick.bid >= jZone.low && iTick.bid <= jZone.high;
if (isInRange)
{
//
jZone.ticks++;
break;
}
}
}
//
// Sorting Zones ...
zones.Sort();
//
CArrayObj mChartObjects;
for (int i = 0; i < zones.Total(); i++)
{
//
XSCZone *iZone = zones.At(i);
//
string iZoneName = "Zone " + IntegerToString(i);
//
// Create Zone Rectangle ...
CChartObjectRectangle *iRect = new CChartObjectRectangle();
iRect.Create(
0,
iZoneName,
0,
startTime,
iZone.high,
endTime,
iZone.low //
);
iRect.Fill(true);
//
// Create Zone Label ...
CChartObjectLabel *iLabel = new CChartObjectLabel();
iLabel.Create(
0,
iZoneName + "_lbl",
0,
startTime,
iZone.high //
);
iLabel.Color(clrWhite);
//
// Calculate TickPercent ...
double iZoneTickPercent = (double)iZone.ticks / ArraySize(ticks) * 100;
iZoneTickPercent = NormalizeDouble(iZoneTickPercent, 2);
string iZoneTickPercentStr = (string)iZoneTickPercent + "%";
//
iLabel.Description(iZoneTickPercentStr);
//
if (iZone.ticks > ArraySize(ticks) * 0.15)
{
iRect.Color(clrOrangeRed);
}
else if (iZone.ticks > ArraySize(ticks) * 0.10)
{
iRect.Color(clrOrange);
}
else
{
iRect.Color(clrLightGray);
}
//
// mChartObjects.Add(iRect);
// mChartObjects.Add(iLabel);
}
}
//
//
//
bool InitialEA()
{
//
bool result = false;
//
result = true;
//
return result;
}
//