Files
xMQL5/BKPS/14041018/Documents/BKP/x-saherelm.x121.xcatb.v1.mq5
T
2026-01-08 11:39:42 +03:30

5499 lines
121 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XCATB
// Description: Integrates All Requirements inside
// this indicator for analyse Markets to
// Detect Trigger Blocks ...
//
// - HK Bars;
// - ATR Band;
// - Signal Bars;
// - Parabolic Sar;
// - HK Signal Bars;
// - Peaks and Vales;
// - Peaks and Vales Goldens;
// - Trending Average Prices;
//
// - ATR;
// - RSI;
// - ADX;
// - DELTA;
// - VOLUME;
//
// 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 XCATB Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XCATB"
//
// Imports ...
#include "../Classes/x-saherelm.x-bar.analyser.class.mq5"
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Market";
//
// Short ...
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Short Period
input ENUM_TIMEFRAMES scPeriod = NULL; // Short Period
//
// Medium ...
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Medium Period
input ENUM_TIMEFRAMES mcPeriod = NULL; // Medium Period
//
// Long ...
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Long Period
input ENUM_TIMEFRAMES lcPeriod = NULL; // Long Period
//
// Hind ...
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Hind Period
input ENUM_TIMEFRAMES hcPeriod = NULL; // Hind Period
//
// Select Trending Cycle ...
// this Cycle Used for All Calculations ...
input ENUM_X_MARKET_CYCLES appliedCycle = X_MARKET_CYCLE_HIND; // Applied Cycle
//
// Presentation ...
input group "Presentation";
input bool showBars = true; // Show Bars
input bool showKI = false; // Show KI
input bool showPV = false; // Show PV
input bool showPVGolden = false; // Show PV Golden
input bool showSar = false; // Show Sar
input bool showTrend = false; // Show Trend
input bool showATRBand = false; // Show ATR Band
input bool showSignalBars = false; // Show Signal Bars
input bool showHKSignalBars = false; // Show Hiken Ashi Signal Bars
//
input int startCalculationForLastBars = 1500; // Calculate Last n Bars
//
// Non Inputs ...
double sarStep = 0.02; // Step
double sarMax = 0.2; // Maximum
double rsiOBLevel = 70.0; // RSI OB Level
double rsiOSLevel = 30.0; // RSI OS Level
double adxThreshold = 25.0; // ADX Threshold
int kiLength = 144; // KI Length
int sarArrowCode = 159; // Parabolic Sar Arrow Code
int peakArrowCode = 159; // Peaks Arrow Code
int valeArrowCode = 159; // Vales Arrow Code
double atrMultiplier = 1.5; // ATR Band Multiplier
bool showShortCycle = false; // Show Short Cycle Range
bool showMediumCycle = false; // Show Medium Cycle Range
bool showLongCycle = false; // Show Long Cycle Range
bool showHindCycle = false; // Show Hind Cycle Range
ENUM_MA_METHOD trendMode = MODE_SMA; // Trend Mode
ENUM_SERIESMODE upperMode = MODE_HIGH; // Peak Method
ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method
ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // ATR Upper Zone Applied To
ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // ATR Lower Zone Applied To
ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // RSI Applied To
ENUM_APPLIED_PRICE trendAppliedTo = PRICE_MEDIAN; // Trend Applied To
ENUM_X_MA_METHOD atrSignalMethod = X_MA_MODE_EMA; // ATR Signalling Method
ENUM_X_MA_METHOD barsSignalMethod = X_MA_MODE_EMA; // Bars Signalling Method
ENUM_X_MA_METHOD deltaSignalMethod = X_MA_MODE_EMA; // Delta Signalling Method
ENUM_X_MA_METHOD hkSignalBarMethod = X_MA_MODE_EMA; // Hiken Ashi Signal Method
ENUM_X_MA_METHOD volumeSignalMethod = X_MA_MODE_EMA; // Volume Signalling Method
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#define bullishState 1
#define neuturalState 0
#define bearishState -1
//
#define emptyValue 0.0
//
// Buffers ...
//
#property indicator_chart_window
//
// Plot: 18
// Color: 4
// Bar: 8
// Data Buffer: 29
#property indicator_buffers 50
#property indicator_plots 19
//
// Plot Buffers ...
//
// SAR ...
//
#define sarBufferIndex 0
#define sarBufferPlotIndex 0
double sarBuffer[];
//
#define sarColorBufferIndex 1
double sarColorBuffer[];
//
#property indicator_label1 "SAR"
#property indicator_type1 DRAW_COLOR_ARROW
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_width1 2
//
// PEAKS ...
//
#define peakBufferIndex 2
#define peakBufferPlotIndex 1
double peakBuffer[];
//
#property indicator_label2 "PEAK"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta
#property indicator_width2 1
//
// VALES ...
//
#define valeBufferIndex 3
#define valeBufferPlotIndex 2
double valeBuffer[];
//
#property indicator_label3 "VALE"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrAqua
#property indicator_width3 1
//
// PEAKS Golden ...
//
#define peakGoldenBufferIndex 4
#define peakGoldenBufferPlotIndex 3
double peakGoldenBuffer[];
//
#property indicator_label4 "PEAK Golden"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrMagenta
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
// VALE Golden ...
//
#define valeGoldenBufferIndex 5
#define valeGoldenBufferPlotIndex 4
double valeGoldenBuffer[];
//
#property indicator_label5 "VALES Golden"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrAqua
#property indicator_style5 STYLE_DOT
#property indicator_width5 1
//
// ATR ...
//
// Upper ...
//
#define atrUpperBufferIndex 6
#define atrUpperBufferPlotIndex 5
double atrUpperBuffer[];
//
#property indicator_label6 "XATRU"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrYellow
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//
// Lower ...
//
#define atrLowerBufferIndex 7
#define atrLowerBufferPlotIndex 6
double atrLowerBuffer[];
//
#property indicator_label7 "XATRL"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrYellow
#property indicator_style7 STYLE_SOLID
#property indicator_width7 1
//
// TREND ...
//
#define trendBufferIndex 8
#define trendBufferPlotIndex 7
double trendBuffer[];
//
#define trendColorBufferIndex 9
double trendColorBuffer[];
//
#property indicator_label8 "Trend"
#property indicator_type8 DRAW_COLOR_LINE
#property indicator_color8 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style8 STYLE_SOLID
#property indicator_width8 2
//
// Signal Bar ...
//
#define sBarOpenBufferIndex 10
double sBarOpenBuffer[];
//
#define sBarHighBufferIndex 11
double sBarHighBuffer[];
//
#define sBarLowBufferIndex 12
double sBarLowBuffer[];
//
#define sBarCloseBufferIndex 13
double sBarCloseBuffer[];
//
#define sBarColorBufferIndex 14
double sBarColorBuffer[];
//
#define sBarBufferPlotIndex 8
#property indicator_label9 "XSGB Open;XSGB High;XSGB Low;XSGB Close"
#property indicator_type9 DRAW_COLOR_CANDLES
#property indicator_color9 CLR_NONE, clrLime, clrRed
//
// XHK SIGNAL ...
//
#define hkSBarOpenBufferIndex 15
double hkSBarOpenBuffer[];
//
#define hkSBarHighBufferIndex 16
double hkSBarHighBuffer[];
//
#define hkSBarLowBufferIndex 17
double hkSBarLowBuffer[];
//
#define hkSBarCloseBufferIndex 18
double hkSBarCloseBuffer[];
//
#define hkSBarColorBufferIndex 19
double hkSBarColorBuffer[];
//
#define hkSBarBufferPlotIndex 9
#property indicator_label10 "XHKSGB Open;XHKSGB High;XHKSGB Low;XHKSGB Close"
#property indicator_type10 DRAW_COLOR_CANDLES
#property indicator_color10 CLR_NONE, clrAqua, clrMagenta
//
// CYCLES Range ...
//
// SHORT ...
//
#define sHHBufferIndex 20
#define sHHBufferPlotIndex 10
double sHHBuffer[];
//
#property indicator_label11 "SH"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrGray
#property indicator_style11 STYLE_DOT
#property indicator_width11 1
//
#define sLLBufferIndex 21
#define sLLBufferPlotIndex 11
double sLLBuffer[];
//
#property indicator_label12 "SL"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrGray
#property indicator_style12 STYLE_DOT
#property indicator_width12 1
//
// MEDIUM ...
//
#define mHHBufferIndex 22
#define mHHBufferPlotIndex 12
double mHHBuffer[];
//
#property indicator_label13 "MH"
#property indicator_type13 DRAW_LINE
#property indicator_color13 clrIndigo
#property indicator_style13 STYLE_DOT
#property indicator_width13 1
//
#define mLLBufferIndex 23
#define mLLBufferPlotIndex 13
double mLLBuffer[];
//
#property indicator_label14 "ML"
#property indicator_type14 DRAW_LINE
#property indicator_color14 clrIndigo
#property indicator_style14 STYLE_DOT
#property indicator_width14 1
//
// LONG ...
//
#define lHHBufferIndex 24
#define lHHBufferPlotIndex 14
double lHHBuffer[];
//
#property indicator_label15 "LH"
#property indicator_type15 DRAW_LINE
#property indicator_color15 clrGoldenrod
#property indicator_style15 STYLE_DOT
#property indicator_width15 1
//
#define lLLBufferIndex 25
#define lLLBufferPlotIndex 15
double lLLBuffer[];
//
#property indicator_label16 "LL"
#property indicator_type16 DRAW_LINE
#property indicator_color16 clrGoldenrod
#property indicator_style16 STYLE_DOT
#property indicator_width16 1
//
// HIND ...
//
#define hHHBufferIndex 26
#define hHHBufferPlotIndex 16
double hHHBuffer[];
//
#property indicator_label17 "HH"
#property indicator_type17 DRAW_LINE
#property indicator_color17 clrBrown
#property indicator_style17 STYLE_DOT
#property indicator_width17 1
//
#define hLLBufferIndex 27
#define hLLBufferPlotIndex 17
double hLLBuffer[];
//
#property indicator_label18 "HL"
#property indicator_type18 DRAW_LINE
#property indicator_color18 clrBrown
#property indicator_style18 STYLE_DOT
#property indicator_width18 1
//
// KI ...
//
#define kiBufferIndex 28
#define kiBufferPlotIndex 18
double kiBuffer[];
//
#define kiColorBufferIndex 29
double kiColorBuffer[];
//
#property indicator_label19 "KI"
#property indicator_type19 DRAW_COLOR_LINE
#property indicator_color19 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style19 STYLE_DASHDOTDOT
#property indicator_width19 2
//
// Data Buffers ...
//
#define mLastBufferIndex 29
//
// SAR ...
//
#define sarStateBufferIndex mLastBufferIndex + 1
double sarStateBuffer[];
//
// TREND State ...
//
#define trendStateBufferIndex mLastBufferIndex + 2
double trendStateBuffer[];
//
// RSI ...
//
#define rsiBufferIndex mLastBufferIndex + 3
double rsiBuffer[];
//
// ADX ...
//
#define adxBufferIndex mLastBufferIndex + 4
double adxBuffer[];
//
#define adxpBufferIndex mLastBufferIndex + 5
double adxpBuffer[];
//
#define adxnBufferIndex mLastBufferIndex + 6
double adxnBuffer[];
//
// DELTA ...
//
#define deltaBufferIndex mLastBufferIndex + 7
double deltaBuffer[];
//
#define deltaSignalBufferIndex mLastBufferIndex + 8
double deltaSignalBuffer[];
//
// VOLUMES ...
//
#define bullishVolumeBufferIndex mLastBufferIndex + 9
double bullishVolumeBuffer[];
//
#define bearishVolumeBufferIndex mLastBufferIndex + 10
double bearishVolumeBuffer[];
//
#define bullishVolumeSignalBufferIndex mLastBufferIndex + 11
double bullishVolumeSignalBuffer[];
//
#define bearishVolumeSignalBufferIndex mLastBufferIndex + 12
double bearishVolumeSignalBuffer[];
//
// ATR ...
//
#define atrBufferIndex mLastBufferIndex + 13
double atrBuffer[];
//
#define atrUpperRawBufferIndex mLastBufferIndex + 14
double atrUpperRawBuffer[];
//
#define atrLowerRawBufferIndex mLastBufferIndex + 15
double atrLowerRawBuffer[];
//
// HK ...
//
#define openHKBufferIndex mLastBufferIndex + 16
double openHKBuffer[];
//
#define highHKBufferIndex mLastBufferIndex + 17
double highHKBuffer[];
//
#define lowHKBufferIndex mLastBufferIndex + 18
double lowHKBuffer[];
//
#define closeHKBufferIndex mLastBufferIndex + 19
double closeHKBuffer[];
//
// KI ...
//
#define kiStateBufferIndex mLastBufferIndex + 20
double kiStateBuffer[];
//
// Variables, Properties and etc ...
//
int limit;
//
int maxLength;
//
int firstBarIndex;
//
// Bars Color Variables ...
color _upColor = clrLime;
color _downColor = clrRed;
color _lineColor = clrLime;
color _bullishColor = clrLime;
color _bearishColor = clrRed;
//
// XMarketCycle sc;
int mSCLength = 0;
ENUM_TIMEFRAMES mSCPeriod = NULL;
//
// XMarketCycle mc;
int mMCLength = 0;
ENUM_TIMEFRAMES mMCPeriod = NULL;
//
// XMarketCycle lc;
int mLCLength = 0;
ENUM_TIMEFRAMES mLCPeriod = NULL;
//
// XMarketCycle hc;
int mHCLength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
//
// Applied Cycle ...
int mAppliedLength;
ENUM_TIMEFRAMES mAppliedPeriod = NULL;
//
// Handlers ...
int atrHandler = INVALID_HANDLE;
int sarHandler = INVALID_HANDLE;
int rsiHandler = INVALID_HANDLE;
int adxHandler = INVALID_HANDLE;
int trendHandler = INVALID_HANDLE;
//
CArrayObj mObjects;
XCPOIDrawer *mDrawer;
XCBarAnalyser *mBarAnalyser;
//
// Conditions Variables ...
//
// Temparory ...
int mCount = 0;
XSignal mSignal;
bool mHas = false;
XBoxZone mSignalBox;
ENUM_X_DIRECTION mDir;
bool mHasSignal = false;
bool mIsBullish = false;
bool mIsBearish = false;
XDirectionShift mDirShift;
string mArrowNamePrefix = NULL;
//
// Signals ...
//
bool mDrawSignals = false;
bool mDrawSignalBoxes = false;
bool mDrawSignalArrows = true;
bool mDrawSignalBoxAtLines = false;
//
int _bullishArrowCode = 225;
int _bearishArrowCode = 226;
//
color _bullishArrowColor = clrLime;
color _bearishArrowColor = clrRed;
//
XPOIStyle mBullishSignalBoxStyle;
XPOIStyle mBearishSignalBoxStyle;
//
ENUM_ARROW_ANCHOR mBullishAnchor = ANCHOR_TOP;
ENUM_ARROW_ANCHOR mBearishAnchor = ANCHOR_BOTTOM;
//
// POI(s) ...
//
// Liquidities ...
bool mDrawLiquidities = false;
bool mDetectLiquidities = true;
XBoxZone mBullishLiquidities[];
XBoxZone mBearishLiquidities[];
XPOIStyle mBullishLiquidityStyle;
XPOIStyle mBearishLiquidityStyle;
//
// Range Breakes ...
bool mDrawRangeBreakes = false;
bool mDetectRangeBreakes = true;
XBoxZone mBullishRangeBreakes[];
XBoxZone mBearishRangeBreakes[];
XPOIStyle mBullishRangeBreakStyle;
XPOIStyle mBearishRangeBreakStyle;
//
// Counters ...
//
int mSameSBCount = 0;
int mSameBullishSBCount = 0;
int mSameBearishSBCount = 0;
//
int mSameKICount = 0;
int mSameBullishKICount = 0;
int mSameBearishKICount = 0;
//
int mSameHKSCount = 0;
int mSameBullishHKSCount = 0;
int mSameBearishHKSCount = 0;
//
int mSameSarCount = 0;
int mSameBullishSarCount = 0;
int mSameBearishSarCount = 0;
//
int mSameTrendCount = 0;
int mSameBullishTrendCount = 0;
int mSameBearishTrendCount = 0;
//
int mSamePeakCount = 0;
int mSameValeCount = 0;
int mSamePeakGoldenCount = 0;
int mSameValeGoldenCount = 0;
//
double mSamePeakGoldenMin = 0;
double mSamePeakGoldenMax = 0;
double mSameValeGoldenMin = 0;
double mSameValeGoldenMax = 0;
//
// Direction Shift ...
//
XDirectionShift mBullishKIChanges[];
XDirectionShift mBearishKIChanges[];
//
XDirectionShift mBullishSBChanges[];
XDirectionShift mBearishSBChanges[];
//
XDirectionShift mBullishHKSChanges[];
XDirectionShift mBearishHKSChanges[];
//
XDirectionShift mBullishSarChanges[];
XDirectionShift mBearishSarChanges[];
//
XDirectionShift mBullishTrendChanges[];
XDirectionShift mBearishTrendChanges[];
//
// Liquidities ...
//
bool isLiquidity = false;
bool isBullishLiquidity = false;
bool isBearishLiquidity = false;
//
// Trigger Bars Conditions ...
//
bool isTriggerBarCond1 = false;
bool isTriggerBarCond1Bullish = false;
bool isTriggerBarCond1Bearish = false;
//
bool isTriggerBarCond2 = false;
bool isTriggerBarCond2Bullish = false;
bool isTriggerBarCond2Bearish = false;
//
bool isTriggerBarCond3 = false;
bool isTriggerBarCond3Bullish = false;
bool isTriggerBarCond3Bearish = false;
//
bool isTriggerBarCond4 = false;
bool isTriggerBarCond4Bullish = false;
bool isTriggerBarCond4Bearish = false;
//
bool isTriggerBarCond5 = false;
bool isTriggerBarCond5Bullish = false;
bool isTriggerBarCond5Bearish = false;
//
bool isTriggerBarCond6 = false;
bool isTriggerBarCond6Bullish = false;
bool isTriggerBarCond6Bearish = false;
//
bool isTriggerBarCond7 = false;
bool isTriggerBarCond7Bullish = false;
bool isTriggerBarCond7Bearish = false;
//
// Summarizing Trigger Bar ...
bool isTriggerBar = false;
bool isTriggerBarBullish = false;
bool isTriggerBarBearish = false;
//
// XPV ...
//
bool isSamePeak = false;
bool isSamePeakP = false;
//
bool isSameVale = false;
bool isSameValeP = false;
//
bool isPeakOverLast = false;
bool isPeakUnderLast = false;
//
bool isValeOverLast = false;
bool isValeUnderLast = false;
//
bool isSamePeakOverLast = false;
bool isSamePeakUnderLast = false;
//
bool isSameValeOverLast = false;
bool isSameValeUnderLast = false;
//
bool isSamePeakGolden = false;
bool isSamePeakGoldenP = false;
//
bool isSameValeGolden = false;
bool isSameValeGoldenP = false;
//
bool isPeakGoldenOverLast = false;
bool isPeakGoldenUnderLast = false;
//
bool isValeGoldenOverLast = false;
bool isValeGoldenUnderLast = false;
//
bool isSamePeakGoldenOverLast = false;
bool isSamePeakGoldenUnderLast = false;
//
bool isSameValeGoldenOverLast = false;
bool isSameValeGoldenUnderLast = false;
//
// XSAR ...
//
bool isSarBullish = false;
bool isSarBullishP = false;
//
bool isSarBearish = false;
bool isSarBearishP = false;
//
bool isSarSwitchedToBullish = false;
bool isSarSwitchedToBearish = false;
//
bool isBullishSarBreakedLast = false;
bool isBearishSarBreakedLast = false;
//
// XSB ...
//
double mSBMax = 0;
double mSBMin = 0;
//
double mSBPMax = 0;
double mSBPMin = 0;
//
bool isSBBullish = false;
bool isSBBullishP = false;
//
bool isSBBearish = false;
bool isSBBearishP = false;
//
bool isSBSwitchedToBullish = false;
bool isSBSwitchedToBearish = false;
//
bool isBullishSBBreakedLast = false;
bool isBearishSBBreakedLast = false;
//
// XHKS ...
//
double mHKSMax = 0;
double mHKSMin = 0;
//
double mHKSPMax = 0;
double mHKSPMin = 0;
//
bool isHKSBullish = false;
bool isHKSBullishP = false;
//
bool isHKSBearish = false;
bool isHKSBearishP = false;
//
bool isHKSSwitchedToBullish = false;
bool isHKSSwitchedToBearish = false;
//
bool isBullishHKSBreakedLast = false;
bool isBearishHKSBreakedLast = false;
//
// XKI ...
//
bool isKIBullish = false;
bool isKIBullishP = false;
//
bool isKIBearish = false;
bool isKIBearishP = false;
//
bool isSameKI = false;
bool isSameBullishKI = false;
bool isSameBearishKI = false;
//
bool isKISwitchedToBullish = false;
bool isKISwitchedToBearish = false;
//
bool isBullishKIBreakedLast = false;
bool isBearishKIBreakedLast = false;
//
// XTREND ...
//
bool isTrendBullish = false;
bool isTrendBullishP = false;
//
bool isTrendBearish = false;
bool isTrendBearishP = false;
//
bool isTrendSwitchedToBullish = false;
bool isTrendSwitchedToBearish = false;
//
bool isBullishTrendBreakedLast = false;
bool isBearishTrendBreakedLast = false;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
bool has = false;
//
ReadBarStyle();
//
// Validate Inputs ...
has = ValidateInputs();
if (!has)
{
return INIT_PARAMETERS_INCORRECT;
}
//
has = InitCycles();
if (!has)
{
return INIT_FAILED;
}
//
// 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();
//
// Initial Requirements ...
has = InitRequirements();
if (!has)
{
return INIT_FAILED;
}
//
if (showBars)
{
ShowBars();
}
else
{
HideBars();
}
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Initial Requirements ...
mDrawer = new XCPOIDrawer();
mBarAnalyser = new XCBarAnalyser();
//
// Preparing Styles ...
//
// Signals ...
//
// Bullish ...
mBullishSignalBoxStyle.width = 1;
mBullishSignalBoxStyle.clr = clrAqua;
mBullishSignalBoxStyle.style = STYLE_DOT;
//
// Bearish ...
mBearishSignalBoxStyle.width = 1;
mBearishSignalBoxStyle.style = STYLE_DOT;
mBearishSignalBoxStyle.clr = clrMagenta;
//
// Liquidities ...
//
// Bullish ...
mBullishLiquidityStyle.width = 1;
mBullishLiquidityStyle.clr = clrLime;
//
// Bearish ...
mBearishLiquidityStyle.width = 1;
mBearishLiquidityStyle.clr = clrRed;
//
// Range Breakes ...
//
// Bullish ...
mBullishRangeBreakStyle.width = 1;
mBullishRangeBreakStyle.clr = clrAqua;
//
// Bearish ...
mBearishRangeBreakStyle.width = 1;
mBearishRangeBreakStyle.clr = clrMagenta;
//
// Init Succeed ...
return INIT_SUCCEEDED;
//
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
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
//
ShowBars();
//
// De Initial Requirements ...
mObjects.Clear();
//
delete mDrawer;
ZeroMemory(mDrawer);
delete mBarAnalyser;
ZeroMemory(mBarAnalyser);
//
// De Initialize all Handlers and etc ...
IndicatorRelease(atrHandler);
IndicatorRelease(sarHandler);
IndicatorRelease(rsiHandler);
IndicatorRelease(adxHandler);
IndicatorRelease(trendHandler);
//
mSignal.Clean();
mDirShift.Clean();
mSignalBox.Clean();
//
Clean(mBullishKIChanges);
Clean(mBearishKIChanges);
Clean(mBullishSBChanges);
Clean(mBearishSBChanges);
Clean(mBullishHKSChanges);
Clean(mBearishHKSChanges);
Clean(mBullishSarChanges);
Clean(mBearishSarChanges);
Clean(mBullishTrendChanges);
Clean(mBearishTrendChanges);
//
Clean(mBullishLiquidities);
Clean(mBearishLiquidities);
Clean(mBullishRangeBreakes);
Clean(mBearishRangeBreakes);
//
mBullishSignalBoxStyle.Clean();
mBearishSignalBoxStyle.Clean();
//
mBullishLiquidityStyle.Clean();
mBearishLiquidityStyle.Clean();
mBullishRangeBreakStyle.Clean();
mBearishRangeBreakStyle.Clean();
//
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
int OnCalculate(
const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[] //
)
{
//
// 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);
//
// Validate Calculated Bars ...
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
// SAR ...
int sarCalculatedBars = BarsCalculated(sarHandler);
//
// RSI ...
int rsiCalculatedBars = BarsCalculated(rsiHandler);
//
// ADX ...
int adxCalculatedBars = BarsCalculated(adxHandler);
//
// TREND ...
int trendCalculatedBars = BarsCalculated(trendHandler);
//
bool isPassedRequiredCalculatedBars =
//
// ATR ...
atrCalculatedBars >= maxLength &&
//
// SAR ...
sarCalculatedBars >= maxLength &&
//
// RSI ...
rsiCalculatedBars >= maxLength &&
//
// ADX ...
adxCalculatedBars >= maxLength &&
//
// TREND ...
trendCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// ATR ...
int copiedAtrs = CopyBuffer(atrHandler, MAIN_LINE, 0, limit, atrBuffer);
//
// SAR ...
int copiedSars = CopyBuffer(sarHandler, MAIN_LINE, 0, limit, sarBuffer);
//
// RSI ...
int copiedRSIs = CopyBuffer(rsiHandler, MAIN_LINE, 0, limit, rsiBuffer);
//
// ADX ...
int copiedADXs = CopyBuffer(adxHandler, MAIN_LINE, 0, limit, adxBuffer);
//
// ADX Plus ...
int copiedADXPs = CopyBuffer(adxHandler, PLUSDI_LINE, 0, limit, adxpBuffer);
//
// ADX Negative ...
int copiedADXNs = CopyBuffer(adxHandler, MINUSDI_LINE, 0, limit, adxnBuffer);
//
// TREND ...
int copiedTrends = CopyBuffer(trendHandler, MAIN_LINE, 0, limit, trendBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// ATR ...
copiedAtrs >= limit &&
//
// SAR ...
copiedSars >= limit &&
//
// RSI ...
copiedRSIs >= limit &&
//
// TREND ...
copiedTrends >= limit
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
if (prev_calculated == 0)
{
//
string message = "History Started ...";
Print(message);
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
if (prev_calculated == 0)
{
//
string message = "History Finished ...";
Print(message);
}
//
return rates_total;
}
//
// Custom Functions ...
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
//
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
sarMax > 0 &&
sarStep > 0 &&
rsiOBLevel > 0 &&
rsiOSLevel > 0 &&
adxThreshold > 0 &&
sarMax > sarStep &&
atrMultiplier > 0 &&
//
IsValid(appliedCycle) &&
//
IsValid(atrUpperPriceType) &&
IsValid(atrLowerPriceType) &&
//
// CYCLES ...
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(mSCLength, mMCLength);
result = MathMax(result, mLCLength);
result = MathMax(result, mHCLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// SAR ...
//
ArraySetAsSeries(sarBuffer, true);
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(sarBufferPlotIndex, PLOT_SHOW_DATA, showSar);
PlotIndexSetDouble(sarBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(sarBufferPlotIndex, PLOT_ARROW, sarArrowCode);
//
ArraySetAsSeries(sarColorBuffer, true);
SetIndexBuffer(sarColorBufferIndex, sarColorBuffer, INDICATOR_COLOR_INDEX);
//
ArraySetAsSeries(sarStateBuffer, true);
SetIndexBuffer(sarStateBufferIndex, sarStateBuffer, INDICATOR_CALCULATIONS);
//
// PEAK / VALE ...
//
ENUM_DRAW_TYPE pvDrawType = showPV ? DRAW_ARROW : DRAW_NONE;
//
// PEAK ...
//
ArraySetAsSeries(peakBuffer, true);
SetIndexBuffer(peakBufferIndex, peakBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(peakBufferPlotIndex, PLOT_SHOW_DATA, showPV);
PlotIndexSetInteger(peakBufferPlotIndex, PLOT_DRAW_TYPE, pvDrawType);
//
PlotIndexSetDouble(peakBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(peakBufferPlotIndex, PLOT_ARROW, peakArrowCode);
//
// VALE ...
//
ArraySetAsSeries(valeBuffer, true);
SetIndexBuffer(valeBufferIndex, valeBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(valeBufferPlotIndex, PLOT_SHOW_DATA, showPV);
PlotIndexSetInteger(valeBufferPlotIndex, PLOT_DRAW_TYPE, pvDrawType);
//
PlotIndexSetDouble(valeBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(valeBufferPlotIndex, PLOT_ARROW, valeArrowCode);
//
// PV GOLDEN ...
//
ENUM_DRAW_TYPE pvGoldenDrawType = showPVGolden ? DRAW_LINE : DRAW_NONE;
//
// PEAK Golden ...
//
ArraySetAsSeries(peakGoldenBuffer, true);
SetIndexBuffer(peakGoldenBufferIndex, peakGoldenBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(peakGoldenBufferPlotIndex, PLOT_SHOW_DATA, showPVGolden);
PlotIndexSetInteger(peakGoldenBufferPlotIndex, PLOT_DRAW_TYPE, pvGoldenDrawType);
//
PlotIndexSetDouble(peakGoldenBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// VALE Golden ...
//
ArraySetAsSeries(valeGoldenBuffer, true);
SetIndexBuffer(valeGoldenBufferIndex, valeGoldenBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(valeGoldenBufferPlotIndex, PLOT_SHOW_DATA, showPVGolden);
PlotIndexSetInteger(valeGoldenBufferPlotIndex, PLOT_DRAW_TYPE, pvGoldenDrawType);
//
PlotIndexSetDouble(valeGoldenBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// ATR Band ...
//
// UPPER ...
ENUM_DRAW_TYPE atrUpperDrawType = showATRBand ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(atrUpperBuffer, true);
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
//
PlotIndexSetDouble(atrUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(atrUpperBufferPlotIndex, PLOT_SHOW_DATA, showATRBand);
PlotIndexSetInteger(atrUpperBufferPlotIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
//
// LOWER ...
ENUM_DRAW_TYPE atrLowerDrawType = showATRBand ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(atrLowerBuffer, true);
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
//
PlotIndexSetDouble(atrLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(atrLowerBufferPlotIndex, PLOT_SHOW_DATA, showATRBand);
PlotIndexSetInteger(atrLowerBufferPlotIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
//
// TREND ...
//
ArraySetAsSeries(trendBuffer, true);
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(trendBufferPlotIndex, PLOT_SHOW_DATA, showTrend);
PlotIndexSetDouble(trendBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
ArraySetAsSeries(trendColorBuffer, true);
SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX);
//
ArraySetAsSeries(trendStateBuffer, true);
SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS);
//
// SIGNAL Bar ...
//
// Signal Bars Color ...
ArraySetAsSeries(sBarColorBuffer, true);
SetIndexBuffer(sBarColorBufferIndex, sBarColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on XHK Bar Buffer ...
PlotIndexSetDouble(sBarBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(sBarBufferPlotIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(sBarOpenBuffer, true);
SetIndexBuffer(sBarOpenBufferIndex, sBarOpenBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(sBarHighBuffer, true);
SetIndexBuffer(sBarHighBufferIndex, sBarHighBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(sBarLowBuffer, true);
SetIndexBuffer(sBarLowBufferIndex, sBarLowBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(sBarCloseBuffer, true);
SetIndexBuffer(sBarCloseBufferIndex, sBarCloseBuffer, INDICATOR_DATA);
//
// XHK SIGNAL Bar ...
//
// HK Bars Color ...
ArraySetAsSeries(hkSBarColorBuffer, true);
SetIndexBuffer(hkSBarColorBufferIndex, hkSBarColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on XHK Bar Buffer ...
PlotIndexSetDouble(hkSBarBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(hkSBarBufferPlotIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(hkSBarOpenBuffer, true);
SetIndexBuffer(hkSBarOpenBufferIndex, hkSBarOpenBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(hkSBarHighBuffer, true);
SetIndexBuffer(hkSBarHighBufferIndex, hkSBarHighBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(hkSBarLowBuffer, true);
SetIndexBuffer(hkSBarLowBufferIndex, hkSBarLowBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(hkSBarCloseBuffer, true);
SetIndexBuffer(hkSBarCloseBufferIndex, hkSBarCloseBuffer, INDICATOR_DATA);
//
// CYCLES ...
//
// SHORT ...
//
ENUM_DRAW_TYPE sDrawType = showShortCycle ? DRAW_LINE : DRAW_NONE;
//
// HH ...
//
ArraySetAsSeries(sHHBuffer, true);
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_SHOW_DATA, showShortCycle);
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_DRAW_TYPE, sDrawType);
PlotIndexSetDouble(sHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// LL ...
//
ArraySetAsSeries(sLLBuffer, true);
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_SHOW_DATA, showShortCycle);
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_DRAW_TYPE, sDrawType);
PlotIndexSetDouble(sLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// MEDIUM ...
//
ENUM_DRAW_TYPE mDrawType = showMediumCycle ? DRAW_LINE : DRAW_NONE;
//
// HH ...
//
ArraySetAsSeries(mHHBuffer, true);
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_SHOW_DATA, showMediumCycle);
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_DRAW_TYPE, mDrawType);
PlotIndexSetDouble(mHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// LL ...
//
ArraySetAsSeries(mLLBuffer, true);
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_SHOW_DATA, showMediumCycle);
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_DRAW_TYPE, mDrawType);
PlotIndexSetDouble(mLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// LONG ...
//
ENUM_DRAW_TYPE lDrawType = showLongCycle ? DRAW_LINE : DRAW_NONE;
//
// HH ...
//
ArraySetAsSeries(lHHBuffer, true);
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_SHOW_DATA, showLongCycle);
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_DRAW_TYPE, lDrawType);
PlotIndexSetDouble(lHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// LL ...
//
ArraySetAsSeries(lLLBuffer, true);
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_SHOW_DATA, showLongCycle);
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_DRAW_TYPE, lDrawType);
PlotIndexSetDouble(lLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// HIND ...
//
ENUM_DRAW_TYPE hDrawType = showHindCycle ? DRAW_LINE : DRAW_NONE;
//
// HH ...
//
ArraySetAsSeries(hHHBuffer, true);
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_SHOW_DATA, showHindCycle);
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_DRAW_TYPE, hDrawType);
PlotIndexSetDouble(hHHBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// LL ...
//
ArraySetAsSeries(hLLBuffer, true);
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_SHOW_DATA, showHindCycle);
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_DRAW_TYPE, hDrawType);
PlotIndexSetDouble(hLLBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// KI ...
//
ArraySetAsSeries(kiBuffer, true);
SetIndexBuffer(kiBufferIndex, kiBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKI);
PlotIndexSetDouble(kiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
ArraySetAsSeries(kiColorBuffer, true);
SetIndexBuffer(kiColorBufferIndex, kiColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// RSI ...
ArraySetAsSeries(rsiBuffer, true);
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
//
// ADX ...
//
ArraySetAsSeries(adxBuffer, true);
SetIndexBuffer(adxBufferIndex, adxBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(adxpBuffer, true);
SetIndexBuffer(adxpBufferIndex, adxpBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(adxnBuffer, true);
SetIndexBuffer(adxnBufferIndex, adxnBuffer, INDICATOR_CALCULATIONS);
//
// DELTA ...
//
ArraySetAsSeries(deltaBuffer, true);
SetIndexBuffer(deltaBufferIndex, deltaBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(deltaSignalBuffer, true);
SetIndexBuffer(deltaSignalBufferIndex, deltaSignalBuffer, INDICATOR_CALCULATIONS);
//
// VOLUME ...
//
ArraySetAsSeries(bullishVolumeBuffer, true);
SetIndexBuffer(bullishVolumeBufferIndex, bullishVolumeBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(bearishVolumeBuffer, true);
SetIndexBuffer(bearishVolumeBufferIndex, bearishVolumeBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(bullishVolumeSignalBuffer, true);
SetIndexBuffer(bullishVolumeSignalBufferIndex, bullishVolumeSignalBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(bearishVolumeSignalBuffer, true);
SetIndexBuffer(bearishVolumeSignalBufferIndex, bearishVolumeSignalBuffer, INDICATOR_CALCULATIONS);
//
// ATR ...
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrUpperRawBuffer, true);
SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrLowerRawBuffer, true);
SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS);
//
// XHK ...
//
ArraySetAsSeries(openHKBuffer, true);
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(highHKBuffer, true);
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(lowHKBuffer, true);
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(closeHKBuffer, true);
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_CALCULATIONS);
//
// KI ...
//
ArraySetAsSeries(kiStateBuffer, true);
SetIndexBuffer(kiStateBufferIndex, kiStateBuffer, INDICATOR_CALCULATIONS);
//
}
/**
* Initial Market Cycles ...
*
* @return ( bool )
*/
bool InitCycles()
{
//
bool result = false;
//
int cPeriodSeconds = PeriodSeconds(_Period);
//
// Find Cycle Period ...
if (scMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mSCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_SHORT,
_Period //
);
}
else
{
mSCPeriod = scPeriod;
}
//
if (IsValid(mSCPeriod))
{
mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
}
//
// Find Cycle Period ...
if (mcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mMCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_MEDIUM,
_Period //
);
}
else
{
mMCPeriod = mcPeriod;
}
//
if (IsValid(mMCPeriod))
{
mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
}
//
// Find Cycle Period ...
if (lcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mLCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_LONG,
_Period //
);
}
else
{
mLCPeriod = lcPeriod;
}
//
if (IsValid(mLCPeriod))
{
mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
}
//
// Find Cycle Period ...
if (hcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mHCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_HIND,
_Period //
);
}
else
{
mHCPeriod = hcPeriod;
}
//
if (IsValid(mHCPeriod))
{
mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
}
//
result = mSCLength > 0 &&
mMCLength > mSCLength &&
mLCLength > mMCLength &&
mHCLength > mLCLength;
//
// Selecte Applied Cycle ...
if (result)
{
//
switch (appliedCycle)
{
//
case X_MARKET_CYCLE_SHORT:
//
mAppliedLength = mSCLength;
mAppliedPeriod = mSCPeriod;
break;
//
case X_MARKET_CYCLE_MEDIUM:
//
mAppliedLength = mMCLength;
mAppliedPeriod = mMCPeriod;
break;
//
case X_MARKET_CYCLE_LONG:
//
mAppliedLength = mLCLength;
mAppliedPeriod = mLCPeriod;
break;
//
case X_MARKET_CYCLE_HIND:
//
mAppliedLength = mHCLength;
mAppliedPeriod = mHCPeriod;
break;
}
}
//
return result;
}
/**
* Initial all Indicator Requirements ...
*
* @return ( false )
*
*/
bool InitRequirements()
{
//
bool result = false;
//
// Handlers ...
//
// SAR ...
sarHandler = iSAR(
_Symbol,
_Period,
sarStep,
sarMax //
);
result = sarHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
mAppliedLength //
);
result = atrHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// RSI ...
rsiHandler = iRSI(
_Symbol,
_Period,
mAppliedLength,
rsiAppliedTo //
);
result = rsiHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// ADX ...
adxHandler = iADX(
_Symbol,
_Period,
mAppliedLength //
);
result = adxHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// TREND ...
trendHandler = iMA(
_Symbol,
_Period,
mAppliedLength,
0,
trendMode,
trendAppliedTo //
);
result = trendHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
/**
* Calculate Custom Buffers ...
*
* @param barIndex: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateBuffers(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
if (barsLimit == 0)
{
//
barsLimit = ratesTotal;
firstBarIndex = barsLimit - 1;
}
else
{
firstBarIndex = startCalculationForLastBars;
}
//
// bool canCalculate = true;
bool canCalculate =
barIndex <= barsLimit;
if (canCalculate)
{
//
// Calculate Values ...
CalculateValues(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(barIndex);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
kiColorBuffer[barIndex] = hideColorIDX;
sarColorBuffer[barIndex] = hideColorIDX;
trendColorBuffer[barIndex] = hideColorIDX;
//
atrUpperRawBuffer[barIndex] = emptyValue;
atrLowerRawBuffer[barIndex] = emptyValue;
}
//
// Value Calculators ...
/**
* Calculate Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateValues(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
int maxBarIndex = startCalculationForLastBars > 0
? startCalculationForLastBars
: ratesTotal;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
// Cycle Ranges ...
CalculateCycleRanges(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// KI ...
CalculateKI(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// PV ...
CalculatePV(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// SAR ...
CalculateSAR(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// SBAR ...
CalculateSBar(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// HKBAR ...
CalculateHKBar(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// DELTA ...
CalculateDelta(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// TREND ...
CalculateTrend(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// VOLUME ...
CalculateVolume(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// ATR Band ...
CalculateATRBand(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Handling Process ...
//
// Prepare Market Conditions ...
PrepareMarketConditions(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Detecting POI(s) ...
DetectPOIs(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Validating ...
ValidatePOIs(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Drawing ...
DrawPOIs(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Do Process on Bars ...
DoProcess(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
/**
* Calculate Cycle Ranges Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateCycleRanges(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// SHORT ...
CalculateCycle(
barIndex,
X_MARKET_CYCLE_SHORT,
sHHBuffer,
sLLBuffer //
);
//
// MEDIUM ...
CalculateCycle(
barIndex,
X_MARKET_CYCLE_MEDIUM,
mHHBuffer,
mLLBuffer //
);
//
// LONG ...
CalculateCycle(
barIndex,
X_MARKET_CYCLE_LONG,
lHHBuffer,
lLLBuffer //
);
//
// HIND ...
CalculateCycle(
barIndex,
X_MARKET_CYCLE_HIND,
hHHBuffer,
hLLBuffer //
);
}
/**
* Calculate KI Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateKI(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
XOHCL iBar;
bool isInited = iBar.Init(
_Symbol,
_Period,
barIndex //
);
//
double iClose = close[barIndex];
//
// Calculate KI / Color ...
double lastKI =
isFirstBar
? emptyValue
: kiBuffer[lastBarIndex];
double iKI = lastKI;
if (isInited)
{
//
double iLLKI = iBar.FindLowest(kiLength, MODE_LOW);
double iHHKI = iBar.FindHighest(kiLength, MODE_HIGH);
//
iKI = (iHHKI + iLLKI) / 2;
if (iLLKI == 0 || iHHKI == 0)
{
iKI = lastKI;
}
}
else
{
iKI = lastKI;
}
kiBuffer[barIndex] = iKI;
//
double iKIState = neuturalState;
double iKIColor = neuturalColorIDX;
if (iClose > iKI)
{
//
iKIState = bullishState;
iKIColor =
!showKI
? hideColorIDX
: bullishColorIDX;
}
else if (iClose < iKI)
{
//
iKIState = bearishState;
iKIColor =
!showKI
? hideColorIDX
: bearishColorIDX;
}
kiStateBuffer[barIndex] = iKIState;
kiColorBuffer[barIndex] = iKIColor;
//
iBar.Clean();
}
/**
* Calculate Peaks and Vales Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculatePV(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
double iSHH = sHHBuffer[barIndex];
double iSLL = sLLBuffer[barIndex];
//
double iMHH = mHHBuffer[barIndex];
double iMLL = mLLBuffer[barIndex];
//
double iLHH = lHHBuffer[barIndex];
double iLLL = lLLBuffer[barIndex];
//
double iHHH = hHHBuffer[barIndex];
double iHLL = hLLBuffer[barIndex];
//
// Calculate VALE ...
bool isVale = iSLL == iMLL &&
iMLL == iLLL &&
iLLL == iHLL;
double iPVale =
isFirstBar
? emptyValue
: valeBuffer[lastBarIndex];
double iVale =
isVale
? iSLL
: iPVale;
valeBuffer[barIndex] = iVale;
//
// Calculate PEAK ...
bool isPeak = iSHH == iMHH &&
iMHH == iLHH &&
iLHH == iHHH;
double iPPeak =
isFirstBar
? emptyValue
: peakBuffer[lastBarIndex];
double iPeak =
isPeak
? iSHH
: iPPeak;
peakBuffer[barIndex] = iPeak;
//
// GOLDEN ...
XOHCL iBar;
bool isInited = iBar.Init(
_Symbol,
_Period,
barIndex //
);
//
// Calculate PV Gold ...
double lastPeakGold =
isFirstBar
? emptyValue
: peakGoldenBuffer[lastBarIndex];
double lastValeGold =
isFirstBar
? emptyValue
: valeGoldenBuffer[lastBarIndex];
double iPeakGold = lastPeakGold;
double iValeGold = lastValeGold;
if (isInited)
{
//
iPeakGold = iBar.FindHighest(mHCLength, MODE_CLOSE);
if (iPeakGold == 0)
{
iPeakGold = lastPeakGold;
}
//
iValeGold = iBar.FindLowest(mHCLength, MODE_CLOSE);
if (iValeGold == 0)
{
iValeGold = lastValeGold;
}
}
else
{
//
iPeakGold = lastPeakGold;
iValeGold = lastValeGold;
}
//
peakGoldenBuffer[barIndex] = iPeakGold;
valeGoldenBuffer[barIndex] = iValeGold;
//
iBar.Clean();
}
/**
* Calculate PSar Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateSAR(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double iLow = low[barIndex];
double iHigh = low[barIndex];
double iSar = sarBuffer[barIndex];
//
bool isBullish = iSar < iLow;
bool isBearish = iSar > iHigh;
//
double iSarState = isBullish
? 1
: isBearish
? -1
: 0;
double iSarColor = iSarState > 0
? bullishColorIDX
: iSarState < 0
? bearishColorIDX
: neuturalColorIDX;
sarStateBuffer[barIndex] = iSarState;
sarColorBuffer[barIndex] = showSar
? iSarColor
: hideColorIDX;
}
/**
* Calculate Signal Bar Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateSBar(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Open ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
open,
sBarOpenBuffer,
barsSignalMethod //
);
//
// Close ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
close,
sBarCloseBuffer,
barsSignalMethod //
);
//
double min = MathMin(sBarCloseBuffer[barIndex], sBarOpenBuffer[barIndex]);
double max = MathMin(sBarCloseBuffer[barIndex], sBarOpenBuffer[barIndex]);
//
sBarLowBuffer[barIndex] = min;
sBarHighBuffer[barIndex] = max;
//
// Calculate HK Signal Color ...
double iSignalColorValue =
sBarOpenBuffer[barIndex] < sBarCloseBuffer[barIndex]
? bullishColorIDX
: bearishColorIDX;
sBarColorBuffer[barIndex] =
showSignalBars
? iSignalColorValue
: hideColorIDX;
}
/**
* Calculate HK and HK Signal Bars Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateHKBar(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
double lastHKOpen =
isFirstBar
? emptyValue
: openHKBuffer[lastBarIndex];
double lastHKClose =
isFirstBar
? emptyValue
: closeHKBuffer[lastBarIndex];
//
double iHKOpenValue = (lastHKOpen + lastHKClose) / 2;
double iHKCloseValue = (open[barIndex] + high[barIndex] + close[barIndex] + low[barIndex]) / 4;
double iHKHighValue = MathMax(high[barIndex], MathMax(iHKOpenValue, iHKCloseValue));
double iHKLowValue = MathMin(low[barIndex], MathMin(iHKOpenValue, iHKCloseValue));
//
// Raw HK Buffers ...
openHKBuffer[barIndex] = iHKOpenValue;
highHKBuffer[barIndex] = iHKHighValue;
lowHKBuffer[barIndex] = iHKLowValue;
closeHKBuffer[barIndex] = iHKCloseValue;
//
// XHK Signal ...
//
// Open ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
openHKBuffer,
hkSBarOpenBuffer,
hkSignalBarMethod //
);
//
// Close ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
closeHKBuffer,
hkSBarCloseBuffer,
hkSignalBarMethod //
);
//
double min = MathMin(hkSBarCloseBuffer[barIndex], hkSBarOpenBuffer[barIndex]);
double max = MathMin(hkSBarCloseBuffer[barIndex], hkSBarOpenBuffer[barIndex]);
//
hkSBarLowBuffer[barIndex] = min;
hkSBarHighBuffer[barIndex] = max;
//
// Calculate HK Signal Color ...
double iHKSignalColorValue =
hkSBarOpenBuffer[barIndex] < hkSBarCloseBuffer[barIndex]
? bullishColorIDX
: bearishColorIDX;
hkSBarColorBuffer[barIndex] =
showHKSignalBars
? iHKSignalColorValue
: hideColorIDX;
}
/**
* Calculate Delta Oscillator Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateDelta(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
double iClose = close[barIndex];
double iOpen = open[barIndex];
double iVolume = (double)iVolume(_Symbol, _Period, barIndex);
//
bool isBullish = iClose > iOpen;
bool isBearish = iClose < iOpen;
//
// DELTA ...
double lastDelta =
isFirstBar
? emptyValue
: deltaBuffer[lastBarIndex];
double iAppliedVolume =
isBullish
? iVolume
: -1 * iVolume;
double iDelta =
lastDelta + iAppliedVolume;
deltaBuffer[barIndex] = iDelta;
//
// Calculate Delta Signal ...
int deltaSignalsCount = iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
deltaBuffer,
deltaSignalBuffer,
deltaSignalMethod //
);
}
/**
* Calculate Trend Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateTrend(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double iLow = low[barIndex];
double iHigh = high[barIndex];
double iClose = close[barIndex];
double iTrend = trendBuffer[barIndex];
//
bool isBullish = iTrend < iLow;
bool isBearish = iTrend > iHigh;
//
double iTrendState =
isBullish
? 1
: isBearish
? -1
: 0;
double iTrendColor =
iTrendState > 0
? bullishColorIDX
: iTrendState < 0
? bearishColorIDX
: neuturalColorIDX;
trendStateBuffer[barIndex] = iTrendState;
trendColorBuffer[barIndex] = showTrend
? iTrendColor
: hideColorIDX;
}
/**
* Calculate Volume Oscillators Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateVolume(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double iClose = close[barIndex];
double iOpen = open[barIndex];
double iVolume = (double)iVolume(_Symbol, _Period, barIndex);
//
bool isBullish = iClose > iOpen;
bool isBearish = iClose < iOpen;
//
double iBullishVolume = emptyValue;
double iBearishVolume = emptyValue;
if (isBullish)
{
iBullishVolume = iVolume;
}
else if (isBearish)
{
iBearishVolume = iVolume;
}
else
{
//
double iHalfVolume = iVolume / 2;
//
iBullishVolume = iHalfVolume;
iBearishVolume = iHalfVolume;
}
bullishVolumeBuffer[barIndex] = iBullishVolume;
bearishVolumeBuffer[barIndex] = iBearishVolume;
//
// Calculate Volume Signals ...
//
int bullishVolumeSignalsCount = iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
bullishVolumeBuffer,
bullishVolumeSignalBuffer,
volumeSignalMethod //
);
//
int bearishVolumeSignalsCount = iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
bearishVolumeBuffer,
bearishVolumeSignalBuffer,
volumeSignalMethod //
);
}
/**
* Calculate ATR Band Values ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateATRBand(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double iATR = atrBuffer[barIndex];
double iAppliedATR = atrMultiplier * iATR;
double iATRUpperPrice = GetAppliedPrice(
atrUpperPriceType,
open,
high,
low,
close,
barIndex //
);
double iATRLowerPrice = GetAppliedPrice(
atrLowerPriceType,
open,
high,
low,
close,
barIndex //
);
double iATRUpper = iATRUpperPrice + iAppliedATR;
double iATRLower = iATRLowerPrice - iAppliedATR;
atrUpperRawBuffer[barIndex] = iATRUpper;
atrLowerRawBuffer[barIndex] = iATRLower;
//
bool canSignalATR = IsValid(atrSignalMethod);
if (canSignalATR)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
atrUpperRawBuffer,
atrUpperBuffer,
atrSignalMethod //
);
//
// Lower ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
mAppliedLength,
atrLowerRawBuffer,
atrLowerBuffer,
atrSignalMethod //
);
}
else
{
//
atrUpperBuffer[barIndex] = iATRUpper;
atrLowerBuffer[barIndex] = iATRLower;
}
}
/**
* Calculate Specified Market Cycle Info ...
*
* @param barIndex: Integer, Bar Index ...
* @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ...
* @param hhBuffer: Highest High Buffer Reference ...
* @param llBuffer: Lowest Low Buffer Reference ...
*/
void CalculateCycle(
int barIndex,
ENUM_X_MARKET_CYCLES cycle,
double &hhBuffer[],
double &llBuffer[] //
)
{
//
XOHCL bar;
bool isBarInited = bar.Init(
_Symbol,
_Period,
barIndex
//
);
if (!isBarInited)
{
return;
}
//
int mLength = 0;
switch (cycle)
{
//
case X_MARKET_CYCLE_SHORT:
mLength = mSCLength;
break;
//
case X_MARKET_CYCLE_MEDIUM:
mLength = mMCLength;
break;
//
case X_MARKET_CYCLE_LONG:
mLength = mLCLength;
break;
//
case X_MARKET_CYCLE_HIND:
mLength = mHCLength;
break;
}
//
if (mLength == 0)
{
return;
}
//
// Find Highest High ...
double hhValue = bar.FindHighest(
mLength,
upperMode //
);
hhBuffer[barIndex] = hhValue;
//
// Find Lowest Low ...
double llValue = bar.FindLowest(
mLength,
lowerMode //
);
llBuffer[barIndex] = llValue;
//
bar.Clean();
}
//
//
//
/**
* Reading Bar Style and Store it ...
*/
void ReadBarStyle()
{
//
long chartId = ChartID();
//
_upColor = GetChartUpColor(chartId);
_downColor = GetChartDownColor(chartId);
_lineColor = GetChartLineColor(chartId);
_bullishColor = GetChartBullishColor(chartId);
_bearishColor = GetChartBearishColor(chartId);
}
/**
* Show Bars ...
*/
void ShowBars()
{
//
long chartId = ChartID();
//
SetChartUpColor(_upColor, chartId);
SetChartDownColor(_downColor, chartId);
SetChartLineColor(_lineColor, chartId);
SetChartBullishColor(_bullishColor, chartId);
SetChartBearishColor(_bearishColor, chartId);
}
/**
* Hide Bars ...
*/
void HideBars()
{
//
long chartId = ChartID();
//
SetChartUpColor(CLR_NONE, chartId);
SetChartDownColor(CLR_NONE, chartId);
SetChartLineColor(CLR_NONE, chartId);
SetChartBullishColor(CLR_NONE, chartId);
SetChartBearishColor(CLR_NONE, chartId);
}
//
// Process Handlers ...
//
/**
* Prepare Market Conditions ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void PrepareMarketConditions(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Check Some Requirements ...
int lastBarIndex = barIndex + 1;
int maxBarIndex = startCalculationForLastBars > 0
? startCalculationForLastBars
: ratesTotal;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
// Recieve Bar ...
XOHCL iBar;
XOHCL iPBar;
mHas = iBar.Init(
_Symbol,
_Period,
barIndex
//
);
mHas =
mHas &&
iBar.GetPreviousBar(iPBar);
if (!mHas)
{
return;
}
//
int cIndex = barIndex;
int pIndex = barIndex + 1;
int p2Index = barIndex + 2;
int p3Index = barIndex + 3;
//
// Check Required Bars Passed ...
mHas = p3Index <= maxBarIndex;
if (!mHas)
{
return;
}
//
// Start Preparing Conditions ...
//
// Liquidities ...
//
isLiquidity =
mBarAnalyser
.IsRejected(
iBar,
mDir,
true,
true //
);
isBullishLiquidity =
isLiquidity &&
IsBullish(mDir);
isBearishLiquidity =
isLiquidity &&
IsBearish(mDir);
//
// Trigger Bars Conditions ...
//
// Cond 1 ...
isTriggerBarCond1 =
mBarAnalyser
.IsValidForTrigger(
iPBar,
mDir,
true, // Cond 1 ...
false, // Cond 2 ...
false, // Cond 3 ...
false, // Cond 4 ...
false, // Cond 5 ...
false, // Cond 6 ...
false // Cond 7 ...
);
isTriggerBarCond1Bullish =
isTriggerBarCond1 &&
IsBullish(mDir);
isTriggerBarCond1Bearish =
isTriggerBarCond1 &&
IsBearish(mDir);
if (isTriggerBarCond1)
{
mArrowNamePrefix += "1";
}
//
// Cond 2 ...
isTriggerBarCond2 =
mBarAnalyser
.IsValidForTrigger(
iPBar,
mDir,
false, // Cond 1 ...
true, // Cond 2 ...
false, // Cond 3 ...
false, // Cond 4 ...
false, // Cond 5 ...
false, // Cond 6 ...
false // Cond 7 ...
);
isTriggerBarCond2Bullish =
isTriggerBarCond2 &&
IsBullish(mDir);
isTriggerBarCond2Bearish =
isTriggerBarCond2 &&
IsBearish(mDir);
if (isTriggerBarCond2)
{
mArrowNamePrefix += ",2";
}
//
// Cond 3 ...
isTriggerBarCond3 =
mBarAnalyser
.IsValidForTrigger(
iPBar,
mDir,
false, // Cond 1 ...
false, // Cond 2 ...
true, // Cond 3 ...
false, // Cond 4 ...
false, // Cond 5 ...
false, // Cond 6 ...
false // Cond 7 ...
);
isTriggerBarCond3Bullish =
isTriggerBarCond3 &&
IsBullish(mDir);
isTriggerBarCond3Bearish =
isTriggerBarCond3 &&
IsBearish(mDir);
if (isTriggerBarCond3)
{
mArrowNamePrefix += ",3";
}
//
// Cond 4 ...
isTriggerBarCond4 =
mBarAnalyser
.IsValidForTrigger(
iPBar,
mDir,
false, // Cond 1 ...
false, // Cond 2 ...
false, // Cond 3 ...
true, // Cond 4 ...
false, // Cond 5 ...
false, // Cond 6 ...
false // Cond 7 ...
);
isTriggerBarCond4Bullish =
isTriggerBarCond4 &&
IsBullish(mDir);
isTriggerBarCond4Bearish =
isTriggerBarCond4 &&
IsBearish(mDir);
if (isTriggerBarCond4)
{
mArrowNamePrefix += ",4";
}
//
// Cond 5 ...
isTriggerBarCond5 =
mBarAnalyser
.IsValidForTrigger(
iPBar,
mDir,
false, // Cond 1 ...
false, // Cond 2 ...
false, // Cond 3 ...
false, // Cond 4 ...
true, // Cond 5 ...
false, // Cond 6 ...
false // Cond 7 ...
);
isTriggerBarCond5Bullish =
isTriggerBarCond5 &&
IsBullish(mDir);
isTriggerBarCond5Bearish =
isTriggerBarCond5 &&
IsBearish(mDir);
if (isTriggerBarCond5)
{
mArrowNamePrefix += ",5";
}
//
// Cond 6 ...
isTriggerBarCond6 =
mBarAnalyser
.IsValidForTrigger(
iPBar,
mDir,
false, // Cond 1 ...
false, // Cond 2 ...
false, // Cond 3 ...
false, // Cond 4 ...
false, // Cond 5 ...
true, // Cond 6 ...
false // Cond 7 ...
);
isTriggerBarCond6Bullish =
isTriggerBarCond6 &&
IsBullish(mDir);
isTriggerBarCond6Bearish =
isTriggerBarCond6 &&
IsBearish(mDir);
if (isTriggerBarCond6)
{
mArrowNamePrefix += ",6";
}
//
// Cond 7 ...
isTriggerBarCond7 =
mBarAnalyser
.IsValidForTrigger(
iPBar,
mDir,
false, // Cond 1 ...
false, // Cond 2 ...
false, // Cond 3 ...
false, // Cond 4 ...
false, // Cond 5 ...
false, // Cond 6 ...
true // Cond 7 ...
);
isTriggerBarCond7Bullish =
isTriggerBarCond7 &&
IsBullish(mDir);
isTriggerBarCond7Bearish =
isTriggerBarCond7 &&
IsBearish(mDir);
if (isTriggerBarCond7)
{
mArrowNamePrefix += ",7";
}
//
// Summarizing Trigger Bar ...
//
isTriggerBar =
isTriggerBarCond1 ||
isTriggerBarCond2 ||
isTriggerBarCond3 ||
isTriggerBarCond4 ||
isTriggerBarCond5 ||
isTriggerBarCond6 ||
isTriggerBarCond7;
//
isTriggerBarBullish =
isTriggerBarCond1Bullish ||
isTriggerBarCond2Bullish ||
isTriggerBarCond3Bullish ||
isTriggerBarCond4Bullish ||
isTriggerBarCond5Bullish ||
isTriggerBarCond6Bullish ||
isTriggerBarCond7Bullish;
//
isTriggerBarBearish =
isTriggerBarCond1Bearish ||
isTriggerBarCond2Bearish ||
isTriggerBarCond3Bearish ||
isTriggerBarCond4Bearish ||
isTriggerBarCond5Bearish ||
isTriggerBarCond6Bearish ||
isTriggerBarCond7Bearish;
//
// Resetting Counters Based on Conditions ...
//
// XPV ...
//
if (!isSamePeak)
{
//
mSamePeakCount = 0;
mSamePeakGoldenMin = 0;
mSamePeakGoldenMax = 0;
}
//
if (!isSameVale)
{
//
mSameValeCount = 0;
mSameValeGoldenMin = 0;
mSameValeGoldenMax = 0;
}
//
if (!isSamePeakGolden)
{
mSamePeakGoldenCount = 0;
}
//
if (!isSameValeGolden)
{
mSameValeGoldenCount = 0;
}
//
// XKI ...
//
if (!isSameKI)
{
mSameKICount = 0;
}
//
if (!isSameBullishKI)
{
mSameBullishKICount = 0;
}
//
if (!isSameBearishKI)
{
mSameBearishKICount = 0;
}
//
// XSB ...
//
if (isSBSwitchedToBullish)
{
//
mSameSBCount = 0;
mSameBullishSBCount = 0;
}
//
if (isSBSwitchedToBearish)
{
//
mSameSBCount = 0;
mSameBearishSBCount = 0;
}
//
// XSAR ...
//
if (isSarSwitchedToBullish)
{
//
mSameSarCount = 0;
mSameBullishSarCount = 0;
}
//
if (isSarSwitchedToBearish)
{
//
mSameSarCount = 0;
mSameBearishSarCount = 0;
}
//
// XHKS ...
//
if (isHKSSwitchedToBullish)
{
//
mSameHKSCount = 0;
mSameBullishHKSCount = 0;
}
//
if (isHKSSwitchedToBearish)
{
//
mSameHKSCount = 0;
mSameBearishHKSCount = 0;
}
//
// XTREND ...
//
if (isTrendSwitchedToBullish)
{
//
mSameTrendCount = 0;
mSameBullishTrendCount = 0;
}
//
if (isTrendSwitchedToBearish)
{
//
mSameTrendCount = 0;
mSameBearishTrendCount = 0;
}
//
// Preparing Conditions ...
//
// XPV ...
//
isSamePeak = peakBuffer[pIndex] == peakBuffer[p2Index];
isSamePeakP = peakBuffer[p2Index] == peakBuffer[p3Index];
//
isSameVale = valeBuffer[pIndex] == valeBuffer[p2Index];
isSameValeP = valeBuffer[p2Index] == valeBuffer[p3Index];
//
isPeakOverLast = peakBuffer[pIndex] > peakBuffer[p2Index];
isPeakUnderLast = peakBuffer[pIndex] < peakBuffer[p2Index];
//
isValeOverLast = valeBuffer[pIndex] > valeBuffer[p2Index];
isValeUnderLast = valeBuffer[pIndex] < valeBuffer[p2Index];
//
isSamePeakOverLast =
isSamePeakP &&
isPeakOverLast;
isSamePeakUnderLast =
isSamePeakP &&
isPeakUnderLast;
//
isSameValeOverLast =
isSameValeP &&
isValeOverLast;
isSameValeUnderLast =
isSameValeP &&
isValeUnderLast;
//
isSamePeakGolden = peakGoldenBuffer[pIndex] == peakGoldenBuffer[p2Index];
isSamePeakGoldenP = peakGoldenBuffer[p2Index] == peakGoldenBuffer[p3Index];
//
isSameValeGolden = valeGoldenBuffer[pIndex] == valeGoldenBuffer[p2Index];
isSameValeGoldenP = valeGoldenBuffer[p2Index] == valeGoldenBuffer[p3Index];
//
isPeakGoldenOverLast = peakGoldenBuffer[pIndex] > peakGoldenBuffer[p2Index];
isPeakGoldenUnderLast = peakGoldenBuffer[pIndex] < peakGoldenBuffer[p2Index];
//
isValeGoldenOverLast = valeGoldenBuffer[pIndex] > valeGoldenBuffer[p2Index];
isValeGoldenUnderLast = valeGoldenBuffer[pIndex] < valeGoldenBuffer[p2Index];
//
isSamePeakGoldenOverLast =
isSamePeakGoldenP &&
isPeakGoldenOverLast;
isSamePeakGoldenUnderLast =
isSamePeakGoldenP &&
isPeakGoldenUnderLast;
//
isSameValeGoldenOverLast =
isSameValeGoldenP &&
isValeGoldenOverLast;
isSameValeGoldenUnderLast =
isSameValeGoldenP &&
isSameValeGoldenUnderLast;
//
// XSAR ...
//
isSarBullish = sarStateBuffer[pIndex] > 0;
isSarBullishP = sarStateBuffer[p2Index] > 0;
//
isSarBearish = sarStateBuffer[pIndex] < 0;
isSarBearishP = sarStateBuffer[p2Index] < 0;
//
isSarSwitchedToBullish =
isSarBullish &&
!isSarBullishP;
isSarSwitchedToBearish =
isSarBearish &&
!isSarBearishP;
//
// XSB ...
//
isSBBullish = sBarCloseBuffer[pIndex] > sBarOpenBuffer[pIndex];
isSBBullishP = sBarCloseBuffer[p2Index] > sBarOpenBuffer[p2Index];
//
isSBBearish = sBarCloseBuffer[pIndex] < sBarOpenBuffer[pIndex];
isSBBearishP = sBarCloseBuffer[p2Index] < sBarOpenBuffer[p2Index];
//
isSBSwitchedToBullish =
isSBBullish &&
!isSBBullishP;
isSBSwitchedToBearish =
isSBBearish &&
!isSBBearishP;
//
mSBMin = MathMin(sBarCloseBuffer[pIndex], sBarOpenBuffer[pIndex]);
mSBMax = MathMax(sBarCloseBuffer[pIndex], sBarOpenBuffer[pIndex]);
//
mSBPMin = MathMin(sBarCloseBuffer[p2Index], sBarOpenBuffer[p2Index]);
mSBPMax = MathMax(sBarCloseBuffer[p2Index], sBarOpenBuffer[p2Index]);
//
// XHKS ...
//
isHKSBullish = hkSBarCloseBuffer[pIndex] > hkSBarOpenBuffer[pIndex];
isHKSBullishP = hkSBarCloseBuffer[p2Index] > hkSBarOpenBuffer[p2Index];
//
isHKSBearish = hkSBarCloseBuffer[pIndex] < hkSBarOpenBuffer[pIndex];
isHKSBearishP = hkSBarCloseBuffer[p2Index] < hkSBarOpenBuffer[p2Index];
//
isHKSSwitchedToBullish =
isHKSBullish &&
!isHKSBullishP;
isHKSSwitchedToBearish =
isHKSBearish &&
!isHKSBearishP;
//
mHKSMin = MathMin(hkSBarCloseBuffer[pIndex], hkSBarOpenBuffer[pIndex]);
mHKSMax = MathMax(hkSBarCloseBuffer[pIndex], hkSBarOpenBuffer[pIndex]);
//
mHKSPMin = MathMin(hkSBarCloseBuffer[p2Index], hkSBarOpenBuffer[p2Index]);
mHKSPMax = MathMax(hkSBarCloseBuffer[p2Index], hkSBarOpenBuffer[p2Index]);
//
// XKI ...
//
isKIBullish = kiStateBuffer[pIndex] > 0;
isKIBullishP = kiStateBuffer[p2Index] > 0;
//
isKIBearish = kiStateBuffer[pIndex] < 0;
isKIBearishP = kiStateBuffer[p2Index] < 0;
//
isSameKI = kiBuffer[pIndex] == kiBuffer[p2Index];
isSameBullishKI =
isSameKI &&
isKIBullish;
isSameBearishKI =
isSameKI &&
isKIBearish;
//
isKISwitchedToBullish =
isKIBullish &&
!isKIBullishP;
isKISwitchedToBearish =
isKIBearish &&
!isKIBearishP;
//
// XTREND ...
//
isTrendBullish = trendStateBuffer[pIndex] > 0;
isTrendBullishP = trendStateBuffer[p2Index] > 0;
//
isTrendBearish = trendStateBuffer[pIndex] < 0;
isTrendBearishP = trendStateBuffer[p2Index] < 0;
//
isTrendSwitchedToBullish =
isTrendBullish &&
!isTrendBullishP;
isTrendSwitchedToBearish =
isTrendBearish &&
!isTrendBearishP;
//
// Detecting Counters and Direction Shifts and it's related Conditions ...
//
// XPV Counters ...
//
if (isSamePeak)
{
//
mSamePeakCount++;
mSamePeakGoldenMin =
mSamePeakGoldenMin == 0
? peakGoldenBuffer[pIndex]
: MathMin(mSamePeakGoldenMin, peakGoldenBuffer[pIndex]);
mSamePeakGoldenMax =
mSamePeakGoldenMax == 0
? peakGoldenBuffer[pIndex]
: MathMax(mSamePeakGoldenMax, peakGoldenBuffer[pIndex]);
}
//
if (isSameVale)
{
//
mSameValeCount++;
mSameValeGoldenMin =
mSameValeGoldenMin == 0
? valeGoldenBuffer[pIndex]
: MathMin(mSameValeGoldenMin, valeGoldenBuffer[pIndex]);
mSameValeGoldenMax =
mSameValeGoldenMax == 0
? valeGoldenBuffer[pIndex]
: MathMax(mSameValeGoldenMax, valeGoldenBuffer[pIndex]);
}
//
if (isSamePeakGolden)
{
mSamePeakGoldenCount++;
}
//
if (isSameValeGolden)
{
mSameValeGoldenCount++;
}
//
// XSB Shifts ...
//
// Detection ...
if (isSBSwitchedToBullish ||
isSBSwitchedToBearish)
{
//
mDirShift.at = iPBar.time;
mDirShift.symbol = _Symbol;
mDirShift.period = _Period;
//
mDirShift.type = "XSBSHFT";
//
mDirShift.after = 0;
mDirShift.before = 0;
//
if (isSBSwitchedToBullish)
{
//
mDirShift.after = mSBMax;
mDirShift.before = mSBPMax;
mDirShift.shiftTo = X_DIRECTION_BULLISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBullishSBChanges //
);
}
}
//
if (isSBSwitchedToBearish)
{
//
mDirShift.after = mSBMin;
mDirShift.before = mSBPMin;
mDirShift.shiftTo = X_DIRECTION_BEARISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBearishSBChanges //
);
}
}
//
mDirShift.Clean();
}
//
// Parsers ...
//
mHas = isSBBullish &&
HasChild(mBearishSBChanges);
if (mHas)
{
isBullishSBBreakedLast = mSBMin > mBearishSBChanges[ArraySize(mBearishSBChanges) - 1].after;
}
//
mHas = isSBBearish &&
HasChild(mBullishSBChanges);
if (mHas)
{
isBearishSBBreakedLast = mSBMax < mBullishSBChanges[ArraySize(mBullishSBChanges) - 1].after;
}
//
// Counters ...
//
if (!isSBSwitchedToBullish &&
!isSBSwitchedToBearish)
{
//
bool isDBullish =
isSBBullish &&
isSBBullishP;
if (isDBullish)
{
mSameBullishSBCount++;
}
//
bool isDBearish =
isSBBearish &&
isSBBearishP;
if (isDBearish)
{
mSameBearishSBCount++;
}
//
if (isDBullish ||
isDBearish)
{
mSameSBCount++;
}
}
//
// XSAR Shifts ...
//
// Detection ...
if (isSarSwitchedToBullish ||
isSarSwitchedToBearish)
{
//
mDirShift.at = iPBar.time;
mDirShift.symbol = _Symbol;
mDirShift.period = _Period;
//
mDirShift.type = "XSARSHFT";
//
mDirShift.after = sarBuffer[pIndex];
mDirShift.before = sarBuffer[p2Index];
//
if (isSarSwitchedToBullish)
{
//
mDirShift.shiftTo = X_DIRECTION_BULLISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBullishSarChanges //
);
}
}
//
if (isSarSwitchedToBearish)
{
//
mDirShift.shiftTo = X_DIRECTION_BEARISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBearishSarChanges //
);
}
}
//
mDirShift.Clean();
}
//
// Parsers ...
//
mHas = isSarBullish &&
HasChild(mBearishSarChanges);
if (mHas)
{
isBullishSarBreakedLast = sarBuffer[pIndex] > mBearishSarChanges[ArraySize(mBearishSarChanges) - 1].after;
}
//
mHas = isSarBearish &&
HasChild(mBullishSarChanges);
if (mHas)
{
isBearishSarBreakedLast = sarBuffer[pIndex] < mBullishSarChanges[ArraySize(mBullishSarChanges) - 1].after;
}
//
// Counters ...
//
if (!isSarSwitchedToBullish &&
!isSarSwitchedToBearish)
{
//
bool isDBullish =
isSarBullish &&
isSarBullishP;
if (isDBullish)
{
mSameBullishSarCount++;
}
//
bool isDBearish =
isSarBearish &&
isSarBearishP;
if (isDBearish)
{
mSameBearishSarCount++;
}
//
if (isDBullish ||
isDBearish)
{
mSameSarCount++;
}
}
//
// XHKS Shifts ...
//
// Detection ...
if (isHKSSwitchedToBullish ||
isHKSSwitchedToBearish)
{
//
mDirShift.at = iPBar.time;
mDirShift.symbol = _Symbol;
mDirShift.period = _Period;
//
mDirShift.type = "XHKSSHFT";
//
mDirShift.after = 0;
mDirShift.before = 0;
//
if (isHKSSwitchedToBullish)
{
//
mDirShift.after = mHKSMax;
mDirShift.before = mHKSPMax;
mDirShift.shiftTo = X_DIRECTION_BULLISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBullishHKSChanges //
);
}
}
//
if (isHKSSwitchedToBearish)
{
//
mDirShift.after = mHKSMin;
mDirShift.before = mHKSPMin;
mDirShift.shiftTo = X_DIRECTION_BEARISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBearishHKSChanges //
);
}
}
//
mDirShift.Clean();
}
//
// Parsers ...
//
mHas = isHKSBullish &&
HasChild(mBearishHKSChanges);
if (mHas)
{
isBullishHKSBreakedLast = mHKSMin > mBearishHKSChanges[ArraySize(mBearishHKSChanges) - 1].after;
}
//
mHas = isHKSBearish &&
HasChild(mBullishHKSChanges);
if (mHas)
{
isBearishHKSBreakedLast = mHKSMax < mBullishHKSChanges[ArraySize(mBullishHKSChanges) - 1].after;
}
//
// Counters ...
//
if (!isHKSSwitchedToBullish &&
!isHKSSwitchedToBearish)
{
//
bool isDBullish =
isHKSBullish &&
isHKSBullishP;
if (isDBullish)
{
mSameBullishHKSCount++;
}
//
bool isDBearish =
isHKSBearish &&
isHKSBearishP;
if (isDBearish)
{
mSameBearishHKSCount++;
}
//
if (isDBullish ||
isDBearish)
{
mSameHKSCount++;
}
}
//
// XKI Shifts ...
//
// Detection ...
if (isKISwitchedToBullish ||
isKISwitchedToBearish)
{
//
mDirShift.at = iPBar.time;
mDirShift.symbol = _Symbol;
mDirShift.period = _Period;
//
mDirShift.type = "XKISHFT";
//
mDirShift.after = kiBuffer[pIndex];
mDirShift.before = kiBuffer[p2Index];
//
if (isKISwitchedToBullish)
{
//
mDirShift.shiftTo = X_DIRECTION_BULLISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBullishKIChanges //
);
}
}
//
if (isKISwitchedToBearish)
{
//
mDirShift.shiftTo = X_DIRECTION_BEARISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBearishKIChanges //
);
}
}
//
mDirShift.Clean();
}
//
// Parsers ...
//
mHas = isKIBullish &&
HasChild(mBearishKIChanges);
if (mHas)
{
isBullishKIBreakedLast = kiBuffer[pIndex] > mBearishKIChanges[ArraySize(mBearishKIChanges) - 1].after;
}
//
mHas = isKIBearish &&
HasChild(mBullishKIChanges);
if (mHas)
{
isBearishKIBreakedLast = kiBuffer[pIndex] < mBullishKIChanges[ArraySize(mBullishKIChanges) - 1].after;
}
//
// Counters ...
//
if (isSameKI)
{
mSameKICount++;
}
//
if (isSameBullishKI)
{
mSameBullishKICount++;
}
//
if (isSameBearishKI)
{
mSameBearishKICount++;
}
//
// XTREND Shifts ...
//
// Detection ...
if (isTrendSwitchedToBullish ||
isTrendSwitchedToBearish)
{
//
mDirShift.at = iPBar.time;
mDirShift.symbol = _Symbol;
mDirShift.period = _Period;
//
mDirShift.type = "XTRENDSHFT";
//
mDirShift.after = trendBuffer[pIndex];
mDirShift.before = trendBuffer[p2Index];
//
if (isTrendSwitchedToBullish)
{
//
mDirShift.shiftTo = X_DIRECTION_BULLISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBullishTrendChanges //
);
}
}
//
if (isTrendSwitchedToBearish)
{
//
mDirShift.shiftTo = X_DIRECTION_BEARISH;
//
if (mDirShift.IsValid())
{
//
AddIfNotExists(
mDirShift,
mBearishTrendChanges //
);
}
}
//
mDirShift.Clean();
}
//
// Parsers ...
//
mHas = isTrendBullish &&
HasChild(mBearishTrendChanges);
if (mHas)
{
isBullishTrendBreakedLast = trendBuffer[pIndex] > mBearishTrendChanges[ArraySize(mBearishTrendChanges) - 1].after;
}
//
mHas = isTrendBearish &&
HasChild(mBullishTrendChanges);
if (mHas)
{
isBearishTrendBreakedLast = trendBuffer[pIndex] < mBullishTrendChanges[ArraySize(mBullishTrendChanges) - 1].after;
}
//
// Counters ...
//
if (!isTrendSwitchedToBullish &&
!isTrendSwitchedToBearish)
{
//
bool isDBullish =
isTrendBullish &&
isTrendBullishP;
if (isDBullish)
{
mSameBullishTrendCount++;
}
//
bool isDBearish =
isTrendBearish &&
isTrendBearishP;
if (isDBearish)
{
mSameBearishTrendCount++;
}
//
if (isDBullish ||
isDBearish)
{
mSameTrendCount++;
}
}
//
//
//
//
// Cleanup Resources ...
//
iBar.Clean();
iPBar.Clean();
mDirShift.Clean();
}
/**
* Detect POI(s) ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void DetectPOIs(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Check Some Requirements ...
int lastBarIndex = barIndex + 1;
int maxBarIndex = startCalculationForLastBars > 0
? startCalculationForLastBars
: ratesTotal;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
// Recieve Bar ...
XOHCL iBar;
XOHCL iPBar;
mHas = iBar.Init(
_Symbol,
_Period,
barIndex
//
);
mHas =
mHas &&
iBar.GetPreviousBar(iPBar);
if (!mHas)
{
return;
}
//
// Liquidities ...
if (mDetectLiquidities)
{
//
if (isLiquidity)
{
//
XBoxZone iLiq;
//
iLiq.type = "XLIQ";
iLiq.symbol = _Symbol;
iLiq.period = _Period;
//
if (isBullishLiquidity)
{
//
iLiq.at = iBar.time;
iLiq.lower = iBar.low;
iLiq.to = iBar.NextAt();
iLiq.from = iBar.BeforeOn();
iLiq.upper = iBar.GetDown();
iLiq.dir = X_DIRECTION_BULLISH;
//
if (iLiq.IsValid())
{
//
AddIfNotExists(
iLiq,
mBullishLiquidities //
);
}
}
//
if (isBearishLiquidity)
{
//
iLiq.at = iBar.time;
iLiq.upper = iBar.high;
iLiq.to = iBar.NextAt();
iLiq.lower = iBar.GetUp();
iLiq.from = iBar.BeforeOn();
iLiq.dir = X_DIRECTION_BEARISH;
//
if (iLiq.IsValid())
{
//
AddIfNotExists(
iLiq,
mBearishLiquidities //
);
}
}
//
iLiq.Clean();
}
}
//
// Range Breakes ...
int mRangeBreakesMinLength = 5;
if (mDetectRangeBreakes)
{
//
XBoxZone iRB;
//
iRB.type = "XRNGB";
iRB.at = iPBar.time;
iRB.to = iPBar.time;
iRB.symbol = _Symbol;
iRB.period = _Period;
//
// Bullish ...
bool isBullishPeakPOI =
(isSamePeakOverLast &&
mSamePeakCount >= mRangeBreakesMinLength);
bool isBullishValePOI =
(isSameValeOverLast &&
mSameValeCount >= mRangeBreakesMinLength);
mHas =
isBullishPeakPOI ||
isBullishValePOI;
if (mHas)
{
//
if (isBullishPeakPOI)
{
//
iRB.lower = mSamePeakGoldenMax;
iRB.upper = peakBuffer[barIndex + 1];
//
iRB.from = iPBar.time - (mSamePeakCount * PeriodSeconds(_Period));
}
//
if (isBullishValePOI)
{
//
iRB.upper = mSameValeGoldenMin;
iRB.lower = valeBuffer[barIndex + 1];
//
iRB.from = iPBar.time - (mSameValeCount * PeriodSeconds(_Period));
}
//
iRB.dir = X_DIRECTION_BULLISH;
//
if (iRB.IsValid())
{
//
AddIfNotExists(
iRB,
mBullishRangeBreakes //
);
}
}
//
// Bearish ...
bool isBearishPeakPOI =
(isSamePeakUnderLast &&
mSamePeakCount >= mRangeBreakesMinLength);
bool isBearishValePOI =
(isSameValeUnderLast &&
mSameValeCount >= mRangeBreakesMinLength);
mHas =
isBearishPeakPOI ||
isBearishValePOI;
if (mHas)
{
//
if (isBearishPeakPOI)
{
//
iRB.lower = mSamePeakGoldenMax;
iRB.upper = peakBuffer[barIndex + 1];
//
iRB.from = iPBar.time - (mSamePeakCount * PeriodSeconds(_Period));
}
//
if (isBearishValePOI)
{
//
iRB.upper = mSameValeGoldenMin;
iRB.lower = valeBuffer[barIndex + 1];
//
iRB.from = iPBar.time - (mSameValeCount * PeriodSeconds(_Period));
}
//
iRB.dir = X_DIRECTION_BEARISH;
//
if (iRB.IsValid())
{
//
AddIfNotExists(
iRB,
mBearishRangeBreakes //
);
}
}
//
iRB.Clean();
}
//
// Cleanup Resources ...
//
iBar.Clean();
iPBar.Clean();
}
/**
* Validate Detected POI(s) ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void ValidatePOIs(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLength = 3;
//
// Liquidities ...
//
// Bullish ...
mHas = HasChild(mBullishLiquidities);
if (mHas)
{
//
ValidateBoxes(
mBullishLiquidities,
barIndex,
barsLength //
);
}
//
// Bearish ...
mHas = HasChild(mBearishLiquidities);
if (mHas)
{
//
ValidateBoxes(
mBearishLiquidities,
barIndex,
barsLength //
);
}
//
// Range Breakes ...
//
// Bullish ...
mHas = HasChild(mBullishRangeBreakes);
if (mHas)
{
//
ValidateBoxes(
mBullishRangeBreakes,
barIndex,
barsLength //
);
}
//
// Bearish ...
mHas = HasChild(mBearishRangeBreakes);
if (mHas)
{
//
ValidateBoxes(
mBearishRangeBreakes,
barIndex,
barsLength //
);
}
//
}
/**
* Draw Detected POI(s) ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void DrawPOIs(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
datetime to = GetBarTime(
_Symbol,
_Period,
barIndex //
);
//
// Liquidities ...
if (mDrawLiquidities)
{
//
// Bullish ...
mCount = ArraySize(mBullishLiquidities);
mHas = IsValidSize(mCount);
if (mHas)
{
//
for (int i = 0; i < mCount; i++)
{
//
XBoxZone iBox = mBullishLiquidities[i];
iBox.to = to;
//
XCBoxObject *iBObj;
mHas = mDrawer.DrawBox(
iBox,
iBObj //
);
if (mHas)
{
//
if (iBox.IsBullish())
{
//
mDrawer.ApplyStyle(
iBObj,
mBullishLiquidityStyle //
);
}
else
{
//
mDrawer.ApplyStyle(
iBObj,
mBearishLiquidityStyle //
);
}
//
mObjects.Add(iBObj);
}
//
iBox.Clean();
}
}
//
// Bearish ...
mCount = ArraySize(mBearishLiquidities);
mHas = IsValidSize(mCount);
if (mHas)
{
//
for (int i = 0; i < mCount; i++)
{
//
XBoxZone iBox = mBearishLiquidities[i];
iBox.to = to;
//
XCBoxObject *iBObj;
mHas = mDrawer.DrawBox(
iBox,
iBObj //
);
if (mHas)
{
//
if (iBox.IsBullish())
{
//
mDrawer.ApplyStyle(
iBObj,
mBullishLiquidityStyle //
);
}
else
{
//
mDrawer.ApplyStyle(
iBObj,
mBearishLiquidityStyle //
);
}
//
mObjects.Add(iBObj);
}
//
iBox.Clean();
}
}
}
//
// Range Breakes ...
if (mDrawRangeBreakes)
{
//
// Bullish ...
mCount = ArraySize(mBullishRangeBreakes);
mHas = IsValidSize(mCount);
if (mHas)
{
//
for (int i = 0; i < mCount; i++)
{
//
XBoxZone iBox = mBullishRangeBreakes[i];
iBox.to = to;
//
XCBoxObject *iBObj;
mHas = mDrawer.DrawBox(
iBox,
iBObj //
);
if (mHas)
{
//
if (iBox.IsBullish())
{
//
mDrawer.ApplyStyle(
iBObj,
mBullishRangeBreakStyle //
);
}
else
{
//
mDrawer.ApplyStyle(
iBObj,
mBearishRangeBreakStyle //
);
}
//
mObjects.Add(iBObj);
}
//
iBox.Clean();
}
}
//
// Bearish ...
mCount = ArraySize(mBearishRangeBreakes);
mHas = IsValidSize(mCount);
if (mHas)
{
//
for (int i = 0; i < mCount; i++)
{
//
XBoxZone iBox = mBearishRangeBreakes[i];
iBox.to = to;
//
XCBoxObject *iBObj;
mHas = mDrawer.DrawBox(
iBox,
iBObj //
);
if (mHas)
{
//
if (iBox.IsBullish())
{
//
mDrawer.ApplyStyle(
iBObj,
mBullishRangeBreakStyle //
);
}
else
{
//
mDrawer.ApplyStyle(
iBObj,
mBearishRangeBreakStyle //
);
}
//
mObjects.Add(iBObj);
}
//
iBox.Clean();
}
}
}
}
/**
* Process Custom Analysing Senarios ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void DoProcess(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Here we Can Detect Conditions ...
//
// Check Some Requirements ...
int lastBarIndex = barIndex + 1;
int maxBarIndex = startCalculationForLastBars > 0
? startCalculationForLastBars
: ratesTotal;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
// Recieve Bar ...
XOHCL iBar;
XOHCL iPBar;
mHas = iBar.Init(
_Symbol,
_Period,
barIndex
//
);
mHas =
mHas &&
iBar.GetPreviousBar(iPBar);
if (!mHas)
{
return;
}
//
// Trigger Bar's Conditions ...
//
// Bullish ...
bool isTBBullish =
//
iBar.IsBullish() &&
isTriggerBarBullish &&
iBar.low > iPBar.low
//
;
//
// Bearish ...
bool isTBBearish =
//
iBar.IsBearish() &&
isTriggerBarBearish &&
iBar.high < iPBar.high
//
;
//
// KI Breakes Validation Conditions ...
//
// Bullish ...
bool isKIBullishBreakes =
//
isKIBullish &&
iBar.IsBullish() &&
iPBar.IsBreaked(
kiBuffer[barIndex + 1],
X_DIRECTION_BULLISH,
X_FIBO_LEVEL_500, // Fibo Level ...
X_BOUNDARY_PRICE_HIGH_LOW // Boundary Type ...
)
//
;
//
// Bearish ...
bool isKIBearishBreakes =
//
isKIBearish &&
iBar.IsBearish() &&
iPBar.IsBreaked(
kiBuffer[barIndex + 1],
X_DIRECTION_BEARISH,
X_FIBO_LEVEL_500, // Fibo Level ...
X_BOUNDARY_PRICE_HIGH_LOW // Boundary Type ...
)
//
;
//
// Conditions By ...
// - Rejecting Trend Line;
// - Trend Line is Over HK;
// - SAR Directional;
// - KI Directional;
// - HKS Directional;
//
bool isTrendsBasedBullish =
//
isKIBullish &&
isSarBullish &&
isHKSBullish &&
//
// TODO: Implement Trend Line is Over HKS MAX ...
//
// Rejectiong Trend Line ...
iPBar.IsBullish() &&
iPBar.low < trendBuffer[barIndex + 1] &&
iPBar.GetDown() > trendBuffer[barIndex + 1]
//
;
//
bool isTrendBasedBearish =
//
isKIBearish &&
isSarBearish &&
isHKSBearish &&
//
// TODO: Implement Trend Line is Under HKS MIN ...
//
// Rejecting Trend Line ...
iPBar.IsBearish() &&
iPBar.high > trendBuffer[barIndex + 1] &&
iPBar.GetUp() < trendBuffer[barIndex + 1]
//
;
//
// Summarization Conditions ...
//
// Bullish ...
mIsBullish =
//
// false
// isTBBullish &&
// isKIBullishBreakes
isTrendsBasedBullish
//
;
//
// Bearish ...
mIsBearish =
//
// false
// isTBBearish &&
// isKIBearishBreakes
isTrendBasedBearish
//
;
//
// Signal Summarize ...
mHasSignal =
mIsBullish ||
mIsBearish;
//
// Handling Signal ...
if (mHasSignal)
{
//
// Creating Signal Box ...
mSignalBox.type = "XSGB";
mSignalBox.at = iBar.time;
mSignalBox.to = iBar.time;
mSignalBox.symbol = _Symbol;
mSignalBox.period = _Period;
mSignalBox.lower = iPBar.low;
mSignalBox.from = iPBar.time;
mSignalBox.upper = iPBar.high;
mSignalBox.dir =
mIsBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Converting Box to Signal ...
double rrs[] = {
1,
1.5,
2,
3 //
};
mHas = ToSignal(
mSignalBox,
mSignal,
rrs, // Risk To Reward Ratios ...
0 // Additional SL ...
);
//
// Draw Signal Box ...
if (mDrawSignalBoxes)
{
//
mHas = mSignalBox.IsValid();
if (mHas)
{
//
XCBoxObject *iSignalBoxObj;
mHas = mDrawer.DrawBox(
mSignalBox,
iSignalBoxObj,
!mDrawSignalBoxAtLines //
);
//
if (mHas)
{
//
// Styling Object ...
if (mSignalBox.IsBullish())
{
//
mDrawer.ApplyStyle(
iSignalBoxObj,
mBullishSignalBoxStyle //
);
}
else
{
//
mDrawer.ApplyStyle(
iSignalBoxObj,
mBearishSignalBoxStyle //
);
}
//
// Storing Object ...
mObjects.Add(iSignalBoxObj);
}
//
ZeroMemory(iSignalBoxObj);
}
}
//
// Draw Signal ...
if (mDrawSignals)
{
//
mHas = mSignal.IsValid();
if (mHas)
{
//
XCSignalObject *iSignalObj;
mHas = mDrawer.DrawSignal(
mSignal,
iSignalObj,
3 //
);
//
if (mHas)
{
mObjects.Add(iSignalObj);
}
//
ZeroMemory(iSignalObj);
}
}
//
// Draw Arrows ...
if (mDrawSignalArrows)
{
//
int arrowWidth = 3;
int arrowCode =
mIsBullish
? _bullishArrowCode
: _bearishArrowCode;
ENUM_X_PRICE arrowPriceType =
mIsBullish
? X_PRICE_LOW
: X_PRICE_HIGH;
color arrowColor =
mIsBullish
? _bullishArrowColor
: _bearishArrowColor;
ENUM_ARROW_ANCHOR arrowAnchor =
mIsBullish
? mBullishAnchor
: mBearishAnchor;
//
XCBarArrowObject *iSignalArrowObj;
mHas = mDrawer.CreateBarArrow(
iBar,
iSignalArrowObj,
arrowPriceType,
arrowCode,
arrowColor,
arrowWidth,
arrowAnchor,
mArrowNamePrefix //
);
if (mHas)
{
mObjects.Add(iSignalArrowObj);
}
//
ZeroMemory(iSignalArrowObj);
}
}
//
// Cleanup Resources ...
//
iBar.Clean();
iPBar.Clean();
mSignal.Clean();
mSignalBox.Clean();
//
mArrowNamePrefix = NULL;
}
//