1556 lines
34 KiB
Plaintext
1556 lines
34 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XCX121X3MAHelper
|
|
// 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 ...
|
|
|
|
//
|
|
// Buffers ...
|
|
enum ENUM_X121_X3MA_BUFFERS
|
|
{
|
|
//
|
|
X121_X3MA_FAST = 0,
|
|
X121_X3MA_FAST_COLOR = 1,
|
|
X121_X3MA_FAST_STATE = 6,
|
|
X121_X3MA_MEDIUM = 2,
|
|
X121_X3MA_MEDIUM_COLOR = 3,
|
|
X121_X3MA_MEDIUM_STATE = 7,
|
|
X121_X3MA_SLOW = 4,
|
|
X121_X3MA_SLOW_COLOR = 5,
|
|
X121_X3MA_SLOW_STATE = 8,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct X121X3MAInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// FAST ...
|
|
int fastLength;
|
|
ENUM_MA_METHOD fastMethod;
|
|
ENUM_APPLIED_PRICE fastAppliedTo;
|
|
|
|
//
|
|
// MEDIUM ...
|
|
int mediumLength;
|
|
ENUM_MA_METHOD mediumMethod;
|
|
ENUM_APPLIED_PRICE mediumAppliedTo;
|
|
|
|
//
|
|
// SLOW ...
|
|
int slowLength;
|
|
ENUM_MA_METHOD slowMethod;
|
|
ENUM_APPLIED_PRICE slowAppliedTo;
|
|
|
|
//
|
|
// Presentation ...
|
|
|
|
//
|
|
int startCalculationForLastBars;
|
|
|
|
//
|
|
bool applyColor;
|
|
|
|
//
|
|
bool showFast;
|
|
bool showSlow;
|
|
bool showMedium;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121X3MAInputs()
|
|
{
|
|
Default();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Cleanup ...
|
|
void Clean()
|
|
{
|
|
//
|
|
// FAST ...
|
|
fastLength = 0;
|
|
fastMethod = MODE_SMA;
|
|
fastAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
// MEDIUM ...
|
|
mediumLength = 0;
|
|
mediumMethod = MODE_SMA;
|
|
mediumAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
// SLOW ...
|
|
slowLength = 0;
|
|
slowMethod = MODE_SMA;
|
|
slowAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
startCalculationForLastBars = 0;
|
|
|
|
//
|
|
applyColor = false;
|
|
|
|
//
|
|
showFast = false;
|
|
showSlow = false;
|
|
showMedium = false;
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
// FAST ...
|
|
fastLength = 6;
|
|
fastMethod = MODE_SMA;
|
|
fastAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
// MEDIUM ...
|
|
mediumLength = 21;
|
|
mediumMethod = MODE_SMA;
|
|
mediumAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
// SLOW ...
|
|
slowLength = 34;
|
|
slowMethod = MODE_SMA;
|
|
slowAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
startCalculationForLastBars = 1000;
|
|
|
|
//
|
|
applyColor = true;
|
|
|
|
//
|
|
showFast = true;
|
|
showSlow = true;
|
|
showMedium = true;
|
|
}
|
|
|
|
//
|
|
// Hide all Visible Buffers ...
|
|
void Hide()
|
|
{
|
|
//
|
|
showFast = false;
|
|
showSlow = false;
|
|
showMedium = false;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
fastLength > 2 &&
|
|
mediumLength > 2 &&
|
|
slowLength > 2 &&
|
|
mediumLength > fastLength &&
|
|
mediumLength < slowLength
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(fastLength, mediumLength);
|
|
result = MathMax(result, slowLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Conditions ...
|
|
struct X121X3MAConditions
|
|
{
|
|
//
|
|
// Common ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
datetime time;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
double fastBuffer[];
|
|
double mediumBuffer[];
|
|
double slowBuffer[];
|
|
double fastStateBuffer[];
|
|
double mediumStateBuffer[];
|
|
double slowStateBuffer[];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isFastOverMedium;
|
|
bool isFastUnderMedium;
|
|
|
|
//
|
|
bool isFastCrossedOverMedium;
|
|
bool isFastCrossedUnderMedium;
|
|
|
|
//
|
|
bool isFastOverSlow;
|
|
bool isFastUnderSlow;
|
|
|
|
//
|
|
bool isFastCrossedOverSlow;
|
|
bool isFastCrossedUnderSlow;
|
|
|
|
//
|
|
bool isMediumOverSlow;
|
|
bool isMediumUnderSlow;
|
|
|
|
//
|
|
bool isMediumCrossedOverSlow;
|
|
bool isMediumCrossedUnderSlow;
|
|
|
|
//
|
|
bool is3MaBullishOrdered;
|
|
bool is3MaBearishOrdered;
|
|
|
|
//
|
|
bool is3MaSwitchedToBullishOrdered;
|
|
bool is3MaSwitchedToBearishOrdered;
|
|
|
|
//
|
|
bool is3MaBullishState;
|
|
bool is3MaBearishState;
|
|
|
|
//
|
|
bool is3MaSwitchedToBullishState;
|
|
bool is3MaSwitchedToBearishState;
|
|
|
|
//
|
|
bool is3MaBullish;
|
|
bool is3MaBearish;
|
|
|
|
//
|
|
bool is3MaSwitchedToBullish;
|
|
bool is3MaSwitchedToBearish;
|
|
|
|
//
|
|
bool is3MaFinishedFromBullish;
|
|
bool is3MaFinishedFromBearish;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121X3MAConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
// Commons ...
|
|
symbol = NULL;
|
|
period = NULL;
|
|
time = NULL;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
XClean(fastBuffer);
|
|
XClean(mediumBuffer);
|
|
XClean(slowBuffer);
|
|
XClean(fastStateBuffer);
|
|
XClean(mediumStateBuffer);
|
|
XClean(slowStateBuffer);
|
|
|
|
//
|
|
ArraySetAsSeries(fastBuffer, true);
|
|
ArraySetAsSeries(mediumBuffer, true);
|
|
ArraySetAsSeries(slowBuffer, true);
|
|
ArraySetAsSeries(fastStateBuffer, true);
|
|
ArraySetAsSeries(mediumStateBuffer, true);
|
|
ArraySetAsSeries(slowStateBuffer, true);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
isFastOverMedium = false;
|
|
isFastUnderMedium = false;
|
|
|
|
//
|
|
isFastCrossedOverMedium = false;
|
|
isFastCrossedUnderMedium = false;
|
|
|
|
//
|
|
isFastOverSlow = false;
|
|
isFastUnderSlow = false;
|
|
|
|
//
|
|
isFastCrossedOverSlow = false;
|
|
isFastCrossedUnderSlow = false;
|
|
|
|
//
|
|
isMediumOverSlow = false;
|
|
isMediumUnderSlow = false;
|
|
|
|
//
|
|
isMediumCrossedOverSlow = false;
|
|
isMediumCrossedUnderSlow = false;
|
|
|
|
//
|
|
is3MaBullishOrdered = false;
|
|
is3MaBearishOrdered = false;
|
|
|
|
//
|
|
is3MaSwitchedToBullishOrdered = false;
|
|
is3MaSwitchedToBearishOrdered = false;
|
|
|
|
//
|
|
is3MaBullishState = false;
|
|
is3MaBearishState = false;
|
|
|
|
//
|
|
is3MaSwitchedToBullishState = false;
|
|
is3MaSwitchedToBearishState = false;
|
|
|
|
//
|
|
is3MaBullish = false;
|
|
is3MaBearish = false;
|
|
|
|
//
|
|
is3MaSwitchedToBullish = false;
|
|
is3MaSwitchedToBearish = false;
|
|
|
|
//
|
|
is3MaFinishedFromBullish = false;
|
|
is3MaFinishedFromBearish = false;
|
|
|
|
//
|
|
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;
|
|
|
|
//
|
|
double score = 1;
|
|
double minScore = 0.5;
|
|
double highScore = 1.5;
|
|
|
|
//
|
|
if (isFastOverSlow)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isFastOverMedium)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isMediumOverSlow)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isFastCrossedOverSlow)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isFastCrossedOverMedium)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isMediumCrossedOverSlow)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
|
|
//
|
|
if (is3MaBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (is3MaBullishState)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (is3MaBullishOrdered)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (is3MaSwitchedToBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (is3MaFinishedFromBearish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (is3MaSwitchedToBullishState)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (is3MaSwitchedToBullishOrdered)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
|
|
//
|
|
if (isFastUnderSlow)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isMediumUnderSlow)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isFastUnderMedium)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isFastCrossedUnderSlow)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isFastCrossedUnderMedium)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isMediumCrossedUnderSlow)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
|
|
//
|
|
if (is3MaBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (is3MaBearishState)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (is3MaBearishOrdered)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (is3MaSwitchedToBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (is3MaFinishedFromBullish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (is3MaSwitchedToBearishState)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (is3MaSwitchedToBearishOrdered)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 =
|
|
//
|
|
"-----------------------" + separator +
|
|
"X3MA: " + separator +
|
|
"-----------------------" + separator +
|
|
ToString("isFastOverMedium", isFastOverMedium, ignoreFalseConditions, separator) +
|
|
ToString("isFastUnderMedium", isFastUnderMedium, ignoreFalseConditions, separator) +
|
|
ToString("isFastCrossedOverMedium", isFastCrossedOverMedium, ignoreFalseConditions, separator) +
|
|
ToString("isFastCrossedUnderMedium", isFastCrossedUnderMedium, ignoreFalseConditions, separator) +
|
|
ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) +
|
|
ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) +
|
|
ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) +
|
|
ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) +
|
|
ToString("isMediumOverSlow", isMediumOverSlow, ignoreFalseConditions, separator) +
|
|
ToString("isMediumUnderSlow", isMediumUnderSlow, ignoreFalseConditions, separator) +
|
|
ToString("isMediumCrossedOverSlow", isMediumCrossedOverSlow, ignoreFalseConditions, separator) +
|
|
ToString("isMediumCrossedUnderSlow", isMediumCrossedUnderSlow, ignoreFalseConditions, separator) +
|
|
ToString("is3MaBullishOrdered", is3MaBullishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("is3MaBearishOrdered", is3MaBearishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("is3MaSwitchedToBullishOrdered", is3MaSwitchedToBullishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("is3MaSwitchedToBearishOrdered", is3MaSwitchedToBearishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("is3MaBullishState", is3MaBullishState, ignoreFalseConditions, separator) +
|
|
ToString("is3MaBearishState", is3MaBearishState, ignoreFalseConditions, separator) +
|
|
ToString("is3MaSwitchedToBullishState", is3MaSwitchedToBullishState, ignoreFalseConditions, separator) +
|
|
ToString("is3MaSwitchedToBearishState", is3MaSwitchedToBearishState, ignoreFalseConditions, separator) +
|
|
ToString("is3MaBullish", is3MaBullish, ignoreFalseConditions, separator) +
|
|
ToString("is3MaBearish", is3MaBearish, ignoreFalseConditions, separator) +
|
|
ToString("is3MaSwitchedToBullish", is3MaSwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("is3MaSwitchedToBearish", is3MaSwitchedToBearish, ignoreFalseConditions, separator) +
|
|
ToString("is3MaFinishedFromBullish", is3MaFinishedFromBullish, ignoreFalseConditions, separator) +
|
|
ToString("is3MaFinishedFromBearish", is3MaFinishedFromBearish, ignoreFalseConditions, separator) +
|
|
//
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
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 XCX121X3MAHelper : public XCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XCX121X3MAHelper()
|
|
: XCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121X3MAHelper()
|
|
{
|
|
//
|
|
mInputs.Clean();
|
|
|
|
//
|
|
Clean(fastBuffer);
|
|
Clean(mediumBuffer);
|
|
Clean(slowBuffer);
|
|
Clean(fastStateBuffer);
|
|
Clean(mediumStateBuffer);
|
|
Clean(slowStateBuffer);
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
X121X3MAInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ArraySetAsSeries(fastBuffer, true);
|
|
ArraySetAsSeries(mediumBuffer, true);
|
|
ArraySetAsSeries(slowBuffer, true);
|
|
ArraySetAsSeries(fastStateBuffer, true);
|
|
ArraySetAsSeries(mediumStateBuffer, true);
|
|
ArraySetAsSeries(slowStateBuffer, true);
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.x121.x3ma",
|
|
"", // FAST ...
|
|
mInputs.fastLength,
|
|
mInputs.fastMethod,
|
|
mInputs.fastAppliedTo,
|
|
"", // MEDIUM ...
|
|
mInputs.mediumLength,
|
|
mInputs.mediumMethod,
|
|
mInputs.mediumAppliedTo,
|
|
"", // SLOW ...
|
|
mInputs.slowLength,
|
|
mInputs.slowMethod,
|
|
mInputs.slowAppliedTo,
|
|
"", // Presentation ...
|
|
mInputs.startCalculationForLastBars,
|
|
mInputs.applyColor,
|
|
mInputs.showFast,
|
|
mInputs.showSlow,
|
|
mInputs.showMedium
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
X121X3MAInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
X121X3MAInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Readers ...
|
|
|
|
//
|
|
// FAST ...
|
|
|
|
//
|
|
double GetFast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(fastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return fastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyFast(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
fastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// FAST STATE ...
|
|
|
|
//
|
|
double GetFastState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(fastStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return fastStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyFastState(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
fastStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// MEDIUM ...
|
|
|
|
//
|
|
double GetMedium(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(mediumBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return mediumBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyMedium(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
mediumBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// MEDIUM STATE ...
|
|
|
|
//
|
|
double GetMediumState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(mediumStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return mediumStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyMediumState(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
mediumStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// SLOW ...
|
|
|
|
//
|
|
double GetSlow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(slowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return slowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySlow(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
slowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// SLOW STATE ...
|
|
|
|
//
|
|
double GetSlowState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(slowStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return slowStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySlowState(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
slowStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
void Free() override
|
|
{
|
|
Cleanup(10);
|
|
}
|
|
|
|
//
|
|
bool GetConditions(
|
|
X121X3MAConditions &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 ...
|
|
|
|
//
|
|
// FAST ...
|
|
|
|
//
|
|
CopyFast(
|
|
zIndex,
|
|
loopback,
|
|
conditions.fastBuffer //
|
|
);
|
|
|
|
//
|
|
CopyFastState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.fastStateBuffer //
|
|
);
|
|
|
|
//
|
|
// MEDIUM ...
|
|
|
|
//
|
|
CopyMedium(
|
|
zIndex,
|
|
loopback,
|
|
conditions.mediumBuffer //
|
|
);
|
|
|
|
//
|
|
CopyMediumState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.mediumStateBuffer //
|
|
);
|
|
|
|
//
|
|
// SLOW ...
|
|
|
|
//
|
|
CopySlow(
|
|
zIndex,
|
|
loopback,
|
|
conditions.slowBuffer //
|
|
);
|
|
|
|
//
|
|
CopySlowState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.slowStateBuffer //
|
|
);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
int zIDX = 0;
|
|
int cIDX = 1;
|
|
int pIDX = cIDX + 1;
|
|
int p2IDX = pIDX + 1;
|
|
int p3IDX = p2IDX + 1;
|
|
int p4IDX = p3IDX + 1;
|
|
|
|
//
|
|
// Calculate ...
|
|
|
|
//
|
|
// FAST ...
|
|
|
|
//
|
|
double cFast = conditions.fastBuffer[cIDX];
|
|
double pFast = conditions.fastBuffer[pIDX];
|
|
double p2Fast = conditions.fastBuffer[p2IDX];
|
|
|
|
//
|
|
double cFastState = conditions.fastStateBuffer[cIDX];
|
|
double pFastState = conditions.fastStateBuffer[pIDX];
|
|
double p2FastState = conditions.fastStateBuffer[p2IDX];
|
|
|
|
//
|
|
// MEDIUM ...
|
|
|
|
//
|
|
double cMedium = conditions.mediumBuffer[cIDX];
|
|
double pMedium = conditions.mediumBuffer[pIDX];
|
|
double p2Medium = conditions.mediumBuffer[p2IDX];
|
|
|
|
//
|
|
double cMediumState = conditions.mediumStateBuffer[cIDX];
|
|
double pMediumState = conditions.mediumStateBuffer[pIDX];
|
|
double p2MediumState = conditions.mediumStateBuffer[p2IDX];
|
|
|
|
//
|
|
// FAST ...
|
|
|
|
//
|
|
double cSlow = conditions.slowBuffer[cIDX];
|
|
double pSlow = conditions.slowBuffer[pIDX];
|
|
double p2Slow = conditions.slowBuffer[p2IDX];
|
|
|
|
//
|
|
double cSlowState = conditions.slowStateBuffer[cIDX];
|
|
double pSlowState = conditions.slowStateBuffer[pIDX];
|
|
double p2SlowState = conditions.slowStateBuffer[p2IDX];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isFastOverMedium = cFast > cMedium;
|
|
bool isFastOverMediumPrev = pFast > pMedium;
|
|
bool isFastCrossedOverMedium = isFastOverMedium &&
|
|
!isFastOverMediumPrev;
|
|
|
|
//
|
|
bool isFastUnderMedium = cFast < cMedium;
|
|
bool isFastUnderMediumPrev = pFast < pMedium;
|
|
bool isFastCrossedUnderMedium = isFastUnderMedium &&
|
|
!isFastUnderMediumPrev;
|
|
|
|
//
|
|
bool isFastOverSlow = cFast > cSlow;
|
|
bool isFastOverSlowPrev = pFast > pSlow;
|
|
bool isFastCrossedOverSlow = isFastOverSlow &&
|
|
!isFastOverSlowPrev;
|
|
|
|
//
|
|
bool isFastUnderSlow = cFast < cSlow;
|
|
bool isFastUnderSlowPrev = pFast < pSlow;
|
|
bool isFastCrossedUnderSlow = isFastUnderSlow &&
|
|
!isFastUnderSlowPrev;
|
|
|
|
//
|
|
bool isMediumOverSlow = cMedium > cSlow;
|
|
bool isMediumOverSlowPrev = pMedium > pSlow;
|
|
bool isMediumCrossedOverSlow = isMediumOverSlow &&
|
|
!isMediumOverSlowPrev;
|
|
|
|
//
|
|
bool isMediumUnderSlow = cMedium < cSlow;
|
|
bool isMediumUnderSlowPrev = pMedium < pSlow;
|
|
bool isMediumCrossedUnderSlow = isMediumUnderSlow &&
|
|
!isMediumUnderSlowPrev;
|
|
|
|
//
|
|
bool is3MaBullishOrdered =
|
|
isFastOverMedium &&
|
|
isMediumOverSlow;
|
|
bool is3MaBullishOrderedPrev =
|
|
isFastOverMediumPrev &&
|
|
isMediumOverSlowPrev;
|
|
|
|
//
|
|
bool is3MaBearishOrdered =
|
|
isFastUnderMedium &&
|
|
isMediumUnderSlow;
|
|
bool is3MaBearishOrderedPrev =
|
|
isFastUnderMediumPrev &&
|
|
isMediumUnderSlowPrev;
|
|
|
|
//
|
|
bool is3MaSwitchedToBullishOrdered = is3MaBullishOrdered &&
|
|
!is3MaBullishOrderedPrev;
|
|
bool is3MaSwitchedToBearishOrdered = is3MaBearishOrdered &&
|
|
!is3MaBearishOrderedPrev;
|
|
|
|
//
|
|
bool is3MaBullishState =
|
|
cFastState > 0 &&
|
|
cMediumState > 0 &&
|
|
cSlowState > 0;
|
|
bool is3MaBullishStatePrev =
|
|
pFastState > 0 &&
|
|
pMediumState > 0 &&
|
|
pSlowState > 0;
|
|
|
|
//
|
|
bool is3MaBearishState =
|
|
cFastState < 0 &&
|
|
cMediumState < 0 &&
|
|
cSlowState < 0;
|
|
bool is3MaBearishStatePrev =
|
|
pFastState < 0 &&
|
|
pMediumState < 0 &&
|
|
pSlowState < 0;
|
|
|
|
//
|
|
bool is3MaSwitchedToBullishState = is3MaBullishState &&
|
|
!is3MaBullishStatePrev;
|
|
bool is3MaSwitchedToBearishState = is3MaBearishState &&
|
|
!is3MaBearishStatePrev;
|
|
|
|
//
|
|
bool is3MaBullish =
|
|
is3MaBullishState &&
|
|
is3MaBullishOrdered;
|
|
bool is3MaBullishPrev =
|
|
is3MaBullishStatePrev &&
|
|
is3MaBullishOrderedPrev;
|
|
|
|
//
|
|
bool is3MaBearish =
|
|
is3MaBearishState &&
|
|
is3MaBearishOrdered;
|
|
bool is3MaBearishPrev =
|
|
is3MaBearishStatePrev &&
|
|
is3MaBearishOrderedPrev;
|
|
|
|
//
|
|
bool is3MaSwitchedToBullish = is3MaBullish &&
|
|
!is3MaBullishPrev;
|
|
bool is3MaSwitchedToBearish = is3MaBearish &&
|
|
!is3MaBearishPrev;
|
|
|
|
//
|
|
bool is3MaFinishedFromBullish = !is3MaBullish &&
|
|
is3MaBullishPrev;
|
|
bool is3MaFinishedFromBearish = !is3MaBearish &&
|
|
is3MaBearishPrev;
|
|
|
|
//
|
|
conditions.is3MaBullish = is3MaBullish;
|
|
conditions.is3MaBearish = is3MaBearish;
|
|
conditions.isFastOverSlow = isFastOverSlow;
|
|
conditions.isFastUnderSlow = isFastUnderSlow;
|
|
conditions.isFastOverMedium = isFastOverMedium;
|
|
conditions.isMediumOverSlow = isMediumOverSlow;
|
|
conditions.isFastUnderMedium = isFastUnderMedium;
|
|
conditions.isMediumUnderSlow = isMediumUnderSlow;
|
|
conditions.is3MaBullishState = is3MaBullishState;
|
|
conditions.is3MaBearishState = is3MaBearishState;
|
|
conditions.is3MaBullishOrdered = is3MaBullishOrdered;
|
|
conditions.is3MaBearishOrdered = is3MaBearishOrdered;
|
|
conditions.isFastCrossedOverSlow = isFastCrossedOverSlow;
|
|
conditions.is3MaSwitchedToBullish = is3MaSwitchedToBullish;
|
|
conditions.is3MaSwitchedToBearish = is3MaSwitchedToBearish;
|
|
conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow;
|
|
conditions.isFastCrossedOverMedium = isFastCrossedOverMedium;
|
|
conditions.isMediumCrossedOverSlow = isMediumCrossedOverSlow;
|
|
conditions.is3MaFinishedFromBullish = is3MaFinishedFromBullish;
|
|
conditions.is3MaFinishedFromBearish = is3MaFinishedFromBearish;
|
|
conditions.isFastCrossedUnderMedium = isFastCrossedUnderMedium;
|
|
conditions.isMediumCrossedUnderSlow = isMediumCrossedUnderSlow;
|
|
conditions.is3MaSwitchedToBullishState = is3MaSwitchedToBullishState;
|
|
conditions.is3MaSwitchedToBearishState = is3MaSwitchedToBearishState;
|
|
conditions.is3MaSwitchedToBullishOrdered = is3MaSwitchedToBullishOrdered;
|
|
conditions.is3MaSwitchedToBearishOrdered = is3MaSwitchedToBearishOrdered;
|
|
|
|
//
|
|
Cleanup();
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
X121X3MAInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
double fastBuffer[];
|
|
double mediumBuffer[];
|
|
double slowBuffer[];
|
|
double fastStateBuffer[];
|
|
double mediumStateBuffer[];
|
|
double slowStateBuffer[];
|
|
|
|
//
|
|
void Calculate(
|
|
int barIndex = 0,
|
|
int maxRequiredBars = 100 //
|
|
)
|
|
{
|
|
//
|
|
// Buffers ...
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
// FAST ...
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_X3MA_FAST,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
fastBuffer //
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_X3MA_FAST_STATE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
fastStateBuffer //
|
|
);
|
|
|
|
//
|
|
// MEDIUM ...
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_X3MA_MEDIUM,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
mediumBuffer //
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_X3MA_MEDIUM_STATE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
mediumStateBuffer //
|
|
);
|
|
|
|
//
|
|
// SLOW ...
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_X3MA_SLOW,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
slowBuffer //
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_X3MA_SLOW_STATE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
slowStateBuffer //
|
|
);
|
|
}
|
|
|
|
//
|
|
void Cleanup(
|
|
int maxAllowed = 100 //
|
|
)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
fastBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
mediumBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
slowBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
fastStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
mediumStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
slowStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |