Files
MQL5Data/Helpers/x-saherelm.x121.xstr.helper.mq5
T
2025-04-13 02:35:47 +03:30

1900 lines
42 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XCX121XSTRHelper
// 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_XSTR_BUFFERS
{
//
X121_XSTR_LINE = 0,
X121_XSTR_COLOR_LINE = 1,
X121_XSTR_UP_LINE = 2,
X121_XSTR_DOWN_LINE = 3,
X121_XSTR_HSM_LINE = 4,
X121_XSTR_LSM_LINE = 5,
X121_XSTR_XVIDYA_LINE = 6,
X121_XSTR_ATR_LINE = 7,
X121_XSTR_PRICE_LINE = 8,
X121_XSTR_STATE_LINE = 9,
};
//
// Input Models ...
struct X121XSTRInputs
{
//
// Props ...
int strLength; // Length
double strMultiplier; // Multiplier
int vidyaLength; // Smothing Length
ENUM_MA_METHOD strBoundaryMode; // Boundary Mode
ENUM_APPLIED_PRICE strAppliedTo; // Applied To
ENUM_APPLIED_PRICE vidyaAppliedTo; // Smoothing Applied To
//
bool showStr; // Show Str
bool showVidya; // Show Vidya
bool showStrUpper; // Show Str Upper
bool showStrLower; // Show Str Lower
bool showStrSMLow; // Show Str SM Low
bool showStrSMHigh; // Show Str SM High
//
// Constructor(s) ...
X121XSTRInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
strLength = 0;
strMultiplier = 0.0;
vidyaLength = 0;
strBoundaryMode = MODE_SMA;
strAppliedTo = PRICE_MEDIAN;
vidyaAppliedTo = PRICE_CLOSE;
//
showStr = false;
showVidya = false;
showStrUpper = false;
showStrLower = false;
showStrSMLow = false;
showStrSMHigh = false;
//
ZeroMemory(this);
}
//
// Default ...
void Default()
{
//
strLength = 14;
vidyaLength = 14;
strMultiplier = 3.0;
strBoundaryMode = MODE_SMA;
strAppliedTo = PRICE_CLOSE;
vidyaAppliedTo = PRICE_CLOSE;
//
showStr = true;
showVidya = true;
showStrUpper = true;
showStrLower = true;
showStrSMLow = true;
showStrSMHigh = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
strLength > 0 &&
strMultiplier > 0
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(strLength, vidyaLength);
//
return result;
}
};
//
// Conditions ...
struct X121XSTRConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
double strBuffer[];
double atrBuffer[];
double vidyaBuffer[];
double strUpBuffer[];
double strDownBuffer[];
double strPriceBuffer[];
double strStateBuffer[];
double strSMLowBuffer[];
double strSMHighBuffer[];
//
// Conditions ...
//
// STR ...
//
bool isStrBullish;
bool isStrBearish;
//
bool isStrSwitchedToBullish;
bool isStrSwitchedToBearish;
//
// VIDYA ...
//
bool isRejectUpVidya;
bool isClosedOverVidya;
bool isCrossedOverVidya;
//
bool isRejectDownVidya;
bool isCloseUnderVidya;
bool isCrossedUnderVidya;
//
// HMS ...
//
bool isRejectUpLSM;
bool isCloseOverLSM;
bool isCrossedOverLSM;
//
bool isRejectDownLSM;
bool isCloseUnderLSM;
bool isCrossedUnderLSM;
//
// HSM ..
//
bool isRejectUpHSM;
bool isCloseOverHSM;
bool isCrossedOverHSM;
//
bool isRejectDownHSM;
bool isCloseUnderHSM;
bool isCrossedUnderHSM;
//
// STR ...
//
bool isRejectUpStr;
bool isCloseOverStr;
bool isCrossedOverStr;
//
bool isRejectDownStr;
bool isCloseUnderStr;
bool isCrossedUnderStr;
//
// HSM / ViDYA ...
//
bool isVidyaOverHSM;
bool isVidyaCrossedOverHSM;
//
bool isVidyaUnderHSM;
bool isVidyaCrossedUnderHSM;
//
// LSM / VIDYA ...
//
bool isVidyaOverLSM;
bool isVidyaCrossedOverLSM;
//
bool isVidyaUnderLSM;
bool isVidyaCrossedUnderLSM;
//
// STR / VIDYA ...
//
bool isVidyaOverStr;
bool isVidyaCrossedOverStr;
//
bool isVidyaUnderStr;
bool isVidyaCrossedUnderStr;
//
// bool isCloseLower
//
// Constructor ...
X121XSTRConditions()
{
Clean();
}
//
// Tools ...
/**
* Cleaning Up ...
*/
void Clean()
{
//
// Commons ...
symbol = NULL;
period = NULL;
time = NULL;
//
// Buffers ...
//
Clean(strBuffer);
Clean(atrBuffer);
Clean(vidyaBuffer);
Clean(strUpBuffer);
Clean(strDownBuffer);
Clean(strPriceBuffer);
Clean(strStateBuffer);
Clean(strSMLowBuffer);
Clean(strSMHighBuffer);
//
ArraySetAsSeries(strBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(vidyaBuffer, true);
ArraySetAsSeries(strUpBuffer, true);
ArraySetAsSeries(strDownBuffer, true);
ArraySetAsSeries(strPriceBuffer, true);
ArraySetAsSeries(strStateBuffer, true);
ArraySetAsSeries(strSMLowBuffer, true);
ArraySetAsSeries(strSMHighBuffer, true);
//
// Conditions ...
isStrBullish = false;
isStrBearish = false;
isRejectUpLSM = false;
isRejectUpHSM = false;
isRejectUpStr = false;
isCloseOverHSM = false;
isCloseOverLSM = false;
isCloseOverStr = false;
isVidyaOverHSM = false;
isVidyaOverLSM = false;
isVidyaOverStr = false;
isRejectDownLSM = false;
isRejectDownHSM = false;
isVidyaUnderStr = false;
isVidyaUnderHSM = false;
isVidyaUnderLSM = false;
isCloseUnderStr = false;
isRejectDownStr = false;
isRejectUpVidya = false;
isCloseUnderHSM = false;
isCloseUnderLSM = false;
isCrossedOverLSM = false;
isCrossedOverHSM = false;
isCrossedOverStr = false;
isCrossedUnderHSM = false;
isCrossedUnderLSM = false;
isCrossedUnderStr = false;
isClosedOverVidya = false;
isRejectDownVidya = false;
isCloseUnderVidya = false;
isCrossedOverVidya = false;
isCrossedUnderVidya = false;
isVidyaCrossedOverHSM = false;
isVidyaCrossedOverStr = false;
isVidyaCrossedOverLSM = false;
isVidyaCrossedUnderHSM = false;
isVidyaCrossedUnderLSM = false;
isVidyaCrossedUnderStr = false;
isStrSwitchedToBullish = false;
isStrSwitchedToBearish = 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 (isStrBullish)
{
bullishScore += minScore;
}
if (isStrSwitchedToBullish)
{
bullishScore += score;
}
if (isRejectUpVidya)
{
bullishScore += minScore;
}
if (isClosedOverVidya)
{
bullishScore += minScore;
}
if (isCrossedOverVidya)
{
bullishScore += minScore;
}
if (isRejectUpLSM)
{
bullishScore += minScore;
}
if (isCloseOverLSM)
{
bullishScore += minScore;
}
if (isCrossedOverLSM)
{
bullishScore += minScore;
}
if (isRejectUpHSM)
{
bullishScore += minScore;
}
if (isCloseOverHSM)
{
bullishScore += minScore;
}
if (isCrossedOverHSM)
{
bullishScore += minScore;
}
if (isRejectUpStr)
{
bullishScore += minScore;
}
if (isCloseOverStr)
{
bullishScore += minScore;
}
if (isCrossedOverStr)
{
bullishScore += minScore;
}
if (isVidyaOverHSM)
{
bullishScore += minScore;
}
if (isVidyaCrossedOverHSM)
{
bullishScore += minScore;
}
if (isVidyaOverLSM)
{
bullishScore += minScore;
}
if (isVidyaCrossedOverLSM)
{
bullishScore += minScore;
}
if (isVidyaOverStr)
{
bullishScore += minScore;
}
if (isVidyaCrossedOverStr)
{
bullishScore += minScore;
}
//
if (isStrBearish)
{
bearishScore += minScore;
}
if (isStrSwitchedToBearish)
{
bearishScore += score;
}
if (isRejectDownVidya)
{
bearishScore += minScore;
}
if (isCloseUnderVidya)
{
bearishScore += minScore;
}
if (isCrossedUnderVidya)
{
bearishScore += minScore;
}
if (isRejectDownLSM)
{
bearishScore += minScore;
}
if (isCloseUnderLSM)
{
bearishScore += minScore;
}
if (isCrossedUnderLSM)
{
bearishScore += minScore;
}
if (isRejectDownHSM)
{
bearishScore += minScore;
}
if (isCloseUnderHSM)
{
bearishScore += minScore;
}
if (isCrossedUnderHSM)
{
bearishScore += minScore;
}
if (isRejectDownStr)
{
bearishScore += minScore;
}
if (isCloseUnderStr)
{
bearishScore += minScore;
}
if (isCrossedUnderStr)
{
bearishScore += minScore;
}
if (isVidyaUnderHSM)
{
bearishScore += minScore;
}
if (isVidyaCrossedUnderHSM)
{
bearishScore += minScore;
}
if (isVidyaUnderLSM)
{
bearishScore += minScore;
}
if (isVidyaCrossedUnderLSM)
{
bearishScore += minScore;
}
if (isVidyaUnderStr)
{
bearishScore += minScore;
}
if (isVidyaCrossedUnderStr)
{
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 +
"XSTR: " + separator +
"-----------------------" + separator +
ToString("isStrBullish", isStrBullish, ignoreFalseConditions, separator) +
ToString("isStrBearish", isStrBearish, ignoreFalseConditions, separator) +
ToString("isStrSwitchedToBullish", isStrSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isStrSwitchedToBearish", isStrSwitchedToBearish, ignoreFalseConditions, separator) +
ToString("isRejectUpVidya", isRejectUpVidya, ignoreFalseConditions, separator) +
ToString("isClosedOverVidya", isClosedOverVidya, ignoreFalseConditions, separator) +
ToString("isCrossedOverVidya", isCrossedOverVidya, ignoreFalseConditions, separator) +
ToString("isRejectDownVidya", isRejectDownVidya, ignoreFalseConditions, separator) +
ToString("isCloseUnderVidya", isCloseUnderVidya, ignoreFalseConditions, separator) +
ToString("isCrossedUnderVidya", isCrossedUnderVidya, ignoreFalseConditions, separator) +
ToString("isRejectUpLSM", isRejectUpLSM, ignoreFalseConditions, separator) +
ToString("isCloseOverLSM", isCloseOverLSM, ignoreFalseConditions, separator) +
ToString("isCrossedOverLSM", isCrossedOverLSM, ignoreFalseConditions, separator) +
ToString("isRejectDownLSM", isRejectDownLSM, ignoreFalseConditions, separator) +
ToString("isCloseUnderLSM", isCloseUnderLSM, ignoreFalseConditions, separator) +
ToString("isCrossedUnderLSM", isCrossedUnderLSM, ignoreFalseConditions, separator) +
ToString("isRejectUpHSM", isRejectUpHSM, ignoreFalseConditions, separator) +
ToString("isCloseOverHSM", isCloseOverHSM, ignoreFalseConditions, separator) +
ToString("isCrossedOverHSM", isCrossedOverHSM, ignoreFalseConditions, separator) +
ToString("isRejectDownHSM", isRejectDownHSM, ignoreFalseConditions, separator) +
ToString("isCloseUnderHSM", isCloseUnderHSM, ignoreFalseConditions, separator) +
ToString("isCrossedUnderHSM", isCrossedUnderHSM, ignoreFalseConditions, separator) +
ToString("isRejectUpStr", isRejectUpStr, ignoreFalseConditions, separator) +
ToString("isCloseOverStr", isCloseOverStr, ignoreFalseConditions, separator) +
ToString("isCrossedOverStr", isCrossedOverStr, ignoreFalseConditions, separator) +
ToString("isRejectDownStr", isRejectDownStr, ignoreFalseConditions, separator) +
ToString("isCloseUnderStr", isCloseUnderStr, ignoreFalseConditions, separator) +
ToString("isCrossedUnderStr", isCrossedUnderStr, ignoreFalseConditions, separator) +
ToString("isVidyaOverHSM", isVidyaOverHSM, ignoreFalseConditions, separator) +
ToString("isVidyaCrossedOverHSM", isVidyaCrossedOverHSM, ignoreFalseConditions, separator) +
ToString("isVidyaUnderHSM", isVidyaUnderHSM, ignoreFalseConditions, separator) +
ToString("isVidyaCrossedUnderHSM", isVidyaCrossedUnderHSM, ignoreFalseConditions, separator) +
ToString("isVidyaOverLSM", isVidyaOverLSM, ignoreFalseConditions, separator) +
ToString("isVidyaCrossedOverLSM", isVidyaCrossedOverLSM, ignoreFalseConditions, separator) +
ToString("isVidyaUnderLSM", isVidyaUnderLSM, ignoreFalseConditions, separator) +
ToString("isVidyaCrossedUnderLSM", isVidyaCrossedUnderLSM, ignoreFalseConditions, separator) +
ToString("isVidyaOverStr", isVidyaOverStr, ignoreFalseConditions, separator) +
ToString("isVidyaCrossedOverStr", isVidyaCrossedOverStr, ignoreFalseConditions, separator) +
ToString("isVidyaUnderStr", isVidyaUnderStr, ignoreFalseConditions, separator) +
ToString("isVidyaCrossedUnderStr", isVidyaCrossedUnderStr, 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 XCX121XSTRHelper : public XCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XCX121XSTRHelper()
: XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XCX121XSTRHelper()
{
//
mInputs.Clean();
//
Clean(strBuffer);
Clean(atrBuffer);
Clean(strPriceBuffer);
Clean(strUpBuffer);
Clean(strDownBuffer);
Clean(strStateBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121XSTRInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
ArraySetAsSeries(strBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(vidyaBuffer, true);
ArraySetAsSeries(strUpBuffer, true);
ArraySetAsSeries(strDownBuffer, true);
ArraySetAsSeries(strPriceBuffer, true);
ArraySetAsSeries(strStateBuffer, true);
ArraySetAsSeries(strSMLowBuffer, true);
ArraySetAsSeries(strSMHighBuffer, true);
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xstr",
//
// Inputs ...
//
// Market ...
"",
mInputs.strLength,
mInputs.strMultiplier,
mInputs.vidyaLength,
mInputs.strBoundaryMode,
mInputs.strAppliedTo,
mInputs.vidyaAppliedTo,
//
// Presentation ...
"",
mInputs.showStr,
mInputs.showVidya,
mInputs.showStrUpper,
mInputs.showStrLower,
mInputs.showStrSMLow,
mInputs.showStrSMHigh
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121XSTRInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121XSTRInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Readers ...
//
// Vidya ...
//
double GetVidya(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(vidyaBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return vidyaBuffer[barIndex];
}
//
int CopyVidya(
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,
vidyaBuffer,
buffer,
forceClean
//
);
}
//
// ATR ...
//
double GetATR(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(atrBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return atrBuffer[barIndex];
}
//
int CopyATR(
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,
atrBuffer,
buffer,
forceClean
//
);
}
//
double GetSTR(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(strBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strBuffer[barIndex];
}
//
int CopySTR(
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,
strBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(strStateBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strStateBuffer[barIndex];
}
//
int CopySTRState(
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,
strStateBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRPrice(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(strPriceBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strPriceBuffer[barIndex];
}
//
int CopySTRPrice(
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,
strPriceBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRUp(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(strUpBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strUpBuffer[barIndex];
}
//
int CopySTRUp(
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,
strUpBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRDown(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(strDownBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strDownBuffer[barIndex];
}
//
int CopySTRDown(
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,
strDownBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRSMLow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(strSMLowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strSMLowBuffer[barIndex];
}
//
int CopySTRSMLow(
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,
strSMLowBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRSMHigh(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(strSMHighBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strSMHighBuffer[barIndex];
}
//
int CopySTRSMHigh(
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,
strSMHighBuffer,
buffer,
forceClean
//
);
}
//
double GetLastSTR(
ENUM_X_DIRECTION dir,
int barIndex = 0 //
)
{
//
double result = 0;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
if (!HasDirection(dir))
{
return result;
}
//
int index = barIndex;
bool isBullish = IsBullish(dir);
//
bool canContinue = true;
while (canContinue)
{
//
double iStr = GetSTR(index);
double iState = GetSTRState(index);
//
canContinue =
isBullish
? iState < 0
: iState > 0;
if (!canContinue)
{
//
result = iStr;
break;
}
//
index++;
}
//
return result;
}
//
void Free() override
{
Cleanup(10);
}
//
bool GetConditions(
X121XSTRConditions &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 ...
//
CopyVidya(
zIndex,
loopback,
conditions.vidyaBuffer //
);
//
CopyATR(
zIndex,
loopback,
conditions.atrBuffer //
);
//
CopySTR(
zIndex,
loopback,
conditions.strBuffer //
);
//
CopySTRState(
zIndex,
loopback,
conditions.strStateBuffer //
);
//
CopySTRPrice(
zIndex,
loopback,
conditions.strPriceBuffer //
);
//
CopySTRUp(
zIndex,
loopback,
conditions.strUpBuffer //
);
//
CopySTRDown(
zIndex,
loopback,
conditions.strDownBuffer //
);
//
CopySTRSMLow(
zIndex,
loopback,
conditions.strSMLowBuffer //
);
//
CopySTRSMHigh(
zIndex,
loopback,
conditions.strSMHighBuffer //
);
//
// Conditions ...
//
int cIDX = 1;
int pIDX = cIDX + 1;
//
// STR ...
//
bool isStrBullish = strStateBuffer[cIDX] > 0;
bool isStrBullishPrev = strStateBuffer[pIDX] > 0;
//
bool isStrBearish = strStateBuffer[cIDX] < 0;
bool isStrBearishPrev = strStateBuffer[pIDX] < 0;
//
bool isStrSwitchedToBullish = isStrBullish &&
!isStrBullishPrev;
bool isStrSwitchedToBearish = isStrBearish &&
!isStrBearishPrev;
//
// VIDYA ...
//
bool isRejectUpVidya = cBar.IsRejected(
vidyaBuffer[cIDX],
X_DIRECTION_BULLISH //
);
//
bool isClosedOverVidya = cBar.close > vidyaBuffer[cIDX];
bool isClosedOverVidyaPrev = pBar.close > vidyaBuffer[pIDX];
bool isCrossedOverVidya = isClosedOverVidya &&
!isClosedOverVidyaPrev;
//
bool isRejectDownVidya = cBar.IsRejected(
vidyaBuffer[cIDX],
X_DIRECTION_BEARISH //
);
//
bool isCloseUnderVidya = cBar.close < vidyaBuffer[cIDX];
bool isCloseUnderVidyaPrev = pBar.close < vidyaBuffer[pIDX];
bool isCrossedUnderVidya = isCloseUnderVidya &&
!isCloseUnderVidyaPrev;
//
// LMS ...
//
bool isRejectUpLSM = cBar.IsRejected(
strSMLowBuffer[cIDX],
X_DIRECTION_BULLISH //
);
//
bool isCloseOverLSM = cBar.close > strSMLowBuffer[cIDX];
bool isCloseOverLSMPrev = pBar.close > strSMLowBuffer[pIDX];
bool isCrossedOverLSM = isCloseOverLSM &&
!isCloseOverLSMPrev;
//
bool isRejectDownLSM = cBar.IsRejected(
strSMLowBuffer[cIDX],
X_DIRECTION_BEARISH //
);
//
bool isCloseUnderLSM = cBar.close < strSMLowBuffer[cIDX];
bool isCloseUnderLSMPrev = pBar.close < strSMLowBuffer[pIDX];
bool isCrossedUnderLSM = isCloseUnderLSM &&
!isCloseUnderLSMPrev;
//
// HSM ..
//
bool isRejectUpHSM = cBar.IsRejected(
strSMHighBuffer[cIDX],
X_DIRECTION_BULLISH //
);
//
bool isCloseOverHSM = cBar.close > strSMHighBuffer[cIDX];
bool isCloseOverHSMPrev = pBar.close > strSMHighBuffer[pIDX];
bool isCrossedOverHSM = isCloseOverHSM &&
!isCloseOverHSMPrev;
//
bool isRejectDownHSM = cBar.IsRejected(
strSMHighBuffer[cIDX],
X_DIRECTION_BEARISH //
);
//
bool isCloseUnderHSM = cBar.close > strSMHighBuffer[cIDX];
bool isCloseUnderHSMPrev = pBar.close > strSMHighBuffer[pIDX];
bool isCrossedUnderHSM = isCloseUnderHSM &&
!isCloseUnderHSMPrev;
//
// STR ...
//
bool isRejectUpStr = cBar.IsRejected(
strBuffer[cIDX],
X_DIRECTION_BULLISH //
);
//
bool isCloseOverStr = cBar.close > strBuffer[cIDX];
bool isCloseOverStrPrev = pBar.close > strBuffer[pIDX];
bool isCrossedOverStr = isCloseOverStr &&
!isCloseOverStrPrev;
//
bool isRejectDownStr = cBar.IsRejected(
strBuffer[cIDX],
X_DIRECTION_BEARISH //
);
//
bool isCloseUnderStr = cBar.close < strBuffer[cIDX];
bool isCloseUnderStrPrev = pBar.close < strBuffer[pIDX];
bool isCrossedUnderStr = isCloseUnderStr &&
!isCloseUnderStrPrev;
//
// HSM / ViDYA ...
//
bool isVidyaOverHSM = vidyaBuffer[cIDX] > strSMHighBuffer[cIDX];
bool isVidyaOverHSMPrev = vidyaBuffer[pIDX] > strSMHighBuffer[pIDX];
bool isVidyaCrossedOverHSM = isVidyaOverHSM &&
!isVidyaOverHSMPrev;
//
bool isVidyaUnderHSM = vidyaBuffer[cIDX] < strSMHighBuffer[cIDX];
bool isVidyaUnderHSMPrev = vidyaBuffer[pIDX] < strSMHighBuffer[pIDX];
bool isVidyaCrossedUnderHSM = isVidyaUnderHSM &&
!isVidyaUnderHSMPrev;
//
// LSM / VIDYA ...
//
bool isVidyaOverLSM = vidyaBuffer[cIDX] > strSMLowBuffer[cIDX];
bool isVidyaOverLSMPrev = vidyaBuffer[pIDX] > strSMLowBuffer[pIDX];
bool isVidyaCrossedOverLSM = isVidyaOverLSM &&
!isVidyaOverLSMPrev;
//
bool isVidyaUnderLSM = vidyaBuffer[cIDX] < strSMLowBuffer[cIDX];
bool isVidyaUnderLSMPrev = vidyaBuffer[pIDX] < strSMLowBuffer[pIDX];
bool isVidyaCrossedUnderLSM = isVidyaUnderLSM &&
!isVidyaUnderLSMPrev;
//
// STR / VIDYA ...
//
bool isVidyaOverStr = vidyaBuffer[cIDX] > strBuffer[cIDX];
bool isVidyaOverStrPrev = vidyaBuffer[pIDX] > strBuffer[pIDX];
bool isVidyaCrossedOverStr = isVidyaOverStr &&
!isVidyaOverStrPrev;
//
bool isVidyaUnderStr = vidyaBuffer[cIDX] < strBuffer[cIDX];
bool isVidyaUnderStrPrev = vidyaBuffer[pIDX] < strBuffer[pIDX];
bool isVidyaCrossedUnderStr = isVidyaUnderStr &&
!isVidyaUnderStrPrev;
//
//
//
//
conditions.isStrBullish = isStrBullish;
conditions.isStrBearish = isStrBearish;
conditions.isRejectUpLSM = isRejectUpLSM;
conditions.isRejectUpHSM = isRejectUpHSM;
conditions.isRejectUpStr = isRejectUpStr;
conditions.isCloseOverHSM = isCloseOverHSM;
conditions.isCloseOverLSM = isCloseOverLSM;
conditions.isCloseOverStr = isCloseOverStr;
conditions.isVidyaOverHSM = isVidyaOverHSM;
conditions.isVidyaOverLSM = isVidyaOverLSM;
conditions.isVidyaOverStr = isVidyaOverStr;
conditions.isRejectDownLSM = isRejectDownLSM;
conditions.isRejectDownHSM = isRejectDownHSM;
conditions.isVidyaUnderStr = isVidyaUnderStr;
conditions.isVidyaUnderHSM = isVidyaUnderHSM;
conditions.isVidyaUnderLSM = isVidyaUnderLSM;
conditions.isCloseUnderStr = isCloseUnderStr;
conditions.isRejectDownStr = isRejectDownStr;
conditions.isRejectUpVidya = isRejectUpVidya;
conditions.isCloseUnderHSM = isCloseUnderHSM;
conditions.isCloseUnderLSM = isCloseUnderLSM;
conditions.isCrossedOverLSM = isCrossedOverLSM;
conditions.isCrossedOverHSM = isCrossedOverHSM;
conditions.isCrossedOverStr = isCrossedOverStr;
conditions.isCrossedUnderHSM = isCrossedUnderHSM;
conditions.isCrossedUnderLSM = isCrossedUnderLSM;
conditions.isCrossedUnderStr = isCrossedUnderStr;
conditions.isClosedOverVidya = isClosedOverVidya;
conditions.isRejectDownVidya = isRejectDownVidya;
conditions.isCloseUnderVidya = isCloseUnderVidya;
conditions.isCrossedOverVidya = isCrossedOverVidya;
conditions.isCrossedUnderVidya = isCrossedUnderVidya;
conditions.isVidyaCrossedOverHSM = isVidyaCrossedOverHSM;
conditions.isVidyaCrossedOverStr = isVidyaCrossedOverStr;
conditions.isVidyaCrossedOverLSM = isVidyaCrossedOverLSM;
conditions.isVidyaCrossedUnderHSM = isVidyaCrossedUnderHSM;
conditions.isVidyaCrossedUnderLSM = isVidyaCrossedUnderLSM;
conditions.isVidyaCrossedUnderStr = isVidyaCrossedUnderStr;
conditions.isStrSwitchedToBullish = isStrSwitchedToBullish;
conditions.isStrSwitchedToBearish = isStrSwitchedToBearish;
//
Cleanup();
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121XSTRInputs mInputs; // Inputs ...
//
// Buffers ...
double strBuffer[];
double atrBuffer[];
double vidyaBuffer[];
double strUpBuffer[];
double strDownBuffer[];
double strPriceBuffer[];
double strStateBuffer[];
double strSMLowBuffer[];
double strSMHighBuffer[];
//
void Calculate(
int barIndex = 0,
int maxRequiredBars = 100 //
)
{
//
// Buffers ...
if (barIndex < 0)
{
barIndex = 0;
}
//
// VIDYA ...
CopyBuffer(
mHandler,
X121_XSTR_XVIDYA_LINE,
barIndex,
maxRequiredBars,
vidyaBuffer
//
);
//
// STR ...
CopyBuffer(
mHandler,
X121_XSTR_LINE,
barIndex,
maxRequiredBars,
strBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
X121_XSTR_STATE_LINE,
barIndex,
maxRequiredBars,
strStateBuffer
//
);
//
// Price ...
CopyBuffer(
mHandler,
X121_XSTR_PRICE_LINE,
barIndex,
maxRequiredBars,
strPriceBuffer
//
);
//
// Up ...
CopyBuffer(
mHandler,
X121_XSTR_UP_LINE,
barIndex,
maxRequiredBars,
strUpBuffer
//
);
//
// STR ...
CopyBuffer(
mHandler,
X121_XSTR_DOWN_LINE,
barIndex,
maxRequiredBars,
strDownBuffer
//
);
//
CopyBuffer(
mHandler,
X121_XSTR_LSM_LINE,
barIndex,
maxRequiredBars,
strSMLowBuffer
//
);
//
CopyBuffer(
mHandler,
X121_XSTR_HSM_LINE,
barIndex,
maxRequiredBars,
strSMHighBuffer
//
);
//
// ATR ...
//
CopyBuffer(
mHandler,
X121_XSTR_ATR_LINE,
barIndex,
maxRequiredBars,
atrBuffer
//
);
}
//
void Cleanup(
int maxAllowed = 100 //
)
{
//
CleanupArray(
vidyaBuffer,
maxAllowed //
);
//
CleanupArray(
strBuffer,
maxAllowed //
);
//
CleanupArray(
atrBuffer,
maxAllowed //
);
//
CleanupArray(
strUpBuffer,
maxAllowed //
);
//
CleanupArray(
strDownBuffer,
maxAllowed //
);
//
CleanupArray(
strPriceBuffer,
maxAllowed //
);
//
CleanupArray(
strStateBuffer,
maxAllowed //
);
//
CleanupArray(
strSMLowBuffer,
maxAllowed //
);
//
CleanupArray(
strSMHighBuffer,
maxAllowed //
);
}
//
};
//
// Tools ...