1398 lines
30 KiB
Plaintext
1398 lines
30 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Indicator
|
|
// -------------------------------------------------
|
|
// Name: XOM1
|
|
// Description: Integrates All Requirements inside
|
|
// this indicator for analyse Markets Based on OM1 ...
|
|
//
|
|
//
|
|
// 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 XOM1 Indicator"
|
|
#property icon "../Images/SaherElm_Logo_Color.ico"
|
|
#property strict
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
#define ShortName "XOM1"
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
input group "Calculation";
|
|
|
|
//
|
|
// 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
|
|
|
|
//
|
|
// PV ...
|
|
input ENUM_SERIESMODE upperMode = MODE_HIGH; // Peak Method
|
|
input ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method
|
|
|
|
//
|
|
// Others ...
|
|
input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level
|
|
input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_382; // Lower Zone Level
|
|
input double sarStep = 0.02; // SAR Step
|
|
input double sarMax = 0.2; // SAR Maximum
|
|
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
|
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
|
|
input int maFastLength = 7; // Fast MA Length
|
|
input int maSlowLength = 20; // Slow MA Length
|
|
|
|
//
|
|
// Presentation ...
|
|
input group "Presentation";
|
|
input bool showPV = true; // Show PV
|
|
input bool showSAR = true; // Show Sar
|
|
input bool showMAFast = true; // Show MA Fast
|
|
input bool showMASlow = true; // Show MA Slow
|
|
input bool showFiboZone = true; // Show Fibo Zone
|
|
|
|
//
|
|
input int startCalculationForLastBars = 1500; // Calculate Last n Bars
|
|
|
|
//
|
|
input int sarArrowCode = 159; // Parabolic Sar Arrow Code
|
|
input int peakArrowCode = 159; // Peaks Arrow Code
|
|
input int valeArrowCode = 159; // Vales Arrow Code
|
|
|
|
//
|
|
// Non Inputs ...
|
|
|
|
//
|
|
#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
|
|
|
|
//
|
|
#property indicator_buffers 21
|
|
#property indicator_plots 7
|
|
|
|
//
|
|
// Plot Buffers ...
|
|
|
|
//
|
|
// Fast MA ...
|
|
|
|
//
|
|
#define maFastBufferIndex 0
|
|
#define maFastBufferPlotIndex 0
|
|
double maFastBuffer[];
|
|
|
|
//
|
|
#define maFastColorBufferIndex 1
|
|
double maFastColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label1 "FastMA"
|
|
#property indicator_type1 DRAW_COLOR_LINE
|
|
#property indicator_color1 CLR_NONE, clrYellow, clrOrangeRed, clrGray
|
|
#property indicator_width1 2
|
|
|
|
//
|
|
// Slow MA ...
|
|
|
|
//
|
|
#define maSlowBufferIndex 2
|
|
#define maSlowBufferPlotIndex 1
|
|
double maSlowBuffer[];
|
|
|
|
//
|
|
#define maSlowColorBufferIndex 3
|
|
double maSlowColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label2 "SlowMA"
|
|
#property indicator_type2 DRAW_COLOR_LINE
|
|
#property indicator_color2 CLR_NONE, clrLime, clrRed, clrGray
|
|
#property indicator_width2 2
|
|
|
|
//
|
|
// SAR ...
|
|
|
|
//
|
|
#define sarBufferIndex 4
|
|
#define sarBufferPlotIndex 2
|
|
double sarBuffer[];
|
|
|
|
//
|
|
#define sarColorBufferIndex 5
|
|
double sarColorBuffer[];
|
|
|
|
//
|
|
#property indicator_label3 "SAR"
|
|
#property indicator_type3 DRAW_COLOR_ARROW
|
|
#property indicator_color3 CLR_NONE, clrLime, clrRed, clrGray
|
|
#property indicator_width3 2
|
|
|
|
//
|
|
// PEAKS ...
|
|
|
|
//
|
|
#define peakBufferIndex 6
|
|
#define peakBufferPlotIndex 3
|
|
double peakBuffer[];
|
|
|
|
//
|
|
#property indicator_label4 "PEAK"
|
|
#property indicator_type4 DRAW_ARROW
|
|
#property indicator_color4 clrMagenta
|
|
#property indicator_width4 3
|
|
|
|
//
|
|
// VALES ...
|
|
|
|
//
|
|
#define valeBufferIndex 7
|
|
#define valeBufferPlotIndex 4
|
|
double valeBuffer[];
|
|
|
|
//
|
|
#property indicator_label5 "VALE"
|
|
#property indicator_type5 DRAW_ARROW
|
|
#property indicator_color5 clrAqua
|
|
#property indicator_width5 3
|
|
|
|
//
|
|
// FIBO Upper ...
|
|
|
|
//
|
|
#define fiboUpperBufferIndex 8
|
|
#define fiboUpperBufferPlotIndex 5
|
|
double fiboUpperBuffer[];
|
|
|
|
//
|
|
#property indicator_label6 "FIBUP"
|
|
#property indicator_type6 DRAW_LINE
|
|
#property indicator_color6 clrAqua
|
|
#property indicator_width6 2
|
|
|
|
//
|
|
// FIBO Lower ...
|
|
|
|
//
|
|
#define fiboLowerBufferIndex 9
|
|
#define fiboLowerBufferPlotIndex 6
|
|
double fiboLowerBuffer[];
|
|
|
|
//
|
|
#property indicator_label7 "FIBLO"
|
|
#property indicator_type7 DRAW_LINE
|
|
#property indicator_color7 clrMagenta
|
|
#property indicator_width7 2
|
|
|
|
//
|
|
// Data Buffers ...
|
|
|
|
//
|
|
#define mLastBufferIndex 9
|
|
|
|
//
|
|
// MA ...
|
|
|
|
//
|
|
#define maFastStateBufferIndex mLastBufferIndex + 1
|
|
double maFastStateBuffer[];
|
|
|
|
//
|
|
#define maSlowStateBufferIndex mLastBufferIndex + 2
|
|
double maSlowStateBuffer[];
|
|
|
|
//
|
|
// SAR ...
|
|
|
|
//
|
|
#define sarStateBufferIndex mLastBufferIndex + 3
|
|
double sarStateBuffer[];
|
|
|
|
//
|
|
// CYCLES ...
|
|
|
|
//
|
|
// SC ...
|
|
|
|
//
|
|
#define sHHBufferIndex mLastBufferIndex + 4
|
|
double sHHBuffer[];
|
|
|
|
//
|
|
#define sLLBufferIndex mLastBufferIndex + 5
|
|
double sLLBuffer[];
|
|
|
|
//
|
|
// MC ...
|
|
|
|
//
|
|
#define mHHBufferIndex mLastBufferIndex + 6
|
|
double mHHBuffer[];
|
|
|
|
//
|
|
#define mLLBufferIndex mLastBufferIndex + 7
|
|
double mLLBuffer[];
|
|
|
|
//
|
|
// LC ...
|
|
|
|
//
|
|
#define lHHBufferIndex mLastBufferIndex + 8
|
|
double lHHBuffer[];
|
|
|
|
//
|
|
#define lLLBufferIndex mLastBufferIndex + 9
|
|
double lLLBuffer[];
|
|
|
|
//
|
|
// HC ...
|
|
|
|
//
|
|
#define hHHBufferIndex mLastBufferIndex + 10
|
|
double hHHBuffer[];
|
|
|
|
//
|
|
#define hLLBufferIndex mLastBufferIndex + 11
|
|
double hLLBuffer[];
|
|
|
|
//
|
|
// Variables, Properties and etc ...
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
int sarHandler = INVALID_HANDLE;
|
|
int maFastHandler = INVALID_HANDLE;
|
|
int maSlowHandler = INVALID_HANDLE;
|
|
|
|
//
|
|
int limit;
|
|
|
|
//
|
|
int maxLength;
|
|
|
|
//
|
|
int firstBarIndex;
|
|
|
|
//
|
|
// Requirements ...
|
|
CArrayObj mObjects;
|
|
XCPOIDrawer *mDrawer;
|
|
|
|
//
|
|
// Event Handlers ...
|
|
|
|
/**
|
|
* Initialize Indicator ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int OnInit()
|
|
{
|
|
//
|
|
bool has = false;
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
// Define Index Buffers ...
|
|
DefineBuffers();
|
|
|
|
//
|
|
// Set Indicator ShortName ...
|
|
SetIndicatorName();
|
|
|
|
//
|
|
// 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
|
|
|
|
//
|
|
delete mDrawer;
|
|
ZeroMemory(mDrawer);
|
|
|
|
//
|
|
mObjects.Clear();
|
|
|
|
//
|
|
// De Initialize all Handlers and etc ...
|
|
IndicatorRelease(sarHandler);
|
|
IndicatorRelease(maFastHandler);
|
|
IndicatorRelease(maSlowHandler);
|
|
}
|
|
|
|
/**
|
|
* 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 ...
|
|
|
|
//
|
|
// MA ...
|
|
int maFastCalculatedBars = BarsCalculated(maFastHandler);
|
|
int maSlowCalculatedBars = BarsCalculated(maSlowHandler);
|
|
|
|
//
|
|
// SAR ...
|
|
int sarCalculatedBars = BarsCalculated(sarHandler);
|
|
|
|
//
|
|
bool isPassedRequiredCalculatedBars =
|
|
//
|
|
// MA ...
|
|
maFastCalculatedBars >= maxLength &&
|
|
maSlowCalculatedBars >= maxLength &&
|
|
//
|
|
// SAR ...
|
|
sarCalculatedBars >= maxLength
|
|
//
|
|
;
|
|
if (!isPassedRequiredCalculatedBars)
|
|
{
|
|
return prev_calculated;
|
|
}
|
|
|
|
//
|
|
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
|
? rates_total
|
|
: (rates_total - prev_calculated) + 1;
|
|
|
|
//
|
|
// Buffers Copy ...
|
|
|
|
//
|
|
// MA ...
|
|
int copiedMAFasts = CopyBuffer(maFastHandler, MAIN_LINE, 0, limit, maFastBuffer);
|
|
int copiedMASlows = CopyBuffer(maSlowHandler, MAIN_LINE, 0, limit, maSlowBuffer);
|
|
|
|
//
|
|
// SAR ...
|
|
int copiedSARs = CopyBuffer(sarHandler, MAIN_LINE, 0, limit, sarBuffer);
|
|
|
|
//
|
|
// Validate Copied Items ...
|
|
bool isPassedRequiredCopiedItems =
|
|
//
|
|
// MA ...
|
|
copiedMAFasts >= limit &&
|
|
copiedMASlows >= limit &&
|
|
//
|
|
// SAR ...
|
|
copiedSARs >= limit
|
|
//
|
|
;
|
|
if (!isPassedRequiredCopiedItems)
|
|
{
|
|
return prev_calculated;
|
|
}
|
|
|
|
//
|
|
// Main Loop ...
|
|
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
{
|
|
//
|
|
CalculateBuffers(
|
|
i,
|
|
prev_calculated,
|
|
rates_total,
|
|
//
|
|
open,
|
|
high,
|
|
close,
|
|
low,
|
|
tick_volume //
|
|
);
|
|
}
|
|
|
|
//
|
|
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 =
|
|
//
|
|
// MA ...
|
|
maFastLength >= 2 &&
|
|
maSlowLength >= 2 &&
|
|
maSlowLength > maFastLength &&
|
|
//
|
|
// SAR ...
|
|
sarMax > 0 &&
|
|
sarStep > 0 &&
|
|
sarMax > sarStep &&
|
|
//
|
|
// 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);
|
|
result = MathMax(result, maFastLength);
|
|
result = MathMax(result, maSlowLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Define Required Buffers ...
|
|
*/
|
|
void DefineBuffers()
|
|
{
|
|
//
|
|
// Fast MA ...
|
|
|
|
//
|
|
ArraySetAsSeries(maFastBuffer, true);
|
|
SetIndexBuffer(maFastBufferIndex, maFastBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(maFastBufferPlotIndex, PLOT_SHOW_DATA, showMAFast);
|
|
PlotIndexSetDouble(maFastBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
|
|
|
//
|
|
ArraySetAsSeries(maFastColorBuffer, true);
|
|
SetIndexBuffer(maFastColorBufferIndex, maFastColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
ArraySetAsSeries(maFastStateBuffer, true);
|
|
SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS);
|
|
|
|
//
|
|
// Slow MA ...
|
|
|
|
//
|
|
ArraySetAsSeries(maSlowBuffer, true);
|
|
SetIndexBuffer(maSlowBufferIndex, maSlowBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(maSlowBufferPlotIndex, PLOT_SHOW_DATA, showMASlow);
|
|
PlotIndexSetDouble(maSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
|
|
|
//
|
|
ArraySetAsSeries(maSlowColorBuffer, true);
|
|
SetIndexBuffer(maSlowColorBufferIndex, maSlowColorBuffer, INDICATOR_COLOR_INDEX);
|
|
|
|
//
|
|
ArraySetAsSeries(maSlowStateBuffer, true);
|
|
SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS);
|
|
|
|
//
|
|
// 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);
|
|
|
|
//
|
|
// FIBO Zone ...
|
|
|
|
//
|
|
ENUM_DRAW_TYPE fiboZoneDrawType = showFiboZone ? DRAW_LINE : DRAW_NONE;
|
|
|
|
//
|
|
// Upper ...
|
|
ArraySetAsSeries(fiboUpperBuffer, true);
|
|
SetIndexBuffer(fiboUpperBufferIndex, fiboUpperBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(fiboUpperBufferPlotIndex, PLOT_SHOW_DATA, showFiboZone);
|
|
PlotIndexSetInteger(fiboUpperBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType);
|
|
PlotIndexSetDouble(fiboUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
|
|
|
//
|
|
// Lower ...
|
|
ArraySetAsSeries(fiboLowerBuffer, true);
|
|
SetIndexBuffer(fiboLowerBufferIndex, fiboLowerBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
PlotIndexSetInteger(fiboLowerBufferPlotIndex, PLOT_SHOW_DATA, showFiboZone);
|
|
PlotIndexSetInteger(fiboLowerBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType);
|
|
PlotIndexSetDouble(fiboLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
|
|
|
//
|
|
// Data Buffers ...
|
|
|
|
//
|
|
// CYCLES ...
|
|
|
|
//
|
|
// SC ...
|
|
|
|
//
|
|
ArraySetAsSeries(sHHBuffer, true);
|
|
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
ArraySetAsSeries(sLLBuffer, true);
|
|
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
// MC ...
|
|
|
|
//
|
|
ArraySetAsSeries(mHHBuffer, true);
|
|
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
ArraySetAsSeries(mLLBuffer, true);
|
|
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
// LC ...
|
|
|
|
//
|
|
ArraySetAsSeries(lHHBuffer, true);
|
|
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
ArraySetAsSeries(lLLBuffer, true);
|
|
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
// HC ...
|
|
|
|
//
|
|
ArraySetAsSeries(hHHBuffer, true);
|
|
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
ArraySetAsSeries(hLLBuffer, true);
|
|
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA);
|
|
|
|
//
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Initial all Indicator Requirements ...
|
|
*
|
|
* @return ( false )
|
|
*
|
|
*/
|
|
bool InitRequirements()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Handlers ...
|
|
|
|
//
|
|
// Fast MA ...
|
|
maFastHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
maFastLength,
|
|
0,
|
|
maMethod,
|
|
maAppliedTo //
|
|
);
|
|
result = maFastHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Slow MA ...
|
|
maSlowHandler = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
maSlowLength,
|
|
0,
|
|
maMethod,
|
|
maAppliedTo //
|
|
);
|
|
result = maSlowHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// SAR ...
|
|
sarHandler = iSAR(
|
|
_Symbol,
|
|
_Period,
|
|
sarStep,
|
|
sarMax //
|
|
);
|
|
result = sarHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mDrawer = new XCPOIDrawer();
|
|
|
|
//
|
|
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[] //
|
|
)
|
|
{
|
|
//
|
|
// Calculate Bars Limit and First Bar Index ...
|
|
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)
|
|
{
|
|
//
|
|
// TODO: Fill Buffers as Empty ...
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
|
|
//
|
|
// Common Requirements ...
|
|
|
|
//
|
|
// CYCLES Ranges ...
|
|
CalculateCycleRanges(
|
|
barIndex,
|
|
prevCalculated,
|
|
ratesTotal,
|
|
open,
|
|
high,
|
|
close,
|
|
low,
|
|
tickVolume //
|
|
);
|
|
|
|
//
|
|
// PV ...
|
|
CalculatePV(
|
|
barIndex,
|
|
prevCalculated,
|
|
ratesTotal,
|
|
open,
|
|
high,
|
|
close,
|
|
low,
|
|
tickVolume //
|
|
);
|
|
|
|
//
|
|
// Fast MA ...
|
|
double iFastMa = maFastBuffer[barIndex];
|
|
double maFastState = close[barIndex] > iFastMa
|
|
? bullishState
|
|
: close[barIndex] < iFastMa
|
|
? bearishState
|
|
: neuturalState;
|
|
double maFastColor = close[barIndex] > iFastMa
|
|
? bullishColorIDX
|
|
: close[barIndex] < iFastMa
|
|
? bearishColorIDX
|
|
: neuturalColorIDX;
|
|
maFastStateBuffer[barIndex] = maFastState;
|
|
maFastColorBuffer[barIndex] = showMAFast
|
|
? maFastColor
|
|
: hideColorIDX;
|
|
|
|
//
|
|
// Slow MA ...
|
|
double iSlowMa = maSlowBuffer[barIndex];
|
|
double maSlowState = close[barIndex] > iSlowMa
|
|
? bullishState
|
|
: close[barIndex] < iSlowMa
|
|
? bearishState
|
|
: neuturalState;
|
|
double maSlowColor = close[barIndex] > iSlowMa
|
|
? bullishColorIDX
|
|
: close[barIndex] < iSlowMa
|
|
? bearishColorIDX
|
|
: neuturalColorIDX;
|
|
maSlowStateBuffer[barIndex] = maSlowState;
|
|
maSlowColorBuffer[barIndex] = showMASlow
|
|
? maSlowColor
|
|
: hideColorIDX;
|
|
|
|
//
|
|
// SAR ...
|
|
double iSar = sarBuffer[barIndex];
|
|
double sarState = low[barIndex] > iSar
|
|
? bullishState
|
|
: high[barIndex] < iSar
|
|
? bearishState
|
|
: neuturalState;
|
|
double sarColor = low[barIndex] > iSar
|
|
? bullishColorIDX
|
|
: high[barIndex] < iSar
|
|
? bearishColorIDX
|
|
: neuturalColorIDX;
|
|
sarStateBuffer[barIndex] = sarState;
|
|
sarColorBuffer[barIndex] = showSAR
|
|
? sarColor
|
|
: hideColorIDX;
|
|
|
|
//
|
|
// FIBO Zone ...
|
|
|
|
//
|
|
double iPeak = peakBuffer[barIndex];
|
|
double iVale = valeBuffer[barIndex];
|
|
|
|
//
|
|
double iFiboUp = GetFibonacciLevel(
|
|
iPeak,
|
|
iVale,
|
|
upperZoneLevel,
|
|
X_DIRECTION_BULLISH);
|
|
|
|
//
|
|
double iFiboLo = GetFibonacciLevel(
|
|
iPeak,
|
|
iVale,
|
|
lowerZoneLevel,
|
|
X_DIRECTION_BULLISH);
|
|
|
|
//
|
|
fiboUpperBuffer[barIndex] = iFiboUp;
|
|
fiboLowerBuffer[barIndex] = iFiboLo;
|
|
}
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
//
|
|
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 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();
|
|
}
|
|
|
|
// |