last works ...
This commit is contained in:
@@ -0,0 +1,551 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXVLMHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XVLM_BUFFERS
|
||||
{
|
||||
XVLM_VOLUME_LINE = 0
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XVLMInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
int length; // Length
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XVLMInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
length = 14;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 1
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XVLMConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double volume[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isVolumeBullish;
|
||||
bool isVolumeBearish;
|
||||
bool isVolumeOverLast;
|
||||
bool isVolumeUnderLast;
|
||||
bool isVolumeChangedToBullish;
|
||||
bool isVolumeChangedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(volume);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(volume, true);
|
||||
|
||||
//
|
||||
isVolumeBullish = false;
|
||||
isVolumeBearish = false;
|
||||
isVolumeOverLast = false;
|
||||
isVolumeUnderLast = false;
|
||||
isVolumeChangedToBullish = false;
|
||||
isVolumeChangedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isVolumeBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isVolumeOverLast)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isVolumeChangedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isVolumeBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isVolumeUnderLast)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isVolumeChangedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
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 =
|
||||
//
|
||||
ToString("isVolumeBullish", isVolumeBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeBearish", isVolumeBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeOverLast", isVolumeOverLast, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeUnderLast", isVolumeUnderLast, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeChangedToBullish", isVolumeChangedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeChangedToBearish", isVolumeChangedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XVLM";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXVLMHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXVLMHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXVLMHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XVLMInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xvlm",
|
||||
//
|
||||
// Inputs ...
|
||||
mInputs.length // Length
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XVLMInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XVLMInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
|
||||
//
|
||||
double GetVolume(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return volumeBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Buffer ...
|
||||
int CopyVolume(
|
||||
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,
|
||||
volumeBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
bool IsBullish(double volume)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
volume > 0;
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsBearish(double volume)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
volume < 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XVLMConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 4 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 4)
|
||||
{
|
||||
loopback = 4;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
CopyVolume(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.volume //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isVolumeBullish = conditions.volume[cIndex] > 0;
|
||||
bool isVolumeBullishPrev = conditions.volume[pIndex] > 0;
|
||||
|
||||
//
|
||||
bool isVolumeBearish = conditions.volume[cIndex] < 0;
|
||||
bool isVolumeBearishPrev = conditions.volume[pIndex] < 0;
|
||||
|
||||
//
|
||||
bool isVolumeOverLast = conditions.volume[cIndex] > conditions.volume[pIndex];
|
||||
bool isVolumeOverLastPrev = conditions.volume[pIndex] > conditions.volume[ppIndex];
|
||||
|
||||
//
|
||||
bool isVolumeUnderLast = conditions.volume[cIndex] < conditions.volume[pIndex];
|
||||
bool isVolumeUnderLastPrev = conditions.volume[pIndex] < conditions.volume[ppIndex];
|
||||
|
||||
//
|
||||
bool isVolumeChangedToBullish = isVolumeBullish &&
|
||||
!isVolumeBullishPrev;
|
||||
bool isVolumeChangedToBearish = isVolumeBearish &&
|
||||
!isVolumeBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isVolumeBullish = isVolumeBullish;
|
||||
conditions.isVolumeBearish = isVolumeBearish;
|
||||
conditions.isVolumeOverLast = isVolumeOverLast;
|
||||
conditions.isVolumeUnderLast = isVolumeUnderLast;
|
||||
conditions.isVolumeChangedToBullish = isVolumeChangedToBullish;
|
||||
conditions.isVolumeChangedToBearish = isVolumeChangedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XVLMInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
int calculatedBars = CountCalculatedBars();
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XVLM_VOLUME_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
volumeBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
Reference in New Issue
Block a user