965 lines
21 KiB
Plaintext
965 lines
21 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
// SaherElm IT Center MQL5 Indicator
|
|
// -------------------------------------------
|
|
// Name: XDSR
|
|
// Description: Dynamic Support and Resistances ...
|
|
//
|
|
// 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 XDSR Indicator"
|
|
#property strict
|
|
|
|
//
|
|
#define ShortName "XDSR"
|
|
|
|
//
|
|
// Includes ...
|
|
#include "../Libraries/x-saherelm.log.lib.mq5"
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
|
|
//
|
|
// INPUT ...
|
|
|
|
//
|
|
// Maarket ...
|
|
input group "Cycles";
|
|
|
|
//
|
|
// Short ...
|
|
input group "Short";
|
|
input ENUM_X_PERIOD_METHOD scMode = X_PERIOD_MANUALLY; // Method
|
|
input ENUM_TIMEFRAMES scPeriod = PERIOD_H4; // Period
|
|
|
|
//
|
|
// Medium ...
|
|
input group "Medium";
|
|
input ENUM_X_PERIOD_METHOD mcMode = X_PERIOD_MANUALLY; // Method
|
|
input ENUM_TIMEFRAMES mcPeriod = PERIOD_H12; // Mid Period
|
|
|
|
//
|
|
// Long ...
|
|
input group "Long";
|
|
input ENUM_X_PERIOD_METHOD lcMode = X_PERIOD_MANUALLY; // Method
|
|
input ENUM_TIMEFRAMES lcPeriod = PERIOD_D1; // Long Period
|
|
|
|
//
|
|
// Hind ...
|
|
input group "Hind";
|
|
input ENUM_X_PERIOD_METHOD hcMode = X_PERIOD_MANUALLY; // Method
|
|
input ENUM_TIMEFRAMES hcPeriod = PERIOD_W1; // Hind Period
|
|
|
|
//
|
|
// BUFFERS ...
|
|
|
|
//
|
|
#property indicator_chart_window
|
|
|
|
//
|
|
#property indicator_buffers 24
|
|
#property indicator_plots 24
|
|
|
|
//
|
|
// Short ...
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
#define scOpenBufferIndex 0
|
|
#define scOpenBufferPlotIndex 0
|
|
double scOpenBuffer[];
|
|
|
|
//
|
|
#define scOpenColorBufferIndex 1
|
|
double scOpenColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label1 "X121_XDSR SC O"
|
|
#property indicator_type1 DRAW_COLOR_LINE
|
|
#property indicator_color1 clrGreen, clrRed
|
|
#property indicator_width1 1
|
|
|
|
//
|
|
// High ...
|
|
#define scHighBufferIndex 2
|
|
#define scHighBufferPlotIndex 1
|
|
double scHighBuffer[];
|
|
|
|
//
|
|
#property indicator_label2 "X121_XDSR SC H"
|
|
#property indicator_type2 DRAW_LINE
|
|
#property indicator_color2 clrAqua
|
|
#property indicator_width2 1
|
|
|
|
//
|
|
// Close ...
|
|
|
|
//
|
|
#define scCloseBufferIndex 3
|
|
#define scCloseBufferPlotIndex 2
|
|
double scCloseBuffer[];
|
|
|
|
//
|
|
#define scCloseColorBufferIndex 4
|
|
double scCloseColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label3 "X121_XDSR SC C"
|
|
#property indicator_type3 DRAW_COLOR_LINE
|
|
#property indicator_color3 clrGreen, clrRed
|
|
#property indicator_width3 1
|
|
|
|
//
|
|
// Low ...
|
|
#define scLowBufferIndex 5
|
|
#define scLowBufferPlotIndex 3
|
|
double scLowBuffer[];
|
|
|
|
//
|
|
#property indicator_label4 "X121_XDSR SC L"
|
|
#property indicator_type4 DRAW_LINE
|
|
#property indicator_color4 clrMagenta
|
|
#property indicator_width4 1
|
|
|
|
//
|
|
// Medium ...
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
#define mcOpenBufferIndex 6
|
|
#define mcOpenBufferPlotIndex 4
|
|
double mcOpenBuffer[];
|
|
|
|
//
|
|
#define mcOpenColorBufferIndex 7
|
|
double mcOpenColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label5 "X121_XDSR MC O"
|
|
#property indicator_type5 DRAW_COLOR_LINE
|
|
#property indicator_color5 clrGreen, clrRed
|
|
#property indicator_width5 1
|
|
|
|
//
|
|
// High ...
|
|
#define mcHighBufferIndex 8
|
|
#define mcHighBufferPlotIndex 5
|
|
double mcHighBuffer[];
|
|
|
|
//
|
|
#property indicator_label6 "X121_XDSR MC H"
|
|
#property indicator_type6 DRAW_LINE
|
|
#property indicator_color6 clrAqua
|
|
#property indicator_width6 1
|
|
|
|
//
|
|
// Close ...
|
|
|
|
//
|
|
#define mcCloseBufferIndex 9
|
|
#define mcCloseBufferPlotIndex 6
|
|
double mcCloseBuffer[];
|
|
|
|
//
|
|
#define mcCloseColorBufferIndex 10
|
|
double mcCloseColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label7 "X121_XDSR MC C"
|
|
#property indicator_type7 DRAW_COLOR_LINE
|
|
#property indicator_color7 clrGreen, clrRed
|
|
#property indicator_width7 1
|
|
|
|
//
|
|
// Low ...
|
|
#define mcLowBufferIndex 11
|
|
#define mcLowBufferPlotIndex 7
|
|
double mcLowBuffer[];
|
|
|
|
//
|
|
#property indicator_label8 "X121_XDSR MC L"
|
|
#property indicator_type8 DRAW_LINE
|
|
#property indicator_color8 clrMagenta
|
|
#property indicator_width8 1
|
|
|
|
//
|
|
// Long ...
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
#define lcOpenBufferIndex 12
|
|
#define lcOpenBufferPlotIndex 8
|
|
double lcOpenBuffer[];
|
|
|
|
//
|
|
#define lcOpenColorBufferIndex 13
|
|
double lcOpenColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label9 "X121_XDSR LC O"
|
|
#property indicator_type9 DRAW_COLOR_LINE
|
|
#property indicator_color9 clrGreen, clrRed
|
|
#property indicator_width9 1
|
|
|
|
//
|
|
// High ...
|
|
#define lcHighBufferIndex 14
|
|
#define lcHighBufferPlotIndex 9
|
|
double lcHighBuffer[];
|
|
|
|
//
|
|
#property indicator_label10 "X121_XDSR LC H"
|
|
#property indicator_type10 DRAW_LINE
|
|
#property indicator_color10 clrAqua
|
|
#property indicator_width10 1
|
|
|
|
//
|
|
// Close ...
|
|
|
|
//
|
|
#define lcCloseBufferIndex 15
|
|
#define lcCloseBufferPlotIndex 10
|
|
double lcCloseBuffer[];
|
|
|
|
//
|
|
#define lcCloseColorBufferIndex 16
|
|
double lcCloseColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label11 "X121_XDSR LC C"
|
|
#property indicator_type11 DRAW_COLOR_LINE
|
|
#property indicator_color11 clrGreen, clrRed
|
|
#property indicator_width11 1
|
|
|
|
//
|
|
// Low ...
|
|
#define lcLowBufferIndex 17
|
|
#define lcLowBufferPlotIndex 11
|
|
double lcLowBuffer[];
|
|
|
|
//
|
|
#property indicator_label12 "X121_XDSR LC L"
|
|
#property indicator_type12 DRAW_LINE
|
|
#property indicator_color12 clrMagenta
|
|
#property indicator_width12 1
|
|
|
|
//
|
|
// Hind ...
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
#define hcOpenBufferIndex 18
|
|
#define hcOpenBufferPlotIndex 12
|
|
double hcOpenBuffer[];
|
|
|
|
//
|
|
#define hcOpenColorBufferIndex 19
|
|
double hcOpenColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label13 "X121_XDSR HC O"
|
|
#property indicator_type13 DRAW_COLOR_LINE
|
|
#property indicator_color13 clrGreen, clrRed
|
|
#property indicator_width13 1
|
|
|
|
//
|
|
// High ...
|
|
#define hcHighBufferIndex 20
|
|
#define hcHighBufferPlotIndex 13
|
|
double hcHighBuffer[];
|
|
|
|
//
|
|
#property indicator_label14 "X121_XDSR HC H"
|
|
#property indicator_type14 DRAW_LINE
|
|
#property indicator_color14 clrAqua
|
|
#property indicator_width14 1
|
|
|
|
//
|
|
// Close ...
|
|
|
|
//
|
|
#define hcCloseBufferIndex 21
|
|
#define hcCloseBufferPlotIndex 14
|
|
double hcCloseBuffer[];
|
|
|
|
//
|
|
#define hcCloseColorBufferIndex 22
|
|
double hcCloseColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label15 "X121_XDSR HC C"
|
|
#property indicator_type15 DRAW_COLOR_LINE
|
|
#property indicator_color15 clrGreen, clrRed
|
|
#property indicator_width15 1
|
|
|
|
//
|
|
// Low ...
|
|
#define hcLowBufferIndex 23
|
|
#define hcLowBufferPlotIndex 15
|
|
double hcLowBuffer[];
|
|
|
|
//
|
|
#property indicator_label16 "X121_XDSR HC L"
|
|
#property indicator_type16 DRAW_LINE
|
|
#property indicator_color16 clrMagenta
|
|
#property indicator_width16 1
|
|
|
|
//
|
|
// VARIABLES ...
|
|
|
|
//
|
|
// Cycles Definitions ...
|
|
XMarketCycle sc;
|
|
XMarketCycle mc;
|
|
XMarketCycle lc;
|
|
XMarketCycle hc;
|
|
|
|
//
|
|
// EVENT Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
// Validate Inputs ...
|
|
if (!ValidateInputs())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
logTag = ShortName;
|
|
|
|
//
|
|
// Define Index Buffers ...
|
|
DefineBuffers();
|
|
|
|
//
|
|
// Set Indicator ShortName ...
|
|
SetIndicatorName();
|
|
|
|
//
|
|
// Initial Market Cycles ...
|
|
if (!InitMarketCycles())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// 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(
|
|
//
|
|
// total Candles on chart ...
|
|
const int rates_total,
|
|
//
|
|
// total calculated Candles on charts ...
|
|
const int prev_calculated,
|
|
//
|
|
// history of Candles Open Time ...
|
|
const datetime &time[],
|
|
//
|
|
// history of Candles Open Price ...
|
|
const double &open[],
|
|
//
|
|
// history of Candles High Price ...
|
|
const double &high[],
|
|
//
|
|
// history of Candles Low Price ...
|
|
const double &low[],
|
|
//
|
|
// history of Candles Close Price ...
|
|
const double &close[],
|
|
//
|
|
// history of Tick Volumes on Candle ...
|
|
const long &tick_volume[],
|
|
//
|
|
// history of Trade Volumes ...
|
|
const long &volume[],
|
|
//
|
|
// history of Candles Spread Price ...
|
|
const int &spread[])
|
|
{
|
|
//
|
|
// 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 - 1
|
|
: (rates_total - prev_calculated);
|
|
|
|
//
|
|
// Main Loop ...
|
|
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
|
{
|
|
//
|
|
// Calculate Buffers ...
|
|
CalculateBuffer(i);
|
|
}
|
|
|
|
//
|
|
return rates_total;
|
|
}
|
|
|
|
//
|
|
// CUSTOM Functions ...
|
|
|
|
//
|
|
// Validate Input Args for Initialization ...
|
|
bool ValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
// Short ...
|
|
IsValidCycle(
|
|
scMode,
|
|
scPeriod)
|
|
//
|
|
&&
|
|
//
|
|
// Medium ...
|
|
IsValidCycle(
|
|
mcMode,
|
|
mcPeriod)
|
|
//
|
|
&&
|
|
//
|
|
// Long ...
|
|
IsValidCycle(
|
|
lcMode,
|
|
lcPeriod)
|
|
//
|
|
&&
|
|
//
|
|
// Hind ...
|
|
IsValidCycle(
|
|
hcMode,
|
|
hcPeriod)
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Define Indexes and Styles ...
|
|
void DefineBuffers()
|
|
{
|
|
//
|
|
// Short ...
|
|
|
|
//
|
|
// High ...
|
|
|
|
//
|
|
ArraySetAsSeries(scHighBuffer, true);
|
|
SetIndexBuffer(scHighBufferIndex, scHighBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(scHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(scHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(scHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Low ...
|
|
|
|
//
|
|
ArraySetAsSeries(scLowBuffer, true);
|
|
SetIndexBuffer(scLowBufferIndex, scLowBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(scLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(scLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(scLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
ArraySetAsSeries(scOpenBuffer, true);
|
|
SetIndexBuffer(scOpenBufferIndex, scOpenBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(scOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(scOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(scOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(scOpenColorBuffer, true);
|
|
SetIndexBuffer(scOpenColorBufferIndex, scOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// Close ...
|
|
|
|
ArraySetAsSeries(scCloseBuffer, true);
|
|
SetIndexBuffer(scCloseBufferIndex, scCloseBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(scCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(scCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(scCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(scCloseColorBuffer, true);
|
|
SetIndexBuffer(scCloseColorBufferIndex, scCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// Medium ...
|
|
|
|
//
|
|
// High ...
|
|
|
|
//
|
|
ArraySetAsSeries(mcHighBuffer, true);
|
|
SetIndexBuffer(mcHighBufferIndex, mcHighBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(mcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(mcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(mcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Low ...
|
|
|
|
//
|
|
ArraySetAsSeries(mcLowBuffer, true);
|
|
SetIndexBuffer(mcLowBufferIndex, mcLowBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(mcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(mcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(mcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
ArraySetAsSeries(mcOpenBuffer, true);
|
|
SetIndexBuffer(mcOpenBufferIndex, mcOpenBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(mcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(mcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(mcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(mcOpenColorBuffer, true);
|
|
SetIndexBuffer(mcOpenColorBufferIndex, mcOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// Close ...
|
|
|
|
ArraySetAsSeries(mcCloseBuffer, true);
|
|
SetIndexBuffer(mcCloseBufferIndex, mcCloseBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(mcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(mcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(mcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(mcCloseColorBuffer, true);
|
|
SetIndexBuffer(mcCloseColorBufferIndex, mcCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// Long ...
|
|
|
|
//
|
|
// High ...
|
|
|
|
//
|
|
ArraySetAsSeries(lcHighBuffer, true);
|
|
SetIndexBuffer(lcHighBufferIndex, lcHighBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(lcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(lcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(lcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Low ...
|
|
|
|
//
|
|
ArraySetAsSeries(lcLowBuffer, true);
|
|
SetIndexBuffer(lcLowBufferIndex, lcLowBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(lcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(lcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(lcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
ArraySetAsSeries(lcOpenBuffer, true);
|
|
SetIndexBuffer(lcOpenBufferIndex, lcOpenBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(lcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(lcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(lcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(lcOpenColorBuffer, true);
|
|
SetIndexBuffer(lcOpenColorBufferIndex, lcOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// Close ...
|
|
|
|
ArraySetAsSeries(lcCloseBuffer, true);
|
|
SetIndexBuffer(lcCloseBufferIndex, lcCloseBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(lcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(lcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(lcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(lcCloseColorBuffer, true);
|
|
SetIndexBuffer(lcCloseColorBufferIndex, lcCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// Hind ...
|
|
|
|
//
|
|
// High ...
|
|
|
|
//
|
|
ArraySetAsSeries(hcHighBuffer, true);
|
|
SetIndexBuffer(hcHighBufferIndex, hcHighBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(hcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(hcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(hcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Low ...
|
|
|
|
//
|
|
ArraySetAsSeries(hcLowBuffer, true);
|
|
SetIndexBuffer(hcLowBufferIndex, hcLowBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(hcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(hcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(hcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
// Open ...
|
|
|
|
//
|
|
ArraySetAsSeries(hcOpenBuffer, true);
|
|
SetIndexBuffer(hcOpenBufferIndex, hcOpenBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(hcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(hcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(hcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(hcOpenColorBuffer, true);
|
|
SetIndexBuffer(hcOpenColorBufferIndex, hcOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
// Close ...
|
|
|
|
ArraySetAsSeries(hcCloseBuffer, true);
|
|
SetIndexBuffer(hcCloseBufferIndex, hcCloseBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(hcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
|
PlotIndexSetInteger(hcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
PlotIndexSetDouble(hcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
|
|
//
|
|
ArraySetAsSeries(hcCloseColorBuffer, true);
|
|
SetIndexBuffer(hcCloseColorBufferIndex, hcCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
|
}
|
|
|
|
//
|
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
void SetIndicatorName()
|
|
{
|
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
}
|
|
|
|
//
|
|
void CalculateBuffer(const int barIndex)
|
|
{
|
|
//
|
|
// First Update Market Cycles ...
|
|
UpdateMarketCycles(barIndex);
|
|
|
|
//
|
|
double bullishColorIDX = 0;
|
|
double bearishColorIDX = 1;
|
|
|
|
//
|
|
// Short ...
|
|
int scBarIndex = sc.GetBarIndex(barIndex);
|
|
XOHCL scBar1 = sc.GetBar(scBarIndex + 1);
|
|
|
|
//
|
|
bool isSCBar1Bullish = scBar1.open < scBar1.close;
|
|
|
|
//
|
|
scOpenBuffer[barIndex] = scBar1.open;
|
|
scHighBuffer[barIndex] = scBar1.high;
|
|
scCloseBuffer[barIndex] = scBar1.close;
|
|
scLowBuffer[barIndex] = scBar1.low;
|
|
|
|
//
|
|
scOpenColorBuffer[barIndex] =
|
|
isSCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
|
|
//
|
|
scCloseColorBuffer[barIndex] =
|
|
isSCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
|
|
//
|
|
// Medium ...
|
|
int mcBarIndex = mc.GetBarIndex(barIndex);
|
|
XOHCL mcBar1 = mc.GetBar(mcBarIndex + 1);
|
|
|
|
//
|
|
bool isMCBar1Bullish = mcBar1.open < mcBar1.close;
|
|
|
|
//
|
|
mcOpenBuffer[barIndex] = mcBar1.open;
|
|
mcHighBuffer[barIndex] = mcBar1.high;
|
|
mcCloseBuffer[barIndex] = mcBar1.close;
|
|
mcLowBuffer[barIndex] = mcBar1.low;
|
|
|
|
//
|
|
mcOpenColorBuffer[barIndex] =
|
|
isMCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
|
|
//
|
|
mcCloseColorBuffer[barIndex] =
|
|
isMCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
|
|
//
|
|
// Long ...
|
|
int lcBarIndex = lc.GetBarIndex(barIndex);
|
|
XOHCL lcBar1 = lc.GetBar(lcBarIndex + 1);
|
|
|
|
//
|
|
bool isLCBar1Bullish = lcBar1.open < lcBar1.close;
|
|
|
|
//
|
|
lcOpenBuffer[barIndex] = lcBar1.open;
|
|
lcHighBuffer[barIndex] = lcBar1.high;
|
|
lcCloseBuffer[barIndex] = lcBar1.close;
|
|
lcLowBuffer[barIndex] = lcBar1.low;
|
|
|
|
//
|
|
lcOpenColorBuffer[barIndex] =
|
|
isLCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
|
|
//
|
|
lcCloseColorBuffer[barIndex] =
|
|
isLCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
|
|
//
|
|
// Hind ...
|
|
int hcBarIndex = hc.GetBarIndex(barIndex);
|
|
XOHCL hcBar1 = hc.GetBar(hcBarIndex + 1);
|
|
|
|
//
|
|
bool isHCBar1Bullish = hcBar1.open < hcBar1.close;
|
|
|
|
//
|
|
hcOpenBuffer[barIndex] = hcBar1.open;
|
|
hcHighBuffer[barIndex] = hcBar1.high;
|
|
hcCloseBuffer[barIndex] = hcBar1.close;
|
|
hcLowBuffer[barIndex] = hcBar1.low;
|
|
|
|
//
|
|
hcOpenColorBuffer[barIndex] =
|
|
isHCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
|
|
//
|
|
hcCloseColorBuffer[barIndex] =
|
|
isHCBar1Bullish
|
|
? bullishColorIDX
|
|
: bearishColorIDX;
|
|
}
|
|
|
|
//
|
|
// TOOLS ...
|
|
|
|
//
|
|
// Initial Market Cycles ...
|
|
bool InitMarketCycles()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Short ...
|
|
sc.method = scMode;
|
|
sc.period = scPeriod;
|
|
result = sc.Init(
|
|
_Symbol,
|
|
_Period,
|
|
X_MARKET_CYCLE_SHORT);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Medium ...
|
|
mc.method = mcMode;
|
|
mc.period = mcPeriod;
|
|
result = mc.Init(
|
|
_Symbol,
|
|
_Period,
|
|
X_MARKET_CYCLE_MEDIUM);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Long ...
|
|
lc.method = lcMode;
|
|
lc.period = lcPeriod;
|
|
result = lc.Init(
|
|
_Symbol,
|
|
_Period,
|
|
X_MARKET_CYCLE_LONG);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Hind ...
|
|
hc.method = hcMode;
|
|
hc.period = hcPeriod;
|
|
result = hc.Init(
|
|
_Symbol,
|
|
_Period,
|
|
X_MARKET_CYCLE_HIND);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Update Market Cycles ...
|
|
bool UpdateMarketCycles(int barIndex)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Short ...
|
|
result = sc.Update(barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Medium ...
|
|
result = mc.Update(barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Long ...
|
|
result = lc.Update(barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Hind ...
|
|
result = hc.Update(barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|