last works ...
This commit is contained in:
@@ -0,0 +1,394 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: X3MA
|
||||
// Description: X3MA Trend Detector ...
|
||||
//
|
||||
// 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 X3MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X3MA"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int fastLength = 50; // Fast Length
|
||||
input int midLength = 100; // Mid Length
|
||||
input int slowLength = 200; // Slow Length
|
||||
input int shiftLength = 0; // Shift
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Mode
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
// Parts ...
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showMid = true; // Show Mid
|
||||
input bool showSlow = true; // Show Slow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
#define fastBufferIndex 0
|
||||
double fastBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X3MA F"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
#define midBufferIndex 1
|
||||
double midBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X3MA M"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrOrange
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
#define slowBufferIndex 2
|
||||
double slowBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X3MA S"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMagenta
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Handlers ...
|
||||
int fastHandler = INVALID_HANDLE;
|
||||
int midHandler = INVALID_HANDLE;
|
||||
int slowHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitHandlers())
|
||||
{
|
||||
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();
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Release Handlers ...
|
||||
IndicatorRelease(fastHandler);
|
||||
IndicatorRelease(midHandler);
|
||||
IndicatorRelease(slowHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
BarsCalculated(fastHandler) >= maxLength &&
|
||||
BarsCalculated(midHandler) >= maxLength &&
|
||||
BarsCalculated(slowHandler) >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
int copiedFasts = CopyBuffer(fastHandler, 0, 0, limit, fastBuffer);
|
||||
int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer);
|
||||
int copiedSlows = CopyBuffer(slowHandler, 0, 0, limit, slowBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
copiedFasts > 0 &&
|
||||
copiedMids > 0 &&
|
||||
copiedSlows > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
fastLength > 2 &&
|
||||
midLength > fastLength &&
|
||||
slowLength > midLength &&
|
||||
//
|
||||
shiftLength >= 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
result = MathMax(fastLength, midLength);
|
||||
result = MathMax(result, slowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Fast ...
|
||||
bool canShowFast = showFast;
|
||||
ENUM_DRAW_TYPE fastDrawType = canShowFast ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(fastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, canShowFast);
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
bool canShowMid = showMid;
|
||||
ENUM_DRAW_TYPE midDrawType = canShowMid ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, canShowMid);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
bool canShowSlow = showSlow;
|
||||
ENUM_DRAW_TYPE slowDrawType = canShowSlow ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(slowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, canShowSlow);
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handlers ...
|
||||
bool InitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Handlers ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
fastHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastLength,
|
||||
shiftLength,
|
||||
method,
|
||||
appliedTo //
|
||||
);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
midHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
midLength,
|
||||
shiftLength,
|
||||
method,
|
||||
appliedTo //
|
||||
);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
slowHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowLength,
|
||||
shiftLength,
|
||||
method,
|
||||
appliedTo //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
fastHandler != INVALID_HANDLE &&
|
||||
midHandler != INVALID_HANDLE &&
|
||||
slowHandler != INVALID_HANDLE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,566 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: X3VWAP
|
||||
// Description: X3VWAP Trend Detector ...
|
||||
//
|
||||
// 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 X3VWAP Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X3VWAP"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int fastLength = 50; // Fast Length
|
||||
input int midLength = 100; // Mid Length
|
||||
input int slowLength = 200; // Slow Length
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
// Parts ...
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showMid = true; // Show Mid
|
||||
input bool showSlow = true; // Show Slow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 11
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
#define fastBufferIndex 0
|
||||
double fastBuffer[];
|
||||
|
||||
#define fastColorBufferIndex 1
|
||||
double fastColorBuffer[];
|
||||
|
||||
//
|
||||
#define fastPlotBufferIndex 0
|
||||
#property indicator_label1 "X3VWAP F"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
#define midBufferIndex 2
|
||||
double midBuffer[];
|
||||
|
||||
#define midColorBufferIndex 3
|
||||
double midColorBuffer[];
|
||||
|
||||
//
|
||||
#define midPlotBufferIndex 1
|
||||
#property indicator_label2 "X3VWAP M"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
#define slowBufferIndex 4
|
||||
double slowBuffer[];
|
||||
|
||||
#define slowColorBufferIndex 5
|
||||
double slowColorBuffer[];
|
||||
|
||||
//
|
||||
#define slowPlotBufferIndex 2
|
||||
#property indicator_label3 "X3VWAP S"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Volumes ...
|
||||
#define volumeBufferIndex 6
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define priceBufferIndex 7
|
||||
double priceBuffer[];
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
#define fastStateBufferIndex 8
|
||||
double fastStateBuffer[];
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
#define midStateBufferIndex 9
|
||||
double midStateBuffer[];
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
#define slowStateBufferIndex 10
|
||||
double slowStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// 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();
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
fastLength > 2 &&
|
||||
midLength > fastLength &&
|
||||
slowLength > midLength
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
result = MathMax(fastLength, midLength);
|
||||
result = MathMax(result, slowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Fast ...
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
ArraySetAsSeries(fastColorBuffer, true);
|
||||
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(fastColorBufferIndex, fastColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(midColorBuffer, true);
|
||||
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(midColorBufferIndex, midColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
ArraySetAsSeries(slowColorBuffer, true);
|
||||
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(slowColorBufferIndex, slowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Volumes ...
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Price ...
|
||||
ArraySetAsSeries(priceBuffer, true);
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
ArraySetAsSeries(fastStateBuffer, true);
|
||||
SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
ArraySetAsSeries(midStateBuffer, true);
|
||||
SetIndexBuffer(midStateBufferIndex, midStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
ArraySetAsSeries(slowStateBuffer, true);
|
||||
SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate Volumes and Price ...
|
||||
|
||||
//
|
||||
if (ratesTotal - bar_index <= maxLength)
|
||||
{
|
||||
//
|
||||
CalculateDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
CalculateDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
|
||||
//
|
||||
CalculateVWAPS(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Required Data Buffers ...
|
||||
void CalculateDataBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double price = GetAppliedPrice(
|
||||
appliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
priceBuffer[bar_index] = price;
|
||||
volumeBuffer[bar_index] = (double)tickVolume[bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Different VWaps ...
|
||||
void CalculateVWAPS(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Fast ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
fastLength,
|
||||
showFast,
|
||||
fastBuffer,
|
||||
fastColorBuffer,
|
||||
fastStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
midLength,
|
||||
showMid,
|
||||
midBuffer,
|
||||
midColorBuffer,
|
||||
midStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
slowLength,
|
||||
showSlow,
|
||||
slowBuffer,
|
||||
slowColorBuffer,
|
||||
slowStateBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate VWAP ...
|
||||
void CalculateVWAP(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length, // Calculation Length
|
||||
bool _show,
|
||||
double &_buffer[],
|
||||
double &_colorBuffer[],
|
||||
double &_stateBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double vSum = 0;
|
||||
double pSum = 0;
|
||||
double mSum = 0;
|
||||
for (int x = 0; x < _length; x++)
|
||||
{
|
||||
//
|
||||
pSum += priceBuffer[x + bar_index];
|
||||
vSum += volumeBuffer[x + bar_index];
|
||||
mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
double iValue = mSum / vSum;
|
||||
iValue = NormalizeDouble(iValue, _Digits);
|
||||
|
||||
//
|
||||
_buffer[bar_index] = iValue;
|
||||
|
||||
//
|
||||
bool isBullish = low[bar_index] > iValue;
|
||||
bool isBearish = high[bar_index] < iValue;
|
||||
|
||||
//
|
||||
double iColor =
|
||||
isBullish
|
||||
? bullishColorIDX
|
||||
: isBearish
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
|
||||
//
|
||||
_colorBuffer[bar_index] = hideColorIDX;
|
||||
_stateBuffer[bar_index] = iColor;
|
||||
if (_show)
|
||||
{
|
||||
_colorBuffer[bar_index] = iColor;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user