transfer important area and its related methods and Properties to XStrategy class ...
This commit is contained in:
@@ -28,15 +28,6 @@
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_X_SIGNALLING_DIRECTION
|
||||
{
|
||||
X_SIGNALLING_NONE = 0,
|
||||
X_SIGNALLING_BOTH_DIRECTIONS = 1,
|
||||
X_SIGNALLING_TREND_DIRECTION = 2,
|
||||
X_SIGNALIING_TREND_REVERSAL_DIRECTION = 3
|
||||
};
|
||||
|
||||
//
|
||||
class XSCBaseStrategy : public XSCBaseAlert
|
||||
{
|
||||
@@ -48,6 +39,7 @@ public:
|
||||
void XSCBaseStrategy(
|
||||
string _symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES _period, // Trading TimeFrame
|
||||
ENUM_TIMEFRAMES _analizePeriod, // Important Area Detect Time Frame
|
||||
double _volume, // Voluem
|
||||
double _r2r, // Risk/Reward Ratio
|
||||
int _slippage, // Trader Slippage
|
||||
@@ -79,6 +71,7 @@ public:
|
||||
mAllowLong = _allowLong;
|
||||
mAllowShort = _allowShort;
|
||||
mMagicNumber = _magicNumber;
|
||||
mAnalizePeriod = _analizePeriod;
|
||||
mUseTPSLAsPoint = _useTPSLAsPoint;
|
||||
mMaxAllowedLongs = _maxAllowedLongs;
|
||||
mMaxAllowedShorts = _maxAllowedShorts;
|
||||
@@ -396,6 +389,30 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES AnalizePeriod()
|
||||
{
|
||||
return mAnalizePeriod;
|
||||
}
|
||||
|
||||
//
|
||||
void AnalizePeriod(ENUM_TIMEFRAMES value)
|
||||
{
|
||||
mAnalizePeriod = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool DrawImportantAreas()
|
||||
{
|
||||
return mDrawImportantAreas;
|
||||
}
|
||||
|
||||
//
|
||||
void DrawImportantAreas(bool value)
|
||||
{
|
||||
mDrawImportantAreas = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Virtual Methods ...
|
||||
|
||||
@@ -749,6 +766,672 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mAnalizePeriod; // Important Area Detect Time Frame
|
||||
bool mDrawImportantAreas; // Draw Important Areas where Founded in Analyzing Time Frame
|
||||
|
||||
//
|
||||
XOHCL support;
|
||||
XOHCL resistance;
|
||||
XOHCL bullishOB;
|
||||
XOHCL bearishOB;
|
||||
|
||||
//
|
||||
double bullishFVGUpper;
|
||||
double bullishFVGLower;
|
||||
XOHCL bullishFVG;
|
||||
|
||||
//
|
||||
double bearishFVGUpper;
|
||||
double bearishFVGLower;
|
||||
XOHCL bearishFVG;
|
||||
|
||||
//
|
||||
XOHCL bullishTrendSwingHighs[];
|
||||
XOHCL bullishTrendSwingLows[];
|
||||
XOHCL bullishTrend;
|
||||
|
||||
//
|
||||
XOHCL bearishTrendSwingHighs[];
|
||||
XOHCL bearishTrendSwingLows[];
|
||||
XOHCL bearishTrend;
|
||||
|
||||
//
|
||||
void DetectImportantAreas()
|
||||
{
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
|
||||
//
|
||||
// Last Bar ...
|
||||
XOHCL cBar;
|
||||
bool result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyzing Bar ...
|
||||
XOHCL aBar;
|
||||
if (IsValid(mAnalizePeriod))
|
||||
{
|
||||
//
|
||||
result = aBar.Init(
|
||||
mSymbol,
|
||||
mAnalizePeriod,
|
||||
cIndex //
|
||||
);
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aBar = cBar;
|
||||
}
|
||||
|
||||
//
|
||||
// Support nad Resistance ...
|
||||
|
||||
//
|
||||
// Check Support Exists or Find ...
|
||||
bool hasSupport = support.IsValid();
|
||||
if (!hasSupport)
|
||||
{
|
||||
//
|
||||
hasSupport =
|
||||
//
|
||||
aBar.HasSupport(support)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (hasSupport)
|
||||
{
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawSupport(
|
||||
support,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
supportTime = aBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Resistance Exists or Find ...
|
||||
bool hasResistance = resistance.IsValid();
|
||||
if (!hasResistance)
|
||||
{
|
||||
//
|
||||
hasResistance =
|
||||
//
|
||||
aBar.HasResistance(resistance)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (hasResistance)
|
||||
{
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawResistance(
|
||||
resistance,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
resistanceTime = aBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Order Blocks ...
|
||||
|
||||
//
|
||||
bool hasBullishOB = bullishOB.IsValid();
|
||||
if (!hasBullishOB)
|
||||
{
|
||||
//
|
||||
hasBullishOB =
|
||||
//
|
||||
aBar.HasBullishOrderBlock(bullishOB)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (hasBullishOB)
|
||||
{
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawBullishOrderBlock(
|
||||
bullishOB,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bullishOBTime = aBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBearishOB = bearishOB.IsValid();
|
||||
if (!hasBearishOB)
|
||||
{
|
||||
//
|
||||
hasBearishOB =
|
||||
//
|
||||
aBar.HasBearishOrderBlock(bearishOB)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (hasBearishOB)
|
||||
{
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawBearishOrderBlock(
|
||||
bearishOB,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bearishOBTime = aBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// FVG ...
|
||||
|
||||
//
|
||||
bool hasBullishFVG = bullishFVG.IsValid();
|
||||
if (!hasBullishFVG)
|
||||
{
|
||||
//
|
||||
hasBullishFVG =
|
||||
//
|
||||
aBar.HasBullishFVG(
|
||||
bullishFVGUpper,
|
||||
bullishFVGLower //
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (hasBullishFVG)
|
||||
{
|
||||
//
|
||||
bullishFVG = aBar;
|
||||
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawBullishFVG(
|
||||
bullishFVG,
|
||||
bullishFVGUpper,
|
||||
bullishFVGLower,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bullishFVGTime = aBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBearishFVG = bearishFVG.IsValid();
|
||||
if (!hasBearishFVG)
|
||||
{
|
||||
//
|
||||
hasBearishFVG =
|
||||
//
|
||||
aBar.HasBearishFVG(
|
||||
bearishFVGUpper,
|
||||
bearishFVGLower //
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (hasBearishFVG)
|
||||
{
|
||||
//
|
||||
bearishFVG = aBar;
|
||||
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawBearishFVG(
|
||||
bearishFVG,
|
||||
bearishFVGUpper,
|
||||
bearishFVGLower,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bearishFVGTime = aBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
|
||||
//
|
||||
bool hasBullishTrend = bullishTrend.IsValid();
|
||||
if (!hasBullishTrend)
|
||||
{
|
||||
//
|
||||
hasBullishTrend = aBar.HasBullishTrend(
|
||||
bullishTrendSwingHighs,
|
||||
bullishTrendSwingLows,
|
||||
false //
|
||||
);
|
||||
|
||||
//
|
||||
if (hasBullishTrend)
|
||||
{
|
||||
//
|
||||
bullishTrend = aBar;
|
||||
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawBullishTrend(
|
||||
bullishTrend,
|
||||
bullishTrendSwingHighs,
|
||||
bullishTrendSwingLows,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBearishTrend = bearishTrend.IsValid();
|
||||
if (!hasBearishTrend)
|
||||
{
|
||||
//
|
||||
hasBearishTrend = aBar.HasBearishTrend(
|
||||
bearishTrendSwingHighs,
|
||||
bearishTrendSwingLows,
|
||||
false //
|
||||
);
|
||||
|
||||
//
|
||||
if (hasBearishTrend)
|
||||
{
|
||||
//
|
||||
bearishTrend = aBar;
|
||||
|
||||
//
|
||||
if (mDrawImportantAreas)
|
||||
{
|
||||
//
|
||||
DrawBearishTrend(
|
||||
bearishTrend,
|
||||
bearishTrendSwingHighs,
|
||||
bearishTrendSwingLows,
|
||||
ChartID() //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
void DestroyImportantAreas()
|
||||
{
|
||||
//
|
||||
bool hasSupport = support.IsValid();
|
||||
if (hasSupport)
|
||||
{
|
||||
//
|
||||
supportTime = NULL;
|
||||
isSupportTested = false;
|
||||
RemoveSupport(support);
|
||||
support.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool hasResistance = resistance.IsValid();
|
||||
if (hasResistance)
|
||||
{
|
||||
//
|
||||
resistanceTime = NULL;
|
||||
isResistanceTested = false;
|
||||
RemoveResistance(resistance);
|
||||
resistance.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBullishOB = bullishOB.IsValid();
|
||||
if (hasBullishOB)
|
||||
{
|
||||
//
|
||||
bullishOBTime = NULL;
|
||||
RemoveBullishOrderBlock(bullishOB);
|
||||
bullishOB.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBearishOB = bearishOB.IsValid();
|
||||
if (hasBearishOB)
|
||||
{
|
||||
//
|
||||
bearishOBTime = NULL;
|
||||
RemoveBearishOrderBlock(bearishOB);
|
||||
bearishOB.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBullishFVG = bullishFVG.IsValid();
|
||||
if (hasBullishFVG)
|
||||
{
|
||||
//
|
||||
bullishFVGUpper = 0;
|
||||
bullishFVGLower = 0;
|
||||
bullishFVGTime = NULL;
|
||||
RemoveBullishFVG(bullishFVG);
|
||||
bullishFVG.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBearishFVG = bearishFVG.IsValid();
|
||||
if (hasBearishFVG)
|
||||
{
|
||||
//
|
||||
bearishFVGUpper = 0;
|
||||
bearishFVGLower = 0;
|
||||
bearishFVGTime = NULL;
|
||||
RemoveBullishFVG(bearishFVG);
|
||||
bearishFVG.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBullishTrend = bullishTrend.IsValid();
|
||||
if (hasBullishTrend)
|
||||
{
|
||||
//
|
||||
RemoveBullishTrend(bullishTrend);
|
||||
bullishTrend.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBearishTrend = bearishTrend.IsValid();
|
||||
if (hasBearishTrend)
|
||||
{
|
||||
//
|
||||
RemoveBearishTrend(bearishTrend);
|
||||
bearishTrend.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void CheckImportantAreasValidation()
|
||||
{
|
||||
//
|
||||
CheckSupportValidation();
|
||||
CheckResistanceValidation();
|
||||
|
||||
//
|
||||
CheckBullishOBValidation();
|
||||
CheckBearishOBValidation();
|
||||
|
||||
//
|
||||
CheckBullishFVGValidation();
|
||||
CheckBearishFVgValidation();
|
||||
|
||||
//
|
||||
CheckBullishTrendValidation();
|
||||
CheckBearishTrendValidation();
|
||||
}
|
||||
|
||||
//
|
||||
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();
|
||||
}
|
||||
|
||||
//
|
||||
datetime bullishOBTime;
|
||||
void CheckBullishOBValidation()
|
||||
{
|
||||
//
|
||||
if (!IsValid(bullishOBTime))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishOBTime))) / PeriodSeconds(mPeriod));
|
||||
if (age >= 50)
|
||||
{
|
||||
//
|
||||
bullishOBTime = NULL;
|
||||
RemoveBullishOrderBlock(bullishOB);
|
||||
bullishOB.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime bearishOBTime;
|
||||
void CheckBearishOBValidation()
|
||||
{
|
||||
//
|
||||
if (!IsValid(bearishOBTime))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishOBTime))) / PeriodSeconds(mPeriod));
|
||||
if (age >= 50)
|
||||
{
|
||||
//
|
||||
bearishOBTime = NULL;
|
||||
RemoveBearishOrderBlock(bearishOB);
|
||||
bearishOB.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime bullishFVGTime;
|
||||
void CheckBullishFVGValidation()
|
||||
{
|
||||
//
|
||||
if (!IsValid(bullishFVGTime))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishFVGTime))) / PeriodSeconds(mPeriod));
|
||||
if (age >= 50)
|
||||
{
|
||||
//
|
||||
bullishFVGTime = NULL;
|
||||
RemoveBullishFVG(bullishFVG);
|
||||
bullishFVG.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime bearishFVGTime;
|
||||
void CheckBearishFVgValidation()
|
||||
{
|
||||
//
|
||||
if (!IsValid(bearishFVGTime))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishFVGTime))) / PeriodSeconds(mPeriod));
|
||||
if (age >= 50)
|
||||
{
|
||||
//
|
||||
bearishFVGTime = NULL;
|
||||
RemoveBearishFVG(bearishFVG);
|
||||
bearishFVG.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void CheckBullishTrendValidation()
|
||||
{
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
}
|
||||
|
||||
//
|
||||
void CheckBearishTrendValidation()
|
||||
{
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user