Cleanup Work Space after Backup 14040203 ...

This commit is contained in:
2025-04-23 05:10:12 +03:30
parent 5316d60869
commit f48d272bba
76 changed files with 0 additions and 81839 deletions
-659
View File
@@ -1,659 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XWZ
// Description: XWZ ...
//
//
// 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 XWZ Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121_X3MA"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int fastMALength = 20; // Fast MA Length
input int midMALength = 50; // Mid MA Length
input int slowMALength = 200; // Slow MA Length
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input bool showMaFast = true; // Show Fast MA
input bool showMaMid = true; // Show Mid MA
input bool showMaSlow = true; // Show Slow MA
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 3
//
// Plot Buffers ...
//
// FAST ...
#define maFastBufferIndex 0
double maFastBuffer[];
#define maFastColorBufferIndex 1
double maFastColorBuffer[];
//
#define maFastPlotBufferIndex 0
#property indicator_label1 "X121 MAF"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// MID ...
#define maMidBufferIndex 2
double maMidBuffer[];
#define maMidColorBufferIndex 3
double maMidColorBuffer[];
//
#define maMidPlotBufferIndex 1
#property indicator_label2 "X121 MAM"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
// SLOW ...
#define maSlowBufferIndex 4
double maSlowBuffer[];
#define maSlowColorBufferIndex 5
double maSlowColorBuffer[];
//
#define maSlowPlotBufferIndex 2
#property indicator_label3 "X121 MAS"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// Data Buffers ...
//
int mLastBufferIndex = 5;
//
// Fast State ...
#define maFastStateBufferIndex mLastBufferIndex + 1
double maFastStateBuffer[];
//
// Mid State ...
#define maMidStateBufferIndex mLastBufferIndex + 2
double maMidStateBuffer[];
//
// Slow State ...
#define maSlowStateBufferIndex mLastBufferIndex + 3
double maSlowStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
int maFastHandler = INVALID_HANDLE;
int maMidHandler = INVALID_HANDLE;
int maSlowHandler = INVALID_HANDLE;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// Fast MA ...
maFastHandler = iMA(
_Symbol,
_Period,
fastMALength,
0,
maMethod,
maAppliedTo //
);
bool isInited = maFastHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Mid MA ...
maMidHandler = iMA(
_Symbol,
_Period,
midMALength,
0,
maMethod,
maAppliedTo //
);
isInited = maMidHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Slow MA ...
maSlowHandler = iMA(
_Symbol,
_Period,
slowMALength,
0,
maMethod,
maAppliedTo //
);
isInited = maSlowHandler != INVALID_HANDLE;
if (!isInited)
{
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();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
IndicatorSetInteger(INDICATOR_DIGITS, 2);
//
// 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
//
IndicatorRelease(maFastHandler);
IndicatorRelease(maMidHandler);
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 ...
//
// Fast MA ...
int maFastCalculatedBars = BarsCalculated(maFastHandler);
//
// Mid MA ...
int maMidCalculatedBars = BarsCalculated(maMidHandler);
//
// Slow MA ...
int maSlowCalculatedBars = BarsCalculated(maSlowHandler);
//
bool isPassedRequiredCalculatedBars =
//
// Fast MA ...
maFastCalculatedBars >= maxLength &&
//
// Slow MA ...
maMidCalculatedBars >= maxLength &&
//
// Slow MA ...
maSlowCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// Fast MA ...
int copiedFastMas = CopyBuffer(maFastHandler, 0, 0, limit, maFastBuffer);
//
// Mid MA ...
int copiedMidMas = CopyBuffer(maMidHandler, 0, 0, limit, maMidBuffer);
//
// Slow MA ...
int copiedSlowMas = CopyBuffer(maSlowHandler, 0, 0, limit, maSlowBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// Fast MA ...
copiedFastMas > 0 &&
//
// Mid MA ...
copiedMidMas > 0 &&
//
// Slow MA ...
copiedSlowMas > 0
//
;
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;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result = fastMALength > 0 &&
midMALength > 0 &&
slowMALength > 0 &&
midMALength > fastMALength &&
slowMALength > midMALength;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(fastMALength, midMALength);
result = MathMax(result, slowMALength);
//
return result;
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Fast ...
ArraySetAsSeries(maFastBuffer, true);
ArraySetAsSeries(maFastColorBuffer, true);
SetIndexBuffer(maFastBufferIndex, maFastBuffer, INDICATOR_DATA);
SetIndexBuffer(maFastColorBufferIndex, maFastColorBuffer, INDICATOR_COLOR_INDEX);
//
// Mid ...
ArraySetAsSeries(maMidBuffer, true);
ArraySetAsSeries(maMidColorBuffer, true);
SetIndexBuffer(maMidBufferIndex, maMidBuffer, INDICATOR_DATA);
SetIndexBuffer(maMidColorBufferIndex, maMidColorBuffer, INDICATOR_COLOR_INDEX);
//
// Slow ...
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(maSlowColorBuffer, true);
SetIndexBuffer(maSlowBufferIndex, maSlowBuffer, INDICATOR_DATA);
SetIndexBuffer(maSlowColorBufferIndex, maSlowColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// Fast State ...
ArraySetAsSeries(maFastStateBuffer, true);
SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS);
//
// Mid State ...
ArraySetAsSeries(maMidStateBuffer, true);
SetIndexBuffer(maMidStateBufferIndex, maMidStateBuffer, INDICATOR_CALCULATIONS);
//
// Slow State ...
ArraySetAsSeries(maSlowStateBuffer, true);
SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateValues(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
maMidBuffer[barIndex] = 0;
maFastBuffer[barIndex] = 0;
maSlowBuffer[barIndex] = 0;
//
maFastColorBuffer[barIndex] = hideColorIDX;
maMidColorBuffer[barIndex] = hideColorIDX;
maSlowColorBuffer[barIndex] = hideColorIDX;
maFastStateBuffer[barIndex] = hideColorIDX;
maMidStateBuffer[barIndex] = hideColorIDX;
maSlowStateBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate Vales ...
*
* @param bar_index: 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 CalculateValues(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Implement Colorify Mechanism ...
//
// Calculate Applied Price ...
ENUM_X_PRICE mPType = ToXPrice(maAppliedTo);
double iPrice = GetAppliedPrice(
mPType,
open,
high,
low,
close,
bar_index //
);
//
double iFast = maFastBuffer[bar_index];
double iMid = maMidBuffer[bar_index];
double iSlow = maSlowBuffer[bar_index];
//
double iFastState = iPrice > iFast
? bullishColorIDX
: iPrice < iFast
? bearishColorIDX
: neuturalColorIDX;
double iMidState = iPrice > iMid
? bullishColorIDX
: iPrice < iMid
? bearishColorIDX
: neuturalColorIDX;
double iSlowState = iPrice > iSlow
? bullishColorIDX
: iPrice < iSlow
? bearishColorIDX
: neuturalColorIDX;
//
maFastColorBuffer[bar_index] =
showMaFast
? iFastState
: hideColorIDX;
maFastStateBuffer[bar_index] = iFastState;
//
maMidColorBuffer[bar_index] =
showMaMid
? iMidState
: hideColorIDX;
maMidStateBuffer[bar_index] = iMidState;
//
maSlowColorBuffer[bar_index] =
showMaSlow
? iSlowState
: hideColorIDX;
maSlowStateBuffer[bar_index] = iSlowState;
}
//
-882
View File
@@ -1,882 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XATR
// Description: XATR ...
//
//
// 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 XATR Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XATR"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
//
input group "RSI Detection";
input int rsiLength = 14; // Length
input ENUM_X_PRICE rsiPriceType = X_PRICE_CLOSE; // Applied To
input ENUM_X_MA_METHOD rsiSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method;
//
input group "ATR Detection";
input int atrLength = 14; // Length
input double atrMultiplier = 1; // Multiplier
input ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // Upper Zone Applied To
input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // Lower Zone Applied To
input ENUM_X_MA_METHOD atrSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method
//
input group "Price Change";
input int priceChangeSmoothingLength = 14; // Length
input ENUM_X_PRICE priceChangeType = X_PRICE_CLOSE; // Price Type
input ENUM_X_MA_METHOD priceChangeSmoothingMethod = X_MA_MODE_SMA; // Moving Average Moethod
//
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showAtrUpper = true; // Show Upper Zone
input bool showAtrLower = true; // Show Lower Zone
input bool showSmoothedAtrUpper = true; // Show Smoothed Upper Zone
input bool showSmoothedAtrLower = true; // Show Smoothed Lower Zone
input bool showRSIChange = true; // Show RSI Change
input bool showSmoothedRSIChange = true; // ShowSmoothed RSI Change
input bool showPriceChange = true; // Show Price Change
input bool showSmoothedPriceChange = true; // ShowSmoothed Price Change
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 10
#property indicator_plots 8
//
// ATR ...
//
// Upper ...
//
#define atrUpperBufferIndex 0
double atrUpperBuffer[];
#property indicator_label1 "X121 ATRU"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// Lower ...
//
#define atrLowerBufferIndex 1
double atrLowerBuffer[];
#property indicator_label2 "X121 ATRL"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrYellow
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// ATR Smoothed ...
//
// Upper ...
//
#define atrSmoothedUpperBufferIndex 2
double atrSmoothedUpperBuffer[];
#property indicator_label3 "X121 ATRUSM"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_DASH
#property indicator_width3 1
//
// Lower ...
//
#define atrSmoothedLowerBufferIndex 3
double atrSmoothedLowerBuffer[];
#property indicator_label4 "X121 ATRLSM"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrYellow
#property indicator_style4 STYLE_DASH
#property indicator_width4 1
//
// Price Change ...
//
#define priceChangeBufferIndex 4
double priceChangeBuffer[];
#property indicator_label5 "X121 PCH"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrOrchid
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//
// Price Change Smoothed ...
//
#define priceChangeSmoothedBufferIndex 5
double priceChangeSmoothedBuffer[];
#property indicator_label6 "X121 PCHSM"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrOrchid
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//
// RSI Change ...
//
#define rsiChangeBufferIndex 6
double rsiChangeBuffer[];
#property indicator_label7 "X121 RSICH"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrCornflowerBlue
#property indicator_style7 STYLE_SOLID
#property indicator_width7 1
//
// RSI Change Smoothed ...
//
#define rsiChangeSmoothedBufferIndex 7
double rsiChangeSmoothedBuffer[];
#property indicator_label8 "X121 RSICHSM"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrCornflowerBlue
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//
// Data Buffers ...
//
int mLastBufferIndex = 7;
//
// ATR ...
#define atrBufferIndex mLastBufferIndex + 1
double atrBuffer[];
//
// RSI ...
#define rsiBufferIndex mLastBufferIndex + 2
double rsiBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// RSI Handler ...
int rsiHandler = INVALID_HANDLE;
//
// ATR Handler ...
int atrHandler = INVALID_HANDLE;
//
ENUM_APPLIED_PRICE rsiAppliedTo = ToAppliedPrice(rsiPriceType);
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// RSI ...
rsiHandler = iRSI(
_Symbol,
_Period,
rsiLength,
rsiAppliedTo //
);
bool isInited = rsiHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
atrLength //
);
isInited = atrHandler != INVALID_HANDLE;
if (!isInited)
{
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();
//
// 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
//
IndicatorRelease(rsiHandler);
IndicatorRelease(atrHandler);
}
/**
* 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);
//
// Fill All Buffers by Zero ...
if (prev_calculated == 0)
{
}
//
// Validate Calculated Bars ...
//
// RSI ...
int rsiCalculatedBars = BarsCalculated(rsiHandler);
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
bool isPassedRequiredCalculatedBars =
//
// RSI ...
rsiCalculatedBars >= maxLength &&
//
// ATR ...
atrCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// RSI ...
int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
//
// ATR ...
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
//
// RSI ...
copiedRsis > 0 &&
//
// ATR ...
copiedAtrs > 0
//
;
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;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result =
//
// RSI ...
rsiLength > 0 &&
//
// ATR ...
atrLength > 0 &&
atrMultiplier > 0 &&
//
priceChangeSmoothingLength > 0 &&
//
IsValid(rsiPriceType) &&
IsValid(priceChangeType) &&
IsValid(atrUpperPriceType) &&
IsValid(atrLowerPriceType)
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(rsiLength, atrLength);
result = MathMax(result, priceChangeSmoothingLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// ATR ...
//
// UPPER ...
ENUM_DRAW_TYPE atrUpperDrawType = showAtrUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrUpperBuffer, true);
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, showAtrUpper);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
//
// LOWER ...
ENUM_DRAW_TYPE atrLowerDrawType = showAtrLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrLowerBuffer, true);
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, showAtrLower);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
//
// ATR Smoothed ...
//
// UPPER ...
ENUM_DRAW_TYPE atrSmoothedUpperDrawType = showSmoothedAtrUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrSmoothedUpperBuffer, true);
SetIndexBuffer(atrSmoothedUpperBufferIndex, atrSmoothedUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrSmoothedUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrUpper);
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_DRAW_TYPE, atrSmoothedUpperDrawType);
//
// LOWER ...
ENUM_DRAW_TYPE atrSmoothedLowerDrawType = showSmoothedAtrLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrSmoothedLowerBuffer, true);
SetIndexBuffer(atrSmoothedLowerBufferIndex, atrSmoothedLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrSmoothedLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrLower);
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_DRAW_TYPE, atrSmoothedLowerDrawType);
//
// PriceChange ...
ENUM_DRAW_TYPE priceChangeDrawType = showPriceChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(priceChangeBuffer, true);
SetIndexBuffer(priceChangeBufferIndex, priceChangeBuffer, INDICATOR_DATA);
PlotIndexSetDouble(priceChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_SHOW_DATA, showPriceChange);
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_DRAW_TYPE, priceChangeDrawType);
//
// PriceChange Smoothed ...
ENUM_DRAW_TYPE priceChangeSmoothedaDrawType = showSmoothedPriceChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(priceChangeSmoothedBuffer, true);
SetIndexBuffer(priceChangeSmoothedBufferIndex, priceChangeSmoothedBuffer, INDICATOR_DATA);
PlotIndexSetDouble(priceChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedPriceChange);
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, priceChangeSmoothedaDrawType);
//
// RSIChange ...
ENUM_DRAW_TYPE rsiChangeDrawType = showRSIChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(rsiChangeBuffer, true);
SetIndexBuffer(rsiChangeBufferIndex, rsiChangeBuffer, INDICATOR_DATA);
PlotIndexSetDouble(rsiChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_SHOW_DATA, showRSIChange);
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_DRAW_TYPE, rsiChangeDrawType);
//
// RSIChangeMa ...
ENUM_DRAW_TYPE rsiChangeMaDrawType = showSmoothedRSIChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(rsiChangeSmoothedBuffer, true);
SetIndexBuffer(rsiChangeSmoothedBufferIndex, rsiChangeSmoothedBuffer, INDICATOR_DATA);
PlotIndexSetDouble(rsiChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedRSIChange);
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, rsiChangeMaDrawType);
//
// Data Buffers ...
//
// ATR ...
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
// RSI ...
ArraySetAsSeries(rsiBuffer, true);
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
//
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
IndicatorSetInteger(INDICATOR_DIGITS, 2);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateAtrZones(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low //
);
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
rsiBuffer[barIndex] = 0;
atrBuffer[barIndex] = 0;
atrUpperBuffer[barIndex] = 0;
atrLowerBuffer[barIndex] = 0;
rsiChangeBuffer[barIndex] = 0;
priceChangeBuffer[barIndex] = 0;
atrSmoothedUpperBuffer[barIndex] = 0;
atrSmoothedLowerBuffer[barIndex] = 0;
rsiChangeSmoothedBuffer[barIndex] = 0;
priceChangeSmoothedBuffer[barIndex] = 0;
}
/**
* Calculate ATR Zones ...
*
* @param bar_index: 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 ...
*/
void CalculateAtrZones(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[] //
)
{
//
double points = GetPoints(_Symbol);
//
// ATR Calculations ...
double iAtr = atrBuffer[bar_index];
double iMultiPliedAtr = iAtr * atrMultiplier;
//
// Select Upper Price ...
double iUpperPrice = GetAppliedPrice(
atrUpperPriceType,
open,
high,
low,
close,
bar_index //
);
//
// Select Lower Price ...
double iLowerPrice = GetAppliedPrice(
atrLowerPriceType,
open,
high,
low,
close,
bar_index //
);
//
// Calculate Atrs ...
//
double iAtrUpper = iUpperPrice + iMultiPliedAtr;
double iAtrLower = iLowerPrice - iMultiPliedAtr;
//
atrUpperBuffer[bar_index] = iAtrUpper;
atrLowerBuffer[bar_index] = iAtrLower;
//
bool canSmoothAtr = atrSmoothingMethod != X_MA_MODE_NONE;
if (canSmoothAtr)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
atrUpperBuffer,
atrSmoothedUpperBuffer,
atrSmoothingMethod //
);
//
// Lower ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
atrLowerBuffer,
atrSmoothedLowerBuffer,
atrSmoothingMethod //
);
}
else
{
//
atrSmoothedUpperBuffer[bar_index] = iAtrUpper;
atrSmoothedLowerBuffer[bar_index] = iAtrLower;
}
//
// RSI Change Calculations ...
//
double iRsi = rsiBuffer[bar_index];
double iRsiP = rsiBuffer[bar_index + 1];
double iRsiPrice = GetAppliedPrice(
rsiPriceType,
open,
high,
low,
close,
bar_index //
);
//
double iRsiChanged = iRsi - iRsiP;
double iRsiPointsChanged = iRsiChanged / points;
//
double iRChange = iRsiPrice + (iRsiChanged * points);
rsiChangeBuffer[bar_index] = iRChange;
//
bool canSmoothRsi = rsiSmoothingMethod != X_MA_MODE_NONE;
if (canSmoothRsi)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
rsiChangeBuffer,
rsiChangeSmoothedBuffer,
rsiSmoothingMethod //
);
}
else
{
rsiChangeSmoothedBuffer[bar_index] = iRChange;
}
//
// PRICE Change Calculation ...
//
double iPChangePrice = GetAppliedPrice(
priceChangeType,
open,
high,
low,
close,
bar_index //
);
double iPPChangePrice = GetAppliedPrice(
priceChangeType,
open,
high,
low,
close,
bar_index + 1 //
);
//
double iPriceChange = iPChangePrice - iPPChangePrice;
double iPricePointsChanged = iPriceChange / points;
double iVolatilityChange = iPriceChange / iAtr;
//
double iPChange = iPChangePrice + (iPricePointsChanged * points);
priceChangeBuffer[bar_index] = iPChange;
//
bool canSmoothPriceChange = priceChangeSmoothingMethod != X_MA_MODE_NONE;
if (canSmoothPriceChange)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
priceChangeBuffer,
priceChangeSmoothedBuffer,
priceChangeSmoothingMethod //
);
}
else
{
priceChangeSmoothedBuffer[bar_index] = iPChange;
}
}
//
-624
View File
@@ -1,624 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XCHE
// Description: XCHE ...
//
//
// 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 XCHE Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XCHE"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int cheLength = 35; // Length
input int cheLoopback = 26; // Loopback
input double cheMultiplier1 = 3.0; // 1st Multiplier
input double cheMultiplier2 = 3.5; // 2nd Multiplier
input ENUM_APPLIED_PRICE cheUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied to
input ENUM_APPLIED_PRICE cheLowerAppliedTo = PRICE_LOW; // Lower Zone Applied to
//
input group "Presentation";
//
input int cheArrowCode = 159; // CHE Arrow Code
//
input bool showLE1 = true; // Show 1st Long Exit
input bool showSE1 = true; // Show 1st Short Exit
input bool showLE2 = true; // Show 2st Long Exit
input bool showSE2 = true; // Show 2st Short Exit
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 8
//
// Exit 1 ...
//
// LONG ...
//
#define le1BufferIndex 0
double le1Buffer[];
#property indicator_label1 "X121 LE1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// SHORT ...
//
#define se1BufferIndex 1
double se1Buffer[];
#property indicator_label2 "X121 SE1"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrMagenta
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
// Exit 2 ...
//
// LONG ...
//
#define le2BufferIndex 2
double le2Buffer[];
#property indicator_label3 "X121 LE2"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrAqua
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//
// SHORT ...
//
#define se2BufferIndex 3
double se2Buffer[];
#property indicator_label4 "X121 SE2"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrMagenta
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//
// Start Buffers ...
//
#define le1StartBufferIndex 4
double le1StartBuffer[];
//
#property indicator_label5 "X121 LE1 S"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrLime
//
#define se1StartBufferIndex 5
double se1StartBuffer[];
//
#property indicator_label6 "X121 SE1 S"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrRed
//
#define le2StartBufferIndex 6
double le2StartBuffer[];
//
#property indicator_label7 "X121 LE2 S"
#property indicator_type7 DRAW_ARROW
#property indicator_color7 clrLime
//
#define se2StartBufferIndex 7
double se2StartBuffer[];
//
#property indicator_label8 "X121 SE2 S"
#property indicator_type8 DRAW_ARROW
#property indicator_color8 clrRed
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Working Array ...
double work[][6];
#define hi1Idx 0
#define lo1Idx 1
#define hi2Idx 2
#define lo2Idx 3
#define trend1Idx 4
#define trend2Idx 5
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
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 cheLength, here we get max Input cheLength
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// 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
}
/**
* 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[] //
)
{
//
if (Bars(_Symbol, _Period) < rates_total)
{
return (prev_calculated);
}
//
if (ArrayRange(work, 0) != rates_total)
{
ArrayResize(work, rates_total);
}
//
// this counts Available Bars ...
//
limit = prev_calculated - 1;
if (limit < 0)
{
limit = 0;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
low,
close);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = true;
//
result =
cheLength >= 9 &&
cheLoopback >= 0;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(cheLength, cheLoopback);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// LEVEL 1 ...
//
// Long Exit 1 ...
//
// Draw Type ...
ENUM_DRAW_TYPE le1DrawType = showLE1 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE le1StartDrawType = showLE1 ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(le1BufferIndex, le1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(le1BufferIndex, PLOT_SHOW_DATA, showLE1);
PlotIndexSetInteger(le1BufferIndex, PLOT_DRAW_TYPE, le1DrawType);
//
// Start Buffer ...
SetIndexBuffer(le1StartBufferIndex, le1StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(le1StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(le1StartBufferIndex, PLOT_DRAW_TYPE, le1StartDrawType);
PlotIndexSetInteger(le1StartBufferIndex, PLOT_ARROW, cheArrowCode);
//
// Short Exit 1 ...
//
// Draw Type ...
ENUM_DRAW_TYPE se1DrawType = showSE1 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE se1StartDrawType = showSE1 ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(se1BufferIndex, se1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(se1BufferIndex, PLOT_SHOW_DATA, showSE1);
PlotIndexSetInteger(se1BufferIndex, PLOT_DRAW_TYPE, se1DrawType);
//
// Start Buffer ...
SetIndexBuffer(se1StartBufferIndex, se1StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(se1StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(se1StartBufferIndex, PLOT_DRAW_TYPE, se1StartDrawType);
PlotIndexSetInteger(se1StartBufferIndex, PLOT_ARROW, cheArrowCode);
//
// LEVEL 2 ...
//
// Long Exit 2 ...
//
// Draw Type ...
ENUM_DRAW_TYPE le2DrawType = showLE2 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE le2StartDrawType = showLE2 ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(le2BufferIndex, le2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(le2BufferIndex, PLOT_SHOW_DATA, showLE2);
PlotIndexSetInteger(le2BufferIndex, PLOT_DRAW_TYPE, le2DrawType);
//
// Start Buffer ...
SetIndexBuffer(le2StartBufferIndex, le2StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(le2StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(le2StartBufferIndex, PLOT_DRAW_TYPE, le2StartDrawType);
PlotIndexSetInteger(le2StartBufferIndex, PLOT_ARROW, cheArrowCode);
//
// Short Exit 2 ...
//
// Draw Type ...
ENUM_DRAW_TYPE se2DrawType = showSE2 ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE se2StartDrawType = showSE2 ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(se2BufferIndex, se2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(se2BufferIndex, PLOT_SHOW_DATA, showSE2);
PlotIndexSetInteger(se2BufferIndex, PLOT_DRAW_TYPE, se2DrawType);
//
// Start Buffer ...
SetIndexBuffer(se2StartBufferIndex, se2StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(se2StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(se2StartBufferIndex, PLOT_DRAW_TYPE, se2StartDrawType);
PlotIndexSetInteger(se2StartBufferIndex, PLOT_ARROW, cheArrowCode);
}
/**
* 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
int prevCalculated, // Previous Calculated
int ratesTotal, // Total Rates
const double &open[], // Rates Open ...
const double &high[], // Rates High ...
const double &low[], // Rates Low ...
const double &close[] // Rates Close ...
)
{
//
// Cleanup Buffers ...
le1Buffer[bar_index] = le1StartBuffer[bar_index] = se1Buffer[bar_index] = se1StartBuffer[bar_index] = EMPTY_VALUE;
le2Buffer[bar_index] = le2StartBuffer[bar_index] = se2Buffer[bar_index] = se2StartBuffer[bar_index] = EMPTY_VALUE;
//
int start = MathMax(bar_index - cheLoopback, 0);
//
// Calculate ATR Value ...
double atrValue = 0;
for (int k = 1; k <= cheLength && (bar_index - k - 1) >= 0; k++)
{
//
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
}
atrValue /= (double)cheLength;
//
// Retrieve Highest High and Lowest Lows ...
double cheLoopbackMax = high[ArrayMaximum(high, start, cheLoopback)];
double cheLoopbackMin = low[ArrayMinimum(low, start, cheLoopback)];
//
// Fill Multi Dimesional Working Array ...
work[bar_index][hi1Idx] = cheLoopbackMax - cheMultiplier1 * atrValue;
work[bar_index][lo1Idx] = cheLoopbackMin + cheMultiplier1 * atrValue;
work[bar_index][hi2Idx] = cheLoopbackMax - cheMultiplier2 * atrValue;
work[bar_index][lo2Idx] = cheLoopbackMin + cheMultiplier2 * atrValue;
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
//
if (bar_index > 0)
{
//
// Calculate Trends ...
if (close[bar_index] > work[bar_index - 1][lo1Idx])
{
work[bar_index][trend1Idx] = 1;
}
//
if (close[bar_index] < work[bar_index - 1][hi1Idx])
{
work[bar_index][trend1Idx] = -1;
}
//
if (close[bar_index] > work[bar_index - 1][lo2Idx])
{
work[bar_index][trend2Idx] = 1;
}
//
if (close[bar_index] < work[bar_index - 1][hi2Idx])
{
work[bar_index][trend2Idx] = -1;
}
//
// Calculate Exit Values ...
//
// Exit 1 ...
//
// Long ...
if (cheMultiplier1 > 0 && work[bar_index][trend1Idx] == 1)
{
//
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
{
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
}
//
le1Buffer[bar_index] = work[bar_index][hi1Idx];
//
if (le1Buffer[bar_index - 1] == EMPTY_VALUE)
{
le1StartBuffer[bar_index] = le1Buffer[bar_index];
}
}
//
// Short ...
if (cheMultiplier1 > 0 && work[bar_index][trend1Idx] == -1)
{
//
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
{
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
}
//
se1Buffer[bar_index] = work[bar_index][lo1Idx];
//
if (se1Buffer[bar_index - 1] == EMPTY_VALUE)
{
se1StartBuffer[bar_index] = se1Buffer[bar_index];
}
}
//
// Exit 2 ...
//
// Long ...
if (cheMultiplier2 > 0 && work[bar_index][trend2Idx] == 1)
{
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
{
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
}
//
le2Buffer[bar_index] = work[bar_index][hi2Idx];
//
if (le2Buffer[bar_index - 1] == EMPTY_VALUE)
{
le2StartBuffer[bar_index] = le2Buffer[bar_index];
}
}
//
// Short ...
if (cheMultiplier2 > 0 && work[bar_index][trend2Idx] == -1)
{
//
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
{
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
}
//
se2Buffer[bar_index] = work[bar_index][lo2Idx];
//
if (se2Buffer[bar_index - 1] == EMPTY_VALUE)
{
se2StartBuffer[bar_index] = se2Buffer[bar_index];
}
}
}
}
//
-532
View File
@@ -1,532 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Ocillator
// -------------------------------------------------
// Name: X121 XDelta
// Description: Detect Comulative Volumes Delta ...
//
//
// 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 XDelta Ocillator"
#property strict
//
// Definitions ...
//
#define ShortName "X121_XDELTA"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Makret ...
input group "Market";
input int maLength = 14; // Moving Averge Length
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
//
// Presentation ...
input group "Presentation";
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input bool showDeltaLine = true; // Show Delta Line
input bool showDeltaHistogram = true; // Show Delta Histogram
input bool showDeltaMa = true; // Show Delta Moving Average
//
// Buffers Props ...
//
#property indicator_separate_window
//
#property indicator_buffers 6
#property indicator_plots 3
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
//
// Buffers ...
//
#define deltaLineBufferIndex 0
double deltaLineBuffer[];
#property indicator_label1 "Delta Line"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#define deltaHistogramBufferIndex 1
double deltaHistogramBuffer[];
//
#define deltaHistogramColorBufferIndex 2
double deltaHistogramColorBuffer[];
#property indicator_label2 "Delta Histogram"
#property indicator_type2 DRAW_COLOR_HISTOGRAM
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
#define deltaMaBufferIndex 3
double deltaMaBuffer[];
#property indicator_label3 "Delta MA"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrOrchid
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//
// Data Buffers ...
#define mLastBufferIndex 3
//
#define rawDeltaBufferIndex mLastBufferIndex + 1
double rawDeltaBuffer[];
//
#define deltaStateBufferIndex mLastBufferIndex + 2
double deltaStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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();
IndicatorSetInteger(INDICATOR_DIGITS, 2);
//
// 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
}
/**
* 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);
//
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,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result = maLength > 0 &&
IsValid(maMethod);
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(0, maLength);
//
return result;
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Delta Line ...
ENUM_DRAW_TYPE deltaLineDrawType = showDeltaLine ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(deltaLineBuffer, true);
SetIndexBuffer(deltaLineBufferIndex, deltaLineBuffer, INDICATOR_DATA);
PlotIndexSetDouble(deltaLineBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_SHOW_DATA, showDeltaLine);
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_DRAW_TYPE, deltaLineDrawType);
//
// Delta Histogram ...
ENUM_DRAW_TYPE deltaHistogramDrawType = showDeltaHistogram ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
//
ArraySetAsSeries(deltaHistogramBuffer, true);
SetIndexBuffer(deltaHistogramBufferIndex, deltaHistogramBuffer, INDICATOR_DATA);
PlotIndexSetDouble(deltaHistogramBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_SHOW_DATA, showDeltaHistogram);
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_DRAW_TYPE, deltaHistogramDrawType);
//
ArraySetAsSeries(deltaHistogramColorBuffer, true);
SetIndexBuffer(deltaHistogramColorBufferIndex, deltaHistogramColorBuffer, INDICATOR_COLOR_INDEX);
//
// Delta Ma ...
ENUM_DRAW_TYPE deltaMaDrawType = showDeltaMa ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(deltaMaBuffer, true);
SetIndexBuffer(deltaMaBufferIndex, deltaMaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(deltaMaBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_SHOW_DATA, showDeltaMa);
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_DRAW_TYPE, deltaMaDrawType);
//
// Data Buffers ...
//
ArraySetAsSeries(rawDeltaBuffer, true);
SetIndexBuffer(rawDeltaBufferIndex, rawDeltaBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(deltaStateBuffer, true);
SetIndexBuffer(deltaStateBufferIndex, deltaStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateValues(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
rawDeltaBuffer[barIndex] = 0.0;
deltaLineBuffer[barIndex] = 0.0;
deltaStateBuffer[barIndex] = 0.0;
deltaHistogramBuffer[barIndex] = 0.0;
deltaMaBuffer[barIndex] = 0.0;
deltaHistogramColorBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate Vales ...
*
* @param bar_index: 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 CalculateValues(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
XOHCL bar;
bool has = bar.Init(
_Symbol,
_Period,
bar_index //
);
if (!has)
{
return;
}
//
double iDelta = 0.0;
//
// Detecting Delta Volume ...
if (bar.IsBullish())
{
iDelta = (double)bar.volume;
}
else if (bar.IsBearish())
{
iDelta = -(double)bar.volume;
}
//
// Checking First Bar Conditions ...
bool isFirstBar =
startCalculationForLastBars > 0
? bar_index == startCalculationForLastBars
: bar_index == ratesTotal;
if (isFirstBar)
{
//
rawDeltaBuffer[bar_index] = iDelta;
deltaLineBuffer[bar_index] = iDelta;
deltaHistogramBuffer[bar_index] = iDelta;
}
else
{
//
iDelta += deltaLineBuffer[bar_index + 1];
//
rawDeltaBuffer[bar_index] = iDelta;
deltaLineBuffer[bar_index] = iDelta;
deltaHistogramBuffer[bar_index] = iDelta;
}
//
// Setting iDelta State ...
double iState = iDelta > 0
? bullishColorIDX
: iDelta < 0
? bearishColorIDX
: hideColorIDX;
//
// Setting iDelta Color ...
double iDeltaColor = iDelta > 0
? bullishColorIDX
: iDelta < 0
? bearishColorIDX
: hideColorIDX;
//
deltaStateBuffer[bar_index] = iState;
deltaHistogramColorBuffer[bar_index] = iDeltaColor;
//
// Calculate Moving Averages ...
int deltaMAsCount = iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
maLength,
rawDeltaBuffer,
deltaMaBuffer,
maMethod //
);
//
bar.Clean();
}
//
-692
View File
@@ -1,692 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XDON
// Description: XDON ...
//
//
// 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 XDON Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XDON"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int donchainLength = 40; // Donchain Length
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showUpper = true; // Show Upper Band
input bool showLower = true; // Show Lower Band
//
input bool showOpen = true; // Show Open
input bool showHigh = true; // Show High
input bool showClose = true; // Show Close
input bool showLow = true; // Show Low
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 8
//
// Plot Buffers ...
//
// Open ...
//
#define donOpenUpperBufferIndex 0
double donOpenUpperBuffer[];
//
#define donOpenUpperPlotBufferIndex 0
#property indicator_label1 "X121 O U"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrCornflowerBlue
#property indicator_width1 1
//
#define donOpenLowerBufferIndex 1
double donOpenLowerBuffer[];
//
#define donOpenLowerPlotBufferIndex 1
#property indicator_label2 "X121 O L"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrCornflowerBlue
#property indicator_width2 1
//
// High ...
//
#define donHighUpperBufferIndex 2
double donHighUpperBuffer[];
//
#define donHighUpperPlotBufferIndex 2
#property indicator_label3 "X121 H U"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrAquamarine
#property indicator_width3 1
//
#define donHighLowerBufferIndex 3
double donHighLowerBuffer[];
//
#define donHighLowerPlotBufferIndex 3
#property indicator_label4 "X121 H L"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrAquamarine
#property indicator_width4 1
//
// Low ...
//
#define donLowUpperBufferIndex 4
double donLowUpperBuffer[];
//
#define donLowUpperPlotBufferIndex 4
#property indicator_label5 "X121 L U"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrDarkOrchid
#property indicator_width5 1
//
#define donLowLowerBufferIndex 5
double donLowLowerBuffer[];
//
#define donLowLowerPlotBufferIndex 5
#property indicator_label6 "X121 L L"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrDarkOrchid
#property indicator_width6 1
//
// Close ...
//
#define donCloseUpperBufferIndex 6
double donCloseUpperBuffer[];
//
#define donCloseUpperPlotBufferIndex 6
#property indicator_label7 "X121 C U"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrCoral
#property indicator_width7 1
//
#define donCloseLowerBufferIndex 7
double donCloseLowerBuffer[];
//
#define donCloseLowerPlotBufferIndex 7
#property indicator_label8 "X121 C L"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrCoral
#property indicator_width8 1
//
// Data Buffers ...
//
int mLastBufferIndex = 7;
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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;
}
/**
* 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
}
/**
* 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 ...
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// 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;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
donchainLength > 0
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Open ...
//
// UPPER ...
bool canShowCOpenUpper = showUpper && showOpen;
ENUM_DRAW_TYPE donOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donOpenUpperBuffer, true);
SetIndexBuffer(donOpenUpperBufferIndex, donOpenUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donOpenUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper);
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_DRAW_TYPE, donOpenUpperDrawType);
//
// LOWER ...
bool canShowCOpenLower = showLower && showOpen;
ENUM_DRAW_TYPE donOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donOpenLowerBuffer, true);
SetIndexBuffer(donOpenLowerBufferIndex, donOpenLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donOpenLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower);
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_DRAW_TYPE, donOpenLowerDrawType);
//
// Close ...
//
// UPPER ...
bool canShowCCloseUpper = showUpper && showClose;
ENUM_DRAW_TYPE donCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donCloseUpperBuffer, true);
SetIndexBuffer(donCloseUpperBufferIndex, donCloseUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donCloseUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper);
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_DRAW_TYPE, donCloseUpperDrawType);
//
// LOWER ...
bool canShowCCloseLower = showLower && showClose;
ENUM_DRAW_TYPE donCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donCloseLowerBuffer, true);
SetIndexBuffer(donCloseLowerBufferIndex, donCloseLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donCloseLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower);
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_DRAW_TYPE, donCloseLowerDrawType);
//
// High ...
//
// UPPER ...
bool canShowCHighUpper = showUpper && showHigh;
ENUM_DRAW_TYPE donHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donHighUpperBuffer, true);
SetIndexBuffer(donHighUpperBufferIndex, donHighUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donHighUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper);
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_DRAW_TYPE, donHighUpperDrawType);
//
// LOWER ...
bool canShowCHighLower = showLower && showHigh;
ENUM_DRAW_TYPE donHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donHighLowerBuffer, true);
SetIndexBuffer(donHighLowerBufferIndex, donHighLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donHighLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighLower);
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_DRAW_TYPE, donHighLowerDrawType);
//
// Low ...
//
// UPPER ...
bool canShowCLowUpper = showUpper && showLow;
ENUM_DRAW_TYPE donLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donLowUpperBuffer, true);
SetIndexBuffer(donLowUpperBufferIndex, donLowUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donLowUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper);
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_DRAW_TYPE, donLowUpperDrawType);
//
// LOWER ...
bool canShowCLowLower = showLower && showLow;
ENUM_DRAW_TYPE donLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donLowLowerBuffer, true);
SetIndexBuffer(donLowLowerBufferIndex, donLowLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donLowLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower);
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType);
//
// Data Buffers ...
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateDonchains(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
donOpenUpperBuffer[barIndex] = EMPTY_VALUE;
donOpenLowerBuffer[barIndex] = EMPTY_VALUE;
donCloseUpperBuffer[barIndex] = EMPTY_VALUE;
donCloseLowerBuffer[barIndex] = EMPTY_VALUE;
donHighUpperBuffer[barIndex] = EMPTY_VALUE;
donHighLowerBuffer[barIndex] = EMPTY_VALUE;
donLowUpperBuffer[barIndex] = EMPTY_VALUE;
donLowLowerBuffer[barIndex] = EMPTY_VALUE;
}
/**
* Calculate Donchain ...
*
* @param bar_index: Integer, Bar Index ...
* @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 ...
* @param _length: Integer, Donchain Length ...
* @param _ouBuffer: Double Array Reference ...
* @param _olBuffer: Double Array Reference ...
* @param _huBuffer: Double Array Reference ...
* @param _hlBuffer: Double Array Reference ...
* @param _luBuffer: Double Array Reference ...
* @param _llBuffer: Double Array Reference ...
* @param _cuBuffer: Double Array Reference ...
* @param _clBuffer: Double Array Reference ...
*/
void CalculateDonchain(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
//
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[],
//
int _length,
//
double &_ouBuffer[],
double &_olBuffer[],
double &_huBuffer[],
double &_hlBuffer[],
double &_luBuffer[],
double &_llBuffer[],
double &_cuBuffer[],
double &_clBuffer[] //
)
{
//
double iUpper = 0;
double iLower = 0;
//
// OPEN ...
//
int from = bar_index;
//
iUpper = open[ArrayMaximum(open, from, _length)];
iLower = open[ArrayMinimum(open, from, _length)];
//
_ouBuffer[bar_index] = iUpper;
_olBuffer[bar_index] = iLower;
//
// HIGH ...
//
iUpper = high[ArrayMaximum(high, from, _length)];
iLower = high[ArrayMinimum(high, from, _length)];
//
_huBuffer[bar_index] = iUpper;
_hlBuffer[bar_index] = iLower;
//
// LOW ...
//
iUpper = low[ArrayMaximum(low, from, _length)];
iLower = low[ArrayMinimum(low, from, _length)];
//
_luBuffer[bar_index] = iUpper;
_llBuffer[bar_index] = iLower;
//
// CLOSE ...
//
iUpper = close[ArrayMaximum(close, from, _length)];
iLower = close[ArrayMinimum(close, from, _length)];
//
_cuBuffer[bar_index] = iUpper;
_clBuffer[bar_index] = iLower;
}
/**
* Calculate Different VWaps ...
*
* @param bar_index: 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 CalculateDonchains(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
CalculateDonchain(
//
bar_index,
prevCalculated,
ratesTotal,
//
open,
high,
close,
low,
tickVolume,
//
donchainLength,
//
donOpenUpperBuffer,
donOpenLowerBuffer,
donHighUpperBuffer,
donHighLowerBuffer,
donLowUpperBuffer,
donLowLowerBuffer,
donCloseUpperBuffer,
donCloseLowerBuffer //
);
}
//
-616
View File
@@ -1,616 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XHK
// Description: XHK ...
//
//
// 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 XHK Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XHK"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int xhkSmoothingLength = 14; // Length
input ENUM_X_MA_METHOD xhkSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
input bool xhkIgnoreSmoothingShadows = false; // Ignore Smoothed Bar Shadows
//
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool drawRawXHKCandles = true; // Draw Raw Candle
input bool drawSmoothedXHKCandles = true; // Draw Smoothed Candle
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 10
#property indicator_plots 2
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
// PLOTTED Buffers ...
//
#define openHKBufferIndex 0
double openHKBuffer[];
//
#define highHKBufferIndex 1
double highHKBuffer[];
//
#define lowHKBufferIndex 2
double lowHKBuffer[];
//
#define closeHKBufferIndex 3
double closeHKBuffer[];
//
#define rawHKColorBufferIndex 4
double rawHKColorBuffer[];
//
#define rawHKBufferIndex 0
#property indicator_label1 "X121 XHK Open;X121 XHK High;X121 XHK Low;X121 XHK Close"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 CLR_NONE, clrDodgerBlue, clrDarkGoldenrod
//
// Open ...
#define openBufferIndex 5
double openBuffer[];
//
// High ...
#define highBufferIndex 6
double highBuffer[];
//
// Low ...
#define lowBufferIndex 7
double lowBuffer[];
//
// Close ...
#define closeBufferIndex 8
double closeBuffer[];
//
// Candle Color ...
#define candleColorBufferIndex 9
double candleColorBuffer[];
//
#define candlesBufferIndex 1
#property indicator_label2 "X121 XHKSM Open;X121 XHKSM High;X121 XHKSM Low;X121 XHKSM Close"
#property indicator_type2 DRAW_COLOR_CANDLES
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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;
}
/**
* 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
//
}
/**
* 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);
//
// Fill All Buffers by Zero ...
if (prev_calculated == 0)
{
}
//
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,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result =
//
true
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(0, xhkSmoothingLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// RAW ...
//
// Raw Candles Color ...
ArraySetAsSeries(rawHKColorBuffer, true);
SetIndexBuffer(rawHKColorBufferIndex, rawHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(rawHKBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(rawHKBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openHKBuffer, true);
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highHKBuffer, true);
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeHKBuffer, true);
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowHKBuffer, true);
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
//
// SMOOTHED ...
//
// Candles Color ...
ArraySetAsSeries(candleColorBuffer, true);
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openBuffer, true);
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highBuffer, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeBuffer, true);
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowBuffer, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateXHK(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low //
);
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
lowHKBuffer[barIndex] = 0.0;
openHKBuffer[barIndex] = 0.0;
highHKBuffer[barIndex] = 0.0;
closeHKBuffer[barIndex] = 0.0;
rawHKColorBuffer[barIndex] = hideColorIDX;
//
lowBuffer[barIndex] = 0.0;
openBuffer[barIndex] = 0.0;
highBuffer[barIndex] = 0.0;
closeBuffer[barIndex] = 0.0;
candleColorBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate ATR Zones ...
*
* @param bar_index: 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 ...
*/
void CalculateXHK(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[] //
)
{
//
double mPrevHKOpenValue;
double mPrevHKCloseValue;
//
if (ArraySize(open) <= bar_index + 1)
{
//
mPrevHKOpenValue = 0;
mPrevHKCloseValue = 0;
}
else
{
//
mPrevHKOpenValue = openHKBuffer[bar_index + 1];
mPrevHKCloseValue = closeHKBuffer[bar_index + 1];
}
//
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
//
double candleColorValue =
mHKOpenValue < mHKCloseValue ? bullishColorIDX : bearishColorIDX;
//
// Raw HK Buffers ...
openHKBuffer[bar_index] = mHKOpenValue;
highHKBuffer[bar_index] = mHKHighValue;
lowHKBuffer[bar_index] = mHKLowValue;
closeHKBuffer[bar_index] = mHKCloseValue;
rawHKColorBuffer[bar_index] = drawRawXHKCandles ? candleColorValue : hideColorIDX;
//
// Apply Smoothing ...
bool canSmooth = xhkSmoothingLength > 0 &&
xhkSmoothingMode != X_MA_MODE_NONE;
if (!canSmooth)
{
//
double min = MathMin(mHKOpenValue, mHKCloseValue);
double max = MathMax(mHKOpenValue, mHKCloseValue);
//
openBuffer[bar_index] = mHKOpenValue;
highBuffer[bar_index] = xhkIgnoreSmoothingShadows ? max : mHKHighValue;
lowBuffer[bar_index] = xhkIgnoreSmoothingShadows ? min : mHKLowValue;
closeBuffer[bar_index] = mHKCloseValue;
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
}
else
{
//
// Open ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
openHKBuffer,
openBuffer,
xhkSmoothingMode //
);
//
// Close ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
closeHKBuffer,
closeBuffer,
xhkSmoothingMode //
);
//
// Ignoring Shadows ...
if (!xhkIgnoreSmoothingShadows)
{
//
// High ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
highHKBuffer,
highBuffer,
xhkSmoothingMode //
);
//
// Low ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
lowHKBuffer,
lowBuffer,
xhkSmoothingMode //
);
}
else
{
//
double min = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
double max = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
//
lowBuffer[bar_index] = min;
highBuffer[bar_index] = max;
}
//
// Calculate Smoothed Color ...
candleColorValue =
openBuffer[bar_index] < closeBuffer[bar_index] ? bullishColorIDX : bearishColorIDX;
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
}
}
//
-625
View File
@@ -1,625 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XWZ
// Description: XWZ ...
//
//
// 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 XWZ Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121_XICH"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input ENUM_X_PRICE chikouSpanMode = X_PRICE_CLOSE; // ChikouSpan Mode
input int tenkanSenLength = 9; // TenkanSen Length
input ENUM_X_BOUNDARY_PRICE tenkanSenMode = X_BOUNDARY_PRICE_HIGH_LOW; // TencanSen Mode
input int kijunSenLength = 26; // KijunSen Length
input ENUM_X_BOUNDARY_PRICE kijunSenMode = X_BOUNDARY_PRICE_HIGH_LOW; // KijunSen Mode
input int senkouSpanBLength = 52; // SenkouSpan B Length
input ENUM_X_BOUNDARY_PRICE senkouSpanBMode = X_BOUNDARY_PRICE_HIGH_LOW; // SenkouSpan B Mode
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input bool shiftKumo = true; // Shift Kumo
input bool showTenkanSen = true; // Show TenkanSen
input bool showKijunSen = true; // Show KijunSen
input bool showChikouSpan = true; // Show ChikouSpan
input bool showSenkouSpanA = true; // Show Senkou Span A
input bool showSenkouSpanB = true; // Show Senkou Span B
input bool showKumo = true; // Show Kumo
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 6
//
// Plot Buffers ...
//
#define tenkanSenBufferIndex 0
double tenkanSenBuffer[];
//
#property indicator_label1 "XICH TK"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrBrown
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
#define kijunSenBufferIndex 1
double kijunSenBuffer[];
//
#property indicator_label2 "XICH KJ"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDodgerBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
#define chikouSpanBufferIndex 2
double chikouSpanBuffer[];
//
#property indicator_label3 "XICH CS"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrDarkGreen
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
#define senkouSpanABufferIndex 3
double senkouSpanABuffer[];
//
#property indicator_label4 "XICH SSA"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrLightGray
#property indicator_style4 STYLE_DASHDOTDOT
#property indicator_width4 2
//
#define senkouSpanBBufferIndex 4
double senkouSpanBBuffer[];
//
#property indicator_label5 "XICH SSB"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrLightGray
#property indicator_style5 STYLE_DASHDOTDOT
#property indicator_width5 2
//
#define senkouABufferIndex 5
double senkouABuffer[];
//
#define senkouBBufferIndex 6
double senkouBBuffer[];
//
#define kumoBufferIndex 5
//
#property indicator_label6 "XICH Kumo"
#property indicator_type6 DRAW_FILLING
#property indicator_color6 clrAqua, clrMagenta
#property indicator_style6 STYLE_SOLID
#property indicator_width6 2
//
// Data Buffers ...
//
int mLastBufferIndex = 6;
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
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();
IndicatorSetInteger(INDICATOR_DIGITS, 2);
//
// 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
}
/**
* 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);
//
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,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
kijunSenLength > 0 &&
tenkanSenLength > 0 &&
senkouSpanBLength > 0 &&
IsValid(kijunSenMode) &&
IsValid(tenkanSenMode) &&
IsValid(chikouSpanMode) &&
IsValid(senkouSpanBMode)
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(kijunSenLength, tenkanSenLength);
result = MathMax(result, senkouSpanBLength);
//
return result;
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(tenkanSenBuffer, true);
SetIndexBuffer(tenkanSenBufferIndex, tenkanSenBuffer, INDICATOR_DATA);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_SHOW_DATA, showTenkanSen);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_TYPE, tenkanSenDrawType);
//
ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(kijunSenBuffer, true);
SetIndexBuffer(kijunSenBufferIndex, kijunSenBuffer, INDICATOR_DATA);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_SHOW_DATA, showKijunSen);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_TYPE, kijunSenDrawType);
//
ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(chikouSpanBuffer, true);
SetIndexBuffer(chikouSpanBufferIndex, chikouSpanBuffer, INDICATOR_DATA);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHIFT, -kijunSenLength);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHOW_DATA, showChikouSpan);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_TYPE, chikouSpanDrawType);
//
int shiftSize = shiftKumo ? kijunSenLength : 0;
//
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(senkouSpanABuffer, true);
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
//
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(senkouSpanBBuffer, true);
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
//
ArraySetAsSeries(senkouABuffer, true);
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
ArraySetAsSeries(senkouBBuffer, true);
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE;
//
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(kumoBufferIndex, PLOT_DRAW_TYPE, kumoDrawType);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateValues(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
senkouABuffer[barIndex] = 0;
senkouBBuffer[barIndex] = 0;
kijunSenBuffer[barIndex] = 0;
tenkanSenBuffer[barIndex] = 0;
chikouSpanBuffer[barIndex] = 0;
senkouSpanABuffer[barIndex] = 0;
senkouSpanBBuffer[barIndex] = 0;
}
/**
* Calculate Vales ...
*
* @param bar_index: 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 CalculateValues(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double uppers[];
double lowers[];
//
double uppersMax = 0;
double uppersMin = 0;
//
double lowersMax = 0;
double lowersMin = 0;
//
// Calculate ChikouSpan ...
double iChikouSpan = GetAppliedPrice(
_Symbol,
_Period,
bar_index,
chikouSpanMode //
);
//
// Calculate TenkanSen ...
GetPriceBoundary(
uppers,
lowers,
_Symbol,
_Period,
tenkanSenMode,
tenkanSenLength,
bar_index //
);
//
uppersMax = uppers[ArrayMaximum(uppers)];
uppersMin = uppers[ArrayMinimum(uppers)];
//
lowersMax = lowers[ArrayMaximum(lowers)];
lowersMin = lowers[ArrayMinimum(lowers)];
//
double iTenkanSen = (uppersMax + lowersMin) / 2;
//
// Calculate KijunSen ...
GetPriceBoundary(
uppers,
lowers,
_Symbol,
_Period,
kijunSenMode,
kijunSenLength,
bar_index //
);
//
uppersMax = uppers[ArrayMaximum(uppers)];
uppersMin = uppers[ArrayMinimum(uppers)];
//
lowersMax = lowers[ArrayMaximum(lowers)];
lowersMin = lowers[ArrayMinimum(lowers)];
//
double iKijunSen = (uppersMax + lowersMin) / 2;
//
// Calculate SenkouSpanB ...
GetPriceBoundary(
uppers,
lowers,
_Symbol,
_Period,
senkouSpanBMode,
senkouSpanBLength,
bar_index //
);
//
uppersMax = uppers[ArrayMaximum(uppers)];
uppersMin = uppers[ArrayMinimum(uppers)];
//
lowersMax = lowers[ArrayMaximum(lowers)];
lowersMin = lowers[ArrayMinimum(lowers)];
//
double iSenkouSpanB = (uppersMax + lowersMin) / 2;
//
// Calculate SenkouSpanA ...
double iSenkouSpanA = (iTenkanSen + iKijunSen) / 2;
//
// Setting Buffers ...
kijunSenBuffer[bar_index] = iKijunSen;
senkouABuffer[bar_index] = iSenkouSpanA;
senkouBBuffer[bar_index] = iSenkouSpanB;
tenkanSenBuffer[bar_index] = iTenkanSen;
chikouSpanBuffer[bar_index] = iChikouSpan;
senkouSpanABuffer[bar_index] = iSenkouSpanA;
senkouSpanBBuffer[bar_index] = iSenkouSpanB;
}
//
-574
View File
@@ -1,574 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XMAS
// Description: XMAS ...
//
//
// 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 XMAS Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121_XMAS"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int length = 14; // MA Length
input ENUM_MA_METHOD method = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH; // Upper Applied To
input ENUM_APPLIED_PRICE midAppliedTo = PRICE_MEDIAN; // Mid Applied To
input ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW; // Lower Applied To
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input bool showUpper = true; // Show Upper
input bool showMid = true; // Show Mid
input bool showLower = true; // Show Lower
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 3
//
// Plot Buffers ...
//
// UPPER ...
#define upperBufferIndex 0
double upperBuffer[];
//
#property indicator_label1 "X121 MASU"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// MID ...
#define midBufferIndex 1
double midBuffer[];
//
#property indicator_label2 "X121 MASM"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrLightBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// LOWER ...
#define lowerBufferIndex 2
double lowerBuffer[];
//
#property indicator_label3 "X121 MASL"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrMagenta
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//
// Data Buffers ...
//
int mLastBufferIndex = 2;
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
int upperHandler = INVALID_HANDLE;
int midHandler = INVALID_HANDLE;
int lowerHandler = INVALID_HANDLE;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// Upper ...
upperHandler = iMA(
_Symbol,
_Period,
length,
0,
method,
upperAppliedTo //
);
bool isInited = upperHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Mid ...
midHandler = iMA(
_Symbol,
_Period,
length,
0,
method,
midAppliedTo //
);
isInited = midHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Lower ...
lowerHandler = iMA(
_Symbol,
_Period,
length,
0,
method,
lowerAppliedTo //
);
isInited = lowerHandler != INVALID_HANDLE;
if (!isInited)
{
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();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
IndicatorSetInteger(INDICATOR_DIGITS, 2);
//
// 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
//
IndicatorRelease(upperHandler);
IndicatorRelease(midHandler);
IndicatorRelease(lowerHandler);
}
/**
* 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 ...
//
// Upper ...
int upperCalculatedBars = BarsCalculated(upperHandler);
//
// Mid ...
int midCalculatedBars = BarsCalculated(midHandler);
//
// Lower ...
int lowerCalculatedBars = BarsCalculated(lowerHandler);
//
bool isPassedRequiredCalculatedBars =
//
// Upper ...
upperCalculatedBars >= maxLength &&
//
// Mid ...
midCalculatedBars >= maxLength &&
//
// Lower ...
lowerCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// Upper ...
int copiedUppers = CopyBuffer(upperHandler, 0, 0, limit, upperBuffer);
//
// Mid ...
int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer);
//
// Lower ...
int copiedLowers = CopyBuffer(lowerHandler, 0, 0, limit, lowerBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// Upper ...
copiedUppers > 0 &&
//
// Mid ...
copiedMids > 0 &&
//
// Lower ...
copiedLowers > 0
//
;
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;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result = length > 0;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(result, length);
//
return result;
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Upper ...
//
ENUM_DRAW_TYPE upperDrawType = showUpper ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(upperBuffer, true);
SetIndexBuffer(upperBufferIndex, upperBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(upperBufferIndex, PLOT_SHOW_DATA, showUpper);
PlotIndexSetInteger(upperBufferIndex, PLOT_DRAW_TYPE, upperDrawType);
//
PlotIndexSetDouble(upperBufferIndex, PLOT_EMPTY_VALUE, 0);
//
// Mid ...
//
ENUM_DRAW_TYPE midDrawType = showMid ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(midBuffer, true);
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, showMid);
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType);
//
PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0);
//
// Lower ...
//
ENUM_DRAW_TYPE lowerDrawType = showLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(lowerBuffer, true);
SetIndexBuffer(lowerBufferIndex, lowerBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lowerBufferIndex, PLOT_SHOW_DATA, showLower);
PlotIndexSetInteger(lowerBufferIndex, PLOT_DRAW_TYPE, lowerDrawType);
//
PlotIndexSetDouble(lowerBufferIndex, PLOT_EMPTY_VALUE, 0);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateValues(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
upperBuffer[barIndex] = 0;
midBuffer[barIndex] = 0;
lowerBuffer[barIndex] = 0;
}
/**
* Calculate Vales ...
*
* @param bar_index: 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 CalculateValues(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Implement Colorify Mechanism ...
}
//
File diff suppressed because it is too large Load Diff
-812
View File
@@ -1,812 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XSTR
// Description: XSTR ...
//
//
// 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 XSTR Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XSTR"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int strLength = 14; // Length
input double strMultiplier = 3; // Multiplier
input int vidyaLength = 14; // Smothing Length
input ENUM_MA_METHOD strBoundaryMode = MODE_SMA; // Boundary Mode
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
input ENUM_APPLIED_PRICE vidyaAppliedTo = PRICE_CLOSE; // Smoothing Applied To
//
input group "Presentation";
input bool showStr = true; // Show Str
input bool showVidya = true; // Show Vidya
input bool showStrUpper = true; // Show Str Upper
input bool showStrLower = true; // Show Str Lower
input bool showStrLowMa = true; // Show Low Smoothed Buffer
input bool showStrHighMa = true; // Show High Smoothed Buffer
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#define emptyValue 0.0
//
#property indicator_chart_window
//
#property indicator_buffers 10
#property indicator_plots 6
//
// STR ...
#define strBufferIndex 0
double strBuffer[];
#define strColorBufferIndex 1
double strColorBuffer[];
//
#define strPlotBufferIndex 0
#property indicator_label1 "X121 STR"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// Up ...
#define strUpBufferIndex 2
double strUpBuffer[];
//
#define strUpPlotBufferIndex 1
#property indicator_label2 "X121 STR U"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrBlueViolet
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// Down ...
#define strDownBufferIndex 3
double strDownBuffer[];
//
#define strDownPlotBufferIndex 2
#property indicator_label3 "X121 STR D"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrBlueViolet
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//
// High MA ...
#define strHighMaBufferIndex 4
double strHighMaBuffer[];
//
#define strHighMaPlotBufferIndex 3
#property indicator_label4 "X121 STR HSM"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrAqua
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//
// Low Ma ...
#define strLowMaBufferIndex 5
double strLowMaBuffer[];
//
#define strLowMaPlotBufferIndex 4
#property indicator_label5 "X121 STR LSM"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrMagenta
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//
// VIDYA ...
#define vidyaBufferIndex 6
double vidyaBuffer[];
//
#define vidyaPlotBufferIndex 5
#property indicator_label6 "X121 VIDYA"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrYellow
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//
// Data Buffers ...
//
int mLastBufferIndex = 6;
//
// STR ...
//
// Atr ...
#define atrBufferIndex mLastBufferIndex + 1
double atrBuffer[];
//
// Price ...
#define strPriceBufferIndex mLastBufferIndex + 2
double strPriceBuffer[];
//
// Trend ...
#define strStateBufferIndex mLastBufferIndex + 3
double strStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// ATR Handler ...
int atrHandler = INVALID_HANDLE;
//
// MA Handler ...
int lowMaHandler = INVALID_HANDLE;
int highMaHandler = INVALID_HANDLE;
int vidyaHandler = INVALID_HANDLE;
//
bool isStrTrendChanged;
bool isStrStartBearishTrend;
bool isStrStartBullishTrend;
//
int changeOfTrend;
int startBearishTrend;
int startBullishTrend;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
strLength //
);
bool isInited = atrHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Low Ma ...
lowMaHandler = iMA(
_Symbol,
_Period,
strLength,
0,
strBoundaryMode,
PRICE_LOW //
);
isInited = lowMaHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// High Ma ...
highMaHandler = iMA(
_Symbol,
_Period,
strLength,
0,
strBoundaryMode,
PRICE_HIGH //
);
isInited = highMaHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Vidya ...
vidyaHandler = iVIDyA(
_Symbol,
_Period,
strLength,
vidyaLength,
0, // Shift ...
vidyaAppliedTo //
);
isInited = vidyaHandler != INVALID_HANDLE;
if (!isInited)
{
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();
//
// 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
//
IndicatorRelease(atrHandler);
IndicatorRelease(vidyaHandler);
IndicatorRelease(lowMaHandler);
IndicatorRelease(highMaHandler);
}
/**
* 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 ...
//
// Validate Calculated Bars ...
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
// VIDYA ...
int vidyaCalculatedBars = BarsCalculated(vidyaHandler);
//
// Low Ma ...
int lowMaCalculatedBars = BarsCalculated(lowMaHandler);
//
// High Ma ...
int highMaCalculatedBars = BarsCalculated(highMaHandler);
//
bool isPassedRequiredCalculatedBars =
//
// ATR ...
atrCalculatedBars >= 0 &&
//
// VIDYA ...
vidyaCalculatedBars >= 0 &&
//
// Low Ma ...
lowMaCalculatedBars >= 0 &&
//
// High Ma ...
highMaCalculatedBars >= 0
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
//
// checking for the limit start of calculation of an indicator ...
limit =
(prev_calculated > rates_total || prev_calculated <= 0)
? maxLength
: prev_calculated - 1;
//
// Buffers Copy ...
//
// ATR ...
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, rates_total, atrBuffer);
//
// VYDIA ...
int copiedVidyas = CopyBuffer(vidyaHandler, 0, 0, rates_total, vidyaBuffer);
//
// Low Ma ...
int copiedLowMas = CopyBuffer(lowMaHandler, 0, 0, rates_total, strLowMaBuffer);
//
// High Ma ...
int copiedHighMas = CopyBuffer(highMaHandler, 0, 0, rates_total, strHighMaBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// ATR ...
copiedAtrs >= 0 &&
//
// VIDYA ...
copiedVidyas >= 0 &&
//
// Low Ma ...
copiedLowMas >= 0 &&
//
// Hig Ma ...
copiedHighMas >= 0
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result =
//
// STR ...
strLength > 0 &&
strMultiplier > 0
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(1, strLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// STR ...
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
//
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
//
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
//
ENUM_DRAW_TYPE strLowMaDrawType = showStrLowMa ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strLowMaBufferIndex, strLowMaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strLowMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_SHOW_DATA, showStrLowMa);
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_DRAW_TYPE, strLowMaDrawType);
//
ENUM_DRAW_TYPE strHighMaDrawType = showStrHighMa ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strHighMaBufferIndex, strHighMaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strHighMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_SHOW_DATA, showStrHighMa);
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_DRAW_TYPE, strHighMaDrawType);
//
ENUM_DRAW_TYPE vidyaDrawType = showVidya ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(vidyaBufferIndex, vidyaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(vidyaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(vidyaPlotBufferIndex, PLOT_SHOW_DATA, showVidya);
PlotIndexSetInteger(vidyaPlotBufferIndex, PLOT_DRAW_TYPE, vidyaDrawType);
//
// Data Buffers ...
//
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
CalculateStr(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low //
);
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
// STR ...
strBuffer[barIndex] = emptyValue;
strUpBuffer[barIndex] = emptyValue;
strDownBuffer[barIndex] = emptyValue;
strPriceBuffer[barIndex] = emptyValue;
strLowMaBuffer[barIndex] = emptyValue;
strHighMaBuffer[barIndex] = emptyValue;
//
strColorBuffer[barIndex] = hideColorIDX;
strStateBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate STR ...
*
* @param bar_index: 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 ...
*/
void CalculateStr(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[] //
)
{
//
// Calculated Price ...
ENUM_X_PRICE mPType = ToXPrice(strAppliedTo);
double price = GetAppliedPrice(
mPType,
open,
high,
low,
close,
bar_index //
);
strPriceBuffer[bar_index] = price;
//
double atr = atrBuffer[bar_index];
//
// Up ...
strUpBuffer[bar_index] = price + (strMultiplier * atr);
//
// Down ...
strDownBuffer[bar_index] = price - (strMultiplier * atr);
//
if (close[bar_index] > strUpBuffer[bar_index - 1])
{
//
strStateBuffer[bar_index] = 1;
if (strStateBuffer[bar_index - 1] == -1)
{
changeOfTrend = 1;
}
}
else if (close[bar_index] < strDownBuffer[bar_index - 1])
{
//
strStateBuffer[bar_index] = -1;
if (strStateBuffer[bar_index - 1] == 1)
{
changeOfTrend = 1;
}
}
else if (strStateBuffer[bar_index - 1] == 1)
{
//
strStateBuffer[bar_index] = 1;
changeOfTrend = 0;
}
else if (strStateBuffer[bar_index - 1] == -1)
{
//
strStateBuffer[bar_index] = -1;
changeOfTrend = 0;
}
//
// Down Trend Starting ...
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
{
startBearishTrend = 1;
}
else
{
startBearishTrend = 0;
}
//
// Up Trend Starting ...
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
{
startBullishTrend = 1;
}
else
{
startBullishTrend = 0;
}
//
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
{
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
}
//
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
{
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
}
//
if (startBearishTrend == 1)
{
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
}
//
if (startBullishTrend == 1)
{
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
}
//
// Draw the indicator ...
//
double colorIDX = hideColorIDX;
strColorBuffer[bar_index] = colorIDX;
//
if (strStateBuffer[bar_index] == 1)
{
//
strBuffer[bar_index] = strDownBuffer[bar_index];
if (changeOfTrend == 1)
{
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
changeOfTrend = 0;
}
//
colorIDX = bullishColorIDX;
}
else if (strStateBuffer[bar_index] == -1)
{
//
strBuffer[bar_index] = strUpBuffer[bar_index];
if (changeOfTrend == 1)
{
//
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
changeOfTrend = 0;
}
//
colorIDX = bearishColorIDX;
}
//
if (showStr)
{
strColorBuffer[bar_index] = colorIDX;
}
//
// Str Mid ...
//
double iStrMid = strDownBuffer[bar_index] + ((strUpBuffer[bar_index] - strDownBuffer[bar_index]) / 2);
//
}
//
-701
View File
@@ -1,701 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XTREND
// Description: XTREND ...
//
//
// 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 XTREND Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XTREND"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input ENUM_APPLIED_PRICE trendPriceType = PRICE_CLOSE; // Detect Trend Price Type
input group "MA Detection";
input int maLength = 50; // MA Length
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input group "ADX Detection";
input int adxLength = 14; // ADX Length
input double adxThreshold = 25; // ADX Threshold for Strong Trends
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input int upTrendArrowCode = 233; // Up Trend Arrow Code
input int downTrendArrowCode = 234; // Down Trend Arrow Code
//
input bool showOnlyTrendStart = true; // Show Only Trend Start
input bool showUpTrend = true; // Show Up Trend
input bool showDownTrend = true; // Show Down Trend
//
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 2
//
// Plot Buffers ...
//
#define upTrendBufferIndex 0
double upTrendBuffer[];
//
#property indicator_label1 "X121 XTREND Up"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrAqua
#property indicator_width1 1
//
#define downTrendBufferIndex 1
double downTrendBuffer[];
//
#property indicator_label2 "X121 XTREND Down"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta
#property indicator_width2 1
//
// Data Buffers ...
//
int mLastBufferIndex = 1;
//
#define maBufferIndex mLastBufferIndex + 1
double maBuffer[];
//
#define adxBufferIndex mLastBufferIndex + 2
double adxBuffer[];
//
#define adxPBufferIndex mLastBufferIndex + 3
double adxPBuffer[];
//
#define adxMBufferIndex mLastBufferIndex + 4
double adxMBuffer[];
//
#define upTBufferIndex mLastBufferIndex + 5
double upTBuffer[];
//
#define downTBufferIndex mLastBufferIndex + 6
double downTBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
double lastValue = 0;
ENUM_X_DIRECTION lastTrendDir = X_DIRECTION_NONE;
//
// MA Handler ...
int maHandler = INVALID_HANDLE;
//
// ADX Handler ...
int adxHandler = INVALID_HANDLE;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// MA ...
maHandler = iMA(
_Symbol,
_Period,
maLength,
0,
maMethod,
maAppliedTo //
);
bool isInited = maHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// ADx ...
adxHandler = iADX(
_Symbol,
_Period,
adxLength //
);
isInited = maHandler != INVALID_HANDLE;
if (!isInited)
{
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();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
IndicatorSetInteger(INDICATOR_DIGITS, 2);
//
// 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
//
IndicatorRelease(maHandler);
IndicatorRelease(adxHandler);
}
/**
* 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 maCalculatedBars = BarsCalculated(maHandler);
//
// ADX ...
int adxCalculatedBars = BarsCalculated(adxHandler);
//
bool isPassedRequiredCalculatedBars =
//
// MA ...
maCalculatedBars >= maxLength &&
//
// ADX ...
adxCalculatedBars >= 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 copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
//
// ADX ...
int copiedAdxs = CopyBuffer(adxHandler, MAIN_LINE, 0, limit, adxBuffer);
int copiedAdxPs = CopyBuffer(adxHandler, PLUSDI_LINE, 0, limit, adxPBuffer);
int copiedAdxMs = CopyBuffer(adxHandler, MINUSDI_LINE, 0, limit, adxMBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// MA ...
copiedMas > 0 &&
//
// ADX ...
copiedAdxs > 0 &&
copiedAdxPs > 0 &&
copiedAdxMs > 0
//
;
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;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
// MA ...
maLength > 0 &&
//
// ADX ...
adxLength > 0 &&
adxThreshold > 0
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(maLength, adxLength);
//
return result;
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// UP Trend ...
//
ENUM_DRAW_TYPE upTrendDrawType = showUpTrend ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(upTrendBuffer, true);
SetIndexBuffer(upTrendBufferIndex, upTrendBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(upTrendBufferIndex, PLOT_SHOW_DATA, showUpTrend);
PlotIndexSetInteger(upTrendBufferIndex, PLOT_DRAW_TYPE, upTrendDrawType);
//
PlotIndexSetDouble(upTrendBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(upTrendBufferIndex, PLOT_ARROW, upTrendArrowCode);
//
// DOWN Trend ...
//
ENUM_DRAW_TYPE downTrendDrawType = showDownTrend ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(downTrendBuffer, true);
SetIndexBuffer(downTrendBufferIndex, downTrendBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(downTrendBufferIndex, PLOT_SHOW_DATA, showDownTrend);
PlotIndexSetInteger(downTrendBufferIndex, PLOT_DRAW_TYPE, downTrendDrawType);
//
PlotIndexSetDouble(downTrendBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(downTrendBufferIndex, PLOT_ARROW, downTrendArrowCode);
//
// Data Buffers ...
//
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(adxBuffer, true);
SetIndexBuffer(adxBufferIndex, adxBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(adxPBuffer, true);
SetIndexBuffer(adxPBufferIndex, adxPBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(adxMBuffer, true);
SetIndexBuffer(adxMBufferIndex, adxMBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(upTBuffer, true);
SetIndexBuffer(upTBufferIndex, upTBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(downTBuffer, true);
SetIndexBuffer(downTBufferIndex, downTBuffer, INDICATOR_CALCULATIONS);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateTrend(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
upTrendBuffer[barIndex] = 0;
downTrendBuffer[barIndex] = 0;
//
maBuffer[barIndex] = 0;
adxBuffer[barIndex] = 0;
adxPBuffer[barIndex] = 0;
adxMBuffer[barIndex] = 0;
}
/**
* Calculate Trends ...
*
* @param bar_index: 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 CalculateTrend(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
ENUM_X_PRICE mPType = ToXPrice(trendPriceType);
double iPrice = GetAppliedPrice(
mPType,
open,
high,
low,
close,
bar_index //
);
//
double iMa = maBuffer[bar_index];
double iAdx = adxBuffer[bar_index];
double points = GetPoints(_Symbol);
double points10 = 10 * points;
//
bool isUpTrend =
iPrice > iMa &&
iAdx > adxThreshold;
bool isDownTrend =
iPrice < iMa &&
iAdx > adxThreshold;
//
if (isUpTrend)
{
//
// double iLastValue =
// prevCalculated <= 0
// ? 0
// : upTrendBuffer[bar_index + 1];
// if (iLastValue > 0 &&
// iValue > iLastValue)
// {
// iValue = iLastValue;
// }
//
double selectedValue = low[bar_index] - points10;
//
double iValue =
!IsBullish(lastTrendDir) ? selectedValue
: !showOnlyTrendStart
? lastValue
: 0;
//
upTrendBuffer[bar_index] = iValue;
upTBuffer[bar_index] = selectedValue;
//
downTrendBuffer[bar_index] = 0;
//
lastValue = iValue;
lastTrendDir = X_DIRECTION_BULLISH;
}
else if (isDownTrend)
{
//
// double iLastValue =
// prevCalculated <= 0
// ? 0
// : downTrendBuffer[bar_index + 1];
// if (iLastValue > 0 &&
// iValue < iLastValue)
// {
// iValue = iLastValue;
// }
//
double selectedValue = high[bar_index] + points10;
//
double iValue =
!IsBearish(lastTrendDir) ? selectedValue
: !showOnlyTrendStart
? lastValue
: 0;
//
upTrendBuffer[bar_index] = 0;
downTrendBuffer[bar_index] = iValue;
downTBuffer[bar_index] = selectedValue;
//
lastValue = iValue;
lastTrendDir = X_DIRECTION_BEARISH;
}
else
{
//
double iValue =
IsBullish(lastTrendDir)
? showOnlyTrendStart
? 0
: lastValue
: IsBearish(lastTrendDir)
? showOnlyTrendStart
? 0
: lastValue
: 0;
//
upTrendBuffer[bar_index] = 0;
downTrendBuffer[bar_index] = 0;
//
upTBuffer[bar_index] = 0;
downTBuffer[bar_index] = 0;
//
lastValue = 0;
lastTrendDir = X_DIRECTION_NONE;
}
}
-544
View File
@@ -1,544 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Ocillator
// -------------------------------------------------
// Name: X121 XVolume
// Description: Detect Bullish/Bearish Volumes ...
//
//
// 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 XVolume Ocillator"
#property strict
//
// Definitions ...
//
#define ShortName "X121_XVOLUME"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Makret ...
input group "Market";
input int maLength = 14; // Moving Averge Length
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
//
// Presentation ...
input group "Presentation";
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input bool showBullishVolume = true; // Show Bullish Volume
input bool showBullishVolumeMa = true; // Show Bullish Volume Moving Average
input bool showBearishVolume = true; // Show Bearish Volume
input bool showBearishVolumeMa = true; // Show Bearish Volume Moving Average
//
// Buffers Props ...
//
#property indicator_separate_window
//
#property indicator_buffers 6
#property indicator_plots 4
//
// Buffers ...
//
#define bullishVolumeBufferIndex 0
double bullishVolumeBuffer[];
#property indicator_label1 "Bullish Volume"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrLime
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
#define bullishVolumeMaBufferIndex 1
double bullishVolumeMaBuffer[];
#property indicator_label2 "Bullish Volume MA"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrLime
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
#define bearishVolumeBufferIndex 2
double bearishVolumeBuffer[];
#property indicator_label3 "Bearish Volume"
#property indicator_type3 DRAW_HISTOGRAM
#property indicator_color3 clrRed
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define bearishVolumeMaBufferIndex 3
double bearishVolumeMaBuffer[];
#property indicator_label4 "Bearish Volume MA"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrRed
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//
// Data Buffers ...
#define mLastBufferIndex 3
//
#define rawBullishVolumeBufferIndex mLastBufferIndex + 1
double rawBullishVolumeBuffer[];
//
#define rawBearishVolumeBufferIndex mLastBufferIndex + 2
double rawBearishVolumeBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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();
IndicatorSetInteger(INDICATOR_DIGITS, 2);
//
// 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
}
/**
* 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);
//
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,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result = maLength > 0 &&
IsValid(maMethod);
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(0, maLength);
//
return result;
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Bullish ...
//
// Volume ...
ENUM_DRAW_TYPE bullishVolumeDrawType = showBullishVolume ? DRAW_HISTOGRAM : DRAW_NONE;
//
ArraySetAsSeries(bullishVolumeBuffer, true);
SetIndexBuffer(bullishVolumeBufferIndex, bullishVolumeBuffer, INDICATOR_DATA);
PlotIndexSetDouble(bullishVolumeBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(bullishVolumeBufferIndex, PLOT_SHOW_DATA, showBullishVolume);
PlotIndexSetInteger(bullishVolumeBufferIndex, PLOT_DRAW_TYPE, bullishVolumeDrawType);
//
// Average ...
ENUM_DRAW_TYPE bullishVolumeMaDrawType = showBullishVolumeMa ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(bullishVolumeMaBuffer, true);
SetIndexBuffer(bullishVolumeMaBufferIndex, bullishVolumeMaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(bullishVolumeMaBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(bullishVolumeMaBufferIndex, PLOT_SHOW_DATA, showBullishVolumeMa);
PlotIndexSetInteger(bullishVolumeMaBufferIndex, PLOT_DRAW_TYPE, bullishVolumeMaDrawType);
//
// Bearish ...
//
// Volume ...
ENUM_DRAW_TYPE bearishVolumeDrawType = showBearishVolume ? DRAW_HISTOGRAM : DRAW_NONE;
//
ArraySetAsSeries(bearishVolumeBuffer, true);
SetIndexBuffer(bearishVolumeBufferIndex, bearishVolumeBuffer, INDICATOR_DATA);
PlotIndexSetDouble(bearishVolumeBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(bearishVolumeBufferIndex, PLOT_SHOW_DATA, showBearishVolume);
PlotIndexSetInteger(bearishVolumeBufferIndex, PLOT_DRAW_TYPE, bearishVolumeDrawType);
//
// Average ...
ENUM_DRAW_TYPE bearishVolumeMaDrawType = showBearishVolumeMa ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(bearishVolumeMaBuffer, true);
SetIndexBuffer(bearishVolumeMaBufferIndex, bearishVolumeMaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(bearishVolumeMaBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(bearishVolumeMaBufferIndex, PLOT_SHOW_DATA, showBearishVolumeMa);
PlotIndexSetInteger(bearishVolumeMaBufferIndex, PLOT_DRAW_TYPE, bearishVolumeMaDrawType);
//
// Data Buffers ...
//
ArraySetAsSeries(rawBullishVolumeBuffer, true);
SetIndexBuffer(rawBullishVolumeBufferIndex, rawBullishVolumeBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(rawBearishVolumeBuffer, true);
SetIndexBuffer(rawBearishVolumeBufferIndex, rawBearishVolumeBuffer, INDICATOR_CALCULATIONS);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateValues(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
bullishVolumeBuffer[barIndex] = EMPTY_VALUE;
bullishVolumeMaBuffer[barIndex] = EMPTY_VALUE;
rawBullishVolumeBuffer[barIndex] = 0;
//
bearishVolumeBuffer[barIndex] = EMPTY_VALUE;
bearishVolumeMaBuffer[barIndex] = EMPTY_VALUE;
rawBearishVolumeBuffer[barIndex] = 0;
}
/**
* Calculate Vales ...
*
* @param bar_index: 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 CalculateValues(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
XOHCL bar;
bool has = bar.Init(
_Symbol,
_Period,
bar_index //
);
if (!has)
{
return;
}
//
double iBullishVolume = 0;
double iBearishVolume = 0;
//
if (bar.IsBullish())
{
//
iBullishVolume = (double)bar.volume;
iBearishVolume = 0;
}
else if (bar.IsBearish())
{
//
iBearishVolume = (double)bar.volume;
iBullishVolume = 0;
}
else
{
//
double volume = ((double)bar.volume) / 2.0;
iBullishVolume = volume;
iBearishVolume = volume;
}
//
bullishVolumeBuffer[bar_index] =
iBullishVolume == 0
? EMPTY_VALUE
: iBullishVolume;
rawBullishVolumeBuffer[bar_index] = iBullishVolume;
//
bearishVolumeBuffer[bar_index] =
iBearishVolume == 0
? EMPTY_VALUE
: iBearishVolume;
rawBearishVolumeBuffer[bar_index] = iBearishVolume;
//
// Calculate Moving Averages ...
//
int bullishMAsCount = iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
maLength,
rawBullishVolumeBuffer,
bullishVolumeMaBuffer,
maMethod //
);
//
int bearishMAsCount = iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
maLength,
rawBearishVolumeBuffer,
bearishVolumeMaBuffer,
maMethod //
);
//
bar.Clean();
}
//
-712
View File
@@ -1,712 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XVWAP
// Description: XVWAP ...
//
//
// 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 XVWAP Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XVWAP"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int vwapFastLength = 20; // Fast Length
input int vwapMidLength = 40; // Mid Length
input int vwapSlowLength = 60; // Slow Length
input ENUM_APPLIED_PRICE vwapAppliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showVWapFast = true; // Show VWap Fast
input bool showVWapMedium = true; // Show VWap Medium
input bool showVWapSlow = true; // Show VWap Slow
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 11
#property indicator_plots 3
//
// Plot Buffers ...
//
// FAST ...
#define vwapFastBufferIndex 0
double vwapFastBuffer[];
#define vwapFastColorBufferIndex 1
double vwapFastColorBuffer[];
//
#define vwapFastPlotBufferIndex 0
#property indicator_label1 "X121 VWF"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// MID ...
#define vwapMidBufferIndex 2
double vwapMidBuffer[];
#define vwapMidColorBufferIndex 3
double vwapMidColorBuffer[];
//
#define vwapMidPlotBufferIndex 1
#property indicator_label2 "X121 VWM"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
// SLOW ...
#define vwapSlowBufferIndex 4
double vwapSlowBuffer[];
#define vwapSlowColorBufferIndex 5
double vwapSlowColorBuffer[];
//
#define vwapSlowPlotBufferIndex 2
#property indicator_label3 "X121 VWS"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// Data Buffers ...
//
int mLastBufferIndex = 5;
//
// Volume ...
#define vwapVolumeBufferIndex mLastBufferIndex + 1
double vwapVolumeBuffer[];
//
// Price ...
#define vwapPriceBufferIndex mLastBufferIndex + 2
double vwapPriceBuffer[];
//
// Fast State ...
#define vwapFastStateBufferIndex mLastBufferIndex + 3
double vwapFastStateBuffer[];
//
// Mid State ...
#define vwapMidStateBufferIndex mLastBufferIndex + 4
double vwapMidStateBuffer[];
//
// Slow State ...
#define vwapSlowStateBufferIndex mLastBufferIndex + 5
double vwapSlowStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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;
}
/**
* 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
}
/**
* 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 ...
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// 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;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
vwapFastLength > 2 &&
vwapMidLength > vwapFastLength &&
vwapSlowLength > vwapMidLength
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// XVWAP ...
result = MathMax(result, vwapFastLength);
result = MathMax(result, vwapMidLength);
result = MathMax(result, vwapSlowLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Fast ...
ArraySetAsSeries(vwapFastBuffer, true);
ArraySetAsSeries(vwapFastColorBuffer, true);
SetIndexBuffer(vwapFastBufferIndex, vwapFastBuffer, INDICATOR_DATA);
SetIndexBuffer(vwapFastColorBufferIndex, vwapFastColorBuffer, INDICATOR_COLOR_INDEX);
//
// Mid ...
ArraySetAsSeries(vwapMidBuffer, true);
ArraySetAsSeries(vwapMidColorBuffer, true);
SetIndexBuffer(vwapMidBufferIndex, vwapMidBuffer, INDICATOR_DATA);
SetIndexBuffer(vwapMidColorBufferIndex, vwapMidColorBuffer, INDICATOR_COLOR_INDEX);
//
// Slow ...
ArraySetAsSeries(vwapSlowBuffer, true);
ArraySetAsSeries(vwapSlowColorBuffer, true);
SetIndexBuffer(vwapSlowBufferIndex, vwapSlowBuffer, INDICATOR_DATA);
SetIndexBuffer(vwapSlowColorBufferIndex, vwapSlowColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// Volumes ...
ArraySetAsSeries(vwapVolumeBuffer, true);
SetIndexBuffer(vwapVolumeBufferIndex, vwapVolumeBuffer, INDICATOR_CALCULATIONS);
//
// Price ...
ArraySetAsSeries(vwapPriceBuffer, true);
SetIndexBuffer(vwapPriceBufferIndex, vwapPriceBuffer, INDICATOR_CALCULATIONS);
//
// Fast State ...
ArraySetAsSeries(vwapFastStateBuffer, true);
SetIndexBuffer(vwapFastStateBufferIndex, vwapFastStateBuffer, INDICATOR_CALCULATIONS);
//
// Mid State ...
ArraySetAsSeries(vwapMidStateBuffer, true);
SetIndexBuffer(vwapMidStateBufferIndex, vwapMidStateBuffer, INDICATOR_CALCULATIONS);
//
// Slow State ...
ArraySetAsSeries(vwapSlowStateBuffer, true);
SetIndexBuffer(vwapSlowStateBufferIndex, vwapSlowStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: 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 bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
// Calculate Required VWAP Data Buffers ...
if (ratesTotal - bar_index <= maxLength)
{
//
CalculateVWAPDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Prevent Moving Forward ...
}
else
{
//
CalculateVWAPDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
CalculateVWAPS(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
vwapFastBuffer[barIndex] = EMPTY_VALUE;
vwapMidBuffer[barIndex] = EMPTY_VALUE;
vwapSlowBuffer[barIndex] = EMPTY_VALUE;
vwapVolumeBuffer[barIndex] = EMPTY_VALUE;
vwapPriceBuffer[barIndex] = EMPTY_VALUE;
//
vwapFastColorBuffer[barIndex] = hideColorIDX;
vwapMidColorBuffer[barIndex] = hideColorIDX;
vwapSlowColorBuffer[barIndex] = hideColorIDX;
vwapFastStateBuffer[barIndex] = hideColorIDX;
vwapMidStateBuffer[barIndex] = hideColorIDX;
vwapSlowStateBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate VWAP Value for Specified Bar ...
*
* @param bar_index: 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 ...
* @param _length: Integer, Specified VWAP Length ...
* @param _show: Boolean, Specified Show Buffer or not ...
* @param _buffer: Double Array Reference, Points to Buffer ...
* @param _colorBuffer: Double Array Reference, Points to Color Buffer ...
* @param _stateBuffer: Double Array Reference, Points to State Buffer ...
*/
void CalculateVWAP(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[],
//
int _length, // Calculation Length
bool _show,
double &_buffer[],
double &_colorBuffer[],
double &_stateBuffer[] //
)
{
//
double vSum = 0;
double pSum = 0;
double mSum = 0;
for (int x = 0; x < _length; x++)
{
//
pSum += vwapPriceBuffer[x + bar_index];
vSum += vwapVolumeBuffer[x + bar_index];
mSum += vwapPriceBuffer[x + bar_index] * vwapVolumeBuffer[x + bar_index];
}
//
double iValue = mSum / vSum;
iValue = NormalizeDouble(iValue, _Digits);
//
_buffer[bar_index] = iValue;
//
bool isBullish = low[bar_index] > iValue;
bool isBearish = high[bar_index] < iValue;
//
double iColor =
isBullish
? bullishColorIDX
: isBearish
? bearishColorIDX
: neuturalColorIDX;
//
_colorBuffer[bar_index] = hideColorIDX;
_stateBuffer[bar_index] = iColor;
if (_show)
{
_colorBuffer[bar_index] = iColor;
}
}
/**
* Calculate VWAP Required Data Buffers ...
*
* @param bar_index: 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 CalculateVWAPDataBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
ENUM_X_PRICE mPType = ToXPrice(vwapAppliedTo);
double price = GetAppliedPrice(
mPType,
open,
high,
low,
close,
bar_index //
);
vwapPriceBuffer[bar_index] = price;
vwapVolumeBuffer[bar_index] = (double)tickVolume[bar_index];
}
/**
* Calculate Different VWaps ...
*
* @param bar_index: 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 CalculateVWAPS(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
vwapFastLength,
showVWapFast,
vwapFastBuffer,
vwapFastColorBuffer,
vwapFastStateBuffer //
);
//
// Mid ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
vwapMidLength,
showVWapMedium,
vwapMidBuffer,
vwapMidColorBuffer,
vwapMidStateBuffer //
);
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
vwapSlowLength,
showVWapSlow,
vwapSlowBuffer,
vwapSlowColorBuffer,
vwapSlowStateBuffer //
);
}
//