rebackup some indicators ...

This commit is contained in:
2024-08-01 03:00:44 +03:30
parent deb71d0c1f
commit 13f08fb99c
6 changed files with 2581 additions and 0 deletions
@@ -0,0 +1,688 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXTDHelper
// 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.xhelper.class.mq5"
//
// Definitions ...
//
enum ENUM_XTD_BUFFERS
{
XTD_BULLISH_LINE = 0,
XTD_BEARISH_LINE = 1,
XTD_SIGNAL_LINE = 2,
};
//
// Input Models ...
struct XTDInputs
{
//
// Props ...
//
int length; // Market Length
bool drawCrosses; // Draw Cross Arrows
//
// Bullish ...
uchar bullishArrowCode; // Cross Over Arrow Code
color bullishArrowColor; // Cross Over Arrow Color
//
// Bearish ...
uchar bearishArrowCode; // Cross Under Arrow Code
color bearishArrowColor; // Cross Under Arrow Color
//
// Constructor(s) ...
XTDInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
length = 0;
drawCrosses = false;
//
// Bullish ...
bullishArrowCode = 228;
bullishArrowColor = CLR_NONE;
//
// Bearish ...
bearishArrowCode = 230;
bearishArrowColor = CLR_NONE;
}
//
// Default ...
void Default()
{
//
length = 14;
drawCrosses = false;
//
// Bullish ...
bullishArrowCode = 228;
bullishArrowColor = CLR_NONE;
//
// Bearish ...
bearishArrowCode = 230;
bearishArrowColor = CLR_NONE;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length >= 2
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(result, length);
//
return result;
}
};
//
// Define Conditions ...
struct XTDConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
double bullish[];
double bearish[];
//
// Conditions ...
//
bool isBullish;
bool isBearish;
bool isSwitchedToBullish;
bool isSwitchedToBearish;
//
void Clean()
{
//
Clean(bullish);
Clean(bearish);
//
ArraySetAsSeries(bullish, true);
ArraySetAsSeries(bearish, true);
//
isBullish = false;
isBearish = false;
isSwitchedToBullish = false;
isSwitchedToBearish = false;
}
//
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
if (isBullish)
{
bullishScore++;
}
if (isSwitchedToBullish)
{
bullishScore++;
}
//
if (isBearish)
{
bearishScore++;
}
if (isSwitchedToBearish)
{
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("isBullish", isBullish, ignoreFalseConditions, separator) +
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag()
{
return "XTD";
}
};
//
// Class ...
class XSCXTDHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXTDHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXTDHelper()
{
//
Clean(signalBuffer);
Clean(bullishBuffer);
Clean(bearishBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XTDInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(bullishBuffer, true);
ArraySetAsSeries(bearishBuffer, true);
ArraySetAsSeries(signalBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xtd",
//
// Inputs ...
//
mInputs.length, // Market Length
mInputs.drawCrosses, // Draw Cross Arrows
//
// Bullish ...
mInputs.bullishArrowCode, // Cross Over Arrow Code
mInputs.bullishArrowColor, // Cross Over Arrow Color
//
// Bearish ...
mInputs.bearishArrowCode, // Cross Under Arrow Code
mInputs.bearishArrowColor // Cross Under Arrow Color
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XTDInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XTDInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
double GetBullish(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(bullishBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return bullishBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyBullish(
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,
bullishBuffer,
buffer,
forceClean
//
);
}
//
double GetBearish(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(bearishBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return bearishBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyBearish(
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,
bearishBuffer,
buffer,
forceClean
//
);
}
//
double GetSignal(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(signalBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return signalBuffer[barIndex];
}
//
// Copy Required Items ...
int CopySignal(
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,
signalBuffer,
buffer,
forceClean
//
);
}
//
bool GetConditions(
XTDConditions &conditions, //
int barIndex = 0, //
int loopback = 3 //
)
{
//
bool result = true;
//
if (loopback < 3)
{
loopback = 3;
}
//
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;
//
CopyBullish(
zIndex,
loopback,
conditions.bullish //
);
CopyBearish(
zIndex,
loopback,
conditions.bearish //
);
//
// Calculate Conditions ...
//
bool isBullish = conditions.bullish[cIndex] > conditions.bearish[cIndex];
bool isBearish = conditions.bullish[cIndex] < conditions.bearish[cIndex];
//
bool isBullishPrev = conditions.bullish[pIndex] > conditions.bearish[pIndex];
bool isBearishPrev = conditions.bullish[pIndex] < conditions.bearish[pIndex];
//
bool isSwitchedToBullish = isBullish &&
!isBullishPrev;
bool isSwitchedToBearish = isBearish &&
!isBearishPrev;
//
conditions.isBullish = isBullish;
conditions.isBearish = isBearish;
conditions.isSwitchedToBullish = isSwitchedToBullish;
conditions.isSwitchedToBearish = isSwitchedToBearish;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XTDInputs mInputs; // Inputs ...
//
// Buffers ...
double bullishBuffer[];
double bearishBuffer[];
double signalBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// Bullish ...
CopyBuffer(
mHandler,
XTD_BULLISH_LINE,
0,
totalBars,
bullishBuffer
//
);
//
// Bearish ...
CopyBuffer(
mHandler,
XTD_BEARISH_LINE,
0,
totalBars,
bearishBuffer
//
);
//
// Signal ...
CopyBuffer(
mHandler,
XTD_SIGNAL_LINE,
0,
totalBars,
signalBuffer
//
);
}
};
//
// Tools ...
@@ -0,0 +1,555 @@
///////////////////////////////////////////////////////
//
// 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() {
Clean(volumeBuffer);
}
//
// 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();
if (totalBars > 1000) {
totalBars = 1000;
}
//
// Trend ...
CopyBuffer(
mHandler,
XVLM_VOLUME_LINE,
0,
totalBars,
volumeBuffer
//
);
}
};
//
// Tools ...
@@ -0,0 +1,438 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Trend Detector Oscillator
// --------------------------------------------------
// Name: XTD
// Description: trend detecting in both sides ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XTD Oscillator"
#property strict
//
// START Constants ...
//
#define ShortName "XTD"
//
// XTD Oscillator States ...
enum ENUM_X_XTD_STATES
{
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
X_XTD_BULLISH_OVER_BEARISH = 1,
X_XTD_NEUTURAL = 0,
X_XTD_BULLISH_UNDER_BEARISH = -1,
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
};
//
// END Constants ...
//
//
// START Inputs ...
//
input int length = 14; // Market Length
input bool drawCrosses = true; // Draw Cross Arrows
//
// Bullish ...
input uchar bullishArrowCode = 228; // Cross Over Arrow Code
input color bullishArrowColor = clrAqua; // Cross Over Arrow Color
//
// Bearish ...
input uchar bearishArrowCode = 230; // Cross Under Arrow Code
input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color
//
// END Inputs ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5";
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5";
//
// START Buffers ...
//
// #property indicator_separate_window
#property indicator_chart_window
//
#property indicator_buffers 3
// #property indicator_plots 3
#property indicator_plots 0
//
#define bullishBufferIndex 0
#define bearishBufferIndex 1
#define signalBufferIndex 2
//
double bullishBuffer[];
double bearishBuffer[];
double signalBuffer[];
//
// #property indicator_label1 "XBullPower"
// #property indicator_type1 DRAW_LINE
// #property indicator_color1 clrLime
// #property indicator_style1 STYLE_SOLID
// #property indicator_width1 1
//
// #property indicator_label2 "XBearPower"
// #property indicator_type2 DRAW_LINE
// #property indicator_color2 clrRed
// #property indicator_style2 STYLE_SOLID
// #property indicator_width2 1
//
// #property indicator_label3 "XSignal"
// #property indicator_type3 DRAW_LINE
// #property indicator_color3 clrGold
// #property indicator_style3 STYLE_DOT
// #property indicator_width3 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int xtdBullishCandleCount = 0;
int xtdBearishCandleCount = 0;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
drawPrefix = ShortName;
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Here we can handle De Initialization Reasons ...
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(0, length);
//
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
//
// Main Loop ...
for (int i = limit; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(i, close);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (length >= 5)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Bullish Buffer ...
string bullishBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
ArraySetAsSeries(bullishBuffer, true);
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_CALCULATIONS);
// SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
// PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
// PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
//
// Bearish Buffer ...
string bearishBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
ArraySetAsSeries(bearishBuffer, true);
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_CALCULATIONS);
// SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
// PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
// PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
//
// Signal Buffer ...
string signalBufferLabel = ShortName + "Signal " + "(" + (string)length + ")";
ArraySetAsSeries(signalBuffer, true);
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_CALCULATIONS);
// SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
// PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
// PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index,
const double &close[])
{
//
// Reset Global Counters ...
xtdBullishCandleCount = 0;
xtdBearishCandleCount = 0;
//
// Loop through Closes ...
for (int i = bar_index; i <= bar_index + length; i++)
{
for (int j = i + 1; j <= bar_index + length; j++)
{
//
if (close[i] > close[j])
{
xtdBullishCandleCount++;
}
//
if (close[i] < close[j])
{
xtdBearishCandleCount++;
}
}
}
//
// Bullish Power Buffer ...
bullishBuffer[bar_index] = MathAbs(xtdBullishCandleCount);
//
// Bearish Power Buffer ...
bearishBuffer[bar_index] = MathAbs(xtdBearishCandleCount);
//
// Signal Buffer ...
signalBuffer[bar_index] = bullishBuffer[bar_index] - bearishBuffer[bar_index];
//
// Check and Draw Crosses if it's Specified ...
if (drawCrosses)
{
DrawCrosses(bar_index);
}
}
//
//
double GetState(
int bar_index // Specified Bar Index
)
{
//
// Check Cross Points ...
// bullishCrossedOverBearish = 2;
// bullishOverBearish = 1;
// bullishCrossedUnderBearish = -2;
// bullishUnderBearish = -1;
// OtherWise = 0;
bool isBullishCrossedOverBearish = IsCrossedOver(
bullishBuffer,
bearishBuffer,
bar_index);
bool isBullishCrossedUnderBearish = IsCrossedUnder(
bullishBuffer,
bearishBuffer,
bar_index);
bool isBullishOverBearish = IsOver(
bullishBuffer,
bearishBuffer,
bar_index);
bool isBullishUnderBearish = IsUnder(
bullishBuffer,
bearishBuffer,
bar_index);
//
double result = X_XTD_NEUTURAL;
if (isBullishCrossedOverBearish)
{
result = X_XTD_BULLISH_CROSSED_OVER_BEARISH;
}
else if (isBullishCrossedUnderBearish)
{
result = X_XTD_BULLISH_CROSSED_UNDER_BEARISH;
}
else if (isBullishOverBearish)
{
result = X_XTD_BULLISH_OVER_BEARISH;
}
else if (isBullishUnderBearish)
{
result = X_XTD_BULLISH_UNDER_BEARISH;
}
else
{
result = X_XTD_NEUTURAL;
}
//
return result;
}
//
// Draw Crosses ...
void DrawCrosses(
int bar_index // the bars which required to draw cross arrow on it ...
)
{
//
double stateValue = GetState(bar_index);
//
bool isOver = stateValue == 2;
double low = iLow(_Symbol, _Period, bar_index);
double high = iHigh(_Symbol, _Period, bar_index);
//
double price = isOver ? low : high;
datetime time = iTime(_Symbol, _Period, bar_index);
ENUM_ARROW_ANCHOR anchor = isOver ? ANCHOR_TOP : ANCHOR_BOTTOM;
uchar arrowCode = isOver ? bullishArrowCode : bearishArrowCode;
color arrowColor = isOver ? bullishArrowColor : bearishArrowColor;
string crossName = "Trend " + (isOver ? "Up" : "Down") + "_" + (string)time + "_" + (string)price;
//
DrawArrow(
0,
crossName,
0,
time,
price,
arrowCode,
anchor,
arrowColor);
}
//
// END Functions ...
//
@@ -0,0 +1,438 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Trend Detector Oscillator
// --------------------------------------------------
// Name: XTD
// Description: trend detecting in both sides ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XTD Oscillator"
#property strict
//
// START Constants ...
//
#define ShortName "XTD"
//
// XTD Oscillator States ...
enum ENUM_X_XTD_STATES
{
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
X_XTD_BULLISH_OVER_BEARISH = 1,
X_XTD_NEUTURAL = 0,
X_XTD_BULLISH_UNDER_BEARISH = -1,
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
};
//
// END Constants ...
//
//
// START Inputs ...
//
input int length = 14; // Market Length
input bool drawCrosses = true; // Draw Cross Arrows
//
// Bullish ...
input uchar bullishArrowCode = 228; // Cross Over Arrow Code
input color bullishArrowColor = clrAqua; // Cross Over Arrow Color
//
// Bearish ...
input uchar bearishArrowCode = 230; // Cross Under Arrow Code
input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color
//
// END Inputs ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5";
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5";
//
// START Buffers ...
//
#property indicator_separate_window
// #property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 2
// #property indicator_plots 0
//
#define bullishBufferIndex 0
#define bearishBufferIndex 1
#define signalBufferIndex 2
//
double bullishBuffer[];
double bearishBuffer[];
double signalBuffer[];
//
#property indicator_label1 "XBullPower"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#property indicator_label2 "XBearPower"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// #property indicator_label3 "XSignal"
// #property indicator_type3 DRAW_LINE
// #property indicator_color3 clrGold
// #property indicator_style3 STYLE_DOT
// #property indicator_width3 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int xtdBullishCandleCount = 0;
int xtdBearishCandleCount = 0;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
drawPrefix = ShortName;
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Here we can handle De Initialization Reasons ...
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(0, length);
//
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
//
// Main Loop ...
for (int i = limit; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(i, close);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (length >= 5)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Bullish Buffer ...
string bullishBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
ArraySetAsSeries(bullishBuffer, true);
// SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
//
// Bearish Buffer ...
string bearishBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
ArraySetAsSeries(bearishBuffer, true);
// SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
//
// Signal Buffer ...
string signalBufferLabel = ShortName + "Signal " + "(" + (string)length + ")";
ArraySetAsSeries(signalBuffer, true);
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_CALCULATIONS);
// SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
// PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
// PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index,
const double &close[])
{
//
// Reset Global Counters ...
xtdBullishCandleCount = 0;
xtdBearishCandleCount = 0;
//
// Loop through Closes ...
for (int i = bar_index; i <= bar_index + length; i++)
{
for (int j = i + 1; j <= bar_index + length; j++)
{
//
if (close[i] > close[j])
{
xtdBullishCandleCount++;
}
//
if (close[i] < close[j])
{
xtdBearishCandleCount++;
}
}
}
//
// Bullish Power Buffer ...
bullishBuffer[bar_index] = MathAbs(xtdBullishCandleCount);
//
// Bearish Power Buffer ...
bearishBuffer[bar_index] = MathAbs(xtdBearishCandleCount);
//
// Signal Buffer ...
signalBuffer[bar_index] = bullishBuffer[bar_index] - bearishBuffer[bar_index];
//
// Check and Draw Crosses if it's Specified ...
if (drawCrosses)
{
DrawCrosses(bar_index);
}
}
//
//
double GetState(
int bar_index // Specified Bar Index
)
{
//
// Check Cross Points ...
// bullishCrossedOverBearish = 2;
// bullishOverBearish = 1;
// bullishCrossedUnderBearish = -2;
// bullishUnderBearish = -1;
// OtherWise = 0;
bool isBullishCrossedOverBearish = IsCrossedOver(
bullishBuffer,
bearishBuffer,
bar_index);
bool isBullishCrossedUnderBearish = IsCrossedUnder(
bullishBuffer,
bearishBuffer,
bar_index);
bool isBullishOverBearish = IsOver(
bullishBuffer,
bearishBuffer,
bar_index);
bool isBullishUnderBearish = IsUnder(
bullishBuffer,
bearishBuffer,
bar_index);
//
double result = X_XTD_NEUTURAL;
if (isBullishCrossedOverBearish)
{
result = X_XTD_BULLISH_CROSSED_OVER_BEARISH;
}
else if (isBullishCrossedUnderBearish)
{
result = X_XTD_BULLISH_CROSSED_UNDER_BEARISH;
}
else if (isBullishOverBearish)
{
result = X_XTD_BULLISH_OVER_BEARISH;
}
else if (isBullishUnderBearish)
{
result = X_XTD_BULLISH_UNDER_BEARISH;
}
else
{
result = X_XTD_NEUTURAL;
}
//
return result;
}
//
// Draw Crosses ...
void DrawCrosses(
int bar_index // the bars which required to draw cross arrow on it ...
)
{
//
double stateValue = GetState(bar_index);
//
bool isOver = stateValue == 2;
double low = iLow(_Symbol, _Period, bar_index);
double high = iHigh(_Symbol, _Period, bar_index);
//
double price = isOver ? low : high;
datetime time = iTime(_Symbol, _Period, bar_index);
ENUM_ARROW_ANCHOR anchor = isOver ? ANCHOR_TOP : ANCHOR_BOTTOM;
uchar arrowCode = isOver ? bullishArrowCode : bearishArrowCode;
color arrowColor = isOver ? bullishArrowColor : bearishArrowColor;
string crossName = "Trend " + (isOver ? "Up" : "Down") + "_" + (string)time + "_" + (string)price;
//
DrawArrow(
0,
crossName,
0,
time,
price,
arrowCode,
anchor,
arrowColor);
}
//
// END Functions ...
//
@@ -0,0 +1,231 @@
//////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: XVLM
// Description: Volume Trend Indicator ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XVLM Indicator"
#property strict
//
// Imports ...
#include <Math/Stat/Normal.mqh>
//
// Definitions ...
//
#define ShortName "XVLM"
//
// Inputs ...
//
input int length = 14; // Length
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 2
#property indicator_plots 0
///
#define volumeBufferIndex 0
double volumeBuffer[];
//
#define volumeColorBufferIndex 1
double volumeColorBuffer[];
//
#property indicator_label1 "XVLM"
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 clrLime, clrRed
//
#define bullishColorIndex 0
#define bearishColorIndex 1
//
// Variables ...
//
int maxLength;
//
double volumes[];
double distances[];
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
ArrayResize(volumes, maxLength, 0);
ArrayResize(distances, maxLength, 0);
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Here we can handle De Initialization Reasons ...
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
static int i = maxLength * 2;
for (i; i < rates_total; i++)
{
//
for (int x = 0; x < length; x++)
{
//
volumes[x] = (double)tick_volume[i - x];
distances[x] =
(close[i - x] > open[i - x])
? high[i - x] - low[i - x]
: low[i - x] - high[i - x];
}
//
double iValue = MathMean(volumes) * MathMean(distances);
//
volumeBuffer[i] = iValue;
volumeColorBuffer[i] = iValue > 0
? bullishColorIndex
: bearishColorIndex;
}
//
i = rates_total - 1;
//
return rates_total;
}
//
// Custom Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
result =
//
length >= 2
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = length;
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(volumeColorBufferIndex, volumeColorBuffer, INDICATOR_CALCULATIONS);
}
@@ -0,0 +1,231 @@
//////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: XVLM
// Description: Volume Trend Indicator ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XVLM Indicator"
#property strict
//
// Imports ...
#include <Math/Stat/Normal.mqh>
//
// Definitions ...
//
#define ShortName "XVLM"
//
// Inputs ...
//
input int length = 14; // Length
//
// Buffers ...
//
#property indicator_separate_window
//
#property indicator_buffers 2
#property indicator_plots 2
///
#define volumeBufferIndex 0
double volumeBuffer[];
//
#define volumeColorBufferIndex 1
double volumeColorBuffer[];
//
#property indicator_label1 "XVLM"
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 clrLime, clrRed
//
#define bullishColorIndex 0
#define bearishColorIndex 1
//
// Variables ...
//
int maxLength;
//
double volumes[];
double distances[];
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
ArrayResize(volumes, maxLength, 0);
ArrayResize(distances, maxLength, 0);
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Here we can handle De Initialization Reasons ...
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
static int i = maxLength * 2;
for (i; i < rates_total; i++)
{
//
for (int x = 0; x < length; x++)
{
//
volumes[x] = (double)tick_volume[i - x];
distances[x] =
(close[i - x] > open[i - x])
? high[i - x] - low[i - x]
: low[i - x] - high[i - x];
}
//
double iValue = MathMean(volumes) * MathMean(distances);
//
volumeBuffer[i] = iValue;
volumeColorBuffer[i] = iValue > 0
? bullishColorIndex
: bearishColorIndex;
}
//
i = rates_total - 1;
//
return rates_total;
}
//
// Custom Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
result =
//
length >= 2
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = length;
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_DATA);
SetIndexBuffer(volumeColorBufferIndex, volumeColorBuffer, INDICATOR_COLOR_INDEX);
}