backup and do some cleanup strategies ...
This commit is contained in:
@@ -1,444 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 //
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,823 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,742 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,723 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,446 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 //
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -588,8 +588,8 @@ public:
|
||||
//
|
||||
hasLong =
|
||||
//
|
||||
isBullishTrend &&
|
||||
cBar.IsBullish() &&
|
||||
// isBullishTrend &&
|
||||
// cBar.IsBullish() &&
|
||||
hasBullishPattern &&
|
||||
hkConditions.isSMHKBullish &&
|
||||
chmaConditions.isFastOverSlow
|
||||
@@ -641,8 +641,8 @@ public:
|
||||
//
|
||||
hasShort =
|
||||
//
|
||||
isBearishTrend &&
|
||||
cBar.IsBearish() &&
|
||||
// isBearishTrend &&
|
||||
// cBar.IsBearish() &&
|
||||
hasBearishPattern &&
|
||||
hkConditions.isSMHKBearish &&
|
||||
chmaConditions.isFastUnderSlow
|
||||
|
||||
Reference in New Issue
Block a user