1159 lines
29 KiB
Plaintext
1159 lines
29 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XCX121XVOLUMESHelper
|
|
// 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 ...
|
|
enum ENUM_X121_XVOLUME_BUFFERS
|
|
{
|
|
//
|
|
X121_XVOLUME_BULLISH_LINE = 0,
|
|
X121_XVOLUME_BULLISH_MA_LINE = 1,
|
|
X121_XVOLUME_BEARISH_LINE = 2,
|
|
X121_XVOLUME_BEARISH_MA_LINE = 3,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct X121XVOLUMEInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Makret ...
|
|
int maLength; // Moving Averge Length
|
|
ENUM_X_MA_METHOD maMethod; // Moving Averge Method
|
|
|
|
//
|
|
// Presentation ...
|
|
int startCalculationForLastBars; // Calculate Last n Bars
|
|
bool showBullishVolume; // Show Bullish Volume
|
|
bool showBullishVolumeMa; // Show Bullish Volume Moving Average
|
|
bool showBearishVolume; // Show Bearish Volume
|
|
bool showBearishVolumeMa; // Show Bearish Volume Moving Average
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
X121XVOLUMEInputs()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleanup Model ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
// Makret ...
|
|
maLength = 0; // Moving Averge Length
|
|
maMethod = X_MA_MODE_NONE; // Moving Averge Method
|
|
|
|
//
|
|
// Presentation ...
|
|
startCalculationForLastBars = 0; // Calculate Last n Bars
|
|
showBullishVolume = false; // Show Bullish Volume
|
|
showBullishVolumeMa = false; // Show Bullish Volume Moving Average
|
|
showBearishVolume = false; // Show Bearish Volume
|
|
showBearishVolumeMa = false; // Show Bearish Volume Moving Average
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
/**
|
|
* Default Inputs ...
|
|
*/
|
|
void Default()
|
|
{
|
|
//
|
|
// Makret ...
|
|
maLength = 14; // Moving Averge Length
|
|
maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
|
|
|
//
|
|
// Presentation ...
|
|
startCalculationForLastBars = 1000; // Calculate Last n Bars
|
|
showBullishVolume = true; // Show Bullish Volume
|
|
showBullishVolumeMa = true; // Show Bullish Volume Moving Average
|
|
showBearishVolume = true; // Show Bearish Volume
|
|
showBearishVolumeMa = true; // Show Bearish Volume Moving Average
|
|
}
|
|
|
|
/**
|
|
* Validate Model ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
maLength > 0 &&
|
|
IsValid(maMethod)
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Retrieve Max Input Length ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(result, maLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Conditions ...
|
|
struct X121XVOLUMEConditions
|
|
{
|
|
//
|
|
// Common ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
datetime time;
|
|
|
|
//
|
|
// Buffers ...
|
|
double bullishVolumeBuffer[];
|
|
double bullishVolumeMaBuffer[];
|
|
double bearishVolumeBuffer[];
|
|
double bearishVolumeMaBuffer[];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isBullishVolumeOverMa;
|
|
bool isBullishVolumeCrossedOverMa;
|
|
|
|
//
|
|
bool isBullishVolumeUnderMa;
|
|
bool isBullishVolumeCrossedUnderMa;
|
|
|
|
//
|
|
bool isBullishVolumeIncreased;
|
|
bool isBullishVolumeSwitchedToIncreased;
|
|
|
|
//
|
|
bool isBullishVolumeDecreased;
|
|
bool isBullishVolumeSwitchedToDecreased;
|
|
|
|
//
|
|
bool isBearishVolumeOverMa;
|
|
bool isBearishVolumeCrossedOverMa;
|
|
|
|
//
|
|
bool isBearishVolumeUnderMa;
|
|
bool isBearishVolumeCrossedUnderMa;
|
|
|
|
//
|
|
bool isBearishVolumeIncreased;
|
|
bool isBearishVolumeSwitchedToIncreased;
|
|
|
|
//
|
|
bool isBearishVolumeDecreased;
|
|
bool isBearishVolumeSwitchedToDecreased;
|
|
|
|
//
|
|
bool isVolumeSwitchedToBullish;
|
|
bool isVolumeSwitchedToBearish;
|
|
bool isBullishVolumeMaOverBearishVolumeMa;
|
|
bool isBullishVolumeMaUnderBearishVolumeMa;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121XVOLUMEConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
// Commons ...
|
|
time = NULL;
|
|
symbol = NULL;
|
|
period = NULL;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
Clean(bullishVolumeBuffer);
|
|
Clean(bullishVolumeMaBuffer);
|
|
Clean(bearishVolumeBuffer);
|
|
Clean(bearishVolumeMaBuffer);
|
|
|
|
//
|
|
ArraySetAsSeries(bullishVolumeBuffer, true);
|
|
ArraySetAsSeries(bullishVolumeMaBuffer, true);
|
|
ArraySetAsSeries(bearishVolumeBuffer, true);
|
|
ArraySetAsSeries(bearishVolumeMaBuffer, true);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
isBullishVolumeOverMa = false;
|
|
isBullishVolumeCrossedOverMa = false;
|
|
|
|
//
|
|
isBullishVolumeUnderMa = false;
|
|
isBullishVolumeCrossedUnderMa = false;
|
|
|
|
//
|
|
isBullishVolumeIncreased = false;
|
|
isBullishVolumeSwitchedToIncreased = false;
|
|
|
|
//
|
|
isBullishVolumeDecreased = false;
|
|
isBullishVolumeSwitchedToDecreased = false;
|
|
|
|
//
|
|
isBearishVolumeOverMa = false;
|
|
isBearishVolumeCrossedOverMa = false;
|
|
|
|
//
|
|
isBearishVolumeUnderMa = false;
|
|
isBearishVolumeCrossedUnderMa = false;
|
|
|
|
//
|
|
isBearishVolumeIncreased = false;
|
|
isBearishVolumeSwitchedToIncreased = false;
|
|
|
|
//
|
|
isBearishVolumeDecreased = false;
|
|
isBearishVolumeSwitchedToDecreased = false;
|
|
|
|
//
|
|
isVolumeSwitchedToBullish = false;
|
|
isVolumeSwitchedToBearish = false;
|
|
isBullishVolumeMaOverBearishVolumeMa = false;
|
|
isBullishVolumeMaUnderBearishVolumeMa = 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 (isBullishVolumeOverMa)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isBearishVolumeUnderMa)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isBullishVolumeIncreased)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isBearishVolumeDecreased)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isBullishVolumeMaOverBearishVolumeMa)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
|
|
//
|
|
if (isVolumeSwitchedToBullish)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isBullishVolumeCrossedOverMa)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isBearishVolumeCrossedUnderMa)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isBullishVolumeSwitchedToIncreased)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isBearishVolumeSwitchedToDecreased)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
|
|
//
|
|
if (isBearishVolumeOverMa)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isBullishVolumeUnderMa)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isBullishVolumeDecreased)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isBearishVolumeIncreased)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isBullishVolumeMaUnderBearishVolumeMa)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
|
|
//
|
|
if (isVolumeSwitchedToBearish)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isBearishVolumeCrossedOverMa)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isBullishVolumeCrossedUnderMa)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isBullishVolumeSwitchedToDecreased)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isBearishVolumeSwitchedToIncreased)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 +
|
|
"XVOLUME: " + separator +
|
|
"-----------------------" + separator +
|
|
ToString("isBullishVolumeOverMa", isBullishVolumeOverMa, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeCrossedOverMa", isBullishVolumeCrossedOverMa, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeUnderMa", isBullishVolumeUnderMa, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeCrossedUnderMa", isBullishVolumeCrossedUnderMa, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeIncreased", isBullishVolumeIncreased, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeSwitchedToIncreased", isBullishVolumeSwitchedToIncreased, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeDecreased", isBullishVolumeDecreased, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeSwitchedToDecreased", isBullishVolumeSwitchedToDecreased, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeOverMa", isBearishVolumeOverMa, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeCrossedOverMa", isBearishVolumeCrossedOverMa, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeUnderMa", isBearishVolumeUnderMa, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeCrossedUnderMa", isBearishVolumeCrossedUnderMa, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeIncreased", isBearishVolumeIncreased, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeSwitchedToIncreased", isBearishVolumeSwitchedToIncreased, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeDecreased", isBearishVolumeDecreased, ignoreFalseConditions, separator) +
|
|
ToString("isBearishVolumeSwitchedToDecreased", isBearishVolumeSwitchedToDecreased, ignoreFalseConditions, separator) +
|
|
ToString("isVolumeSwitchedToBullish", isVolumeSwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("isVolumeSwitchedToBearish", isVolumeSwitchedToBearish, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeMaOverBearishVolumeMa", isBullishVolumeMaOverBearishVolumeMa, ignoreFalseConditions, separator) +
|
|
ToString("isBullishVolumeMaUnderBearishVolumeMa", isBullishVolumeMaUnderBearishVolumeMa, 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 XCX121XVOLUMEHelper : public XCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XCX121XVOLUMEHelper()
|
|
: XCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121XVOLUMEHelper()
|
|
{
|
|
//
|
|
mInputs.Clean();
|
|
|
|
//
|
|
Clean(bullishVolumeBuffer);
|
|
Clean(bullishVolumeMaBuffer);
|
|
Clean(bearishVolumeBuffer);
|
|
Clean(bearishVolumeMaBuffer);
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
X121XVOLUMEInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ArraySetAsSeries(bullishVolumeBuffer, true);
|
|
ArraySetAsSeries(bullishVolumeMaBuffer, true);
|
|
ArraySetAsSeries(bearishVolumeBuffer, true);
|
|
ArraySetAsSeries(bearishVolumeMaBuffer, true);
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.x121.xvolume",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Market ...
|
|
"",
|
|
mInputs.maLength,
|
|
mInputs.maMethod,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
//
|
|
mInputs.startCalculationForLastBars,
|
|
mInputs.showBullishVolume,
|
|
mInputs.showBullishVolumeMa,
|
|
mInputs.showBearishVolume,
|
|
mInputs.showBearishVolumeMa
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
X121XVOLUMEInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
X121XVOLUMEInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Readers ...
|
|
|
|
//
|
|
// Bullish ...
|
|
|
|
//
|
|
double GetBullishVolume(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(bullishVolumeBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return bullishVolumeBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyBullishVolume(
|
|
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,
|
|
bullishVolumeBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetBullishVolumeMa(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(bullishVolumeMaBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return bullishVolumeMaBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyBullishVolumeMa(
|
|
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,
|
|
bullishVolumeMaBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Bearish ...
|
|
|
|
//
|
|
double GetBearishVolume(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(bearishVolumeBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return bearishVolumeBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyBearishVolume(
|
|
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,
|
|
bearishVolumeBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetBearishVolumeMa(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(bearishVolumeMaBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return bearishVolumeMaBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyBearishVolumeMa(
|
|
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,
|
|
bearishVolumeMaBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
bool GetConditions(
|
|
X121XVOLUMEConditions &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 ...
|
|
|
|
//
|
|
CopyBullishVolume(
|
|
zIndex,
|
|
loopback,
|
|
conditions.bullishVolumeBuffer //
|
|
);
|
|
|
|
//
|
|
CopyBullishVolumeMa(
|
|
zIndex,
|
|
loopback,
|
|
conditions.bullishVolumeMaBuffer //
|
|
);
|
|
|
|
//
|
|
CopyBearishVolume(
|
|
zIndex,
|
|
loopback,
|
|
conditions.bearishVolumeBuffer //
|
|
);
|
|
|
|
//
|
|
CopyBearishVolumeMa(
|
|
zIndex,
|
|
loopback,
|
|
conditions.bearishVolumeMaBuffer //
|
|
);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
int cIDX = 1;
|
|
int pIDX = cIDX + 1;
|
|
int pPIDX = pIDX + 1;
|
|
|
|
//
|
|
bool isBullishVolumeOverMa = conditions.bullishVolumeBuffer[cIDX] > conditions.bullishVolumeMaBuffer[cIDX];
|
|
bool isBullishVolumeOverMaP = conditions.bullishVolumeBuffer[pIDX] > conditions.bullishVolumeMaBuffer[pIDX];
|
|
bool isBullishVolumeCrossedOverMa = isBullishVolumeOverMa &&
|
|
!isBullishVolumeOverMaP;
|
|
|
|
//
|
|
bool isBullishVolumeUnderMa = conditions.bullishVolumeBuffer[cIDX] < conditions.bullishVolumeMaBuffer[cIDX];
|
|
bool isBullishVolumeUnderMaP = conditions.bullishVolumeBuffer[pIDX] < conditions.bullishVolumeMaBuffer[pIDX];
|
|
bool isBullishVolumeCrossedUnderMa = isBullishVolumeUnderMa &&
|
|
!isBullishVolumeUnderMaP;
|
|
|
|
//
|
|
bool isBullishVolumeIncreased = conditions.bullishVolumeBuffer[cIDX] > conditions.bullishVolumeBuffer[pIDX];
|
|
bool isBullishVolumeIncreasedP = conditions.bullishVolumeBuffer[pIDX] > conditions.bullishVolumeBuffer[pPIDX];
|
|
bool isBullishVolumeSwitchedToIncreased = isBullishVolumeIncreased &&
|
|
!isBullishVolumeIncreasedP;
|
|
|
|
//
|
|
bool isBullishVolumeDecreased = conditions.bullishVolumeBuffer[cIDX] < conditions.bullishVolumeBuffer[pIDX];
|
|
bool isBullishVolumeDecreasedP = conditions.bullishVolumeBuffer[pIDX] < conditions.bullishVolumeBuffer[pPIDX];
|
|
bool isBullishVolumeSwitchedToDecreased = isBullishVolumeDecreased &&
|
|
!isBullishVolumeDecreasedP;
|
|
|
|
//
|
|
bool isBearishVolumeOverMa = conditions.bearishVolumeBuffer[cIDX] > conditions.bearishVolumeMaBuffer[cIDX];
|
|
bool isBearishVolumeOverMaP = conditions.bearishVolumeBuffer[pIDX] > conditions.bearishVolumeMaBuffer[pIDX];
|
|
bool isBearishVolumeCrossedOverMa = isBearishVolumeOverMa &&
|
|
!isBearishVolumeOverMaP;
|
|
|
|
//
|
|
bool isBearishVolumeUnderMa = conditions.bearishVolumeBuffer[cIDX] < conditions.bearishVolumeMaBuffer[cIDX];
|
|
bool isBearishVolumeUnderMaP = conditions.bearishVolumeBuffer[pIDX] < conditions.bearishVolumeMaBuffer[pIDX];
|
|
bool isBearishVolumeCrossedUnderMa = isBearishVolumeUnderMa &&
|
|
!isBearishVolumeUnderMaP;
|
|
|
|
//
|
|
bool isBearishVolumeIncreased = conditions.bearishVolumeBuffer[cIDX] > conditions.bearishVolumeBuffer[pIDX];
|
|
bool isBearishVolumeIncreasedP = conditions.bearishVolumeBuffer[pIDX] > conditions.bearishVolumeBuffer[pPIDX];
|
|
bool isBearishVolumeSwitchedToIncreased = isBearishVolumeIncreased &&
|
|
!isBearishVolumeIncreasedP;
|
|
|
|
//
|
|
bool isBearishVolumeDecreased = conditions.bearishVolumeBuffer[cIDX] < conditions.bearishVolumeBuffer[pIDX];
|
|
bool isBearishVolumeDecreasedP = conditions.bearishVolumeBuffer[pIDX] < conditions.bearishVolumeBuffer[pPIDX];
|
|
bool isBearishVolumeSwitchedToDecreased = isBearishVolumeDecreased &&
|
|
!isBearishVolumeDecreasedP;
|
|
|
|
//
|
|
bool isBullishVolumeMaOverBearishVolumeMa = conditions.bullishVolumeMaBuffer[cIDX] > conditions.bearishVolumeMaBuffer[cIDX];
|
|
bool isBullishVolumeMaOverBearishVolumeMaP = conditions.bullishVolumeMaBuffer[pIDX] > conditions.bearishVolumeMaBuffer[pIDX];
|
|
bool isVolumeSwitchedToBullish = isBullishVolumeMaOverBearishVolumeMa &&
|
|
!isBullishVolumeMaOverBearishVolumeMaP;
|
|
|
|
//
|
|
bool isBullishVolumeMaUnderBearishVolumeMa = conditions.bullishVolumeMaBuffer[cIDX] < conditions.bearishVolumeMaBuffer[cIDX];
|
|
bool isBullishVolumeMaUnderBearishVolumeMaP = conditions.bullishVolumeMaBuffer[pIDX] < conditions.bearishVolumeMaBuffer[pIDX];
|
|
bool isVolumeSwitchedToBearish = isBullishVolumeMaUnderBearishVolumeMa &&
|
|
!isBullishVolumeMaUnderBearishVolumeMaP;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
conditions.isBullishVolumeOverMa = isBullishVolumeOverMa;
|
|
conditions.isBullishVolumeCrossedOverMa = isBullishVolumeCrossedOverMa;
|
|
|
|
//
|
|
conditions.isBullishVolumeUnderMa = isBullishVolumeUnderMa;
|
|
conditions.isBullishVolumeCrossedUnderMa = isBullishVolumeCrossedUnderMa;
|
|
|
|
//
|
|
conditions.isBullishVolumeIncreased = isBullishVolumeIncreased;
|
|
conditions.isBullishVolumeSwitchedToIncreased = isBullishVolumeSwitchedToIncreased;
|
|
|
|
//
|
|
conditions.isBullishVolumeDecreased = isBullishVolumeDecreased;
|
|
conditions.isBullishVolumeSwitchedToDecreased = isBullishVolumeSwitchedToDecreased;
|
|
|
|
//
|
|
conditions.isBearishVolumeOverMa = isBearishVolumeOverMa;
|
|
conditions.isBearishVolumeCrossedOverMa = isBearishVolumeCrossedOverMa;
|
|
|
|
//
|
|
conditions.isBearishVolumeUnderMa = isBearishVolumeUnderMa;
|
|
conditions.isBearishVolumeCrossedUnderMa = isBearishVolumeCrossedUnderMa;
|
|
|
|
//
|
|
conditions.isBearishVolumeIncreased = isBearishVolumeIncreased;
|
|
conditions.isBearishVolumeSwitchedToIncreased = isBearishVolumeSwitchedToIncreased;
|
|
|
|
//
|
|
conditions.isBearishVolumeDecreased = isBearishVolumeDecreased;
|
|
conditions.isBearishVolumeSwitchedToDecreased = isBearishVolumeSwitchedToDecreased;
|
|
|
|
//
|
|
conditions.isVolumeSwitchedToBullish = isVolumeSwitchedToBullish;
|
|
conditions.isVolumeSwitchedToBearish = isVolumeSwitchedToBearish;
|
|
conditions.isBullishVolumeMaOverBearishVolumeMa = isBullishVolumeMaOverBearishVolumeMa;
|
|
conditions.isBullishVolumeMaUnderBearishVolumeMa = isBullishVolumeMaUnderBearishVolumeMa;
|
|
|
|
//
|
|
Cleanup();
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
X121XVOLUMEInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
double bullishVolumeBuffer[];
|
|
double bullishVolumeMaBuffer[];
|
|
double bearishVolumeBuffer[];
|
|
double bearishVolumeMaBuffer[];
|
|
|
|
//
|
|
void Calculate(
|
|
int barIndex = 0,
|
|
int maxRequiredBars = 100 //
|
|
)
|
|
{
|
|
//
|
|
// Buffers ...
|
|
if (barIndex < 0) {
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVOLUME_BULLISH_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
bullishVolumeBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVOLUME_BULLISH_MA_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
bullishVolumeMaBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVOLUME_BEARISH_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
bearishVolumeBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVOLUME_BEARISH_MA_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
bearishVolumeMaBuffer
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
void Cleanup(
|
|
int maxAllowed = 100 //
|
|
)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
bullishVolumeBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
bullishVolumeMaBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
bearishVolumeBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
bearishVolumeMaBuffer,
|
|
maxAllowed //
|
|
);
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|