update workspace ...
This commit is contained in:
Binary file not shown.
@@ -1,350 +0,0 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XAMA
|
||||
// Description: Trend Magic 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_XAMA"
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 0,
|
||||
X_XAMA_BEARISH = 2,
|
||||
X_XAMA_NEUTURAL = 1,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret";
|
||||
input int length = 52; // Length
|
||||
input int fastEMA = 2; // Fast EMA Length
|
||||
input int slowEMA = 30; // Slow EMA Length
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLine = true; // Show Line
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
|
||||
#property indicator_label1 "X121_XAMA"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int maHandler = 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 MA Handler ...
|
||||
maHandler = iAMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
fastEMA,
|
||||
slowEMA,
|
||||
maShift,
|
||||
appliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
Print(message);
|
||||
|
||||
//
|
||||
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(maHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -1,454 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Styles
|
||||
// ---------------------------------------------------
|
||||
// Name: X121_CC
|
||||
// Description: Candle Styles ...
|
||||
//
|
||||
//
|
||||
// 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_CC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_CC"
|
||||
|
||||
//
|
||||
// Holds an SnapShot of Charts Configuration ...
|
||||
struct XChartStyle
|
||||
{
|
||||
//
|
||||
// chart's ID ...
|
||||
long chartId;
|
||||
//
|
||||
// chart's mode ...
|
||||
ENUM_CHART_MODE mode;
|
||||
//
|
||||
// show bid line ...
|
||||
bool showBidLine;
|
||||
//
|
||||
// show ask line ...
|
||||
bool showAskLine;
|
||||
//
|
||||
// show grids on chart ...
|
||||
bool showGrid;
|
||||
//
|
||||
// show volumes ...
|
||||
bool showVolumes;
|
||||
//
|
||||
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
|
||||
bool showTradeLevels;
|
||||
//
|
||||
// chart autoscroll ...
|
||||
bool autoScroll;
|
||||
//
|
||||
// chart quick navigation state ...
|
||||
bool quickNavigation;
|
||||
//
|
||||
// chart's foreground color ...
|
||||
color foreGroundColor;
|
||||
//
|
||||
// chart's background color ...
|
||||
color backGroundColor;
|
||||
//
|
||||
// Up Color ...
|
||||
color upColor;
|
||||
//
|
||||
// Down Color ...
|
||||
color downColor;
|
||||
//
|
||||
// Bullish color ...
|
||||
color bullishColor;
|
||||
//
|
||||
// Bearish color ...
|
||||
color bearishColor;
|
||||
//
|
||||
// grid color ...
|
||||
color gridColor;
|
||||
//
|
||||
// bid line color ...
|
||||
color bidLineColor;
|
||||
//
|
||||
// ask line color ...
|
||||
color askLineColor;
|
||||
//
|
||||
// line mode and doji candlestick color ...
|
||||
color lineColor;
|
||||
//
|
||||
// Color of stop order levels (Stop Loss and Take Profit) ...
|
||||
color stopColor;
|
||||
//
|
||||
// volumes color ...
|
||||
color volumesColor;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Chart Style";
|
||||
input color upColor = clrLime; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrLime; // Line mode and Doji candlestick Color
|
||||
input color bearishColor = clrRed; // Bullish Color
|
||||
input color bullishColor = clrLime; // Bearish Color
|
||||
input color volumesColor = clrGreen; // Volumes Color
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandles = true; // Show Candles
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XChartStyle chartStyle;
|
||||
XChartStyle clearStyle;
|
||||
|
||||
//
|
||||
// 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();
|
||||
|
||||
//
|
||||
// Apply Chart Style ...
|
||||
ApplyCustomChartStyle();
|
||||
|
||||
//
|
||||
// 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 : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Custom Chart Style ...
|
||||
void ApplyCustomChartStyle()
|
||||
{
|
||||
//
|
||||
// Read Current Chart Config and Store it ...
|
||||
ReadChartStyle();
|
||||
|
||||
//
|
||||
// After Reading Current Chart Style ...
|
||||
// we have to Save Configs and Change Styles ...
|
||||
clearStyle = chartStyle;
|
||||
|
||||
//
|
||||
clearStyle.upColor = CLR_NONE;
|
||||
clearStyle.downColor = CLR_NONE;
|
||||
clearStyle.lineColor = CLR_NONE;
|
||||
clearStyle.bullishColor = CLR_NONE;
|
||||
clearStyle.bearishColor = CLR_NONE;
|
||||
|
||||
//
|
||||
// Decide to Show or not Candles based on User Input ...
|
||||
if (showCandles)
|
||||
{
|
||||
SetChartStyle(chartStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChartStyle(clearStyle);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read Previous Chart Style ...
|
||||
void ReadChartStyle()
|
||||
{
|
||||
//
|
||||
// Retrieve Current Chart ID ...
|
||||
long chartId = ChartID();
|
||||
chartStyle.chartId = chartId;
|
||||
|
||||
//
|
||||
// Retrieve Chart Mode ...
|
||||
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
|
||||
|
||||
//
|
||||
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
|
||||
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
|
||||
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
|
||||
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
|
||||
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
|
||||
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
|
||||
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
|
||||
|
||||
//
|
||||
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
|
||||
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
|
||||
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
|
||||
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
|
||||
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
|
||||
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
|
||||
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
|
||||
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
|
||||
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
|
||||
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
|
||||
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
|
||||
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
|
||||
|
||||
//
|
||||
chartStyle.upColor = upColor;
|
||||
chartStyle.downColor = downColor;
|
||||
chartStyle.lineColor = lineColor;
|
||||
chartStyle.bearishColor = bearishColor;
|
||||
chartStyle.bullishColor = bullishColor;
|
||||
chartStyle.volumesColor = volumesColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
void SetChartStyle(
|
||||
XChartStyle &mChartStyle // Chart Style to Apply
|
||||
)
|
||||
{
|
||||
//
|
||||
ApplyChartStyle(
|
||||
mChartStyle.chartId,
|
||||
mChartStyle.mode,
|
||||
mChartStyle.showBidLine,
|
||||
mChartStyle.showAskLine,
|
||||
mChartStyle.showGrid,
|
||||
mChartStyle.showVolumes,
|
||||
mChartStyle.showTradeLevels,
|
||||
mChartStyle.autoScroll,
|
||||
mChartStyle.quickNavigation,
|
||||
mChartStyle.foreGroundColor,
|
||||
mChartStyle.backGroundColor,
|
||||
mChartStyle.upColor,
|
||||
mChartStyle.downColor,
|
||||
mChartStyle.bullishColor,
|
||||
mChartStyle.bearishColor,
|
||||
mChartStyle.gridColor,
|
||||
mChartStyle.bidLineColor,
|
||||
mChartStyle.askLineColor,
|
||||
mChartStyle.lineColor,
|
||||
mChartStyle.stopColor,
|
||||
mChartStyle.volumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,264 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCT
|
||||
// Description: Trend Magic 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_XCT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCT"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandleTime = true; // Show Candle Time
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (showCandleTime)
|
||||
{
|
||||
CreateIndicatorObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjectDelete(0, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Delete Object ...
|
||||
ObjectDelete(0, ShortName);
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// 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[])
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(time, true);
|
||||
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
XCandleRemains remainTime;
|
||||
GetCandleRemainsTime(
|
||||
remainTime,
|
||||
_Symbol,
|
||||
_Period,
|
||||
0);
|
||||
|
||||
//
|
||||
string msg = ToString(
|
||||
remainTime,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
":",
|
||||
true);
|
||||
|
||||
//
|
||||
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
|
||||
|
||||
//
|
||||
string _sp = "";
|
||||
if (mSpread < 10)
|
||||
_sp = "..";
|
||||
else if (mSpread < 100)
|
||||
_sp = ".";
|
||||
|
||||
//
|
||||
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in: " + msg;
|
||||
|
||||
//
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_COLOR, clr);
|
||||
ObjectSetString(0, ShortName, OBJPROP_TEXT, objText);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_FONTSIZE, 10);
|
||||
ObjectSetString(0, ShortName, OBJPROP_FONT, "Courier");
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
void CreateIndicatorObject()
|
||||
{
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
|
||||
|
||||
//
|
||||
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
|
||||
switch (corner)
|
||||
{
|
||||
case CORNER_LEFT_UPPER:
|
||||
Anchor = ANCHOR_LEFT_UPPER;
|
||||
break;
|
||||
case CORNER_RIGHT_UPPER:
|
||||
Anchor = ANCHOR_RIGHT_UPPER;
|
||||
break;
|
||||
case CORNER_LEFT_LOWER:
|
||||
Anchor = ANCHOR_LEFT_LOWER;
|
||||
break;
|
||||
case CORNER_RIGHT_LOWER:
|
||||
Anchor = ANCHOR_RIGHT_LOWER;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -1,486 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------------
|
||||
// Name: X121_HK
|
||||
// Description: Hiken Ashi ...
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XHK Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XHK"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool drawCandles = true; // Draw Hiken Ashi Candle
|
||||
input bool drawCandleLines = false; // Show HikenAshi Lines
|
||||
|
||||
//
|
||||
// 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 13
|
||||
#property indicator_plots 5
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
#define openBufferIndex 0
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define highBufferIndex 1
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define lowBufferIndex 2
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
// Close ...
|
||||
#define closeBufferIndex 3
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
// Candle Color ...
|
||||
#define candleColorBufferIndex 4
|
||||
double candleColorBuffer[];
|
||||
|
||||
//
|
||||
#define candlesBufferIndex 0
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XHK Open;X121_XHK High;X121_XHK Low;X121_XHK Close"
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 clrAqua, clrMagenta, CLR_NONE
|
||||
|
||||
//
|
||||
#define openHKBufferIndex 5
|
||||
#define openHKColorBufferIndex 6
|
||||
double openHKBuffer[];
|
||||
double openHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define openHKBufferPlotIndex 1
|
||||
#property indicator_label2 "X121_XHK O"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define highHKBufferIndex 7
|
||||
#define highHKColorBufferIndex 8
|
||||
double highHKBuffer[];
|
||||
double highHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define highHKBufferPlotIndex 2
|
||||
#property indicator_label3 "X121_XHK H"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define lowHKBufferIndex 9
|
||||
#define lowHKColorBufferIndex 10
|
||||
double lowHKBuffer[];
|
||||
double lowHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define lowHKBufferPlotIndex 3
|
||||
#property indicator_label4 "X121_XHK L"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
#define closeHKBufferIndex 11
|
||||
#define closeHKColorBufferIndex 12
|
||||
double closeHKBuffer[];
|
||||
double closeHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define closeHKBufferPlotIndex 4
|
||||
#property indicator_label5 "X121_XHK C"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 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
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i, prev_calculated, rates_total, open, high, close, low);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Candles Color ...
|
||||
ArraySetAsSeries(candleColorBuffer, true);
|
||||
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(candleColorBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, false);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open HK ...
|
||||
ENUM_DRAW_TYPE openDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(openHKBuffer, true);
|
||||
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_DRAW_TYPE, openDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(openHKColorBuffer, true);
|
||||
SetIndexBuffer(openHKColorBufferIndex, openHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// High HK ...
|
||||
ENUM_DRAW_TYPE highDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(highHKBuffer, true);
|
||||
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_DRAW_TYPE, highDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(highHKColorBuffer, true);
|
||||
SetIndexBuffer(highHKColorBufferIndex, highHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Low HK ...
|
||||
ENUM_DRAW_TYPE lowDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(lowHKBuffer, true);
|
||||
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_DRAW_TYPE, lowDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lowHKColorBuffer, true);
|
||||
SetIndexBuffer(lowHKColorBufferIndex, lowHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Close HK ...
|
||||
ENUM_DRAW_TYPE closeDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(closeHKBuffer, true);
|
||||
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_DRAW_TYPE, closeDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(closeHKColorBuffer, true);
|
||||
SetIndexBuffer(closeHKColorBufferIndex, closeHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[])
|
||||
{
|
||||
//
|
||||
double mPrevHKOpenValue;
|
||||
double mPrevHKCloseValue;
|
||||
|
||||
//
|
||||
if (ArraySize(open) <= bar_index + 1)
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = 0;
|
||||
mPrevHKCloseValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = openBuffer[bar_index + 1];
|
||||
mPrevHKCloseValue = closeBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
|
||||
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
|
||||
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
|
||||
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
|
||||
|
||||
//
|
||||
openBuffer[bar_index] = mHKOpenValue;
|
||||
highBuffer[bar_index] = mHKHighValue;
|
||||
lowBuffer[bar_index] = mHKLowValue;
|
||||
closeBuffer[bar_index] = mHKCloseValue;
|
||||
|
||||
//
|
||||
double candleColorValue =
|
||||
mHKOpenValue < mHKCloseValue ? 0 : 1;
|
||||
|
||||
//
|
||||
candleColorBuffer[bar_index] = drawCandles ? candleColorValue : 2;
|
||||
|
||||
//
|
||||
openHKBuffer[bar_index] = mHKOpenValue;
|
||||
openHKColorBuffer[bar_index] = candleColorValue;
|
||||
|
||||
//
|
||||
highHKBuffer[bar_index] = mHKHighValue;
|
||||
highHKColorBuffer[bar_index] = candleColorValue;
|
||||
|
||||
//
|
||||
lowHKBuffer[bar_index] = mHKLowValue;
|
||||
lowHKColorBuffer[bar_index] = candleColorValue;
|
||||
|
||||
//
|
||||
closeHKBuffer[bar_index] = mHKCloseValue;
|
||||
closeHKColorBuffer[bar_index] = candleColorValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -1,602 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XHULL
|
||||
// Description: Hull 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_XHULL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XHULL"
|
||||
|
||||
//
|
||||
struct XHullData
|
||||
{
|
||||
//
|
||||
double value;
|
||||
double value3;
|
||||
|
||||
//
|
||||
double wsum1;
|
||||
double wsum2;
|
||||
double wsum3;
|
||||
|
||||
//
|
||||
double lsum1;
|
||||
double lsum2;
|
||||
double lsum3;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class For Hull Calculations ...
|
||||
class XSCHull
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
|
||||
{
|
||||
//
|
||||
// These are a way above to assign Private variables at Construct time ...
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCHull()
|
||||
{
|
||||
ArrayFree(mData);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Hull ...
|
||||
bool Init(
|
||||
int mPeriod,
|
||||
double mDivisor)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mFullPeriod = (int)(mPeriod > 1 ? mPeriod : 1);
|
||||
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (mDivisor > 1 ? mDivisor : 1) : 1);
|
||||
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
|
||||
|
||||
//
|
||||
mArraySize = -1;
|
||||
mWeight1 = mWeight2 = mWeight3 = 1;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// CalCulate Specific Value ...
|
||||
double Calculate(
|
||||
double value,
|
||||
int i,
|
||||
int bars)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (mArraySize < bars)
|
||||
{
|
||||
//
|
||||
mArraySize = ArrayResize(mData, bars + 500);
|
||||
if (mArraySize < bars)
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].value = value;
|
||||
if (i > mFullPeriod)
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
|
||||
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
|
||||
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
|
||||
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 = mData[i].wsum2 =
|
||||
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
|
||||
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
|
||||
{
|
||||
//
|
||||
if (w1 > 0)
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 += mData[i - k].value * w1;
|
||||
mData[i].lsum1 += mData[i - k].value;
|
||||
mWeight1 += w1;
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].wsum2 += mData[i - k].value * w2;
|
||||
mData[i].lsum2 += mData[i - k].value;
|
||||
mWeight2 += w2;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
|
||||
|
||||
//
|
||||
if (i > mSqrtPeriod)
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
|
||||
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 =
|
||||
mData[i].lsum3 = mWeight3 = 0;
|
||||
|
||||
//
|
||||
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 += mData[i - k].value3 * w3;
|
||||
mData[i].lsum3 += mData[i - k].value3;
|
||||
mWeight3 += w3;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = mData[i].wsum3 / mWeight3;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
int mFullPeriod;
|
||||
int mHalfPeriod;
|
||||
int mSqrtPeriod;
|
||||
int mArraySize;
|
||||
double mWeight1;
|
||||
double mWeight2;
|
||||
double mWeight3;
|
||||
|
||||
//
|
||||
XHullData mData[];
|
||||
};
|
||||
|
||||
//
|
||||
// END XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 72; // Length
|
||||
input double divisor = 2.0; // Divisor (Speed)
|
||||
|
||||
//
|
||||
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 showUpZone = true; // Show Up Zone
|
||||
input bool showDownZone = true; // Show Down Zone
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// UP Zone ...
|
||||
|
||||
//
|
||||
#define upZoneBufferIndex 0
|
||||
#define upZoneColorBufferIndex 1
|
||||
|
||||
//
|
||||
double upZoneBuffer[];
|
||||
double upZoneColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XHULL Up"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLightGray, clrAqua, clrMagenta
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// DOWN Zone ...
|
||||
|
||||
//
|
||||
#define downZoneBufferIndex 2
|
||||
#define downZoneColorBufferIndex 3
|
||||
|
||||
//
|
||||
double downZoneBuffer[];
|
||||
double downZoneColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XHULL Down"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrLightGray, clrAqua, clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XSCHull *mUpZHull;
|
||||
XSCHull *mDownZHull;
|
||||
|
||||
//
|
||||
// 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();
|
||||
|
||||
//
|
||||
// Make an Instance of Hull Class ...
|
||||
|
||||
//
|
||||
mUpZHull = new XSCHull();
|
||||
mUpZHull.Init(
|
||||
length,
|
||||
divisor);
|
||||
|
||||
//
|
||||
mDownZHull = new XSCHull();
|
||||
mDownZHull.Init(
|
||||
length,
|
||||
divisor);
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
delete mUpZHull;
|
||||
delete mDownZHull;
|
||||
}
|
||||
|
||||
//
|
||||
// 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++)
|
||||
{
|
||||
//
|
||||
double upPrice = getPrice(
|
||||
upAppliedTo,
|
||||
open, high, low, close, i);
|
||||
|
||||
//
|
||||
double downPrice = getPrice(
|
||||
downAppliedTo,
|
||||
open, high, low, close, i);
|
||||
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
rates_total,
|
||||
upPrice,
|
||||
downPrice);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
length >= 9 &&
|
||||
divisor >= 0.5;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
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()
|
||||
{
|
||||
//
|
||||
// UP Zone ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE upZoneDrawType = showUpZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(upZoneBufferIndex, upZoneBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_SHOW_DATA, showUpZone);
|
||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_DRAW_TYPE, upZoneDrawType);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
SetIndexBuffer(upZoneColorBufferIndex, upZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN Zone ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE downZoneDrawType = showDownZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(downZoneBufferIndex, downZoneBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_SHOW_DATA, showDownZone);
|
||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_DRAW_TYPE, downZoneDrawType);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
SetIndexBuffer(downZoneColorBufferIndex, downZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
int ratesTotal, // Total Rates
|
||||
double upPrice, // Up Price ...
|
||||
double downPrice // Down Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double upValue = mUpZHull.Calculate(
|
||||
upPrice,
|
||||
bar_index,
|
||||
ratesTotal);
|
||||
upZoneBuffer[bar_index] = upValue;
|
||||
double upColorIDX = (bar_index > 0)
|
||||
? (upZoneBuffer[bar_index] > upZoneBuffer[bar_index - 1])
|
||||
? 1
|
||||
: (upZoneBuffer[bar_index] < upZoneBuffer[bar_index - 1])
|
||||
? 2
|
||||
: upZoneColorBuffer[bar_index - 1]
|
||||
: 0;
|
||||
upZoneColorBuffer[bar_index] = upColorIDX;
|
||||
|
||||
//
|
||||
double downValue = mDownZHull.Calculate(
|
||||
downPrice,
|
||||
bar_index,
|
||||
ratesTotal);
|
||||
downZoneBuffer[bar_index] = downValue;
|
||||
double downColorIDX = (bar_index > 0)
|
||||
? (downZoneBuffer[bar_index] > downZoneBuffer[bar_index - 1])
|
||||
? 1
|
||||
: (downZoneBuffer[bar_index] < downZoneBuffer[bar_index - 1])
|
||||
? 2
|
||||
: downZoneColorBuffer[bar_index - 1]
|
||||
: 0;
|
||||
downZoneColorBuffer[bar_index] = downColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// 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.
@@ -118,7 +118,7 @@ input bool shiftKumo = true; // Shift Kumo to Future
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
@@ -243,6 +243,29 @@ double senkouSpanBBuffer[];
|
||||
#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 ...
|
||||
//
|
||||
@@ -253,6 +276,7 @@ double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mTenkanSenTopMode = NULL;
|
||||
@@ -296,6 +320,19 @@ int OnInit()
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Init Handler ...
|
||||
mHandler = iIchimoku(
|
||||
_Symbol,
|
||||
_Period,
|
||||
tenkanSenLength,
|
||||
kijunSenLength,
|
||||
senkouSpanBLength);
|
||||
if (mHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
@@ -320,6 +357,9 @@ void OnDeinit(const int reason)
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -371,9 +411,34 @@ int OnCalculate(
|
||||
// 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--)
|
||||
@@ -550,6 +615,34 @@ void DefineBuffers()
|
||||
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);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,469 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X121_XMC MA Cross Indicator
|
||||
// ---------------------------------------------------
|
||||
// Name: X121_XMC
|
||||
// Description: Moving Average Crosses
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XMC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XMC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Fast";
|
||||
input int fastMaLength = 9; // Length
|
||||
input int fastMaShift = 0; // Shift
|
||||
input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Method
|
||||
input ENUM_APPLIED_PRICE fastMaAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Slow";
|
||||
input int slowMaLength = 18; // Length
|
||||
input int slowMaShift = 0; // Shift
|
||||
input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Method
|
||||
input ENUM_APPLIED_PRICE slowMaAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Verifier";
|
||||
input int verifierMaLength = 50; // Length
|
||||
input int verifierMaShift = 0; // Shift
|
||||
input ENUM_MA_METHOD verifierMaMethod = MODE_EMA; // Method
|
||||
input ENUM_APPLIED_PRICE verifierMaAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showFastMa = true; // Show Fast
|
||||
input bool showSlowMa = true; // Show Slow
|
||||
input bool showVerifierMa = true; // Show Verifier
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define fastMaBufferIndex 0
|
||||
double fastMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XMC MA F"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define slowMaBufferIndex 1
|
||||
double slowMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XMC MA S"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDarkOrange
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// VERIFIER ...
|
||||
#define verifierMaBufferIndex 2
|
||||
double verifierMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XMC MA V"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrDarkBlue
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int fastMaHandler = INVALID_HANDLE;
|
||||
int slowMaHandler = INVALID_HANDLE;
|
||||
int verifierMaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// MA Initialization ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
fastMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastMaLength,
|
||||
fastMaShift,
|
||||
fastMaMethod,
|
||||
fastMaAppliedTo);
|
||||
if (fastMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
LogMessage(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
slowMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowMaLength,
|
||||
slowMaShift,
|
||||
slowMaMethod,
|
||||
slowMaAppliedTo);
|
||||
if (slowMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
LogMessage(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// VERIFIER ...
|
||||
verifierMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
verifierMaLength,
|
||||
verifierMaShift,
|
||||
verifierMaMethod,
|
||||
verifierMaAppliedTo);
|
||||
if (verifierMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
LogMessage(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// 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(fastMaHandler);
|
||||
IndicatorRelease(slowMaHandler);
|
||||
IndicatorRelease(verifierMaHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int fastMaCalculatedBars = BarsCalculated(fastMaHandler);
|
||||
int slowMaCalculatedBars = BarsCalculated(slowMaHandler);
|
||||
int verifierMaCalculatedBars = BarsCalculated(verifierMaHandler);
|
||||
if (fastMaCalculatedBars < maxLength ||
|
||||
slowMaCalculatedBars < maxLength ||
|
||||
verifierMaCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedFastMas = CopyBuffer(fastMaHandler, 0, 0, limit, fastMaBuffer);
|
||||
int copiedSlowMas = CopyBuffer(slowMaHandler, 0, 0, limit, slowMaBuffer);
|
||||
int copiedVerifierMas = CopyBuffer(verifierMaHandler, 0, 0, limit, verifierMaBuffer);
|
||||
if (copiedFastMas <= 0 ||
|
||||
copiedSlowMas <= 0 ||
|
||||
copiedVerifierMas <= 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 =
|
||||
//
|
||||
// Validate Ma ...
|
||||
(fastMaLength > 2 &&
|
||||
slowMaLength > fastMaLength &&
|
||||
verifierMaLength > slowMaLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ma ...
|
||||
result = MathMax(result, fastMaLength);
|
||||
result = MathMax(result, slowMaLength);
|
||||
result = MathMax(result, verifierMaLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
ENUM_DRAW_TYPE fastMaDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(fastMaBuffer, true);
|
||||
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastMaDrawType);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ENUM_DRAW_TYPE slowMaDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(slowMaBuffer, true);
|
||||
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowMaDrawType);
|
||||
|
||||
//
|
||||
// VERIFIER ...
|
||||
ENUM_DRAW_TYPE verifierMaDrawType = showVerifierMa ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(verifierMaBuffer, true);
|
||||
SetIndexBuffer(verifierMaBufferIndex, verifierMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_TYPE, verifierMaDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -1,786 +0,0 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------
|
||||
// Name: X121_XMRB
|
||||
// Description: Moving Average Ribbon
|
||||
//
|
||||
//
|
||||
// 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_XMRB Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XMRB"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Ribbon 1";
|
||||
input int fast1Length = 3; // Fast
|
||||
input int slow1Length = 5; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 2";
|
||||
input int fast2Length = 8; // Fast
|
||||
input int slow2Length = 13; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 3";
|
||||
input int fast3Length = 21; // Fast
|
||||
input int slow3Length = 34; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 4";
|
||||
input int fast4Length = 55; // Fast
|
||||
input int slow4Length = 89; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 5";
|
||||
input int fast5Length = 144; // Fast
|
||||
input int slow5Length = 233; // Slow
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_MA_METHOD ribbonMode = MODE_EMA; // Mode
|
||||
input ENUM_APPLIED_PRICE ribbonAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showFastMa = true; // Show Fast
|
||||
input bool showSlowMa = true; // Show Slow
|
||||
input bool showRibbon = false; // Show Ribbon
|
||||
|
||||
//
|
||||
// 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 12
|
||||
#property indicator_plots 12
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define fastMaBufferIndex 0
|
||||
double fastMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XMRB F"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define slowMaBufferIndex 1
|
||||
double slowMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XMRB S"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
#define fast1BufferIndex 2
|
||||
double fast1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XMRB 1 F"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAquamarine
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define fast2BufferIndex 3
|
||||
double fast2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XMRB 2 F"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAquamarine
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
#define fast3BufferIndex 4
|
||||
double fast3Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XMRB 3 F"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrAquamarine
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define fast4BufferIndex 5
|
||||
double fast4Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XMRB 4 F"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrAquamarine
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define fast5BufferIndex 6
|
||||
double fast5Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XMRB 5 F"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrAquamarine
|
||||
#property indicator_style7 STYLE_DOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
#define slow1BufferIndex 7
|
||||
double slow1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XMRB 1 S"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrPlum
|
||||
#property indicator_style8 STYLE_DOT
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
#define slow2BufferIndex 8
|
||||
double slow2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "X121_XMRB 2 S"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrPlum
|
||||
#property indicator_style9 STYLE_DOT
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
#define slow3BufferIndex 9
|
||||
double slow3Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121_XMRB 3 S"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrPlum
|
||||
#property indicator_style10 STYLE_DOT
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
#define slow4BufferIndex 10
|
||||
double slow4Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "X121_XMRB 4 S"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrPlum
|
||||
#property indicator_style11 STYLE_DOT
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
#define slow5BufferIndex 11
|
||||
double slow5Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "X121_XMRB 5 S"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrPlum
|
||||
#property indicator_style12 STYLE_DOT
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int fast1MaHandler = INVALID_HANDLE;
|
||||
int fast2MaHandler = INVALID_HANDLE;
|
||||
int fast3MaHandler = INVALID_HANDLE;
|
||||
int fast4MaHandler = INVALID_HANDLE;
|
||||
int fast5MaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
int slow1MaHandler = INVALID_HANDLE;
|
||||
int slow2MaHandler = INVALID_HANDLE;
|
||||
int slow3MaHandler = INVALID_HANDLE;
|
||||
int slow4MaHandler = INVALID_HANDLE;
|
||||
int slow5MaHandler = 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();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initialize MAs ...
|
||||
if (!InitializeMas())
|
||||
{
|
||||
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
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
IndicatorRelease(fast1MaHandler);
|
||||
IndicatorRelease(fast2MaHandler);
|
||||
IndicatorRelease(fast3MaHandler);
|
||||
IndicatorRelease(fast4MaHandler);
|
||||
IndicatorRelease(fast5MaHandler);
|
||||
|
||||
//
|
||||
IndicatorRelease(slow1MaHandler);
|
||||
IndicatorRelease(slow2MaHandler);
|
||||
IndicatorRelease(slow3MaHandler);
|
||||
IndicatorRelease(slow4MaHandler);
|
||||
IndicatorRelease(slow5MaHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 fast1MaCalculatedBars = BarsCalculated(fast1MaHandler);
|
||||
int fast2MaCalculatedBars = BarsCalculated(fast2MaHandler);
|
||||
int fast3MaCalculatedBars = BarsCalculated(fast3MaHandler);
|
||||
int fast4MaCalculatedBars = BarsCalculated(fast4MaHandler);
|
||||
int fast5MaCalculatedBars = BarsCalculated(fast5MaHandler);
|
||||
//
|
||||
int slow1MaCalculatedBars = BarsCalculated(slow1MaHandler);
|
||||
int slow2MaCalculatedBars = BarsCalculated(slow2MaHandler);
|
||||
int slow3MaCalculatedBars = BarsCalculated(slow3MaHandler);
|
||||
int slow4MaCalculatedBars = BarsCalculated(slow4MaHandler);
|
||||
int slow5MaCalculatedBars = BarsCalculated(slow5MaHandler);
|
||||
if (
|
||||
fast1MaCalculatedBars < maxLength ||
|
||||
fast2MaCalculatedBars < maxLength ||
|
||||
fast3MaCalculatedBars < maxLength ||
|
||||
fast4MaCalculatedBars < maxLength ||
|
||||
fast5MaCalculatedBars < maxLength ||
|
||||
slow1MaCalculatedBars < maxLength ||
|
||||
slow2MaCalculatedBars < maxLength ||
|
||||
slow3MaCalculatedBars < maxLength ||
|
||||
slow4MaCalculatedBars < maxLength ||
|
||||
slow5MaCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
//
|
||||
int copiedFast1Mas = CopyBuffer(fast1MaHandler, 0, 0, limit, fast1Buffer);
|
||||
int copiedFast2Mas = CopyBuffer(fast2MaHandler, 0, 0, limit, fast2Buffer);
|
||||
int copiedFast3Mas = CopyBuffer(fast3MaHandler, 0, 0, limit, fast3Buffer);
|
||||
int copiedFast4Mas = CopyBuffer(fast4MaHandler, 0, 0, limit, fast4Buffer);
|
||||
int copiedFast5Mas = CopyBuffer(fast5MaHandler, 0, 0, limit, fast5Buffer);
|
||||
//
|
||||
int copiedSlow1Mas = CopyBuffer(slow1MaHandler, 0, 0, limit, slow1Buffer);
|
||||
int copiedSlow2Mas = CopyBuffer(slow2MaHandler, 0, 0, limit, slow2Buffer);
|
||||
int copiedSlow3Mas = CopyBuffer(slow3MaHandler, 0, 0, limit, slow3Buffer);
|
||||
int copiedSlow4Mas = CopyBuffer(slow4MaHandler, 0, 0, limit, slow4Buffer);
|
||||
int copiedSlow5Mas = CopyBuffer(slow5MaHandler, 0, 0, limit, slow5Buffer);
|
||||
if (
|
||||
copiedFast1Mas <= 0 ||
|
||||
copiedFast2Mas <= 0 ||
|
||||
copiedFast3Mas <= 0 ||
|
||||
copiedFast4Mas <= 0 ||
|
||||
copiedFast5Mas <= 0 ||
|
||||
copiedSlow1Mas <= 0 ||
|
||||
copiedSlow2Mas <= 0 ||
|
||||
copiedSlow3Mas <= 0 ||
|
||||
copiedSlow4Mas <= 0 ||
|
||||
copiedSlow5Mas <= 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 =
|
||||
//
|
||||
(fast1Length > 2 &&
|
||||
fast2Length > fast1Length &&
|
||||
fast3Length > fast2Length &&
|
||||
fast4Length > fast3Length &&
|
||||
fast5Length > fast4Length &&
|
||||
slow1Length > fast1Length &&
|
||||
slow2Length > fast2Length &&
|
||||
slow3Length > fast3Length &&
|
||||
slow4Length > fast4Length &&
|
||||
slow5Length > fast5Length &&
|
||||
slow2Length > slow1Length &&
|
||||
slow3Length > slow2Length &&
|
||||
slow4Length > slow3Length &&
|
||||
slow5Length > slow4Length
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ma ...
|
||||
|
||||
//
|
||||
result = MathMax(fast1Length, fast2Length);
|
||||
result = MathMax(result, fast3Length);
|
||||
result = MathMax(result, fast4Length);
|
||||
result = MathMax(result, fast5Length);
|
||||
|
||||
//
|
||||
result = MathMax(result, slow1Length);
|
||||
result = MathMax(result, slow2Length);
|
||||
result = MathMax(result, slow3Length);
|
||||
result = MathMax(result, slow4Length);
|
||||
result = MathMax(result, slow5Length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Ma Handlers ...
|
||||
bool InitializeMas()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
fast1MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast1Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast2MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast2Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast3MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast3Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast4MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast4Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast5MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast5Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
|
||||
//
|
||||
slow1MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow1Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow2MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow2Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow3MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow3Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow4MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow4Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow5MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow5Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
|
||||
//
|
||||
result =
|
||||
fast1MaHandler != INVALID_HANDLE &&
|
||||
fast2MaHandler != INVALID_HANDLE &&
|
||||
fast3MaHandler != INVALID_HANDLE &&
|
||||
fast4MaHandler != INVALID_HANDLE &&
|
||||
fast5MaHandler != INVALID_HANDLE &&
|
||||
slow1MaHandler != INVALID_HANDLE &&
|
||||
slow2MaHandler != INVALID_HANDLE &&
|
||||
slow3MaHandler != INVALID_HANDLE &&
|
||||
slow4MaHandler != INVALID_HANDLE &&
|
||||
slow5MaHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Handlers ...";
|
||||
Print(message);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// FAST ...
|
||||
ENUM_DRAW_TYPE fastDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(fastMaBuffer, true);
|
||||
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ENUM_DRAW_TYPE slowDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(slowMaBuffer, true);
|
||||
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
|
||||
|
||||
//
|
||||
// DATA ...
|
||||
ENUM_DRAW_TYPE ribbonDrawType = showRibbon ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast1Buffer, true);
|
||||
SetIndexBuffer(fast1BufferIndex, fast1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast2Buffer, true);
|
||||
SetIndexBuffer(fast2BufferIndex, fast2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast3Buffer, true);
|
||||
SetIndexBuffer(fast3BufferIndex, fast3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast4Buffer, true);
|
||||
SetIndexBuffer(fast4BufferIndex, fast4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast5Buffer, true);
|
||||
SetIndexBuffer(fast5BufferIndex, fast5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow1Buffer, true);
|
||||
SetIndexBuffer(slow1BufferIndex, slow1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow2Buffer, true);
|
||||
SetIndexBuffer(slow2BufferIndex, slow2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow3Buffer, true);
|
||||
SetIndexBuffer(slow3BufferIndex, slow3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow4Buffer, true);
|
||||
SetIndexBuffer(slow4BufferIndex, slow4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow5Buffer, true);
|
||||
SetIndexBuffer(slow5BufferIndex, slow5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
// Retireve Values ...
|
||||
|
||||
//
|
||||
double fast1Value = fast1Buffer[bar_index];
|
||||
double fast2Value = fast2Buffer[bar_index];
|
||||
double fast3Value = fast3Buffer[bar_index];
|
||||
double fast4Value = fast4Buffer[bar_index];
|
||||
double fast5Value = fast5Buffer[bar_index];
|
||||
|
||||
//
|
||||
double slow1Value = slow1Buffer[bar_index];
|
||||
double slow2Value = slow2Buffer[bar_index];
|
||||
double slow3Value = slow3Buffer[bar_index];
|
||||
double slow4Value = slow4Buffer[bar_index];
|
||||
double slow5Value = slow5Buffer[bar_index];
|
||||
|
||||
//
|
||||
double fastValue = (fast1Value + fast2Value + fast3Value + fast4Value + fast5Value) / 5;
|
||||
fastMaBuffer[bar_index] = fastValue;
|
||||
|
||||
//
|
||||
double slowValue = (slow1Value + slow2Value + slow3Value + slow4Value + slow5Value) / 5;
|
||||
slowMaBuffer[bar_index] = slowValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
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.
@@ -1,992 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: X121_XPV
|
||||
// Description: Market Peaks and Vales
|
||||
//
|
||||
//
|
||||
// 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_XPV Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XPV"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// 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 double fiboLevel1 = 0.382; // Fibio 1st Level
|
||||
input double fiboLevel2 = 0.5; // Fibio 2st Level
|
||||
input double fiboLevel3 = 0.618; // Fibio 3rd Level
|
||||
|
||||
//
|
||||
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 showPeaksAndVales = true; // Show Peaks and Vales
|
||||
input bool showLevels = false; // Show Levels
|
||||
input bool showFibo1Levels = true; // Show Fibo 1st Level
|
||||
input bool showFibo2Levels = true; // Show Fibo 2nd Level
|
||||
input bool showFibo3Levels = true; // Show Fibo 3rd Level
|
||||
|
||||
//
|
||||
// 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 26
|
||||
#property indicator_plots 18
|
||||
|
||||
//
|
||||
// PEKSANDVALES ...
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
|
||||
//
|
||||
#define peaksBufferIndex 0
|
||||
double peaksBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XPV PEAKS"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
|
||||
//
|
||||
#define valesBufferIndex 1
|
||||
double valesBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XPV VALES"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define rBufferIndex 2
|
||||
double rBuffer[];
|
||||
|
||||
//
|
||||
#define rColorBufferIndex 3
|
||||
double rColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XPV R"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrAqua, CLR_NONE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define sBufferIndex 4
|
||||
#define sBufferPlotIndex 3
|
||||
double sBuffer[];
|
||||
|
||||
//
|
||||
#define sColorBufferIndex 5
|
||||
double sColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XPV S"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 clrMagenta, CLR_NONE
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// FIBBO Level 1 ...
|
||||
|
||||
//
|
||||
#define fl1BufferIndex 6
|
||||
#define fl1BufferPlotIndex 4
|
||||
double fl1Buffer[];
|
||||
|
||||
//
|
||||
#define fl1ColorBufferIndex 7
|
||||
double fl1ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XPV FL1"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 CLR_NONE, clrGold
|
||||
#property indicator_style5 STYLE_DASHDOTDOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// FIBBO Level 2 ...
|
||||
|
||||
//
|
||||
#define fl2BufferIndex 8
|
||||
#define fl2BufferPlotIndex 5
|
||||
double fl2Buffer[];
|
||||
|
||||
//
|
||||
#define fl2ColorBufferIndex 9
|
||||
double fl2ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XPV FL2"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrGold
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// FIBBO Level 3 ...
|
||||
|
||||
//
|
||||
#define fl3BufferIndex 10
|
||||
#define fl3BufferPlotIndex 6
|
||||
double fl3Buffer[];
|
||||
|
||||
//
|
||||
#define fl3ColorBufferIndex 11
|
||||
double fl3ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XPV FL3"
|
||||
#property indicator_type7 DRAW_COLOR_LINE
|
||||
#property indicator_color7 CLR_NONE, clrGold
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// LEVELS ...
|
||||
|
||||
//
|
||||
#define sHHBufferIndex 12
|
||||
#define sHHBufferPlotIndex 7
|
||||
double sHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XPV SHH"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrLightGray
|
||||
#property indicator_style8 STYLE_DOT
|
||||
#property indicator_width8 1
|
||||
|
||||
#define sLLBufferIndex 13
|
||||
#define sLLBufferPlotIndex 8
|
||||
double sLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "X121_XPV SLL"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrLightGray
|
||||
#property indicator_style9 STYLE_DOT
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
#define mHHBufferIndex 14
|
||||
#define mHHBufferPlotIndex 9
|
||||
double mHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121_XPV MHH"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrLightGray
|
||||
#property indicator_style10 STYLE_DOT
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
#define mLLBufferIndex 15
|
||||
#define mLLBufferPlotIndex 10
|
||||
double mLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "X121_XPV MLL"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrLightGray
|
||||
#property indicator_style11 STYLE_DOT
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
#define lHHBufferIndex 16
|
||||
#define lHHBufferPlotIndex 11
|
||||
double lHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "X121_XPV LHH"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrLightGray
|
||||
#property indicator_style12 STYLE_DOT
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
#define lLLBufferIndex 17
|
||||
#define lLLBufferPlotIndex 12
|
||||
double lLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label13 "X121_XPV LLL"
|
||||
#property indicator_type13 DRAW_LINE
|
||||
#property indicator_color13 clrLightGray
|
||||
#property indicator_style13 STYLE_DOT
|
||||
#property indicator_width13 1
|
||||
|
||||
//
|
||||
#define hHHBufferIndex 18
|
||||
#define hHHBufferPlotIndex 13
|
||||
double hHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label14 "X121_XPV HHH"
|
||||
#property indicator_type14 DRAW_LINE
|
||||
#property indicator_color14 clrLightGray
|
||||
#property indicator_style14 STYLE_DOT
|
||||
#property indicator_width14 1
|
||||
|
||||
//
|
||||
#define hLLBufferIndex 19
|
||||
#define hLLBufferPlotIndex 14
|
||||
double hLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label15 "X121_XPV HLL"
|
||||
#property indicator_type15 DRAW_LINE
|
||||
#property indicator_color15 clrLightGray
|
||||
#property indicator_style15 STYLE_DOT
|
||||
#property indicator_width15 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double lastPeak;
|
||||
double lastVale;
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(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;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// RANGE ...
|
||||
|
||||
//
|
||||
// PEAKS and VALES ...
|
||||
ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
ArraySetAsSeries(peaksBuffer, true);
|
||||
SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225);
|
||||
// PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW_SHIFT, -20);
|
||||
PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
ArraySetAsSeries(valesBuffer, true);
|
||||
SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225);
|
||||
// PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW_SHIFT, 20);
|
||||
PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
|
||||
|
||||
//
|
||||
// SUPPORT and RESISTANCE ...
|
||||
//
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
ArraySetAsSeries(rBuffer, true);
|
||||
SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// RESISTANCE Color ...
|
||||
ArraySetAsSeries(rColorBuffer, true);
|
||||
SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
ArraySetAsSeries(sBuffer, true);
|
||||
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// SUPPORT Color ...
|
||||
ArraySetAsSeries(sColorBuffer, true);
|
||||
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// FIBBO Levels ...
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl1Buffer, true);
|
||||
SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl1BufferIndex, PLOT_SHOW_DATA, showFibo1Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl1ColorBuffer, true);
|
||||
SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl2Buffer, true);
|
||||
SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl2BufferIndex, PLOT_SHOW_DATA, showFibo2Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl2ColorBuffer, true);
|
||||
SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// LEVEL 3 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl3Buffer, true);
|
||||
SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl3BufferIndex, PLOT_SHOW_DATA, showFibo3Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl3ColorBuffer, true);
|
||||
SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE zoneDrawType = showLevels ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// SHORT Buffers ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// MEDIUM Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LONG Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// HIND Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate ...
|
||||
|
||||
//
|
||||
double rColorIDX = 1;
|
||||
double sColorIDX = 1;
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// RESISTANCE SUPPORT ...
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
double rValue = (sHHValue + mHHValue + lHHValue + hHHValue) / 4;
|
||||
rBuffer[bar_index] = rValue;
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
double sValue = (sLLValue + mLLValue + lLLValue + hLLValue) / 4;
|
||||
sBuffer[bar_index] = sValue;
|
||||
|
||||
//
|
||||
// PEAKS and VALES ...
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
bool isPeak = rValue == hHHValue &&
|
||||
hHHValue == lHHValue &&
|
||||
lHHValue == mHHValue &&
|
||||
mHHValue == sHHValue;
|
||||
//
|
||||
if (isPeak && lastPeak != rValue)
|
||||
{
|
||||
//
|
||||
if (showPeaksAndVales)
|
||||
{
|
||||
rColorIDX = 0;
|
||||
}
|
||||
|
||||
//
|
||||
lastPeak = rValue;
|
||||
peaksBuffer[bar_index] = lastPeak;
|
||||
}
|
||||
else
|
||||
{
|
||||
peaksBuffer[bar_index] = lastPeak;
|
||||
}
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
bool isVale = sValue == hLLValue &&
|
||||
hLLValue == lLLValue &&
|
||||
lLLValue == mLLValue &&
|
||||
mLLValue == sLLValue;
|
||||
|
||||
//
|
||||
if (isVale && lastVale != sValue)
|
||||
{
|
||||
//
|
||||
if (showPeaksAndVales)
|
||||
{
|
||||
sColorIDX = 0;
|
||||
}
|
||||
|
||||
//
|
||||
lastVale = sValue;
|
||||
valesBuffer[bar_index] = lastVale;
|
||||
}
|
||||
else
|
||||
{
|
||||
valesBuffer[bar_index] = lastVale;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Default Colors ...
|
||||
|
||||
//
|
||||
rColorBuffer[bar_index] = rColorIDX;
|
||||
sColorBuffer[bar_index] = sColorIDX;
|
||||
|
||||
//
|
||||
// Calculate Fibonacci ...
|
||||
double upPrice = peaksBuffer[bar_index];
|
||||
double downPrice = valesBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Level 1 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel1BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel1,
|
||||
1);
|
||||
fl1Buffer[bar_index] = fibLevel1BullishValue;
|
||||
double fl1BullColorIdx = showFibo1Levels ? 1 : 0;
|
||||
fl1ColorBuffer[bar_index] = fl1BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel1BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel1,
|
||||
// 0);
|
||||
// fl1BearBuffer[bar_index] = fibLevel1BearishValue;
|
||||
// double fl1BearColorIdx = showFibo1Levels ? 1 : 0;
|
||||
// fl1BearColorBuffer[bar_index] = fl1BearColorIdx;
|
||||
|
||||
//
|
||||
// Level 2 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel2BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel2,
|
||||
1);
|
||||
fl2Buffer[bar_index] = fibLevel2BullishValue;
|
||||
double fl2BullColorIdx = showFibo2Levels ? 1 : 0;
|
||||
fl2ColorBuffer[bar_index] = fl2BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel2BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel2,
|
||||
// 0);
|
||||
// fl2BearBuffer[bar_index] = fibLevel2BearishValue;
|
||||
// double fl2BearColorIdx = showFibo2Levels ? 1 : 0;
|
||||
// fl2BearColorBuffer[bar_index] = fl2BearColorIdx;
|
||||
|
||||
//
|
||||
// Level 3 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel3BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel3,
|
||||
1);
|
||||
fl3Buffer[bar_index] = fibLevel3BullishValue;
|
||||
double fl3BullColorIdx = showFibo3Levels ? 1 : 0;
|
||||
fl3ColorBuffer[bar_index] = fl3BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel3BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel3,
|
||||
// 0);
|
||||
// fl3BearBuffer[bar_index] = fibLevel3BearishValue;
|
||||
// double fl3BearColorIdx = showFibo3Levels ? 1 : 0;
|
||||
// fl3BearColorBuffer[bar_index] = fl3BearColorIdx;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -1,437 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ----------------------------------------------------
|
||||
// Name: X121_XSSLC
|
||||
// Description: SSL 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_XSSLC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XSSLC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 36; // Length
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Applied To
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showUp = true; // Show Up
|
||||
input bool showDown = true; // Show Down
|
||||
|
||||
//
|
||||
// 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 5
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
#define upBufferIndex 0
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XSSLC Up"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define downBufferIndex 1
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XSSLC Down"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define upMaBufferIndex 2
|
||||
double upMaBuffer[];
|
||||
|
||||
//
|
||||
#define downMaBufferIndex 3
|
||||
double downMaBuffer[];
|
||||
|
||||
//
|
||||
#define kpiBufferIndex 4
|
||||
double kpiBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int upHandler = INVALID_HANDLE;
|
||||
int downHandler = 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();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initialize Requierd Handlers ...
|
||||
upHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
upAppliedTo);
|
||||
downHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
downAppliedTo);
|
||||
if (upHandler == INVALID_HANDLE || downHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
Print(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
IndicatorRelease(upHandler);
|
||||
IndicatorRelease(downHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 upCalculatedBars = BarsCalculated(upHandler);
|
||||
int downCalculatedBars = BarsCalculated(downHandler);
|
||||
if (upCalculatedBars < maxLength ||
|
||||
downCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedUps = CopyBuffer(upHandler, 0, 0, limit, upMaBuffer);
|
||||
int copiedDowns = CopyBuffer(downHandler, 0, 0, limit, downMaBuffer);
|
||||
if (copiedUps <= 0 ||
|
||||
copiedDowns <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i, limit, rates_total, prev_calculated, close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(length > 2)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// UP ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
|
||||
ArraySetAsSeries(upBuffer, true);
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
|
||||
ArraySetAsSeries(downBuffer, true);
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, showDown);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_TYPE, downDrawType);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// UP MA ...
|
||||
ArraySetAsSeries(upMaBuffer, true);
|
||||
SetIndexBuffer(upMaBufferIndex, upMaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// DOWN MA ...
|
||||
ArraySetAsSeries(downMaBuffer, true);
|
||||
SetIndexBuffer(downMaBufferIndex, downMaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// KPI ...
|
||||
ArraySetAsSeries(kpiBuffer, true);
|
||||
SetIndexBuffer(kpiBufferIndex, kpiBuffer, 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
|
||||
int limit,
|
||||
int ratesTotal,
|
||||
int prevCalculated,
|
||||
const double &close[])
|
||||
{
|
||||
//
|
||||
double upMaValue = upMaBuffer[bar_index];
|
||||
double downMaValue = downMaBuffer[bar_index];
|
||||
|
||||
//
|
||||
double closeValue = close[bar_index];
|
||||
|
||||
//
|
||||
double kpiValue;
|
||||
if (closeValue > upMaValue) {
|
||||
kpiValue = 1;
|
||||
} else if (closeValue < downMaValue) {
|
||||
kpiValue = -1;
|
||||
} else {
|
||||
kpiValue = kpiBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
kpiBuffer[bar_index] = kpiValue;
|
||||
|
||||
//
|
||||
double upValue = kpiValue < 0 ? downMaValue : upMaValue;
|
||||
upBuffer[bar_index] = upValue;
|
||||
|
||||
//
|
||||
double downValue = kpiValue < 0 ? upMaValue : downMaValue;
|
||||
downBuffer[bar_index] = downValue;
|
||||
}
|
||||
|
||||
//
|
||||
// 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.
@@ -1,354 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XTM
|
||||
// Description: Trend Magic 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_XTM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "X121_XTM"
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 0,
|
||||
X_XTM_BEARISH = 2,
|
||||
X_XTM_NEUTURAL = 1,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret";
|
||||
input int length = 35; // Length
|
||||
input int shift = 0; // Shift
|
||||
|
||||
//
|
||||
input group "Calculations";
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLine = true; // Show Line
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
double maBuffer[];
|
||||
|
||||
#define maColorBufferIndex 1
|
||||
double maColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XTM"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int maHandler = 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 MA Handler ...
|
||||
maHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
shift,
|
||||
method,
|
||||
appliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
Print(message);
|
||||
|
||||
//
|
||||
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(maHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
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.
@@ -1,775 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
Reference in New Issue
Block a user