bkp workspace ...
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,631 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCHE
|
||||
// Description: Chandelier Exit Indicator ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCHE"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 35; // Length
|
||||
input int loopback = 26; // Loopback
|
||||
input double multiplier1 = 3.0; // 1st Multiplier
|
||||
input double multiplier2 = 3.5; // 2nd Multiplier
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLongExit1Line = true; // Show 1st Long Exit
|
||||
input bool showShortExit1Line = true; // Show 1st Short Exit
|
||||
input bool showLongExit2Line = true; // Show 2st Long Exit
|
||||
input bool showShortExit2Line = true; // Show 2st Short Exit
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
#define longExit1BufferIndex 0
|
||||
double longExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XCHE LE 1"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
#define shortExit1BufferIndex 1
|
||||
double shortExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XCHE SE 1"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color2 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
#define longExit2BufferIndex 2
|
||||
double longExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XCHE LE 2"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color3 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
#define shortExit2BufferIndex 3
|
||||
double shortExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XCHE SE 2"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color4 clrMagenta
|
||||
|
||||
//
|
||||
// START Arrows ...
|
||||
|
||||
//
|
||||
// Long Exit 1 Start ...
|
||||
#define longExit1StartBufferIndex 4
|
||||
double longExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XCHE LES 1"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrLime
|
||||
|
||||
//
|
||||
// Short Exit 1 Start ...
|
||||
#define shortExit1StartBufferIndex 5
|
||||
double shortExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XCHE SES 1"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 Start ...
|
||||
#define longExit2StartBufferIndex 6
|
||||
double longExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XCHE LES 2"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 Start ...
|
||||
#define shortExit2StartBufferIndex 7
|
||||
double shortExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XCHE SES 2"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrMagenta
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
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
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
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();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
if (Bars(_Symbol, _Period) < rates_total)
|
||||
{
|
||||
return (prev_calculated);
|
||||
}
|
||||
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
ArrayResize(work, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
length >= 9 &&
|
||||
loopback >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(length, loopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
uint arrowCode = 159;
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit1DrawType = showLongExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit1StartDrawType = showLongExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit1BufferIndex, longExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_SHOW_DATA, showLongExit1Line);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_DRAW_TYPE, longExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit1StartBufferIndex, longExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_DRAW_TYPE, longExit1StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit1DrawType = showShortExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit1StartDrawType = showShortExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit1BufferIndex, shortExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_SHOW_DATA, showShortExit1Line);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_DRAW_TYPE, shortExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit1StartBufferIndex, shortExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_DRAW_TYPE, shortExit1StartDrawType);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit2DrawType = showLongExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit2StartDrawType = showLongExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit2BufferIndex, longExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_SHOW_DATA, showLongExit2Line);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_DRAW_TYPE, longExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit2StartBufferIndex, longExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_DRAW_TYPE, longExit2StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit2DrawType = showShortExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit2StartDrawType = showShortExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit2BufferIndex, shortExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_SHOW_DATA, showShortExit2Line);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_DRAW_TYPE, shortExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit2StartBufferIndex, shortExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_DRAW_TYPE, shortExit2StartDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
longExit1Buffer[bar_index] = longExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index] = shortExit1StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
longExit2Buffer[bar_index] = longExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index] = shortExit2StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
int start = MathMax(bar_index - loopback, 0);
|
||||
|
||||
//
|
||||
// Calculate ATR Value ...
|
||||
double atrValue = 0;
|
||||
for (int k = 1; k <= length && (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)length;
|
||||
|
||||
//
|
||||
// Retrieve Highest High and Lowest Lows ...
|
||||
double loopbackMax = high[ArrayMaximum(high, start, loopback)];
|
||||
double loopbackMin = low[ArrayMinimum(low, start, loopback)];
|
||||
|
||||
//
|
||||
// Fill Multi Dimesional Working Array ...
|
||||
work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue;
|
||||
work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue;
|
||||
work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue;
|
||||
work[bar_index][lo2Idx] = loopbackMin + multiplier2 * 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 (multiplier1 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
longExit1Buffer[bar_index] = work[bar_index][hi1Idx];
|
||||
|
||||
//
|
||||
if (longExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit1StartBuffer[bar_index] = longExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier1 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit1Buffer[bar_index] = work[bar_index][lo1Idx];
|
||||
|
||||
//
|
||||
if (shortExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (multiplier2 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
longExit2Buffer[bar_index] = work[bar_index][hi2Idx];
|
||||
|
||||
//
|
||||
if (longExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit2StartBuffer[bar_index] = longExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier2 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit2Buffer[bar_index] = work[bar_index][lo2Idx];
|
||||
|
||||
//
|
||||
if (shortExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,348 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XDEMA
|
||||
// Description: Super Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// 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_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "X121_XDEMA"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int length = 200; // Length
|
||||
input int shift = 0; // Shift
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showDema = true; // Show Dema
|
||||
input bool showEMA = false; // Show EMA
|
||||
input bool showEMAOfEMA = false; // Show EMA of EMA
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include <MovingAverages.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
#define demaBufferIndex 0
|
||||
double demaBuffer[];
|
||||
|
||||
//
|
||||
#define demaColorBufferIndex 1
|
||||
double demaColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XDEMA DEMA"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrDodgerBlue, CLR_NONE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define emaBufferIndex 2
|
||||
double emaBuffer[];
|
||||
|
||||
//
|
||||
#define emaColorBufferIndex 3
|
||||
double emaColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XDEMA EMA"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrBlue, CLR_NONE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define emaOfEMABufferIndex 4
|
||||
double emaOfEMABuffer[];
|
||||
|
||||
//
|
||||
#define emaOfEMAColorBufferIndex 5
|
||||
double emaOfEMAColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XDEMA EMA of EMA"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrOrange, CLR_NONE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
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();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(price, true);
|
||||
|
||||
//
|
||||
// check for data ...
|
||||
if (rates_total < 2 * length - 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// calculate EMA ...
|
||||
ExponentialMAOnBuffer(rates_total, prev_calculated, 0, length, price, emaBuffer);
|
||||
|
||||
//
|
||||
// calculate EMA on EMA array ...
|
||||
ExponentialMAOnBuffer(rates_total, prev_calculated, length - 1, length, emaBuffer, emaOfEMABuffer);
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// calculate DEMA ...
|
||||
demaBuffer[i] = 2 * emaBuffer[i] - emaOfEMABuffer[i];
|
||||
|
||||
//
|
||||
double showColorIDX = 0;
|
||||
double hideColorIDX = 1;
|
||||
|
||||
//
|
||||
demaColorBuffer[i] = hideColorIDX;
|
||||
emaColorBuffer[i] = hideColorIDX;
|
||||
emaOfEMAColorBuffer[i] = hideColorIDX;
|
||||
|
||||
//
|
||||
if (showDema)
|
||||
{
|
||||
demaColorBuffer[i] = showColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showEMA)
|
||||
{
|
||||
emaColorBuffer[i] = showColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showEMAOfEMA)
|
||||
{
|
||||
emaOfEMAColorBuffer[i] = showColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(length > 2 &&
|
||||
shift >= 0)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// DEMA ...
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
ArraySetAsSeries(demaBuffer, true);
|
||||
SetIndexBuffer(demaBufferIndex, demaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(demaBufferIndex, PLOT_SHOW_DATA, showDema);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
ArraySetAsSeries(demaColorBuffer, true);
|
||||
SetIndexBuffer(demaColorBufferIndex, demaColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// EMA ...
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
ArraySetAsSeries(emaBuffer, true);
|
||||
SetIndexBuffer(emaBufferIndex, emaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(emaBufferIndex, PLOT_SHOW_DATA, showEMA);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
ArraySetAsSeries(emaColorBuffer, true);
|
||||
SetIndexBuffer(emaColorBufferIndex, emaColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// EMA of EMA ...
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
ArraySetAsSeries(emaOfEMABuffer, true);
|
||||
SetIndexBuffer(emaOfEMABufferIndex, emaOfEMABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(emaOfEMABufferIndex, PLOT_SHOW_DATA, showEMAOfEMA);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
ArraySetAsSeries(emaOfEMAColorBuffer, true);
|
||||
SetIndexBuffer(emaOfEMAColorBufferIndex, emaOfEMAColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,964 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XDSR
|
||||
// Description: Dynamic Support and Resistances ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XDSR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XDSR"
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// INPUT ...
|
||||
|
||||
//
|
||||
// Maarket ...
|
||||
input group "Cycles";
|
||||
|
||||
//
|
||||
// Short ...
|
||||
input group "Short";
|
||||
input ENUM_X_PERIOD_METHOD scMode = X_PERIOD_MANUALLY; // Method
|
||||
input ENUM_TIMEFRAMES scPeriod = PERIOD_H4; // Period
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
input group "Medium";
|
||||
input ENUM_X_PERIOD_METHOD mcMode = X_PERIOD_MANUALLY; // Method
|
||||
input ENUM_TIMEFRAMES mcPeriod = PERIOD_H12; // Mid Period
|
||||
|
||||
//
|
||||
// Long ...
|
||||
input group "Long";
|
||||
input ENUM_X_PERIOD_METHOD lcMode = X_PERIOD_MANUALLY; // Method
|
||||
input ENUM_TIMEFRAMES lcPeriod = PERIOD_D1; // Long Period
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
input group "Hind";
|
||||
input ENUM_X_PERIOD_METHOD hcMode = X_PERIOD_MANUALLY; // Method
|
||||
input ENUM_TIMEFRAMES hcPeriod = PERIOD_W1; // Hind Period
|
||||
|
||||
//
|
||||
// BUFFERS ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 24
|
||||
#property indicator_plots 24
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
#define scOpenBufferIndex 0
|
||||
#define scOpenBufferPlotIndex 0
|
||||
double scOpenBuffer[];
|
||||
|
||||
//
|
||||
#define scOpenColorBufferIndex 1
|
||||
double scOpenColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XDSR SC O"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrGreen, clrRed
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define scHighBufferIndex 2
|
||||
#define scHighBufferPlotIndex 1
|
||||
double scHighBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XDSR SC H"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
#define scCloseBufferIndex 3
|
||||
#define scCloseBufferPlotIndex 2
|
||||
double scCloseBuffer[];
|
||||
|
||||
//
|
||||
#define scCloseColorBufferIndex 4
|
||||
double scCloseColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XDSR SC C"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrGreen, clrRed
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define scLowBufferIndex 5
|
||||
#define scLowBufferPlotIndex 3
|
||||
double scLowBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XDSR SC L"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrMagenta
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
#define mcOpenBufferIndex 6
|
||||
#define mcOpenBufferPlotIndex 4
|
||||
double mcOpenBuffer[];
|
||||
|
||||
//
|
||||
#define mcOpenColorBufferIndex 7
|
||||
double mcOpenColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XDSR MC O"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 clrGreen, clrRed
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define mcHighBufferIndex 8
|
||||
#define mcHighBufferPlotIndex 5
|
||||
double mcHighBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XDSR MC H"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrAqua
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
#define mcCloseBufferIndex 9
|
||||
#define mcCloseBufferPlotIndex 6
|
||||
double mcCloseBuffer[];
|
||||
|
||||
//
|
||||
#define mcCloseColorBufferIndex 10
|
||||
double mcCloseColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XDSR MC C"
|
||||
#property indicator_type7 DRAW_COLOR_LINE
|
||||
#property indicator_color7 clrGreen, clrRed
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define mcLowBufferIndex 11
|
||||
#define mcLowBufferPlotIndex 7
|
||||
double mcLowBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XDSR MC L"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrMagenta
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
#define lcOpenBufferIndex 12
|
||||
#define lcOpenBufferPlotIndex 8
|
||||
double lcOpenBuffer[];
|
||||
|
||||
//
|
||||
#define lcOpenColorBufferIndex 13
|
||||
double lcOpenColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "X121_XDSR LC O"
|
||||
#property indicator_type9 DRAW_COLOR_LINE
|
||||
#property indicator_color9 clrGreen, clrRed
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define lcHighBufferIndex 14
|
||||
#define lcHighBufferPlotIndex 9
|
||||
double lcHighBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121_XDSR LC H"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrAqua
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
#define lcCloseBufferIndex 15
|
||||
#define lcCloseBufferPlotIndex 10
|
||||
double lcCloseBuffer[];
|
||||
|
||||
//
|
||||
#define lcCloseColorBufferIndex 16
|
||||
double lcCloseColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "X121_XDSR LC C"
|
||||
#property indicator_type11 DRAW_COLOR_LINE
|
||||
#property indicator_color11 clrGreen, clrRed
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define lcLowBufferIndex 17
|
||||
#define lcLowBufferPlotIndex 11
|
||||
double lcLowBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "X121_XDSR LC L"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrMagenta
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
#define hcOpenBufferIndex 18
|
||||
#define hcOpenBufferPlotIndex 12
|
||||
double hcOpenBuffer[];
|
||||
|
||||
//
|
||||
#define hcOpenColorBufferIndex 19
|
||||
double hcOpenColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label13 "X121_XDSR HC O"
|
||||
#property indicator_type13 DRAW_COLOR_LINE
|
||||
#property indicator_color13 clrGreen, clrRed
|
||||
#property indicator_width13 1
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define hcHighBufferIndex 20
|
||||
#define hcHighBufferPlotIndex 13
|
||||
double hcHighBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label14 "X121_XDSR HC H"
|
||||
#property indicator_type14 DRAW_LINE
|
||||
#property indicator_color14 clrAqua
|
||||
#property indicator_width14 1
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
#define hcCloseBufferIndex 21
|
||||
#define hcCloseBufferPlotIndex 14
|
||||
double hcCloseBuffer[];
|
||||
|
||||
//
|
||||
#define hcCloseColorBufferIndex 22
|
||||
double hcCloseColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label15 "X121_XDSR HC C"
|
||||
#property indicator_type15 DRAW_COLOR_LINE
|
||||
#property indicator_color15 clrGreen, clrRed
|
||||
#property indicator_width15 1
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define hcLowBufferIndex 23
|
||||
#define hcLowBufferPlotIndex 15
|
||||
double hcLowBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label16 "X121_XDSR HC L"
|
||||
#property indicator_type16 DRAW_LINE
|
||||
#property indicator_color16 clrMagenta
|
||||
#property indicator_width16 1
|
||||
|
||||
//
|
||||
// VARIABLES ...
|
||||
|
||||
//
|
||||
// Cycles Definitions ...
|
||||
XMarketCycle sc;
|
||||
XMarketCycle mc;
|
||||
XMarketCycle lc;
|
||||
XMarketCycle hc;
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initial Market Cycles ...
|
||||
if (!InitMarketCycles())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total - 1
|
||||
: (rates_total - prev_calculated);
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
CalculateBuffer(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Short ...
|
||||
IsValidCycle(
|
||||
scMode,
|
||||
scPeriod)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Medium ...
|
||||
IsValidCycle(
|
||||
mcMode,
|
||||
mcPeriod)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Long ...
|
||||
IsValidCycle(
|
||||
lcMode,
|
||||
lcPeriod)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Hind ...
|
||||
IsValidCycle(
|
||||
hcMode,
|
||||
hcPeriod)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(scHighBuffer, true);
|
||||
SetIndexBuffer(scHighBufferIndex, scHighBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(scHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(scHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(scHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(scLowBuffer, true);
|
||||
SetIndexBuffer(scLowBufferIndex, scLowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(scLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(scLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(scLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(scOpenBuffer, true);
|
||||
SetIndexBuffer(scOpenBufferIndex, scOpenBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(scOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(scOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(scOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(scOpenColorBuffer, true);
|
||||
SetIndexBuffer(scOpenColorBufferIndex, scOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
ArraySetAsSeries(scCloseBuffer, true);
|
||||
SetIndexBuffer(scCloseBufferIndex, scCloseBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(scCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(scCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(scCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(scCloseColorBuffer, true);
|
||||
SetIndexBuffer(scCloseColorBufferIndex, scCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mcHighBuffer, true);
|
||||
SetIndexBuffer(mcHighBufferIndex, mcHighBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(mcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(mcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mcLowBuffer, true);
|
||||
SetIndexBuffer(mcLowBufferIndex, mcLowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(mcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(mcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mcOpenBuffer, true);
|
||||
SetIndexBuffer(mcOpenBufferIndex, mcOpenBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(mcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(mcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mcOpenColorBuffer, true);
|
||||
SetIndexBuffer(mcOpenColorBufferIndex, mcOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
ArraySetAsSeries(mcCloseBuffer, true);
|
||||
SetIndexBuffer(mcCloseBufferIndex, mcCloseBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(mcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(mcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mcCloseColorBuffer, true);
|
||||
SetIndexBuffer(mcCloseColorBufferIndex, mcCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lcHighBuffer, true);
|
||||
SetIndexBuffer(lcHighBufferIndex, lcHighBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(lcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(lcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lcLowBuffer, true);
|
||||
SetIndexBuffer(lcLowBufferIndex, lcLowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(lcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(lcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lcOpenBuffer, true);
|
||||
SetIndexBuffer(lcOpenBufferIndex, lcOpenBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(lcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(lcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lcOpenColorBuffer, true);
|
||||
SetIndexBuffer(lcOpenColorBufferIndex, lcOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
ArraySetAsSeries(lcCloseBuffer, true);
|
||||
SetIndexBuffer(lcCloseBufferIndex, lcCloseBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(lcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(lcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lcCloseColorBuffer, true);
|
||||
SetIndexBuffer(lcCloseColorBufferIndex, lcCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hcHighBuffer, true);
|
||||
SetIndexBuffer(hcHighBufferIndex, hcHighBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(hcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(hcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hcLowBuffer, true);
|
||||
SetIndexBuffer(hcLowBufferIndex, hcLowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(hcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(hcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hcOpenBuffer, true);
|
||||
SetIndexBuffer(hcOpenBufferIndex, hcOpenBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(hcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(hcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hcOpenColorBuffer, true);
|
||||
SetIndexBuffer(hcOpenColorBufferIndex, hcOpenColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
ArraySetAsSeries(hcCloseBuffer, true);
|
||||
SetIndexBuffer(hcCloseBufferIndex, hcCloseBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(hcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(hcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hcCloseColorBuffer, true);
|
||||
SetIndexBuffer(hcCloseColorBufferIndex, hcCloseColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateBuffer(const int barIndex)
|
||||
{
|
||||
//
|
||||
// First Update Market Cycles ...
|
||||
UpdateMarketCycles(barIndex);
|
||||
|
||||
//
|
||||
double bullishColorIDX = 0;
|
||||
double bearishColorIDX = 1;
|
||||
|
||||
//
|
||||
// Short ...
|
||||
int scBarIndex = sc.GetBarIndex(barIndex);
|
||||
XOHCL scBar1 = sc.GetBar(scBarIndex + 1);
|
||||
|
||||
//
|
||||
bool isSCBar1Bullish = scBar1.open < scBar1.close;
|
||||
|
||||
//
|
||||
scOpenBuffer[barIndex] = scBar1.open;
|
||||
scHighBuffer[barIndex] = scBar1.high;
|
||||
scCloseBuffer[barIndex] = scBar1.close;
|
||||
scLowBuffer[barIndex] = scBar1.low;
|
||||
|
||||
//
|
||||
scOpenColorBuffer[barIndex] =
|
||||
isSCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
|
||||
//
|
||||
scCloseColorBuffer[barIndex] =
|
||||
isSCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
int mcBarIndex = mc.GetBarIndex(barIndex);
|
||||
XOHCL mcBar1 = mc.GetBar(mcBarIndex + 1);
|
||||
|
||||
//
|
||||
bool isMCBar1Bullish = mcBar1.open < mcBar1.close;
|
||||
|
||||
//
|
||||
mcOpenBuffer[barIndex] = mcBar1.open;
|
||||
mcHighBuffer[barIndex] = mcBar1.high;
|
||||
mcCloseBuffer[barIndex] = mcBar1.close;
|
||||
mcLowBuffer[barIndex] = mcBar1.low;
|
||||
|
||||
//
|
||||
mcOpenColorBuffer[barIndex] =
|
||||
isMCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
|
||||
//
|
||||
mcCloseColorBuffer[barIndex] =
|
||||
isMCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
|
||||
//
|
||||
// Long ...
|
||||
int lcBarIndex = lc.GetBarIndex(barIndex);
|
||||
XOHCL lcBar1 = lc.GetBar(lcBarIndex + 1);
|
||||
|
||||
//
|
||||
bool isLCBar1Bullish = lcBar1.open < lcBar1.close;
|
||||
|
||||
//
|
||||
lcOpenBuffer[barIndex] = lcBar1.open;
|
||||
lcHighBuffer[barIndex] = lcBar1.high;
|
||||
lcCloseBuffer[barIndex] = lcBar1.close;
|
||||
lcLowBuffer[barIndex] = lcBar1.low;
|
||||
|
||||
//
|
||||
lcOpenColorBuffer[barIndex] =
|
||||
isLCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
|
||||
//
|
||||
lcCloseColorBuffer[barIndex] =
|
||||
isLCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
int hcBarIndex = hc.GetBarIndex(barIndex);
|
||||
XOHCL hcBar1 = hc.GetBar(hcBarIndex + 1);
|
||||
|
||||
//
|
||||
bool isHCBar1Bullish = hcBar1.open < hcBar1.close;
|
||||
|
||||
//
|
||||
hcOpenBuffer[barIndex] = hcBar1.open;
|
||||
hcHighBuffer[barIndex] = hcBar1.high;
|
||||
hcCloseBuffer[barIndex] = hcBar1.close;
|
||||
hcLowBuffer[barIndex] = hcBar1.low;
|
||||
|
||||
//
|
||||
hcOpenColorBuffer[barIndex] =
|
||||
isHCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
|
||||
//
|
||||
hcCloseColorBuffer[barIndex] =
|
||||
isHCBar1Bullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// TOOLS ...
|
||||
|
||||
//
|
||||
// Initial Market Cycles ...
|
||||
bool InitMarketCycles()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Short ...
|
||||
sc.method = scMode;
|
||||
sc.period = scPeriod;
|
||||
result = sc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_SHORT);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
mc.method = mcMode;
|
||||
mc.period = mcPeriod;
|
||||
result = mc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_MEDIUM);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Long ...
|
||||
lc.method = lcMode;
|
||||
lc.period = lcPeriod;
|
||||
result = lc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_LONG);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
hc.method = hcMode;
|
||||
hc.period = hcPeriod;
|
||||
result = hc.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_HIND);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Update Market Cycles ...
|
||||
bool UpdateMarketCycles(int barIndex)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Short ...
|
||||
result = sc.Update(barIndex);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
result = mc.Update(barIndex);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Long ...
|
||||
result = lc.Update(barIndex);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
result = hc.Update(barIndex);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,836 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121_XICH
|
||||
// Description: Ichimoku Kinko Hyo ...
|
||||
//
|
||||
//
|
||||
// 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_XICH Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XICH"
|
||||
|
||||
//
|
||||
// Ichimoku Golden Numbers ...
|
||||
enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS
|
||||
{
|
||||
X_ICH_BASE = 9,
|
||||
X_ICH_GOLDEN = 17,
|
||||
X_ICH_CYCLE = 26,
|
||||
X_ICH_PERIOD = 35,
|
||||
X_ICH_STAR = 45,
|
||||
X_ICH_MED = 52,
|
||||
X_ICH_LONG = 63,
|
||||
X_ICH_FULL = 72
|
||||
};
|
||||
|
||||
//
|
||||
// Ichimoku Lines Calculator Mode ...
|
||||
enum ENUM_X_ICHIMOKU_CALCULATION_MODE
|
||||
{
|
||||
//
|
||||
X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low
|
||||
X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// ICHIMOKU Kinko Hyo ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
input group "Tenkan Sen";
|
||||
input int tenkanSenLength = 9; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
input group "Kijun Sen";
|
||||
input int kijunSenLength = 26; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
input group "Senkou Span B";
|
||||
input int senkouSpanBLength = 52; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
input group "Chikou Span";
|
||||
input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTenkanSen = true; // Show Tenkan Sen
|
||||
input bool showKijunSen = true; // Show Kijun Sen
|
||||
input bool showKijunSenPlus = false; // Show Kijun Sen +
|
||||
input bool showKijunSenNegative = false; // Show Kijun Sen -
|
||||
input bool showChikouSpan = true; // Show Chikou Span
|
||||
input bool showSenkouSpanA = true; // Show Senkou Span A
|
||||
input bool showSenkouSpanB = true; // Show Senkou Span B
|
||||
input bool showKumo = true; // Show Kumo
|
||||
input bool shiftKumo = true; // Shift Kumo to Future
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
#define tenkanSenBufferIndex 0
|
||||
double tenkanSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XICH TK"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
#define kijunSenBufferIndex 1
|
||||
double kijunSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XICH KJ"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDodgerBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define kijunSenPlusBufferIndex 2
|
||||
double kijunSenPlusBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XICH KJ+"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMediumTurquoise
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define kijunSenNegativeBufferIndex 3
|
||||
double kijunSenNegativeBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XICH KJ-"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrDarkSeaGreen
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
|
||||
//
|
||||
#define chikouSpanBufferIndex 4
|
||||
double chikouSpanBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XICH CS"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrDarkGreen
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define senkouABufferIndex 5
|
||||
double senkouABuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XICH SSA"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrLightGray
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define senkouBBufferIndex 6
|
||||
double senkouBBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XICH SSB"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrLightGray
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
|
||||
//
|
||||
#define senkouSpanABufferIndex 7
|
||||
double senkouSpanABuffer[];
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
#define senkouSpanBBufferIndex 8
|
||||
double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
// KUMOCLOUD ...
|
||||
|
||||
//
|
||||
#define kumoBufferIndex 7
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XICH Kumo"
|
||||
#property indicator_type8 DRAW_FILLING
|
||||
#property indicator_color8 clrAqua, clrMagenta
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define dTenkanBufferIndex 9
|
||||
double dTenkanBuffer[];
|
||||
|
||||
//
|
||||
#define dKijunBufferIndex 10
|
||||
double dKijunBuffer[];
|
||||
|
||||
//
|
||||
#define dChikouBufferIndex 11
|
||||
double dChikouBuffer[];
|
||||
|
||||
//
|
||||
#define dSSABufferIndex 12
|
||||
double dSSABuffer[];
|
||||
|
||||
//
|
||||
#define dSSBBufferIndex 13
|
||||
double dSSBBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mTenkanSenTopMode = NULL;
|
||||
ENUM_SERIESMODE mTenkanSenBottomMode = NULL;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mKijunSenTopMode = NULL;
|
||||
ENUM_SERIESMODE mKijunSenBottomMode = NULL;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mSenkouSpanBTopMode = NULL;
|
||||
ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
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();
|
||||
|
||||
//
|
||||
// Init Handler ...
|
||||
mHandler = iIchimoku(
|
||||
_Symbol,
|
||||
_Period,
|
||||
tenkanSenLength,
|
||||
kijunSenLength,
|
||||
senkouSpanBLength);
|
||||
if (mHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int ichCalculatedBars = BarsCalculated(mHandler);
|
||||
if (ichCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedTenkans = CopyBuffer(mHandler, TENKANSEN_LINE, 0, limit, dTenkanBuffer);
|
||||
int copiedKijuns = CopyBuffer(mHandler, KIJUNSEN_LINE, 0, limit, dKijunBuffer);
|
||||
int copiedChikous = CopyBuffer(mHandler, CHIKOUSPAN_LINE, 0, limit, dChikouBuffer);
|
||||
int copiedSSAs = CopyBuffer(mHandler, SENKOUSPANA_LINE, 0, limit, dSSABuffer);
|
||||
int copiedSSBs = CopyBuffer(mHandler, SENKOUSPANB_LINE, 0, limit, dSSBBuffer);
|
||||
if (
|
||||
copiedSSAs < 0 ||
|
||||
copiedSSBs < 0 ||
|
||||
copiedKijuns < 0 ||
|
||||
copiedTenkans < 0 ||
|
||||
copiedChikous < 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(tenkanSenLength > 2 &&
|
||||
kijunSenLength > tenkanSenLength &&
|
||||
senkouSpanBLength > kijunSenLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ichimoku ...
|
||||
result = MathMax(result, tenkanSenLength);
|
||||
result = MathMax(result, kijunSenLength);
|
||||
result = MathMax(result, senkouSpanBLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// KIJUNSEN Plus ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenPlusDrawType = showKijunSenPlus ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenPlusBuffer, true);
|
||||
SetIndexBuffer(kijunSenPlusBufferIndex, kijunSenPlusBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHIFT, kijunSenLength);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_TYPE, kijunSenPlusDrawType);
|
||||
|
||||
//
|
||||
// KIJUNSEN Negative ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenNegativeDrawType = showKijunSenNegative ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenNegativeBuffer, true);
|
||||
SetIndexBuffer(kijunSenNegativeBufferIndex, kijunSenNegativeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_TYPE, kijunSenNegativeDrawType);
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// SENKOUSPAN A and B ...
|
||||
int shiftSize = shiftKumo ? kijunSenLength : 0;
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(senkouABuffer, true);
|
||||
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(senkouBBuffer, true);
|
||||
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
ArraySetAsSeries(senkouSpanABuffer, true);
|
||||
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
ArraySetAsSeries(senkouSpanBBuffer, true);
|
||||
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// D Tenkan ...
|
||||
ArraySetAsSeries(dTenkanBuffer, true);
|
||||
SetIndexBuffer(dTenkanBufferIndex, dTenkanBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D Kijun ...
|
||||
ArraySetAsSeries(dKijunBuffer, true);
|
||||
SetIndexBuffer(dKijunBufferIndex, dKijunBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D Chikou ...
|
||||
ArraySetAsSeries(dChikouBuffer, true);
|
||||
SetIndexBuffer(dChikouBufferIndex, dChikouBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D SSA ...
|
||||
ArraySetAsSeries(dSSABuffer, true);
|
||||
SetIndexBuffer(dSSABufferIndex, dSSABuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D SSB ...
|
||||
ArraySetAsSeries(dSSBBuffer, true);
|
||||
SetIndexBuffer(dSSBBufferIndex, dSSBBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
double topValue;
|
||||
double bottomValue;
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
// Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (tenkanSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_HIGH;
|
||||
mTenkanSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_OPEN;
|
||||
mTenkanSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mTenkanSenTopMode,
|
||||
tenkanSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mTenkanSenBottomMode,
|
||||
tenkanSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double tenkanSenValue = (topValue + bottomValue) / 2;
|
||||
tenkanSenBuffer[bar_index] = tenkanSenValue;
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
// Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (kijunSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_HIGH;
|
||||
mKijunSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_OPEN;
|
||||
mKijunSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mKijunSenTopMode,
|
||||
kijunSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mKijunSenBottomMode,
|
||||
kijunSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double kijunSenValue = (topValue + bottomValue) / 2;
|
||||
kijunSenBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
kijunSenPlusBuffer[bar_index] = kijunSenValue;
|
||||
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
double chikouSpanValue = GetAppliedPrice(
|
||||
bar_index,
|
||||
chikuoSpanAppliedTo);
|
||||
chikouSpanBuffer[bar_index] = chikouSpanValue;
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2;
|
||||
senkouABuffer[bar_index] = senkouSpanAValue;
|
||||
senkouSpanABuffer[bar_index] = senkouSpanAValue;
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
// Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (senkouSpanBMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_HIGH;
|
||||
mSenkouSpanBBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_OPEN;
|
||||
mSenkouSpanBBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mSenkouSpanBTopMode,
|
||||
senkouSpanBLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mSenkouSpanBBottomMode,
|
||||
senkouSpanBLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double senkouSpanBValue = (topValue + bottomValue) / 2;
|
||||
senkouBBuffer[bar_index] = senkouSpanBValue;
|
||||
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,721 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XOSC
|
||||
// Description: provides some oscillator values
|
||||
// as empty Indicator ...
|
||||
//
|
||||
//
|
||||
// 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_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "X121_XOSC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
input group "ATR";
|
||||
input int atrLength = 14; // Length
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "RVI";
|
||||
input int rviLength = 10; // Length
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
input group "Bulls Power";
|
||||
input int bullpLength = 13; // Length
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
input group "Bears Power";
|
||||
input int bearpLength = 13; // Length
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
input group "Volumes";
|
||||
input ENUM_APPLIED_VOLUME volumeAppliedTo = VOLUME_TICK; // Applied To
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
input group "RSI";
|
||||
input int rsiLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
input group "CCI";
|
||||
input int cciLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE cciAppliedTo = PRICE_TYPICAL; // Applied To
|
||||
|
||||
//
|
||||
// STDDEV ...
|
||||
input group "Standard Deviation";
|
||||
input int stddevLength = 20; // Length
|
||||
input int stddevShift = 0; // Shift
|
||||
input ENUM_MA_METHOD stddevMethod = MODE_SMA; // Mode
|
||||
input ENUM_APPLIED_PRICE stddevAppliedTo = PRICE_CLOSE; // AppliedTo
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
input group "Momentum";
|
||||
input int momentumLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE momentumAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
input group "SAR";
|
||||
input double sarStep = 0.02; // Step
|
||||
input double sarMaximum = 0.2; // Maximum
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "MACD";
|
||||
input int macdFastLength = 12; // Fast Length
|
||||
input int macdSlowLength = 26; // Slow Length
|
||||
input int macdSignaLength = 9; // Signal Length
|
||||
input ENUM_APPLIED_PRICE macdAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
// The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "Stochastic";
|
||||
input int stochKLength = 5; // K Length
|
||||
input int stochDLength = 3; // D Length
|
||||
input int stochSlowing = 3; // Slowing
|
||||
input ENUM_MA_METHOD stochMaMethod = MODE_SMA; // Ma Method
|
||||
input ENUM_STO_PRICE stochMode = STO_LOWHIGH; // Calculation Mode
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
#define atrBufferIndex 0
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
#define rviMainBufferIndex 1
|
||||
#define rviSignalBufferIndex 2
|
||||
double rviMainBuffer[];
|
||||
double rviSignalBuffer[];
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
#define bullPBufferIndex 3
|
||||
double bullPBuffer[];
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
#define bearPBufferIndex 4
|
||||
double bearPBuffer[];
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
#define volumeBufferIndex 5
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex 6
|
||||
double rsiBuffer[];
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
#define cciBufferIndex 7
|
||||
double cciBuffer[];
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
#define momentumBufferIndex 8
|
||||
double momentumBuffer[];
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
#define sarBufferIndex 9
|
||||
double sarBuffer[];
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
#define macdMainBufferIndex 10
|
||||
#define macdSignalBufferIndex 11
|
||||
double macdMainBuffer[];
|
||||
double macdSignalBuffer[];
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
#define stochMainBufferIndex 12
|
||||
#define stochSignalBufferIndex 13
|
||||
double stochMainBuffer[];
|
||||
double stochSignalBuffer[];
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
#define stddevBufferIndex 14
|
||||
double stddevBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
int rviHandler = INVALID_HANDLE;
|
||||
int bullPHandler = INVALID_HANDLE;
|
||||
int bearPHandler = INVALID_HANDLE;
|
||||
int volumeHandler = INVALID_HANDLE;
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
int cciHandler = INVALID_HANDLE;
|
||||
int momentumHandler = INVALID_HANDLE;
|
||||
int sarHandler = INVALID_HANDLE;
|
||||
int macdHandler = INVALID_HANDLE;
|
||||
int stochHandler = INVALID_HANDLE;
|
||||
int stddevHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
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();
|
||||
|
||||
//
|
||||
// Initializing Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength);
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
rviHandler = iRVI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rviLength);
|
||||
|
||||
//
|
||||
// BULLSPOWER ...
|
||||
bullPHandler = iBullsPower(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bullpLength);
|
||||
|
||||
//
|
||||
// BEARSPOWER ...
|
||||
bearPHandler = iBearsPower(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bullpLength);
|
||||
|
||||
//
|
||||
// VOLUMES ...
|
||||
volumeHandler = iVolumes(
|
||||
_Symbol,
|
||||
_Period,
|
||||
volumeAppliedTo);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rsiLength,
|
||||
rsiAppliedTo);
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
cciHandler = iCCI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
cciLength,
|
||||
cciAppliedTo);
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
momentumHandler = iMomentum(
|
||||
_Symbol,
|
||||
_Period,
|
||||
momentumLength,
|
||||
momentumAppliedTo);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
sarHandler = iSAR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
sarStep,
|
||||
sarMaximum);
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
macdHandler = iMACD(
|
||||
_Symbol,
|
||||
_Period,
|
||||
macdFastLength,
|
||||
macdSlowLength,
|
||||
macdSignaLength,
|
||||
macdAppliedTo);
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
stochHandler = iStochastic(
|
||||
_Symbol,
|
||||
_Period,
|
||||
stochKLength,
|
||||
stochDLength,
|
||||
stochSlowing,
|
||||
stochMaMethod,
|
||||
stochMode);
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
stddevHandler = iStdDev(
|
||||
_Symbol,
|
||||
_Period,
|
||||
stddevLength,
|
||||
stddevShift,
|
||||
stddevMethod,
|
||||
stddevAppliedTo);
|
||||
|
||||
//
|
||||
bool isAllHandlersInit =
|
||||
//
|
||||
atrHandler != INVALID_HANDLE &&
|
||||
rviHandler != INVALID_HANDLE &&
|
||||
bullPHandler != INVALID_HANDLE &&
|
||||
bearPHandler != INVALID_HANDLE &&
|
||||
volumeHandler != INVALID_HANDLE &&
|
||||
rsiHandler != INVALID_HANDLE &&
|
||||
cciHandler != INVALID_HANDLE &&
|
||||
momentumHandler != INVALID_HANDLE &&
|
||||
sarHandler != INVALID_HANDLE &&
|
||||
macdHandler != INVALID_HANDLE &&
|
||||
stochHandler != INVALID_HANDLE &&
|
||||
stddevHandler != INVALID_HANDLE
|
||||
//
|
||||
;
|
||||
if (!isAllHandlersInit)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(atrHandler);
|
||||
IndicatorRelease(rviHandler);
|
||||
IndicatorRelease(bullPHandler);
|
||||
IndicatorRelease(bearPHandler);
|
||||
IndicatorRelease(volumeHandler);
|
||||
IndicatorRelease(rsiHandler);
|
||||
IndicatorRelease(cciHandler);
|
||||
IndicatorRelease(momentumHandler);
|
||||
IndicatorRelease(sarHandler);
|
||||
IndicatorRelease(macdHandler);
|
||||
IndicatorRelease(stochHandler);
|
||||
IndicatorRelease(stddevHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
int rviCalculatedBars = BarsCalculated(rviHandler);
|
||||
int bullPCalculatedBars = BarsCalculated(bullPHandler);
|
||||
int bearPCalculatedBars = BarsCalculated(bearPHandler);
|
||||
int volumeCalculatedBars = BarsCalculated(volumeHandler);
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
int cciCalculatedBars = BarsCalculated(cciHandler);
|
||||
int momentumCalculatedBars = BarsCalculated(momentumHandler);
|
||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
||||
int macdCalculatedBars = BarsCalculated(macdHandler);
|
||||
int stochCalculatedBars = BarsCalculated(stochHandler);
|
||||
int stddevCalculatedBars = BarsCalculated(stddevHandler);
|
||||
|
||||
//
|
||||
bool isCalculatedBarsPassed =
|
||||
//
|
||||
atrCalculatedBars >= maxLength &&
|
||||
rviCalculatedBars >= maxLength &&
|
||||
bullPCalculatedBars >= maxLength &&
|
||||
bearPCalculatedBars >= maxLength &&
|
||||
volumeCalculatedBars >= maxLength &&
|
||||
rsiCalculatedBars >= maxLength &&
|
||||
cciCalculatedBars >= maxLength &&
|
||||
momentumCalculatedBars >= maxLength &&
|
||||
sarCalculatedBars >= maxLength &&
|
||||
macdCalculatedBars >= maxLength &&
|
||||
stochCalculatedBars >= maxLength &&
|
||||
stddevCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isCalculatedBarsPassed)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int atrCopiedItems = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
||||
int rviMainCopiedItems = CopyBuffer(rviHandler, MAIN_LINE, 0, limit, rviMainBuffer);
|
||||
int rviSignalCopiedItems = CopyBuffer(rviHandler, SIGNAL_LINE, 0, limit, rviSignalBuffer);
|
||||
int bullPCopiedItems = CopyBuffer(bullPHandler, 0, 0, limit, bullPBuffer);
|
||||
int bearPCopiedItems = CopyBuffer(bearPHandler, 0, 0, limit, bearPBuffer);
|
||||
int volumeCopiedItems = CopyBuffer(volumeHandler, 0, 0, limit, volumeBuffer);
|
||||
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
int cciCopiedItems = CopyBuffer(cciHandler, 0, 0, limit, cciBuffer);
|
||||
int momentumCopiedItems = CopyBuffer(momentumHandler, 0, 0, limit, momentumBuffer);
|
||||
int sarCopiedItems = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
||||
int macdMainCopiedItems = CopyBuffer(macdHandler, MAIN_LINE, 0, limit, macdMainBuffer);
|
||||
int macdSignalCopiedItems = CopyBuffer(macdHandler, SIGNAL_LINE, 0, limit, macdSignalBuffer);
|
||||
int stochMainCopiedItems = CopyBuffer(stochHandler, MAIN_LINE, 0, limit, stochMainBuffer);
|
||||
int stocSignalhCopiedItems = CopyBuffer(stochHandler, SIGNAL_LINE, 0, limit, stochSignalBuffer);
|
||||
int stddevCopiedItems = CopyBuffer(stddevHandler, 0, 0, limit, stddevBuffer);
|
||||
|
||||
//
|
||||
bool isCopiedBarsPassed =
|
||||
//
|
||||
atrCopiedItems > 0 &&
|
||||
rviMainCopiedItems > 0 &&
|
||||
rviSignalCopiedItems > 0 &&
|
||||
bullPCopiedItems > 0 &&
|
||||
bearPCopiedItems > 0 &&
|
||||
volumeCopiedItems > 0 &&
|
||||
rsiCopiedItems > 0 &&
|
||||
cciCopiedItems > 0 &&
|
||||
momentumCopiedItems > 0 &&
|
||||
sarCopiedItems > 0 &&
|
||||
macdMainCopiedItems > 0 &&
|
||||
macdSignalCopiedItems > 0 &&
|
||||
stochMainCopiedItems > 0 &&
|
||||
stocSignalhCopiedItems > 0 &&
|
||||
stddevCopiedItems > 0
|
||||
//
|
||||
;
|
||||
if (!isCopiedBarsPassed)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
// HERE We Do Not anything ...
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
atrLength >= 2 &&
|
||||
rviLength >= 2 &&
|
||||
bullpLength >= 2 &&
|
||||
bearpLength >= 2 &&
|
||||
rsiLength >= 2 &&
|
||||
cciLength >= 2 &&
|
||||
momentumLength >= 2 &&
|
||||
sarStep > 0 &&
|
||||
sarStep < sarMaximum &&
|
||||
macdFastLength >= 2 &&
|
||||
macdSlowLength > macdFastLength &&
|
||||
macdSignaLength >= 2 &&
|
||||
stochKLength >= 2 &&
|
||||
stochDLength >= 2 &&
|
||||
stochSlowing >= 2 &&
|
||||
stddevLength >= 2 &&
|
||||
stddevShift >= 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(atrLength, rviLength);
|
||||
result = MathMax(result, bullpLength);
|
||||
result = MathMax(result, bearpLength);
|
||||
result = MathMax(result, rsiLength);
|
||||
result = MathMax(result, cciLength);
|
||||
result = MathMax(result, momentumLength);
|
||||
result = MathMax(result, macdFastLength);
|
||||
result = MathMax(result, macdSlowLength);
|
||||
result = MathMax(result, macdSignaLength);
|
||||
result = MathMax(result, stochKLength);
|
||||
result = MathMax(result, stochDLength);
|
||||
result = MathMax(result, stochSlowing);
|
||||
result = MathMax(result, stddevLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
|
||||
//
|
||||
// Main ...
|
||||
ArraySetAsSeries(rviMainBuffer, true);
|
||||
SetIndexBuffer(rviMainBufferIndex, rviMainBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
ArraySetAsSeries(rviSignalBuffer, true);
|
||||
SetIndexBuffer(rviSignalBufferIndex, rviSignalBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
ArraySetAsSeries(bullPBuffer, true);
|
||||
SetIndexBuffer(bullPBufferIndex, bullPBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
ArraySetAsSeries(bearPBuffer, true);
|
||||
SetIndexBuffer(bearPBufferIndex, bearPBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
ArraySetAsSeries(cciBuffer, true);
|
||||
SetIndexBuffer(cciBufferIndex, cciBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
ArraySetAsSeries(momentumBuffer, true);
|
||||
SetIndexBuffer(momentumBufferIndex, momentumBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
ArraySetAsSeries(sarBuffer, true);
|
||||
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
ArraySetAsSeries(stddevBuffer, true);
|
||||
SetIndexBuffer(stddevBufferIndex, stddevBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
|
||||
//
|
||||
// Main ...
|
||||
ArraySetAsSeries(macdMainBuffer, true);
|
||||
SetIndexBuffer(macdMainBufferIndex, macdMainBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
ArraySetAsSeries(macdSignalBuffer, true);
|
||||
SetIndexBuffer(macdSignalBufferIndex, macdSignalBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,580 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XSTR
|
||||
// Description: Super Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// 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_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "X121_XSTR"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "ATR";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 3.0; // Multiplier
|
||||
input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showTrends = true; // Show Trends
|
||||
input bool fillTrends = true; // Fill Trends
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define fillUpBufferIndex 0
|
||||
double fillUpBuffer[];
|
||||
|
||||
#define fillDownBufferIndex 1
|
||||
double fillDownBuffer[];
|
||||
|
||||
//
|
||||
#define fillingPlotBufferIndex 0
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XSTR Filling"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 clrBisque, clrPaleGreen
|
||||
|
||||
//
|
||||
#define mainBufferIndex 2
|
||||
#define mainPlotBufferIndex 1
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainColorBufferIndex 3
|
||||
double mainColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XSTR"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define atrBufferIndex 4
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
#define trendBufferIndex 5
|
||||
double trendBuffer[];
|
||||
|
||||
//
|
||||
#define upBufferIndex 6
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#define downBufferIndex 7
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#define priceBufferIndex 8
|
||||
double priceBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
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();
|
||||
|
||||
//
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength);
|
||||
if (atrHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
int numOfRequiredAtrs;
|
||||
if (prev_calculated > rates_total || prev_calculated < 0)
|
||||
{
|
||||
numOfRequiredAtrs = rates_total;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
numOfRequiredAtrs = rates_total - prev_calculated;
|
||||
if (prev_calculated > 0)
|
||||
{
|
||||
numOfRequiredAtrs++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Checking for stop ...
|
||||
if (IsStopped())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Number of items Copy or not ...
|
||||
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
|
||||
if (copiedATRs <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
if (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
{
|
||||
//
|
||||
// starting index for calculation of all bars ...
|
||||
limit = maxLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// starting number for calculation of new bars
|
||||
limit = prev_calculated - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
double price = getPrice(
|
||||
atrAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
i);
|
||||
// price = (high[i] + low[i]) / 2;
|
||||
priceBuffer[i] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[i];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
upBuffer[i] = price + (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
downBuffer[i] = price - (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[i] > upBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[i] < downBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
|
||||
{
|
||||
downBuffer[i] = downBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
|
||||
{
|
||||
upBuffer[i] = upBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = 0;
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
|
||||
//
|
||||
if (trendBuffer[i] == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = downBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 1;
|
||||
}
|
||||
else if (trendBuffer[i] == -1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = upBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 2;
|
||||
}
|
||||
|
||||
//
|
||||
if (showTrends)
|
||||
{
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// Filling ...
|
||||
if (fillTrends)
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = mainBuffer[i];
|
||||
fillDownBuffer[i] = close[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = EMPTY_VALUE;
|
||||
fillDownBuffer[i] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
atrLength >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = atrLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// PLOT Buffers ...
|
||||
|
||||
//
|
||||
// FILLINGS ...
|
||||
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// MAIN ...
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends);
|
||||
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// UP ...
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// PRICE ...
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TEMPLATE Function ...
|
||||
|
||||
template <typename T>
|
||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
||||
{
|
||||
switch (tprice)
|
||||
{
|
||||
case PRICE_CLOSE:
|
||||
return (close[i]);
|
||||
case PRICE_OPEN:
|
||||
return (open[i]);
|
||||
case PRICE_HIGH:
|
||||
return (high[i]);
|
||||
case PRICE_LOW:
|
||||
return (low[i]);
|
||||
case PRICE_MEDIAN:
|
||||
return ((high[i] + low[i]) / 2.0);
|
||||
case PRICE_TYPICAL:
|
||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
||||
case PRICE_WEIGHTED:
|
||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,757 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XZG
|
||||
// Description: Zogzag Implementation ...
|
||||
//
|
||||
//
|
||||
// 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_XZG Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X121_XZG"
|
||||
|
||||
//
|
||||
// DEFINITIONS ...
|
||||
enum ENUM_X_ZG_SEARCH_MODE
|
||||
{
|
||||
X_ZG_SEARCH_EXTREMUM = 0, // searching for the first extremum
|
||||
X_ZG_SEARCH_PEAK = 1, // searching for the next ZigZag peak
|
||||
X_ZG_SEARCH_VALE = -1 // searching for the next ZigZag vale
|
||||
};
|
||||
|
||||
//
|
||||
// How to Calculate Up and Down Price ...
|
||||
enum ENUM_X_ZG_PRICE_MODE
|
||||
{
|
||||
//
|
||||
X_ZG_PRICE_HIGH_LOW_MODE = 1,
|
||||
X_ZG_PRICE_OPEN_CLOSE_MODE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// INPUT ...
|
||||
|
||||
//
|
||||
input int depth = 12; // Depth
|
||||
input int deviation = 5; // Deviation
|
||||
input int backStep = 3; // Back Step
|
||||
input ENUM_X_ZG_PRICE_MODE mode = X_ZG_PRICE_HIGH_LOW_MODE; // Mode
|
||||
|
||||
//
|
||||
// BUFFERS ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// ZigZag ...
|
||||
|
||||
//
|
||||
#define mainBufferIndex 0
|
||||
#define mainBufferPlotIndex 0
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XZG Main"
|
||||
#property indicator_type1 DRAW_SECTION
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Highs ...
|
||||
|
||||
//
|
||||
// ZigZag Pointer or Line Indicator ...
|
||||
#define arrowBufferIndex 1
|
||||
#define arrowBufferPlotIndex 1
|
||||
double arrowBuffer[];
|
||||
|
||||
//
|
||||
#define arrowColorBufferIndex 2
|
||||
double arrowColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XZG PV"
|
||||
#property indicator_type2 DRAW_COLOR_ARROW
|
||||
#property indicator_color2 clrAqua, clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define highsBufferIndex 3
|
||||
double highsBuffer[];
|
||||
|
||||
//
|
||||
// Lows ...
|
||||
|
||||
//
|
||||
#define lowsBufferIndex 4
|
||||
double lowsBuffer[];
|
||||
|
||||
//
|
||||
// VARIABLES ...
|
||||
|
||||
//
|
||||
int mRecalc = 3; // Number of last extremes for recalculation
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// logTag = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double mZGHigh[];
|
||||
double mZGLow[];
|
||||
if (mode == X_ZG_PRICE_OPEN_CLOSE_MODE)
|
||||
{
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGHigh,
|
||||
open
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGLow,
|
||||
close
|
||||
//
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGHigh,
|
||||
high
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGLow,
|
||||
low
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
int zigZagResult = CalcukateZigZag(
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
mZGHigh,
|
||||
mZGLow
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
if (zigZagResult != rates_total)
|
||||
{
|
||||
return zigZagResult;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
depth > 0 &&
|
||||
deviation > 0 &&
|
||||
backStep > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Main ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(mainBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Arrow ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(arrowBufferIndex, arrowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW, 159);
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW_SHIFT, 0);
|
||||
PlotIndexSetDouble(arrowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Arrow Color ...
|
||||
SetIndexBuffer(arrowColorBufferIndex, arrowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Highs ...
|
||||
SetIndexBuffer(highsBufferIndex, highsBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Lows ...
|
||||
SetIndexBuffer(lowsBufferIndex, lowsBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Zig Zag ...
|
||||
int CalcukateZigZag(
|
||||
const int prev_calculated,
|
||||
const int rates_total,
|
||||
double &high[],
|
||||
double &low[]
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
if (rates_total < 100)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Variables ...
|
||||
int i = 0;
|
||||
|
||||
//
|
||||
int start = 0;
|
||||
int extreme_counter = 0;
|
||||
int extreme_search = X_ZG_SEARCH_EXTREMUM;
|
||||
int shift = 0;
|
||||
int back = 0;
|
||||
int last_high_pos = 0;
|
||||
int last_low_pos = 0;
|
||||
|
||||
//
|
||||
double val = 0;
|
||||
double res = 0;
|
||||
double curlow = 0;
|
||||
double curhigh = 0;
|
||||
double last_high = 0;
|
||||
double last_low = 0;
|
||||
|
||||
//
|
||||
double colorIDX = 0;
|
||||
double lastZigZagValue = 0;
|
||||
|
||||
//
|
||||
// Initializing ...
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
//
|
||||
ArrayInitialize(mainBuffer, 0);
|
||||
ArrayInitialize(highsBuffer, 0);
|
||||
ArrayInitialize(lowsBuffer, 0);
|
||||
|
||||
//
|
||||
start = depth;
|
||||
}
|
||||
|
||||
//
|
||||
// Already Calculated Before ...
|
||||
if (prev_calculated > 0)
|
||||
{
|
||||
//
|
||||
i = rates_total - 1;
|
||||
|
||||
//
|
||||
// Searching for the third X_ZG_SEARCH_EXTREMUM from the last UnComplete Bar ...
|
||||
while (extreme_counter < mRecalc && i > rates_total - 100)
|
||||
{
|
||||
//
|
||||
res = mainBuffer[i];
|
||||
if (res != 0)
|
||||
{
|
||||
extreme_counter++;
|
||||
}
|
||||
|
||||
//
|
||||
i--;
|
||||
}
|
||||
|
||||
//
|
||||
i++;
|
||||
start = i;
|
||||
|
||||
//
|
||||
// What type of X_ZG_SEARCH_EXTREMUM we Search for ...
|
||||
if (lowsBuffer[i] != 0)
|
||||
{
|
||||
//
|
||||
curlow = lowsBuffer[i];
|
||||
extreme_search = X_ZG_SEARCH_PEAK;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
curhigh = highsBuffer[i];
|
||||
extreme_search = X_ZG_SEARCH_VALE;
|
||||
}
|
||||
|
||||
//
|
||||
// Clear Values ...
|
||||
for (i = start + 1; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = 0;
|
||||
lowsBuffer[i] = 0;
|
||||
highsBuffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Search for High and Low Extremes ...
|
||||
for (shift = start; shift < rates_total && !IsStopped(); shift++)
|
||||
{
|
||||
//
|
||||
// Low ...
|
||||
val = low[Lowest(low, depth, shift)];
|
||||
if (val == last_low)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
last_low = val;
|
||||
|
||||
//
|
||||
if ((low[shift] - val) > deviation * _Point)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
for (back = 1; back <= backStep; back++)
|
||||
{
|
||||
//
|
||||
res = lowsBuffer[shift - back];
|
||||
if ((res != 0) && (res > val))
|
||||
{
|
||||
lowsBuffer[shift - back] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (low[shift] == val)
|
||||
{
|
||||
lowsBuffer[shift] = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
lowsBuffer[shift] = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// High ...
|
||||
val = high[Highest(high, depth, shift)];
|
||||
if (val == last_high)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
last_high = val;
|
||||
|
||||
//
|
||||
if ((val - high[shift]) > deviation * _Point)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
for (back = 1; back <= backStep; back++)
|
||||
{
|
||||
//
|
||||
res = highsBuffer[shift - back];
|
||||
if ((res != 0) && (res < val))
|
||||
{
|
||||
highsBuffer[shift - back] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (high[shift] == val)
|
||||
{
|
||||
highsBuffer[shift] = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
highsBuffer[shift] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Set Last Value ...
|
||||
if (extreme_search == 0) // Undefined Values ...
|
||||
{
|
||||
//
|
||||
last_low = 0;
|
||||
last_high = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
last_low = curlow;
|
||||
last_high = curhigh;
|
||||
}
|
||||
|
||||
//
|
||||
// Final Selection of Extreme Points for ZigZag ...
|
||||
for (shift = start; shift < rates_total && !IsStopped(); shift++)
|
||||
{
|
||||
//
|
||||
res = 0;
|
||||
|
||||
//
|
||||
switch (extreme_search)
|
||||
{
|
||||
//
|
||||
case X_ZG_SEARCH_EXTREMUM:
|
||||
//
|
||||
if (last_low == 0 && last_high == 0)
|
||||
{
|
||||
//
|
||||
if (highsBuffer[shift] != 0)
|
||||
{
|
||||
//
|
||||
last_high_pos = shift;
|
||||
last_high = high[shift];
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_VALE;
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_high;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (lowsBuffer[shift] != 0)
|
||||
{
|
||||
//
|
||||
last_low_pos = shift;
|
||||
last_low = low[shift];
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_PEAK;
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_low;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
case X_ZG_SEARCH_PEAK:
|
||||
//
|
||||
if (lowsBuffer[shift] != 0 && lowsBuffer[shift] < last_low && highsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
mainBuffer[last_low_pos] = 0;
|
||||
|
||||
//
|
||||
last_low_pos = shift;
|
||||
last_low = lowsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_low;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (highsBuffer[shift] != 0 && lowsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
last_high_pos = shift;
|
||||
last_high = highsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_high;
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_VALE;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
case X_ZG_SEARCH_VALE:
|
||||
//
|
||||
if (highsBuffer[shift] != 0 && highsBuffer[shift] > last_high && lowsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
mainBuffer[last_high_pos] = 0;
|
||||
|
||||
//
|
||||
last_high_pos = shift;
|
||||
last_high = highsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_high;
|
||||
}
|
||||
|
||||
//
|
||||
if (lowsBuffer[shift] != 0 && highsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
last_low_pos = shift;
|
||||
last_low = lowsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_low;
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_PEAK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
double iZigZagForColor = lastZigZagValue;
|
||||
double iZigZag = mainBuffer[shift];
|
||||
if (iZigZag == 0 && lastZigZagValue != 0)
|
||||
{
|
||||
arrowBuffer[shift] = lastZigZagValue;
|
||||
}
|
||||
else if (iZigZag != 0)
|
||||
{
|
||||
//
|
||||
lastZigZagValue = iZigZag;
|
||||
arrowBuffer[shift] = lastZigZagValue;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX =
|
||||
lastZigZagValue > iZigZagForColor
|
||||
? 0
|
||||
: lastZigZagValue < iZigZagForColor
|
||||
? 1
|
||||
: colorIDX;
|
||||
arrowColorBuffer[shift] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// TOOLS ...
|
||||
|
||||
//
|
||||
// Search for the index of the highest bar ...
|
||||
int Highest(
|
||||
const double &mArray[],
|
||||
const int mDepth,
|
||||
const int mStart //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (mStart < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double max = mArray[mStart];
|
||||
result = mStart;
|
||||
|
||||
//
|
||||
// Start searching ...
|
||||
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
|
||||
{
|
||||
//
|
||||
if (mArray[i] > max)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
max = mArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Return index of the highest bar
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Search for the index of the lowest bar ...
|
||||
int Lowest(
|
||||
const double &mArray[],
|
||||
const int mDepth,
|
||||
const int mStart //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (mStart < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double min = mArray[mStart];
|
||||
result = mStart;
|
||||
|
||||
//
|
||||
// Start searching ...
|
||||
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
|
||||
{
|
||||
//
|
||||
if (mArray[i] < min)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
min = mArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Return index of the lowest bar
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,775 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCHNL
|
||||
// Description: XCHL Channel Indicator ...
|
||||
//
|
||||
//
|
||||
// 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_XCHNL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCHNL"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// END XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret Cycles";
|
||||
input int shortLength = 9; // Short Length
|
||||
input int mediumLength = 17; // Medium Length
|
||||
input int longLength = 26; // Long Length
|
||||
input int hindLength = 35; // Hind Length
|
||||
|
||||
//
|
||||
input group "Trend";
|
||||
input int numOfShoulder = 10; // Number of Shoulders for Swings
|
||||
|
||||
//
|
||||
input group "Detection Modes";
|
||||
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTrend = false; // Show Trend
|
||||
input bool showSRs = false; // Show Support and Resistance
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// PEKSANDVALES ...
|
||||
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 0
|
||||
|
||||
#define sHHBufferIndex 0
|
||||
#define sLLBufferIndex 1
|
||||
#define mHHBufferIndex 2
|
||||
#define mLLBufferIndex 3
|
||||
#define lHHBufferIndex 4
|
||||
#define lLLBufferIndex 5
|
||||
#define hHHBufferIndex 6
|
||||
#define hLLBufferIndex 7
|
||||
|
||||
double sHHBuffer[];
|
||||
double sLLBuffer[];
|
||||
double mHHBuffer[];
|
||||
double mLLBuffer[];
|
||||
double lHHBuffer[];
|
||||
double lLLBuffer[];
|
||||
double hHHBuffer[];
|
||||
double hLLBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Make an Instance of Hull Class ...
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod 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
|
||||
|
||||
//
|
||||
RemoveDraws(drawPrefix);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Validate Peaks and Vales ...
|
||||
(shortLength > 2 &&
|
||||
mediumLength > shortLength &&
|
||||
longLength > mediumLength &&
|
||||
hindLength > longLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
result = MathMax(shortLength, mediumLength);
|
||||
result = MathMax(result, longLength);
|
||||
result = MathMax(result, hindLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate ...
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int sHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sHHValue = GetAppliedPrice(
|
||||
sHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
sHHBuffer[bar_index] = sHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int sLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sLLValue = GetAppliedPrice(
|
||||
sLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
sLLBuffer[bar_index] = sLLValue;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int mHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mHHValue = GetAppliedPrice(
|
||||
mHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
mHHBuffer[bar_index] = mHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int mLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mLLValue = GetAppliedPrice(
|
||||
mLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
mLLBuffer[bar_index] = mLLValue;
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int lHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lHHValue = GetAppliedPrice(
|
||||
lHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
lHHBuffer[bar_index] = lHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int lLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lLLValue = GetAppliedPrice(
|
||||
lLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
lLLBuffer[bar_index] = lLLValue;
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int hHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hHHValue = GetAppliedPrice(
|
||||
hHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
hHHBuffer[bar_index] = hHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int hLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hLLValue = GetAppliedPrice(
|
||||
hLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
hLLBuffer[bar_index] = hLLValue;
|
||||
|
||||
//
|
||||
// Find Swings ...
|
||||
|
||||
//
|
||||
// High ...
|
||||
int hSwing1 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
bar_index + 1);
|
||||
|
||||
int hSwing2 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
hSwing1 + 1);
|
||||
|
||||
//
|
||||
// High ...
|
||||
int hSwing3 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
hSwing2 + 1);
|
||||
|
||||
// int hSwing4 = FindSwing(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// MODE_HIGH,
|
||||
// numOfShoulder,
|
||||
// hSwing3 + 1);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
int lSwing1 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
bar_index + 1);
|
||||
|
||||
int lSwing2 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
lSwing1 + 1);
|
||||
|
||||
int lSwing3 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
lSwing2 + 1);
|
||||
|
||||
// int lSwing4 = FindSwing(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// MODE_LOW,
|
||||
// numOfShoulder,
|
||||
// lSwing3 + 1);
|
||||
|
||||
//
|
||||
if (bar_index < 50)
|
||||
{
|
||||
|
||||
//
|
||||
bool isStrongResistance =
|
||||
//
|
||||
hHHBuffer[bar_index + 1] == hHHBuffer[bar_index + 2] &&
|
||||
hHHBuffer[bar_index + 2] == hHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
lHHBuffer[bar_index + 1] == lHHBuffer[bar_index + 2] &&
|
||||
lHHBuffer[bar_index + 2] == lHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
mHHBuffer[bar_index + 1] == mHHBuffer[bar_index + 2] &&
|
||||
mHHBuffer[bar_index + 2] == mHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
sHHBuffer[bar_index + 1] == sHHBuffer[bar_index + 2] &&
|
||||
sHHBuffer[bar_index + 2] == sHHBuffer[bar_index + 3]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isStrongSupport =
|
||||
//
|
||||
hLLBuffer[bar_index + 1] == hLLBuffer[bar_index + 2] &&
|
||||
hLLBuffer[bar_index + 2] == hLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
lLLBuffer[bar_index + 1] == lLLBuffer[bar_index + 2] &&
|
||||
lLLBuffer[bar_index + 2] == lLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
mLLBuffer[bar_index + 1] == mLLBuffer[bar_index + 2] &&
|
||||
mLLBuffer[bar_index + 2] == mLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
sLLBuffer[bar_index + 1] == sLLBuffer[bar_index + 2] &&
|
||||
sLLBuffer[bar_index + 2] == sLLBuffer[bar_index + 3]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isStrongResistance && showSRs)
|
||||
{
|
||||
//
|
||||
DrawSupportResistance(
|
||||
"R",
|
||||
clrRed,
|
||||
sHHBuffer[bar_index + 3],
|
||||
bar_index + 3);
|
||||
}
|
||||
|
||||
//
|
||||
if (isStrongSupport && showSRs)
|
||||
{
|
||||
//
|
||||
DrawSupportResistance(
|
||||
"S",
|
||||
clrGreen,
|
||||
sLLBuffer[bar_index + 3],
|
||||
bar_index + 3);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (showTrend && bar_index < 20)
|
||||
{
|
||||
//
|
||||
DrawSwing(
|
||||
"High1",
|
||||
MODE_HIGH,
|
||||
clrAqua,
|
||||
hSwing1,
|
||||
hSwing2);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"Low1",
|
||||
MODE_LOW,
|
||||
clrAqua,
|
||||
lSwing1,
|
||||
lSwing2);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"High2",
|
||||
MODE_HIGH,
|
||||
clrMagenta,
|
||||
hSwing2,
|
||||
hSwing3);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"Low2",
|
||||
MODE_LOW,
|
||||
clrMagenta,
|
||||
lSwing2,
|
||||
lSwing3);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void DrawSwing(
|
||||
string prefix, // Prefix ...
|
||||
ENUM_SERIESMODE mode, // Swing Mode ...
|
||||
color swingColor, // Color ...
|
||||
int index1, // Index 1 ...
|
||||
int index2 // Index 2 ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (mode != MODE_HIGH && mode != MODE_LOW)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL c1 = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index1);
|
||||
|
||||
//
|
||||
datetime time1 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index1);
|
||||
|
||||
//
|
||||
XOHCL c2 = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index2);
|
||||
|
||||
//
|
||||
datetime time2 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index2);
|
||||
|
||||
//
|
||||
double value1 = -1;
|
||||
double value2 = -1;
|
||||
|
||||
//
|
||||
switch (mode)
|
||||
{
|
||||
//
|
||||
case MODE_HIGH:
|
||||
value1 = c1.high;
|
||||
value2 = c2.high;
|
||||
break;
|
||||
|
||||
//
|
||||
case MODE_LOW:
|
||||
value1 = c1.low;
|
||||
value2 = c2.low;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
if (value1 == -1 || value2 == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
long chartId = ChartID();
|
||||
string tlName = prefix + "_" + "TrendLine";
|
||||
|
||||
// //
|
||||
// if (IsDrawExists(tlName)) {
|
||||
// RemoveDraw(tlName);
|
||||
// }
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartId,
|
||||
tlName,
|
||||
0,
|
||||
time2,
|
||||
value2,
|
||||
time1,
|
||||
value1,
|
||||
swingColor,
|
||||
STYLE_DOT,
|
||||
3,
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Support and Resistance ...
|
||||
void DrawSupportResistance(
|
||||
string prefix, // Prefix ...
|
||||
color lColor, // Color ...
|
||||
double price, // Support or Resistance price ...
|
||||
int bar_index // Start Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
datetime time1 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
datetime time2 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index - 1);
|
||||
|
||||
//
|
||||
long chartId = ChartID();
|
||||
string tlName = prefix + "_" + "TL" + "_" + (string)(NormalizePrice(price, _Symbol));
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartId,
|
||||
tlName,
|
||||
0,
|
||||
time1,
|
||||
price,
|
||||
time2,
|
||||
price,
|
||||
lColor,
|
||||
STYLE_DOT,
|
||||
3,
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,365 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XDON
|
||||
// Description: DONCHAIN Channel ...
|
||||
//
|
||||
// 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 XDON Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XDON"
|
||||
|
||||
//
|
||||
// INPUT ...
|
||||
|
||||
//
|
||||
input int length = 52; // Market Length
|
||||
input double offset = 0; // Offset
|
||||
|
||||
//
|
||||
// BUFFERS ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
#define upperOBufferIndex 0
|
||||
double upperOBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XDON OU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrCornflowerBlue
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
#define lowerOBufferIndex 1
|
||||
double lowerOBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XDON OL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrCornflowerBlue
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
#define upperCBufferIndex 2
|
||||
double upperCBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XDON CU"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrCoral
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
#define lowerCBufferIndex 3
|
||||
double lowerCBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XDON CL"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrCoral
|
||||
#property indicator_width4 2
|
||||
|
||||
//
|
||||
#define upperHBufferIndex 4
|
||||
double upperHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XDON HU"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrAquamarine
|
||||
#property indicator_width5 2
|
||||
|
||||
//
|
||||
#define lowerHBufferIndex 5
|
||||
double lowerHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "XDON HL"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrAquamarine
|
||||
#property indicator_width6 2
|
||||
|
||||
//
|
||||
#define upperLBufferIndex 6
|
||||
double upperLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "XDON LU"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrDarkOrchid
|
||||
#property indicator_width7 2
|
||||
|
||||
//
|
||||
#define lowerLBufferIndex 7
|
||||
double lowerLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "XDON LL"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrDarkOrchid
|
||||
#property indicator_width8 2
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
if (rates_total < length - 1)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
int start = prev_calculated == 0
|
||||
? length
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int barIndex = start; barIndex < rates_total; barIndex++)
|
||||
{
|
||||
//
|
||||
// OPEN ...
|
||||
|
||||
//
|
||||
double upperOValue = open[ArrayMaximum(open, barIndex - length + 1, length)];
|
||||
double lowerOValue = open[ArrayMinimum(open, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double oDelta = MathAbs(upperOValue - lowerOValue);
|
||||
double oOffsetValue = oDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperOBuffer[barIndex] = upperOValue - oOffsetValue;
|
||||
lowerOBuffer[barIndex] = lowerOValue + oOffsetValue;
|
||||
|
||||
//
|
||||
// CLOSE ...
|
||||
|
||||
//
|
||||
double upperCValue = close[ArrayMaximum(close, barIndex - length + 1, length)];
|
||||
double lowerCValue = close[ArrayMinimum(close, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double cDelta = MathAbs(upperCValue - lowerCValue);
|
||||
double cOffsetValue = cDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperCBuffer[barIndex] = upperCValue - cOffsetValue;
|
||||
lowerCBuffer[barIndex] = lowerCValue + cOffsetValue;
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
|
||||
//
|
||||
double upperHValue = high[ArrayMaximum(high, barIndex - length + 1, length)];
|
||||
double lowerHValue = high[ArrayMinimum(high, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double hDelta = MathAbs(upperHValue - lowerHValue);
|
||||
double hOffsetValue = hDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperHBuffer[barIndex] = upperHValue - hOffsetValue;
|
||||
lowerHBuffer[barIndex] = lowerHValue + hOffsetValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
|
||||
//
|
||||
double upperLValue = low[ArrayMaximum(low, barIndex - length + 1, length)];
|
||||
double lowerLValue = low[ArrayMinimum(low, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double lDelta = MathAbs(upperLValue - lowerLValue);
|
||||
double lOffsetValue = lDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperLBuffer[barIndex] = upperLValue - lOffsetValue;
|
||||
lowerLBuffer[barIndex] = lowerLValue + lOffsetValue;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = length >= 7;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperOBufferIndex, upperOBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperOBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(upperOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerOBufferIndex, lowerOBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerOBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(lowerOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperCBufferIndex, upperCBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperCBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(upperCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerCBufferIndex, lowerCBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerCBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(lowerCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperHBufferIndex, upperHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperHBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(upperHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerHBufferIndex, lowerHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerHBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(lowerHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperLBufferIndex, upperLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperLBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(upperLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerLBufferIndex, lowerLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerLBufferIndex, PLOT_SHOW_DATA, true);
|
||||
PlotIndexSetDouble(lowerLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
Reference in New Issue
Block a user