Files
xMQL5/MQLTestWorkspace/BKPS/BKP/x121 old style indicators/Indicators/x-saherelm.x121.xppsr.mq5
T

1215 lines
30 KiB
Plaintext

/////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_PPSR Pivot Points Indicator
// ---------------------------------------------------------
// Name: X121_PPSR
// Description: Pivot Points
// Market Analysor ...
//
//
// 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_PPSR Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_PPSR"
//
// XPERIOD Calculation Method ...
// USED For Multiple Time Frames ...
enum ENUM_X_PERIOD_METHOD
{
//
X_PERIOD_NOTHING,
//
X_PERIOD_AUTO,
//
X_PERIOD_MANUALLY
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Level 1";
input ENUM_X_PERIOD_METHOD l1Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l1Period = NULL; // Time Period
input ENUM_SERIESMODE l1HHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE l1LLMode = MODE_LOW; // Lowest Low Calculation Method
//
input group "Level 2";
input ENUM_X_PERIOD_METHOD l2Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l2Period = NULL; // Time Period
input ENUM_SERIESMODE l2HHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE l2LLMode = MODE_LOW; // Lowest Low Calculation Method
//
input group "Level 3";
input ENUM_X_PERIOD_METHOD l3Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l3Period = NULL; // Time Period
input ENUM_SERIESMODE l3HHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE l3LLMode = MODE_LOW; // Lowest Low Calculation Method
//
input group "Level 4";
input ENUM_X_PERIOD_METHOD l4Method = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES l4Period = NULL; // Time Period
input ENUM_SERIESMODE l4HHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE l4LLMode = MODE_LOW; // Lowest Low Calculation Method
//
input group "Presentation";
//
input group "Support and Resistace Levels";
input bool showSRLevel1 = true; // Show Level 1
input bool showSRLevel2 = true; // Show Level 2
input bool showSRLevel3 = true; // Show Level 3
input bool showSRLevel4 = true; // Show Level 4
//
input group "Pivot Point Levels";
input bool showPPLevel1 = true; // Show Level 1 Pivots
input bool showPPLevel2 = true; // Show Level 2 Pivots
input bool showPPLevel3 = true; // Show Level 3 Pivots
input bool showPPLevel4 = true; // Show Level 4 Pivots
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 24
#property indicator_plots 24
//
// PLOTTED Buffers ...
//
// LEVEL 1 ...
//
// RESISTANCE ...
//
#define l1RBufferIndex 0
double l1RBuffer[];
//
#property indicator_label1 "X121_PPSR L1 R"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrGoldenrod
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
#define l1R1BufferIndex 1
double l1R1Buffer[];
//
#property indicator_label2 "X121_PPSR L1 R1"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrGoldenrod
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
#define l1R2BufferIndex 2
double l1R2Buffer[];
//
#property indicator_label3 "X121_PPSR L1 R2"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrGoldenrod
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// SUPPORT ...
//
#define l1SBufferIndex 3
double l1SBuffer[];
//
#property indicator_label4 "X121_PPSR L1 S"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrLightGreen
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
#define l1S1BufferIndex 4
double l1S1Buffer[];
//
#property indicator_label5 "X121_PPSR L1 S1"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrLightGreen
#property indicator_style5 STYLE_DOT
#property indicator_width5 1
//
#define l1S2BufferIndex 5
double l1S2Buffer[];
//
#property indicator_label6 "X121_PPSR L1 S2"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrLightGreen
#property indicator_style6 STYLE_DOT
#property indicator_width6 1
//
// LEVEL 2 ...
//
// RESISTANCE ...
//
#define l2RBufferIndex 6
double l2RBuffer[];
//
#property indicator_label7 "X121_PPSR L2 R"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrGoldenrod
#property indicator_style7 STYLE_DOT
#property indicator_width7 1
//
#define l2R1BufferIndex 7
double l2R1Buffer[];
//
#property indicator_label8 "X121_PPSR L2 R2"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrGoldenrod
#property indicator_style8 STYLE_DOT
#property indicator_width8 1
//
#define l2R2BufferIndex 8
double l2R2Buffer[];
//
#property indicator_label9 "X121_PPSR L2 R2"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrGoldenrod
#property indicator_style9 STYLE_DOT
#property indicator_width9 1
//
// SUPPORT ...
//
#define l2SBufferIndex 9
double l2SBuffer[];
//
#property indicator_label10 "X121_PPSR L2 S"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrLightGreen
#property indicator_style10 STYLE_DOT
#property indicator_width10 1
//
#define l2S1BufferIndex 10
double l2S1Buffer[];
//
#property indicator_label11 "X121_PPSR L2 S1"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrLightGreen
#property indicator_style11 STYLE_DOT
#property indicator_width11 1
//
#define l2S2BufferIndex 11
double l2S2Buffer[];
//
#property indicator_label12 "X121_PPSR L2 S2"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrLightGreen
#property indicator_style12 STYLE_DOT
#property indicator_width12 1
//
// LEVEL 3 ...
//
// RESISTANCE ...
//
#define l3RBufferIndex 12
double l3RBuffer[];
//
#property indicator_label13 "X121_PPSR L3 R"
#property indicator_type13 DRAW_LINE
#property indicator_color13 clrGoldenrod
#property indicator_style13 STYLE_DOT
#property indicator_width13 1
//
#define l3R1BufferIndex 13
double l3R1Buffer[];
//
#property indicator_label14 "X121_PPSR L3 R1"
#property indicator_type14 DRAW_LINE
#property indicator_color14 clrGoldenrod
#property indicator_style14 STYLE_DOT
#property indicator_width14 1
//
#define l3R2BufferIndex 14
double l3R2Buffer[];
//
#property indicator_label15 "X121_PPSR L3 R2"
#property indicator_type15 DRAW_LINE
#property indicator_color15 clrGoldenrod
#property indicator_style15 STYLE_DOT
#property indicator_width15 1
//
// SUPPORT ...
//
#define l3SBufferIndex 15
double l3SBuffer[];
//
#property indicator_label16 "X121_PPSR L3 S"
#property indicator_type16 DRAW_LINE
#property indicator_color16 clrLightGreen
#property indicator_style16 STYLE_DOT
#property indicator_width16 1
//
#define l3S1BufferIndex 16
double l3S1Buffer[];
//
#property indicator_label17 "X121_PPSR L3 S1"
#property indicator_type17 DRAW_LINE
#property indicator_color17 clrLightGreen
#property indicator_style17 STYLE_DOT
#property indicator_width17 1
//
#define l3S2BufferIndex 17
double l3S2Buffer[];
//
#property indicator_label18 "X121_PPSR L3 S2"
#property indicator_type18 DRAW_LINE
#property indicator_color18 clrLightGreen
#property indicator_style18 STYLE_DOT
#property indicator_width18 1
//
// LEVEL 4 ...
//
// RESISTANCE ...
//
#define l4RBufferIndex 18
double l4RBuffer[];
//
#property indicator_label19 "X121_PPSR L4 R"
#property indicator_type19 DRAW_LINE
#property indicator_color19 clrGoldenrod
#property indicator_style19 STYLE_DOT
#property indicator_width19 1
//
#define l4R1BufferIndex 19
double l4R1Buffer[];
//
#property indicator_label20 "X121_PPSR L4 R1"
#property indicator_type20 DRAW_LINE
#property indicator_color20 clrGoldenrod
#property indicator_style20 STYLE_DOT
#property indicator_width20 1
//
#define l4R2BufferIndex 20
double l4R2Buffer[];
//
#property indicator_label21 "X121_PPSR L4 R2"
#property indicator_type21 DRAW_LINE
#property indicator_color21 clrGoldenrod
#property indicator_style21 STYLE_DOT
#property indicator_width21 1
//
// SUPPORT ...
//
#define l4SBufferIndex 21
double l4SBuffer[];
//
#property indicator_label22 "X121_PPSR L4 S"
#property indicator_type22 DRAW_LINE
#property indicator_color22 clrLightGreen
#property indicator_style22 STYLE_DOT
#property indicator_width22 1
//
#define l4S1BufferIndex 22
double l4S1Buffer[];
//
#property indicator_label23 "X121_PPSR L4 S1"
#property indicator_type23 DRAW_LINE
#property indicator_color23 clrLightGreen
#property indicator_style23 STYLE_DOT
#property indicator_width23 1
//
#define l4S2BufferIndex 23
double l4S2Buffer[];
//
#property indicator_label24 "X121_PPSR L4 S2"
#property indicator_type24 DRAW_LINE
#property indicator_color24 clrLightGreen
#property indicator_style24 STYLE_DOT
#property indicator_width24 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int currentPeriodSecconds = 0;
//
int mL1Candles;
double mLastL1R;
double mLastL1S;
int mLastL1StartBarIndex = 0;
ENUM_SERIESMODE mL1HHMode = NULL;
ENUM_SERIESMODE mL1LLMode = NULL;
datetime mLastL1StartTime = NULL;
ENUM_TIMEFRAMES mL1Period = NULL;
//
int mL2Candles;
double mLastL2R;
double mLastL2S;
int mLastL2StartBarIndex = 0;
ENUM_SERIESMODE mL2HHMode = NULL;
ENUM_SERIESMODE mL2LLMode = NULL;
datetime mLastL2StartTime = NULL;
ENUM_TIMEFRAMES mL2Period = NULL;
//
int mL3Candles;
double mLastL3R;
double mLastL3S;
int mLastL3StartBarIndex = 0;
ENUM_SERIESMODE mL3HHMode = NULL;
ENUM_SERIESMODE mL3LLMode = NULL;
datetime mLastL3StartTime = NULL;
ENUM_TIMEFRAMES mL3Period = NULL;
//
int mL4Candles;
double mLastL4R;
double mLastL4S;
int mLastL4StartBarIndex = 0;
ENUM_SERIESMODE mL4HHMode = NULL;
ENUM_SERIESMODE mL4LLMode = NULL;
datetime mLastL4StartTime = NULL;
ENUM_TIMEFRAMES mL4Period = NULL;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Do Initialization ...
//
if (currentPeriodSecconds == 0)
{
currentPeriodSecconds = PeriodSeconds(_Period);
}
//
// Find Level 1 Period ...
if (mL1Period == NULL)
{
//
if (l1Method == X_PERIOD_AUTO)
{
mL1Period = GetNearestTimeFrame(_Period);
}
else
{
mL1Period = l1Period;
}
//
int level1PeriodSecconds = PeriodSeconds(mL1Period);
//
mL1Candles = level1PeriodSecconds / currentPeriodSecconds;
//
mL1HHMode = l1HHMode == NULL ? MODE_HIGH : l1HHMode;
mL1LLMode = l1LLMode == NULL ? MODE_LOW : l1LLMode;
}
//
// Find Level 2 Period ...
if (mL2Period == NULL)
{
//
if (l2Method == X_PERIOD_AUTO)
{
mL2Period = GetMediestTimeFrame(_Period);
}
else
{
mL2Period = l2Period;
}
//
int level2PeriodSecconds = PeriodSeconds(mL2Period);
//
mL2Candles = level2PeriodSecconds / currentPeriodSecconds;
//
mL2HHMode = l2HHMode == NULL ? MODE_HIGH : l2HHMode;
mL2LLMode = l2LLMode == NULL ? MODE_LOW : l2LLMode;
}
//
// Find Level 3 Period ...
if (mL3Period == NULL)
{
//
if (l3Method == X_PERIOD_AUTO)
{
mL3Period = GetFarestTimeFrame(_Period);
}
else
{
mL3Period = l3Period;
}
//
int level3PeriodSecconds = PeriodSeconds(mL3Period);
//
mL3Candles = level3PeriodSecconds / currentPeriodSecconds;
//
mL3HHMode = l3HHMode == NULL ? MODE_HIGH : l3HHMode;
mL3LLMode = l3LLMode == NULL ? MODE_LOW : l3LLMode;
}
//
// Find Level 4 Period ...
if (mL4Period == NULL)
{
//
if (l4Method == X_PERIOD_AUTO)
{
mL4Period = GetHindmostTimeFrame(_Period);
}
else
{
mL4Period = l4Period;
}
//
int level4PeriodSecconds = PeriodSeconds(mL4Period);
//
mL4Candles = level4PeriodSecconds / currentPeriodSecconds;
//
mL4HHMode = l4HHMode == NULL ? MODE_HIGH : l4HHMode;
mL4LLMode = l4LLMode == NULL ? MODE_LOW : l4LLMode;
}
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
string comment = GenerateComment();
Comment(comment);
//
// 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
}
//
// Calculations ...
//
// 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 : (rates_total - prev_calculated) + 1;
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
// Validate Inputs ...
(l1Method != X_PERIOD_NOTHING &&
(l1Period == NULL ? l1Method == X_PERIOD_AUTO : true))
//
&&
//
(l2Method != X_PERIOD_NOTHING &&
(l2Period == NULL ? l2Method == X_PERIOD_AUTO : true))
//
&&
//
(l3Method != X_PERIOD_NOTHING &&
(l3Period == NULL ? l3Method == X_PERIOD_AUTO : true))
//
&&
//
(l4Method != X_PERIOD_NOTHING &&
(l4Period == NULL ? l4Method == X_PERIOD_AUTO : true))
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// LEVEL 1 ...
ENUM_DRAW_TYPE l1DrawType = showSRLevel1 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE l1PPDrawType = showPPLevel1 ? DRAW_LINE : DRAW_NONE;
//
// RESISTANCE ...
ArraySetAsSeries(l1RBuffer, true);
SetIndexBuffer(l1RBufferIndex, l1RBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l1RBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l1RBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l1RBufferIndex, PLOT_DRAW_TYPE, l1DrawType);
ArraySetAsSeries(l1R1Buffer, true);
SetIndexBuffer(l1R1BufferIndex, l1R1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l1R1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l1R1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l1R1BufferIndex, PLOT_DRAW_TYPE, l1PPDrawType);
ArraySetAsSeries(l1R2Buffer, true);
SetIndexBuffer(l1R2BufferIndex, l1R2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l1R2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l1R2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l1R2BufferIndex, PLOT_DRAW_TYPE, l1PPDrawType);
//
// SUPPORT ...
ArraySetAsSeries(l1SBuffer, true);
SetIndexBuffer(l1SBufferIndex, l1SBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l1SBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l1SBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l1SBufferIndex, PLOT_DRAW_TYPE, l1DrawType);
ArraySetAsSeries(l1S1Buffer, true);
SetIndexBuffer(l1S1BufferIndex, l1S1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l1S1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l1S1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l1S1BufferIndex, PLOT_DRAW_TYPE, l1PPDrawType);
ArraySetAsSeries(l1S2Buffer, true);
SetIndexBuffer(l1S2BufferIndex, l1S2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l1S2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l1S2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l1S2BufferIndex, PLOT_DRAW_TYPE, l1PPDrawType);
//
// LEVEL 2 ...
ENUM_DRAW_TYPE l2DrawType = showSRLevel2 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE l2PPDrawType = showPPLevel2 ? DRAW_LINE : DRAW_NONE;
//
// RESISTANCE ...
ArraySetAsSeries(l2RBuffer, true);
SetIndexBuffer(l2RBufferIndex, l2RBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l2RBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l2RBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l2RBufferIndex, PLOT_DRAW_TYPE, l2DrawType);
ArraySetAsSeries(l2R1Buffer, true);
SetIndexBuffer(l2R1BufferIndex, l2R1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l2R1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l2R1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l2R1BufferIndex, PLOT_DRAW_TYPE, l2PPDrawType);
ArraySetAsSeries(l2R2Buffer, true);
SetIndexBuffer(l2R2BufferIndex, l2R2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l2R2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l2R2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l2R2BufferIndex, PLOT_DRAW_TYPE, l2PPDrawType);
//
// SUPPORT ...
ArraySetAsSeries(l2SBuffer, true);
SetIndexBuffer(l2SBufferIndex, l2SBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l2SBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l2SBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l2SBufferIndex, PLOT_DRAW_TYPE, l2DrawType);
ArraySetAsSeries(l2S1Buffer, true);
SetIndexBuffer(l2S1BufferIndex, l2S1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l2S1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l2S1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l2S1BufferIndex, PLOT_DRAW_TYPE, l2PPDrawType);
ArraySetAsSeries(l2S2Buffer, true);
SetIndexBuffer(l2S2BufferIndex, l2S2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l2S2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l2S2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l2S2BufferIndex, PLOT_DRAW_TYPE, l2PPDrawType);
//
// LEVEL 3 ...
ENUM_DRAW_TYPE l3DrawType = showSRLevel3 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE l3PPDrawType = showPPLevel3 ? DRAW_LINE : DRAW_NONE;
//
// RESISTANCE ...
ArraySetAsSeries(l3RBuffer, true);
SetIndexBuffer(l3RBufferIndex, l3RBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l3RBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l3RBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l3RBufferIndex, PLOT_DRAW_TYPE, l3DrawType);
ArraySetAsSeries(l3R1Buffer, true);
SetIndexBuffer(l3R1BufferIndex, l3R1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l3R1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l3R1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l3R1BufferIndex, PLOT_DRAW_TYPE, l3PPDrawType);
ArraySetAsSeries(l3R2Buffer, true);
SetIndexBuffer(l3R2BufferIndex, l3R2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l3R2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l3R2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l3R2BufferIndex, PLOT_DRAW_TYPE, l3PPDrawType);
//
// SUPPORT ...
ArraySetAsSeries(l3SBuffer, true);
SetIndexBuffer(l3SBufferIndex, l3SBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l3SBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l3SBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l3SBufferIndex, PLOT_DRAW_TYPE, l3DrawType);
ArraySetAsSeries(l3S1Buffer, true);
SetIndexBuffer(l3S1BufferIndex, l3S1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l3S1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l3S1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l3S1BufferIndex, PLOT_DRAW_TYPE, l3PPDrawType);
ArraySetAsSeries(l3S2Buffer, true);
SetIndexBuffer(l3S2BufferIndex, l3S2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l3S2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l3S2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l3S2BufferIndex, PLOT_DRAW_TYPE, l3PPDrawType);
//
// LEVEL 4 ...
ENUM_DRAW_TYPE l4DrawType = showSRLevel4 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE l4PPDrawType = showPPLevel4 ? DRAW_LINE : DRAW_NONE;
//
// RESISTANCE ...
ArraySetAsSeries(l4RBuffer, true);
SetIndexBuffer(l4RBufferIndex, l4RBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l4RBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l4RBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l4RBufferIndex, PLOT_DRAW_TYPE, l4DrawType);
ArraySetAsSeries(l4R1Buffer, true);
SetIndexBuffer(l4R1BufferIndex, l4R1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l4R1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l4R1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l4R1BufferIndex, PLOT_DRAW_TYPE, l4PPDrawType);
ArraySetAsSeries(l4R2Buffer, true);
SetIndexBuffer(l4R2BufferIndex, l4R2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l4R2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l4R2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l4R2BufferIndex, PLOT_DRAW_TYPE, l4PPDrawType);
//
// SUPPORT ...
ArraySetAsSeries(l4SBuffer, true);
SetIndexBuffer(l4SBufferIndex, l4SBuffer, INDICATOR_DATA);
PlotIndexSetInteger(l4SBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l4SBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l4SBufferIndex, PLOT_DRAW_TYPE, l4DrawType);
ArraySetAsSeries(l4S1Buffer, true);
SetIndexBuffer(l4S1BufferIndex, l4S1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l4S1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l4S1BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l4S1BufferIndex, PLOT_DRAW_TYPE, l4PPDrawType);
ArraySetAsSeries(l4S2Buffer, true);
SetIndexBuffer(l4S2BufferIndex, l4S2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(l4S2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(l4S2BufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(l4S2BufferIndex, PLOT_DRAW_TYPE, l4PPDrawType);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
XOHCL c = GetCandle(bar_index);
//
int maxCandles = MathMax(mL1Candles, mL2Candles);
maxCandles = MathMax(maxCandles, mL3Candles);
maxCandles = MathMax(maxCandles, mL4Candles);
//
double l1RValue = 0;
double l1SValue = 0;
double l1CloseValue = 0;
//
double l2RValue = 0;
double l2SValue = 0;
double l2CloseValue = 0;
//
double l3RValue = 0;
double l3SValue = 0;
double l3CloseValue = 0;
//
double l4RValue = 0;
double l4SValue = 0;
double l4CloseValue = 0;
//
double l1PPValue = 0;
double l1R1Value = 0;
double l1R2Value = 0;
double l1S1Value = 0;
double l1S2Value = 0;
//
double l2PPValue = 0;
double l2R1Value = 0;
double l2R2Value = 0;
double l2S1Value = 0;
double l2S2Value = 0;
//
double l3PPValue = 0;
double l3R1Value = 0;
double l3R2Value = 0;
double l3S1Value = 0;
double l3S2Value = 0;
//
double l4PPValue = 0;
double l4R1Value = 0;
double l4R2Value = 0;
double l4S1Value = 0;
double l4S2Value = 0;
//
// LEVEL 1 ...
//
l1RValue = GetHighestHigh(
mL1Candles,
bar_index,
mL1HHMode);
l1SValue = GetLowestLow(
mL1Candles,
bar_index,
mL1LLMode);
l1CloseValue = GetLowestLow(
mL1Candles,
bar_index,
MODE_CLOSE);
//
// Calculate Pivot Points ...
double l1Diff = MathAbs(l1RValue - l1SValue);
l1PPValue = (l1RValue + l1SValue + l1CloseValue) / 3;
//
l1R1Value = (2 * l1PPValue) - l1SValue;
l1R2Value = l1PPValue + (l1Diff);
//
l1S1Value = (2 * l1PPValue) - l1RValue;
l1S2Value = l1PPValue - l1Diff;
//
// LEVEL 2 ...
//
l2RValue = GetHighestHigh(
mL2Candles,
bar_index,
mL2HHMode);
l2SValue = GetLowestLow(
mL2Candles,
bar_index,
mL2LLMode);
l2CloseValue = GetLowestLow(
mL2Candles,
bar_index,
MODE_CLOSE);
//
// Calculate Pivot Points ...
double l2Diff = MathAbs(l2RValue - l2SValue);
l2PPValue = (l2RValue + l2SValue + l2CloseValue) / 3;
//
l2R1Value = (2 * l2PPValue) - l2SValue;
l2R2Value = l2PPValue + (l2Diff);
//
l2S1Value = (2 * l2PPValue) - l2RValue;
l2S2Value = l2PPValue - l2Diff;
//
// LEVEL 3 ...
//
l3RValue = GetHighestHigh(
mL3Candles,
bar_index,
mL3HHMode);
l3SValue = GetLowestLow(
mL3Candles,
bar_index,
mL3LLMode);
l3CloseValue = GetLowestLow(
mL3Candles,
bar_index,
MODE_CLOSE);
//
// Calculate Pivot Points ...
double l3Diff = MathAbs(l3RValue - l3SValue);
l3PPValue = (l3RValue + l3SValue + l3CloseValue) / 3;
//
l3R1Value = (2 * l3PPValue) - l3SValue;
l3R2Value = l1PPValue + (l3Diff);
//
l3S1Value = (2 * l3PPValue) - l3RValue;
l3S2Value = l3PPValue - l3Diff;
//
// LEVEL 4 ...
//
l4RValue = GetHighestHigh(
mL4Candles,
bar_index,
mL4HHMode);
l4SValue = GetLowestLow(
mL4Candles,
bar_index,
mL4LLMode);
l4CloseValue = GetLowestLow(
mL4Candles,
bar_index,
MODE_CLOSE);
//
// Calculate Pivot Points ...
double l4Diff = MathAbs(l4RValue - l4SValue);
l4PPValue = (l4RValue + l4SValue + l4CloseValue) / 3;
//
l4R1Value = (2 * l4PPValue) - l4SValue;
l4R2Value = l4PPValue + (l4Diff);
//
l4S1Value = (2 * l4PPValue) - l4RValue;
l4S2Value = l4PPValue - l4Diff;
//
// FILLING BUFFERS ...
//
l1RBuffer[bar_index] = l1RValue;
l1R1Buffer[bar_index] = l1R1Value;
l1R2Buffer[bar_index] = l1R2Value;
//
l1SBuffer[bar_index] = l1SValue;
l1S1Buffer[bar_index] = l1S1Value;
l1S2Buffer[bar_index] = l1S2Value;
//
l2RBuffer[bar_index] = l2RValue;
l2R1Buffer[bar_index] = l2R1Value;
l2R2Buffer[bar_index] = l2R2Value;
//
l2SBuffer[bar_index] = l2SValue;
l2S1Buffer[bar_index] = l2S1Value;
l2S2Buffer[bar_index] = l2S2Value;
//
l3RBuffer[bar_index] = l3RValue;
l3R1Buffer[bar_index] = l3R1Value;
l3R2Buffer[bar_index] = l3R2Value;
//
l3SBuffer[bar_index] = l3SValue;
l3S1Buffer[bar_index] = l3S1Value;
l3S2Buffer[bar_index] = l3S2Value;
//
l4RBuffer[bar_index] = l4RValue;
l4R1Buffer[bar_index] = l4R1Value;
l4R2Buffer[bar_index] = l4R2Value;
//
l4SBuffer[bar_index] = l4SValue;
l4S1Buffer[bar_index] = l4S1Value;
l4S2Buffer[bar_index] = l4S2Value;
}
//
// Generate Comment String ...
string GenerateComment()
{
//
string result = "";
//
result += "L1 P: " + EnumToString(mL1Period) + "\n";
result += "L2 P: " + EnumToString(mL2Period) + "\n";
result += "L3 P: " + EnumToString(mL3Period) + "\n";
result += "L4 P: " + EnumToString(mL4Period);
//
return result;
}
//
// END Functions ...
//