last ...
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "../Helpers/x-saherelm.x121.xche.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xdon.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xhk.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xmas.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xpv.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xstr.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xtrend.helper.mq5"
|
||||
@@ -43,6 +44,7 @@ struct X121Inputs
|
||||
X121XCCInputs xccInputs;
|
||||
X121XPVInputs xpvInputs;
|
||||
X121XHKInputs xhkInputs;
|
||||
X121XMASInputs xmasInputs;
|
||||
X121XATRInputs xatrInputs;
|
||||
X121XSTRInputs xstrInputs;
|
||||
X121XCHEInputs xcheInputs;
|
||||
@@ -70,6 +72,7 @@ struct X121Inputs
|
||||
xccInputs.Clean();
|
||||
xpvInputs.Clean();
|
||||
xhkInputs.Clean();
|
||||
xmasInputs.Clean();
|
||||
xatrInputs.Clean();
|
||||
xstrInputs.Clean();
|
||||
xcheInputs.Clean();
|
||||
@@ -90,6 +93,7 @@ struct X121Inputs
|
||||
xccInputs.Default();
|
||||
xpvInputs.Default();
|
||||
xhkInputs.Default();
|
||||
xmasInputs.Default();
|
||||
xatrInputs.Default();
|
||||
xstrInputs.Default();
|
||||
xcheInputs.Default();
|
||||
@@ -115,6 +119,7 @@ struct X121Inputs
|
||||
xccInputs.IsValid() &&
|
||||
xpvInputs.IsValid() &&
|
||||
xhkInputs.IsValid() &&
|
||||
xmasInputs.IsValid() &&
|
||||
xatrInputs.IsValid() &&
|
||||
xstrInputs.IsValid() &&
|
||||
xcheInputs.IsValid() &&
|
||||
@@ -141,6 +146,7 @@ struct X121Inputs
|
||||
//
|
||||
int xpvMax = xpvInputs.Max();
|
||||
int xhkMax = xpvInputs.Max();
|
||||
int xmasMax = xpvInputs.Max();
|
||||
int xatrMax = xatrInputs.Max();
|
||||
int xstrMax = xstrInputs.Max();
|
||||
int xcheMax = xcheInputs.Max();
|
||||
@@ -150,6 +156,7 @@ struct X121Inputs
|
||||
|
||||
//
|
||||
result = MathMax(xpvMax, xhkMax);
|
||||
result = MathMax(result, xmasMax);
|
||||
result = MathMax(result, xatrMax);
|
||||
result = MathMax(result, xstrMax);
|
||||
result = MathMax(result, xcheMax);
|
||||
@@ -202,6 +209,9 @@ struct X121Conditions
|
||||
double valesBuffer[];
|
||||
double strUpBuffer[];
|
||||
double downTBuffer[];
|
||||
double masMidBuffer[];
|
||||
double masUpperBuffer[];
|
||||
double masLowerBuffer[];
|
||||
double strDownBuffer[];
|
||||
double vwapMidBuffer[];
|
||||
double upTrendBuffer[];
|
||||
@@ -635,10 +645,13 @@ struct X121Conditions
|
||||
Clean(strUpBuffer);
|
||||
Clean(downTBuffer);
|
||||
Clean(volumeBuffer);
|
||||
Clean(masMidBuffer);
|
||||
Clean(strDownBuffer);
|
||||
Clean(vwapMidBuffer);
|
||||
Clean(upTrendBuffer);
|
||||
Clean(x3maMidBuffer);
|
||||
Clean(masUpperBuffer);
|
||||
Clean(masLowerBuffer);
|
||||
Clean(le1StartBuffer);
|
||||
Clean(se1StartBuffer);
|
||||
Clean(le2StartBuffer);
|
||||
@@ -710,10 +723,13 @@ struct X121Conditions
|
||||
ArraySetAsSeries(strUpBuffer, true);
|
||||
ArraySetAsSeries(downTBuffer, true);
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
ArraySetAsSeries(masMidBuffer, true);
|
||||
ArraySetAsSeries(strDownBuffer, true);
|
||||
ArraySetAsSeries(vwapMidBuffer, true);
|
||||
ArraySetAsSeries(upTrendBuffer, true);
|
||||
ArraySetAsSeries(x3maMidBuffer, true);
|
||||
ArraySetAsSeries(masUpperBuffer, true);
|
||||
ArraySetAsSeries(masLowerBuffer, true);
|
||||
ArraySetAsSeries(le1StartBuffer, true);
|
||||
ArraySetAsSeries(se1StartBuffer, true);
|
||||
ArraySetAsSeries(le2StartBuffer, true);
|
||||
@@ -2397,6 +2413,7 @@ class XCX121Helper : public XCBase
|
||||
XCX121XCCHelper *xccHelper;
|
||||
XCX121XPVHelper *xpvHelper;
|
||||
XCX121XHKHelper *xhkHelper;
|
||||
XCX121XMASHelper *xmasHelper;
|
||||
XCX121XATRHelper *xatrHelper;
|
||||
XCX121XSTRHelper *xstrHelper;
|
||||
XCX121XCHEHelper *xcheHelper;
|
||||
@@ -2420,6 +2437,7 @@ class XCX121Helper : public XCBase
|
||||
xccInputs.Clean();
|
||||
xpvInputs.Clean();
|
||||
xhkInputs.Clean();
|
||||
xmasInputs.Clean();
|
||||
xatrInputs.Clean();
|
||||
xdonInputs.Clean();
|
||||
xstrInputs.Clean();
|
||||
@@ -2432,6 +2450,7 @@ class XCX121Helper : public XCBase
|
||||
delete xccHelper;
|
||||
delete xpvHelper;
|
||||
delete xhkHelper;
|
||||
delete xmasHelper;
|
||||
delete xatrHelper;
|
||||
delete xstrHelper;
|
||||
delete xcheHelper;
|
||||
@@ -2444,6 +2463,7 @@ class XCX121Helper : public XCBase
|
||||
ZeroMemory(xccHelper);
|
||||
ZeroMemory(xpvHelper);
|
||||
ZeroMemory(xhkHelper);
|
||||
ZeroMemory(xmasHelper);
|
||||
ZeroMemory(xatrHelper);
|
||||
ZeroMemory(xstrHelper);
|
||||
ZeroMemory(xcheHelper);
|
||||
@@ -2508,6 +2528,7 @@ class XCX121Helper : public XCBase
|
||||
xccInputs = inputs.xccInputs;
|
||||
xpvInputs = inputs.xpvInputs;
|
||||
xhkInputs = inputs.xhkInputs;
|
||||
xmasInputs = inputs.xmasInputs;
|
||||
xatrInputs = inputs.xatrInputs;
|
||||
xstrInputs = inputs.xstrInputs;
|
||||
xcheInputs = inputs.xcheInputs;
|
||||
@@ -2558,6 +2579,19 @@ class XCX121Helper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
xmasHelper = new XCX121XMASHelper();
|
||||
result = xmasHelper.Init(
|
||||
symbol,
|
||||
period,
|
||||
xmasInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
xatrHelper = new XCX121XATRHelper();
|
||||
@@ -2719,6 +2753,28 @@ class XCX121Helper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
bool GetMASConditions(
|
||||
X121XMASConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xmasHelper.GetConditions(
|
||||
conditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
bool GetATRConditions(
|
||||
@@ -2879,6 +2935,7 @@ class XCX121Helper : public XCBase
|
||||
//
|
||||
xpvHelper.Free();
|
||||
xhkHelper.Free();
|
||||
xmasHelper.Free();
|
||||
xatrHelper.Free();
|
||||
xstrHelper.Free();
|
||||
xcheHelper.Free();
|
||||
@@ -2979,6 +3036,19 @@ class XCX121Helper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
X121XMASConditions xmasConditions;
|
||||
result = GetMASConditions(
|
||||
xmasConditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
X121XATRConditions xatrConditions;
|
||||
@@ -3293,6 +3363,30 @@ class XCX121Helper : public XCBase
|
||||
conditions.isSMHKSwitchedToBullish = xhkConditions.isSMHKSwitchedToBullish;
|
||||
conditions.isRawHKSwitchedToBullish = xhkConditions.isRawHKSwitchedToBullish;
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
Copy(
|
||||
xmasConditions.upperBuffer,
|
||||
conditions.masUpperBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
Copy(
|
||||
xmasConditions.midBuffer,
|
||||
conditions.masMidBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
Copy(
|
||||
xmasConditions.lowerBuffer,
|
||||
conditions.masLowerBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// XTREND ...
|
||||
|
||||
@@ -4458,6 +4552,7 @@ class XCX121Helper : public XCBase
|
||||
//
|
||||
xpvConditions.Clean();
|
||||
xhkConditions.Clean();
|
||||
xmasConditions.Clean();
|
||||
xatrConditions.Clean();
|
||||
xstrConditions.Clean();
|
||||
xcheConditions.Clean();
|
||||
@@ -4491,6 +4586,7 @@ class XCX121Helper : public XCBase
|
||||
X121XCCInputs xccInputs;
|
||||
X121XPVInputs xpvInputs;
|
||||
X121XHKInputs xhkInputs;
|
||||
X121XMASInputs xmasInputs;
|
||||
X121XATRInputs xatrInputs;
|
||||
X121XDONInputs xdonInputs;
|
||||
X121XSTRInputs xstrInputs;
|
||||
|
||||
@@ -0,0 +1,788 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XCX121XMASHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper 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.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
enum ENUM_X121_XMAS_BUFFERS
|
||||
{
|
||||
//
|
||||
X121_XMAS_UPPER_LINE = 0,
|
||||
X121_XMAS_MID_LINE = 1,
|
||||
X121_XMAS_LOWER_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X121XMASInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
int length; // MA Length
|
||||
ENUM_MA_METHOD method; // MA Method
|
||||
ENUM_APPLIED_PRICE upperAppliedTo; // Upper Applied To
|
||||
ENUM_APPLIED_PRICE midAppliedTo; // Mid Applied To
|
||||
ENUM_APPLIED_PRICE lowerAppliedTo; // Lower Applied To
|
||||
|
||||
//
|
||||
int startCalculationForLastBars; // Calculate Last n Bars
|
||||
bool showUpper; // Show Upper
|
||||
bool showMid; // Show Mid
|
||||
bool showLower; // Show Lower
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X121XMASInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0; // MA Length
|
||||
method = MODE_EMA; // MA Method
|
||||
upperAppliedTo = PRICE_HIGH; // Upper Applied To
|
||||
midAppliedTo = PRICE_MEDIAN; // Mid Applied To
|
||||
lowerAppliedTo = PRICE_LOW; // Lower Applied To
|
||||
|
||||
//
|
||||
startCalculationForLastBars = 0; // Calculate Last n Bars
|
||||
showUpper = false; // Show Upper
|
||||
showMid = false; // Show Mid
|
||||
showLower = false; // Show Lower
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 14; // MA Length
|
||||
method = MODE_EMA; // MA Method
|
||||
upperAppliedTo = PRICE_HIGH; // Upper Applied To
|
||||
midAppliedTo = PRICE_MEDIAN; // Mid Applied To
|
||||
lowerAppliedTo = PRICE_LOW; // Lower Applied To
|
||||
|
||||
//
|
||||
startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
showUpper = true; // Show Upper
|
||||
showMid = true; // Show Mid
|
||||
showLower = true; // Show Lower
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
struct X121XMASConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double upperBuffer[];
|
||||
double midBuffer[];
|
||||
double lowerBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121XMASConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Commons ...
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
Clean(upperBuffer);
|
||||
Clean(midBuffer);
|
||||
Clean(lowerBuffer);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upperBuffer, true);
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(lowerBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Conditions Scores ...
|
||||
*
|
||||
* @param bullishScore: Double, Directional Scores Reference ...
|
||||
* @param bearishScore: Double, Directional Scores Reference ...
|
||||
*/
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
// TODO: Implement if Required ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Summary String for Represent Conditions State ...
|
||||
*
|
||||
* @param onlyCommons: Boolean, Just Generate Only Commons Conditions ...
|
||||
* @param onlyConditions: Boolean, Just Generate Only Conditions ...
|
||||
* @param includeScores: Boolean, Attach Scores Representations on Result ...
|
||||
* @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ...
|
||||
* @param separator: String, Separate Lines ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
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 =
|
||||
//
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve nique Tag Identifier ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
return GetTypeName(this);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XCX121XMASHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XMASHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XMASHelper()
|
||||
{
|
||||
//
|
||||
mInputs.Clean();
|
||||
|
||||
//
|
||||
Clean(upperBuffer);
|
||||
Clean(midBuffer);
|
||||
Clean(lowerBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XMASInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upperBuffer, true);
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(lowerBuffer, true);
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xmas",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length,
|
||||
mInputs.method,
|
||||
mInputs.upperAppliedTo,
|
||||
mInputs.midAppliedTo,
|
||||
mInputs.lowerAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
mInputs.startCalculationForLastBars,
|
||||
//
|
||||
mInputs.showUpper,
|
||||
mInputs.showMid,
|
||||
mInputs.showLower
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XMASInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XMASInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Readers ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
double GetUpper(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(upperBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return upperBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyUpper(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
upperBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
|
||||
//
|
||||
double GetUMid(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(midBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return midBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyMid(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
midBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
double GetULower(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(lowerBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return lowerBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyLower(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
lowerBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
X121XMASConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 5)
|
||||
{
|
||||
loopback = 5;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyUpper(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.upperBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
CopyMid(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.midBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
CopyLower(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.lowerBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
int cIDX = 1;
|
||||
int pIDX = cIDX + 1;
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
|
||||
//
|
||||
Cleanup();
|
||||
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XMASInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double upperBuffer[];
|
||||
double midBuffer[];
|
||||
double lowerBuffer[];
|
||||
|
||||
//
|
||||
void Calculate(
|
||||
int maxRequiredBars = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XMAS_UPPER_LINE,
|
||||
0,
|
||||
maxRequiredBars,
|
||||
upperBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// FAST STATE ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XMAS_MID_LINE,
|
||||
0,
|
||||
maxRequiredBars,
|
||||
midBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// MID ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XMAS_LOWER_LINE,
|
||||
0,
|
||||
maxRequiredBars,
|
||||
lowerBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void Cleanup(
|
||||
int maxAllowed = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
CleanupArray(
|
||||
upperBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
midBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
lowerBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,574 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XMAS
|
||||
// Description: XMAS ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XMAS Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XMAS"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int length = 14; // MA Length
|
||||
input ENUM_MA_METHOD method = MODE_EMA; // MA Method
|
||||
input ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH; // Upper Applied To
|
||||
input ENUM_APPLIED_PRICE midAppliedTo = PRICE_MEDIAN; // Mid Applied To
|
||||
input ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW; // Lower Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showUpper = true; // Show Upper
|
||||
input bool showMid = true; // Show Mid
|
||||
input bool showLower = true; // Show Lower
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
#define upperBufferIndex 0
|
||||
double upperBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121 MASU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// MID ...
|
||||
#define midBufferIndex 1
|
||||
double midBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121 MASM"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrLightBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
#define lowerBufferIndex 2
|
||||
double lowerBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121 MASL"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMagenta
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 2;
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int upperHandler = INVALID_HANDLE;
|
||||
int midHandler = INVALID_HANDLE;
|
||||
int lowerHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
upperHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
upperAppliedTo //
|
||||
);
|
||||
bool isInited = upperHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
midHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
midAppliedTo //
|
||||
);
|
||||
isInited = midHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
lowerHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
lowerAppliedTo //
|
||||
);
|
||||
isInited = lowerHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
|
||||
//
|
||||
IndicatorRelease(upperHandler);
|
||||
IndicatorRelease(midHandler);
|
||||
IndicatorRelease(lowerHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
int upperCalculatedBars = BarsCalculated(upperHandler);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
int midCalculatedBars = BarsCalculated(midHandler);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
int lowerCalculatedBars = BarsCalculated(lowerHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// Upper ...
|
||||
upperCalculatedBars >= maxLength &&
|
||||
//
|
||||
// Mid ...
|
||||
midCalculatedBars >= maxLength &&
|
||||
//
|
||||
// Lower ...
|
||||
lowerCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
int copiedUppers = CopyBuffer(upperHandler, 0, 0, limit, upperBuffer);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
int copiedLowers = CopyBuffer(lowerHandler, 0, 0, limit, lowerBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// Upper ...
|
||||
copiedUppers > 0 &&
|
||||
//
|
||||
// Mid ...
|
||||
copiedMids > 0 &&
|
||||
//
|
||||
// Lower ...
|
||||
copiedLowers > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = length > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE upperDrawType = showUpper ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upperBuffer, true);
|
||||
SetIndexBuffer(upperBufferIndex, upperBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(upperBufferIndex, PLOT_SHOW_DATA, showUpper);
|
||||
PlotIndexSetInteger(upperBufferIndex, PLOT_DRAW_TYPE, upperDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(upperBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE midDrawType = showMid ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, showMid);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE lowerDrawType = showLower ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(lowerBuffer, true);
|
||||
SetIndexBuffer(lowerBufferIndex, lowerBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lowerBufferIndex, PLOT_SHOW_DATA, showLower);
|
||||
PlotIndexSetInteger(lowerBufferIndex, PLOT_DRAW_TYPE, lowerDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(lowerBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
upperBuffer[barIndex] = 0;
|
||||
midBuffer[barIndex] = 0;
|
||||
lowerBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Implement Colorify Mechanism ...
|
||||
}
|
||||
|
||||
//
|
||||
@@ -2607,7 +2607,14 @@ struct X121SMCStrategyConditionParser
|
||||
//
|
||||
// Validate CBar ...
|
||||
cBar.IsBullish() &&
|
||||
cBar.open >= cSMHKBar.open &&
|
||||
//
|
||||
(cBar.low >= cXConditions.valesGoldenBuffer[cIDX] ||
|
||||
(cBar.low < cXConditions.valesGoldenBuffer[cIDX] &&
|
||||
cXConditions.isSarSwitchedToBullish)) &&
|
||||
//
|
||||
(cBar.open == cXConditions.xhkSMOpenBuffer[cIDX] ||
|
||||
(cBar.low < cXConditions.xhkSMLowBuffer[cIDX] &&
|
||||
cBar.GetDown() > cXConditions.xhkSMHighBuffer[cIDX])) &&
|
||||
//
|
||||
cXConditions.isSarBullish
|
||||
//
|
||||
@@ -2625,7 +2632,14 @@ struct X121SMCStrategyConditionParser
|
||||
//
|
||||
// Validate CBar ...
|
||||
cBar.IsBearish() &&
|
||||
cBar.open <= cSMHKBar.open &&
|
||||
//
|
||||
(cBar.high <= cXConditions.peaksGoldenBuffer[cIDX] ||
|
||||
(cBar.high > cXConditions.peaksGoldenBuffer[cIDX] &&
|
||||
cXConditions.isSarSwitchedToBearish)) &&
|
||||
//
|
||||
(cBar.open == cXConditions.xhkSMOpenBuffer[cIDX] ||
|
||||
(cBar.high > cXConditions.xhkSMHighBuffer[cIDX] &&
|
||||
cBar.GetUp() < cXConditions.xhkSMLowBuffer[cIDX])) &&
|
||||
//
|
||||
cXConditions.isSarBearish
|
||||
//
|
||||
@@ -2920,88 +2934,91 @@ struct X121SMCStrategyConditionParser
|
||||
double points = GetPoints(box.symbol);
|
||||
double minPointsDiff = points * 20;
|
||||
|
||||
// //
|
||||
// double prefferSL = 0;
|
||||
//
|
||||
double prefferSL = 0;
|
||||
|
||||
// //
|
||||
// // First Check Based on Prev Bar ...
|
||||
// // double prevDiff =
|
||||
// // isBullish
|
||||
// // ? cBar.low < zBar.open
|
||||
// // ? zBar.open - cBar.low
|
||||
// // : 0
|
||||
// // : isBearish
|
||||
// // ? cBar.high > zBar.open
|
||||
// // ? cBar.high - zBar.open
|
||||
// // : 0
|
||||
// // : 0;
|
||||
// // if (prevDiff >= minPointsDiff)
|
||||
// // {
|
||||
// // //
|
||||
// // prefferSL =
|
||||
// // isBullish
|
||||
// // ? cBar.low
|
||||
// // : cBar.high;
|
||||
// // }
|
||||
//
|
||||
// Other SL Conditions ...
|
||||
if (prefferSL <= 0)
|
||||
{
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
if (zBar.open < cXConditions.valesGoldenBuffer[cIDX])
|
||||
{
|
||||
prefferSL = cXConditions.valesBuffer[cIDX];
|
||||
}
|
||||
else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX] &&
|
||||
zBar.open < cXConditions.peaksGoldenBuffer[cIDX])
|
||||
{
|
||||
prefferSL = cXConditions.valesGoldenBuffer[cIDX];
|
||||
}
|
||||
else if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX])
|
||||
{
|
||||
//
|
||||
if (cXConditions.sarBuffer[cIDX] > cXConditions.peaksGoldenBuffer[cIDX])
|
||||
{
|
||||
prefferSL = cXConditions.sarBuffer[cIDX];
|
||||
}
|
||||
else
|
||||
{
|
||||
prefferSL = zBar.open > cXConditions.peaksGoldenBuffer[cIDX];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX])
|
||||
{
|
||||
prefferSL = cXConditions.peaksBuffer[cIDX];
|
||||
}
|
||||
else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX] &&
|
||||
zBar.open > cXConditions.valesGoldenBuffer[cIDX])
|
||||
{
|
||||
prefferSL = cXConditions.peaksGoldenBuffer[cIDX];
|
||||
}
|
||||
else if (zBar.open < cXConditions.valesGoldenBuffer[cIDX])
|
||||
{
|
||||
//
|
||||
if (cXConditions.sarBuffer[cIDX] < cXConditions.valesGoldenBuffer[cIDX])
|
||||
{
|
||||
prefferSL = cXConditions.sarBuffer[cIDX];
|
||||
}
|
||||
else
|
||||
{
|
||||
prefferSL = cXConditions.valesGoldenBuffer[cIDX];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// //
|
||||
// // Other SL Conditions ...
|
||||
// if (prefferSL <= 0)
|
||||
// {
|
||||
// //
|
||||
// if (isBullish)
|
||||
// {
|
||||
// //
|
||||
// if (zBar.open < cXConditions.valesGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.valesBuffer[cIDX];
|
||||
// }
|
||||
// else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.valesGoldenBuffer[cIDX];
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //
|
||||
// if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.peaksBuffer[cIDX];
|
||||
// }
|
||||
// else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.peaksGoldenBuffer[cIDX];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
if (prefferSL > 0)
|
||||
{
|
||||
//
|
||||
box.upper =
|
||||
isBullish
|
||||
? zBar.open
|
||||
: prefferSL;
|
||||
|
||||
// //
|
||||
// if (prefferSL > 0)
|
||||
// {
|
||||
// //
|
||||
// prefferSL =
|
||||
// prefferSL <= minPointsDiff
|
||||
// ? minPointsDiff
|
||||
// : prefferSL;
|
||||
|
||||
// //
|
||||
// box.upper =
|
||||
// isBullish
|
||||
// ? zBar.open
|
||||
// : prefferSL;
|
||||
|
||||
// //
|
||||
// box.lower =
|
||||
// isBullish
|
||||
// ? prefferSL
|
||||
// : zBar.open;
|
||||
// }
|
||||
//
|
||||
box.lower =
|
||||
isBullish
|
||||
? prefferSL
|
||||
: zBar.open;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Conditions to Force Has Holder Box ...
|
||||
|
||||
result =
|
||||
result &&
|
||||
holderBox.IsValid();
|
||||
holderBox.IsValid() &&
|
||||
dir == holderBox.dir;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
@@ -3036,6 +3053,368 @@ struct X121SMCStrategyConditionParser
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool HasSenario2Conditions(
|
||||
ENUM_X_CYCLES ttfCycle,
|
||||
XBoxZone &breakedBoxes[],
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0,
|
||||
bool forceBarType = false,
|
||||
bool forceFiboPressure = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
IsValid(ttfCycle) &&
|
||||
HasChild(breakedBoxes);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Add support for Extracting Trend ...
|
||||
ENUM_X_DIRECTION trend = X_DIRECTION_NONE;
|
||||
bool hasBullishTrend = IsBullish(trend);
|
||||
bool hasBearishTrend = IsBearish(trend);
|
||||
|
||||
//
|
||||
// TTF Cycle Extract ...
|
||||
XPOIState ttfState;
|
||||
X121Conditions ttfXConditions;
|
||||
XC121SMCCycleHelper *ttfHelper;
|
||||
X121SMCCycleConditions ttfConditions;
|
||||
result = provider.SelectCycle(
|
||||
ttfCycle,
|
||||
ttfState,
|
||||
ttfXConditions,
|
||||
ttfHelper,
|
||||
ttfConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
ttfState.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Parse(ttfXConditions);
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Resources ...
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
|
||||
//
|
||||
double ask = GetAsk(ttfState.symbol);
|
||||
double bid = GetBid(ttfState.symbol);
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
ttfState.symbol,
|
||||
ttfState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
ttfState.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// First we Have to Detect Inside Box ...
|
||||
XBoxZone insideBox;
|
||||
count = ArraySize(breakedBoxes);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XBoxZone iBox = breakedBoxes[i];
|
||||
|
||||
//
|
||||
bool isInside =
|
||||
IsInsideBox(
|
||||
zBar,
|
||||
iBox //
|
||||
);
|
||||
if (isInside)
|
||||
{
|
||||
//
|
||||
// Since we have to Follow Trend based on Breaked Boxes ...
|
||||
// we have to use:
|
||||
// - Breaked Bullish Boxes on Bearish Trend ...
|
||||
// - Breaked Bearish Boxes on Bullish Trend ...
|
||||
isInside =
|
||||
hasBullishTrend
|
||||
? iBox.IsBearish()
|
||||
: hasBearishTrend
|
||||
? iBox.IsBullish()
|
||||
: false;
|
||||
|
||||
//
|
||||
// Check Inside ...
|
||||
if (isInside)
|
||||
{
|
||||
//
|
||||
insideBox = iBox;
|
||||
iBox.Clean();
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Inside Box is Valid or not ...
|
||||
result = insideBox.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
ttfState.Clean();
|
||||
insideBox.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Update Inside Box From and To ...
|
||||
// Based on Breaked ...
|
||||
insideBox.from = insideBox.to;
|
||||
insideBox.to = TimeCurrent();
|
||||
|
||||
//
|
||||
// Detect Breaked Box Direction ...
|
||||
bool isInsideBoxBullish = insideBox.IsBullish();
|
||||
bool isInsideBoxBearish = insideBox.IsBearish();
|
||||
|
||||
//
|
||||
// Detect Inside Box Rejection ...
|
||||
|
||||
//
|
||||
bool isUpperBearishReject =
|
||||
cBar.high >= insideBox.upper &&
|
||||
cBar.GetUp() < insideBox.upper;
|
||||
|
||||
//
|
||||
bool isUpperBullishReject =
|
||||
cBar.low <= insideBox.upper &&
|
||||
cBar.GetDown() > insideBox.upper;
|
||||
|
||||
//
|
||||
bool isLowerBearishReject =
|
||||
cBar.high >= insideBox.lower &&
|
||||
cBar.GetUp() < insideBox.lower;
|
||||
|
||||
//
|
||||
bool isLowerBullishReject =
|
||||
cBar.low <= insideBox.lower &&
|
||||
cBar.GetDown() > insideBox.lower;
|
||||
|
||||
//
|
||||
// Apply Force Bar Type ...
|
||||
if (forceBarType)
|
||||
{
|
||||
//
|
||||
isUpperBearishReject =
|
||||
isUpperBearishReject &&
|
||||
cBar.IsBearish();
|
||||
|
||||
//
|
||||
isUpperBullishReject =
|
||||
isUpperBullishReject &&
|
||||
cBar.IsBullish();
|
||||
|
||||
//
|
||||
isLowerBearishReject =
|
||||
isLowerBearishReject &&
|
||||
cBar.IsBearish();
|
||||
|
||||
//
|
||||
isLowerBullishReject =
|
||||
isLowerBullishReject &&
|
||||
cBar.IsBullish();
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Force Fibo Pressure ...
|
||||
if (forceBarType)
|
||||
{
|
||||
//
|
||||
isUpperBearishReject =
|
||||
isUpperBearishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BEARISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
|
||||
//
|
||||
isUpperBullishReject =
|
||||
isUpperBullishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BULLISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
|
||||
//
|
||||
isLowerBearishReject =
|
||||
isLowerBearishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BEARISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
|
||||
//
|
||||
isLowerBullishReject =
|
||||
isLowerBullishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BULLISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Conditions ...
|
||||
isBullish = (
|
||||
//
|
||||
hasBullishTrend &&
|
||||
isInsideBoxBearish &&
|
||||
isLowerBullishReject
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Bearish Conditions ...
|
||||
isBearish = (
|
||||
//
|
||||
hasBearishTrend &&
|
||||
isInsideBoxBullish &&
|
||||
isUpperBearishReject
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
box = insideBox;
|
||||
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish //
|
||||
);
|
||||
|
||||
//
|
||||
// Cleanup Resource ...
|
||||
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
|
||||
//
|
||||
ttfState.Clean();
|
||||
insideBox.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool HasSenario4Conditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
@@ -3639,367 +4018,5 @@ struct X121SMCStrategyConditionParser
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool HasSenario2Conditions(
|
||||
ENUM_X_CYCLES ttfCycle,
|
||||
ENUM_X_DIRECTION trend,
|
||||
XBoxZone &unavailableBoxes[],
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0,
|
||||
bool forceBarType = false,
|
||||
bool forceFiboPressure = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
IsValid(ttfCycle) &&
|
||||
HasDirection(trend) &&
|
||||
HasChild(unavailableBoxes);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBullishTrend = IsBullish(trend);
|
||||
bool hasBearishTrend = IsBearish(trend);
|
||||
|
||||
//
|
||||
// TTF Cycle Extract ...
|
||||
XPOIState ttfState;
|
||||
X121Conditions ttfXConditions;
|
||||
XC121SMCCycleHelper *ttfHelper;
|
||||
X121SMCCycleConditions ttfConditions;
|
||||
result = provider.SelectCycle(
|
||||
ttfCycle,
|
||||
ttfState,
|
||||
ttfXConditions,
|
||||
ttfHelper,
|
||||
ttfConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
ttfState.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Parse(ttfXConditions);
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Resources ...
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
|
||||
//
|
||||
double ask = GetAsk(ttfState.symbol);
|
||||
double bid = GetBid(ttfState.symbol);
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
ttfState.symbol,
|
||||
ttfState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
ttfState.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// First we Have to Detect Inside Box ...
|
||||
XBoxZone insideBox;
|
||||
count = ArraySize(unavailableBoxes);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XBoxZone iBox = unavailableBoxes[i];
|
||||
|
||||
//
|
||||
bool isInside =
|
||||
IsInsideBox(
|
||||
zBar,
|
||||
iBox //
|
||||
);
|
||||
if (isInside)
|
||||
{
|
||||
//
|
||||
// Since we have to Follow Trend based on Breaked Boxes ...
|
||||
// we have to use:
|
||||
// - Breaked Bullish Boxes on Bearish Trend ...
|
||||
// - Breaked Bearish Boxes on Bullish Trend ...
|
||||
isInside =
|
||||
hasBullishTrend
|
||||
? iBox.IsBearish()
|
||||
: hasBearishTrend
|
||||
? iBox.IsBullish()
|
||||
: false;
|
||||
|
||||
//
|
||||
// Check Inside ...
|
||||
if (isInside)
|
||||
{
|
||||
//
|
||||
insideBox = iBox;
|
||||
iBox.Clean();
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Inside Box is Valid or not ...
|
||||
result = insideBox.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
ttfState.Clean();
|
||||
insideBox.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Update Inside Box From and To ...
|
||||
// Based on Breaked ...
|
||||
insideBox.from = insideBox.to;
|
||||
insideBox.to = TimeCurrent();
|
||||
|
||||
//
|
||||
// Detect Breaked Box Direction ...
|
||||
bool isInsideBoxBullish = insideBox.IsBullish();
|
||||
bool isInsideBoxBearish = insideBox.IsBearish();
|
||||
|
||||
//
|
||||
// Detect Inside Box Rejection ...
|
||||
|
||||
//
|
||||
bool isUpperBearishReject =
|
||||
cBar.high >= insideBox.upper &&
|
||||
cBar.GetUp() < insideBox.upper;
|
||||
|
||||
//
|
||||
bool isUpperBullishReject =
|
||||
cBar.low <= insideBox.upper &&
|
||||
cBar.GetDown() > insideBox.upper;
|
||||
|
||||
//
|
||||
bool isLowerBearishReject =
|
||||
cBar.high >= insideBox.lower &&
|
||||
cBar.GetUp() < insideBox.lower;
|
||||
|
||||
//
|
||||
bool isLowerBullishReject =
|
||||
cBar.low <= insideBox.lower &&
|
||||
cBar.GetDown() > insideBox.lower;
|
||||
|
||||
//
|
||||
// Apply Force Bar Type ...
|
||||
if (forceBarType)
|
||||
{
|
||||
//
|
||||
isUpperBearishReject =
|
||||
isUpperBearishReject &&
|
||||
cBar.IsBearish();
|
||||
|
||||
//
|
||||
isUpperBullishReject =
|
||||
isUpperBullishReject &&
|
||||
cBar.IsBullish();
|
||||
|
||||
//
|
||||
isLowerBearishReject =
|
||||
isLowerBearishReject &&
|
||||
cBar.IsBearish();
|
||||
|
||||
//
|
||||
isLowerBullishReject =
|
||||
isLowerBullishReject &&
|
||||
cBar.IsBullish();
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Force Fibo Pressure ...
|
||||
if (forceBarType)
|
||||
{
|
||||
//
|
||||
isUpperBearishReject =
|
||||
isUpperBearishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BEARISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
|
||||
//
|
||||
isUpperBullishReject =
|
||||
isUpperBullishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BULLISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
|
||||
//
|
||||
isLowerBearishReject =
|
||||
isLowerBearishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BEARISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
|
||||
//
|
||||
isLowerBullishReject =
|
||||
isLowerBullishReject &&
|
||||
ttfHelper
|
||||
.mBarAnalyser
|
||||
.HasFiboPressure(
|
||||
cBar,
|
||||
X_DIRECTION_BULLISH,
|
||||
X_FIBO_LEVEL_382 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Conditions ...
|
||||
isBullish = (
|
||||
//
|
||||
hasBullishTrend &&
|
||||
isInsideBoxBearish &&
|
||||
isLowerBullishReject
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Bearish Conditions ...
|
||||
isBearish = (
|
||||
//
|
||||
hasBearishTrend &&
|
||||
isInsideBoxBullish &&
|
||||
isUpperBearishReject
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
box = insideBox;
|
||||
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish //
|
||||
);
|
||||
|
||||
//
|
||||
// Cleanup Resource ...
|
||||
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
|
||||
//
|
||||
ttfState.Clean();
|
||||
insideBox.Clean();
|
||||
ZeroMemory(ttfHelper);
|
||||
ttfConditions.Clean();
|
||||
ttfXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
@@ -938,10 +938,7 @@ struct X121SMCStrategyXWZWorkingZone
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION trend;
|
||||
result = IsValid();
|
||||
//&&
|
||||
// DetectOveralDirection(trend);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
@@ -969,7 +966,7 @@ struct X121SMCStrategyXWZWorkingZone
|
||||
// ---------------------------------------------
|
||||
// XPVHK Conditions ...
|
||||
// ---------------------------------------------
|
||||
bool useSenario1 = true;
|
||||
bool useSenario1 = false;
|
||||
bool isSenario1Happend = false;
|
||||
bool isSenario1Bullish = false;
|
||||
bool isSenario1Bearish = false;
|
||||
@@ -1021,11 +1018,15 @@ struct X121SMCStrategyXWZWorkingZone
|
||||
// when Has UnAvailable Boxes ...
|
||||
has = HasBreakedBoxes();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
ENUM_X_DIRECTION overalTrend;
|
||||
bool hasTrend = DetectOveralTrend(overalTrend);
|
||||
if (hasTrend)
|
||||
{
|
||||
//
|
||||
isSenario2Happend = cParser.HasSenario2Conditions(
|
||||
X_CYCLE_DECISION,
|
||||
trend,
|
||||
breakedBoxes,
|
||||
box,
|
||||
dir,
|
||||
@@ -1050,6 +1051,7 @@ struct X121SMCStrategyXWZWorkingZone
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Senario 3:
|
||||
|
||||
@@ -804,6 +804,14 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false;
|
||||
x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || true;
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
|
||||
//
|
||||
x121Inputs.xmasInputs.showUpper = showAll || true;
|
||||
x121Inputs.xmasInputs.showMid = showAll || true;
|
||||
x121Inputs.xmasInputs.showLower = showAll || true;
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
x121Inputs.xatrInputs.showATRUpper = showAll || false;
|
||||
|
||||
Reference in New Issue
Block a user