1600 lines
36 KiB
Plaintext
1600 lines
36 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XCX121XVWAPHelper
|
|
// 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_XVWAP_BUFFERS
|
|
{
|
|
//
|
|
X121_XVWAP_FAST_LINE = 0,
|
|
X121_XVWAP_FAST_STATE_LINE = 8,
|
|
X121_XVWAP_MID_LINE = 2,
|
|
X121_XVWAP_MID_STATE_LINE = 9,
|
|
X121_XVWAP_SLOW_LINE = 4,
|
|
X121_XVWAP_SLOW_STATE_LINE = 10,
|
|
X121_XVWAP_VOLUME_LINE = 6,
|
|
X121_XVWAP_PRICE_LINE = 7,
|
|
};
|
|
|
|
//
|
|
enum ENUM_XVWAP_STATES
|
|
{
|
|
XVWAP_STATE_BULLISH = 1,
|
|
XVWAP_STATE_BEARISH = 2,
|
|
XVWAP_STATE_NEUTURAL = 3,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct X121XVWAPInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
int vwapFastLength; // Fast Length
|
|
int vwapMidLength; // Mid Length
|
|
int vwapSlowLength; // Slow Length
|
|
ENUM_APPLIED_PRICE vwapAppliedTo; // Applied To
|
|
|
|
//
|
|
int startCalculationForLastBars; // Calculate Last n Bars
|
|
|
|
//
|
|
bool showVWapFast; // Show VWap Fast
|
|
bool showVWapMedium; // Show VWap Medium
|
|
bool showVWapSlow; // Show VWap Slow
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
X121XVWAPInputs()
|
|
{
|
|
//
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Clean ...
|
|
void Clean()
|
|
{
|
|
//
|
|
vwapFastLength = 0;
|
|
vwapMidLength = 0;
|
|
vwapSlowLength = 0;
|
|
vwapAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
startCalculationForLastBars = 0;
|
|
|
|
//
|
|
showVWapFast = false;
|
|
showVWapMedium = false;
|
|
showVWapSlow = false;
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
vwapFastLength = 20;
|
|
vwapMidLength = 50;
|
|
vwapSlowLength = 200;
|
|
vwapAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
startCalculationForLastBars = 1000;
|
|
|
|
//
|
|
showVWapFast = true;
|
|
showVWapMedium = true;
|
|
showVWapSlow = true;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
vwapFastLength > 2 &&
|
|
vwapMidLength > vwapFastLength &&
|
|
vwapSlowLength > vwapMidLength
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(vwapFastLength, vwapMidLength);
|
|
result = MathMax(result, vwapSlowLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Conditions ...
|
|
struct X121XVWAPConditions
|
|
{
|
|
//
|
|
// Common ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
datetime time;
|
|
|
|
//
|
|
// Buffers ...
|
|
double vwapFastBuffer[];
|
|
double vwapMidBuffer[];
|
|
double vwapSlowBuffer[];
|
|
double vwapVolumeBuffer[];
|
|
double vwapPriceBuffer[];
|
|
double vwapFastStateBuffer[];
|
|
double vwapMidStateBuffer[];
|
|
double vwapSlowStateBuffer[];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isVWapFastBullish;
|
|
bool isVWapFastBearish;
|
|
bool isVWapFastNeutural;
|
|
|
|
//
|
|
bool isVWapMidBullish;
|
|
bool isVWapMidBearish;
|
|
bool isVWapMidNeutural;
|
|
|
|
//
|
|
bool isVWapSlowBullish;
|
|
bool isVWapSlowBearish;
|
|
bool isVWapSlowNeutural;
|
|
|
|
//
|
|
bool isVWapFastOverMid;
|
|
bool isVWapMidOverSlow;
|
|
|
|
//
|
|
bool isVWapFastUnderMid;
|
|
bool isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isVWapBullishState;
|
|
bool isVWapBearishState;
|
|
bool isVWapNeuturalState;
|
|
|
|
//
|
|
bool isVWapBullishOrdered;
|
|
bool isVWapBearishOrdered;
|
|
|
|
//
|
|
bool isVWapSwitchedToBullishOrdered;
|
|
bool isVWapSwitchedToBearishOrdered;
|
|
|
|
//
|
|
bool isVWapSwitchedToBullishState;
|
|
bool isVWapSwitchedToBearishState;
|
|
bool isVWapSwitchedToNeuturalState;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121XVWAPConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
// Commons ...
|
|
symbol = NULL;
|
|
period = NULL;
|
|
time = NULL;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
Clean(vwapFastBuffer);
|
|
Clean(vwapMidBuffer);
|
|
Clean(vwapSlowBuffer);
|
|
Clean(vwapVolumeBuffer);
|
|
Clean(vwapPriceBuffer);
|
|
Clean(vwapFastStateBuffer);
|
|
Clean(vwapMidStateBuffer);
|
|
Clean(vwapSlowStateBuffer);
|
|
|
|
//
|
|
ArraySetAsSeries(vwapFastBuffer, true);
|
|
ArraySetAsSeries(vwapMidBuffer, true);
|
|
ArraySetAsSeries(vwapSlowBuffer, true);
|
|
ArraySetAsSeries(vwapVolumeBuffer, true);
|
|
ArraySetAsSeries(vwapPriceBuffer, true);
|
|
ArraySetAsSeries(vwapFastStateBuffer, true);
|
|
ArraySetAsSeries(vwapMidStateBuffer, true);
|
|
ArraySetAsSeries(vwapSlowStateBuffer, true);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
isVWapFastBullish = false;
|
|
isVWapFastBearish = false;
|
|
isVWapFastNeutural = false;
|
|
|
|
//
|
|
isVWapMidBullish = false;
|
|
isVWapMidBearish = false;
|
|
isVWapMidNeutural = false;
|
|
|
|
//
|
|
isVWapSlowBullish = false;
|
|
isVWapSlowBearish = false;
|
|
isVWapSlowNeutural = false;
|
|
|
|
//
|
|
isVWapFastOverMid = false;
|
|
isVWapMidOverSlow = false;
|
|
|
|
//
|
|
isVWapFastUnderMid = false;
|
|
isVWapMidUnderSlow = false;
|
|
|
|
//
|
|
isVWapBullishState = false;
|
|
isVWapBearishState = false;
|
|
isVWapNeuturalState = false;
|
|
|
|
//
|
|
isVWapBullishOrdered = false;
|
|
isVWapBearishOrdered = false;
|
|
|
|
//
|
|
isVWapSwitchedToBullishOrdered = false;
|
|
isVWapSwitchedToBearishOrdered = false;
|
|
|
|
//
|
|
isVWapSwitchedToBullishState = false;
|
|
isVWapSwitchedToBearishState = false;
|
|
isVWapSwitchedToNeuturalState = 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 (isVWapBullishState)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isVWapBullishOrdered)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isVWapSwitchedToBullishState)
|
|
{
|
|
bullishScore += highScore;
|
|
}
|
|
if (isVWapSwitchedToBullishOrdered)
|
|
{
|
|
bullishScore += highScore;
|
|
}
|
|
if (!isVWapBullishState &&
|
|
!isVWapSwitchedToBullishState)
|
|
{
|
|
//
|
|
if (isVWapFastBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isVWapSlowBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
}
|
|
if (!isVWapBullishOrdered &&
|
|
!isVWapSwitchedToBullishOrdered)
|
|
{
|
|
//
|
|
if (isVWapFastOverMid)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isVWapMidOverSlow)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (isVWapBearishState)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isVWapBearishOrdered)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isVWapSwitchedToBearishState)
|
|
{
|
|
bearishScore += highScore;
|
|
}
|
|
if (isVWapSwitchedToBearishOrdered)
|
|
{
|
|
bearishScore += highScore;
|
|
}
|
|
if (!isVWapBearishState &&
|
|
!isVWapSwitchedToBearishState)
|
|
{
|
|
//
|
|
if (isVWapFastBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isVWapSlowBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
}
|
|
if (!isVWapBearishOrdered &&
|
|
!isVWapSwitchedToBearishOrdered)
|
|
{
|
|
//
|
|
if (isVWapFastUnderMid)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isVWapMidUnderSlow)
|
|
{
|
|
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 +
|
|
"XVWAP: " + separator +
|
|
"-----------------------" + separator +
|
|
ToString("isVWapFastBullish", isVWapFastBullish, ignoreFalseConditions, separator) +
|
|
ToString("isVWapFastBearish", isVWapFastBearish, ignoreFalseConditions, separator) +
|
|
ToString("isVWapFastNeutural", isVWapFastNeutural, ignoreFalseConditions, separator) +
|
|
ToString("isVWapMidBullish", isVWapMidBullish, ignoreFalseConditions, separator) +
|
|
ToString("isVWapMidBearish", isVWapMidBearish, ignoreFalseConditions, separator) +
|
|
ToString("isVWapMidNeutural", isVWapMidNeutural, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSlowBullish", isVWapSlowBullish, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSlowBearish", isVWapSlowBearish, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSlowNeutural", isVWapSlowNeutural, ignoreFalseConditions, separator) +
|
|
ToString("isVWapFastOverMid", isVWapFastOverMid, ignoreFalseConditions, separator) +
|
|
ToString("isVWapMidOverSlow", isVWapMidOverSlow, ignoreFalseConditions, separator) +
|
|
ToString("isVWapFastUnderMid", isVWapFastUnderMid, ignoreFalseConditions, separator) +
|
|
ToString("isVWapMidUnderSlow", isVWapMidUnderSlow, ignoreFalseConditions, separator) +
|
|
ToString("isVWapBullishState", isVWapBullishState, ignoreFalseConditions, separator) +
|
|
ToString("isVWapBearishState", isVWapBearishState, ignoreFalseConditions, separator) +
|
|
ToString("isVWapNeuturalState", isVWapNeuturalState, ignoreFalseConditions, separator) +
|
|
ToString("isVWapBullishOrdered", isVWapBullishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("isVWapBearishOrdered", isVWapBearishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSwitchedToBullishOrdered", isVWapSwitchedToBullishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSwitchedToBearishOrdered", isVWapSwitchedToBearishOrdered, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSwitchedToBullishState", isVWapSwitchedToBullishState, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSwitchedToBearishState", isVWapSwitchedToBearishState, ignoreFalseConditions, separator) +
|
|
ToString("isVWapSwitchedToNeuturalState", isVWapSwitchedToNeuturalState, 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 XCX121XVWAPHelper : public XCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XCX121XVWAPHelper()
|
|
: XCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121XVWAPHelper()
|
|
{
|
|
//
|
|
mInputs.Clean();
|
|
|
|
//
|
|
Clean(vwapFastBuffer);
|
|
Clean(vwapMidBuffer);
|
|
Clean(vwapSlowBuffer);
|
|
Clean(vwapVolumeBuffer);
|
|
Clean(vwapPriceBuffer);
|
|
Clean(vwapFastStateBuffer);
|
|
Clean(vwapMidStateBuffer);
|
|
Clean(vwapSlowStateBuffer);
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
X121XVWAPInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ArraySetAsSeries(vwapFastBuffer, true);
|
|
ArraySetAsSeries(vwapMidBuffer, true);
|
|
ArraySetAsSeries(vwapSlowBuffer, true);
|
|
ArraySetAsSeries(vwapVolumeBuffer, true);
|
|
ArraySetAsSeries(vwapPriceBuffer, true);
|
|
ArraySetAsSeries(vwapFastStateBuffer, true);
|
|
ArraySetAsSeries(vwapMidStateBuffer, true);
|
|
ArraySetAsSeries(vwapSlowStateBuffer, true);
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.x121.xvwap",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Market ...
|
|
"",
|
|
mInputs.vwapFastLength,
|
|
mInputs.vwapMidLength,
|
|
mInputs.vwapSlowLength,
|
|
mInputs.vwapAppliedTo,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
//
|
|
mInputs.startCalculationForLastBars,
|
|
//
|
|
mInputs.showVWapFast,
|
|
mInputs.showVWapMedium,
|
|
mInputs.showVWapSlow
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
X121XVWAPInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
X121XVWAPInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Readers ...
|
|
|
|
//
|
|
double GetVWapFast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapFastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapFastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapFast(
|
|
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,
|
|
vwapFastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// STATE FAST ...
|
|
|
|
//
|
|
double GetVWapFastState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapFastStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapFastStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapFastState(
|
|
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,
|
|
vwapFastStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// MID ...
|
|
|
|
//
|
|
double GetVWapMid(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapMidBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapMidBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapMid(
|
|
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,
|
|
vwapMidBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// STATE MID ...
|
|
|
|
//
|
|
double GetVWapMidState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapMidStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapMidStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapMidState(
|
|
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,
|
|
vwapMidStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// SLOW ...
|
|
|
|
//
|
|
double GetVWapSlowBuffer(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapSlowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapSlowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapSlow(
|
|
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,
|
|
vwapSlowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// STATE SLOW ...
|
|
|
|
//
|
|
double GetVWapSlowState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapSlowStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapSlowStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapSlowState(
|
|
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,
|
|
vwapSlowStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// VOLUME ...
|
|
|
|
//
|
|
double GetVWapVolume(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapVolumeBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapVolumeBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapVolume(
|
|
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,
|
|
vwapVolumeBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// PRICE ...
|
|
|
|
//
|
|
double GetVWapPrice(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(vwapPriceBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return vwapPriceBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyVWapPrice(
|
|
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,
|
|
vwapPriceBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Converts to State ...
|
|
ENUM_XVWAP_STATES ToVWAPState(double value)
|
|
{
|
|
//
|
|
ENUM_XVWAP_STATES result =
|
|
value == 1
|
|
? XVWAP_STATE_BULLISH
|
|
: value == 2
|
|
? XVWAP_STATE_BEARISH
|
|
: XVWAP_STATE_NEUTURAL;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool IsVWAPBullish(double value)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = ToVWAPState(value) == XVWAP_STATE_BULLISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool IsVWAPBearish(double value)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = ToVWAPState(value) == XVWAP_STATE_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool IsVWAPNeutural(double value)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = ToVWAPState(value) == XVWAP_STATE_NEUTURAL;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void Free() override
|
|
{
|
|
Cleanup(10);
|
|
}
|
|
|
|
//
|
|
bool GetConditions(
|
|
X121XVWAPConditions &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 ...
|
|
|
|
//
|
|
CopyVWapFast(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapFastBuffer //
|
|
);
|
|
|
|
//
|
|
CopyVWapFastState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapFastStateBuffer //
|
|
);
|
|
|
|
//
|
|
CopyVWapMid(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapMidBuffer //
|
|
);
|
|
|
|
//
|
|
CopyVWapMidState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapMidStateBuffer //
|
|
);
|
|
|
|
//
|
|
CopyVWapSlow(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapSlowBuffer //
|
|
);
|
|
|
|
//
|
|
CopyVWapSlowState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapSlowStateBuffer //
|
|
);
|
|
|
|
//
|
|
CopyVWapVolume(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapVolumeBuffer //
|
|
);
|
|
|
|
//
|
|
CopyVWapPrice(
|
|
zIndex,
|
|
loopback,
|
|
conditions.vwapPriceBuffer //
|
|
);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
int cIDX = 1;
|
|
int pIDX = cIDX + 1;
|
|
|
|
//
|
|
// SAR ...
|
|
|
|
//
|
|
bool isVWapFastBullish = IsVWAPBullish(conditions.vwapFastStateBuffer[cIDX]);
|
|
bool isVWapFastBullishPrev = IsVWAPBullish(conditions.vwapFastStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapFastBearish = IsVWAPBearish(conditions.vwapFastStateBuffer[cIDX]);
|
|
bool isVWapFastBearishPrev = IsVWAPBearish(conditions.vwapFastStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapFastNeutural = IsVWAPNeutural(conditions.vwapFastStateBuffer[cIDX]);
|
|
bool isVWapFastNeuturalPrev = IsVWAPNeutural(conditions.vwapFastStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapMidBullish = IsVWAPBullish(conditions.vwapMidStateBuffer[cIDX]);
|
|
bool isVWapMidBullishPrev = IsVWAPBullish(conditions.vwapMidStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapMidBearish = IsVWAPBearish(conditions.vwapMidStateBuffer[cIDX]);
|
|
bool isVWapMidBearishPrev = IsVWAPBearish(conditions.vwapMidStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapMidNeutural = IsVWAPNeutural(conditions.vwapMidStateBuffer[cIDX]);
|
|
bool isVWapMidNeuturalPrev = IsVWAPNeutural(conditions.vwapMidStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapSlowBullish = IsVWAPBullish(conditions.vwapSlowStateBuffer[cIDX]);
|
|
bool isVWapSlowBullishPrev = IsVWAPBullish(conditions.vwapSlowStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapSlowBearish = IsVWAPBearish(conditions.vwapSlowStateBuffer[cIDX]);
|
|
bool isVWapSlowBearishPrev = IsVWAPBearish(conditions.vwapSlowStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapSlowNeutural = IsVWAPNeutural(conditions.vwapSlowStateBuffer[cIDX]);
|
|
bool isVWapSlowNeuturalPrev = IsVWAPNeutural(conditions.vwapSlowStateBuffer[pIDX]);
|
|
|
|
//
|
|
bool isVWapFastOverMid = conditions.vwapFastBuffer[cIDX] > conditions.vwapMidBuffer[cIDX];
|
|
bool isVWapFastOverMidPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapMidBuffer[pIDX];
|
|
|
|
//
|
|
bool isVWapMidOverSlow = conditions.vwapMidBuffer[cIDX] > conditions.vwapSlowBuffer[cIDX];
|
|
bool isVWapMidOverSlowPrev = conditions.vwapMidBuffer[pIDX] > conditions.vwapSlowBuffer[pIDX];
|
|
|
|
//
|
|
bool isVWapFastUnderMid = conditions.vwapFastBuffer[cIDX] < conditions.vwapMidBuffer[cIDX];
|
|
bool isVWapFastUnderMidPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapMidBuffer[pIDX];
|
|
|
|
//
|
|
bool isVWapMidUnderSlow = conditions.vwapMidBuffer[cIDX] < conditions.vwapSlowBuffer[cIDX];
|
|
bool isVWapMidUnderSlowPrev = conditions.vwapMidBuffer[pIDX] < conditions.vwapSlowBuffer[pIDX];
|
|
|
|
//
|
|
bool isVWapBullishState = isVWapFastBullish &&
|
|
isVWapMidBullish &&
|
|
isVWapSlowBullish;
|
|
bool isVWapBullishStatePrev = isVWapFastBullishPrev &&
|
|
isVWapMidBullishPrev &&
|
|
isVWapSlowBullishPrev;
|
|
|
|
//
|
|
bool isVWapBearishState = isVWapFastBearish &&
|
|
isVWapMidBearish &&
|
|
isVWapSlowBearish;
|
|
bool isVWapBearishStatePrev = isVWapFastBearishPrev &&
|
|
isVWapMidBearishPrev &&
|
|
isVWapSlowBearishPrev;
|
|
|
|
//
|
|
bool isVWapNeuturalState = isVWapFastNeutural &&
|
|
isVWapMidNeutural &&
|
|
isVWapSlowNeutural;
|
|
bool isVWapNeuturalStatePrev = isVWapFastNeuturalPrev &&
|
|
isVWapMidNeuturalPrev &&
|
|
isVWapSlowNeuturalPrev;
|
|
|
|
//
|
|
bool isVWapBullishOrdered = isVWapFastOverMid &&
|
|
isVWapMidOverSlow;
|
|
bool isVWapBullishOrderedPrev = isVWapFastOverMidPrev &&
|
|
isVWapMidOverSlowPrev;
|
|
|
|
//
|
|
bool isVWapBearishOrdered = isVWapFastUnderMid &&
|
|
isVWapMidUnderSlow;
|
|
bool isVWapBearishOrderedPrev = isVWapFastUnderMidPrev &&
|
|
isVWapMidUnderSlowPrev;
|
|
|
|
//
|
|
bool isVWapSwitchedToBullishOrdered = isVWapBullishOrdered &&
|
|
!isVWapBullishOrderedPrev;
|
|
bool isVWapSwitchedToBearishOrdered = isVWapBearishOrdered &&
|
|
!isVWapBearishOrderedPrev;
|
|
|
|
//
|
|
bool isVWapSwitchedToBullishState = isVWapBullishState &&
|
|
!isVWapBullishStatePrev;
|
|
bool isVWapSwitchedToBearishState = isVWapBearishState &&
|
|
!isVWapBearishStatePrev;
|
|
bool isVWapSwitchedToNeuturalState = isVWapNeuturalState &&
|
|
!isVWapNeuturalStatePrev;
|
|
|
|
//
|
|
conditions.isVWapFastBullish = isVWapFastBullish;
|
|
conditions.isVWapFastBearish = isVWapFastBearish;
|
|
conditions.isVWapFastNeutural = isVWapFastNeutural;
|
|
conditions.isVWapMidBullish = isVWapMidBullish;
|
|
conditions.isVWapMidBearish = isVWapMidBearish;
|
|
conditions.isVWapMidNeutural = isVWapMidNeutural;
|
|
conditions.isVWapSlowBullish = isVWapSlowBullish;
|
|
conditions.isVWapSlowBearish = isVWapSlowBearish;
|
|
conditions.isVWapSlowNeutural = isVWapSlowNeutural;
|
|
conditions.isVWapFastOverMid = isVWapFastOverMid;
|
|
conditions.isVWapMidOverSlow = isVWapMidOverSlow;
|
|
conditions.isVWapFastUnderMid = isVWapFastUnderMid;
|
|
conditions.isVWapMidUnderSlow = isVWapMidUnderSlow;
|
|
conditions.isVWapBullishState = isVWapBullishState;
|
|
conditions.isVWapBearishState = isVWapBearishState;
|
|
conditions.isVWapNeuturalState = isVWapNeuturalState;
|
|
conditions.isVWapBullishOrdered = isVWapBullishOrdered;
|
|
conditions.isVWapBearishOrdered = isVWapBearishOrdered;
|
|
conditions.isVWapSwitchedToBullishOrdered = isVWapSwitchedToBullishOrdered;
|
|
conditions.isVWapSwitchedToBearishOrdered = isVWapSwitchedToBearishOrdered;
|
|
conditions.isVWapSwitchedToBullishState = isVWapSwitchedToBullishState;
|
|
conditions.isVWapSwitchedToBearishState = isVWapSwitchedToBearishState;
|
|
conditions.isVWapSwitchedToNeuturalState = isVWapSwitchedToNeuturalState;
|
|
|
|
//
|
|
Cleanup();
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
X121XVWAPInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
double vwapFastBuffer[];
|
|
double vwapMidBuffer[];
|
|
double vwapSlowBuffer[];
|
|
double vwapVolumeBuffer[];
|
|
double vwapPriceBuffer[];
|
|
double vwapFastStateBuffer[];
|
|
double vwapMidStateBuffer[];
|
|
double vwapSlowStateBuffer[];
|
|
|
|
//
|
|
void Calculate(
|
|
int maxRequiredBars = 100 //
|
|
)
|
|
{
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
// FAST ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_FAST_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapFastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// FAST STATE ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_FAST_STATE_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapFastStateBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// MID ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_MID_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapMidBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// MID STATE ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_MID_STATE_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapMidStateBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// SLOW ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_SLOW_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapSlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// SLOW STATE ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_SLOW_STATE_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapSlowStateBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// VOLUME ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_VOLUME_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapVolumeBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// PRICE ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XVWAP_PRICE_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
vwapPriceBuffer
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
void Cleanup(
|
|
int maxAllowed = 100 //
|
|
)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
vwapFastBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
vwapMidBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
vwapSlowBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
vwapVolumeBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
vwapPriceBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
vwapFastStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
vwapMidStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
vwapSlowStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Tools ... |