1289 lines
28 KiB
Plaintext
1289 lines
28 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Indicator
|
|
// -------------------------------------------------
|
|
// Name: XPV
|
|
// Description: Peaks and Vales ...
|
|
//
|
|
//
|
|
// 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 XPV Indicator"
|
|
#property strict
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
#define ShortName "XPV"
|
|
|
|
//
|
|
// Includes Common Library ...
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
input group "Makret Cycles";
|
|
|
|
//
|
|
input group "Short";
|
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
|
|
|
//
|
|
input group "Medium";
|
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
input group "Long";
|
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
input group "Hind";
|
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
|
|
|
//
|
|
input group "Fibonacci";
|
|
input double fiboLevel1 = 0.236; // Fibio 1st Level
|
|
input double fiboLevel2 = 0.382; // Fibio 2st Level
|
|
input double fiboLevel3 = 0.5; // Fibio 3rd Level
|
|
input double fiboLevel4 = 0.618; // Fibio 4th Level
|
|
input double fiboLevel5 = 0.764; // Fibio 5th Level
|
|
|
|
//
|
|
input group "Boundary Detection Modes";
|
|
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
|
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
|
|
|
//
|
|
input group "Presentation";
|
|
input bool showPeaksAndVales = true; // Show Peaks and Vales
|
|
input bool showLevels = false; // Show Levels
|
|
input bool showConsolidations = false; // Show Consolidations
|
|
input bool showFibo1Levels = false; // Show Fibo 1st Level
|
|
input bool showFibo2Levels = false; // Show Fibo 2nd Level
|
|
input bool showFibo3Levels = false; // Show Fibo 3rd Level
|
|
input bool showFibo4Levels = false; // Show Fibo 4th Level
|
|
input bool showFibo5Levels = false; // Show Fibo 5th Level
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
#property indicator_chart_window
|
|
|
|
//
|
|
#property indicator_buffers 32
|
|
#property indicator_plots 32
|
|
|
|
//
|
|
// PEAKS ...
|
|
|
|
//
|
|
#define peaksBufferIndex 0
|
|
double peaksBuffer[];
|
|
|
|
//
|
|
#property indicator_label1 "XPV PEAKS"
|
|
#property indicator_type1 DRAW_ARROW
|
|
#property indicator_color1 clrAqua
|
|
#property indicator_width1 1
|
|
|
|
//
|
|
// VALES ...
|
|
|
|
//
|
|
#define valesBufferIndex 1
|
|
double valesBuffer[];
|
|
|
|
//
|
|
#property indicator_label2 "XPV VALES"
|
|
#property indicator_type2 DRAW_ARROW
|
|
#property indicator_color2 clrMagenta
|
|
#property indicator_width2 1
|
|
|
|
//
|
|
#define rBufferIndex 2
|
|
double rBuffer[];
|
|
|
|
//
|
|
#define rColorBufferIndex 3
|
|
double rColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label3 "XPV R"
|
|
#property indicator_type3 DRAW_COLOR_LINE
|
|
#property indicator_color3 CLR_NONE, clrAqua
|
|
#property indicator_style3 STYLE_DOT
|
|
#property indicator_width3 1
|
|
|
|
//
|
|
#define sBufferIndex 4
|
|
#define sBufferPlotIndex 3
|
|
double sBuffer[];
|
|
|
|
//
|
|
#define sColorBufferIndex 5
|
|
double sColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label4 "XPV S"
|
|
#property indicator_type4 DRAW_COLOR_LINE
|
|
#property indicator_color4 CLR_NONE, clrMagenta
|
|
#property indicator_style4 STYLE_DOT
|
|
#property indicator_width4 1
|
|
|
|
//
|
|
// FIBBO Level 1 ...
|
|
|
|
//
|
|
#define fl1BufferIndex 6
|
|
#define fl1BufferPlotIndex 4
|
|
double fl1Buffer[];
|
|
|
|
//
|
|
#define fl1ColorBufferIndex 7
|
|
double fl1ColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label5 "XPV FL1"
|
|
#property indicator_type5 DRAW_COLOR_LINE
|
|
#property indicator_color5 CLR_NONE, clrGold
|
|
#property indicator_style5 STYLE_DASHDOTDOT
|
|
#property indicator_width5 1
|
|
|
|
//
|
|
// FIBBO Level 2 ...
|
|
|
|
//
|
|
#define fl2BufferIndex 8
|
|
#define fl2BufferPlotIndex 5
|
|
double fl2Buffer[];
|
|
|
|
//
|
|
#define fl2ColorBufferIndex 9
|
|
double fl2ColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label6 "XPV FL2"
|
|
#property indicator_type6 DRAW_COLOR_LINE
|
|
#property indicator_color6 CLR_NONE, clrGold
|
|
#property indicator_style6 STYLE_DASHDOTDOT
|
|
#property indicator_width6 1
|
|
|
|
//
|
|
// FIBBO Level 3 ...
|
|
|
|
//
|
|
#define fl3BufferIndex 10
|
|
#define fl3BufferPlotIndex 6
|
|
double fl3Buffer[];
|
|
|
|
//
|
|
#define fl3ColorBufferIndex 11
|
|
double fl3ColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label7 "XPV FL3"
|
|
#property indicator_type7 DRAW_COLOR_LINE
|
|
#property indicator_color7 CLR_NONE, clrGold
|
|
#property indicator_style7 STYLE_DASHDOTDOT
|
|
#property indicator_width7 1
|
|
|
|
//
|
|
// FIBBO Level 4 ...
|
|
|
|
//
|
|
#define fl4BufferIndex 12
|
|
#define fl4BufferPlotIndex 7
|
|
double fl4Buffer[];
|
|
|
|
//
|
|
#define fl4ColorBufferIndex 13
|
|
double fl4ColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label8 "XPV FL4"
|
|
#property indicator_type8 DRAW_COLOR_LINE
|
|
#property indicator_color8 CLR_NONE, clrGold
|
|
#property indicator_style8 STYLE_DASHDOTDOT
|
|
#property indicator_width8 1
|
|
|
|
//
|
|
// FIBBO Level 5 ...
|
|
|
|
//
|
|
#define fl5BufferIndex 14
|
|
#define fl5BufferPlotIndex 8
|
|
double fl5Buffer[];
|
|
|
|
//
|
|
#define fl5ColorBufferIndex 15
|
|
double fl5ColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label9 "XPV FL5"
|
|
#property indicator_type9 DRAW_COLOR_LINE
|
|
#property indicator_color9 CLR_NONE, clrGold
|
|
#property indicator_style9 STYLE_DASHDOTDOT
|
|
#property indicator_width9 1
|
|
|
|
//
|
|
// LEVELS ...
|
|
|
|
//
|
|
#define scHHBufferIndex 16
|
|
#define scHHBufferPlotIndex 9
|
|
double scHHBuffer[];
|
|
|
|
//
|
|
#define scHHColorBufferIndex 17
|
|
double scHHColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label10 "XPV SHH"
|
|
#property indicator_type10 DRAW_COLOR_LINE
|
|
#property indicator_color10 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style10 STYLE_DOT
|
|
#property indicator_width10 1
|
|
|
|
#define scLLBufferIndex 18
|
|
#define scLLBufferPlotIndex 10
|
|
double scLLBuffer[];
|
|
|
|
//
|
|
#define scLLColorBufferIndex 19
|
|
double scLLColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label11 "XPV SLL"
|
|
#property indicator_type11 DRAW_COLOR_LINE
|
|
#property indicator_color11 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style11 STYLE_DOT
|
|
#property indicator_width11 1
|
|
|
|
//
|
|
#define mcHHBufferIndex 20
|
|
#define mcHHBufferPlotIndex 11
|
|
double mcHHBuffer[];
|
|
|
|
//
|
|
#define mcHHColorBufferIndex 21
|
|
double mcHHColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label12 "XPV MHH"
|
|
#property indicator_type12 DRAW_COLOR_LINE
|
|
#property indicator_color12 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style12 STYLE_DOT
|
|
#property indicator_width12 1
|
|
|
|
//
|
|
#define mcLLBufferIndex 22
|
|
#define mcLLBufferPlotIndex 12
|
|
double mcLLBuffer[];
|
|
|
|
//
|
|
#define mcLLColorBufferIndex 23
|
|
double mcLLColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label13 "XPV MLL"
|
|
#property indicator_type13 DRAW_COLOR_LINE
|
|
#property indicator_color13 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style13 STYLE_DOT
|
|
#property indicator_width13 1
|
|
|
|
//
|
|
#define lcHHBufferIndex 24
|
|
#define lcHHBufferPlotIndex 13
|
|
double lcHHBuffer[];
|
|
|
|
//
|
|
#define lcHHColorBufferIndex 25
|
|
double lcHHColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label14 "XPV LHH"
|
|
#property indicator_type14 DRAW_COLOR_LINE
|
|
#property indicator_color14 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style14 STYLE_DOT
|
|
#property indicator_width14 1
|
|
|
|
//
|
|
#define lcLLBufferIndex 26
|
|
#define lcLLBufferPlotIndex 14
|
|
double lcLLBuffer[];
|
|
|
|
//
|
|
#define lcLLColorBufferIndex 27
|
|
double lcLLColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label15 "XPV LLL"
|
|
#property indicator_type15 DRAW_COLOR_LINE
|
|
#property indicator_color15 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style15 STYLE_DOT
|
|
#property indicator_width15 1
|
|
|
|
//
|
|
#define hcHHBufferIndex 28
|
|
#define hcHHBufferPlotIndex 15
|
|
double hcHHBuffer[];
|
|
|
|
//
|
|
#define hcHHColorBufferIndex 29
|
|
double hcHHColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label16 "XPV HHH"
|
|
#property indicator_type16 DRAW_COLOR_LINE
|
|
#property indicator_color16 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style16 STYLE_DOT
|
|
#property indicator_width16 1
|
|
|
|
//
|
|
#define hcLLBufferIndex 30
|
|
#define hcLLBufferPlotIndex 16
|
|
double hcLLBuffer[];
|
|
|
|
//
|
|
#define hcLLColorBufferIndex 31
|
|
double hcLLColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label17 "XPV HLL"
|
|
#property indicator_type17 DRAW_COLOR_LINE
|
|
#property indicator_color17 CLR_NONE, clrLightGray, clrAqua, clrMagenta
|
|
#property indicator_style17 STYLE_DOT
|
|
#property indicator_width17 1
|
|
|
|
//
|
|
// Variables, Properties and etc ...
|
|
|
|
//
|
|
int maxLength;
|
|
|
|
//
|
|
double mHideColorIDX = 0;
|
|
|
|
//
|
|
// XMarketCycle sc;
|
|
int mSCLength = 0;
|
|
double mLastSCHH = 0;
|
|
double mLastSCLL = 0;
|
|
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
|
|
|
//
|
|
// XMarketCycle mc;
|
|
int mMCLength = 0;
|
|
double mLastMCHH = 0;
|
|
double mLastMCLL = 0;
|
|
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
|
|
|
//
|
|
// XMarketCycle lc;
|
|
int mLCLength = 0;
|
|
double mLastLCHH = 0;
|
|
double mLastLCLL = 0;
|
|
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
|
|
|
//
|
|
// XMarketCycle hc;
|
|
int mHCLength = 0;
|
|
double mLastHCHH = 0;
|
|
double mLastHCLL = 0;
|
|
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
|
|
|
//
|
|
double lastPeak = 0;
|
|
double lastVale = 0;
|
|
|
|
//
|
|
// Event Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
// Validate Inputs ...
|
|
if (!ValidateInputs())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
if (!InitMarketCycles())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// because in some cases we may have more than one input for
|
|
// calculation and we must prevent any calculation
|
|
// untill we pass the biggest input length, here we get max Input length
|
|
// and then wait until pass it ...
|
|
maxLength = ExtractMaxLengthOfInputs();
|
|
|
|
//
|
|
// Define Index Buffers ...
|
|
DefineBuffers();
|
|
|
|
//
|
|
// Set Indicator ShortName ...
|
|
SetIndicatorName();
|
|
|
|
//
|
|
// Init Succeed ...
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//
|
|
// DeInitialization ...
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//
|
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
// REASON_REMOVE 1 Program removed from a chart
|
|
// REASON_RECOMPILE 2 Program recompiled
|
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
// REASON_CHARTCLOSE 4 Chart closed
|
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
// REASON_TEMPLATE 7 Another chart template applied
|
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
// REASON_CLOSE 9 Terminal closed
|
|
}
|
|
|
|
//
|
|
// Calculating what we want ...
|
|
int OnCalculate(
|
|
const int rates_total, // Total Bars on Chart ...
|
|
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
const datetime &time[], // History of Open Time ...
|
|
const double &open[], // History of Open Price ...
|
|
const double &high[], // History of High Price ...
|
|
const double &low[], // History of Low Price ...
|
|
const double &close[], // History of Close Price ...
|
|
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
const long &volume[], // History of Trade Volumes ...
|
|
const int &spread[] // History of Spread Price ...
|
|
//
|
|
)
|
|
{
|
|
//
|
|
// Prepare Buffers ...
|
|
ArraySetAsSeries(time, true);
|
|
ArraySetAsSeries(open, true);
|
|
ArraySetAsSeries(high, true);
|
|
ArraySetAsSeries(low, true);
|
|
ArraySetAsSeries(close, true);
|
|
ArraySetAsSeries(tick_volume, true);
|
|
ArraySetAsSeries(volume, true);
|
|
ArraySetAsSeries(spread, true);
|
|
|
|
//
|
|
// this counts Available Bars ...
|
|
int limit;
|
|
|
|
//
|
|
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
|
|
//
|
|
// Main Loop ...
|
|
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
{
|
|
//
|
|
CalculateBuffers(i);
|
|
}
|
|
|
|
//
|
|
return rates_total;
|
|
}
|
|
|
|
//
|
|
// Functions ...
|
|
|
|
//
|
|
// Validate Input Args for Initialization ...
|
|
bool ValidateInputs()
|
|
{
|
|
//
|
|
bool result =
|
|
//
|
|
(IsValid(scMethod, scPeriod) &&
|
|
IsValid(mcMethod, mcPeriod) &&
|
|
IsValid(lcMethod, lcPeriod) &&
|
|
IsValid(hcMethod, hcPeriod))
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve all Exists Input Max Length ...
|
|
// use for Start Of Drawing ...
|
|
int ExtractMaxLengthOfInputs()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(mSCLength, mMCLength);
|
|
result = MathMax(result, mLCLength);
|
|
result = MathMax(result, mHCLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Define Indexes and Styles ...
|
|
void DefineBuffers()
|
|
{
|
|
//
|
|
// PEAKS and VALES ...
|
|
ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE;
|
|
|
|
//
|
|
// PEAKS ...
|
|
ArraySetAsSeries(peaksBuffer, true);
|
|
SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225);
|
|
PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
|
PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
|
|
|
|
//
|
|
// VALES ...
|
|
ArraySetAsSeries(valesBuffer, true);
|
|
SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225);
|
|
PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
|
PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
|
|
|
|
//
|
|
// SUPPORT and RESISTANCE ...
|
|
//
|
|
|
|
//
|
|
// RESISTANCE ...
|
|
ArraySetAsSeries(rBuffer, true);
|
|
SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false);
|
|
PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
|
|
//
|
|
// RESISTANCE Color ...
|
|
ArraySetAsSeries(rColorBuffer, true);
|
|
SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// SUPPORT ...
|
|
ArraySetAsSeries(sBuffer, true);
|
|
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(sBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false);
|
|
|
|
//
|
|
// SUPPORT Color ...
|
|
ArraySetAsSeries(sColorBuffer, true);
|
|
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// FIBBO Levels ...
|
|
|
|
//
|
|
// LEVEL 1 ...
|
|
|
|
//
|
|
// Buffer ...
|
|
ArraySetAsSeries(fl1Buffer, true);
|
|
SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_SHOW_DATA, showFibo1Levels);
|
|
|
|
//
|
|
// Color ...
|
|
ArraySetAsSeries(fl1ColorBuffer, true);
|
|
SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LEVEL 2 ...
|
|
|
|
//
|
|
// Buffer ...
|
|
ArraySetAsSeries(fl2Buffer, true);
|
|
SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_SHOW_DATA, showFibo2Levels);
|
|
|
|
//
|
|
// Color ...
|
|
ArraySetAsSeries(fl2ColorBuffer, true);
|
|
SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LEVEL 3 ...
|
|
|
|
//
|
|
// Buffer ...
|
|
ArraySetAsSeries(fl3Buffer, true);
|
|
SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_SHOW_DATA, showFibo3Levels);
|
|
|
|
//
|
|
// Color ...
|
|
ArraySetAsSeries(fl3ColorBuffer, true);
|
|
SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LEVEL 4 ...
|
|
|
|
//
|
|
// Buffer ...
|
|
ArraySetAsSeries(fl4Buffer, true);
|
|
SetIndexBuffer(fl4BufferIndex, fl4Buffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_SHOW_DATA, showFibo4Levels);
|
|
|
|
//
|
|
// Color ...
|
|
ArraySetAsSeries(fl4ColorBuffer, true);
|
|
SetIndexBuffer(fl4ColorBufferIndex, fl4ColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LEVEL 5 ...
|
|
|
|
//
|
|
// Buffer ...
|
|
ArraySetAsSeries(fl5Buffer, true);
|
|
SetIndexBuffer(fl5BufferIndex, fl5Buffer, INDICATOR_DATA);
|
|
PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_SHOW_DATA, showFibo5Levels);
|
|
|
|
//
|
|
// Color ...
|
|
ArraySetAsSeries(fl5ColorBuffer, true);
|
|
SetIndexBuffer(fl5ColorBufferIndex, fl5ColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// SHORT Buffers ...
|
|
|
|
//
|
|
// HIGH ...
|
|
ArraySetAsSeries(scHHBuffer, true);
|
|
SetIndexBuffer(scHHBufferIndex, scHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(scHHColorBuffer, true);
|
|
SetIndexBuffer(scHHColorBufferIndex, scHHColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LOW ...
|
|
ArraySetAsSeries(scLLBuffer, true);
|
|
SetIndexBuffer(scLLBufferIndex, scLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(scLLColorBuffer, true);
|
|
SetIndexBuffer(scLLColorBufferIndex, scLLColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// MEDIUM Buffer ...
|
|
|
|
//
|
|
// HIGH ...
|
|
ArraySetAsSeries(mcHHBuffer, true);
|
|
SetIndexBuffer(mcHHBufferIndex, mcHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(mcHHColorBuffer, true);
|
|
SetIndexBuffer(mcHHColorBufferIndex, mcHHColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LOW ...
|
|
ArraySetAsSeries(mcLLBuffer, true);
|
|
SetIndexBuffer(mcLLBufferIndex, mcLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(mcLLColorBuffer, true);
|
|
SetIndexBuffer(mcLLColorBufferIndex, mcLLColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LONG Buffer ...
|
|
|
|
//
|
|
// HIGH ...
|
|
ArraySetAsSeries(lcHHBuffer, true);
|
|
SetIndexBuffer(lcHHBufferIndex, lcHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(lcHHColorBuffer, true);
|
|
SetIndexBuffer(lcHHColorBufferIndex, lcHHColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LOW ...
|
|
ArraySetAsSeries(lcLLBuffer, true);
|
|
SetIndexBuffer(lcLLBufferIndex, lcLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(lcLLColorBuffer, true);
|
|
SetIndexBuffer(lcLLColorBufferIndex, lcLLColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// HIND Buffer ...
|
|
|
|
//
|
|
// HIGH ...
|
|
ArraySetAsSeries(hcHHBuffer, true);
|
|
SetIndexBuffer(hcHHBufferIndex, hcHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(hcHHColorBuffer, true);
|
|
SetIndexBuffer(hcHHColorBufferIndex, hcHHColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// LOW ...
|
|
ArraySetAsSeries(hcLLBuffer, true);
|
|
SetIndexBuffer(hcLLBufferIndex, hcLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
|
|
|
//
|
|
ArraySetAsSeries(hcLLColorBuffer, true);
|
|
SetIndexBuffer(hcLLColorBufferIndex, hcLLColorBuffer, INDICATOR_COLOR_INDEX);
|
|
}
|
|
|
|
//
|
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
void SetIndicatorName()
|
|
{
|
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
}
|
|
|
|
//
|
|
// Calculate Buffers ...
|
|
void CalculateBuffers(
|
|
int bar_index // Selected Bar Index
|
|
)
|
|
{
|
|
//
|
|
// Calculate Cycles ...
|
|
CalculateCycles(bar_index);
|
|
|
|
//
|
|
// Calculate Peaks and Vales ...
|
|
CalculatePeaksAndVales(bar_index);
|
|
|
|
//
|
|
// Calculate Fibonnaci ...
|
|
CalculateFibonacci(bar_index);
|
|
}
|
|
|
|
//
|
|
// Custom ...
|
|
|
|
//
|
|
// Initial Market Cycles ...
|
|
bool InitMarketCycles()
|
|
{
|
|
//
|
|
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;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Calculate Specified Cycles HH and LL ...
|
|
void CalculateCycle(
|
|
int barIndex,
|
|
ENUM_X_MARKET_CYCLES cycle,
|
|
double &lastHH,
|
|
double &hhBuffer[],
|
|
double &hhColorBuffer[],
|
|
double &lastLL,
|
|
double &llBuffer[],
|
|
double &llColorBuffer[] //
|
|
)
|
|
{
|
|
//
|
|
XOHCL bar;
|
|
bar.Init(
|
|
_Symbol,
|
|
_Period,
|
|
barIndex
|
|
//
|
|
);
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
//
|
|
double hhValue = bar.FindHighest(
|
|
mLength,
|
|
hhMode
|
|
//
|
|
);
|
|
hhBuffer[barIndex] = hhValue;
|
|
|
|
//
|
|
double hhColorIDX =
|
|
!showLevels
|
|
? mHideColorIDX
|
|
: (hhValue == lastHH)
|
|
? !showConsolidations
|
|
? mHideColorIDX
|
|
: 1
|
|
: hhValue > lastHH
|
|
? 2
|
|
: hhValue < lastHH
|
|
? 3
|
|
: mHideColorIDX;
|
|
hhColorBuffer[barIndex] = hhColorIDX;
|
|
|
|
//
|
|
lastHH = hhValue;
|
|
|
|
//
|
|
double llValue = bar.FindLowest(
|
|
mLength,
|
|
llMode
|
|
//
|
|
);
|
|
llBuffer[barIndex] = llValue;
|
|
|
|
//
|
|
double llColorIDX =
|
|
!showLevels
|
|
? mHideColorIDX
|
|
: (llValue == lastLL)
|
|
? !showConsolidations
|
|
? mHideColorIDX
|
|
: 1
|
|
: llValue > lastLL
|
|
? 2
|
|
: llValue < lastLL
|
|
? 3
|
|
: mHideColorIDX;
|
|
llColorBuffer[barIndex] = llColorIDX;
|
|
|
|
//
|
|
lastLL = llValue;
|
|
}
|
|
|
|
//
|
|
// Calculate Cycles Up and Down Boundaries ...
|
|
void CalculateCycles(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
// Short ...
|
|
CalculateCycle(
|
|
barIndex,
|
|
X_MARKET_CYCLE_SHORT,
|
|
//
|
|
mLastSCHH,
|
|
scHHBuffer,
|
|
scHHColorBuffer,
|
|
//
|
|
mLastSCLL,
|
|
scLLBuffer,
|
|
scLLColorBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Medium ...
|
|
CalculateCycle(
|
|
barIndex,
|
|
X_MARKET_CYCLE_MEDIUM,
|
|
//
|
|
mLastMCHH,
|
|
mcHHBuffer,
|
|
mcHHColorBuffer,
|
|
//
|
|
mLastMCLL,
|
|
mcLLBuffer,
|
|
mcLLColorBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Long ...
|
|
CalculateCycle(
|
|
barIndex,
|
|
X_MARKET_CYCLE_LONG,
|
|
//
|
|
mLastLCHH,
|
|
lcHHBuffer,
|
|
lcHHColorBuffer,
|
|
//
|
|
mLastLCLL,
|
|
lcLLBuffer,
|
|
lcLLColorBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Hind ...
|
|
CalculateCycle(
|
|
barIndex,
|
|
X_MARKET_CYCLE_HIND,
|
|
//
|
|
mLastHCHH,
|
|
hcHHBuffer,
|
|
hcHHColorBuffer,
|
|
//
|
|
mLastHCLL,
|
|
hcLLBuffer,
|
|
hcLLColorBuffer
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Calculate Peaks and Values ...
|
|
void CalculatePeaksAndVales(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
// Retrieve Requirements ...
|
|
|
|
//
|
|
// Short ...
|
|
double scHHValue = scHHBuffer[barIndex];
|
|
double scLLValue = scLLBuffer[barIndex];
|
|
|
|
//
|
|
// Medium ...
|
|
double mcHHValue = mcHHBuffer[barIndex];
|
|
double mcLLValue = mcLLBuffer[barIndex];
|
|
|
|
//
|
|
// Long ...
|
|
double lcHHValue = lcHHBuffer[barIndex];
|
|
double lcLLValue = lcLLBuffer[barIndex];
|
|
|
|
//
|
|
// Hind ...
|
|
double hcHHValue = hcHHBuffer[barIndex];
|
|
double hcLLValue = hcLLBuffer[barIndex];
|
|
|
|
//
|
|
double rColorIDX = mHideColorIDX;
|
|
double sColorIDX = mHideColorIDX;
|
|
|
|
//
|
|
// RESISTANCE ...
|
|
double rValue = (scHHValue + mcHHValue + lcHHValue + hcHHValue) / 4;
|
|
|
|
//
|
|
// PEAKS ...
|
|
bool isPeak = rValue == hcHHValue &&
|
|
hcHHValue == lcHHValue &&
|
|
lcHHValue == mcHHValue &&
|
|
mcHHValue == scHHValue;
|
|
|
|
//
|
|
if (isPeak && lastPeak != rValue)
|
|
{
|
|
//
|
|
rColorIDX = 1;
|
|
lastPeak = rValue;
|
|
}
|
|
|
|
//
|
|
// SUPPORT ...
|
|
double sValue = (scLLValue + mcLLValue + lcLLValue + hcLLValue) / 4;
|
|
|
|
//
|
|
// VALES ...
|
|
bool isVale = sValue == hcLLValue &&
|
|
hcLLValue == lcLLValue &&
|
|
lcLLValue == mcLLValue &&
|
|
mcLLValue == scLLValue;
|
|
|
|
//
|
|
if (isVale && lastVale != sValue)
|
|
{
|
|
//
|
|
sColorIDX = 1;
|
|
|
|
//
|
|
lastVale = sValue;
|
|
}
|
|
|
|
//
|
|
rBuffer[barIndex] = rValue;
|
|
sBuffer[barIndex] = sValue;
|
|
peaksBuffer[barIndex] = lastPeak;
|
|
valesBuffer[barIndex] = lastVale;
|
|
|
|
//
|
|
if (showPeaksAndVales)
|
|
{
|
|
//
|
|
rColorBuffer[barIndex] = rColorIDX;
|
|
sColorBuffer[barIndex] = sColorIDX;
|
|
}
|
|
else
|
|
{
|
|
//
|
|
rColorBuffer[barIndex] = mHideColorIDX;
|
|
sColorBuffer[barIndex] = mHideColorIDX;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Calculate Fibonacci Level 1 ...
|
|
void CalculateFibonacci(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
// Select Requirements ...
|
|
double upPrice = peaksBuffer[barIndex];
|
|
double downPrice = valesBuffer[barIndex];
|
|
|
|
//
|
|
// Level 1 ...
|
|
double fibLevel1Value = GetFibonacciLevel(
|
|
upPrice,
|
|
downPrice,
|
|
fiboLevel1,
|
|
1);
|
|
//
|
|
// Level 2 ...
|
|
double fibLevel2Value = GetFibonacciLevel(
|
|
upPrice,
|
|
downPrice,
|
|
fiboLevel2,
|
|
1);
|
|
|
|
//
|
|
// Level 3 ...
|
|
double fibLevel3Value = GetFibonacciLevel(
|
|
upPrice,
|
|
downPrice,
|
|
fiboLevel3,
|
|
1);
|
|
|
|
//
|
|
// Level 4 ...
|
|
double fibLevel4Value = GetFibonacciLevel(
|
|
upPrice,
|
|
downPrice,
|
|
fiboLevel4,
|
|
1);
|
|
|
|
//
|
|
// Level 5 ...
|
|
double fibLevel5Value = GetFibonacciLevel(
|
|
upPrice,
|
|
downPrice,
|
|
fiboLevel5,
|
|
1);
|
|
|
|
//
|
|
fl1Buffer[barIndex] = fibLevel1Value;
|
|
fl2Buffer[barIndex] = fibLevel2Value;
|
|
fl3Buffer[barIndex] = fibLevel3Value;
|
|
fl4Buffer[barIndex] = fibLevel4Value;
|
|
fl5Buffer[barIndex] = fibLevel5Value;
|
|
|
|
//
|
|
double fl1ColorIdx = showFibo1Levels ? 1 : mHideColorIDX;
|
|
double fl2ColorIdx = showFibo2Levels ? 1 : mHideColorIDX;
|
|
double fl3ColorIdx = showFibo3Levels ? 1 : mHideColorIDX;
|
|
double fl4ColorIdx = showFibo4Levels ? 1 : mHideColorIDX;
|
|
double fl5ColorIdx = showFibo5Levels ? 1 : mHideColorIDX;
|
|
|
|
//
|
|
fl1ColorBuffer[barIndex] = fl1ColorIdx;
|
|
fl2ColorBuffer[barIndex] = fl2ColorIdx;
|
|
fl3ColorBuffer[barIndex] = fl3ColorIdx;
|
|
fl4ColorBuffer[barIndex] = fl4ColorIdx;
|
|
fl5ColorBuffer[barIndex] = fl5ColorIdx;
|
|
}
|
|
|
|
// |