Files
xMQL5/MQLTestWorkspace/BKPS/INDICATORS/x-saherelm.x121.xman.mq5
T
2024-04-30 19:09:35 +03:30

3920 lines
84 KiB
Plaintext

///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: X121_XMAN
// Description: Market Analyzer
// - Find Peaks and Vales
// - Find Trend
// - Find Market Direction
// - Detect Pivot Points and Swings
//
// Contains:
// -----------
// - 4 Cycle of TimeFrames
// - Fibonacci Golden Zone
// - Trend Detection using True Range Averaging
// - Trend Detecting using Moving Averages Ribbon
// - Trend Detecting using SSL Channel
// - Trend Detecting using Hull Implementation
//
// 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 X121_XMAN Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_XMAN"
//
// XPERIOD Calculation Method ...
// USED For Multiple Time Frames ...
enum ENUM_X_PERIOD_METHOD
{
//
X_PERIOD_NOTHING, // Nothing
X_PERIOD_AUTO, // Auto Select
X_PERIOD_MANUALLY // Manually
};
//
enum ENUM_X_MA_METHOD
{
X_MA_NOTHING, // Nothing
X_MA_SMA, // Simple
X_MA_EMA, // Expotential
X_MA_SMMA, // Smoothed Simple
X_MA_LWMA, // Linear Weighted
X_MA_AMA // Adaptive
};
//
struct XHullData
{
//
double value;
double value3;
//
double wsum1;
double wsum2;
double wsum3;
//
double lsum1;
double lsum2;
double lsum3;
};
//
// Holds an SnapShot of Charts Configuration ...
struct XChartStyle
{
//
// chart's ID ...
long chartId;
//
// chart's mode ...
ENUM_CHART_MODE mode;
//
// show bid line ...
bool showBidLine;
//
// show ask line ...
bool showAskLine;
//
// show grids on chart ...
bool showGrid;
//
// show volumes ...
bool showVolumes;
//
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
bool showTradeLevels;
//
// chart autoscroll ...
bool autoScroll;
//
// chart quick navigation state ...
bool quickNavigation;
//
// chart's foreground color ...
color foreGroundColor;
//
// chart's background color ...
color backGroundColor;
//
// Up Color ...
color upColor;
//
// Down Color ...
color downColor;
//
// Bullish color ...
color bullishColor;
//
// Bearish color ...
color bearishColor;
//
// grid color ...
color gridColor;
//
// bid line color ...
color bidLineColor;
//
// ask line color ...
color askLineColor;
//
// line mode and doji candlestick color ...
color lineColor;
//
// Color of stop order levels (Stop Loss and Take Profit) ...
color stopColor;
//
// volumes color ...
color volumesColor;
};
//
struct XMRBColorInfo
{
double clr;
double state;
};
//
// a Class For Hull Calculations ...
class XSCHull
{
//
public:
//
// Constructor ...
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
{
//
// These are a way above to assign Private variables at Construct time ...
}
//
// Deconstructor ...
~XSCHull()
{
ArrayFree(mData);
}
//
// Initial Hull ...
bool Init(
int mPeriod,
double mDivisor)
{
//
bool result = false;
//
mFullPeriod = (int)(mPeriod > 1 ? mPeriod : 1);
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (mDivisor > 1 ? mDivisor : 1) : 1);
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
//
mArraySize = -1;
mWeight1 = mWeight2 = mWeight3 = 1;
//
result = true;
//
return result;
}
//
// CalCulate Specific Value ...
double Calculate(
double value,
int i,
int bars)
{
//
double result = 0;
//
if (mArraySize < bars)
{
//
mArraySize = ArrayResize(mData, bars + 500);
if (mArraySize < bars)
return result;
}
//
mData[i].value = value;
if (i > mFullPeriod)
{
//
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
}
else
{
//
mData[i].wsum1 = mData[i].wsum2 =
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
{
//
if (w1 > 0)
{
//
mData[i].wsum1 += mData[i - k].value * w1;
mData[i].lsum1 += mData[i - k].value;
mWeight1 += w1;
}
//
mData[i].wsum2 += mData[i - k].value * w2;
mData[i].lsum2 += mData[i - k].value;
mWeight2 += w2;
}
}
//
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
//
if (i > mSqrtPeriod)
{
//
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
}
else
{
//
mData[i].wsum3 =
mData[i].lsum3 = mWeight3 = 0;
//
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
{
//
mData[i].wsum3 += mData[i - k].value3 * w3;
mData[i].lsum3 += mData[i - k].value3;
mWeight3 += w3;
}
}
//
result = mData[i].wsum3 / mWeight3;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
int mFullPeriod;
int mHalfPeriod;
int mSqrtPeriod;
int mArraySize;
double mWeight1;
double mWeight2;
double mWeight3;
//
XHullData mData[];
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Chart Style";
input color upColor = clrLime; // Up Color
input color downColor = clrRed; // Down Color
input color lineColor = clrLime; // Line mode and Doji candlestick Color
input color bearishColor = clrRed; // Bullish Color
input color bullishColor = clrLime; // Bearish Color
input color volumesColor = clrGreen; // Volumes Color
//
input group "Makret Cycles";
//
input group "Level 1";
input ENUM_X_PERIOD_METHOD l1Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l1Period = NULL; // Time Period
//
input group "Level 2";
input ENUM_X_PERIOD_METHOD l2Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l2Period = NULL; // Time Period
//
input group "Level 3";
input ENUM_X_PERIOD_METHOD l3Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l3Period = NULL; // Time Period
//
input group "Level 4";
input ENUM_X_PERIOD_METHOD l4Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l4Period = NULL; // Time Period
//
input group "Fibonacci";
input double fiboLevel1 = 0.382; // Fibio 1st Level
input double fiboLevel2 = 0.5; // Fibio 2st Level
input double fiboLevel3 = 0.618; // Fibio 3rd Level
//
input group "Boundary Detection Modes";
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
//
input group "Trend Detection";
input double trendMultiplier = 3; // Multiplier
input ENUM_APPLIED_PRICE trendPriceAppliedTo = PRICE_MEDIAN; // Applied To
//
input group "Ribbon Detection";
input ENUM_X_MA_METHOD ribbonMode = X_MA_AMA; // How to Calculate
//
input group "Hull Trend";
input double hullDivisor = 2.0; // Divisor (Speed)
input ENUM_APPLIED_PRICE hullUpAppliedTo = PRICE_HIGH; // Up Zone Applied to
input ENUM_APPLIED_PRICE hullDownAppliedTo = PRICE_LOW; // Down Zone Applied to
//
input group "SSL Channel Detection";
input ENUM_X_MA_METHOD sslcMode = X_MA_SMA; // How to Calculate
input ENUM_APPLIED_PRICE sslcUpAppliedTo = PRICE_HIGH; // Up Applied To
input ENUM_APPLIED_PRICE sslcDownAppliedTo = PRICE_LOW; // Down Applied To
//
input group "Presentation";
input bool showCandles = true; // Show Candles
input bool showHKCandles = true; // Draw Hiken Ashi Candle
input bool showPeaksAndVales = true; // Show Peaks and Vales
input bool showTrends = true; // Show Trends
input bool fillTrends = false; // Fill Trends
input bool showLevels = false; // Show Levels
input bool showConsolidations = false; // Show Consolidations
input bool showRibbons = false; // Show Ribbons
input bool showHull = false; // Show Hull
input bool showSSLChannel = false; // Show SSL Channel
input bool showFibo1Levels = true; // Show Fibo 1st Level
input bool showFibo2Levels = true; // Show Fibo 2nd Level
input bool showFibo3Levels = true; // Show Fibo 3rd Level
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 84
#property indicator_plots 41
//
// PEKSANDVALES ...
//
// PEAKS ...
//
#define peaksBufferIndex 0
double peaksBuffer[];
//
#property indicator_label1 "X121_XMAN PEAKS"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrAqua
#property indicator_width1 1
//
// VALES ...
//
#define valesBufferIndex 1
double valesBuffer[];
//
#property indicator_label2 "X121_XMAN VALES"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta
#property indicator_width2 1
//
#define rBufferIndex 2
double rBuffer[];
//
#define rColorBufferIndex 3
double rColorBuffer[];
//
#property indicator_label3 "X121_XMAN R"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrAqua
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define sBufferIndex 4
#define sBufferPlotIndex 3
double sBuffer[];
//
#define sColorBufferIndex 5
double sColorBuffer[];
//
#property indicator_label4 "X121_XMAN S"
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_color4 CLR_NONE, clrMagenta
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
// FIBBO Level 1 ...
//
#define fl1BufferIndex 6
#define fl1BufferPlotIndex 4
double fl1Buffer[];
//
#define fl1ColorBufferIndex 7
double fl1ColorBuffer[];
//
#property indicator_label5 "X121_XMAN FL1"
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_color5 CLR_NONE, clrGold
#property indicator_style5 STYLE_DASHDOTDOT
#property indicator_width5 1
//
// FIBBO Level 2 ...
//
#define fl2BufferIndex 8
#define fl2BufferPlotIndex 5
double fl2Buffer[];
//
#define fl2ColorBufferIndex 9
double fl2ColorBuffer[];
//
#property indicator_label6 "X121_XMAN FL2"
#property indicator_type6 DRAW_COLOR_LINE
#property indicator_color6 CLR_NONE, clrGold
#property indicator_style6 STYLE_DASHDOTDOT
#property indicator_width6 1
//
// FIBBO Level 3 ...
//
#define fl3BufferIndex 10
#define fl3BufferPlotIndex 6
double fl3Buffer[];
//
#define fl3ColorBufferIndex 11
double fl3ColorBuffer[];
//
#property indicator_label7 "X121_XMAN FL3"
#property indicator_type7 DRAW_COLOR_LINE
#property indicator_color7 CLR_NONE, clrGold
#property indicator_style7 STYLE_DASHDOTDOT
#property indicator_width7 1
//
// LEVELS ...
//
#define sHHBufferIndex 12
#define sHHBufferPlotIndex 7
double sHHBuffer[];
//
#define sHHColorBufferIndex 13
double sHHColorBuffer[];
//
#property indicator_label8 "X121_XMAN SHH"
#property indicator_type8 DRAW_COLOR_LINE
#property indicator_color8 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style8 STYLE_DOT
#property indicator_width8 1
#define sLLBufferIndex 14
#define sLLBufferPlotIndex 8
double sLLBuffer[];
//
#define sLLColorBufferIndex 15
double sLLColorBuffer[];
//
#property indicator_label9 "X121_XMAN SLL"
#property indicator_type9 DRAW_COLOR_LINE
#property indicator_color9 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style9 STYLE_DOT
#property indicator_width9 1
//
#define mHHBufferIndex 16
#define mHHBufferPlotIndex 9
double mHHBuffer[];
//
#define mHHColorBufferIndex 17
double mHHColorBuffer[];
//
#property indicator_label10 "X121_XMAN MHH"
#property indicator_type10 DRAW_COLOR_LINE
#property indicator_color10 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style10 STYLE_DOT
#property indicator_width10 1
//
#define mLLBufferIndex 18
#define mLLBufferPlotIndex 10
double mLLBuffer[];
//
#define mLLColorBufferIndex 19
double mLLColorBuffer[];
//
#property indicator_label11 "X121_XMAN MLL"
#property indicator_type11 DRAW_COLOR_LINE
#property indicator_color11 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style11 STYLE_DOT
#property indicator_width11 1
//
#define lHHBufferIndex 20
#define lHHBufferPlotIndex 11
double lHHBuffer[];
//
#define lHHColorBufferIndex 21
double lHHColorBuffer[];
//
#property indicator_label12 "X121_XMAN LHH"
#property indicator_type12 DRAW_COLOR_LINE
#property indicator_color12 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style12 STYLE_DOT
#property indicator_width12 1
//
#define lLLBufferIndex 22
#define lLLBufferPlotIndex 12
double lLLBuffer[];
//
#define lLLColorBufferIndex 23
double lLLColorBuffer[];
//
#property indicator_label13 "X121_XMAN LLL"
#property indicator_type13 DRAW_COLOR_LINE
#property indicator_color13 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style13 STYLE_DOT
#property indicator_width13 1
//
#define hHHBufferIndex 24
#define hHHBufferPlotIndex 13
double hHHBuffer[];
//
#define hHHColorBufferIndex 25
double hHHColorBuffer[];
//
#property indicator_label14 "X121_XMAN HHH"
#property indicator_type14 DRAW_COLOR_LINE
#property indicator_color14 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style14 STYLE_DOT
#property indicator_width14 1
//
#define hLLBufferIndex 26
#define hLLBufferPlotIndex 14
double hLLBuffer[];
//
#define hLLColorBufferIndex 27
double hLLColorBuffer[];
//
#property indicator_label15 "X121_XMAN HLL"
#property indicator_type15 DRAW_COLOR_LINE
#property indicator_color15 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style15 STYLE_DOT
#property indicator_width15 1
//
// XSTR Buffers ...
//
#define fillUpBufferIndex 28
double fillUpBuffer[];
#define fillDownBufferIndex 29
double fillDownBuffer[];
//
#define fillingBufferPlotIndex 15
//
#property indicator_label16 "X121_XMAN TRND Filling"
#property indicator_type16 DRAW_FILLING
#property indicator_color16 clrBisque, clrPaleGreen
//
#define trendBufferIndex 30
#define trendBufferPlotIndex 16
double trendBuffer[];
//
#define trendColorBufferIndex 31
double trendColorBuffer[];
//
#property indicator_label17 "X121_XMAN TRND"
#property indicator_type17 DRAW_COLOR_LINE
#property indicator_color17 CLR_NONE, clrGreen, clrDarkRed
#property indicator_style17 STYLE_DOT
#property indicator_width17 1
//
// XMRB ...
//
// RIBBON 1 ...
// High ...
//
#define ribbon1BufferIndex 32
#define ribbon1BufferPlotIndex 17
double ribbon1Buffer[];
//
#define ribbon1ColorBufferIndex 33
double ribbon1ColorBuffer[];
//
#property indicator_label18 "X121_XMAN RB 1"
#property indicator_type18 DRAW_COLOR_LINE
#property indicator_color18 CLR_NONE, clrGray, clrGreen, clrDarkRed
#property indicator_style18 STYLE_DASH
#property indicator_width18 1
//
// RIBBON 2 ...
// Open ...
//
#define ribbon2BufferIndex 34
#define ribbon2BufferPlotIndex 18
double ribbon2Buffer[];
//
#define ribbon2ColorBufferIndex 35
double ribbon2ColorBuffer[];
//
#property indicator_label19 "X121_XMAN RB 2"
#property indicator_type19 DRAW_COLOR_LINE
#property indicator_color19 CLR_NONE, clrGray, clrGreen, clrDarkRed
#property indicator_style19 STYLE_DASH
#property indicator_width19 1
//
// RIBBON 3 ...
// Close ...
//
#define ribbon3BufferIndex 36
#define ribbon3BufferPlotIndex 19
double ribbon3Buffer[];
//
#define ribbon3ColorBufferIndex 37
double ribbon3ColorBuffer[];
//
#property indicator_label20 "X121_XMAN RB 3"
#property indicator_type20 DRAW_COLOR_LINE
#property indicator_color20 CLR_NONE, clrGray, clrGreen, clrDarkRed
#property indicator_style20 STYLE_DASH
#property indicator_width20 1
//
// RIBBON 4 ...
// Median ...
//
#define ribbon4BufferIndex 38
#define ribbon4BufferPlotIndex 20
double ribbon4Buffer[];
//
#define ribbon4ColorBufferIndex 39
double ribbon4ColorBuffer[];
//
#property indicator_label21 "X121_XMAN RB 4"
#property indicator_type21 DRAW_COLOR_LINE
#property indicator_color21 CLR_NONE, clrGray, clrGreen, clrDarkRed
#property indicator_style21 STYLE_DASH
#property indicator_width21 1
//
// RIBBON 5 ...
// Typical ...
//
#define ribbon5BufferIndex 40
#define ribbon5BufferPlotIndex 21
double ribbon5Buffer[];
//
#define ribbon5ColorBufferIndex 41
double ribbon5ColorBuffer[];
//
#property indicator_label22 "X121_XMAN RB 5"
#property indicator_type22 DRAW_COLOR_LINE
#property indicator_color22 CLR_NONE, clrGray, clrGreen, clrDarkRed
#property indicator_style22 STYLE_DASH
#property indicator_width22 1
//
// RIBBON 6 ...
// Low ...
//
#define ribbon6BufferIndex 42
#define ribbon6BufferPlotIndex 22
double ribbon6Buffer[];
//
#define ribbon6ColorBufferIndex 43
double ribbon6ColorBuffer[];
//
#property indicator_label23 "X121_XMAN RB 6"
#property indicator_type23 DRAW_COLOR_LINE
#property indicator_color23 CLR_NONE, clrGray, clrGreen, clrDarkRed
#property indicator_style23 STYLE_DASH
#property indicator_width23 1
//
// XSSLC ...
//
#define sslcUpBufferIndex 44
#define sslcUpBufferPlotIndex 23
double sslcUpBuffer[];
//
#define sslcUpColorBufferIndex 45
double sslcUpColorBuffer[];
//
#property indicator_label24 "X121_XMAN SSLC Up"
#property indicator_type24 DRAW_COLOR_LINE
#property indicator_color24 CLR_NONE, clrLime
#property indicator_style24 STYLE_SOLID
#property indicator_width24 1
//
#define sslcDownBufferIndex 46
#define sslcDownBufferPlotIndex 24
double sslcDownBuffer[];
//
#define sslcDownColorBufferIndex 47
double sslcDownColorBuffer[];
//
#property indicator_label25 "X121_XMAN SSLC Down"
#property indicator_type25 DRAW_COLOR_LINE
#property indicator_color25 CLR_NONE, clrRed
#property indicator_style25 STYLE_SOLID
#property indicator_width25 1
//
// XHULL ...
//
// UP Zone ...
//
#define hullUpZoneBufferIndex 48
#define hullUpZoneBufferPlotIndex 25
#define hullUpZoneColorBufferIndex 49
//
double hullUpZoneBuffer[];
double hullUpZoneColorBuffer[];
//
#property indicator_label26 "X121_XMAN HULL Up"
#property indicator_type26 DRAW_COLOR_LINE
#property indicator_color26 CLR_NONE, clrGray, clrAqua, clrMagenta
#property indicator_width26 1
//
// DOWN Zone ...
//
#define hullDownZoneBufferIndex 50
#define hullDownZoneBufferPlotIndex 26
#define hullDownZoneColorBufferIndex 51
//
double hullDownZoneBuffer[];
double hullDownZoneColorBuffer[];
//
#property indicator_label27 "X121_XMAN HULL Down"
#property indicator_type27 DRAW_COLOR_LINE
#property indicator_color27 CLR_NONE, clrGray, clrAqua, clrMagenta
#property indicator_width27 1
//
// Open ...
#define hkOpenBufferIndex 52
double hkOpenBuffer[];
//
// High ...
#define hkHighBufferIndex 53
double hkHighBuffer[];
//
// Low ...
#define hkLowBufferIndex 54
double hkLowBuffer[];
//
// Close ...
#define hkCloseBufferIndex 55
double hkCloseBuffer[];
//
// Candle Color ...
#define hkCandleColorBufferIndex 56
double hkCandleColorBuffer[];
//
#define hkCandlesBufferIndex 27
//
#property indicator_label28 "X121_XMAN HK Open;X121_XMAN HK High;X121_XMAN HK Low;X121_XMAN HK Close"
#property indicator_type28 DRAW_COLOR_CANDLES
#property indicator_color28 CLR_NONE, clrAqua, clrMagenta
//
// DATA Buffers ...
#define lastBufferIndex 56
//
#define atrBufferIndex lastBufferIndex + 1
double atrBuffer[];
//
#define trendStateBufferIndex lastBufferIndex + 2
double trendStateBuffer[];
//
#define upBufferIndex lastBufferIndex + 3
double upBuffer[];
//
#define downBufferIndex lastBufferIndex + 4
double downBuffer[];
//
#define priceBufferIndex lastBufferIndex + 5
double priceBuffer[];
//
#define sslcUpMaBufferIndex lastBufferIndex + 6
double sslcUpMaBuffer[];
//
#define sslcDownMaBufferIndex lastBufferIndex + 7
double sslcDownMaBuffer[];
//
#define sslcKpiBufferIndex lastBufferIndex + 8
double sslcKpiBuffer[];
//
// STATE Buffers ...
//
// When new Peaks Happens it's Valued otherwise EMPTY_VALUE ...
#define peaksStateBufferIndex lastBufferIndex + 9
double peaksStateBuffer[];
//
// When new Vales Happens it's Valued otherwise EMPTY_VALUE ...
#define valesStateBufferIndex lastBufferIndex + 10
double valesStateBuffer[];
//
// SHORT Cycle ...
//
#define sHHStateBufferIndex lastBufferIndex + 11
double sHHStateBuffer[];
//
#define sLLStateBufferIndex lastBufferIndex + 12
double sLLStateBuffer[];
//
// MEDIUM Cycle ...
//
#define mHHStateBufferIndex lastBufferIndex + 13
double mHHStateBuffer[];
//
#define mLLStateBufferIndex lastBufferIndex + 14
double mLLStateBuffer[];
//
// LONG Cycle ...
//
#define lHHStateBufferIndex lastBufferIndex + 15
double lHHStateBuffer[];
//
#define lLLStateBufferIndex lastBufferIndex + 16
double lLLStateBuffer[];
//
// HIND Cycle ...
//
#define hHHStateBufferIndex lastBufferIndex + 17
double hHHStateBuffer[];
//
#define hLLStateBufferIndex lastBufferIndex + 18
double hLLStateBuffer[];
//
// XSTR ...
#define strTrendStateBufferIndex lastBufferIndex + 19
double strTrendStateBuffer[];
//
// XMRB ...
//
// RIBBON 1 (High) ...
#define rb1StateBufferIndex lastBufferIndex + 20
double rb1StateBuffer[];
//
// RIBBON 2 (Open) ...
#define rb2StateBufferIndex lastBufferIndex + 21
double rb2StateBuffer[];
//
// RIBBON 3 (Close) ...
#define rb3StateBufferIndex lastBufferIndex + 22
double rb3StateBuffer[];
//
// RIBBON 4 (Median) ...
#define rb4StateBufferIndex lastBufferIndex + 23
double rb4StateBuffer[];
//
// RIBBON 5 (Typical) ...
#define rb5StateBufferIndex lastBufferIndex + 24
double rb5StateBuffer[];
//
// RIBBON 6 (Low) ...
#define rb6StateBufferIndex lastBufferIndex + 25
double rb6StateBuffer[];
//
// XHULL ...
//
#define hullUpStateBufferIndex lastBufferIndex + 26
double hullUpStateBuffer[];
//
#define hullDownStateBufferIndex lastBufferIndex + 27
double hullDownStateBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
double lastPeak;
double lastVale;
//
double mLastSHH = 0;
double mLastSLL = 0;
//
double mLastMHH = 0;
double mLastMLL = 0;
//
double mLastLHH = 0;
double mLastLLL = 0;
//
double mLastHHH = 0;
double mLastHLL = 0;
//
double mHideColorIDX = 0;
//
int currentPeriodSecconds = 0;
//
// CYCLE 1 ...
int mL1Candles;
int mL1PeriodSecconds = 0;
int mLastL1StartBarIndex = 0;
datetime mLastL1StartTime = NULL;
ENUM_TIMEFRAMES mL1Period = NULL;
//
// CYCLE 2 ...
int mL2Candles;
int mL2PeriodSecconds = 0;
int mLastL2StartBarIndex = 0;
datetime mLastL2StartTime = NULL;
ENUM_TIMEFRAMES mL2Period = NULL;
//
// CYCLE 3 ...
int mL3Candles;
int mL3PeriodSecconds = 0;
int mLastL3StartBarIndex = 0;
datetime mLastL3StartTime = NULL;
ENUM_TIMEFRAMES mL3Period = NULL;
//
// CYCLE 4 ...
int mL4Candles;
int mL4PeriodSecconds = 0;
int mLastL4StartBarIndex = 0;
datetime mLastL4StartTime = NULL;
ENUM_TIMEFRAMES mL4Period = NULL;
//
// XSTR ...
//
int atrHandler = INVALID_HANDLE;
//
int changeOfTrend;
int startBearishTrend;
int startBullishTrend;
//
int mStrLength;
//
// XMRB ...
int mMRBLength;
int mMRBAMAFast = 2;
int mMRBAMASlow = 30;
//
int rb1Handler = INVALID_HANDLE;
int rb2Handler = INVALID_HANDLE;
int rb3Handler = INVALID_HANDLE;
int rb4Handler = INVALID_HANDLE;
int rb5Handler = INVALID_HANDLE;
int rb6Handler = INVALID_HANDLE;
//
// XSSLC ...
//
int mSSLCLength;
//
int sslcUpHandler = INVALID_HANDLE;
int sslcDownHandler = INVALID_HANDLE;
//
// XHULL ...
//
int mHULLLength;
//
XSCHull *mUpZHull;
XSCHull *mDownZHull;
//
double mLastHullUpValue;
double mLastHullUpColorValue = 1;
double mLastHullDownValue;
double mLastHullDownColorValue = 1;
//
// XCC ...
//
XChartStyle chartStyle;
XChartStyle clearStyle;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initial Periods ...
InitialCycles();
//
drawPrefix = ShortName;
//
// 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();
//
// We Can Choose ATR Length based on Other Cycles ...
mStrLength = mL4Candles;
atrHandler = iATR(
_Symbol,
_Period,
mStrLength);
if (atrHandler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
mMRBLength = mL4Candles;
if (!InitRibbons())
{
return INIT_FAILED;
}
//
mSSLCLength = mL4Candles;
if (!InitSSLChannel())
{
return INIT_FAILED;
}
//
mHULLLength = mL4Candles;
if (!InitHullTrend())
{
return INIT_FAILED;
}
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Apply Chart Style ...
ApplyCustomChartStyle();
//
// 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 ...
IndicatorRelease(atrHandler);
//
// XMRB ...
IndicatorRelease(rb1Handler);
IndicatorRelease(rb2Handler);
IndicatorRelease(rb3Handler);
IndicatorRelease(rb4Handler);
IndicatorRelease(rb5Handler);
IndicatorRelease(rb6Handler);
//
// XSSLC ...
IndicatorRelease(sslcUpHandler);
IndicatorRelease(sslcDownHandler);
//
// XHULL ...
delete mUpZHull;
delete mDownZHull;
//
Comment("");
}
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// this counts Available Bars ...
int limit;
//
limit = prev_calculated - 1;
if (limit < 0)
{
limit = 0;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
//
double upPrice = GetAppliedPrice(
hullUpAppliedTo,
open, high, low, close, i);
//
double downPrice = GetAppliedPrice(
hullDownAppliedTo,
open, high, low, close, i);
//
CalculateHull(i, rates_total, upPrice, downPrice);
}
//
bool isXSTRCalculated = CalculateXSTR(
rates_total,
prev_calculated,
open,
high,
low,
close);
if (!isXSTRCalculated)
{
return prev_calculated;
}
//
// 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);
//
// Checking Handlers Calculated Bars ...
//
// XMRB ...
int rb1CalculatedBars = BarsCalculated(rb1Handler);
int rb2CalculatedBars = BarsCalculated(rb2Handler);
int rb3CalculatedBars = BarsCalculated(rb3Handler);
int rb4CalculatedBars = BarsCalculated(rb4Handler);
int rb5CalculatedBars = BarsCalculated(rb5Handler);
int rb6CalculatedBars = BarsCalculated(rb6Handler);
//
// XSSLC ...
int sslcUpCalculatedBars = BarsCalculated(sslcUpHandler);
int sslcDownCalculatedBars = BarsCalculated(sslcDownHandler);
//
bool isCalculatedBarsNotPassed =
//
// XMRB ...
rb1CalculatedBars < maxLength ||
rb2CalculatedBars < maxLength ||
rb3CalculatedBars < maxLength ||
rb4CalculatedBars < maxLength ||
rb5CalculatedBars < maxLength ||
rb6CalculatedBars < maxLength ||
//
// XSSLC ...
sslcUpCalculatedBars < maxLength ||
sslcDownCalculatedBars < maxLength
//
;
//
if (isCalculatedBarsNotPassed)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Check Handlers Copied Bars ...
//
// XMRB ...
int rb1CopiedBars = CopyBuffer(rb1Handler, 0, 0, limit, ribbon1Buffer);
int rb2CopiedBars = CopyBuffer(rb2Handler, 0, 0, limit, ribbon2Buffer);
int rb3CopiedBars = CopyBuffer(rb3Handler, 0, 0, limit, ribbon3Buffer);
int rb4CopiedBars = CopyBuffer(rb4Handler, 0, 0, limit, ribbon4Buffer);
int rb5CopiedBars = CopyBuffer(rb5Handler, 0, 0, limit, ribbon5Buffer);
int rb6CopiedBars = CopyBuffer(rb6Handler, 0, 0, limit, ribbon6Buffer);
//
// XSSLC ...
int sslcUpCopiedBars = CopyBuffer(sslcUpHandler, 0, 0, limit, sslcUpMaBuffer);
int sslcDownCopiedBars = CopyBuffer(sslcDownHandler, 0, 0, limit, sslcDownMaBuffer);
//
bool isCopiedBarsNotPassed =
//
// XMRB ...
rb1CopiedBars < 0 ||
rb2CopiedBars < 0 ||
rb3CopiedBars < 0 ||
rb4CopiedBars < 0 ||
rb5CopiedBars < 0 ||
rb6CopiedBars < 0 ||
//
// XSSLC ...
sslcUpCopiedBars < 0 ||
sslcDownCopiedBars < 0
//
;
//
if (isCopiedBarsNotPassed)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(i);
//
CalculateRibbonsColors(i, low, high);
//
CalculateHikenAshi(i, prev_calculated, rates_total, open, high, close, low);
//
CalculateSSLC(i, limit, rates_total, prev_calculated, close);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
// Validate User Inputs ...
result =
//
// L1 ...
// Short Cycle ...
(
//
l1Method == X_PERIOD_AUTO
? l1Period == NULL
: l1Period != NULL && l1Method != X_PERIOD_NOTHING
//
)
//
&&
//
// L2 ...
// Medium Cycle ...
(
//
l2Method == X_PERIOD_AUTO
? l2Period == NULL
: l2Period != NULL && l2Method != X_PERIOD_NOTHING
//
)
//
&&
//
// L3 ...
// Long Cycle ...
(
//
l3Method == X_PERIOD_AUTO
? l3Period == NULL
: l3Period != NULL && l3Method != X_PERIOD_NOTHING
//
)
//
&&
//
// L4 ...
// Hind Cycle ...
(
//
l4Method == X_PERIOD_AUTO
? l4Period == NULL
: l4Period != NULL && l4Method != X_PERIOD_NOTHING
//
)
//
&&
//
// Validate Ribbon ...
(
//
ribbonMode != X_MA_NOTHING
//
)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 1;
//
result = MathMax(result, mL1Candles);
result = MathMax(result, mL2Candles);
result = MathMax(result, mL3Candles);
result = MathMax(result, mL4Candles);
//
return result;
}
//
// Initial Multi Time Frame Cycles Periods ...
void InitialCycles()
{
//
// Calculate Current Period Secconds ...
currentPeriodSecconds = PeriodSeconds(_Period);
//
// Nearest ...
// Calculate Cycle 1 Requirements ...
if (mL1Period == NULL)
{
//
if (l1Method == X_PERIOD_AUTO)
{
mL1Period = GetNearestTimeFrame(_Period);
}
else
{
mL1Period = l1Period;
}
//
mL1PeriodSecconds = PeriodSeconds(mL1Period);
//
mL1Candles = mL1PeriodSecconds / currentPeriodSecconds;
}
//
// Mediest ...
// Calculate Cycle 2 Requirements ...
if (mL2Period == NULL)
{
//
if (l2Method == X_PERIOD_AUTO)
{
mL2Period = GetMediestTimeFrame(_Period);
}
else
{
mL2Period = l2Period;
}
//
mL2PeriodSecconds = PeriodSeconds(mL2Period);
//
mL2Candles = mL2PeriodSecconds / currentPeriodSecconds;
}
//
// Farest ...
// Calculate Cycle 3 Requirements ...
if (mL3Period == NULL)
{
//
if (l3Method == X_PERIOD_AUTO)
{
mL3Period = GetFarestTimeFrame(_Period);
}
else
{
mL3Period = l3Period;
}
//
mL3PeriodSecconds = PeriodSeconds(mL3Period);
//
mL3Candles = mL3PeriodSecconds / currentPeriodSecconds;
}
//
// HindMost ...
// Calculate Cycle 4 Requirements ...
if (mL4Period == NULL)
{
//
if (l4Method == X_PERIOD_AUTO)
{
mL4Period = GetHindmostTimeFrame(_Period);
}
else
{
mL4Period = l4Period;
}
//
mL4PeriodSecconds = PeriodSeconds(mL4Period);
//
mL4Candles = mL4PeriodSecconds / currentPeriodSecconds;
}
//
string comment = GenerateCyclesRepresentation();
Comment(comment);
}
//
bool InitRibbons()
{
//
bool result = false;
//
if (mMRBLength <= 0)
{
return result;
}
//
// RIBBON 1 ...
// High ...
result = InitMaHandler(
rb1Handler,
mMRBLength,
ribbonMode,
PRICE_HIGH);
if (!result)
{
return result;
}
//
// RIBBON 2 ...
// Open ...
result = InitMaHandler(
rb2Handler,
mMRBLength,
ribbonMode,
PRICE_OPEN);
if (!result)
{
return result;
}
//
// RIBBON 3 ...
// Close ...
result = InitMaHandler(
rb3Handler,
mMRBLength,
ribbonMode,
PRICE_CLOSE);
if (!result)
{
return result;
}
//
// RIBBON 4 ...
// Median ...
result = InitMaHandler(
rb4Handler,
mMRBLength,
ribbonMode,
PRICE_MEDIAN);
if (!result)
{
return result;
}
//
// RIBBON 5 ...
// Typical ...
result = InitMaHandler(
rb5Handler,
mMRBLength,
ribbonMode,
PRICE_TYPICAL);
if (!result)
{
return result;
}
//
// RIBBON 6 ...
// Low ...
result = InitMaHandler(
rb6Handler,
mMRBLength,
ribbonMode,
PRICE_LOW);
//
return result;
}
//
bool InitSSLChannel()
{
//
bool result = false;
//
if (mSSLCLength <= 0)
{
return result;
}
//
// SSLUP ...
result = InitMaHandler(
sslcUpHandler,
mSSLCLength,
sslcMode,
sslcUpAppliedTo);
if (!result)
{
return result;
}
//
// SSLDOWN ...
result = InitMaHandler(
sslcDownHandler,
mSSLCLength,
sslcMode,
sslcDownAppliedTo);
//
return result;
}
//
bool InitHullTrend()
{
//
bool result = false;
//
if (mHULLLength <= 0)
{
return result;
}
//
mUpZHull = new XSCHull();
mUpZHull.Init(
mHULLLength,
hullDivisor);
//
mDownZHull = new XSCHull();
mDownZHull.Init(
mHULLLength,
hullDivisor);
//
result = true;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// RANGE ...
//
// PEAKS and VALES ...
ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE;
//
// PEAKS ...
ArraySetAsSeries(peaksBuffer, true);
SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA);
PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225);
PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
//
// VALES ...
ArraySetAsSeries(valesBuffer, true);
SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA);
PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225);
PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
//
// SUPPORT and RESISTANCE ...
//
//
// RESISTANCE ...
ArraySetAsSeries(rBuffer, true);
SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA);
PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
// RESISTANCE Color ...
ArraySetAsSeries(rColorBuffer, true);
SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX);
//
// SUPPORT ...
ArraySetAsSeries(sBuffer, true);
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
PlotIndexSetInteger(sBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false);
//
// SUPPORT Color ...
ArraySetAsSeries(sColorBuffer, true);
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
//
// FIBBO Levels ...
//
// LEVEL 1 ...
//
// Buffer ...
ArraySetAsSeries(fl1Buffer, true);
SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_SHOW_DATA, showFibo1Levels);
//
// Color ...
ArraySetAsSeries(fl1ColorBuffer, true);
SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX);
//
// LEVEL 2 ...
//
// BULLISH ...
ArraySetAsSeries(fl2Buffer, true);
SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_SHOW_DATA, showFibo2Levels);
//
// BULLISH Color ...
ArraySetAsSeries(fl2ColorBuffer, true);
SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX);
//
// LEVEL 3 ...
//
// BULLISH ...
ArraySetAsSeries(fl3Buffer, true);
SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_SHOW_DATA, showFibo3Levels);
//
// BULLISH Color ...
ArraySetAsSeries(fl3ColorBuffer, true);
SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX);
//
// SHORT Buffers ...
//
// HIGH ...
ArraySetAsSeries(sHHBuffer, true);
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(sHHColorBuffer, true);
SetIndexBuffer(sHHColorBufferIndex, sHHColorBuffer, INDICATOR_COLOR_INDEX);
//
// LOW ...
ArraySetAsSeries(sLLBuffer, true);
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(sLLColorBuffer, true);
SetIndexBuffer(sLLColorBufferIndex, sLLColorBuffer, INDICATOR_COLOR_INDEX);
//
// MEDIUM Buffer ...
//
// HIGH ...
ArraySetAsSeries(mHHBuffer, true);
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(mHHColorBuffer, true);
SetIndexBuffer(mHHColorBufferIndex, mHHColorBuffer, INDICATOR_COLOR_INDEX);
//
// LOW ...
ArraySetAsSeries(mLLBuffer, true);
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(mLLColorBuffer, true);
SetIndexBuffer(mLLColorBufferIndex, mLLColorBuffer, INDICATOR_COLOR_INDEX);
//
// LONG Buffer ...
//
// HIGH ...
ArraySetAsSeries(lHHBuffer, true);
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(lHHColorBuffer, true);
SetIndexBuffer(lHHColorBufferIndex, lHHColorBuffer, INDICATOR_COLOR_INDEX);
//
// LOW ...
ArraySetAsSeries(lLLBuffer, true);
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(lLLColorBuffer, true);
SetIndexBuffer(lLLColorBufferIndex, lLLColorBuffer, INDICATOR_COLOR_INDEX);
//
// HIND Buffer ...
//
// HIGH ...
ArraySetAsSeries(hHHBuffer, true);
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(hHHColorBuffer, true);
SetIndexBuffer(hHHColorBufferIndex, hHHColorBuffer, INDICATOR_COLOR_INDEX);
//
// LOW ...
ArraySetAsSeries(hLLBuffer, true);
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
//
ArraySetAsSeries(hLLColorBuffer, true);
SetIndexBuffer(hLLColorBufferIndex, hLLColorBuffer, INDICATOR_COLOR_INDEX);
//
// XSTR ...
//
// FILLINGS ...
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fillingBufferPlotIndex, PLOT_SHOW_DATA, false);
//
// MAIN ...
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA);
PlotIndexSetInteger(trendBufferPlotIndex, PLOT_SHOW_DATA, showTrends);
SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX);
//
// RIBBON 1 ...
//
ArraySetAsSeries(ribbon1Buffer, true);
SetIndexBuffer(ribbon1BufferIndex, ribbon1Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(ribbon1BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(ribbon1BufferPlotIndex, PLOT_SHOW_DATA, showRibbons);
//
ArraySetAsSeries(ribbon1ColorBuffer, true);
SetIndexBuffer(ribbon1ColorBufferIndex, ribbon1ColorBuffer, INDICATOR_COLOR_INDEX);
//
// RIBBON 2 ...
//
ArraySetAsSeries(ribbon2Buffer, true);
SetIndexBuffer(ribbon2BufferIndex, ribbon2Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(ribbon2BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(ribbon2BufferPlotIndex, PLOT_SHOW_DATA, showRibbons);
//
ArraySetAsSeries(ribbon2ColorBuffer, true);
SetIndexBuffer(ribbon2ColorBufferIndex, ribbon2ColorBuffer, INDICATOR_COLOR_INDEX);
//
// RIBBON 3 ...
//
ArraySetAsSeries(ribbon3Buffer, true);
SetIndexBuffer(ribbon3BufferIndex, ribbon3Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(ribbon3BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(ribbon3BufferPlotIndex, PLOT_SHOW_DATA, showRibbons);
//
ArraySetAsSeries(ribbon3ColorBuffer, true);
SetIndexBuffer(ribbon3ColorBufferIndex, ribbon3ColorBuffer, INDICATOR_COLOR_INDEX);
//
// RIBBON 4 ...
//
ArraySetAsSeries(ribbon4Buffer, true);
SetIndexBuffer(ribbon4BufferIndex, ribbon4Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(ribbon4BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(ribbon4BufferPlotIndex, PLOT_SHOW_DATA, showRibbons);
//
ArraySetAsSeries(ribbon4ColorBuffer, true);
SetIndexBuffer(ribbon4ColorBufferIndex, ribbon4ColorBuffer, INDICATOR_COLOR_INDEX);
//
// RIBBON 5 ...
//
ArraySetAsSeries(ribbon5Buffer, true);
SetIndexBuffer(ribbon5BufferIndex, ribbon5Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(ribbon5BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(ribbon5BufferPlotIndex, PLOT_SHOW_DATA, showRibbons);
//
ArraySetAsSeries(ribbon5ColorBuffer, true);
SetIndexBuffer(ribbon5ColorBufferIndex, ribbon5ColorBuffer, INDICATOR_COLOR_INDEX);
//
// RIBBON 6 ...
//
ArraySetAsSeries(ribbon6Buffer, true);
SetIndexBuffer(ribbon6BufferIndex, ribbon6Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(ribbon6BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(ribbon6BufferPlotIndex, PLOT_SHOW_DATA, showRibbons);
//
ArraySetAsSeries(ribbon6ColorBuffer, true);
SetIndexBuffer(ribbon6ColorBufferIndex, ribbon6ColorBuffer, INDICATOR_COLOR_INDEX);
//
// XSSLC ...
//
// UP ...
//
ArraySetAsSeries(sslcUpBuffer, true);
SetIndexBuffer(sslcUpBufferIndex, sslcUpBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(sslcUpBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(sslcUpBufferPlotIndex, PLOT_SHOW_DATA, showSSLChannel);
//
ArraySetAsSeries(sslcUpColorBuffer, true);
SetIndexBuffer(sslcUpColorBufferIndex, sslcUpColorBuffer, INDICATOR_COLOR_INDEX);
//
// DOWN ...
//
ArraySetAsSeries(sslcDownBuffer, true);
SetIndexBuffer(sslcDownBufferIndex, sslcDownBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(sslcDownBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(sslcDownBufferPlotIndex, PLOT_SHOW_DATA, showSSLChannel);
//
ArraySetAsSeries(sslcDownColorBuffer, true);
SetIndexBuffer(sslcDownColorBufferIndex, sslcDownColorBuffer, INDICATOR_COLOR_INDEX);
//
// XHULL ...
//
// UP ...
//
SetIndexBuffer(hullUpZoneBufferIndex, hullUpZoneBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hullUpZoneBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(hullUpZoneBufferPlotIndex, PLOT_SHOW_DATA, showHull);
//
SetIndexBuffer(hullUpZoneColorBufferIndex, hullUpZoneColorBuffer, INDICATOR_COLOR_INDEX);
//
// DOWN ...
//
SetIndexBuffer(hullDownZoneBufferIndex, hullDownZoneBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hullDownZoneBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(hullDownZoneBufferPlotIndex, PLOT_SHOW_DATA, showHull);
//
SetIndexBuffer(hullDownZoneColorBufferIndex, hullDownZoneColorBuffer, INDICATOR_COLOR_INDEX);
//
// XHK ...
//
// Candles Color ...
ArraySetAsSeries(hkCandleColorBuffer, true);
SetIndexBuffer(hkCandleColorBufferIndex, hkCandleColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(hkCandlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
//
PlotIndexSetInteger(hkCandlesBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(hkCandleColorBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(hkOpenBuffer, true);
PlotIndexSetInteger(hkOpenBufferIndex, PLOT_SHOW_DATA, false);
SetIndexBuffer(hkOpenBufferIndex, hkOpenBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(hkHighBuffer, true);
SetIndexBuffer(hkHighBufferIndex, hkHighBuffer, INDICATOR_DATA);
PlotIndexSetInteger(hkHighBufferIndex, PLOT_SHOW_DATA, false);
//
// Close ...
ArraySetAsSeries(hkCloseBuffer, true);
SetIndexBuffer(hkCloseBufferIndex, hkCloseBuffer, INDICATOR_DATA);
PlotIndexSetInteger(hkCloseBufferIndex, PLOT_SHOW_DATA, false);
//
// Low ...
ArraySetAsSeries(hkLowBuffer, true);
SetIndexBuffer(hkLowBufferIndex, hkLowBuffer, INDICATOR_DATA);
PlotIndexSetInteger(hkLowBufferIndex, PLOT_SHOW_DATA, false);
//
// DATA Buffers ...
//
// ATR ...
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
// TREND ...
SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS);
//
// UP ...
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
//
// DOWN ...
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
//
// PRICE ...
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
//
// SSLCDOWNMA ...
ArraySetAsSeries(sslcUpMaBuffer, true);
SetIndexBuffer(sslcUpMaBufferIndex, sslcUpMaBuffer, INDICATOR_CALCULATIONS);
//
// SSLCUPMA ...
ArraySetAsSeries(sslcDownMaBuffer, true);
SetIndexBuffer(sslcDownMaBufferIndex, sslcDownMaBuffer, INDICATOR_CALCULATIONS);
//
// SSLCKPI ...
ArraySetAsSeries(sslcKpiBuffer, true);
SetIndexBuffer(sslcKpiBufferIndex, sslcKpiBuffer, INDICATOR_CALCULATIONS);
//
// STATE Buffers ...
//
// PEAKS ...
ArraySetAsSeries(peaksStateBuffer, true);
SetIndexBuffer(peaksStateBufferIndex, peaksStateBuffer, INDICATOR_CALCULATIONS);
//
// VALES ...
ArraySetAsSeries(valesStateBuffer, true);
SetIndexBuffer(valesStateBufferIndex, valesStateBuffer, INDICATOR_CALCULATIONS);
//
// CYCLES ...
//
// SHORT ...
//
ArraySetAsSeries(sHHStateBuffer, true);
SetIndexBuffer(sHHStateBufferIndex, sHHStateBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(sLLStateBuffer, true);
SetIndexBuffer(sLLStateBufferIndex, sLLStateBuffer, INDICATOR_CALCULATIONS);
//
// MEDIUM ...
//
ArraySetAsSeries(mHHStateBuffer, true);
SetIndexBuffer(mHHStateBufferIndex, mHHStateBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(mLLStateBuffer, true);
SetIndexBuffer(mLLStateBufferIndex, mLLStateBuffer, INDICATOR_CALCULATIONS);
//
// LONG ...
//
ArraySetAsSeries(lHHStateBuffer, true);
SetIndexBuffer(lHHStateBufferIndex, lHHStateBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(lLLStateBuffer, true);
SetIndexBuffer(lLLStateBufferIndex, lLLStateBuffer, INDICATOR_CALCULATIONS);
//
// HIND ...
//
ArraySetAsSeries(hHHStateBuffer, true);
SetIndexBuffer(hHHStateBufferIndex, hHHStateBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(hLLStateBuffer, true);
SetIndexBuffer(hLLStateBufferIndex, hLLStateBuffer, INDICATOR_CALCULATIONS);
//
// XSTR ...
SetIndexBuffer(strTrendStateBufferIndex, strTrendStateBuffer, INDICATOR_CALCULATIONS);
//
// XMBR ...
//
// RIBBON 1 _ (High) ...
ArraySetAsSeries(rb1StateBuffer, true);
SetIndexBuffer(rb1StateBufferIndex, rb1StateBuffer, INDICATOR_CALCULATIONS);
//
// RIBBON 2 _ (Open) ...
ArraySetAsSeries(rb2StateBuffer, true);
SetIndexBuffer(rb2StateBufferIndex, rb2StateBuffer, INDICATOR_CALCULATIONS);
//
// RIBBON 3 _ (Close) ...
ArraySetAsSeries(rb3StateBuffer, true);
SetIndexBuffer(rb3StateBufferIndex, rb3StateBuffer, INDICATOR_CALCULATIONS);
//
// RIBBON 4 _ (Median) ...
ArraySetAsSeries(rb4StateBuffer, true);
SetIndexBuffer(rb4StateBufferIndex, rb4StateBuffer, INDICATOR_CALCULATIONS);
//
// RIBBON 5 _ (Typical) ...
ArraySetAsSeries(rb5StateBuffer, true);
SetIndexBuffer(rb5StateBufferIndex, rb5StateBuffer, INDICATOR_CALCULATIONS);
//
// RIBBON 6 _ (Low) ...
ArraySetAsSeries(rb6StateBuffer, true);
SetIndexBuffer(rb6StateBufferIndex, rb6StateBuffer, INDICATOR_CALCULATIONS);
//
// XHULL ...
//
// UP Zone ...
SetIndexBuffer(hullUpStateBufferIndex, hullUpStateBuffer, INDICATOR_CALCULATIONS);
//
// DOWN Zone ...
SetIndexBuffer(hullDownStateBufferIndex, hullDownStateBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// Calculate ...
//
// Calculate Short Cycle ...
CalculateShortCycle(bar_index);
//
// Calculate Medium Cycle ...
CalculateMediumCycle(bar_index);
//
// Calculate Long Cycle ...
CalculateLongCycle(bar_index);
//
// Calculate Hind Cycle ...
CalculateHindCycle(bar_index);
//
// Calculate Peaks and Vales ...
CalculatePeaksAndVales(bar_index);
//
// Calculate Fibonnaci ...
CalculateFibonacci(bar_index);
}
//
// START Calculation Parts ...
//
//
// SHORT Cycle ...
void CalculateShortCycle(
int bar_index // Selected Bar Index
)
{
//
ENUM_TIMEFRAMES mPeriod = mL1Period;
//
double hhValue = GetCycleHHC(
bar_index,
mPeriod);
//
double llValue = GetCycleLLC(
bar_index,
mPeriod);
//
double lastHH = mLastSHH;
double lastLL = mLastSLL;
//
double mHHState = EMPTY_VALUE;
double mhhColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (hhValue == lastHH)
{
mhhColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (hhValue > lastHH)
{
mhhColorIDX = 2;
}
else if (hhValue < lastHH)
{
mhhColorIDX = 3;
}
//
mHHState = mhhColorIDX;
}
else
{
mhhColorIDX = mHideColorIDX;
}
//
double mLLState = EMPTY_VALUE;
double mllColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (llValue == lastLL)
{
mllColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (llValue > lastLL)
{
mllColorIDX = 2;
}
else if (llValue < lastLL)
{
mllColorIDX = 3;
}
//
mLLState = mllColorIDX;
}
else
{
mllColorIDX = mHideColorIDX;
}
//
mLastSHH = hhValue;
mLastSLL = llValue;
//
sHHBuffer[bar_index] = hhValue;
sLLBuffer[bar_index] = llValue;
sHHStateBuffer[bar_index] = mHHState;
sLLStateBuffer[bar_index] = mLLState;
sHHColorBuffer[bar_index] = mhhColorIDX;
sLLColorBuffer[bar_index] = mllColorIDX;
}
//
// MEDIUM Cycle ...
void CalculateMediumCycle(
int bar_index // Selected Bar Index
)
{
//
ENUM_TIMEFRAMES mPeriod = mL2Period;
//
double hhValue = GetCycleHHC(
bar_index,
mPeriod);
//
double llValue = GetCycleLLC(
bar_index,
mPeriod);
//
double lastHH = mLastMHH;
double lastLL = mLastMLL;
//
double mHHState = EMPTY_VALUE;
double mhhColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (hhValue == lastHH)
{
mhhColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (hhValue > lastHH)
{
mhhColorIDX = 2;
}
else if (hhValue < lastHH)
{
mhhColorIDX = 3;
}
//
mHHState = mhhColorIDX;
}
else
{
mhhColorIDX = mHideColorIDX;
}
//
double mLLState = EMPTY_VALUE;
double mllColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (llValue == lastLL)
{
mllColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (llValue > lastLL)
{
mllColorIDX = 2;
}
else if (llValue < lastLL)
{
mllColorIDX = 3;
}
//
mLLState = mllColorIDX;
}
else
{
mllColorIDX = mHideColorIDX;
}
//
mLastMHH = hhValue;
mLastMLL = llValue;
//
mHHBuffer[bar_index] = hhValue;
mLLBuffer[bar_index] = llValue;
mHHStateBuffer[bar_index] = mHHState;
mLLStateBuffer[bar_index] = mLLState;
mHHColorBuffer[bar_index] = mhhColorIDX;
mLLColorBuffer[bar_index] = mllColorIDX;
}
//
// LONG Cycle ...
void CalculateLongCycle(
int bar_index // Selected Bar Index
)
{
//
ENUM_TIMEFRAMES mPeriod = mL3Period;
//
double hhValue = GetCycleHHC(
bar_index,
mPeriod);
//
double llValue = GetCycleLLC(
bar_index,
mPeriod);
//
double lastHH = mLastLHH;
double lastLL = mLastLLL;
//
double mHHState = EMPTY_VALUE;
double mhhColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (hhValue == lastHH)
{
mhhColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (hhValue > lastHH)
{
mhhColorIDX = 2;
}
else if (hhValue < lastHH)
{
mhhColorIDX = 3;
}
//
mHHState = mhhColorIDX;
}
else
{
mhhColorIDX = mHideColorIDX;
}
//
double mLLState = EMPTY_VALUE;
double mllColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (llValue == lastLL)
{
mllColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (llValue > lastLL)
{
mllColorIDX = 2;
}
else if (llValue < lastLL)
{
mllColorIDX = 3;
}
//
mLLState = mllColorIDX;
}
else
{
mllColorIDX = mHideColorIDX;
}
//
mLastLHH = hhValue;
mLastLLL = llValue;
//
lHHBuffer[bar_index] = hhValue;
lLLBuffer[bar_index] = llValue;
lHHStateBuffer[bar_index] = mHHState;
lLLStateBuffer[bar_index] = mLLState;
lHHColorBuffer[bar_index] = mhhColorIDX;
lLLColorBuffer[bar_index] = mllColorIDX;
}
//
// HIND Cycle ...
void CalculateHindCycle(
int bar_index // Selected Bar Index
)
{
//
ENUM_TIMEFRAMES mPeriod = mL4Period;
//
double hhValue = GetCycleHHC(
bar_index,
mPeriod);
//
double llValue = GetCycleLLC(
bar_index,
mPeriod);
//
double lastHH = mLastHHH;
double lastLL = mLastHLL;
//
double mHHState = EMPTY_VALUE;
double mhhColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (hhValue == lastHH)
{
mhhColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (hhValue > lastHH)
{
mhhColorIDX = 2;
}
else if (hhValue < lastHH)
{
mhhColorIDX = 3;
}
//
mHHState = mhhColorIDX;
}
else
{
mhhColorIDX = mHideColorIDX;
}
//
double mLLState = EMPTY_VALUE;
double mllColorIDX = mHideColorIDX;
if (showLevels)
{
//
if (llValue == lastLL)
{
mllColorIDX = showConsolidations ? 1 : mHideColorIDX;
}
else if (llValue > lastLL)
{
mllColorIDX = 2;
}
else if (llValue < lastLL)
{
mllColorIDX = 3;
}
//
mLLState = mllColorIDX;
}
else
{
mllColorIDX = mHideColorIDX;
}
//
mLastHHH = hhValue;
mLastHLL = llValue;
//
hHHBuffer[bar_index] = hhValue;
hLLBuffer[bar_index] = llValue;
hHHStateBuffer[bar_index] = mHHState;
hLLStateBuffer[bar_index] = mLLState;
hHHColorBuffer[bar_index] = mhhColorIDX;
hLLColorBuffer[bar_index] = mllColorIDX;
}
//
// Calculate Peaks and Values ...
void CalculatePeaksAndVales(
int bar_index // Bar Index
)
{
//
// Retrieve Requirements ...
//
// Short ...
double sHHValue = sHHBuffer[bar_index];
double sLLValue = sLLBuffer[bar_index];
//
// Medium ...
double mHHValue = mHHBuffer[bar_index];
double mLLValue = mLLBuffer[bar_index];
//
// Long ...
double lHHValue = lHHBuffer[bar_index];
double lLLValue = lLLBuffer[bar_index];
//
// Hind ...
double hHHValue = hHHBuffer[bar_index];
double hLLValue = hLLBuffer[bar_index];
//
double rColorIDX = mHideColorIDX;
double sColorIDX = mHideColorIDX;
//
// RESISTANCE ...
double rValue = (sHHValue + mHHValue + lHHValue + hHHValue) / 4;
//
// PEAKS ...
bool isPeak = rValue == hHHValue &&
hHHValue == lHHValue &&
lHHValue == mHHValue &&
mHHValue == sHHValue;
//
if (isPeak && lastPeak != rValue)
{
//
rColorIDX = 1;
lastPeak = rValue;
}
//
// SUPPORT ...
double sValue = (sLLValue + mLLValue + lLLValue + hLLValue) / 4;
//
// VALES ...
bool isVale = sValue == hLLValue &&
hLLValue == lLLValue &&
lLLValue == mLLValue &&
mLLValue == sLLValue;
//
if (isVale && lastVale != sValue)
{
//
sColorIDX = 1;
lastVale = sValue;
}
//
rBuffer[bar_index] = rValue;
sBuffer[bar_index] = sValue;
peaksBuffer[bar_index] = lastPeak;
valesBuffer[bar_index] = lastVale;
//
if (showPeaksAndVales)
{
//
rColorBuffer[bar_index] = rColorIDX;
sColorBuffer[bar_index] = sColorIDX;
}
else
{
//
rColorBuffer[bar_index] = mHideColorIDX;
sColorBuffer[bar_index] = mHideColorIDX;
}
}
//
// Calculate Fibonacci Level 1 ...
void CalculateFibonacci(
int bar_index // Bar Index
)
{
//
// Select Requirements ...
double upPrice = peaksBuffer[bar_index];
double downPrice = valesBuffer[bar_index];
//
// Level 1 ...
double fibLevel1Value = GetFibonacciLevel(
upPrice,
downPrice,
fiboLevel1,
1);
//
// Level 2 ...
double fibLevel2Value = GetFibonacciLevel(
upPrice,
downPrice,
fiboLevel2,
1);
//
// Level 3 ...
double fibLevel3Value = GetFibonacciLevel(
upPrice,
downPrice,
fiboLevel3,
1);
//
fl1Buffer[bar_index] = fibLevel1Value;
fl2Buffer[bar_index] = fibLevel2Value;
fl3Buffer[bar_index] = fibLevel3Value;
//
double fl1ColorIdx = showFibo1Levels ? 1 : mHideColorIDX;
double fl2ColorIdx = showFibo2Levels ? 1 : mHideColorIDX;
double fl3ColorIdx = showFibo3Levels ? 1 : mHideColorIDX;
//
fl1ColorBuffer[bar_index] = fl1ColorIdx;
fl2ColorBuffer[bar_index] = fl2ColorIdx;
fl3ColorBuffer[bar_index] = fl3ColorIdx;
}
//
// XSTR ...
bool CalculateXSTR(
const int rates_total,
const int prev_calculated,
const double &open[],
const double &high[],
const double &low[],
const double &close[] //
)
{
//
bool result = false;
//
int numOfRequiredAtrs;
if (prev_calculated > rates_total || prev_calculated < 0)
{
numOfRequiredAtrs = rates_total;
}
else
{
//
numOfRequiredAtrs = rates_total - prev_calculated;
if (prev_calculated > 0)
{
numOfRequiredAtrs++;
}
}
//
// Checking for stop ...
if (IsStopped())
{
return result;
}
//
// Check Number of items Copy or not ...
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
if (copiedATRs <= 0)
{
return result;
}
//
//
int limit;
//
// checking for the limit start of calculation of an indicator ...
if (prev_calculated > rates_total || prev_calculated <= 0)
{
//
// starting index for calculation of all bars ...
limit = maxLength;
}
else
{
//
// starting number for calculation of new bars
limit = prev_calculated - 1;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
//
// Calculated Price ...
double price = GetAppliedPrice(
trendPriceAppliedTo,
open,
high,
low,
close,
i);
// price = (high[i] + low[i]) / 2;
priceBuffer[i] = price;
//
double atr = atrBuffer[i];
//
// Up ...
upBuffer[i] = price + (trendMultiplier * atr);
//
// Down ...
downBuffer[i] = price - (trendMultiplier * atr);
//
if (close[i] > upBuffer[i - 1])
{
//
trendStateBuffer[i] = 1;
if (trendStateBuffer[i - 1] == -1)
{
changeOfTrend = 1;
}
}
else if (close[i] < downBuffer[i - 1])
{
//
trendStateBuffer[i] = -1;
if (trendStateBuffer[i - 1] == 1)
{
changeOfTrend = 1;
}
}
else if (trendStateBuffer[i - 1] == 1)
{
//
trendStateBuffer[i] = 1;
changeOfTrend = 0;
}
else if (trendStateBuffer[i - 1] == -1)
{
//
trendStateBuffer[i] = -1;
changeOfTrend = 0;
}
//
// Down Trend Starting ...
if (trendStateBuffer[i] < 0 && trendStateBuffer[i - 1] > 0)
{
startBearishTrend = 1;
}
else
{
startBearishTrend = 0;
}
//
// Up Trend Starting ...
if (trendStateBuffer[i] > 0 && trendStateBuffer[i - 1] < 0)
{
startBullishTrend = 1;
}
else
{
startBullishTrend = 0;
}
//
if (trendStateBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
{
downBuffer[i] = downBuffer[i - 1];
}
//
if (trendStateBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
{
upBuffer[i] = upBuffer[i - 1];
}
//
if (startBearishTrend == 1)
{
upBuffer[i] = priceBuffer[i] + (trendMultiplier * atr);
}
//
if (startBullishTrend == 1)
{
downBuffer[i] = priceBuffer[i] - (trendMultiplier * atr);
}
//
// Draw the indicator ...
//
double colorIDX = 0;
double state = EMPTY_VALUE;
trendColorBuffer[i] = colorIDX;
//
if (trendStateBuffer[i] == 1)
{
//
trendBuffer[i] = downBuffer[i];
if (changeOfTrend == 1)
{
//
trendBuffer[i - 1] = trendBuffer[i - 2];
changeOfTrend = 0;
//
state = 1;
}
//
colorIDX = 1;
}
else if (trendStateBuffer[i] == -1)
{
//
trendBuffer[i] = upBuffer[i];
if (changeOfTrend == 1)
{
//
trendBuffer[i - 1] = trendBuffer[i - 2];
changeOfTrend = 0;
//
state = 2;
}
//
colorIDX = 2;
}
//
if (showTrends)
{
trendColorBuffer[i] = colorIDX;
}
strTrendStateBuffer[i] = state;
//
// Filling ...
if (fillTrends)
{
//
fillUpBuffer[i] = trendBuffer[i];
fillDownBuffer[i] = close[i];
}
else
{
//
fillUpBuffer[i] = EMPTY_VALUE;
fillDownBuffer[i] = EMPTY_VALUE;
}
}
//
result = true;
//
return true;
}
//
XMRBColorInfo GetRibbonColorIndex(
double value,
const double h,
const double l //
)
{
//
XMRBColorInfo result;
//
result.state = EMPTY_VALUE;
result.clr = mHideColorIDX;
//
// Color Indexes ...
// 0 => HIDE
// 1 => NEUTURAL
// 2 => BULLISH
// 3 => BEARISH
//
result.clr = 1;
//
if (value < l && value < h)
{
result.clr = 2;
}
else if (value > h && value > l)
{
result.clr = 3;
}
else if (value < h && value > l)
{
result.clr = 1;
}
//
result.state = result.clr;
//
if (!showRibbons)
{
result.clr = mHideColorIDX;
}
//
return result;
}
//
// Calculate Ribbons Color ...
void CalculateRibbonsColors(
int bar_index, // Bar Index
const double &high[],
const double &low[] //
)
{
//
double tmpVal;
XMRBColorInfo tmpColorIDX;
//
double h = high[bar_index];
double l = low[bar_index];
//
// RIBBON 1 ...
tmpVal = ribbon1Buffer[bar_index];
tmpColorIDX = GetRibbonColorIndex(
tmpVal,
h,
l);
rb1StateBuffer[bar_index] = tmpColorIDX.state;
ribbon1ColorBuffer[bar_index] = tmpColorIDX.clr;
//
// RIBBON 2 ...
tmpVal = ribbon2Buffer[bar_index];
tmpColorIDX = GetRibbonColorIndex(
tmpVal,
h,
l);
rb2StateBuffer[bar_index] = tmpColorIDX.state;
ribbon2ColorBuffer[bar_index] = tmpColorIDX.clr;
//
// RIBBON 3 ...
tmpVal = ribbon3Buffer[bar_index];
tmpColorIDX = GetRibbonColorIndex(
tmpVal,
h,
l);
rb3StateBuffer[bar_index] = tmpColorIDX.state;
ribbon3ColorBuffer[bar_index] = tmpColorIDX.clr;
//
// RIBBON 4 ...
tmpVal = ribbon4Buffer[bar_index];
tmpColorIDX = GetRibbonColorIndex(
tmpVal,
h,
l);
rb4StateBuffer[bar_index] = tmpColorIDX.state;
ribbon4ColorBuffer[bar_index] = tmpColorIDX.clr;
//
// RIBBON 5 ...
tmpVal = ribbon5Buffer[bar_index];
tmpColorIDX = GetRibbonColorIndex(
tmpVal,
h,
l);
rb5StateBuffer[bar_index] = tmpColorIDX.state;
ribbon5ColorBuffer[bar_index] = tmpColorIDX.clr;
//
// RIBBON 6 ...
tmpVal = ribbon6Buffer[bar_index];
tmpColorIDX = GetRibbonColorIndex(
tmpVal,
h,
l);
rb6StateBuffer[bar_index] = tmpColorIDX.state;
ribbon6ColorBuffer[bar_index] = tmpColorIDX.clr;
}
//
// Calculate SSL Channel ...
void CalculateSSLC(
int bar_index, // Selected Bar Index
int limit,
int ratesTotal,
int prevCalculated,
const double &close[])
{
//
double upMaValue = sslcUpMaBuffer[bar_index];
double downMaValue = sslcDownMaBuffer[bar_index];
//
double closeValue = close[bar_index];
//
double kpiValue;
if (closeValue > upMaValue)
{
kpiValue = 1;
}
else if (closeValue < downMaValue)
{
kpiValue = -1;
}
else
{
kpiValue = sslcKpiBuffer[bar_index + 1];
}
//
sslcKpiBuffer[bar_index] = kpiValue;
//
double upValue = kpiValue < 0 ? downMaValue : upMaValue;
sslcUpBuffer[bar_index] = upValue;
//
double downValue = kpiValue < 0 ? upMaValue : downMaValue;
sslcDownBuffer[bar_index] = downValue;
//
if (showSSLChannel)
{
//
sslcUpColorBuffer[bar_index] = 1;
sslcDownColorBuffer[bar_index] = 1;
}
else
{
//
sslcUpColorBuffer[bar_index] = mHideColorIDX;
sslcDownColorBuffer[bar_index] = mHideColorIDX;
}
}
//
// Calculate XHULL ...
void CalculateHull(
int bar_index, // Selected Bar Index
int ratesTotal, // Total Rates
double upPrice, // Up Price ...
double downPrice // Down Price ...
)
{
//
double upValue = mUpZHull.Calculate(
upPrice,
bar_index,
ratesTotal);
hullUpZoneBuffer[bar_index] = upValue;
double upColorIDX = (bar_index > 0)
? (hullUpZoneBuffer[bar_index] > hullUpZoneBuffer[bar_index - 1])
? 2
: (hullUpZoneBuffer[bar_index] < hullUpZoneBuffer[bar_index - 1])
? 3
: hullUpZoneColorBuffer[bar_index - 1]
: 1;
//
double downValue = mDownZHull.Calculate(
downPrice,
bar_index,
ratesTotal);
hullDownZoneBuffer[bar_index] = downValue;
double downColorIDX = (bar_index > 0)
? (hullDownZoneBuffer[bar_index] > hullDownZoneBuffer[bar_index - 1])
? 2
: (hullDownZoneBuffer[bar_index] < hullDownZoneBuffer[bar_index - 1])
? 3
: hullDownZoneColorBuffer[bar_index - 1]
: 1;
//
if (showHull)
{
//
hullUpZoneColorBuffer[bar_index] = upColorIDX;
hullDownZoneColorBuffer[bar_index] = downColorIDX;
}
else
{
//
hullUpZoneColorBuffer[bar_index] = mHideColorIDX;
hullDownZoneColorBuffer[bar_index] = mHideColorIDX;
}
}
//
// Calculate HikenAshi Buffers ...
void CalculateHikenAshi(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[])
{
//
double mPrevHKOpenValue;
double mPrevHKCloseValue;
//
if (ArraySize(open) <= bar_index + 1)
{
//
mPrevHKOpenValue = 0;
mPrevHKCloseValue = 0;
}
else
{
//
mPrevHKOpenValue = hkOpenBuffer[bar_index + 1];
mPrevHKCloseValue = hkCloseBuffer[bar_index + 1];
}
//
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
//
hkOpenBuffer[bar_index] = mHKOpenValue;
hkHighBuffer[bar_index] = mHKHighValue;
hkLowBuffer[bar_index] = mHKLowValue;
hkCloseBuffer[bar_index] = mHKCloseValue;
//
double candleColorValue =
mHKOpenValue < mHKCloseValue ? 1 : 2;
//
hkCandleColorBuffer[bar_index] = showHKCandles ? candleColorValue : 0;
}
//
// END Calculation Parts ...
//
//
// START Utilities ...
//
//
bool InitMaHandler(
int &handler,
int length,
ENUM_X_MA_METHOD mode,
ENUM_APPLIED_PRICE appliedTo)
{
//
bool result = false;
//
if (length <= 0)
{
return result;
}
//
bool genericMethod = false;
ENUM_MA_METHOD method = NULL;
if (mode == X_MA_AMA)
{
//
handler = iAMA(
_Symbol,
_Period,
length,
mMRBAMAFast,
mMRBAMASlow,
0,
appliedTo);
}
else if (mode == X_MA_EMA)
{
//
method = MODE_EMA;
genericMethod = true;
}
else if (mode == X_MA_LWMA)
{
//
method = MODE_LWMA;
genericMethod = true;
}
else if (mode == X_MA_SMA)
{
//
method = MODE_SMA;
genericMethod = true;
}
else if (mode == X_MA_SMMA)
{
//
method = MODE_SMMA;
genericMethod = true;
}
//
if (genericMethod && handler == INVALID_HANDLE)
{
//
handler = iMA(
_Symbol,
_Period,
length,
0,
method,
appliedTo);
}
//
result = handler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Cycles Highest High ...
double GetCycleHH(
int bar_index, // Bar Index
ENUM_TIMEFRAMES period // Period
)
{
//
datetime mCycleStartAt = GetPeriodStartTime(
_Symbol,
period);
//
int mStartCycleBarIndex = iBarShift(
_Symbol,
_Period,
mCycleStartAt,
false);
//
int mCycleCount = MathAbs(mStartCycleBarIndex - bar_index);
if (mCycleCount < 1)
{
mCycleCount = 1;
}
//
// HIGH ...
int hhIndex = iHighest(
_Symbol,
_Period,
hhMode,
mCycleCount,
bar_index);
double result = GetAppliedPrice(
hhIndex,
hhMode);
//
return result;
}
//
// Retrieve Cycles Lowest Low ...
double GetCycleLL(
int bar_index, // Bar Index
ENUM_TIMEFRAMES period // Period
)
{
//
datetime mCycleStartAt = GetPeriodStartTime(
_Symbol,
period);
//
int mStartCycleBarIndex = iBarShift(
_Symbol,
_Period,
mCycleStartAt,
false);
//
int mCycleCount = MathAbs(mStartCycleBarIndex - bar_index);
if (mCycleCount < 1)
{
mCycleCount = 1;
}
//
// LOW ...
int llIndex = iLowest(
_Symbol,
_Period,
llMode,
mCycleCount,
bar_index);
double result = GetAppliedPrice(
llIndex,
llMode);
//
return result;
}
//
// Retrieve Cycles Highest High ...
double GetCycleHHC(
int bar_index, // Bar Index
ENUM_TIMEFRAMES period // Period
)
{
//
int mCycleCount = 0;
if (period == mL1Period)
{
mCycleCount = mL1Candles;
}
else if (period == mL2Period)
{
mCycleCount = mL2Candles;
}
else if (period == mL3Period)
{
mCycleCount = mL3Candles;
}
else if (period == mL4Period)
{
mCycleCount = mL4Candles;
}
//
// HIGH ...
int hhIndex = iHighest(
_Symbol,
_Period,
hhMode,
mCycleCount,
bar_index);
double result = GetAppliedPrice(
hhIndex,
hhMode);
//
return result;
}
//
// Retrieve Cycles Lowest Low ...
double GetCycleLLC(
int bar_index, // Bar Index
ENUM_TIMEFRAMES period // Period
)
{
//
int mCycleCount = 0;
if (period == mL1Period)
{
mCycleCount = mL1Candles;
}
else if (period == mL2Period)
{
mCycleCount = mL2Candles;
}
else if (period == mL3Period)
{
mCycleCount = mL3Candles;
}
else if (period == mL4Period)
{
mCycleCount = mL4Candles;
}
//
// LOW ...
int llIndex = iLowest(
_Symbol,
_Period,
llMode,
mCycleCount,
bar_index);
double result = GetAppliedPrice(
llIndex,
llMode);
//
return result;
}
//
string GenerateCyclesRepresentation()
{
//
string result = "";
//
result += "C1: " + ToString(mL1Period) + "\n";
result += "C2: " + ToString(mL2Period) + "\n";
result += "C3: " + ToString(mL3Period) + "\n";
result += "C4: " + ToString(mL4Period);
//
return result;
}
//
// Apply Custom Chart Style ...
void ApplyCustomChartStyle()
{
//
// Read Current Chart Config and Store it ...
ReadChartStyle();
//
// After Reading Current Chart Style ...
// we have to Save Configs and Change Styles ...
clearStyle = chartStyle;
//
clearStyle.upColor = CLR_NONE;
clearStyle.downColor = CLR_NONE;
clearStyle.lineColor = CLR_NONE;
clearStyle.bullishColor = CLR_NONE;
clearStyle.bearishColor = CLR_NONE;
//
// Decide to Show or not Candles based on User Input ...
if (showCandles)
{
SetChartStyle(chartStyle);
}
else
{
SetChartStyle(clearStyle);
}
}
//
// Read Previous Chart Style ...
void ReadChartStyle()
{
//
// Retrieve Current Chart ID ...
long chartId = ChartID();
chartStyle.chartId = chartId;
//
// Retrieve Chart Mode ...
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
//
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
//
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
//
chartStyle.upColor = upColor;
chartStyle.downColor = downColor;
chartStyle.lineColor = lineColor;
chartStyle.bearishColor = bearishColor;
chartStyle.bullishColor = bullishColor;
chartStyle.volumesColor = volumesColor;
}
//
// Set Chart Style ...
void SetChartStyle(
XChartStyle &mChartStyle // Chart Style to Apply
)
{
//
ApplyChartStyle(
mChartStyle.chartId,
mChartStyle.mode,
mChartStyle.showBidLine,
mChartStyle.showAskLine,
mChartStyle.showGrid,
mChartStyle.showVolumes,
mChartStyle.showTradeLevels,
mChartStyle.autoScroll,
mChartStyle.quickNavigation,
mChartStyle.foreGroundColor,
mChartStyle.backGroundColor,
mChartStyle.upColor,
mChartStyle.downColor,
mChartStyle.bullishColor,
mChartStyle.bearishColor,
mChartStyle.gridColor,
mChartStyle.bidLineColor,
mChartStyle.askLineColor,
mChartStyle.lineColor,
mChartStyle.stopColor,
mChartStyle.volumesColor);
}
//
// END Utilities ...
//
//
// END Functions ...
//