Cleanup ...
This commit is contained in:
@@ -1,156 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCButton
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
// a Button Creation Class ...
|
||||
class XCButton : public XCObject
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XCButton()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCButton()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Create an Instance of Class Object ...
|
||||
*
|
||||
* @param name: Object Name
|
||||
* @param xDis: X Distance
|
||||
* @param yDis: Y Distance
|
||||
* @param xSize: X Size
|
||||
* @param ySize: Y Size
|
||||
*/
|
||||
bool Create(
|
||||
string name,
|
||||
int xDis,
|
||||
int yDis,
|
||||
int xSize,
|
||||
int ySize,
|
||||
long chartID = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Object creation and property settings
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = ObjectCreate(chartID, name, OBJ_BUTTON, 0, 0, 0);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, xSize);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, ySize);
|
||||
|
||||
//
|
||||
mName = name;
|
||||
mChartID = chartID;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
/**
|
||||
* Set Object Border Color ...
|
||||
*
|
||||
* @param value: color
|
||||
*/
|
||||
void BorderColor(color value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_BORDER_COLOR, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object Background Color ...
|
||||
*
|
||||
* @param value: color
|
||||
*/
|
||||
void BGColor(color value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_BGCOLOR, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object Text Color ...
|
||||
*
|
||||
* @param value: Color
|
||||
*/
|
||||
void Color(color value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_COLOR, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object Text ...
|
||||
*
|
||||
* @param value: text
|
||||
*/
|
||||
void Text(string value)
|
||||
{
|
||||
ObjectSetString(mChartID, mName, OBJPROP_TEXT, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Button Click State ...
|
||||
*
|
||||
* @param value: state
|
||||
*/
|
||||
void State(bool value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_STATE, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
@@ -1,186 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCEdit
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
// a Label Creation Class ...
|
||||
class XCEdit : public XCObject
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XCEdit()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCEdit()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Create an Instance of Class Object ...
|
||||
*
|
||||
* @param name: Object Name
|
||||
* @param xDis: X Distance
|
||||
* @param yDis: Y Distance
|
||||
* @param xSize: X Size
|
||||
* @param ySize: Y Size
|
||||
*/
|
||||
bool Create(
|
||||
string name,
|
||||
int xDis,
|
||||
int yDis,
|
||||
int xSize,
|
||||
int ySize,
|
||||
long chartID = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Object creation and property settings
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = ObjectCreate(chartID, name, OBJ_EDIT, 0, 0, 0);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, xSize);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, ySize);
|
||||
|
||||
//
|
||||
mName = name;
|
||||
mChartID = chartID;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
/**
|
||||
* Set Object Border Color ...
|
||||
*
|
||||
* @param value: color
|
||||
*/
|
||||
void BorderColor(color value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_BORDER_COLOR, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Background Color of Object ...
|
||||
*
|
||||
* @param value: color
|
||||
*/
|
||||
void BGColor(color value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_BGCOLOR, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object Text Color ...
|
||||
*
|
||||
* @param value: color
|
||||
*/
|
||||
void Color(color value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_COLOR, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Text of Object ...
|
||||
*
|
||||
* @param value: text
|
||||
*/
|
||||
void Text(string value)
|
||||
{
|
||||
ObjectSetString(mChartID, mName, OBJPROP_TEXT, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current Text of Object ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string Text()
|
||||
{
|
||||
return ObjectGetString(mChartID, mName, OBJPROP_TEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Font Size of Object ...
|
||||
*
|
||||
* @param value: size
|
||||
*/
|
||||
void FontSize(int value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_FONTSIZE, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Font Name Of Object ...
|
||||
*
|
||||
* @param value: font name
|
||||
*/
|
||||
void Font(string value)
|
||||
{
|
||||
ObjectSetString(mChartID, mName, OBJPROP_FONT, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ReadOnly State of Object ...
|
||||
*
|
||||
* @param value: boolean value
|
||||
*/
|
||||
void ReadOnly(bool value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_READONLY, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
@@ -1,160 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCLabel
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
// a Label Creation Class ...
|
||||
class XCLabel : public XCObject
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XCLabel()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCLabel()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Create an Instance of Class Object ...
|
||||
*
|
||||
* @param name: Object Name
|
||||
* @param xDis: X Distance
|
||||
* @param yDis: Y Distance
|
||||
*/
|
||||
bool Create(
|
||||
string name,
|
||||
int xDis,
|
||||
int yDis,
|
||||
long chartID = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Object creation and property settings
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = ObjectCreate(chartID, name, OBJ_LABEL, 0, 0, 0);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
|
||||
|
||||
//
|
||||
mName = name;
|
||||
mChartID = chartID;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
/**
|
||||
* Set Text Color ...
|
||||
*
|
||||
* @param value: color
|
||||
*/
|
||||
void Color(color value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_COLOR, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Text of Object ...
|
||||
*
|
||||
* @param value: text
|
||||
*/
|
||||
void Text(string value)
|
||||
{
|
||||
ObjectSetString(mChartID, mName, OBJPROP_TEXT, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Text Of Object ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string Text()
|
||||
{
|
||||
return ObjectGetString(mChartID, mName, OBJPROP_TEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Font Size of Object ...
|
||||
*
|
||||
* @param value: size
|
||||
*/
|
||||
void FontSize(int value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_FONTSIZE, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Font Name Of Object ...
|
||||
*
|
||||
* @param value: font name
|
||||
*/
|
||||
void Font(string value)
|
||||
{
|
||||
ObjectSetString(mChartID, mName, OBJPROP_FONT, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object Anchor ...
|
||||
*
|
||||
* @param value: anchor
|
||||
*/
|
||||
void Anchor(ENUM_ANCHOR_POINT value)
|
||||
{
|
||||
ObjectSetInteger(mChartID, mName, OBJPROP_ANCHOR, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
@@ -1,299 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCPanel
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../XCObjects/x-saherelm.x-button.class.mq5"
|
||||
#include "../XCObjects/x-saherelm.x-edit.class.mq5"
|
||||
#include "../XCObjects/x-saherelm.x-label.class.mq5"
|
||||
#include "../XCObjects/x-saherelm.x-rectangle.label.class.mq5"
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
class XCPanel : XCObject
|
||||
{
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XCPanel()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCPanel()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
//
|
||||
// Action ...
|
||||
|
||||
/**
|
||||
* Create an instance of Panel Object ...
|
||||
*
|
||||
* @param name: Object name
|
||||
* @param xDis: X Distance
|
||||
* @param yDis: Y Distance
|
||||
* @param xSize: X Size
|
||||
* @param ySize: Y Size
|
||||
* @param titleBarBorderType: Border Type of Panel TitleBar
|
||||
* @param titleBarBGColor: Background Color of Panel TitleBar
|
||||
* @param caption: Caption Text of Panel TitleBar
|
||||
* @param captionontSize: Font Size of Panel Caption
|
||||
* @param captionColor: Text Color of Panel Caption
|
||||
* @param captionAnchor: Anchor Point of Panel Caption
|
||||
* @param bodyBorderType: Border Type of Panel Body
|
||||
* @param bodyBGColor: Background Color of Panel Body
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Create(
|
||||
string name,
|
||||
int xDis,
|
||||
int yDis,
|
||||
int xSize,
|
||||
int ySize,
|
||||
//
|
||||
long chartID = 0,
|
||||
//
|
||||
// Title Bar ...
|
||||
ENUM_BORDER_TYPE titleBarBorderType = BORDER_FLAT,
|
||||
color titleBarBGColor = clrBlueViolet,
|
||||
//
|
||||
// Caption ...
|
||||
string caption = "",
|
||||
int captionontSize = 9,
|
||||
color captionColor = clrWhite,
|
||||
ENUM_ANCHOR_POINT captionAnchor = ANCHOR_LEFT_UPPER,
|
||||
//
|
||||
// Body ...
|
||||
ENUM_BORDER_TYPE bodyBorderType = BORDER_FLAT,
|
||||
color bodyBGColor = clrMediumSlateBlue //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Enables mouse move events on the chart
|
||||
ChartSetInteger(chartID, CHART_EVENT_MOUSE_MOVE, true);
|
||||
|
||||
//
|
||||
result = IsValid(name);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mTitleBarName = name + "_TITLE_BAR";
|
||||
mCaptionLblName = name + "_CAPTION";
|
||||
mBodyName = name + "_BODY";
|
||||
|
||||
//
|
||||
if (!IsValid(caption))
|
||||
{
|
||||
caption = name;
|
||||
}
|
||||
|
||||
//
|
||||
// Title Bar ...
|
||||
int titleBarHeight = 20;
|
||||
result = mTitleBar.Create(
|
||||
mTitleBarName,
|
||||
xDis,
|
||||
yDis,
|
||||
xSize,
|
||||
titleBarHeight //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Destroy();
|
||||
return result;
|
||||
}
|
||||
mTitleBar.BorderType(titleBarBorderType);
|
||||
mTitleBar.BGColor(titleBarBGColor);
|
||||
|
||||
//
|
||||
// Body ...
|
||||
result = mBody.Create(
|
||||
mBodyName,
|
||||
xDis,
|
||||
yDis + titleBarHeight - 1,
|
||||
xSize,
|
||||
ySize //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Destroy();
|
||||
return result;
|
||||
}
|
||||
mBody.BorderType(bodyBorderType);
|
||||
mBody.BGColor(bodyBGColor);
|
||||
mBody.AsBackGround(true);
|
||||
|
||||
//
|
||||
// Caption ...
|
||||
result = mCaptionLbl.Create(mCaptionLblName, xDis, yDis);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Destroy();
|
||||
return result;
|
||||
}
|
||||
mCaptionLbl.Text(caption);
|
||||
mCaptionLbl.Color(captionColor);
|
||||
mCaptionLbl.Anchor(captionAnchor);
|
||||
mCaptionLbl.FontSize(captionontSize);
|
||||
|
||||
//
|
||||
// Adding Child Objects ...
|
||||
mTitleBar.Add(mBodyName);
|
||||
mTitleBar.Add(mCaptionLblName);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Panel Object and all of it's Child
|
||||
*/
|
||||
void Destroy()
|
||||
{
|
||||
//
|
||||
mBodyName = NULL;
|
||||
mTitleBarName = NULL;
|
||||
mCaptionLblName = NULL;
|
||||
|
||||
//
|
||||
mBody.Destroy();
|
||||
mTitleBar.Destroy();
|
||||
mCaptionLbl.Destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Event Handling for Mouse Movement ...
|
||||
* @param id: Event ID
|
||||
* @param lparam: Event parameter of long type
|
||||
* @param dparam: Event parameter of double type
|
||||
* @param sparam: Event parameter of string type
|
||||
*/
|
||||
void OnEvent(
|
||||
int id,
|
||||
long lparam,
|
||||
double dparam,
|
||||
string sparam //
|
||||
)
|
||||
{
|
||||
//
|
||||
mTitleBar.OnEvent(
|
||||
id,
|
||||
lparam,
|
||||
dparam,
|
||||
sparam //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Specific Child Object ...
|
||||
*
|
||||
* @param name: object name
|
||||
*/
|
||||
void Add(string name)
|
||||
{
|
||||
mTitleBar.Add(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Panel Caption ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string Caption()
|
||||
{
|
||||
return mCaptionLbl.Text();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Panel Caption ...
|
||||
*
|
||||
* @param value: Caption
|
||||
*/
|
||||
void Caption(string value)
|
||||
{
|
||||
mCaptionLbl.Text(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Caption Color ...
|
||||
*
|
||||
* @param value: Color
|
||||
*/
|
||||
void CptionColor(color value)
|
||||
{
|
||||
mCaptionLbl.Color(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Panel Body BG Color ...
|
||||
*
|
||||
* @param value: Color
|
||||
*/
|
||||
void BodyColor(color value)
|
||||
{
|
||||
mBody.BGColor(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Panel Titlebar BG Color ...
|
||||
*
|
||||
* @param value: Color
|
||||
*/
|
||||
void TitleBarBGColor(color value)
|
||||
{
|
||||
mTitleBar.BGColor(value);
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string mBodyName;
|
||||
string mTitleBarName;
|
||||
string mCaptionLblName;
|
||||
|
||||
//
|
||||
XCLabel mCaptionLbl;
|
||||
XCRectangleLabel mBody;
|
||||
XCRectangleLabel mTitleBar;
|
||||
|
||||
//
|
||||
};
|
||||
@@ -1,259 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCRectangleLabel
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
// a Rectangle Label Creation Class ...
|
||||
class XCRectangleLabel : public XCObject
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XCRectangleLabel()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCRectangleLabel()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Create an Instance of Class Object ...
|
||||
*
|
||||
* @param name: Object Name
|
||||
* @param xDis: X Distance
|
||||
* @param yDis: Y Distance
|
||||
* @param xSize: X Size
|
||||
* @param ySize: Y Size
|
||||
*/
|
||||
bool Create(
|
||||
string name,
|
||||
int xDis,
|
||||
int yDis,
|
||||
int xSize,
|
||||
int ySize,
|
||||
long chartID = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Object creation and property settings
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, 0, 0, 0);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, xSize);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, ySize);
|
||||
|
||||
//
|
||||
mName = name;
|
||||
mChartID = chartID;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Name to Object
|
||||
* @param name: name
|
||||
*/
|
||||
void Add(string name)
|
||||
{
|
||||
//
|
||||
// Add a new object by name to the rectangle label and track distances
|
||||
ArrayResize(mAddedNames, ArraySize(mAddedNames) + 1);
|
||||
ArrayResize(mAddedXDisDiffrence, ArraySize(mAddedXDisDiffrence) + 1);
|
||||
ArrayResize(mAddedYDisDiffrence, ArraySize(mAddedYDisDiffrence) + 1);
|
||||
|
||||
//
|
||||
mAddedNames[ArraySize(mAddedNames) - 1] = name;
|
||||
mAddedXDisDiffrence[ArraySize(mAddedXDisDiffrence) - 1] = ObjectGetInteger(0, mName, OBJPROP_XDISTANCE) - ObjectGetInteger(0, name, OBJPROP_XDISTANCE);
|
||||
mAddedYDisDiffrence[ArraySize(mAddedYDisDiffrence) - 1] = ObjectGetInteger(0, mName, OBJPROP_YDISTANCE) - ObjectGetInteger(0, name, OBJPROP_YDISTANCE);
|
||||
}
|
||||
|
||||
//
|
||||
// Handlers ...
|
||||
|
||||
/**
|
||||
* Event Handling for Mouse Movement ...
|
||||
* @param id: Event ID
|
||||
* @param lparam: Event parameter of long type
|
||||
* @param dparam: Event parameter of double type
|
||||
* @param sparam: Event parameter of string type
|
||||
*/
|
||||
void OnEvent(
|
||||
int id,
|
||||
long lparam,
|
||||
double dparam,
|
||||
string sparam //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Handle mouse movement events for dragging the rectangle label
|
||||
if (id == CHARTEVENT_MOUSE_MOVE)
|
||||
{
|
||||
//
|
||||
int X = (int)lparam;
|
||||
int Y = (int)dparam;
|
||||
int MouseState = (int)sparam;
|
||||
|
||||
//
|
||||
string name = mName;
|
||||
int XSize = (int)ObjectGetInteger(0, name, OBJPROP_XSIZE);
|
||||
int YSize = (int)ObjectGetInteger(0, name, OBJPROP_YSIZE);
|
||||
int XDistance = (int)ObjectGetInteger(0, name, OBJPROP_XDISTANCE);
|
||||
int YDistance = (int)ObjectGetInteger(0, name, OBJPROP_YDISTANCE);
|
||||
|
||||
//
|
||||
if (MouseState == 1 &&
|
||||
mPreviousMouseState == 0)
|
||||
{
|
||||
//
|
||||
mlbDownX = X;
|
||||
mlbDownY = Y;
|
||||
mlbDownXDistance = XDistance;
|
||||
mlbDownYDistance = YDistance;
|
||||
|
||||
//
|
||||
if (X >= XDistance &&
|
||||
Y >= YDistance &&
|
||||
X <= XDistance + XSize &&
|
||||
Y <= YDistance + YSize)
|
||||
{
|
||||
mMovingState = true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (mMovingState)
|
||||
{
|
||||
//
|
||||
ChartSetInteger(0, CHART_MOUSE_SCROLL, false);
|
||||
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, mlbDownXDistance + X - mlbDownX);
|
||||
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, mlbDownYDistance + Y - mlbDownY);
|
||||
|
||||
//
|
||||
for (int i = 0; i < ArraySize(mAddedNames); i++)
|
||||
{
|
||||
//
|
||||
ObjectSetInteger(0, mAddedNames[i], OBJPROP_XDISTANCE, mlbDownXDistance + X - mlbDownX - mAddedXDisDiffrence[i]);
|
||||
ObjectSetInteger(0, mAddedNames[i], OBJPROP_YDISTANCE, mlbDownYDistance + Y - mlbDownY - mAddedYDisDiffrence[i]);
|
||||
}
|
||||
|
||||
//
|
||||
ChartRedraw(0);
|
||||
}
|
||||
|
||||
//
|
||||
if (MouseState == 0)
|
||||
{
|
||||
//
|
||||
mMovingState = false;
|
||||
ChartSetInteger(0, CHART_MOUSE_SCROLL, true);
|
||||
}
|
||||
|
||||
//
|
||||
mPreviousMouseState = MouseState;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
/**
|
||||
* Set Object Border Type ...
|
||||
*
|
||||
* @param borderType: Specified border type
|
||||
*/
|
||||
void BorderType(ENUM_BORDER_TYPE borderType)
|
||||
{
|
||||
//
|
||||
ObjectSetInteger(
|
||||
mChartID,
|
||||
mName,
|
||||
OBJPROP_BORDER_TYPE,
|
||||
borderType //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object Background Color
|
||||
*
|
||||
* @param value: color
|
||||
*/
|
||||
void BGColor(color value)
|
||||
{
|
||||
//
|
||||
ObjectSetInteger(
|
||||
mChartID,
|
||||
mName,
|
||||
OBJPROP_BGCOLOR,
|
||||
value //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Mouse state tracking variables ...
|
||||
int mlbDownX;
|
||||
int mlbDownY;
|
||||
int mlbDownXDistance;
|
||||
int mlbDownYDistance;
|
||||
int mPreviousMouseState;
|
||||
|
||||
//
|
||||
bool mMovingState; // State for whether the object is moving
|
||||
|
||||
//
|
||||
string mAddedNames[]; // Array of added names
|
||||
long mAddedXDisDiffrence[]; // Arrays to store added distance differences
|
||||
long mAddedYDisDiffrence[]; // Arrays to store added distance differences
|
||||
};
|
||||
@@ -1,116 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCObject
|
||||
// Description: Base Class Of Chart Object Class
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../x-saherelm.base.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
// a Button Creation Class ...
|
||||
class XCObject : XSCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XCObject()
|
||||
{
|
||||
mChartID = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCObject()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Class Instance ...
|
||||
*/
|
||||
void Destroy()
|
||||
{
|
||||
//
|
||||
mName = NULL;
|
||||
ObjectDelete(0, mName);
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
/**
|
||||
* Retrieve Object Name ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string Name()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Registered Chart ID ...
|
||||
*
|
||||
* @return ( long )
|
||||
*/
|
||||
long ChartID()
|
||||
{
|
||||
return mChartID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object ZOrder ...
|
||||
*
|
||||
* @param value: z order
|
||||
*/
|
||||
void ZOrder(int value)
|
||||
{
|
||||
ObjectSetInteger(0, mName, OBJPROP_ZORDER, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object as Background ...
|
||||
*
|
||||
* @param value: boolean value
|
||||
*/
|
||||
void AsBackGround(bool value)
|
||||
{
|
||||
ObjectSetInteger(0, mName, OBJPROP_BACK, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string mName; // Name of Object ...
|
||||
long mChartID; // Chart ID ...
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,79 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCZone
|
||||
// Description: provides all Zone requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include <Arrays/ArrayObj.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Specific Zone ...
|
||||
class XSCZone : public CObject
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
double high;
|
||||
double low;
|
||||
int ticks;
|
||||
double percent;
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime start;
|
||||
datetime end;
|
||||
|
||||
//
|
||||
// Compare Two Zone With Each Other ...
|
||||
virtual int Compare(
|
||||
const CObject *node,
|
||||
const int mode = 0 //
|
||||
) const
|
||||
{
|
||||
//
|
||||
const XSCZone *other = (XSCZone *)node;
|
||||
|
||||
//
|
||||
return other.ticks - ticks;
|
||||
}
|
||||
|
||||
//
|
||||
// Props ...
|
||||
string GetTag() {
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result = "XZ_" + ToString(period) + "_" + ToString(start);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,237 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XCTime
|
||||
// Description: Timing 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 XCTime Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "XCTime"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_LEFT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTime = true; // Show 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 (showTime)
|
||||
{
|
||||
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
|
||||
|
||||
//
|
||||
ulong chID = FindChartID(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Delete Object ...
|
||||
ObjectDelete(chID, ShortName);
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(time, true);
|
||||
|
||||
//
|
||||
if (!showTime)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
ulong chID = FindChartID(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//s
|
||||
int offset = TimeGMTOffset();
|
||||
string timeString =
|
||||
"Local: " + string(TimeLocal()) +
|
||||
", Server: " + string(TimeTradeServer());
|
||||
timeString = timeString;
|
||||
|
||||
//
|
||||
string objText = timeString;
|
||||
|
||||
//
|
||||
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr);
|
||||
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
|
||||
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
|
||||
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Arial");
|
||||
|
||||
//
|
||||
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 (!showTime)
|
||||
{
|
||||
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 ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,993 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XCHSwings
|
||||
// Description: XCHSwings Detector ...
|
||||
//
|
||||
// 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 XCHVWAP Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XCHVWAP"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int length = 12; // Length
|
||||
|
||||
//
|
||||
input group "Cycles";
|
||||
|
||||
//
|
||||
input group "Short";
|
||||
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Medium";
|
||||
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Long";
|
||||
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Hind";
|
||||
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
//
|
||||
input bool showSwingHighs = true; // Show Swing Highs
|
||||
input bool showSwingLows = true; // Show Swing Lows
|
||||
//
|
||||
input bool showCurrent = true; // Show Cycle Cycle
|
||||
input bool showShort = true; // Show Short Cycle
|
||||
input bool showMedium = true; // Show Medium Cycle
|
||||
input bool showLong = true; // Show Long Cycle
|
||||
input bool showHind = true; // Show Hind Cycle
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 10
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
#define cSHBufferIndex 0
|
||||
double cSHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XCHVSwings CH"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrMagenta
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
#define cSLBufferIndex 1
|
||||
double cSLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XCHVSwings CL"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
#define sSHBufferIndex 2
|
||||
double sSHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XCHVSwings SH"
|
||||
#property indicator_type3 DRAW_ARROW
|
||||
#property indicator_color3 clrMagenta
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
#define sSLBufferIndex 3
|
||||
double sSLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XCHVSwings SL"
|
||||
#property indicator_type4 DRAW_ARROW
|
||||
#property indicator_color4 clrAqua
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 2
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
#define mSHBufferIndex 4
|
||||
double mSHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XCHVSwings MH"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrMagenta
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 2
|
||||
|
||||
//
|
||||
#define mSLBufferIndex 5
|
||||
double mSLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "XCHVSwings ML"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrAqua
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 2
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
#define lSHBufferIndex 6
|
||||
double lSHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "XCHVSwings LH"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrMagenta
|
||||
#property indicator_style7 STYLE_SOLID
|
||||
#property indicator_width7 2
|
||||
|
||||
//
|
||||
#define lSLBufferIndex 7
|
||||
double lSLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "XCHVSwings LL"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrAqua
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 2
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
#define hSHBufferIndex 8
|
||||
double hSHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "XCHVSwings HH"
|
||||
#property indicator_type9 DRAW_ARROW
|
||||
#property indicator_color9 clrMagenta
|
||||
#property indicator_style9 STYLE_SOLID
|
||||
#property indicator_width9 2
|
||||
|
||||
//
|
||||
#define hSLBufferIndex 9
|
||||
double hSLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "XCHVSwings HL"
|
||||
#property indicator_type10 DRAW_ARROW
|
||||
#property indicator_color10 clrAqua
|
||||
#property indicator_style10 STYLE_SOLID
|
||||
#property indicator_width10 2
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Cuurent ...
|
||||
int mCMarketLength = length;
|
||||
|
||||
//
|
||||
double cH1 = 0;
|
||||
double cL1 = 0;
|
||||
datetime cH1Time = 0;
|
||||
datetime cL1Time = 0;
|
||||
|
||||
//
|
||||
// Short ...
|
||||
int mSCycleLength = 0;
|
||||
int mSMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||
|
||||
//
|
||||
double sH1 = 0;
|
||||
double sL1 = 0;
|
||||
datetime sH1Time = 0;
|
||||
datetime sL1Time = 0;
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
int mMCycleLength = 0;
|
||||
int mMMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||
|
||||
//
|
||||
double mH1 = 0;
|
||||
double mL1 = 0;
|
||||
datetime mH1Time = 0;
|
||||
datetime mL1Time = 0;
|
||||
|
||||
//
|
||||
// Long ...
|
||||
int mLCycleLength = 0;
|
||||
int mLMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||
|
||||
//
|
||||
double lH1 = 0;
|
||||
double lL1 = 0;
|
||||
datetime lH1Time = 0;
|
||||
datetime lL1Time = 0;
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
int mHCycleLength = 0;
|
||||
int mHMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||
|
||||
//
|
||||
double hH1 = 0;
|
||||
double hL1 = 0;
|
||||
datetime hH1Time = 0;
|
||||
datetime hL1Time = 0;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitMarketCycles())
|
||||
{
|
||||
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(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int start;
|
||||
|
||||
//
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
start = maxLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = prev_calculated - 1;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = start; i < rates_total - maxLength && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
time,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length >= 2 &&
|
||||
//
|
||||
(IsValid(scMethod, scPeriod) &&
|
||||
IsValid(mcMethod, mcPeriod) &&
|
||||
IsValid(lcMethod, lcPeriod) &&
|
||||
IsValid(hcMethod, hcPeriod))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Market Cycles ...
|
||||
bool InitMarketCycles()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Current Cycle Initialization ...
|
||||
|
||||
//
|
||||
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||
|
||||
//
|
||||
// Short Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (scMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mSCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSCPeriod = scPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mSCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||
mSMarketLength = mSCycleLength * mCMarketLength;
|
||||
result = mSCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Medium Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (mcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mMCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMCPeriod = mcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mMCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||
mMMarketLength = mMCycleLength * mCMarketLength;
|
||||
result = mMCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Long Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (lcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mLCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_LONG,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLCPeriod = lcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mLCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||
mLMarketLength = mLCycleLength * mCMarketLength;
|
||||
result = mLCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hind Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (hcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mHCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_HIND,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mHCPeriod = hcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mHCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||
mHMarketLength = mHCycleLength * mCMarketLength;
|
||||
result = mHCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(mCMarketLength, mSMarketLength);
|
||||
result = MathMax(result, mMMarketLength);
|
||||
result = MathMax(result, mLMarketLength);
|
||||
result = MathMax(result, mHMarketLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
|
||||
// Setting Indicator Digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE cSHDrawType =
|
||||
showCurrent && showSwingHighs
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(cSHBufferIndex, cSHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(cSHBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(cSHBufferIndex, PLOT_ARROW, 234);
|
||||
PlotIndexSetInteger(cSHBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingHighs);
|
||||
PlotIndexSetInteger(cSHBufferIndex, PLOT_DRAW_TYPE, cSHDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE cSLDrawType =
|
||||
showCurrent && showSwingLows
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(cSLBufferIndex, cSLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(cSLBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(cSLBufferIndex, PLOT_ARROW, 233);
|
||||
PlotIndexSetInteger(cSLBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingLows);
|
||||
PlotIndexSetInteger(cSLBufferIndex, PLOT_DRAW_TYPE, cSLDrawType);
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE sSHDrawType =
|
||||
showShort && showSwingHighs
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(sSHBufferIndex, sSHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(sSHBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(sSHBufferIndex, PLOT_ARROW, 234);
|
||||
PlotIndexSetInteger(sSHBufferIndex, PLOT_SHOW_DATA, showShort && showSwingHighs);
|
||||
PlotIndexSetInteger(sSHBufferIndex, PLOT_DRAW_TYPE, sSHDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE sSLDrawType =
|
||||
showShort && showSwingLows
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(sSLBufferIndex, sSLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(sSLBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(sSLBufferIndex, PLOT_ARROW, 233);
|
||||
PlotIndexSetInteger(sSLBufferIndex, PLOT_SHOW_DATA, showShort && showSwingLows);
|
||||
PlotIndexSetInteger(sSLBufferIndex, PLOT_DRAW_TYPE, sSLDrawType);
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE mSHDrawType =
|
||||
showMedium && showSwingHighs
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(mSHBufferIndex, mSHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(mSHBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(mSHBufferIndex, PLOT_ARROW, 234);
|
||||
PlotIndexSetInteger(mSHBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingHighs);
|
||||
PlotIndexSetInteger(mSHBufferIndex, PLOT_DRAW_TYPE, mSHDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE mSLDrawType =
|
||||
showMedium && showSwingLows
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(mSLBufferIndex, mSLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(mSLBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(mSLBufferIndex, PLOT_ARROW, 233);
|
||||
PlotIndexSetInteger(mSLBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingLows);
|
||||
PlotIndexSetInteger(mSLBufferIndex, PLOT_DRAW_TYPE, mSLDrawType);
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE lSHDrawType =
|
||||
showLong && showSwingHighs
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(lSHBufferIndex, lSHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(lSHBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(lSHBufferIndex, PLOT_ARROW, 234);
|
||||
PlotIndexSetInteger(lSHBufferIndex, PLOT_SHOW_DATA, showLong && showSwingHighs);
|
||||
PlotIndexSetInteger(lSHBufferIndex, PLOT_DRAW_TYPE, lSHDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE lSLDrawType =
|
||||
showLong && showSwingLows
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(lSLBufferIndex, lSLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(lSLBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(lSLBufferIndex, PLOT_ARROW, 233);
|
||||
PlotIndexSetInteger(lSLBufferIndex, PLOT_SHOW_DATA, showLong && showSwingLows);
|
||||
PlotIndexSetInteger(lSLBufferIndex, PLOT_DRAW_TYPE, lSLDrawType);
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE hSHDrawType =
|
||||
showHind && showSwingHighs
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(hSHBufferIndex, hSHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(hSHBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(hSHBufferIndex, PLOT_ARROW, 234);
|
||||
PlotIndexSetInteger(hSHBufferIndex, PLOT_SHOW_DATA, showHind && showSwingHighs);
|
||||
PlotIndexSetInteger(hSHBufferIndex, PLOT_DRAW_TYPE, hSHDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE hSLDrawType =
|
||||
showHind && showSwingLows
|
||||
? DRAW_ARROW
|
||||
: DRAW_NONE;
|
||||
|
||||
//
|
||||
SetIndexBuffer(hSLBufferIndex, hSLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(hSLBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(hSLBufferIndex, PLOT_ARROW, 233);
|
||||
PlotIndexSetInteger(hSLBufferIndex, PLOT_SHOW_DATA, showHind && showSwingLows);
|
||||
PlotIndexSetInteger(hSLBufferIndex, PLOT_DRAW_TYPE, hSLDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
//
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateCycles(
|
||||
//
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
time,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycles(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
//
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// CURRENT ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
time,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mCMarketLength,
|
||||
showCurrent,
|
||||
cSHBuffer,
|
||||
cSLBuffer,
|
||||
cH1,
|
||||
cH1Time,
|
||||
cL1,
|
||||
cL1Time //
|
||||
);
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
time,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mSMarketLength,
|
||||
showShort,
|
||||
sSHBuffer,
|
||||
sSLBuffer,
|
||||
sH1,
|
||||
sH1Time,
|
||||
sL1,
|
||||
sL1Time //
|
||||
);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
time,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mMMarketLength,
|
||||
showMedium,
|
||||
mSHBuffer,
|
||||
mSLBuffer,
|
||||
mH1,
|
||||
mH1Time,
|
||||
mL1,
|
||||
mL1Time //
|
||||
);
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
time,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mLMarketLength,
|
||||
showLong,
|
||||
lSHBuffer,
|
||||
lSLBuffer,
|
||||
lH1,
|
||||
lH1Time,
|
||||
lL1,
|
||||
lL1Time //
|
||||
);
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
time,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mHMarketLength,
|
||||
showHind,
|
||||
hSHBuffer,
|
||||
hSLBuffer,
|
||||
hH1,
|
||||
hH1Time,
|
||||
hL1,
|
||||
hL1Time //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycle(
|
||||
//
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
//
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length, // Calculation Length
|
||||
bool _show,
|
||||
double &_hBuffer[],
|
||||
double &_lBuffer[],
|
||||
double &_h1,
|
||||
datetime &_h1Time,
|
||||
double &_l1,
|
||||
datetime &_l1Time //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool isSwingHigh = true;
|
||||
bool isSwingLow = true;
|
||||
|
||||
//
|
||||
_hBuffer[bar_index] = 0;
|
||||
_lBuffer[bar_index] = 0;
|
||||
|
||||
//
|
||||
// Check for Swing High
|
||||
for (int j = 1; j <= _length; j++)
|
||||
{
|
||||
//
|
||||
if (high[bar_index] <= high[bar_index + j] || high[bar_index] <= high[bar_index - j])
|
||||
{
|
||||
//
|
||||
isSwingHigh = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Swing Low
|
||||
for (int j = 1; j <= _length; j++)
|
||||
{
|
||||
//
|
||||
if (low[bar_index] >= low[bar_index + j] || low[bar_index] >= low[bar_index - j])
|
||||
{
|
||||
//
|
||||
isSwingLow = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (isSwingHigh)
|
||||
{
|
||||
//
|
||||
_hBuffer[bar_index] = high[bar_index];
|
||||
if (high[bar_index] > _h1 || _h1 == 0)
|
||||
{
|
||||
//
|
||||
_h1 = high[bar_index];
|
||||
_h1Time = time[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (isSwingLow)
|
||||
{
|
||||
//
|
||||
_lBuffer[bar_index] = low[bar_index];
|
||||
if (low[bar_index] < _l1 || _l1 == 0)
|
||||
{
|
||||
//
|
||||
_l1 = low[bar_index];
|
||||
_l1Time = time[bar_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,900 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XCHTD
|
||||
// Description: XCHTD Cycles ...
|
||||
//
|
||||
// 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 XCHTD Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XCHTD"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
enum ENUM_XCHTD_MODE
|
||||
{
|
||||
XCHTD_POWER_MODE = 0, // Using Power
|
||||
XCHTD_PRESSURE_MODE = 1, // Using Pressure
|
||||
XCHTD_TYPE_MODE = 2, // Using Type
|
||||
XCHTD_STRONG_MODE = 3, // Using Power and Pressures
|
||||
};
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 14; // Length
|
||||
input ENUM_XCHTD_MODE mode = XCHTD_POWER_MODE; // Mode
|
||||
|
||||
//
|
||||
input group "Cycles";
|
||||
|
||||
//
|
||||
input group "Short";
|
||||
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Medium";
|
||||
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Long";
|
||||
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Hind";
|
||||
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
// Current ...
|
||||
input bool showCurrent = true; // Show Current Cycle
|
||||
input bool showShort = true; // Show Short Cycle
|
||||
input bool showMedium = true; // Show Medium Cycle
|
||||
input bool showLong = true; // Show Long Cycle
|
||||
input bool showHind = true; // Show Hind Cycle
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
#define cBullBufferIndex 0
|
||||
double cBullBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XCHTD C Bull"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
|
||||
//
|
||||
#define cBearBufferIndex 1
|
||||
double cBearBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XCHTD C Bear"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_color2 clrRed
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
#define sBullBufferIndex 2
|
||||
double sBullBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XCHTD S Bull"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrLime
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
|
||||
//
|
||||
#define sBearBufferIndex 3
|
||||
double sBearBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XCHTD S Bear"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_color4 clrRed
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
#define mBullBufferIndex 4
|
||||
double mBullBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XCHTD M Bull"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrLime
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
|
||||
//
|
||||
#define mBearBufferIndex 5
|
||||
double mBearBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "XCHTD M Bear"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_color6 clrRed
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
#define lBullBufferIndex 6
|
||||
double lBullBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "XCHTD L Bull"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrLime
|
||||
#property indicator_style7 STYLE_SOLID
|
||||
|
||||
//
|
||||
#define lBearBufferIndex 7
|
||||
double lBearBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "XCHTD L Bear"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_color8 clrRed
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
#define hBullBufferIndex 8
|
||||
double hBullBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "XCHTD H Bull"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrLime
|
||||
#property indicator_style9 STYLE_SOLID
|
||||
|
||||
//
|
||||
#define hBearBufferIndex 9
|
||||
double hBearBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "XCHTD H Bear"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_style10 STYLE_SOLID
|
||||
#property indicator_color10 clrRed
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
int mCMarketLength = length;
|
||||
|
||||
//
|
||||
// Short ...
|
||||
int mSCycleLength = 0;
|
||||
int mSMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
int mMCycleLength = 0;
|
||||
int mMMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||
|
||||
//
|
||||
// Long ...
|
||||
int mLCycleLength = 0;
|
||||
int mLMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
int mHCycleLength = 0;
|
||||
int mHMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitMarketCycles())
|
||||
{
|
||||
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(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length >= 2 &&
|
||||
//
|
||||
(IsValid(scMethod, scPeriod) &&
|
||||
IsValid(mcMethod, mcPeriod) &&
|
||||
IsValid(lcMethod, lcPeriod) &&
|
||||
IsValid(hcMethod, hcPeriod))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Market Cycles ...
|
||||
bool InitMarketCycles()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Current Cycle Initialization ...
|
||||
|
||||
//
|
||||
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||
|
||||
//
|
||||
// Short Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (scMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mSCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSCPeriod = scPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mSCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||
mSMarketLength = mSCycleLength * mCMarketLength;
|
||||
result = mSCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Medium Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (mcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mMCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMCPeriod = mcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mMCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||
mMMarketLength = mMCycleLength * mCMarketLength;
|
||||
result = mMCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Long Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (lcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mLCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_LONG,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLCPeriod = lcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mLCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||
mLMarketLength = mLCycleLength * mCMarketLength;
|
||||
result = mLCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hind Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (hcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mHCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_HIND,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mHCPeriod = hcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mHCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||
mHMarketLength = mHCycleLength * mCMarketLength;
|
||||
result = mHCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(mCMarketLength, mSMarketLength);
|
||||
result = MathMax(result, mMMarketLength);
|
||||
result = MathMax(result, mLMarketLength);
|
||||
result = MathMax(result, mHMarketLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(cBullBuffer, true);
|
||||
SetIndexBuffer(cBullBufferIndex, cBullBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(cBullBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||
// PlotIndexSetInteger(cBullBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(cBearBuffer, true);
|
||||
SetIndexBuffer(cBearBufferIndex, cBearBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(cBearBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||
// PlotIndexSetInteger(cBearBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sBullBuffer, true);
|
||||
SetIndexBuffer(sBullBufferIndex, sBullBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(sBullBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||
// PlotIndexSetInteger(sBullBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sBearBuffer, true);
|
||||
SetIndexBuffer(sBearBufferIndex, sBearBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(sBearBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||
// PlotIndexSetInteger(sBearBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mBullBuffer, true);
|
||||
SetIndexBuffer(mBullBufferIndex, mBullBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(mBullBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||
// PlotIndexSetInteger(mBullBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mBearBuffer, true);
|
||||
SetIndexBuffer(mBearBufferIndex, mBearBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(mBearBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||
// PlotIndexSetInteger(mBearBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lBullBuffer, true);
|
||||
SetIndexBuffer(lBullBufferIndex, lBullBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(lBullBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||
// PlotIndexSetInteger(lBullBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lBearBuffer, true);
|
||||
SetIndexBuffer(lBearBufferIndex, lBearBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(lBearBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||
// PlotIndexSetInteger(lBearBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hBullBuffer, true);
|
||||
SetIndexBuffer(hBullBufferIndex, hBullBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(hBullBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||
// PlotIndexSetInteger(hBullBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hBearBuffer, true);
|
||||
SetIndexBuffer(hBearBufferIndex, hBearBuffer, INDICATOR_CALCULATIONS);
|
||||
// PlotIndexSetInteger(hBearBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||
// PlotIndexSetInteger(hBearBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
|
||||
//
|
||||
// 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[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateCycles(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycles(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// CURRENT ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mCMarketLength,
|
||||
showCurrent,
|
||||
cBullBuffer,
|
||||
cBearBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mSMarketLength,
|
||||
showShort,
|
||||
sBullBuffer,
|
||||
sBearBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mMMarketLength,
|
||||
showMedium,
|
||||
mBullBuffer,
|
||||
mBearBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mLMarketLength,
|
||||
showLong,
|
||||
lBullBuffer,
|
||||
lBearBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mHMarketLength,
|
||||
showHind,
|
||||
hBullBuffer,
|
||||
hBearBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycle(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length, // Calculation Length
|
||||
bool _show,
|
||||
double &_bull[],
|
||||
double &_bear[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double bullPower = 0;
|
||||
double bearPower = 0;
|
||||
|
||||
//
|
||||
double lowShadow = 0;
|
||||
double highShadow = 0;
|
||||
|
||||
//
|
||||
double bullPressure = 0;
|
||||
double bearPressure = 0;
|
||||
|
||||
//
|
||||
double bullRange = 0;
|
||||
double bearRange = 0;
|
||||
|
||||
//
|
||||
for (int i = bar_index; i < bar_index + _length; i++)
|
||||
{
|
||||
//
|
||||
bool isBullish =
|
||||
//
|
||||
close[i] > open[i]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBearish =
|
||||
//
|
||||
close[i] < open[i]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double iUpper = MathMax(open[i], close[i]);
|
||||
double iLower = MathMin(open[i], close[i]);
|
||||
|
||||
//
|
||||
double iBody = iUpper - iLower;
|
||||
double iRange = high[i] - low[i];
|
||||
|
||||
//
|
||||
double iHighShadow = high[i] - iUpper;
|
||||
double iLowShadow = iLower - low[i];
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
bullPower += iBody;
|
||||
bullRange += iRange;
|
||||
bearPressure += iHighShadow;
|
||||
}
|
||||
else if (isBearish)
|
||||
{
|
||||
//
|
||||
bearPower += iBody;
|
||||
bearRange += iRange;
|
||||
bullPressure += iLowShadow;
|
||||
}
|
||||
|
||||
//
|
||||
lowShadow += iLowShadow;
|
||||
highShadow += iHighShadow;
|
||||
}
|
||||
|
||||
//
|
||||
if (mode == XCHTD_POWER_MODE)
|
||||
{
|
||||
//
|
||||
_bull[bar_index] = bullPower;
|
||||
_bear[bar_index] = bearPower;
|
||||
}
|
||||
else if (mode == XCHTD_PRESSURE_MODE)
|
||||
{
|
||||
//
|
||||
_bull[bar_index] = bullPressure;
|
||||
_bear[bar_index] = bearPressure;
|
||||
}
|
||||
else if (mode == XCHTD_TYPE_MODE)
|
||||
{
|
||||
//
|
||||
_bull[bar_index] = bullRange;
|
||||
_bear[bar_index] = bearRange;
|
||||
}
|
||||
else if (mode == XCHTD_STRONG_MODE)
|
||||
{
|
||||
//
|
||||
_bull[bar_index] = bullPower + bullPressure;
|
||||
_bear[bar_index] = bearPower + bearPressure;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1,814 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XCHVLM
|
||||
// Description: XCHVLM Cycles ...
|
||||
//
|
||||
// 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 XCHVLM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XCHVLM"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include <Math/Stat/Normal.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 14; // Length
|
||||
|
||||
//
|
||||
input group "Cycles";
|
||||
|
||||
//
|
||||
input group "Short";
|
||||
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Medium";
|
||||
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Long";
|
||||
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Hind";
|
||||
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input bool showCurrent = true; // Show Current Cycle
|
||||
input bool showShort = true; // Show Short Cycle
|
||||
input bool showMedium = true; // Show Medium Cycle
|
||||
input bool showLong = true; // Show Long Cycle
|
||||
input bool showHind = true; // Show Hind Cycle
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
#define cBufferIndex 0
|
||||
double cBuffer[];
|
||||
|
||||
//
|
||||
#define cColorBufferIndex 1
|
||||
double cColorBuffer[];
|
||||
|
||||
//
|
||||
#define cPlotBufferIndex 0
|
||||
#property indicator_label1 "XCHVLM C"
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
#define sBufferIndex 2
|
||||
double sBuffer[];
|
||||
|
||||
//
|
||||
#define sColorBufferIndex 3
|
||||
double sColorBuffer[];
|
||||
|
||||
//
|
||||
#define sPlotBufferIndex 1
|
||||
#property indicator_label2 "XCHVLM S"
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color2 CLR_NONE, clrLime, clrRed
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
#define mBufferIndex 4
|
||||
double mBuffer[];
|
||||
|
||||
//
|
||||
#define mColorBufferIndex 5
|
||||
double mColorBuffer[];
|
||||
|
||||
//
|
||||
#define mPlotBufferIndex 2
|
||||
#property indicator_label3 "XCHVLM M"
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_type3 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color3 CLR_NONE, clrLime, clrRed
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
#define lBufferIndex 6
|
||||
double lBuffer[];
|
||||
|
||||
//
|
||||
#define lColorBufferIndex 7
|
||||
double lColorBuffer[];
|
||||
|
||||
//
|
||||
#define lPlotBufferIndex 3
|
||||
#property indicator_label4 "XCHVLM L"
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_type4 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color4 CLR_NONE, clrLime, clrRed
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
#define hBufferIndex 8
|
||||
double hBuffer[];
|
||||
|
||||
//
|
||||
#define hColorBufferIndex 9
|
||||
double hColorBuffer[];
|
||||
|
||||
//
|
||||
#define hPlotBufferIndex 4
|
||||
#property indicator_label5 "XCHVLM H"
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_type5 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color5 CLR_NONE, clrLime, clrRed
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
int mCMarketLength = length;
|
||||
double cVolumes[];
|
||||
double cDistances[];
|
||||
|
||||
//
|
||||
// Short ...
|
||||
int mSCycleLength = 0;
|
||||
int mSMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||
double sVolumes[];
|
||||
double sDistances[];
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
int mMCycleLength = 0;
|
||||
int mMMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||
double mVolumes[];
|
||||
double mDistances[];
|
||||
|
||||
//
|
||||
// Long ...
|
||||
int mLCycleLength = 0;
|
||||
int mLMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||
double lVolumes[];
|
||||
double lDistances[];
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
int mHCycleLength = 0;
|
||||
int mHMarketLength = 0;
|
||||
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||
double hVolumes[];
|
||||
double hDistances[];
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitMarketCycles())
|
||||
{
|
||||
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();
|
||||
|
||||
//
|
||||
// Current ...
|
||||
ArrayResize(cVolumes, maxLength, 0);
|
||||
ArrayResize(cDistances, maxLength, 0);
|
||||
|
||||
//
|
||||
// Short ...
|
||||
ArrayResize(sVolumes, maxLength, 0);
|
||||
ArrayResize(sDistances, maxLength, 0);
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
ArrayResize(mVolumes, maxLength, 0);
|
||||
ArrayResize(mDistances, maxLength, 0);
|
||||
|
||||
//
|
||||
// Long ...
|
||||
ArrayResize(lVolumes, maxLength, 0);
|
||||
ArrayResize(lDistances, maxLength, 0);
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
ArrayResize(hVolumes, maxLength, 0);
|
||||
ArrayResize(hDistances, maxLength, 0);
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
Clean(cVolumes);
|
||||
Clean(cDistances);
|
||||
|
||||
//
|
||||
Clean(sVolumes);
|
||||
Clean(sDistances);
|
||||
|
||||
//
|
||||
Clean(mVolumes);
|
||||
Clean(mDistances);
|
||||
|
||||
//
|
||||
Clean(lVolumes);
|
||||
Clean(lDistances);
|
||||
|
||||
//
|
||||
Clean(hVolumes);
|
||||
Clean(hDistances);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
static int i = maxLength * 2;
|
||||
for (i; i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
i = rates_total - 1;
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length >= 2 &&
|
||||
//
|
||||
(IsValid(scMethod, scPeriod) &&
|
||||
IsValid(mcMethod, mcPeriod) &&
|
||||
IsValid(lcMethod, lcPeriod) &&
|
||||
IsValid(hcMethod, hcPeriod))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Market Cycles ...
|
||||
bool InitMarketCycles()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Current Cycle Initialization ...
|
||||
|
||||
//
|
||||
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||
|
||||
//
|
||||
// Short Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (scMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mSCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSCPeriod = scPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mSCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||
mSMarketLength = mSCycleLength * mCMarketLength;
|
||||
result = mSCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Medium Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (mcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mMCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMCPeriod = mcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mMCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||
mMMarketLength = mMCycleLength * mCMarketLength;
|
||||
result = mMCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Long Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (lcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mLCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_LONG,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLCPeriod = lcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mLCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||
mLMarketLength = mLCycleLength * mCMarketLength;
|
||||
result = mLCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hind Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (hcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mHCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_HIND,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mHCPeriod = hcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mHCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||
mHMarketLength = mHCycleLength * mCMarketLength;
|
||||
result = mHCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(mCMarketLength, mSMarketLength);
|
||||
result = MathMax(result, mMMarketLength);
|
||||
result = MathMax(result, mLMarketLength);
|
||||
result = MathMax(result, mHMarketLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
// PlotIndexSetInteger(cPlotBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||
// PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||
// SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
// PlotIndexSetInteger(sPlotBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||
// PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||
// SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
// PlotIndexSetInteger(mPlotBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||
// PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||
// SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
// PlotIndexSetInteger(lPlotBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||
// PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||
// SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
// ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
// PlotIndexSetInteger(hPlotBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||
// PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||
// SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
|
||||
//
|
||||
// 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[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateCycles(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycles(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// CURRENT ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mCMarketLength,
|
||||
showCurrent,
|
||||
cVolumes,
|
||||
cDistances,
|
||||
cBuffer,
|
||||
cColorBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mSMarketLength,
|
||||
showShort,
|
||||
sVolumes,
|
||||
sDistances,
|
||||
sBuffer,
|
||||
sColorBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mMMarketLength,
|
||||
showMedium,
|
||||
mVolumes,
|
||||
mDistances,
|
||||
mBuffer,
|
||||
mColorBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mLMarketLength,
|
||||
showLong,
|
||||
lVolumes,
|
||||
lDistances,
|
||||
lBuffer,
|
||||
lColorBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mHMarketLength,
|
||||
showHind,
|
||||
hVolumes,
|
||||
hDistances,
|
||||
hBuffer,
|
||||
hColorBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycle(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length, // Calculation Length
|
||||
bool _show,
|
||||
double &_volumes[],
|
||||
double &_distances[],
|
||||
double &_buffer[],
|
||||
double &_colorBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
for (int x = 0; x < _length; x++)
|
||||
{
|
||||
//
|
||||
_volumes[x] = (double)tickVolume[bar_index - x];
|
||||
_distances[x] =
|
||||
(close[bar_index - x] > open[bar_index - x])
|
||||
? high[bar_index - x] - low[bar_index - x]
|
||||
: low[bar_index - x] - high[bar_index - x];
|
||||
}
|
||||
|
||||
//
|
||||
double iValue = MathMean(_volumes) * MathMean(_distances);
|
||||
|
||||
//
|
||||
_buffer[bar_index] = iValue;
|
||||
_colorBuffer[bar_index] = iValue > 0
|
||||
? _show
|
||||
? bullishColorIDX
|
||||
: hideColorIDX
|
||||
: _show
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1,830 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XCHVWAP
|
||||
// Description: XCHVWAP Trend Detector ...
|
||||
//
|
||||
// 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 XCHVWAP Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XCHVWAP"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Cycles";
|
||||
|
||||
//
|
||||
input group "Short";
|
||||
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Medium";
|
||||
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Long";
|
||||
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
input group "Hind";
|
||||
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showShort = true; // Show Short Cycle
|
||||
input bool showMedium = true; // Show Medium Cycle
|
||||
input bool showLong = true; // Show Long Cycle
|
||||
input bool showHind = true; // Show Hind Cycle
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 14
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
#define sBufferIndex 0
|
||||
double sBuffer[];
|
||||
|
||||
//
|
||||
#define sColorBufferIndex 1
|
||||
double sColorBuffer[];
|
||||
|
||||
//
|
||||
#define sPlotBufferIndex 0
|
||||
#property indicator_label1 "XCHVWAP S"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
#define mBufferIndex 2
|
||||
double mBuffer[];
|
||||
|
||||
//
|
||||
#define mColorBufferIndex 3
|
||||
double mColorBuffer[];
|
||||
|
||||
//
|
||||
#define mPlotBufferIndex 1
|
||||
#property indicator_label2 "XCHVWAP M"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
#define lBufferIndex 4
|
||||
double lBuffer[];
|
||||
|
||||
//
|
||||
#define lColorBufferIndex 5
|
||||
double lColorBuffer[];
|
||||
|
||||
//
|
||||
#define lPlotBufferIndex 2
|
||||
#property indicator_label3 "XCHVWAP L"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
#define hBufferIndex 6
|
||||
double hBuffer[];
|
||||
|
||||
//
|
||||
#define hColorBufferIndex 7
|
||||
double hColorBuffer[];
|
||||
|
||||
//
|
||||
#define hPlotBufferIndex 3
|
||||
#property indicator_label4 "XCHVWAP H"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Volumes ...
|
||||
#define volumeBufferIndex 8
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define priceBufferIndex 9
|
||||
double priceBuffer[];
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
#define sStateBufferIndex 10
|
||||
double sStateBuffer[];
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
#define mStateBufferIndex 11
|
||||
double mStateBuffer[];
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
#define lStateBufferIndex 12
|
||||
double lStateBuffer[];
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
#define hStateBufferIndex 13
|
||||
double hStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Short ...
|
||||
int mSCycleLength = 0;
|
||||
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
int mMCycleLength = 0;
|
||||
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||
|
||||
//
|
||||
// Long ...
|
||||
int mLCycleLength = 0;
|
||||
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
int mHCycleLength = 0;
|
||||
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitMarketCycles())
|
||||
{
|
||||
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(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, 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,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(IsValid(scMethod, scPeriod) &&
|
||||
IsValid(mcMethod, mcPeriod) &&
|
||||
IsValid(lcMethod, lcPeriod) &&
|
||||
IsValid(hcMethod, hcPeriod))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Market Cycles ...
|
||||
bool InitMarketCycles()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Current Cycle Initialization ...
|
||||
|
||||
//
|
||||
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||
|
||||
//
|
||||
// Short Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (scMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mSCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSCPeriod = scPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mSCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||
result = mSCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Medium Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (mcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mMCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMCPeriod = mcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mMCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||
result = mMCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Long Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (lcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mLCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_LONG,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLCPeriod = lcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mLCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||
result = mLCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hind Cycle Initialization ...
|
||||
|
||||
//
|
||||
// Find Cycle Period ...
|
||||
if (hcMethod == X_PERIOD_AUTO)
|
||||
{
|
||||
//
|
||||
// Select Period ...
|
||||
mHCPeriod = GetCyclePeriod(
|
||||
X_MARKET_CYCLE_HIND,
|
||||
_Period //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
mHCPeriod = hcPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(mHCPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||
result = mHCycleLength > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
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()
|
||||
{
|
||||
//
|
||||
// Short ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sBuffer, true);
|
||||
ArraySetAsSeries(sColorBuffer, true);
|
||||
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mBuffer, true);
|
||||
ArraySetAsSeries(mColorBuffer, true);
|
||||
SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lBuffer, true);
|
||||
ArraySetAsSeries(lColorBuffer, true);
|
||||
SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Hind ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hBuffer, true);
|
||||
ArraySetAsSeries(hColorBuffer, true);
|
||||
SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Volumes ...
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Price ...
|
||||
ArraySetAsSeries(priceBuffer, true);
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Short State ...
|
||||
ArraySetAsSeries(sStateBuffer, true);
|
||||
SetIndexBuffer(sStateBufferIndex, sStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Medium State ...
|
||||
ArraySetAsSeries(mStateBuffer, true);
|
||||
SetIndexBuffer(mStateBufferIndex, mStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Long State ...
|
||||
ArraySetAsSeries(lStateBuffer, true);
|
||||
SetIndexBuffer(lStateBufferIndex, lStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Hind State ...
|
||||
ArraySetAsSeries(hStateBuffer, true);
|
||||
SetIndexBuffer(hStateBufferIndex, hStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(mSCycleLength, mMCycleLength);
|
||||
result = MathMax(result, mLCycleLength);
|
||||
result = MathMax(result, mHCycleLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate Volumes and Price ...
|
||||
|
||||
//
|
||||
if (ratesTotal - bar_index <= maxLength)
|
||||
{
|
||||
//
|
||||
CalculateDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
CalculateDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
|
||||
//
|
||||
CalculateCycles(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateDataBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double price = GetAppliedPrice(
|
||||
appliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
priceBuffer[bar_index] = price;
|
||||
volumeBuffer[bar_index] = (double)tickVolume[bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycles(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// SHORT ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mSCycleLength,
|
||||
showShort,
|
||||
sBuffer,
|
||||
sColorBuffer,
|
||||
sStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mMCycleLength,
|
||||
showMedium,
|
||||
mBuffer,
|
||||
mColorBuffer,
|
||||
mStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mLCycleLength,
|
||||
showLong,
|
||||
lBuffer,
|
||||
lColorBuffer,
|
||||
lStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
CalculateCycle(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
mHCycleLength,
|
||||
showHind,
|
||||
hBuffer,
|
||||
hColorBuffer,
|
||||
hStateBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycle(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length, // Calculation Length
|
||||
bool _show,
|
||||
double &_buffer[],
|
||||
double &_colorBuffer[],
|
||||
double &_stateBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double vSum = 0;
|
||||
double pSum = 0;
|
||||
double mSum = 0;
|
||||
for (int x = 0; x < _length; x++)
|
||||
{
|
||||
//
|
||||
pSum += priceBuffer[x + bar_index];
|
||||
vSum += volumeBuffer[x + bar_index];
|
||||
mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
double iValue = mSum / vSum;
|
||||
iValue = NormalizeDouble(iValue, _Digits);
|
||||
|
||||
//
|
||||
_buffer[bar_index] = iValue;
|
||||
|
||||
//
|
||||
bool isBullish = low[bar_index] > iValue;
|
||||
bool isBearish = high[bar_index] < iValue;
|
||||
|
||||
//
|
||||
double iColor =
|
||||
isBullish
|
||||
? bullishColorIDX
|
||||
: isBearish
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
|
||||
//
|
||||
_colorBuffer[bar_index] = hideColorIDX;
|
||||
_stateBuffer[bar_index] = iColor;
|
||||
if (_show)
|
||||
{
|
||||
_colorBuffer[bar_index] = iColor;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user