1089 lines
25 KiB
Plaintext
1089 lines
25 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
// SaherElm IT Center MQL5 Indicator
|
|
// -------------------------------------------
|
|
// Name: XCHM
|
|
// Description: XCHMrend 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 XCHM Indicator"
|
|
#property strict
|
|
|
|
//
|
|
#define ShortName "XCHM"
|
|
|
|
//
|
|
// Includes Common Library ...
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
// Market ...
|
|
input group "Market";
|
|
input int fastLength = 9; // Fast Length
|
|
input int slowLength = 18; // Slow Length
|
|
input ENUM_MA_METHOD method = MODE_SMA; // Mode
|
|
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
|
|
|
//
|
|
input group "Cycles";
|
|
|
|
//
|
|
input group "Short";
|
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
|
|
|
//
|
|
input group "Medium";
|
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
input group "Long";
|
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
input group "Hind";
|
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
// Presentation ...
|
|
input group "Presentation";
|
|
|
|
//
|
|
// Parts ...
|
|
input bool showFast = true; // Show Fast
|
|
input bool showSlow = true; // Show Slow
|
|
|
|
//
|
|
// AVG ...
|
|
input bool showAVG = true; // Show Average
|
|
|
|
//
|
|
// Cycles ...
|
|
input bool showCurrent = true; // Show Current Cycle
|
|
input bool showShort = true; // Show Short Cycle
|
|
input bool showMedium = true; // Show Medium Cycle
|
|
input bool showLong = true; // Show Long Cycle
|
|
input bool showHind = true; // Show Hind Cycle
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
#property indicator_chart_window
|
|
|
|
//
|
|
#property indicator_buffers 12
|
|
#property indicator_plots 12
|
|
|
|
//
|
|
// AVG ...
|
|
|
|
//
|
|
// Fast ...
|
|
#define avgFastBufferIndex 0
|
|
double avgFastBuffer[];
|
|
|
|
//
|
|
#property indicator_label1 "XCHM AF"
|
|
#property indicator_type1 DRAW_LINE
|
|
#property indicator_color1 clrGreen
|
|
#property indicator_style1 STYLE_SOLID
|
|
#property indicator_width1 1
|
|
|
|
//
|
|
// Slow ...
|
|
#define avgSlowBufferIndex 1
|
|
double avgSlowBuffer[];
|
|
|
|
//
|
|
#property indicator_label2 "XCHM AS"
|
|
#property indicator_type2 DRAW_LINE
|
|
#property indicator_color2 clrRed
|
|
#property indicator_style2 STYLE_SOLID
|
|
#property indicator_width2 1
|
|
|
|
//
|
|
// Current ...
|
|
|
|
//
|
|
// Fast ...
|
|
#define cFastBufferIndex 2
|
|
double cFastBuffer[];
|
|
|
|
//
|
|
#property indicator_label3 "XCHM CF"
|
|
#property indicator_type3 DRAW_LINE
|
|
#property indicator_color3 clrAqua
|
|
#property indicator_style3 STYLE_DOT
|
|
#property indicator_width3 1
|
|
|
|
//
|
|
// Slow ...
|
|
#define cSlowBufferIndex 3
|
|
double cSlowBuffer[];
|
|
|
|
//
|
|
#property indicator_label4 "XCHM CS"
|
|
#property indicator_type4 DRAW_LINE
|
|
#property indicator_color4 clrMagenta
|
|
#property indicator_style4 STYLE_DOT
|
|
#property indicator_width4 1
|
|
|
|
//
|
|
// Short ...
|
|
|
|
//
|
|
// Fast ...
|
|
#define sFastBufferIndex 4
|
|
double sFastBuffer[];
|
|
|
|
//
|
|
#property indicator_label5 "XCHM SF"
|
|
#property indicator_type5 DRAW_LINE
|
|
#property indicator_color5 clrAqua
|
|
#property indicator_style5 STYLE_DOT
|
|
#property indicator_width5 1
|
|
|
|
//
|
|
// Slow ...
|
|
#define sSlowBufferIndex 5
|
|
double sSlowBuffer[];
|
|
|
|
//
|
|
#property indicator_label6 "XCHM SS"
|
|
#property indicator_type6 DRAW_LINE
|
|
#property indicator_color6 clrMagenta
|
|
#property indicator_style6 STYLE_DOT
|
|
#property indicator_width6 1
|
|
|
|
//
|
|
// Medium ...
|
|
|
|
//
|
|
// Fast ...
|
|
#define mFastBufferIndex 6
|
|
double mFastBuffer[];
|
|
|
|
//
|
|
#property indicator_label7 "XCHM MF"
|
|
#property indicator_type7 DRAW_LINE
|
|
#property indicator_color7 clrAqua
|
|
#property indicator_style7 STYLE_DOT
|
|
#property indicator_width7 1
|
|
|
|
//
|
|
// Slow ...
|
|
#define mSlowBufferIndex 7
|
|
double mSlowBuffer[];
|
|
|
|
//
|
|
#property indicator_label8 "XCHM MS"
|
|
#property indicator_type8 DRAW_LINE
|
|
#property indicator_color8 clrMagenta
|
|
#property indicator_style8 STYLE_DOT
|
|
#property indicator_width8 1
|
|
|
|
//
|
|
// Long ...
|
|
|
|
//
|
|
// Fast ...
|
|
#define lFastBufferIndex 8
|
|
double lFastBuffer[];
|
|
|
|
//
|
|
#property indicator_label9 "XCHM LF"
|
|
#property indicator_type9 DRAW_LINE
|
|
#property indicator_color9 clrAqua
|
|
#property indicator_style9 STYLE_DOT
|
|
#property indicator_width9 1
|
|
|
|
//
|
|
// Slow ...
|
|
#define lSlowBufferIndex 9
|
|
double lSlowBuffer[];
|
|
|
|
//
|
|
#property indicator_label10 "XCHM LS"
|
|
#property indicator_type10 DRAW_LINE
|
|
#property indicator_color10 clrMagenta
|
|
#property indicator_style10 STYLE_DOT
|
|
#property indicator_width10 1
|
|
|
|
//
|
|
// Hind ...
|
|
|
|
//
|
|
// Fast ...
|
|
#define hFastBufferIndex 10
|
|
double hFastBuffer[];
|
|
|
|
//
|
|
#property indicator_label11 "XCHM HF"
|
|
#property indicator_type11 DRAW_LINE
|
|
#property indicator_color11 clrAqua
|
|
#property indicator_style11 STYLE_DOT
|
|
#property indicator_width11 1
|
|
|
|
//
|
|
// Slow ...
|
|
#define hSlowBufferIndex 11
|
|
double hSlowBuffer[];
|
|
|
|
//
|
|
#property indicator_label12 "XCHM HS"
|
|
#property indicator_type12 DRAW_LINE
|
|
#property indicator_color12 clrMagenta
|
|
#property indicator_style12 STYLE_DOT
|
|
#property indicator_width12 1
|
|
|
|
//
|
|
// Variables ...
|
|
|
|
//
|
|
int maxLength;
|
|
|
|
//
|
|
// Current ...
|
|
int cFastHandler = INVALID_HANDLE;
|
|
int cSlowHandler = INVALID_HANDLE;
|
|
|
|
//
|
|
// Short ...
|
|
int mSCLength = 0;
|
|
int mSCFastLength = 0;
|
|
int mSCSlowLength = 0;
|
|
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
|
int sFastHandler = INVALID_HANDLE;
|
|
int sSlowHandler = INVALID_HANDLE;
|
|
|
|
//
|
|
// Medium ...
|
|
int mMCLength = 0;
|
|
int mMCFastLength = 0;
|
|
int mMCSlowLength = 0;
|
|
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
|
int mFastHandler = INVALID_HANDLE;
|
|
int mSlowHandler = INVALID_HANDLE;
|
|
|
|
//
|
|
// Long ...
|
|
int mLCLength = 0;
|
|
int mLCFastLength = 0;
|
|
int mLCSlowLength = 0;
|
|
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
|
int lFastHandler = INVALID_HANDLE;
|
|
int lSlowHandler = INVALID_HANDLE;
|
|
|
|
//
|
|
// Hind ...
|
|
int mHCLength = 0;
|
|
int mHCFastLength = 0;
|
|
int mHCSlowLength = 0;
|
|
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
|
int hFastHandler = INVALID_HANDLE;
|
|
int hSlowHandler = INVALID_HANDLE;
|
|
|
|
//
|
|
// EVENT Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
// Validate Inputs ...
|
|
if (!ValidateInputs())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
if (!InitMarketCycles())
|
|
{
|
|
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
|
|
|
|
//
|
|
// Current ...
|
|
IndicatorRelease(cFastHandler);
|
|
IndicatorRelease(cSlowHandler);
|
|
|
|
//
|
|
// Short ...
|
|
IndicatorRelease(sFastHandler);
|
|
IndicatorRelease(sSlowHandler);
|
|
|
|
//
|
|
// Medium ...
|
|
IndicatorRelease(mFastHandler);
|
|
IndicatorRelease(mSlowHandler);
|
|
|
|
//
|
|
// Long ...
|
|
IndicatorRelease(lFastHandler);
|
|
IndicatorRelease(lSlowHandler);
|
|
|
|
//
|
|
// Hind ...
|
|
IndicatorRelease(hFastHandler);
|
|
IndicatorRelease(hSlowHandler);
|
|
}
|
|
|
|
//
|
|
// 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 =
|
|
//
|
|
// Current ...
|
|
BarsCalculated(cFastHandler) >= maxLength &&
|
|
BarsCalculated(cSlowHandler) >= maxLength &&
|
|
//
|
|
// Short ...
|
|
BarsCalculated(sFastHandler) >= maxLength &&
|
|
BarsCalculated(sSlowHandler) >= maxLength &&
|
|
//
|
|
// Medium ...
|
|
BarsCalculated(mFastHandler) >= maxLength &&
|
|
BarsCalculated(mSlowHandler) >= maxLength &&
|
|
//
|
|
// Long ...
|
|
BarsCalculated(lFastHandler) >= maxLength &&
|
|
BarsCalculated(lSlowHandler) >= maxLength &&
|
|
//
|
|
// Hind ...
|
|
BarsCalculated(hFastHandler) >= maxLength &&
|
|
BarsCalculated(hSlowHandler) >= maxLength
|
|
//
|
|
;
|
|
if (!isPassedRequiredCalculatedBars)
|
|
{
|
|
return prev_calculated;
|
|
}
|
|
|
|
//
|
|
limit =
|
|
(prev_calculated > rates_total || prev_calculated <= 0)
|
|
? rates_total
|
|
: (rates_total - prev_calculated) + 1;
|
|
|
|
//
|
|
// Buffers Copy ...
|
|
|
|
//
|
|
// Current ...
|
|
int copiedCFasts = CopyBuffer(cFastHandler, 0, 0, limit, cFastBuffer);
|
|
int copiedCSlows = CopyBuffer(cSlowHandler, 0, 0, limit, cSlowBuffer);
|
|
|
|
//
|
|
// Short ...
|
|
int copiedSFasts = CopyBuffer(sFastHandler, 0, 0, limit, sFastBuffer);
|
|
int copiedSSlows = CopyBuffer(sSlowHandler, 0, 0, limit, sSlowBuffer);
|
|
|
|
//
|
|
// Medium ...
|
|
int copiedMFasts = CopyBuffer(mFastHandler, 0, 0, limit, mFastBuffer);
|
|
int copiedMSlows = CopyBuffer(mSlowHandler, 0, 0, limit, mSlowBuffer);
|
|
|
|
//
|
|
// Long ...
|
|
int copiedLFasts = CopyBuffer(lFastHandler, 0, 0, limit, lFastBuffer);
|
|
int copiedLSlows = CopyBuffer(lSlowHandler, 0, 0, limit, lSlowBuffer);
|
|
|
|
//
|
|
// Hind ...
|
|
int copiedHFasts = CopyBuffer(hFastHandler, 0, 0, limit, hFastBuffer);
|
|
int copiedHSlows = CopyBuffer(hSlowHandler, 0, 0, limit, hSlowBuffer);
|
|
|
|
//
|
|
// Validate Copied Items ...
|
|
bool isPassedRequiredCopiedItems =
|
|
//
|
|
//
|
|
// Current ...
|
|
copiedCFasts > 0 &&
|
|
copiedCSlows > 0 &&
|
|
//
|
|
// Short ...
|
|
copiedSFasts > 0 &&
|
|
copiedSSlows > 0 &&
|
|
//
|
|
// Medium ...
|
|
copiedMFasts > 0 &&
|
|
copiedMSlows > 0 &&
|
|
//
|
|
// Long ...
|
|
copiedLFasts > 0 &&
|
|
copiedLSlows > 0 &&
|
|
//
|
|
// Hind ...
|
|
copiedHFasts > 0 &&
|
|
copiedHSlows > 0
|
|
//
|
|
;
|
|
if (!isPassedRequiredCopiedItems)
|
|
{
|
|
return prev_calculated;
|
|
}
|
|
|
|
//
|
|
// Main Loop ...
|
|
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
{
|
|
CalculateBuffers(i);
|
|
}
|
|
|
|
//
|
|
return rates_total;
|
|
}
|
|
|
|
//
|
|
// CUSTOM Functions ...
|
|
|
|
//
|
|
// Validate Input Args for Initialization ...
|
|
bool ValidateInputs()
|
|
{
|
|
//
|
|
bool result =
|
|
//
|
|
fastLength > 2 &&
|
|
slowLength > fastLength &&
|
|
//
|
|
(IsValid(scMethod, scPeriod) &&
|
|
IsValid(mcMethod, mcPeriod) &&
|
|
IsValid(lcMethod, lcPeriod) &&
|
|
IsValid(hcMethod, hcPeriod))
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve all Exists Input Max Length ...
|
|
// use for Start Of Drawing ...
|
|
int ExtractMaxLengthOfInputs()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
// Current ...
|
|
result = MathMax(fastLength, slowLength);
|
|
|
|
//
|
|
// Short ...
|
|
result = MathMax(result, mSCFastLength);
|
|
result = MathMax(result, mSCSlowLength);
|
|
|
|
//
|
|
// Medium ...
|
|
result = MathMax(result, mMCFastLength);
|
|
result = MathMax(result, mMCSlowLength);
|
|
|
|
//
|
|
// Long ...
|
|
result = MathMax(result, mLCFastLength);
|
|
result = MathMax(result, mLCSlowLength);
|
|
|
|
//
|
|
// Hind ...
|
|
result = MathMax(result, mHCFastLength);
|
|
result = MathMax(result, mHCSlowLength);
|
|
|
|
//
|
|
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()
|
|
{
|
|
//
|
|
// AVG ...
|
|
|
|
//
|
|
// Fast ...
|
|
bool canShowAVGFast = showAVG && showFast;
|
|
ENUM_DRAW_TYPE avgFastDrawType = canShowAVGFast ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(avgFastBuffer, true);
|
|
SetIndexBuffer(avgFastBufferIndex, avgFastBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(avgFastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(avgFastBufferIndex, PLOT_SHOW_DATA, canShowAVGFast);
|
|
PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_TYPE, avgFastDrawType);
|
|
|
|
//
|
|
// Slow ...
|
|
bool canShowAVGSlow = showAVG && showSlow;
|
|
ENUM_DRAW_TYPE avgSlowDrawType = canShowAVGSlow ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(avgSlowBuffer, true);
|
|
SetIndexBuffer(avgSlowBufferIndex, avgSlowBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(avgSlowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(avgSlowBufferIndex, PLOT_SHOW_DATA, canShowAVGSlow);
|
|
PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_TYPE, avgSlowDrawType);
|
|
|
|
//
|
|
// Current ...
|
|
|
|
//
|
|
// Fast ...
|
|
bool canShowCFast = showCurrent && showFast;
|
|
ENUM_DRAW_TYPE cFastDrawType = canShowCFast ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(cFastBuffer, true);
|
|
SetIndexBuffer(cFastBufferIndex, cFastBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(cFastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(cFastBufferIndex, PLOT_SHOW_DATA, canShowCFast);
|
|
PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_TYPE, cFastDrawType);
|
|
|
|
//
|
|
// Slow ...
|
|
bool canShowCSlow = showCurrent && showSlow;
|
|
ENUM_DRAW_TYPE cSlowDrawType = canShowCSlow ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(cSlowBuffer, true);
|
|
SetIndexBuffer(cSlowBufferIndex, cSlowBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(cSlowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(cSlowBufferIndex, PLOT_SHOW_DATA, canShowCSlow);
|
|
PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_TYPE, cSlowDrawType);
|
|
|
|
//
|
|
// Short ...
|
|
|
|
//
|
|
// Fast ...
|
|
bool canShowSFast = showShort && showFast;
|
|
ENUM_DRAW_TYPE sFastDrawType = canShowSFast ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(sFastBuffer, true);
|
|
SetIndexBuffer(sFastBufferIndex, sFastBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(sFastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(sFastBufferIndex, PLOT_SHOW_DATA, canShowSFast);
|
|
PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_TYPE, sFastDrawType);
|
|
|
|
//
|
|
// Slow ...
|
|
bool canShowSSlow = showShort && showSlow;
|
|
ENUM_DRAW_TYPE sSlowDrawType = canShowSSlow ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(sSlowBuffer, true);
|
|
SetIndexBuffer(sSlowBufferIndex, sSlowBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(sSlowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(sSlowBufferIndex, PLOT_SHOW_DATA, canShowSSlow);
|
|
PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_TYPE, sSlowDrawType);
|
|
|
|
//
|
|
// Medium ...
|
|
|
|
//
|
|
// Fast ...
|
|
bool canShowMFast = showMedium && showFast;
|
|
ENUM_DRAW_TYPE mFastDrawType = canShowMFast ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(mFastBuffer, true);
|
|
SetIndexBuffer(mFastBufferIndex, mFastBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(mFastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(mFastBufferIndex, PLOT_SHOW_DATA, canShowMFast);
|
|
PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_TYPE, mFastDrawType);
|
|
|
|
//
|
|
// Slow ...
|
|
bool canShowMSlow = showMedium && showSlow;
|
|
ENUM_DRAW_TYPE mSlowDrawType = canShowMSlow ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(mSlowBuffer, true);
|
|
SetIndexBuffer(mSlowBufferIndex, mSlowBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(mSlowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(mSlowBufferIndex, PLOT_SHOW_DATA, canShowMSlow);
|
|
PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_TYPE, mSlowDrawType);
|
|
|
|
//
|
|
// Long ...
|
|
|
|
//
|
|
// Fast ...
|
|
bool canShowLFast = showLong && showFast;
|
|
ENUM_DRAW_TYPE lFastDrawType = canShowLFast ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(lFastBuffer, true);
|
|
SetIndexBuffer(lFastBufferIndex, lFastBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(lFastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(lFastBufferIndex, PLOT_SHOW_DATA, canShowLFast);
|
|
PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_TYPE, lFastDrawType);
|
|
|
|
//
|
|
// Slow ...
|
|
bool canShowLSlow = showLong && showSlow;
|
|
ENUM_DRAW_TYPE lSlowDrawType = canShowLSlow ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(lSlowBuffer, true);
|
|
SetIndexBuffer(lSlowBufferIndex, lSlowBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(lSlowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(lSlowBufferIndex, PLOT_SHOW_DATA, canShowLSlow);
|
|
PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_TYPE, lSlowDrawType);
|
|
|
|
//
|
|
// Hind ...
|
|
|
|
//
|
|
// Fast ...
|
|
bool canShowHFast = showHind && showFast;
|
|
ENUM_DRAW_TYPE hFastDrawType = canShowHFast ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(hFastBuffer, true);
|
|
SetIndexBuffer(hFastBufferIndex, hFastBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(hFastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(hFastBufferIndex, PLOT_SHOW_DATA, canShowHFast);
|
|
PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_TYPE, hFastDrawType);
|
|
|
|
//
|
|
// Slow ...
|
|
bool canShowHSlow = showHind && showSlow;
|
|
ENUM_DRAW_TYPE hSlowDrawType = canShowHSlow ? DRAW_LINE : DRAW_NONE;
|
|
ArraySetAsSeries(hSlowBuffer, true);
|
|
SetIndexBuffer(hSlowBufferIndex, hSlowBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(hSlowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(hSlowBufferIndex, PLOT_SHOW_DATA, canShowHSlow);
|
|
PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_TYPE, hSlowDrawType);
|
|
}
|
|
|
|
//
|
|
// Initial Market Cycles ...
|
|
bool InitMarketCycles()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Current Cycle Initialization ...
|
|
|
|
//
|
|
int cPeriodSeconds = PeriodSeconds(_Period);
|
|
|
|
//
|
|
// Initialize Handlers ...
|
|
cFastHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
fastLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
cSlowHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
slowLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
result =
|
|
//
|
|
cFastHandler != INVALID_HANDLE &&
|
|
cSlowHandler != INVALID_HANDLE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Initialization ...
|
|
|
|
//
|
|
// Find Cycle Period ...
|
|
if (scMethod == X_PERIOD_AUTO)
|
|
{
|
|
//
|
|
// Select Period ...
|
|
mSCPeriod = GetCyclePeriod(
|
|
X_MARKET_CYCLE_SHORT,
|
|
_Period //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
mSCPeriod = scPeriod;
|
|
}
|
|
|
|
//
|
|
result = IsValid(mSCPeriod);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
|
mSCFastLength = fastLength * mSCLength;
|
|
mSCSlowLength = slowLength * mSCLength;
|
|
|
|
//
|
|
result = mSCLength > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initialize Handlers ...
|
|
sFastHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mSCFastLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
sSlowHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mSCSlowLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
result =
|
|
//
|
|
sFastHandler != INVALID_HANDLE &&
|
|
sSlowHandler != INVALID_HANDLE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Medium Cycle Initialization ...
|
|
|
|
//
|
|
// Find Cycle Period ...
|
|
if (mcMethod == X_PERIOD_AUTO)
|
|
{
|
|
//
|
|
// Select Period ...
|
|
mMCPeriod = GetCyclePeriod(
|
|
X_MARKET_CYCLE_MEDIUM,
|
|
_Period //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
mMCPeriod = mcPeriod;
|
|
}
|
|
|
|
//
|
|
result = IsValid(mMCPeriod);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
|
mMCFastLength = fastLength * mMCLength;
|
|
mMCSlowLength = slowLength * mMCLength;
|
|
|
|
//
|
|
result = mMCLength > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initialize Handlers ...
|
|
mFastHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mMCFastLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
mSlowHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mMCSlowLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
result =
|
|
//
|
|
mFastHandler != INVALID_HANDLE &&
|
|
mSlowHandler != INVALID_HANDLE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Long Cycle Initialization ...
|
|
|
|
//
|
|
// Find Cycle Period ...
|
|
if (lcMethod == X_PERIOD_AUTO)
|
|
{
|
|
//
|
|
// Select Period ...
|
|
mLCPeriod = GetCyclePeriod(
|
|
X_MARKET_CYCLE_LONG,
|
|
_Period //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
mLCPeriod = lcPeriod;
|
|
}
|
|
|
|
//
|
|
result = IsValid(mLCPeriod);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
|
mLCFastLength = fastLength * mLCLength;
|
|
mLCSlowLength = slowLength * mLCLength;
|
|
|
|
//
|
|
result = mLCLength > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initialize Handlers ...
|
|
lFastHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mLCFastLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
lSlowHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mLCSlowLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
result =
|
|
//
|
|
lFastHandler != INVALID_HANDLE &&
|
|
lSlowHandler != INVALID_HANDLE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Hind Cycle Initialization ...
|
|
|
|
//
|
|
// Find Cycle Period ...
|
|
if (hcMethod == X_PERIOD_AUTO)
|
|
{
|
|
//
|
|
// Select Period ...
|
|
mHCPeriod = GetCyclePeriod(
|
|
X_MARKET_CYCLE_HIND,
|
|
_Period //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
mHCPeriod = hcPeriod;
|
|
}
|
|
|
|
//
|
|
result = IsValid(mHCPeriod);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
|
mHCFastLength = fastLength * mHCLength;
|
|
mHCSlowLength = slowLength * mHCLength;
|
|
|
|
//
|
|
result = mHCLength > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initialize Handlers ...
|
|
hFastHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mHCFastLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
hSlowHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
mHCSlowLength,
|
|
0,
|
|
method,
|
|
appliedTo //
|
|
);
|
|
result =
|
|
//
|
|
hFastHandler != INVALID_HANDLE &&
|
|
hSlowHandler != INVALID_HANDLE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Do all Custom Calculations ...
|
|
void CalculateBuffers(int barIndex)
|
|
{
|
|
//
|
|
double cFast = cFastBuffer[barIndex];
|
|
double sFast = sFastBuffer[barIndex];
|
|
double mFast = mFastBuffer[barIndex];
|
|
double lFast = lFastBuffer[barIndex];
|
|
double hFast = hFastBuffer[barIndex];
|
|
|
|
//
|
|
double fast =
|
|
cFast +
|
|
sFast +
|
|
mFast +
|
|
lFast +
|
|
hFast;
|
|
avgFastBuffer[barIndex] = fast / 5;
|
|
|
|
//
|
|
double cSlow = cSlowBuffer[barIndex];
|
|
double sSlow = sSlowBuffer[barIndex];
|
|
double mSlow = mSlowBuffer[barIndex];
|
|
double lSlow = lSlowBuffer[barIndex];
|
|
double hSlow = hSlowBuffer[barIndex];
|
|
|
|
//
|
|
double slow =
|
|
cSlow +
|
|
sSlow +
|
|
mSlow +
|
|
lSlow +
|
|
hSlow;
|
|
avgSlowBuffer[barIndex] = slow / 5;
|
|
}
|
|
|
|
// |