diff --git a/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-button.class.mq5 b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-button.class.mq5 new file mode 100644 index 00000000..1d9d6abb --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-button.class.mq5 @@ -0,0 +1,156 @@ +/////////////////////////////////////////////////////// +// +// 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: + // +}; diff --git a/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-edit.class.mq5 b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-edit.class.mq5 new file mode 100644 index 00000000..dab9ffea --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-edit.class.mq5 @@ -0,0 +1,186 @@ +/////////////////////////////////////////////////////// +// +// 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: + // +}; diff --git a/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-label.class.mq5 b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-label.class.mq5 new file mode 100644 index 00000000..ddb91e8f --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-label.class.mq5 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// 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: + // +}; diff --git a/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-panel.class.mq5 b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-panel.class.mq5 new file mode 100644 index 00000000..ee441357 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-panel.class.mq5 @@ -0,0 +1,299 @@ +/////////////////////////////////////////////////////// +// +// 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; + + // +}; \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-rectangle.label.class.mq5 b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-rectangle.label.class.mq5 new file mode 100644 index 00000000..055cc712 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.x-rectangle.label.class.mq5 @@ -0,0 +1,259 @@ +/////////////////////////////////////////////////////// +// +// 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 +}; diff --git a/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.xcobject.class.mq5 b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.xcobject.class.mq5 new file mode 100644 index 00000000..4252b2c4 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/XCObjects/x-saherelm.xcobject.class.mq5 @@ -0,0 +1,116 @@ +/////////////////////////////////////////////////////// +// +// 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: + // +}; diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.base.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.base.class.mq5 new file mode 100644 index 00000000..a9771d1b --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.base.class.mq5 @@ -0,0 +1,97 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XBaseClass +// 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 "../Libraries/x-saherelm.common.lib.mq5" + +// +// XBase Class ... +class XSCBase +{ + // + // Public ... +public: + // + // Protected ... + + // + // Represent Basic Unique Tag ... + virtual string GetTag(); + + // + // Retrieve Class Token ... + virtual string GetToken(); + + // + // Protected +protected: + // + // Private ... +private: +}; + +// +template +string GenerateSpecifiedCommonSummary( + T &mItem, + string separator = "\n", + bool includeScores = true, + bool setLabel = false // +) +{ + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + mItem.GenerateScore( + bullishScore, + bearishScore // + ); + + // + result = + // + (!setLabel + ? "" + : "Commons:" + separator) + + "---------------" + separator + + "Symbol: " + mItem.symbol + separator + + "Period: " + ToString(mItem.period) + separator + + "Time: " + ToString(mItem.time) + separator + + (includeScores + ? "---------------" + separator + + "Scores:" + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "---------------" + separator + : "") + + "" + // + ; + + // + return result; +} + +// diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.x121.xtrade.handler.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.x121.xtrade.handler.class.mq5 new file mode 100644 index 00000000..fb58cbe9 Binary files /dev/null and b/Documents/BKP/14030802-X121/Classes/x-saherelm.x121.xtrade.handler.class.mq5 differ diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.xaccount.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.xaccount.class.mq5 new file mode 100644 index 00000000..66169f54 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.xaccount.class.mq5 @@ -0,0 +1,398 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCAccount +// Description: provides all Account 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 + +// +// START Definitions ... +// + +// +// END Definitions ... +// + +// +// START Import and Inclused requirements ... +// + +// +// Includes ... +#include +#include "../Classes/x-saherelm.base.class.mq5" + +// +// END Import and Inclused requirements ... +// + +// +// START Overrides ... +// + +// +// END Overrides ... +// + +// +// a Class for Manage Account ... +class XSCAccount : public XSCBase +{ + // + // Public ... +public: + // + // Constructor ... + void XSCAccount() + { + // + mAccountInfo = new CAccountInfo(); + } + + // + // Deconstructor ... + void ~XSCAccount() + { + } + + // + // START Provided Functions ... + // + + // + // User Account ... + long GetUserAccount() + { + return mAccountInfo.Login(); + } + + // + // Account Leverage ... + long GetLeverage() + { + return mAccountInfo.Leverage(); + } + + // + // Get Trade Expert State ... + bool CanExpertTrade() + { + return mAccountInfo.TradeExpert(); + } + + // + // User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ... + // -------------------------- + // ACCOUNT_TRADE_MODE_DEMO + // ACCOUNT_TRADE_MODE_CONTEST + // ACCOUNT_TRADE_MODE_REAL + ENUM_ACCOUNT_TRADE_MODE GetTradeMode() + { + return mAccountInfo.TradeMode(); + } + + // + // Get Account Balance ... + double GetBalance() + { + return mAccountInfo.Balance(); + } + + // + // Get the amount of give Credit ... + double GetCredit() + { + return mAccountInfo.Credit(); + } + + // + // Get the amount of current Profit on account ... + double GetProfit() + { + return mAccountInfo.Profit(); + } + + // + // Get the amount of current Equity on account ... + double GetEquity() + { + return mAccountInfo.Equity(); + } + + // + // Get the amount of reserved Margin ... + double GetMargin() + { + return mAccountInfo.Margin(); + } + + // + // Get the amount of free Margin ... + double GetFreeMargin() + { + return mAccountInfo.FreeMargin(); + } + + // + // Get the Level of Margin ... + double GetMarginLevel() + { + return mAccountInfo.MarginLevel(); + } + + // + // Get the Level Of Margin for a Deposit ... + double GetMarginCall() + { + return mAccountInfo.MarginCall(); + } + + // + // Get the Level of Margin for Stop out ... + double GetMarginStopOut() + { + return mAccountInfo.MarginStopOut(); + } + + // + // Get the Client Name ... + string GetName() + { + return mAccountInfo.Name(); + } + + // + // Get the Trade Server Name ... + string GetServerName() + { + return mAccountInfo.Server(); + } + + // + // Get deposit Currency Name ... + string GetCurrency() + { + return mAccountInfo.Currency(); + } + + // + // Get the Company Name that serves an Account ... + string GetCompany() + { + return mAccountInfo.Company(); + } + + // + // Calculate Profits for the current account based on passed parameters ... + double CalculateTradeProfit( + const string symbol, // trading symbol + ENUM_ORDER_TYPE type, // order type + double volume, // volume + double entry, // open price + double exit // close price + ) + { + // + double result = mAccountInfo.OrderProfitCheck( + symbol, + type, + volume, + entry, + exit); + + // + return result; + } + + // + // Calculate amount of margin which required for trade operation ... + double CalculateMarging( + const string symbol, // trading symbol + ENUM_ORDER_TYPE type, // order type + double volume, // volume + double entry // open price + ) + { + // + double result = mAccountInfo.MarginCheck( + symbol, + type, + volume, + entry); + + // + return result; + } + + // + // Calculate amount of free margin left after trade operation ... + double CalculateFreeMarging( + const string symbol, // trading symbol + ENUM_ORDER_TYPE type, // order type + double volume, // volume + double entry // open price + ) + { + // + double result = mAccountInfo.FreeMarginCheck( + symbol, + type, + volume, + entry); + + // + return result; + } + + // + // Calculate the Maximum possible volume of trade operation ... + double CalculateMaxVolume( + const string symbol, // trading symbol + ENUM_ORDER_TYPE type, // order type + double entry, // open price + double percent = 100 // percent of available margin + ) + { + // + double result = mAccountInfo.MaxLotCheck( + symbol, + type, + entry, + percent); + + // + return result; + } + + // + // Calculate Point Value for Given Symbol based on Account ... + double GetPointValue( + string symbol // trading symbol + ) + { + // + double result = 0; + + // + double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE); + double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE); + double point = SymbolInfoDouble(symbol, SYMBOL_POINT); + + // + double ticksPerPoint = tickSize / point; + + // + result = tickValue / ticksPerPoint; + + // + return result; + } + + // + // Calculate Risk Amount based on account Currency by Providing: + // Points and Volume ... + double CalculateRiskAmount( + string symbol, // trading symbol + double points, // amount of Risk Points + double volume // position Volume + ) + { + // + double result = 0; + + // + double pointValue = GetPointValue(symbol); + + // + result = pointValue * volume * points; + + // + return result; + } + + // + // Calculate Risk Points based on account Currency by Providing: + // Volume and Amount ... + double CalculateRiskPoints( + string symbol, // trading symbol + double volume, // position Volume + double amount // amount of Risk based on Account Currency + ) + { + // + double result = 0; + + // + double pointValue = GetPointValue(symbol); + + // + result = amount / (pointValue * volume); + + // + return result; + } + + // + // Calculate Volume based on account Currency by Providing: + // Amount and Risk Points ... + double CalculateVolume( + string symbol, // trading symbol + double amount, // amount of Risk based on Account Currency + double points // amount of Risk Points + ) + { + // + double result = 0; + + // + points = + points <= 0 + ? 10 + : points; + + // + double pointValue = GetPointValue(symbol); + + // + result = amount / (pointValue * points); + + // + return result; + } + + // + // END Provided Functions ... + // + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Account Info ... + CAccountInfo mAccountInfo; +}; + +// +// START Usefull Functions ... +// + +// +// END Usefull Functions ... +// diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.xalert.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.xalert.class.mq5 new file mode 100644 index 00000000..7f15e326 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.xalert.class.mq5 @@ -0,0 +1,1575 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCAlert +// Description: provides all Alerts 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 "../Classes/x-saherelm.base.class.mq5" + +// +// Class Definition ... + +class XSCAlert : public XSCBase +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor ... + XSCAlert( + string prefix = "X-Alert", // Alerts Prefixe + bool enableAlerts = true, // Enable Alerts + bool logAlerts = true, // Log Alerts + bool terminalAlerts = false, // Terminal Alerts + bool mailAlerts = false, // Mail Alerts + bool pushAlerts = false // Push Alerts + ) + { + // + mPrefix = prefix; + mLogAlerts = logAlerts; + mMailAlerts = mailAlerts; + mPushAlerts = pushAlerts; + mEnableAlerts = enableAlerts; + mTerminalAlerts = terminalAlerts; + + // + // Normalize Prefix if Not Provided ... + if (!IsValid(mPrefix)) + { + mPrefix = GetTag(); + } + } + + // + // Deconstructor ... + ~XSCAlert() {} + + // + // Override ... + string GetTag() override + { + return GetSpecificToken(this); + } + + // + // Properties Getter(s) / Setter(s) ... + + // + string GetPrefix() + { + return mPrefix; + } + + // + void SetPrefix(string value) + { + mPrefix = value; + } + + // + bool GetLogAlerts() + { + return mLogAlerts; + } + + // + void SetLogAlerts(bool value) + { + mLogAlerts = value; + } + + // + bool GetEnableAlerts() + { + return mEnableAlerts; + } + + // + void SetEnableAlerts(bool value) + { + mEnableAlerts = value; + } + + // + bool GetPushAlerts() + { + return mPushAlerts; + } + + // + void SetPushAlerts(bool value) + { + mPushAlerts = value; + } + + // + bool GetMailAlerts() + { + return mMailAlerts; + } + + // + void SetMailAlerts(bool value) + { + mMailAlerts = value; + } + + // + bool GetTerminalAlerts() + { + return mTerminalAlerts; + } + + // + void SetTerminalAlerts(bool value) + { + mTerminalAlerts = value; + } + + // + // Tools Funtions ... + + // + // Alerts ... + + // + // Logging an Alert ... + void LogAlert(string message) + { + // + // Validate Args ... + if (!CanLogAlert()) + { + return; + } + + // + Log(message); + } + + // + // Terminal Alert ... + void TerminalAlert(string message) + { + // + // Validate Args ... + if (!CanTerminalAlert()) + { + return; + } + + // + // Prepare Message ... + message = PrepareMessage(message); + + // Send Terminal Alert ... + Alert(message); + } + + // + // Mail Alert ... + void MailAlert(string message) + { + // + // Validate Args ... + if (!CanMailAlert()) + { + return; + } + + // + // Send Mail Alert ... + SendMail(GetPrefix(), message); + } + + // + // Send Push Notification ... + void PushAlert(string message) + { + // + // Validate Args ... + if (!CanPushAlert()) + { + return; + } + + // + // Prepare Message ... + message = PrepareMessage(message); + + // + // Send Push Notification Alert ... + SendNotification(message); + } + + // + // Send an Alert by Handling all Different Specified + // type's of Alert's if they are Enabled ... + void Alert(string message) + { + // + // Handle Log, if Enabled ... + LogAlert(message); + + // + // Handle Mail if Enabled ... + MailAlert(message); + + // + // Handle Push if Enabled ... + PushAlert(message); + + // + // Handle Terminal if Enabled ... + TerminalAlert(message); + } + + // + // Logs ... + + // + // Log a Message ... + void Log(string message) + { + // + if (!CanLog()) + { + return; + } + + // + Print(GetPrefix(), " > ", message); + } + void Log(string tag, string message) + { + // + if (!CanLog()) + { + return; + } + + // + Print(GetPrefix(), "_", tag, " > ", message); + } + void LogEmpty() + { + // + if (!CanLog()) + { + return; + } + + // + Print(" "); + } + + // + // Log Specific Array ... + template + void LogArray( + T &array[], // Array to Log + string label = NULL // Array Label + ) + { + // + if (!CanLog()) + { + return; + } + + // + Print(GetPrefix(), ">", (IsValid(label) ? label : "")); + ArrayPrint(array); + } + + // + // Error ... + + // + // Log an Error ... + void LogError( + int error = -1 // Specific Error, if it's equal to -1, use Last Error ... + ) + { + // + if (!CanLog()) + { + return; + } + + // + if (error <= -1) + { + error = GetLastError(); + } + + // + string errorMsg = GetErrorDescription(error); + + // + Log("Error: " + errorMsg); + } + + // + // Retrieve Specified Error Code Description ... + string GetErrorDescription(int err_code) + { + // + string result = ""; + + // + switch (err_code) + { + // + //--- Constant Description + + // + case ERR_SUCCESS: + result = "The operation completed successfully"; + break; + + // + case ERR_INTERNAL_ERROR: + result = "Unexpected internal error"; + break; + + // + case ERR_WRONG_INTERNAL_PARAMETER: + result = "Wrong parameter in the inner call of the client terminal function"; + break; + + // + case ERR_INVALID_PARAMETER: + result = "Wrong parameter when calling the system function"; + break; + + // + case ERR_NOT_ENOUGH_MEMORY: + result = "Not enough memory to perform the system function"; + break; + + // + case ERR_STRUCT_WITHOBJECTS_ORCLASS: + result = "The structure contains objects of strings and/or dynamic arrays and/or structure of such objects and/or classes"; + break; + + // + case ERR_INVALID_ARRAY: + result = "Array of a wrong type, wrong size, or a damaged object of a dynamic array"; + break; + + // + case ERR_ARRAY_RESIZE_ERROR: + result = "Not enough memory for the relocation of an array, or an attempt to change the size of a static array"; + break; + + // + case ERR_STRING_RESIZE_ERROR: + result = "Not enough memory for the relocation of string"; + break; + + // + case ERR_NOTINITIALIZED_STRING: + result = "Not initialized string"; + break; + + // + case ERR_INVALID_DATETIME: + result = "Invalid date and/or time"; + break; + + // + case ERR_ARRAY_BAD_SIZE: + result = "Requested array size exceeds 2 GB"; + break; + + // + case ERR_INVALID_POINTER: + result = "Wrong pointer"; + break; + + // + case ERR_INVALID_POINTER_TYPE: + result = "Wrong type of pointer"; + break; + + // + case ERR_FUNCTION_NOT_ALLOWED: + result = "System function is not allowed to call"; + break; + + // + //--- Charts + + // + case ERR_CHART_WRONG_ID: + result = "Wrong chart ID"; + break; + + // + case ERR_CHART_NO_REPLY: + result = "Chart does not respond"; + break; + + // + case ERR_CHART_NOT_FOUND: + result = "Chart not found"; + break; + + // + case ERR_CHART_NO_EXPERT: + result = "No Expert Advisor in the chart that could handle the event"; + break; + + // + case ERR_CHART_CANNOT_OPEN: + result = "Chart opening error"; + break; + + // + case ERR_CHART_CANNOT_CHANGE: + result = "Failed to change chart symbol and period"; + break; + + // + case ERR_CHART_CANNOT_CREATE_TIMER: + result = "Failed to create timer"; + break; + + // + case ERR_CHART_WRONG_PROPERTY: + result = "Wrong chart property ID"; + break; + + // + case ERR_CHART_SCREENSHOT_FAILED: + result = "Error creating screenshots"; + break; + + // + case ERR_CHART_NAVIGATE_FAILED: + result = "Error navigating through chart"; + break; + + // + case ERR_CHART_TEMPLATE_FAILED: + result = "Error applying template"; + break; + + // + case ERR_CHART_WINDOW_NOT_FOUND: + result = "Subwindow containing the indicator was not found"; + break; + + // + case ERR_CHART_INDICATOR_CANNOT_ADD: + result = "Error adding an indicator to chart"; + break; + + // + case ERR_CHART_INDICATOR_CANNOT_DEL: + result = "Error deleting an indicator from the chart"; + break; + + // + case ERR_CHART_INDICATOR_NOT_FOUND: + result = "Indicator not found on the specified chart"; + break; + + // + //--- Graphical Objects + case ERR_OBJECT_ERROR: + result = "Error working with a graphical object"; + break; + + // + case ERR_OBJECT_NOT_FOUND: + result = "Graphical object was not found"; + break; + + // + case ERR_OBJECT_WRONG_PROPERTY: + result = "Wrong ID of a graphical object property"; + break; + + // + case ERR_OBJECT_GETDATE_FAILED: + result = "Unable to get date corresponding to the value"; + break; + + // + case ERR_OBJECT_GETVALUE_FAILED: + result = "Unable to get value corresponding to the date"; + break; + + // + //--- MarketInfo + + // + case ERR_MARKET_UNKNOWN_SYMBOL: + result = "Unknown symbol"; + break; + + // + case ERR_MARKET_NOT_SELECTED: + result = "Symbol is not selected in MarketWatch"; + break; + + // + case ERR_MARKET_WRONG_PROPERTY: + result = "Wrong identifier of a symbol property"; + break; + + // + case ERR_MARKET_LASTTIME_UNKNOWN: + result = "Time of the last tick is not known (no ticks)"; + break; + + // + case ERR_MARKET_SELECT_ERROR: + result = "Error adding or deleting a symbol in MarketWatch"; + break; + + // + //--- History Access + + // + case ERR_HISTORY_NOT_FOUND: + result = "Requested history not found"; + break; + + // + case ERR_HISTORY_WRONG_PROPERTY: + result = "Wrong ID of the history property"; + break; + + // + //--- Global_Variables + + // + case ERR_GLOBALVARIABLE_NOT_FOUND: + result = "Global variable of the client terminal is not found"; + break; + + // + case ERR_GLOBALVARIABLE_EXISTS: + result = "Global variable of the client terminal with the same name already exists"; + break; + + // + case ERR_MAIL_SEND_FAILED: + result = "Email sending failed"; + break; + + // + case ERR_PLAY_SOUND_FAILED: + result = "Sound playing failed"; + break; + + // + case ERR_MQL5_WRONG_PROPERTY: + result = "Wrong identifier of the program property"; + break; + + // + case ERR_TERMINAL_WRONG_PROPERTY: + result = "Wrong identifier of the terminal property"; + break; + + // + case ERR_FTP_SEND_FAILED: + result = "File sending via ftp failed"; + break; + + // + case ERR_NOTIFICATION_SEND_FAILED: + result = "Error in sending notification"; + break; + + // + //--- Custom Indicator Buffers + + // + case ERR_BUFFERS_NO_MEMORY: + result = "Not enough memory for the distribution of indicator buffers"; + break; + + // + case ERR_BUFFERS_WRONG_INDEX: + result = "Wrong indicator buffer index"; + break; + + // + //--- Custom Indicator Properties + + // + case ERR_CUSTOM_WRONG_PROPERTY: + result = "Wrong ID of the custom indicator property"; + break; + + // + //--- Account + + // + case ERR_ACCOUNT_WRONG_PROPERTY: + result = "Wrong account property ID"; + break; + + // + case ERR_TRADE_WRONG_PROPERTY: + result = "Wrong trade property ID"; + break; + + // + case ERR_TRADE_DISABLED: + result = "Trading by Expert Advisors prohibited"; + break; + + // + case ERR_TRADE_POSITION_NOT_FOUND: + result = "Position not found"; + break; + + // + case ERR_TRADE_ORDER_NOT_FOUND: + result = "Order not found"; + break; + + // + case ERR_TRADE_DEAL_NOT_FOUND: + result = "Deal not found"; + break; + + // + case ERR_TRADE_SEND_FAILED: + result = "Trade request sending failed"; + break; + + // + //--- Indicators + + // + case ERR_INDICATOR_UNKNOWN_SYMBOL: + result = "Unknown symbol"; + break; + + // + case ERR_INDICATOR_CANNOT_CREATE: + result = "Indicator cannot be created"; + break; + + // + case ERR_INDICATOR_NO_MEMORY: + result = "Not enough memory to add the indicator"; + break; + + // + case ERR_INDICATOR_CANNOT_APPLY: + result = "The indicator cannot be applied to another indicator"; + break; + + // + case ERR_INDICATOR_CANNOT_ADD: + result = "Error applying an indicator to chart"; + break; + + // + case ERR_INDICATOR_DATA_NOT_FOUND: + result = "Requested data not found"; + break; + + // + case ERR_INDICATOR_WRONG_HANDLE: + result = "Wrong indicator handle"; + break; + + // + case ERR_INDICATOR_WRONG_PARAMETERS: + result = "Wrong number of parameters when creating an indicator"; + break; + + // + case ERR_INDICATOR_PARAMETERS_MISSING: + result = "No parameters when creating an indicator"; + break; + + // + case ERR_INDICATOR_CUSTOM_NAME: + result = "The first parameter in the array must be the name of the custom indicator"; + break; + + // + case ERR_INDICATOR_PARAMETER_TYPE: + result = "Invalid parameter type in the array when creating an indicator"; + break; + + // + case ERR_INDICATOR_WRONG_INDEX: + result = "Wrong index of the requested indicator buffer"; + break; + + // + //--- Depth of Market + + // + case ERR_BOOKS_CANNOT_ADD: + result = "Depth Of Market can not be added"; + break; + + // + case ERR_BOOKS_CANNOT_DELETE: + result = "Depth Of Market can not be removed"; + break; + + // + case ERR_BOOKS_CANNOT_GET: + result = "The data from Depth Of Market can not be obtained"; + break; + + // + case ERR_BOOKS_CANNOT_SUBSCRIBE: + result = "Error in subscribing to receive new data from Depth Of Market"; + break; + + // + //--- File Operations + + // + case ERR_TOO_MANY_FILES: + result = "More than 64 files cannot be opened at the same time"; + break; + + // + case ERR_WRONG_FILENAME: + result = "Invalid file name"; + break; + + // + case ERR_TOO_LONG_FILENAME: + result = "Too long file name"; + break; + + // + case ERR_CANNOT_OPEN_FILE: + result = "File opening error"; + break; + + // + case ERR_FILE_CACHEBUFFER_ERROR: + result = "Not enough memory for cache to read"; + break; + + // + case ERR_CANNOT_DELETE_FILE: + result = "File deleting error"; + break; + + // + case ERR_INVALID_FILEHANDLE: + result = "A file with this handle was closed, or was not opening at all"; + break; + + // + case ERR_WRONG_FILEHANDLE: + result = "Wrong file handle"; + break; + + // + case ERR_FILE_NOTTOWRITE: + result = "The file must be opened for writing"; + break; + + // + case ERR_FILE_NOTTOREAD: + result = "The file must be opened for reading"; + break; + + // + case ERR_FILE_NOTBIN: + result = "The file must be opened as a binary one"; + break; + + // + case ERR_FILE_NOTTXT: + result = "The file must be opened as a text"; + break; + + // + case ERR_FILE_NOTTXTORCSV: + result = "The file must be opened as a text or CSV"; + break; + + // + case ERR_FILE_NOTCSV: + result = "The file must be opened as CSV"; + break; + + // + case ERR_FILE_READERROR: + result = "File reading error"; + break; + + // + case ERR_FILE_BINSTRINGSIZE: + result = "String size must be specified, because the file is opened as binary"; + break; + + // + case ERR_INCOMPATIBLE_FILE: + result = "A text file must be for string arrays, for other arrays - binary"; + break; + + // + case ERR_FILE_IS_DIRECTORY: + result = "This is not a file, this is a directory"; + break; + + // + case ERR_FILE_NOT_EXIST: + result = "File does not exist"; + break; + + // + case ERR_FILE_CANNOT_REWRITE: + result = "File can not be rewritten"; + break; + + // + case ERR_WRONG_DIRECTORYNAME: + result = "Wrong directory name"; + break; + + // + case ERR_DIRECTORY_NOT_EXIST: + result = "Directory does not exist"; + break; + + // + case ERR_FILE_ISNOT_DIRECTORY: + result = "This is a file, not a directory"; + break; + + // + case ERR_CANNOT_DELETE_DIRECTORY: + result = "The directory cannot be removed"; + break; + + // + case ERR_CANNOT_CLEAN_DIRECTORY: + result = "Failed to clear the directory (probably one or more files are blocked and removal operation failed)"; + break; + + // + case ERR_FILE_WRITEERROR: + result = "Failed to write a resource to a file"; + break; + + // + //--- String Casting + + // + case ERR_NO_STRING_DATE: + result = "No date in the string"; + break; + + // + case ERR_WRONG_STRING_DATE: + result = "Wrong date in the string"; + break; + + // + case ERR_WRONG_STRING_TIME: + result = "Wrong time in the string"; + break; + + // + case ERR_STRING_TIME_ERROR: + result = "Error converting string to date"; + break; + + // + case ERR_STRING_OUT_OF_MEMORY: + result = "Not enough memory for the string"; + break; + + // + case ERR_STRING_SMALL_LEN: + result = "The string length is less than expected"; + break; + + // + case ERR_STRING_TOO_BIGNUMBER: + result = "Too large number, more than ULONG_MAX"; + break; + + // + case ERR_WRONG_FORMATSTRING: + result = "Invalid format string"; + break; + + // + case ERR_TOO_MANY_FORMATTERS: + result = "Amount of format specifiers more than the parameters"; + break; + + // + case ERR_TOO_MANY_PARAMETERS: + result = "Amount of parameters more than the format specifiers"; + break; + + // + case ERR_WRONG_STRING_PARAMETER: + result = "Damaged parameter of string type"; + break; + + // + case ERR_STRINGPOS_OUTOFRANGE: + result = "Position outside the string"; + break; + + // + case ERR_STRING_ZEROADDED: + result = "0 added to the string end, a useless operation"; + break; + + // + case ERR_STRING_UNKNOWNTYPE: + result = "Unknown data type when converting to a string"; + break; + + // + case ERR_WRONG_STRING_OBJECT: + result = "Damaged string object"; + break; + + // + //--- Operations with Arrays + + // + case ERR_INCOMPATIBLE_ARRAYS: + result = "Copying incompatible arrays. String array can be copied only to a string array, and a numeric array - in numeric array only"; + break; + + // + case ERR_SMALL_ASSERIES_ARRAY: + result = "The receiving array is declared as AS_SERIES, and it is of insufficient size"; + break; + + // + case ERR_SMALL_ARRAY: + result = "Too small array, the starting position is outside the array"; + break; + + // + case ERR_ZEROSIZE_ARRAY: + result = "An array of zero length"; + break; + + // + case ERR_NUMBER_ARRAYS_ONLY: + result = "Must be a numeric array"; + break; + + // + case ERR_ONEDIM_ARRAYS_ONLY: + result = "Must be a one-dimensional array"; + break; + + // + case ERR_SERIES_ARRAY: + result = "Timeseries cannot be used"; + break; + + // + case ERR_DOUBLE_ARRAY_ONLY: + result = "Must be an array of type double"; + break; + + // + case ERR_FLOAT_ARRAY_ONLY: + result = "Must be an array of type float"; + break; + + // + case ERR_LONG_ARRAY_ONLY: + result = "Must be an array of type long"; + break; + + // + case ERR_INT_ARRAY_ONLY: + result = "Must be an array of type int"; + break; + + // + case ERR_SHORT_ARRAY_ONLY: + result = "Must be an array of type short"; + break; + + // + case ERR_CHAR_ARRAY_ONLY: + result = "Must be an array of type char"; + break; + + // + //--- Operations with OpenCL + + // + case ERR_OPENCL_NOT_SUPPORTED: + result = "OpenCL functions are not supported on this computer"; + break; + + // + case ERR_OPENCL_INTERNAL: + result = "Internal error occurred when running OpenCL"; + break; + + // + case ERR_OPENCL_INVALID_HANDLE: + result = "Invalid OpenCL handle"; + break; + + // + case ERR_OPENCL_CONTEXT_CREATE: + result = "Error creating the OpenCL context"; + break; + + // + case ERR_OPENCL_QUEUE_CREATE: + result = "Failed to create a run queue in OpenCL"; + break; + + // + case ERR_OPENCL_PROGRAM_CREATE: + result = "Error occurred when compiling an OpenCL program"; + break; + + // + case ERR_OPENCL_TOO_LONG_KERNEL_NAME: + result = "Too long kernel name (OpenCL kernel)"; + break; + + // + case ERR_OPENCL_KERNEL_CREATE: + result = "Error creating an OpenCL kernel"; + break; + + // + case ERR_OPENCL_SET_KERNEL_PARAMETER: + result = "Error occurred when setting parameters for the OpenCL kernel"; + break; + + // + case ERR_OPENCL_EXECUTE: + result = "OpenCL program runtime error"; + break; + + // + case ERR_OPENCL_WRONG_BUFFER_SIZE: + result = "Invalid size of the OpenCL buffer"; + break; + + // + case ERR_OPENCL_WRONG_BUFFER_OFFSET: + result = "Invalid offset in the OpenCL buffer"; + break; + + // + case ERR_OPENCL_BUFFER_CREATE: + result = "Failed to create and OpenCL buffer"; + break; + + // + //--- User-Defined Errors + default: + result = "UNKNOWN Erro ..."; + break; + } + + // + return result; + } + + // + // Retrieve Specified Error Code Description ... + string GetTradeServerReturnCodeDescription(int return_code) + { + // + string result = ""; + + // + switch (return_code) + { + // + case TRADE_RETCODE_REQUOTE: + result = "Requote"; + break; + + // + case TRADE_RETCODE_REJECT: + result = "Request rejected"; + break; + + // + case TRADE_RETCODE_CANCEL: + result = "Request canceled by trader"; + break; + + // + case TRADE_RETCODE_PLACED: + result = "Order placed"; + break; + + // + case TRADE_RETCODE_DONE: + result = "Request completed"; + break; + + // + case TRADE_RETCODE_DONE_PARTIAL: + result = "Only part of the request was completed"; + break; + + // + case TRADE_RETCODE_ERROR: + result = "Request processing error"; + break; + + // + case TRADE_RETCODE_TIMEOUT: + result = "Request canceled by timeout"; + break; + + // + case TRADE_RETCODE_INVALID: + result = "Invalid request"; + break; + + // + case TRADE_RETCODE_INVALID_VOLUME: + result = "Invalid volume in the request"; + break; + + // + case TRADE_RETCODE_INVALID_PRICE: + result = "Invalid price in the request"; + break; + + // + case TRADE_RETCODE_INVALID_STOPS: + result = "Invalid stops in the request"; + break; + + // + case TRADE_RETCODE_TRADE_DISABLED: + result = "Trade is disabled"; + break; + + // + case TRADE_RETCODE_MARKET_CLOSED: + result = "Market is closed"; + break; + + // + case TRADE_RETCODE_NO_MONEY: + result = "There is not enough money to complete the request"; + break; + + // + case TRADE_RETCODE_PRICE_CHANGED: + result = "Prices changed"; + break; + + // + case TRADE_RETCODE_PRICE_OFF: + result = "There are no quotes to process the request"; + break; + + // + case TRADE_RETCODE_INVALID_EXPIRATION: + result = "Invalid order expiration date in the request"; + break; + + // + case TRADE_RETCODE_ORDER_CHANGED: + result = "Order state changed"; + break; + + // + case TRADE_RETCODE_TOO_MANY_REQUESTS: + result = "Too frequent requests"; + break; + + // + case TRADE_RETCODE_NO_CHANGES: + result = "No changes in request"; + break; + + // + case TRADE_RETCODE_SERVER_DISABLES_AT: + result = "Autotrading disabled by server"; + break; + + // + case TRADE_RETCODE_CLIENT_DISABLES_AT: + result = "Autotrading disabled by client terminal"; + break; + + // + case TRADE_RETCODE_LOCKED: + result = "Request locked for processing"; + break; + + // + case TRADE_RETCODE_FROZEN: + result = "Order or position frozen"; + break; + + // + case TRADE_RETCODE_INVALID_FILL: + result = "Invalid order filling type"; + break; + + // + case TRADE_RETCODE_CONNECTION: + result = "No connection with the trade server"; + break; + + // + case TRADE_RETCODE_ONLY_REAL: + result = "Operation is allowed only for live accounts"; + break; + + // + case TRADE_RETCODE_LIMIT_ORDERS: + result = "The number of pending orders has reached the limit"; + break; + + // + case TRADE_RETCODE_LIMIT_VOLUME: + result = "The volume of orders and positions for the symbol has reached the limit"; + break; + + // + default: + result = "Invalid return code of the trade server"; + break; + } + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... + + // + bool CanLog() + { + return mLogAlerts; + } + + // + bool CanLogAlert() + { + // + bool result = GetEnableAlerts() && GetLogAlerts(); + + // + return result; + } + + // + bool CanTerminalAlert() + { + // + bool result = GetEnableAlerts() && GetTerminalAlerts(); + + // + return result; + } + + // + bool CanMailAlert() + { + // + bool result = GetEnableAlerts() && GetMailAlerts(); + + // + return result; + } + + // + bool CanPushAlert() + { + // + bool result = GetEnableAlerts() && GetPushAlerts(); + + // + return result; + } + +private: + // + // Props ... + string mPrefix; // Alerts Prefixe + bool mEnableAlerts; // Enable Alerts + bool mLogAlerts; // Log Alerts + bool mTerminalAlerts; // Terminal Alerts + bool mMailAlerts; // Mail Alerts + bool mPushAlerts; // Push Alerts + + // + // Tools ... + + // + // Clear Escape String and + // Attach Alert Prefix to Message ... + string PrepareMessage(string message) + { + // + StringReplace(message, "\n", " | "); + + // + StringConcatenate(message, GetPrefix(), " > ", message); + + // + return message; + } +}; + +// +// a Base Class by Support Alert ... +class XSCBaseAlert : public XSCBase +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor(s) ... + void XSCBaseAlert() + { + // + // Instance Alert ... + mAlert = new XSCAlert(); + } + + // + // Deconstructors ... + void ~XSCBaseAlert() + { + // + delete mAlert; + } + + // + // Alert Handler Functions ... + + // + // Alert Functions Getter(s) / Setters(s) ... + + // + string GetAlertPrefix() + { + return mAlert.GetPrefix(); + } + + // + void SetAlertPrefix(string value) + { + mAlert.SetPrefix(value); + } + + // + bool GetAlertLogAlerts() + { + return mAlert.GetLogAlerts(); + } + + // + void SetAlertLogAlerts(bool value) + { + mAlert.SetLogAlerts(value); + } + + // + bool GetAlertEnableAlerts() + { + return mAlert.GetEnableAlerts(); + } + + // + void SetAlertEnableAlerts(bool value) + { + mAlert.SetEnableAlerts(value); + } + + // + bool GetAlertPushAlerts() + { + return mAlert.GetPushAlerts(); + } + + // + void SetAlertPushAlerts(bool value) + { + mAlert.SetPushAlerts(value); + } + + // + bool GetAlertMailAlerts() + { + return mAlert.GetMailAlerts(); + } + + // + void SetAlertMailAlerts(bool value) + { + mAlert.SetMailAlerts(value); + } + + // + bool GetAlertTerminalAlerts() + { + return mAlert.GetTerminalAlerts(); + } + + // + void SetAlertTerminalAlerts(bool value) + { + mAlert.SetTerminalAlerts(value); + } + + // + // Alert Actions ... + + // + // Logging an Alert ... + void LogAlert(string message) + { + mAlert.LogAlert(message); + } + + // + // Terminal Alert ... + void TerminalAlert(string message) + { + mAlert.TerminalAlert(message); + } + + // + // Mail Alert ... + void MailAlert(string message) + { + mAlert.MailAlert(message); + } + + // + // Send Push Notification ... + void PushAlert(string message) + { + mAlert.PushAlert(message); + } + + // + // Send an Alert by Handling all Different Specified + // type's of Alert's if they are Enabled ... + void Alert(string message) + { + mAlert.Alert(message); + } + + // + // Logs ... + + // + // Log a Message ... + void Log(string message) + { + mAlert.Log(message); + } + void Log(string tag, string message) + { + mAlert.Log(tag, message); + } + void LogEmpty() + { + mAlert.LogEmpty(); + } + + // + // Log Specific Array ... + template + void LogArray( + T &array[], // Array to Log + string label = NULL // Array Label + ) + { + mAlert.LogArray(array, label); + } + + // + // Error ... + + // + // Log an Error ... + void LogError( + int error = -1 // Specific Error, if it's equal to -1, use Last Error ... + ) + { + mAlert.LogError(error); + } + + // + // Retrieve Specified Error Code Description ... + string GetErrorDescription(int err_code) + { + return mAlert.GetErrorDescription(err_code); + } + + // + // Retrieve Specified Error Code Description ... + string GetTradeServerReturnCodeDescription(int return_code) + { + return mAlert.GetTradeServerReturnCodeDescription(return_code); + } + + // + // Protected ... +protected: + // + // Alert ... + XSCAlert *mAlert; + + // + // Private ... +private: +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.xhelper.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.xhelper.class.mq5 new file mode 100644 index 00000000..966eb8d9 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.xhelper.class.mq5 @@ -0,0 +1,148 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCBaseHelper +// Description: provides all Base Indicator +// Helper 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 + +// +// Includes ... +#include "../Classes/x-saherelm.base.class.mq5" + +// +// Definitions ... + +// +// a Class for Handle base requirements ... +// for indicators ... +class XSCBaseHelper : public XSCBase +{ + // + // Public ... +public: + // + // Constructor ... + void XSCBaseHelper( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period // Trading Time Frame + ) + { + // + mSymbol = symbol; + mPeriod = period; + } + + // + // Deconstructor ... + void ~XSCBaseHelper() + { + // + IndicatorRelease(mHandler); + } + + // + // Setter(s) / Getter(s) ... + + // + // Symbol ... + string GetSymbol() + { + return mSymbol; + } + + // + // Period ... + ENUM_TIMEFRAMES GetPeriod() + { + return mPeriod; + } + + // + // Retrieve Bars ... + int CountBars() + { + // + int result = + Bars( + mSymbol, + mPeriod + // + ); + + // + return result; + } + + // + // Retrieve Indicator Calculated Bars ... + int CountCalculatedBars() + { + return BarsCalculated(mHandler); + } + + // + // Generate Tag ... + virtual string GetTag() + { + // + string result = NULL; + + // + result = + // + GetToken() + + "[" + + GetSymbol() + "|" + + ToString(GetPeriod()) + + "]" + // + ; + + // + return result; + } + + // + // Functions ... + + // + // Protected ... +protected: + // + // Props ... + + // + // Symbol ... + string mSymbol; + + // + // Period ... + ENUM_TIMEFRAMES mPeriod; + + // + // Indicator Handler ... + int mHandler; + + // + // Private ... +private: + // +}; + +// +// Tools .... \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.xhttp.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.xhttp.class.mq5 new file mode 100644 index 00000000..82adadb6 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.xhttp.class.mq5 @@ -0,0 +1,373 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCHttp +// Description: provides all HTTP 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 + +// +// Definitions ... + +// +enum X_HTTP_METHOD +{ + X_HTTP_GET, + X_HTTP_POST +}; + +// +// Imports ... + +// +// Includes ... +#include "../Classes/x-saherelm.base.class.mq5" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// a Class for Manage Account ... +class XSCHttp : public XSCBase +{ + // + // Public ... +public: + // + // Constructor ... + void XSCHttp() + { + XSCHttp("", 10000); + } + void XSCHttp( + string path, // Base Folder to Store Data + int timeout // base timeout for Requests + ) + { + // + Path(path); + Timeout(timeout); + } + + // + // Deconstructor ... + void ~XSCHttp() + { + } + + // + // Properties Getter(s) / Setter(s) ... + + // + // Path ... + void Path(string value) + { + // + mPath = value; + + // + if (!IsValid(mPath)) + { + mPath = GetTag(); + } + } + + string Path() + { + return mPath; + } + + // + // Timeout ... + void Timeout(int value) + { + mTimeout = value; + } + + // + int Timeout() + { + return mTimeout; + } + + // + // Error ... + int Error() + { + return mError; + } + + // + // Response ... + string Response() + { + return mResponse; + } + + // + // Overrides ... + string GetTag() override + { + return GetSpecificToken(this); + } + + // + // Tools ... + + // + // Send Global Request ... + int SendRequest( + X_HTTP_METHOD method, // Httm Request Method + const string url, // Server Address + const string headers, // Headers providing + const char &payload[], // the Data which needs to Send + char &response[], // Response of request + string responseHeaders, // Response Headers + int timeout = 500 // Timeout for response default is 500 + ) + { + // + int result = -1; + + // + string strMethod = ToString(method); + if (StringLen(strMethod) == 0) + { + return result; + } + + // + // Reset State ... + ResetState(); + + // + result = WebRequest( + strMethod, + url, + headers, + timeout, + payload, + response, + responseHeaders); + + // + if (result < 0) + { + mError = GetLastError(); + } + else + { + mResponse = CharArrayToString(response); + } + + // + return result; + } + + // + // Get Request ... + int GetRequest( + const string url, // Server Address + const string headers, // Headers providing + const char &payload[], // the Data which needs to Send + char &response[], // Response of request + string responseHeaders, // Response Headers + int timeout = 500 // Timeout for response default is 500 + ) + { + // + int result = SendRequest( + X_HTTP_GET, + url, + headers, + payload, + response, + responseHeaders, + timeout); + + // + return result; + } + + // + // Post Request ... + int PostRequest( + const string url, // Server Address + const string headers, // Headers providing + const char &payload[], // the Data which needs to Send + char &response[], // Response of request + string responseHeaders, // Response Headers + int timeout = 500 // Timeout for response default is 500 + ) + { + // + int result = SendRequest( + X_HTTP_POST, + url, + headers, + payload, + response, + responseHeaders, + timeout); + + // + return result; + } + + // + // Handle Download Specific URL Content to Specific Path and File Name ... + bool Download( + string url, // the URL address which going to download + string fileName // Specify Destination file name to Store Response + ) + { + // + bool result = false; + + // + string filePath = GetFilePath(fileName); + string cookie = NULL; + string referer = NULL; + int timeout = Timeout(); + + // + char payload[]; + string headers; + char response[]; + string responseHeaders; + + // + // Send Request ... + int requestResult = GetRequest( + url, + headers, + payload, + response, + responseHeaders, + timeout); + + // + // Define File Handler ... + int mFileHandler = FileOpen( + filePath, + FILE_WRITE | FILE_BIN); + if (mFileHandler == INVALID_HANDLE) + { + // + mError = GetLastError(); + return result; + } + + // + // Write Response to File ... + uint writed = FileWriteArray( + mFileHandler, + response, + 0, + ArraySize(response)); + FileFlush(mFileHandler); + FileClose(mFileHandler); + + // + result = writed > 0; + + // + return result; + } + + // + // END Provided Functions ... + // + + // + // Protected ... +protected: + // + // Destintion Folder Path ... + string mPath; + + // + // WEB Request Timeout Value ... + int mTimeout; + + // + // WEB Request's Response ... + string mResponse; + + // + // Error Value ... + int mError; + + // + // Private ... +private: + // + // Reset Errors State ... + void ResetState() + { + // + // Reset Errors ... + mError = -1; + mResponse = ""; + ResetLastError(); + } + + // + // Generate Full File Path ... + string GetFilePath(string fileName) + { + // + string result = ""; + + // + result = + // + Path() + "\\" + fileName + // + ; + + // + return result; + } +}; + +// +// Tools ... + +// +// Convert enum to String ... +string ToString(X_HTTP_METHOD method) +{ + // + string result = ""; + + // + switch (method) + { + // + case X_HTTP_GET: + result = "GET"; + break; + + // + case X_HTTP_POST: + result = "POST"; + break; + } + + // + return result; +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.xmd5.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.xmd5.class.mq5 new file mode 100644 index 00000000..3311aa5a --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.xmd5.class.mq5 @@ -0,0 +1,441 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCMD5 +// Description: Provides MD5 Hashing 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 + +// +// START Definitions ... +// + +// +static uchar _md5_PADDING[64] = + { + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +// +#define _md5_F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define _md5_G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define _md5_H(x, y, z) ((x) ^ (y) ^ (z)) +#define _md5_I(x, y, z) ((y) ^ ((x) | (~z))) +#define _md5_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + +// +#define _md5_FF(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_F((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_GG(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_G((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_HH(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_H((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_II(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_I((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_INIT_STATE_0 0x67452301 +#define _md5_INIT_STATE_1 0xefcdab89 +#define _md5_INIT_STATE_2 0x98badcfe +#define _md5_INIT_STATE_3 0x10325476 + +// +#define _md5_S11 7 +#define _md5_S12 12 +#define _md5_S13 17 +#define _md5_S14 22 + +// +#define _md5_S21 5 +#define _md5_S22 9 +#define _md5_S23 14 +#define _md5_S24 20 + +// +#define _md5_S31 4 +#define _md5_S32 11 +#define _md5_S33 16 +#define _md5_S34 23 + +// +#define _md5_S41 6 +#define _md5_S42 10 +#define _md5_S43 15 +#define _md5_S44 21 + +// +// END Definitions ... +// + +// +// XCMD5 a library for Hashing ... +class XSCMD5 +{ + // + // Public Provides ... +public: + // + // Protected Provides ... + + // + // Constructor ... + XSCMD5(void) {} + + // + // Deconstructor ... + ~XSCMD5(void) {} + + // + // Hash Specified Char Array ... + string Hash( + uchar &mSource[], // Specify Char Array to Hash + int mLength = 0 // Specify Length of Char Array which required to hash + ) + { + // + string result = ""; + + // + int sourceCount = ArraySize(mSource); + + // + // Validate Args ... + if ( + sourceCount <= 0 || + (sourceCount > 0 && mLength > sourceCount)) + { + return result; + } + + // + // Normalize Args ... + if (mLength == 0) + { + mLength = sourceCount; + } + + // + // Init MD5 ... + MD5Init(); + + // + // Update Buffer ... + MD5Update(mSource, mLength); + + // + // Calculate Result ... + result = MD5Final(); + + // + return result; + } + + // + // Hash Specified String ... + string Hash( + string mSource // Specified String + ) + { + // + string result = ""; + + // + // Converts String to Char Array ... + uchar bytes[]; + StringToCharArray( + mSource, + bytes, + 0, + StringLen(mSource)); + + // + result = Hash( + bytes, + ArraySize(bytes)); + + // + return result; + } + +protected: + // + // Private Provides ... +private: + // + uint m_lMD5[4]; + uint m_nCount[2]; + uchar m_lpszBuffer[64]; + + // + // Convert Byte to DWord ... + void ByteToDWord(int &out[], uint &in[], uint len) + { + // + uint i = 0; + uint j = 0; + + // + for (; j < len; i++, j += 4) + { + out[i] = (int)in[j] | (int)in[j + 1] << 8 | (int)in[j + 2] << 16 | (int)in[j + 3] << 24; + } + } + + // + // Convert DWord to Byte ... + void DWordToByte(uchar &out[], int &in[], uint len) + { + // + uint i = 0; + uint j = 0; + + // + for (; j < len; i++, j += 4) + { + // + out[j] = (uchar)(in[i] & 0xff); + out[j + 1] = (uchar)((in[i] >> 8) & 0xff); + out[j + 2] = (uchar)((in[i] >> 16) & 0xff); + out[j + 3] = (uchar)((in[i] >> 24) & 0xff); + } + } + + // + // Init MD5 Array ... + void MD5Init() + { + // + ArrayInitialize(m_lpszBuffer, 64); + + // + m_nCount[0] = m_nCount[1] = 0; + m_lMD5[0] = _md5_INIT_STATE_0; + m_lMD5[1] = _md5_INIT_STATE_1; + m_lMD5[2] = _md5_INIT_STATE_2; + m_lMD5[3] = _md5_INIT_STATE_3; + } + + // + // Update MD5 ... + void MD5Update(uchar &inBuf[], uint inLen) + { + // + int i, ii; + int mdi; + + // + uint in[16]; + int i0 = 0; + + // + mdi = (int)((m_nCount[0] >> 3) & 0x3F); + + // + if ((m_nCount[0] + ((uint)inLen << 3)) < m_nCount[0]) + { + m_nCount[1]++; + } + + // + m_nCount[0] += ((uint)inLen << 3); + m_nCount[1] += ((uint)inLen >> 29); + + // + while ((inLen--) > 0) + { + // + m_lpszBuffer[mdi++] = inBuf[i0++]; + if (mdi == 0x40) + { + // + for (i = 0, ii = 0; i < 16; i++, ii += 4) + { + in[i] = (((uint)m_lpszBuffer[ii + 3]) << 24) | (((uint)m_lpszBuffer[ii + 2]) << 16) | (((uint)m_lpszBuffer[ii + 1]) << 8) | ((uint)m_lpszBuffer[ii]); + } + + // + Transform(m_lMD5, in); + + // + mdi = 0; + } + } + } + + // + // Finalize an MD5 Expression ... + string MD5Final() + { + // + uchar bits[8]; + int nIndex; + uint nPadLen; + const int nMD5Size = 16; + uchar lpszMD5[16]; + string temp; + string out = ""; + int i; + + // + DWordToByte(bits, m_nCount, 8); + nIndex = (int)((m_nCount[0] >> 3) & 0x3f); + nPadLen = (nIndex < 56) ? (56 - nIndex) : (120 - nIndex); + MD5Update(_md5_PADDING, nPadLen); + MD5Update(bits, 8); + DWordToByte(lpszMD5, m_lMD5, nMD5Size); + + // + for (i = 0; i < nMD5Size; i++) + { + // + if (lpszMD5[i] == 0) + { + temp = "00"; + } + else if (lpszMD5[i] <= 15) + { + temp = StringFormat("0%x", lpszMD5[i]); + } + else + { + temp = StringFormat("%x", lpszMD5[i]); + } + + // + out += temp; + } + + // + lpszMD5[0] = '\0'; + + // + return (out); + } + + // + // Transform Buffers ... + void Transform(uint &buf[], uint &in[]) + { + // + uint a = buf[0], b = buf[1], c = buf[2], d = buf[3]; + + // + _md5_FF(a, b, c, d, in[0], _md5_S11, 0xD76AA478); + _md5_FF(d, a, b, c, in[1], _md5_S12, 0xE8C7B756); + _md5_FF(c, d, a, b, in[2], _md5_S13, 0x242070DB); + _md5_FF(b, c, d, a, in[3], _md5_S14, 0xC1BDCEEE); + _md5_FF(a, b, c, d, in[4], _md5_S11, 0xF57C0FAF); + _md5_FF(d, a, b, c, in[5], _md5_S12, 0x4787C62A); + _md5_FF(c, d, a, b, in[6], _md5_S13, 0xA8304613); + _md5_FF(b, c, d, a, in[7], _md5_S14, 0xFD469501); + _md5_FF(a, b, c, d, in[8], _md5_S11, 0x698098D8); + _md5_FF(d, a, b, c, in[9], _md5_S12, 0x8B44F7AF); + _md5_FF(c, d, a, b, in[10], _md5_S13, 0xFFFF5BB1); + _md5_FF(b, c, d, a, in[11], _md5_S14, 0x895CD7BE); + _md5_FF(a, b, c, d, in[12], _md5_S11, 0x6B901122); + _md5_FF(d, a, b, c, in[13], _md5_S12, 0xFD987193); + _md5_FF(c, d, a, b, in[14], _md5_S13, 0xA679438E); + _md5_FF(b, c, d, a, in[15], _md5_S14, 0x49B40821); + + // + _md5_GG(a, b, c, d, in[1], _md5_S21, 0xF61E2562); + _md5_GG(d, a, b, c, in[6], _md5_S22, 0xC040B340); + _md5_GG(c, d, a, b, in[11], _md5_S23, 0x265E5A51); + _md5_GG(b, c, d, a, in[0], _md5_S24, 0xE9B6C7AA); + _md5_GG(a, b, c, d, in[5], _md5_S21, 0xD62F105D); + _md5_GG(d, a, b, c, in[10], _md5_S22, 0x02441453); + _md5_GG(c, d, a, b, in[15], _md5_S23, 0xD8A1E681); + _md5_GG(b, c, d, a, in[4], _md5_S24, 0xE7D3FBC8); + _md5_GG(a, b, c, d, in[9], _md5_S21, 0x21E1CDE6); + _md5_GG(d, a, b, c, in[14], _md5_S22, 0xC33707D6); + _md5_GG(c, d, a, b, in[3], _md5_S23, 0xF4D50D87); + _md5_GG(b, c, d, a, in[8], _md5_S24, 0x455A14ED); + _md5_GG(a, b, c, d, in[13], _md5_S21, 0xA9E3E905); + _md5_GG(d, a, b, c, in[2], _md5_S22, 0xFCEFA3F8); + _md5_GG(c, d, a, b, in[7], _md5_S23, 0x676F02D9); + _md5_GG(b, c, d, a, in[12], _md5_S24, 0x8D2A4C8A); + + // + _md5_HH(a, b, c, d, in[5], _md5_S31, 0xFFFA3942); + _md5_HH(d, a, b, c, in[8], _md5_S32, 0x8771F681); + _md5_HH(c, d, a, b, in[11], _md5_S33, 0x6D9D6122); + _md5_HH(b, c, d, a, in[14], _md5_S34, 0xFDE5380C); + _md5_HH(a, b, c, d, in[1], _md5_S31, 0xA4BEEA44); + _md5_HH(d, a, b, c, in[4], _md5_S32, 0x4BDECFA9); + _md5_HH(c, d, a, b, in[7], _md5_S33, 0xF6BB4B60); + _md5_HH(b, c, d, a, in[10], _md5_S34, 0xBEBFBC70); + _md5_HH(a, b, c, d, in[13], _md5_S31, 0x289B7EC6); + _md5_HH(d, a, b, c, in[0], _md5_S32, 0xEAA127FA); + _md5_HH(c, d, a, b, in[3], _md5_S33, 0xD4EF3085); + _md5_HH(b, c, d, a, in[6], _md5_S34, 0x04881D05); + _md5_HH(a, b, c, d, in[9], _md5_S31, 0xD9D4D039); + _md5_HH(d, a, b, c, in[12], _md5_S32, 0xE6DB99E5); + _md5_HH(c, d, a, b, in[15], _md5_S33, 0x1FA27CF8); + _md5_HH(b, c, d, a, in[2], _md5_S34, 0xC4AC5665); + + // + _md5_II(a, b, c, d, in[0], _md5_S41, 0xF4292244); + _md5_II(d, a, b, c, in[7], _md5_S42, 0x432AFF97); + _md5_II(c, d, a, b, in[14], _md5_S43, 0xAB9423A7); + _md5_II(b, c, d, a, in[5], _md5_S44, 0xFC93A039); + _md5_II(a, b, c, d, in[12], _md5_S41, 0x655B59C3); + _md5_II(d, a, b, c, in[3], _md5_S42, 0x8F0CCC92); + _md5_II(c, d, a, b, in[10], _md5_S43, 0xFFEFF47D); + _md5_II(b, c, d, a, in[1], _md5_S44, 0x85845DD1); + _md5_II(a, b, c, d, in[8], _md5_S41, 0x6FA87E4F); + _md5_II(d, a, b, c, in[15], _md5_S42, 0xFE2CE6E0); + _md5_II(c, d, a, b, in[6], _md5_S43, 0xA3014314); + _md5_II(b, c, d, a, in[13], _md5_S44, 0x4E0811A1); + _md5_II(a, b, c, d, in[4], _md5_S41, 0xF7537E82); + _md5_II(d, a, b, c, in[11], _md5_S42, 0xBD3AF235); + _md5_II(c, d, a, b, in[2], _md5_S43, 0x2AD7D2BB); + _md5_II(b, c, d, a, in[9], _md5_S44, 0xEB86D391); + + // + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; + } +}; diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.xstrategy.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.xstrategy.class.mq5 new file mode 100644 index 00000000..c8cbe531 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.xstrategy.class.mq5 @@ -0,0 +1,1689 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XSCBaseStrategy +// 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 "../Libraries/x-saherelm.tools.lib.mq5" +#include "../Classes/x-saherelm.xtrade.class.mq5" +#include "../Classes/x-saherelm.xalert.class.mq5" + +// +// Definitions ... + +// +class XSCBaseStrategy : public XSCBaseAlert +{ + // + // Public ... +public: + // + // Constructors ... + void XSCBaseStrategy( + string _symbol, // Trading Symbol + ENUM_TIMEFRAMES _period, // Trading TimeFrame + ENUM_TIMEFRAMES _analizePeriod, // Important Area Detect Time Frame + double _volume, // Voluem + double _r2r, // Risk/Reward Ratio + int _slippage, // Trader Slippage + long _magicNumber, // Trader Magic Number + bool _ignoreSignalExecution = false, // Ignore Signal Execution + bool _useTPSLAsPoint = false, // Converts TP and SL by Provided Points + bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points + double _tpPoint = 0, // TP As Point + double _slPoint = 0, // SL As Point + bool _ignoreTP = false, // TP set to 0 + bool _ignoreSL = false, // SL set to 0 + bool _allowLong = true, + bool _allowShort = true, + int _maxAllowedLongs = 0, + int _maxAllowedShorts = 0 // + ) + { + // + // Fill Properties ... + mR2R = _r2r; + mVolume = _volume; + mSymbol = _symbol; + mPeriod = _period; + mTPPoint = _tpPoint; + mSLPoint = _slPoint; + mIgnoreTP = _ignoreTP; + mIgnoreSL = _ignoreSL; + mSlippage = _slippage; + mAllowLong = _allowLong; + mAllowShort = _allowShort; + mMagicNumber = _magicNumber; + mAnalizePeriod = _analizePeriod; + mUseTPSLAsPoint = _useTPSLAsPoint; + mMaxAllowedLongs = _maxAllowedLongs; + mMaxAllowedShorts = _maxAllowedShorts; + mForceMaxTPSLAsPoint = _forceMaxTPSLAsPoint; + mIgnoreSignalExecution = _ignoreSignalExecution; + + // + mForceDisabled = false; + + // + // Initial Trader Class Instance ... + trader = new XSCTrade( + mSlippage, + mMagicNumber // + ); + + // + // Initial Time Tracker ... + barTracker.Init( + mSymbol, + mPeriod // + ); + + // + SetAlertPrefix(GetTag()); + } + + // + // Deconstructor ... + void ~XSCBaseStrategy() + { + // + delete trader; + + // + Reset(); + } + + // + // Getter and Setter (s) ... + + // + int Slippage() + { + return mSlippage; + } + + // + long MagicNumber() + { + return mMagicNumber; + } + + // + string Symbol() + { + return mSymbol; + } + + // + ENUM_TIMEFRAMES Period() + { + return mPeriod; + } + + // + bool IsDisabled() + { + return mForceDisabled; + } + + // + void Disable() + { + mForceDisabled = true; + } + + // + void Enable() + { + mForceDisabled = false; + } + + // + double Volume() + { + return mVolume; + } + + // + void Volume(double value) + { + // + if (value < 0.01) + { + value = 0.01; + } + + // + mVolume = value; + } + + // + double R2R() + { + return mR2R; + } + + // + bool AllowLong() + { + return mAllowLong; + } + + // + void AllowLong(bool value) + { + mAllowLong = value; + } + + // + bool AllowShort() + { + return mAllowShort; + } + + // + void AllowShort(bool value) + { + mAllowShort = value; + } + + // + int MaxAllowedLongs() + { + return mMaxAllowedLongs; + } + + // + void MaxAllowedLongs(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxAllowedLongs = value; + } + + // + int MaxAllowedShorts() + { + return mMaxAllowedShorts; + } + + // + void MaxAllowedShorts(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxAllowedShorts = value; + } + + // + int RequiredPivots() + { + return mRequiredPivots; + } + + // + void RequiredPivots(int value) + { + // + if (value < 3) + { + value = 3; + } + + // + mRequiredPivots = value; + } + + // + int RequiredShoulders() + { + return mRequiredShoulders; + } + + // + void RequiredShoulders(int value) + { + // + if (value < 5) + { + value = 5; + } + + // + mRequiredShoulders = value; + } + + // + bool UseTPSLAsPoint() + { + return mUseTPSLAsPoint; + } + + // + void UseTPSLAsPoint(bool value) + { + mUseTPSLAsPoint = value; + } + + // + bool ForceMaxTPSLAsPoint() + { + return mForceMaxTPSLAsPoint; + } + + // + void ForceMaxTPSLAsPoint(bool value) + { + mForceMaxTPSLAsPoint = value; + } + + // + double TPPoint() + { + return mTPPoint; + } + + // + void TPPoint(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mTPPoint = value; + } + + // + double SLPoint() + { + return mSLPoint; + } + + // + void SLPoint(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mSLPoint = value; + } + + // + bool IgnoreTP() + { + return mIgnoreTP; + } + + // + void IgnoreTP(bool value) + { + mIgnoreTP = value; + } + + // + bool IgnoreSL() + { + return mIgnoreSL; + } + + // + void IgnoreSL(bool value) + { + mIgnoreSL = value; + } + + // + bool IgnoreSignalExecution() + { + return mIgnoreSignalExecution; + } + + // + void IgnoreSignalExecution(bool value) + { + mIgnoreSignalExecution = value; + } + + // + // On Signal Handlers ... + void AddSignalEventHandler(TOnSignal handler) + { + // + Add( + handler, + mOnSignalEventHandlers // + ); + } + + // + ENUM_TIMEFRAMES AnalizePeriod() + { + return mAnalizePeriod; + } + + // + void AnalizePeriod(ENUM_TIMEFRAMES value) + { + mAnalizePeriod = value; + } + + // + bool DrawImportantAreas() + { + return mDrawImportantAreas; + } + + // + void DrawImportantAreas(bool value) + { + mDrawImportantAreas = value; + } + + // + // Important Areas Getters ... + + // + bool GetSupport( + XOHCL &bar // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + result = support.IsValid(); + if (result) + { + bar = support; + } + + // + return result; + } + + // + bool GetResistance( + XOHCL &bar // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + result = resistance.IsValid(); + if (result) + { + bar = resistance; + } + + // + return result; + } + + // + bool GetBullishOB( + XOHCL &bar // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + result = bullishOB.IsValid(); + if (result) + { + bar = bullishOB; + } + + // + return result; + } + + // + bool GetBearishOB( + XOHCL &bar // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + result = bearishOB.IsValid(); + if (result) + { + bar = bearishOB; + } + + // + return result; + } + + // + bool GetBullishFVG( + XOHCL &bar, + double upper, + double lower // + ) + { + // + bool result = false; + + // + upper = 0; + lower = 0; + bar.Clean(); + + // + result = bullishFVG.IsValid(); + if (result) + { + // + bar = bullishFVG; + upper = bullishFVGUpper; + lower = bullishFVGLower; + } + + // + return result; + } + + // + bool GetBearishFVG( + XOHCL &bar, + double upper, + double lower // + ) + { + // + bool result = false; + + // + upper = 0; + lower = 0; + bar.Clean(); + + // + result = bearishFVG.IsValid(); + if (result) + { + // + bar = bearishFVG; + upper = bearishFVGUpper; + lower = bearishFVGLower; + } + + // + return result; + } + + // + bool GetBullishTrend( + XOHCL &bar, + XOHCL &swingHighs[], + XOHCL &swingLows[] // + ) + { + // + bool result = false; + + // + bar.Clean(); + Clean(swingHighs); + Clean(swingLows); + + // + result = bullishTrend.IsValid(); + if (result) + { + // + bar = bullishTrend; + + // + Copy( + bullishTrendSwingHighs, + swingHighs // + ); + Copy( + bullishTrendSwingLows, + swingLows // + ); + } + + // + return result; + } + + // + bool GetBearishTrend( + XOHCL &bar, + XOHCL &swingHighs[], + XOHCL &swingLows[] // + ) + { + // + bool result = false; + + // + bar.Clean(); + Clean(swingHighs); + Clean(swingLows); + + // + result = bearishTrend.IsValid(); + if (result) + { + // + bar = bearishTrend; + + // + Copy( + bearishTrendSwingHighs, + swingHighs // + ); + Copy( + bearishTrendSwingLows, + swingLows // + ); + } + + // + return result; + } + + // + // Virtual Methods ... + + // + // Tag ... + virtual string GetTag() + { + return "XBaseStrategy"; + } + + // + // Check Conditions for Signal ... + // this must be Override based on each Strategy ... + virtual bool HasSignal( + XSignal &signal // + ) + { + return false; + } + + // + // Check Conditions For Signal and Execute Signal ... + virtual void HandleTick() + { + // + if (IsDisabled()) + { + return; + } + + // + if (!AllowLong() && !AllowShort()) + { + return; + } + + // + if (!barTracker.CanProcessBar()) + { + return; + } + + // + MqlTick cTick; + bool hasTick = GetTick( + mSymbol, + cTick // + ); + bool isSameAsLast = cTick.time == lastTick.time; + if (isSameAsLast) + { + return; + } + + // + lastTick = cTick; + + // + XSignal signal; + bool hasSignal = HasSignal(signal); + if (!hasSignal) + { + return; + } + + // + barTracker.Waits(); + + // + Execute(signal); + } + + // + // Handle Signal Execution ... + virtual bool Execute(XSignal &signal) + { + // + bool result = false; + + // + // Prepare and Normalize Signal ... + result = PrepareSignal(signal); + if (!result) + { + return result; + } + + // + // Notify Signal Event Handler(s) ... + NotifyOnSignalEventHandlers(signal); + + // + // Check Signal Execution Enabled or not ... + result = !mIgnoreSignalExecution; + if (!result) + { + return result; + } + + // + bool isLong = IsLong(signal.type); + + // + ENUM_X_SIGNAL_EXECUTION_RESULT state; + result = trader.ExecuteSignal( + signal, + state // + ); + if (result) + { + // + string message = "Execute " + (isLong ? "Long" : "Short") + " " + signal.symbol + "/" + ToString(signal.period) + " ..."; + Alert(message); + + // + OnSignalExecuted(signal); + } + else + { + OnSignalExecutionFailed(signal, state); + } + + // + return result; + } + + // + // Calls When a Signal Executed Successfully ... + virtual void OnSignalExecuted(XSignal &signal) + { + } + + // + // Calls When a Signal Execution Failed ... + virtual void OnSignalExecutionFailed( + XSignal &signal, + ENUM_X_SIGNAL_EXECUTION_RESULT result // + ) + { + } + + // + // Protected ... +protected: + // + int mSlippage; // Trader Slippage + long mMagicNumber; // Trader Magic Number + bool mForceDisabled; // Force Disabled + bool mAllowLong; // Allow Long Signals + bool mAllowShort; // Allow Short Signals + int mMaxAllowedLongs; // Max Allowed Longs + int mMaxAllowedShorts; // Max Allowed Shorts + + // + bool mUseTPSLAsPoint; // Converts TP and SL by Provided Points + bool mForceMaxTPSLAsPoint; // Force Max TP and SL by Provided Points + double mTPPoint; // TP As Point + double mSLPoint; // SL As Point + bool mIgnoreTP; // TP set to 0 + bool mIgnoreSL; // SL set to 0 + bool mIgnoreSignalExecution; // Ignore Signal Execution + + // + string mSymbol; // Trading Symbol ... + ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ... + + // + double mR2R; // Risk/Rewar Ratio ... + double mVolume; // Static Volume Per Trades ... + + // + XBarTracker barTracker; // Strategy Time Tracker ... + + // + // Trend Detecting ... + int mRequiredPivots; // Required Pivots For Trend Detecting ... + int mRequiredShoulders; // Required Pivots Shoulders ... + + // + XSCTrade *trader; + + // + MqlTick lastTick; + + // + void Reset() + { + barTracker.Clean(); + } + + // + // Prepare and Normalize Signal for Execution in Strategy ... + bool PrepareSignal(XSignal &signal) + { + // + bool result = false; + + // + // Check Strategy Is Enables ... + result = !IsDisabled(); + if (!result) + { + return result; + } + + // + // Validate Signal ... + result = signal.IsValid(); + if (!result) + { + return result; + } + + // + bool isLong = IsLong(signal.type); + + // + // Check Type Enabled ... + result = + // + isLong + ? AllowLong() + : AllowShort() + // + ; + if (!result) + { + return result; + } + + // + // Check Max Allowed Trades Limitation ... + if ( + (isLong && MaxAllowedLongs() > 0) || + (!isLong && MaxAllowedShorts() > 0)) + { + // + // Here We Have to Count Positions ... + + // + // Get and Count Positions ... + XPosition longs[]; + XPosition shorts[]; + trader.GetPositions( + longs, + shorts, + signal.symbol // + ); + + // + int longsCount = ArraySize(longs); + int shortsCount = ArraySize(shorts); + + // + result = + // + isLong + ? longsCount < MaxAllowedLongs() + : shortsCount < MaxAllowedShorts() + // + ; + if (!result) + { + return result; + } + } + + // + // Check TP and SL ... + double points = GetPoints(signal.symbol); + if (mUseTPSLAsPoint) + { + // + double sl = 0; + double tp = 0; + bool isCalculated = !(mSLPoint > 0 || mTPPoint > 0) + ? false + : CalculateTPSLByPoint( + sl, + tp, + signal.type, + signal.entry, + points, + mR2R, + mSLPoint, + mTPPoint // + ); + if (isCalculated) + { + // + signal.sl = sl; + signal.tp = tp; + } + } + else if (mForceMaxTPSLAsPoint) + { + // + if (mSLPoint > 0) + { + // + double risk = signal.GetRisk(); + double riskPoints = risk / points; + + // + if (riskPoints > mSLPoint) + { + // + signal.sl = + isLong + ? signal.entry - (mSLPoint * points) + : signal.entry + (mSLPoint * points); + } + } + + // + if (mTPPoint > 0) + { + // + double reward = signal.GetReward(); + double rewardPoints = reward / points; + + // + if (rewardPoints > mTPPoint) + { + // + signal.tp = + isLong + ? signal.entry + (mTPPoint * points) + : signal.entry - (mTPPoint * points); + } + } + } + + // + if (mIgnoreTP) + { + signal.tp = 0; + } + + // + if (mIgnoreSL) + { + signal.sl = 0; + } + + // + return result; + } + + // + // Notified Signal Event Handler(s) ... + void NotifyOnSignalEventHandlers(XSignal &signal) + { + // + if (!signal.IsValid()) + { + return; + } + + // + int count = ArraySize(mOnSignalEventHandlers); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + mOnSignalEventHandlers[i](signal); + } + } + + // + ENUM_TIMEFRAMES mAnalizePeriod; // Important Area Detect Time Frame + bool mDrawImportantAreas; // Draw Important Areas where Founded in Analyzing Time Frame + + // + XOHCL support; + XOHCL resistance; + XOHCL bullishOB; + XOHCL bearishOB; + + // + double bullishFVGUpper; + double bullishFVGLower; + XOHCL bullishFVG; + + // + double bearishFVGUpper; + double bearishFVGLower; + XOHCL bearishFVG; + + // + XOHCL bullishTrendSwingHighs[]; + XOHCL bullishTrendSwingLows[]; + XOHCL bullishTrend; + + // + XOHCL bearishTrendSwingHighs[]; + XOHCL bearishTrendSwingLows[]; + XOHCL bearishTrend; + + // + void DetectImportantAreas() + { + // + int zIndex = 0; + int cIndex = zIndex + 1; + + // + // Last Bar ... + XOHCL cBar; + bool result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return; + } + + // + // Analyzing Bar ... + XOHCL aBar; + if (IsValid(mAnalizePeriod)) + { + // + result = aBar.Init( + mSymbol, + mAnalizePeriod, + cIndex // + ); + + // + if (!result) + { + return; + } + } + else + { + aBar = cBar; + } + + // + // Support nad Resistance ... + + // + // Check Support Exists or Find ... + bool hasSupport = support.IsValid(); + if (!hasSupport) + { + // + hasSupport = + // + aBar.HasSupport(support) + // + ; + + // + if (hasSupport) + { + // + if (mDrawImportantAreas) + { + // + DrawSupport( + support, + ChartID() // + ); + } + + // + supportTime = aBar.time; + } + } + + // + // Check Resistance Exists or Find ... + bool hasResistance = resistance.IsValid(); + if (!hasResistance) + { + // + hasResistance = + // + aBar.HasResistance(resistance) + // + ; + + // + if (hasResistance) + { + // + if (mDrawImportantAreas) + { + // + DrawResistance( + resistance, + ChartID() // + ); + } + + // + resistanceTime = aBar.time; + } + } + + // + // Order Blocks ... + + // + bool hasBullishOB = bullishOB.IsValid(); + if (!hasBullishOB) + { + // + hasBullishOB = + // + aBar.HasBullishOrderBlock(bullishOB) + // + ; + + // + if (hasBullishOB) + { + // + if (mDrawImportantAreas) + { + // + DrawBullishOrderBlock( + bullishOB, + ChartID() // + ); + } + + // + bullishOBTime = aBar.time; + } + } + + // + bool hasBearishOB = bearishOB.IsValid(); + if (!hasBearishOB) + { + // + hasBearishOB = + // + aBar.HasBearishOrderBlock(bearishOB) + // + ; + + // + if (hasBearishOB) + { + // + if (mDrawImportantAreas) + { + // + DrawBearishOrderBlock( + bearishOB, + ChartID() // + ); + } + + // + bearishOBTime = aBar.time; + } + } + + // + // FVG ... + + // + bool hasBullishFVG = bullishFVG.IsValid(); + if (!hasBullishFVG) + { + // + hasBullishFVG = + // + aBar.HasBullishFVG( + bullishFVGUpper, + bullishFVGLower // + ) + // + ; + + // + if (hasBullishFVG) + { + // + bullishFVG = aBar; + + // + if (mDrawImportantAreas) + { + // + DrawBullishFVG( + bullishFVG, + bullishFVGUpper, + bullishFVGLower, + ChartID() // + ); + } + + // + bullishFVGTime = aBar.time; + } + } + + // + bool hasBearishFVG = bearishFVG.IsValid(); + if (!hasBearishFVG) + { + // + hasBearishFVG = + // + aBar.HasBearishFVG( + bearishFVGUpper, + bearishFVGLower // + ) + // + ; + + // + if (hasBearishFVG) + { + // + bearishFVG = aBar; + + // + if (mDrawImportantAreas) + { + // + DrawBearishFVG( + bearishFVG, + bearishFVGUpper, + bearishFVGLower, + ChartID() // + ); + } + + // + bearishFVGTime = aBar.time; + } + } + + // + // TREND ... + + // + bool hasBullishTrend = bullishTrend.IsValid(); + if (!hasBullishTrend) + { + // + hasBullishTrend = aBar.HasBullishTrend( + bullishTrendSwingHighs, + bullishTrendSwingLows, + false // + ); + + // + if (hasBullishTrend) + { + // + bullishTrend = aBar; + + // + if (mDrawImportantAreas) + { + // + DrawBullishTrend( + bullishTrend, + bullishTrendSwingHighs, + bullishTrendSwingLows, + ChartID() // + ); + } + } + } + + // + bool hasBearishTrend = bearishTrend.IsValid(); + if (!hasBearishTrend) + { + // + hasBearishTrend = aBar.HasBearishTrend( + bearishTrendSwingHighs, + bearishTrendSwingLows, + false // + ); + + // + if (hasBearishTrend) + { + // + bearishTrend = aBar; + + // + if (mDrawImportantAreas) + { + // + DrawBearishTrend( + bearishTrend, + bearishTrendSwingHighs, + bearishTrendSwingLows, + ChartID() // + ); + } + } + } + + // + } + + // + void DestroyImportantAreas() + { + // + bool hasSupport = support.IsValid(); + if (hasSupport) + { + // + supportTime = NULL; + isSupportTested = false; + RemoveSupport(support); + support.Clean(); + } + + // + bool hasResistance = resistance.IsValid(); + if (hasResistance) + { + // + resistanceTime = NULL; + isResistanceTested = false; + RemoveResistance(resistance); + resistance.Clean(); + } + + // + bool hasBullishOB = bullishOB.IsValid(); + if (hasBullishOB) + { + // + bullishOBTime = NULL; + RemoveBullishOrderBlock(bullishOB); + bullishOB.Clean(); + } + + // + bool hasBearishOB = bearishOB.IsValid(); + if (hasBearishOB) + { + // + bearishOBTime = NULL; + RemoveBearishOrderBlock(bearishOB); + bearishOB.Clean(); + } + + // + bool hasBullishFVG = bullishFVG.IsValid(); + if (hasBullishFVG) + { + // + bullishFVGUpper = 0; + bullishFVGLower = 0; + bullishFVGTime = NULL; + RemoveBullishFVG(bullishFVG); + bullishFVG.Clean(); + } + + // + bool hasBearishFVG = bearishFVG.IsValid(); + if (hasBearishFVG) + { + // + bearishFVGUpper = 0; + bearishFVGLower = 0; + bearishFVGTime = NULL; + RemoveBullishFVG(bearishFVG); + bearishFVG.Clean(); + } + + // + bool hasBullishTrend = bullishTrend.IsValid(); + if (hasBullishTrend) + { + // + RemoveBullishTrend(bullishTrend); + bullishTrend.Clean(); + } + + // + bool hasBearishTrend = bearishTrend.IsValid(); + if (hasBearishTrend) + { + // + RemoveBearishTrend(bearishTrend); + bearishTrend.Clean(); + } + } + + // + void CheckImportantAreasValidation() + { + // + CheckSupportValidation(); + CheckResistanceValidation(); + + // + CheckBullishOBValidation(); + CheckBearishOBValidation(); + + // + CheckBullishFVGValidation(); + CheckBearishFVgValidation(); + + // + CheckBullishTrendValidation(); + CheckBearishTrendValidation(); + } + + // + bool isSupportTested; + datetime supportTime; + void CheckSupportValidation() + { + // + if (!isSupportTested) + { + // + if (support.IsValid() && IsValid(supportTime)) + { + // + int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(supportTime))) / PeriodSeconds(mPeriod)); + if (age >= 50) + { + // + isSupportTested = false; + supportTime = NULL; + RemoveSupport(support); + support.Clean(); + } + } + return; + } + + // + XOHCL cBar; + bool isInited = cBar.Init( + mSymbol, + mPeriod, + 1 // + ); + if (!isInited) + { + return; + } + + // + double points = GetPoints(mSymbol); + + // + // Find Price Distance ... + double highDiff = MathAbs(cBar.high - support.high); + double lowDiff = MathAbs(cBar.low - support.high); + + // + bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points; + if (!isBreaked) + { + return; + } + + // + isSupportTested = false; + RemoveSupport(support); + supportTime = NULL; + support.Clean(); + } + + // + bool isResistanceTested; + datetime resistanceTime; + void CheckResistanceValidation() + { + // + if (!isResistanceTested) + { + // + if (resistance.IsValid() && IsValid(resistanceTime)) + { + // + int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(resistanceTime))) / PeriodSeconds(mPeriod)); + if (age >= 50) + { + // + isResistanceTested = false; + resistanceTime = NULL; + RemoveResistance(resistance); + resistance.Clean(); + } + } + return; + } + + // + XOHCL cBar; + bool isInited = cBar.Init( + mSymbol, + mPeriod, + 1 // + ); + if (!isInited) + { + return; + } + + // + double points = GetPoints(mSymbol); + + // + // Find Price Distance ... + double highDiff = MathAbs(cBar.high - resistance.low); + double lowDiff = MathAbs(cBar.low - resistance.low); + + // + bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points; + if (!isBreaked) + { + return; + } + + // + isResistanceTested = false; + RemoveResistance(resistance); + resistanceTime = NULL; + resistance.Clean(); + } + + // + datetime bullishOBTime; + void CheckBullishOBValidation() + { + // + if (!IsValid(bullishOBTime)) + { + return; + } + + // + int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishOBTime))) / PeriodSeconds(mPeriod)); + if (age >= 50) + { + // + bullishOBTime = NULL; + RemoveBullishOrderBlock(bullishOB); + bullishOB.Clean(); + } + } + + // + datetime bearishOBTime; + void CheckBearishOBValidation() + { + // + if (!IsValid(bearishOBTime)) + { + return; + } + + // + int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishOBTime))) / PeriodSeconds(mPeriod)); + if (age >= 50) + { + // + bearishOBTime = NULL; + RemoveBearishOrderBlock(bearishOB); + bearishOB.Clean(); + } + } + + // + datetime bullishFVGTime; + void CheckBullishFVGValidation() + { + // + if (!IsValid(bullishFVGTime)) + { + return; + } + + // + int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishFVGTime))) / PeriodSeconds(mPeriod)); + if (age >= 50) + { + // + bullishFVGTime = NULL; + RemoveBullishFVG(bullishFVG); + bullishFVG.Clean(); + } + } + + // + datetime bearishFVGTime; + void CheckBearishFVgValidation() + { + // + if (!IsValid(bearishFVGTime)) + { + return; + } + + // + int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishFVGTime))) / PeriodSeconds(mPeriod)); + if (age >= 50) + { + // + bearishFVGTime = NULL; + RemoveBearishFVG(bearishFVG); + bearishFVG.Clean(); + } + } + + // + void CheckBullishTrendValidation() + { + // + // TODO: Complete this ... + } + + // + void CheckBearishTrendValidation() + { + // + // TODO: Complete this ... + } + + // + // Private ... +private: + // + // Props ... + + // + // On Signal Recieved Event Handler(s) ... + TOnSignal mOnSignalEventHandlers[]; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.xtrade.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.xtrade.class.mq5 new file mode 100644 index 00000000..b9adec5c --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.xtrade.class.mq5 @@ -0,0 +1,6626 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCTrade +// Description: provides all Trade 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 "../Classes/x-saherelm.base.class.mq5" +#include "../Libraries/x-saherelm.tools.lib.mq5" +#include "../Classes/x-saherelm.xalert.class.mq5" +#include "../Libraries/x-saherelm.xtrade.lib.mq5" +#include "../Classes/x-saherelm.xaccount.class.mq5" + +// +// Definitions ... + +// +// Overrides ... + +// +// XCTrade Base Class ... +class XSCTradeBase : public CTrade +{ +public: + // + // Modify Specific Position, by Specific Comment ... + bool PositionModify( + const string symbol, // Symbol + const double sl, // Stop Loss + const double tp, // Take Profit + const string comment = "" // Comment For Modify + ) + { + // + // check stopped + if (IsStopped(__FUNCTION__)) + { + return (false); + } + + // + // check position existence + if (!SelectPosition(symbol)) + { + return (false); + } + + // + // clean + ClearStructures(); + + // + // setting request + m_request.action = TRADE_ACTION_SLTP; + m_request.symbol = symbol; + m_request.magic = m_magic; + m_request.sl = sl; + m_request.tp = tp; + m_request.position = PositionGetInteger(POSITION_TICKET); + + // + // Specified Comment ... + if (StringLen(comment) > 0) + { + m_request.comment = comment; + } + + // + // action and return the result + return (OrderSend(m_request, m_result)); + } + bool PositionModify( + const ulong ticket, // Position Ticket + const double sl, // Stop Loss + const double tp, // Take Profit + const string comment = "" // Comment For Modify + ) + { + // + // check stopped + if (IsStopped(__FUNCTION__)) + { + return (false); + } + + // + // check position existence + if (!PositionSelectByTicket(ticket)) + { + return (false); + } + + // + // clean + ClearStructures(); + + // + // setting request + m_request.action = TRADE_ACTION_SLTP; + m_request.position = ticket; + m_request.symbol = PositionGetString(POSITION_SYMBOL); + m_request.magic = m_magic; + m_request.sl = sl; + m_request.tp = tp; + + // + // Specified Comment ... + if (StringLen(comment) > 0) + { + m_request.comment = comment; + } + + // + // action and return the result + return (OrderSend(m_request, m_result)); + } + + // + // Close Specific Position, by Specific Comment ... + bool PositionClose( + const string symbol, // Symbol + const ulong deviation, // Deviation + const string comment = "" // Comment For Close + ) + { + // + bool partial_close = false; + int retry_count = 10; + uint retcode = TRADE_RETCODE_REJECT; + + // + // check stopped + if (IsStopped(__FUNCTION__)) + { + return (false); + } + + // + // clean + ClearStructures(); + + // + // check filling + if (!FillingCheck(symbol)) + { + return (false); + } + + // + do + { + // + // check + if (SelectPosition(symbol)) + { + // + if ((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) + { + // + // prepare request for close BUY position + m_request.type = ORDER_TYPE_SELL; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_BID); + } + else + { + // + // prepare request for close SELL position + m_request.type = ORDER_TYPE_BUY; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_ASK); + } + } + else + { + // + // position not found + m_result.retcode = retcode; + return (false); + } + + // + // setting request + m_request.action = TRADE_ACTION_DEAL; + m_request.symbol = symbol; + m_request.volume = PositionGetDouble(POSITION_VOLUME); + m_request.magic = m_magic; + m_request.deviation = (deviation == ULONG_MAX) ? m_deviation : deviation; + m_request.position = PositionGetInteger(POSITION_TICKET); + + // + // Specify Comment ... + m_request.comment = comment; + + // + // check volume + double max_volume = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX); + if (m_request.volume > max_volume) + { + // + m_request.volume = max_volume; + partial_close = true; + } + else + { + partial_close = false; + } + + // + // hedging? just send order + if (IsHedging()) + { + return (OrderSend(m_request, m_result)); + } + + // + // order send + if (!OrderSend(m_request, m_result)) + { + // + if (--retry_count != 0) + { + continue; + } + + // + if (retcode == TRADE_RETCODE_DONE_PARTIAL) + { + m_result.retcode = retcode; + } + + // + return (false); + } + + // + //--- WARNING. If position volume exceeds the maximum volume allowed for deal, + //--- and when the asynchronous trade mode is on, for safety reasons, position is closed not completely, + //--- but partially. It is decreased by the maximum volume allowed for deal. + if (m_async_mode) + { + break; + } + + // + retcode = TRADE_RETCODE_DONE_PARTIAL; + if (partial_close) + { + Sleep(1000); + } + } while (partial_close); + + // + // succeed + return (true); + } + bool PositionClose( + const ulong ticket, // Position Ticket + const ulong deviation, // Deviation + const string comment = "" // Comment For Close + ) + { + // + // check stopped + if (IsStopped(__FUNCTION__)) + { + return (false); + } + + // + // check position existence + if (!PositionSelectByTicket(ticket)) + { + return (false); + } + + // + string symbol = PositionGetString(POSITION_SYMBOL); + + // + // clean + ClearStructures(); + + // + // check filling + if (!FillingCheck(symbol)) + { + return (false); + } + + // + // check + if ((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) + { + // + // prepare request for close BUY position + m_request.type = ORDER_TYPE_SELL; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_BID); + } + else + { + // + // prepare request for close SELL position + m_request.type = ORDER_TYPE_BUY; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_ASK); + } + + // + // setting request + m_request.action = TRADE_ACTION_DEAL; + m_request.position = ticket; + m_request.symbol = symbol; + m_request.volume = PositionGetDouble(POSITION_VOLUME); + m_request.magic = m_magic; + m_request.deviation = (deviation == ULONG_MAX) ? m_deviation : deviation; + + // + // Specify Comment ... + m_request.comment = comment; + + // + // close position + return (OrderSend(m_request, m_result)); + } + + // + // Partial Close Specific Position, by Specific Comment ... + bool PositionClosePartial( + const string symbol, // Symbol + const double volume, // Partial Closing Volume + const ulong deviation, // Deviation + const string comment = "" // Comment For Close + ) + { + // + uint retcode = TRADE_RETCODE_REJECT; + + // + // check stopped + if (IsStopped(__FUNCTION__)) + { + return (false); + } + + // + // for hedging mode only + if (!IsHedging()) + { + return (false); + } + + // + // clean + ClearStructures(); + + // + // check filling + if (!FillingCheck(symbol)) + { + return (false); + } + + // + // check + if (SelectPosition(symbol)) + { + // + if ((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) + { + // + // prepare request for close BUY position + m_request.type = ORDER_TYPE_SELL; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_BID); + } + else + { + // + // prepare request for close SELL position + m_request.type = ORDER_TYPE_BUY; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_ASK); + } + } + else + { + // + // position not found + m_result.retcode = retcode; + return (false); + } + + // + // check volume + double position_volume = PositionGetDouble(POSITION_VOLUME); + if (position_volume > volume) + { + position_volume = volume; + } + + // + // setting request + m_request.action = TRADE_ACTION_DEAL; + m_request.symbol = symbol; + m_request.volume = position_volume; + m_request.magic = m_magic; + m_request.deviation = (deviation == ULONG_MAX) ? m_deviation : deviation; + m_request.position = PositionGetInteger(POSITION_TICKET); + + // + // Specifieng Comment ... + m_request.comment = comment; + + // + // hedging? just send order + return (OrderSend(m_request, m_result)); + } + bool PositionClosePartial( + const ulong ticket, // Position Ticket + const double volume, // Partial Closing Volume + const ulong deviation, // Deviation + const string comment = "" // Comment For Close + ) + { + // + // check stopped + if (IsStopped(__FUNCTION__)) + { + return (false); + } + + // + // for hedging mode only + if (!IsHedging()) + { + return (false); + } + + // + // check position existence + if (!PositionSelectByTicket(ticket)) + { + return (false); + } + + // + string symbol = PositionGetString(POSITION_SYMBOL); + + // + // clean + ClearStructures(); + + // + // check filling + if (!FillingCheck(symbol)) + { + return (false); + } + + // + // check + if ((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) + { + // + // prepare request for close BUY position + m_request.type = ORDER_TYPE_SELL; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_BID); + } + else + { + // + // prepare request for close SELL position + m_request.type = ORDER_TYPE_BUY; + m_request.price = SymbolInfoDouble(symbol, SYMBOL_ASK); + } + + // + // check volume + double position_volume = PositionGetDouble(POSITION_VOLUME); + if (position_volume > volume) + { + position_volume = volume; + } + + // + // setting request + m_request.action = TRADE_ACTION_DEAL; + m_request.position = ticket; + m_request.symbol = symbol; + m_request.volume = position_volume; + m_request.magic = m_magic; + m_request.deviation = (deviation == ULONG_MAX) ? m_deviation : deviation; + + // + // Specifieng Comment ... + m_request.comment = comment; + + // + // close position + return (OrderSend(m_request, m_result)); + } +}; + +// +// Implementation ... + +// +// a Class For Manage Trades and Handle Trading Actions ... +class XSCTrade : public XSCBase +{ + // + // Public ... +public: + // + // Props ... + XSCAccount *mAccount; // Account Info Provider + + // + // Constructors ... + void XSCTrade( + int slippage, // Specify Slippage + ulong magicNumber, // Specify Magic Number + double maxAllowedSpread = 0, // Max Allowed Spred for Opening Trades + int maxAllowedPositions = 0, // Max Allowed Positions + double maxAllowedDrawdownFactor = 0 // Max Allowed Drawdown Factor + ) + { + // + // Setting Props ... + mSlippage = slippage; + mMagicNumber = magicNumber; + + // + mMaxAllowedSpread = maxAllowedSpread; + mMaxAllowedPositions = maxAllowedPositions; + mMaxAllowedDrawdownFactor = maxAllowedDrawdownFactor; + + // + mAccount = new XSCAccount(); + + // + // Instance Base Trader Class ... + mTrader = new XSCTradeBase(); + + // + // Configuring Base Trader Class ... + mTrader.SetAsyncMode(false); + mTrader.SetDeviationInPoints(mSlippage); + mTrader.SetExpertMagicNumber(mMagicNumber); + + // + // Setting Log Level ... + mTrader.LogLevel(LOG_LEVEL_ERRORS); + + // + // OnTrade Context ... + + // + mDaysForRead = 1; + mScanStarted = false; + + // + // Reset On Trade Counter ... + ResetOnTradeContext(); + + // + // Init On Trade Context ... + InitOnTradeContext(); + } + + // + // Deconstructor ... + ~XSCTrade() + { + // + // Remove Pointer ... + delete mTrader; + delete mAccount; + + // + Clean(mOnModifyEventHandlers); + Clean(mStopLossEventHandlers); + Clean(mTakeProfitEventHandlers); + Clean(mOnForceCloseEventHandlers); + Clean(mDealsChangedEventHandlers); + Clean(mOrdersChangedEventHandlers); + Clean(mOnPartialCloseEventHandlers); + Clean(mPositionsChangedEventHandlers); + Clean(mTradeStateChangedEventHandlers); + } + + // + // Props ... + + // + // Retrieve Slippage ... + int GetSlippage() + { + return mSlippage; + } + + // + // Retrieve Magic Number ... + ulong GetMagicNumber() + { + return mMagicNumber; + } + + // + double GetMaxAllowedSpread() + { + return mMaxAllowedSpread; + } + + // + int GetMaxAllowedPositions() + { + return mMaxAllowedPositions; + } + + // + void SetMaxAllowedPositions(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxAllowedPositions = value; + } + + // + double GetMaxAllowedDrawdownFactor() + { + return mMaxAllowedDrawdownFactor; + } + + // + // Add Event Listeners ... + + // + void AddOnModifyPositionEventHandler(TOnModify handler) + { + // + Add( + handler, + mOnModifyEventHandlers + // + ); + } + + // + void AddOnForceClosePositionEventHandler(TOnForceClose handler) + { + // + Add( + handler, + mOnForceCloseEventHandlers + // + ); + } + + // + void AddOnPartialClosePositionEventHandler(TOnPartialClose handler) + { + // + Add( + handler, + mOnPartialCloseEventHandlers + // + ); + } + + // + // Add New Deals Changed Event Handler ... + void AddOnTradeStateChangedEventHandler(TOnTradeStateChanged handler) + { + // + Add( + handler, + mTradeStateChangedEventHandlers + // + ); + } + + // + // Add New Deals Changed Event Handler ... + void AddOnDealsChangedEventHandler(TOnDealsChanged handler) + { + // + Add( + handler, + mDealsChangedEventHandlers + // + ); + } + + // + // Add New Orders Changed Event Handler ... + void AddOnOrdersChangedEventHandler(TOnOrdersChanged handler) + { + // + Add( + handler, + mOrdersChangedEventHandlers + // + ); + } + + // + // Add New Positions Changed Event Handler ... + void AddOnPositionsChangedEventHandler(TOnPositionsChanged handler) + { + // + Add( + handler, + mPositionsChangedEventHandlers + // + ); + } + + // + // Add New Stop Loss Event Handler ... + void AddOnStopLossEventHandler(TOnStopLoss handler) + { + // + Add( + handler, + mStopLossEventHandlers + // + ); + } + + // + // Add New Stop Loss Event Handler ... + void AddOnTakeProfitEventHandler(TOnTakeProfit handler) + { + // + Add( + handler, + mTakeProfitEventHandlers + // + ); + } + + // + // Functions ... + + // + // Handlers ... + + // + // Process On Trade Requirement ... + // this Only Used when we Have to Proccess OnTrade Event in EA(s) ... + void HandleOnTradeEvent( + XOnTradeHandlerState &result // Hold's Result + ) + { + // + result.Clean(); + + // + if (mScanStarted) + { + // + ProcessOnTradeContext(result); + } + else + { + // + // Init Trade Context ... + InitOnTradeContext(); + + // + return; + } + + // + // Here we Can Check the Start ... + bool isValid = + // + result.IsValid() && + // + !result.hasNewDeal && + !result.hasNewOrder && + !result.hasNewPosition && + !result.hasNewHistoryOrder + // + ; + if (!isValid) + { + return; + } + + // + // State ... + + // + // Notfy Trade State Changed Event ... + NotifyTradeStateChangeEvent(result); + + // + // Deals ... + if (result.hasNewDeal) + { + // + // Notfy Deals Changed Event ... + NotifyDealsChangeEvent(result.newDeals); + + // + // Retrieve Last Deal ... + XDeal deals[]; + int dealsCount = GetDeals(deals); + if (dealsCount > 0) + { + // + XDeal lastDeal = deals[0]; + + // + if (lastDeal.reason == DEAL_REASON_TP) + { + NotifyTakeProfitEvent(lastDeal); + } + else if (lastDeal.reason == DEAL_REASON_SL) + { + NotifyStopLossEvent(lastDeal); + } + } + } + + // + // Orders ... + if (result.hasNewOrder || result.hasNewHistoryOrder) + { + // + // Notfy Orders Changed Event ... + NotifyOrdersChangeEvent(result.newOrders + result.newHistoryOrders); + } + + // + // Positions ... + if (result.hasNewPosition) + { + // + // Notfy Positions Changed Event ... + NotifyPositionsChangeEvent(result.newPositions); + } + } + + // + // This Must be Called Every time OnTrade Event Happening ... + // this Used for Implementing Custom Senarios ... + XOnTradeHandlerState HandleOnTrade() + { + // + // Handle OnTrade Event ... + XOnTradeHandlerState state; + HandleOnTradeEvent(state); + if ( + !state.hasNewDeal && + !state.hasNewOrder && + !state.hasNewPosition && + !state.hasNewHistoryOrder) + { + return state; + } + + // + // State ... + + // + // Notfy Trade State Changed Event ... + NotifyTradeStateChangeEvent(state); + + // + // DEALS ... + if (state.hasNewDeal) + { + // + // Notfy Deals Changed Event ... + NotifyDealsChangeEvent(state.newDeals); + + // + // Retrieve Last Deal ... + XDeal deals[]; + GetDeals(deals); + int dealsCount = ArraySize(deals); + if (dealsCount > 0) + { + // + XDeal lastDeal = deals[0]; + + // + if (lastDeal.reason == DEAL_REASON_TP) + { + NotifyTakeProfitEvent(lastDeal); + } + else if (lastDeal.reason == DEAL_REASON_SL) + { + NotifyStopLossEvent(lastDeal); + } + } + } + + // + // ORDERS ... + if (state.hasNewOrder || state.hasNewHistoryOrder) + { + // + // Notfy Orders Changed Event ... + NotifyOrdersChangeEvent(state.newOrders + state.newHistoryOrders); + } + + // + // POSITIONS ... + if (state.hasNewPosition) + { + // + // Notfy Positions Changed Event ... + NotifyPositionsChangeEvent(state.newPositions); + } + + // + return state; + } + + // + // Trade Actions ... + + // + // Main ... + + // + // Policies ... + + // + // Check Acocunt Balance is Allow new Trades or not ... + bool CheckEquityForTrade() + { + // + bool result = false; + + // + if (mMaxAllowedDrawdownFactor <= 0) + { + // + result = true; + return result; + } + + // + double equity = mAccount.GetEquity(); + double balance = mAccount.GetBalance(); + + // + double selectedBalance = MathMax(equity, balance) - MathMin(equity, balance); + + // + double maxAllowedBalanceDrawDown = GetMaxAllowedEquity(); + + // + result = equity > balance || + (equity <= balance && + selectedBalance <= maxAllowedBalanceDrawDown); + + // + return result; + } + + // + // Check Max Allowed Positions Policy for Trade ... + bool CheckPositionsForTrade() + { + // + bool result = false; + + // + if (mMaxAllowedPositions <= 0) + { + // + result = true; + return result; + } + + // + XPosition positions[]; + int positionsCount = GetPositions(positions); + if (positionsCount <= 0) + { + // + result = true; + return result; + } + + // + result = positionsCount < mMaxAllowedPositions; + + // + return result; + } + + // + // Check Spread is Ok for Executing Specific Signal ... + bool CheckSpreadForSignalExecution(XSignal &mSignal) + { + // + bool result = false; + + // + bool isSpreadCheckEnable = mMaxAllowedSpread > 0; + if (!isSpreadCheckEnable) + { + result = true; + } + else + { + // + // Retrieve Signal Spread ... + double spread = mSignal.GetSpread(); + result = spread <= mMaxAllowedSpread; + } + + // + return result; + } + + // + // Check Account Policy ... + bool CheckAccountPolicy( + XSignal &mSignal, // For Executing Signal + ENUM_X_SIGNAL_EXECUTION_RESULT &state // State Holder + ) + { + // + bool result = false; + + // + // Check Positions For Trade ... + result = CheckPositionsForTrade(); + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_MAX_REACHED; + return result; + } + + // + // Check Equity For Trade ... + result = CheckEquityForTrade(); + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_NO_EQUITY; + return result; + } + + // + // Check Spread for Trade ... + result = CheckSpreadForSignalExecution(mSignal); + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_SPREAD; + return result; + } + + // + return result; + } + + // + // Execute a Signal ... + bool ExecuteSignal( + XSignal &mSignal, // Signal + ENUM_X_SIGNAL_EXECUTION_RESULT &state, // Result + ENUM_ORDER_TYPE_TIME lifetime = ORDER_TIME_GTC, // Order LifeTime + datetime expiration = NULL, // order expiration time + bool checkPolicies = true // Check Account Policies + ) + { + // + bool result = false; + state = X_SIGNAL_EXECUTION_UNKNOWN; + + // + double currentEntry = GetEntry( + mSignal.symbol, + mSignal.type + // + ); + bool isLong = IsLong(mSignal.type); + + // + if (!mSignal.IsValid()) + { + // + state = X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS; + return result; + } + + // + // Prepare Signal Comment ... + string mSComment = mSignal.GenerateComment(); + if (!Contains(mSComment, mSignal.comment)) + { + mSignal.comment += mSComment; + } + + // + // Handle Market Execution ... + if (mSignal.mode == X_ORDER_MODE_MARKET) + { + // + // Do Apply Policies here ... + bool hasPolicy = !checkPolicies + ? true + : CheckAccountPolicy(mSignal, state); + if (!hasPolicy) + { + result = false; + } + else + { + // + if (isLong) + { + // + result = Buy( + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, + mSignal.sl, + mSignal.tp, + mSignal.comment + // + ); + } + else + { + // + result = Sell( + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, + mSignal.sl, + mSignal.tp, + mSignal.comment + // + ); + } + } + } + // + // Handle Stop Execution ... + else if (mSignal.mode == X_ORDER_MODE_STOP) + { + + // + // Check Conditions ... + + // + // Check Price ... + result = isLong + ? mSignal.entry > currentEntry + : mSignal.entry < currentEntry; + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR; + return result; + } + + // + // Execute Order ... + if (isLong) + { + // + result = BuyStop( + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, + mSignal.sl, + mSignal.tp, + lifetime, + expiration, + mSignal.comment + // + ); + } + else + { + // + result = SellStop( + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, + mSignal.sl, + mSignal.tp, + lifetime, + expiration, + mSignal.comment + // + ); + } + } + // + // Handle Limit Execution ... + else if (mSignal.mode == X_ORDER_MODE_LIMIT) + { + // + // Check Conditions ... + + // + // Check Price ... + result = isLong + ? mSignal.entry < currentEntry + : mSignal.entry > currentEntry; + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR; + return result; + } + + // + // Execute Order ... + if (isLong) + { + // + result = BuyLimit( + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, + mSignal.sl, + mSignal.tp, + lifetime, + expiration, + mSignal.comment + // + ); + } + else + { + // + result = SellLimit( + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, + mSignal.sl, + mSignal.tp, + lifetime, + expiration, + mSignal.comment + // + ); + } + } + + // + // Handle Ticket ... + if (result) + { + // + state = X_SIGNAL_EXECUTION_SUCCEED; + + // + ulong ticket; + if (mSignal.mode == X_ORDER_MODE_MARKET) + { + ticket = GetLastOpenPositionTicket(); + } + else + { + ticket = GetLastPlacedOrderTicket(); + } + + // + mSignal.positionId = ticket; + + // + // Handle Store XPositionInfo ... + if (mSignal.mode == X_ORDER_MODE_MARKET) + { + // + // TODO: Implement this ... + } + + // + // Handle Executing Support Signals ... + int supportsCount = ArraySize(mSignal.supports); + if (supportsCount > 0) + { + // + int executed = 0; + for (int i = 0; i < supportsCount; i++) + { + // + XSignal iSupport = mSignal.supports[i]; + + // + int supIndex = i + 1; + string iComment = GenerateSupportTag(ticket); + iSupport.comment = iComment; + + // + bool isExecuted = ExecuteSignal( + iSupport, + state, + lifetime, + expiration + // + ); + if (isExecuted) + { + executed++; + } + } + + // + result = executed == supportsCount; + } + } + + // + return result; + } + + // + // Execute a Collection Of Signals ... + int ExecuteSignals( + XSignal &signals[], // Collection of Signal for Execution + ENUM_X_SIGNAL_EXECUTION_RESULT &states[], // Signal Execution Result + ENUM_ORDER_TYPE_TIME lifetime = ORDER_TIME_GTC, // Order LifeTime + datetime expiration = NULL, // order expiration time + bool checkPolicies = true // Check Account Policies + ) + { + // + int result = 0; + + // + Clean(states); + + // + int signalsCount = ArraySize(signals); + if (signalsCount <= 0) + { + return result; + } + + // + ArrayResize(states, signalsCount); + ArrayInitialize(states, X_SIGNAL_EXECUTION_UNKNOWN); + for (int i = 0; i < signalsCount; i++) + { + // + bool isExecuted = ExecuteSignal( + signals[i], + states[i], + lifetime, + expiration, + checkPolicies + // + ); + + // + if (isExecuted) + { + result++; + } + } + + // + return result; + } + + // + int ExecuteSpecifiedSignals( + XSignal &signals[], // Collection of Signal for Execution + XSignal ¬Executeds[], // Not Executed Signal + ENUM_X_SIGNAL_EXECUTION_RESULT &states[], // Signal Execution Result + ENUM_ORDER_TYPE_TIME lifetime = ORDER_TIME_GTC, // Order LifeTime + datetime expiration = NULL, // order expiration time + bool checkPolicies = true // Check Account Policies + ) + { + // + int result = 0; + + // + Clean(states); + Clean(notExecuteds); + + // + int signalsCount = ArraySize(signals); + if (signalsCount <= 0) + { + return result; + } + + // + ArrayResize(states, signalsCount); + ArrayInitialize(states, X_SIGNAL_EXECUTION_UNKNOWN); + for (int i = 0; i < signalsCount; i++) + { + // + bool isExecuted = ExecuteSignal( + signals[i], + states[i], + lifetime, + expiration + // + ); + + // + if (isExecuted) + { + result++; + } + else + { + // + AddRef( + signals[i], + notExecuteds // + ); + } + } + + // + return result; + } + + // + // Regular Trade Actions ... + + // + // Buy ... + + // + // Force Open a Buy/Long Position ... + bool Buy( + string symbol, // Specified Symbol + ENUM_TIMEFRAMES period, // Specified Trade's Period + double volume, // position volume + double price, // execution price + double sl = 0, // stop loss price + double tp = 0, // take profit price + string comment = NULL // comment + ) + { + // + bool result = false; + + // + ENUM_TIMEFRAMES mPeriod = ExtractPeriod(comment); + if (!IsValid(comment) || + !IsValid(mPeriod)) + { + // + string mPeriodStr = GeneratePeriodTag(period); + + // + comment += mPeriodStr; + } + + // + result = mTrader.Buy( + volume, + symbol, + price, + sl, + tp, + comment + // + ); + + // + return result; + } + + // + // Send BUY LIMIT order ... + bool BuyLimit( + string symbol, // Specified Symbol + ENUM_TIMEFRAMES period, // Specified Trade's Period + double volume, // order volume + double price, // order price + double sl = 0.0, // stop loss price + double tp = 0.0, // take profit price + ENUM_ORDER_TYPE_TIME typeTime = ORDER_TIME_GTC, // order lifetime + datetime expiration = 0, // order expiration time + string comment = NULL // comment + ) + { + // + bool result = false; + + // + ENUM_TIMEFRAMES mPeriod = ExtractPeriod(comment); + if (!IsValid(comment) || + !IsValid(mPeriod)) + { + // + string mPeriodStr = GeneratePeriodTag(period); + + // + comment += mPeriodStr; + } + + // + result = mTrader.BuyLimit( + volume, + price, + symbol, + sl, + tp, + typeTime, + expiration, + comment + // + ); + + // + return result; + } + + // + // Send BUY STOP order ... + bool BuyStop( + string symbol, // Specified Symbol + ENUM_TIMEFRAMES period, // Specified Trade's Period + double volume, // order volume + double price, // order price + double sl = 0.0, // stop loss price + double tp = 0.0, // take profit price + ENUM_ORDER_TYPE_TIME typeTime = ORDER_TIME_GTC, // order lifetime + datetime expiration = 0, // order expiration time + string comment = NULL // comment + ) + { + // + bool result = false; + + // + ENUM_TIMEFRAMES mPeriod = ExtractPeriod(comment); + if (!IsValid(comment) || + !IsValid(mPeriod)) + { + // + string mPeriodStr = GeneratePeriodTag(period); + + // + comment += mPeriodStr; + } + + // + result = mTrader.BuyStop( + volume, + price, + symbol, + sl, + tp, + typeTime, + expiration, + comment + // + ); + + // + return result; + } + + // + // Sell ... + + // + // Force Open a Sell/Short Position ... + bool Sell( + string symbol, // Specified Symbol + ENUM_TIMEFRAMES period, // Specified Trade's Period + double volume, // position volume + double price, // execution price + double sl = 0, // stop loss price + double tp = 0, // take profit price + string comment = NULL // comment + ) + { + // + bool result = false; + + // + ENUM_TIMEFRAMES mPeriod = ExtractPeriod(comment); + if (!IsValid(comment) || + !IsValid(mPeriod)) + { + // + string mPeriodStr = GeneratePeriodTag(period); + + // + comment += mPeriodStr; + } + + // + result = mTrader.Sell( + volume, + symbol, + price, + sl, + tp, + comment + // + ); + + // + return result; + } + + // + // Send SELL LIMIT order ... + bool SellLimit( + string symbol, // Specified Symbol + ENUM_TIMEFRAMES period, // Specified Trade's Period + double volume, // order volume + double price, // order price + double sl = 0.0, // stop loss price + double tp = 0.0, // take profit price + ENUM_ORDER_TYPE_TIME typeTime = ORDER_TIME_GTC, // order lifetime + datetime expiration = 0, // order expiration time + string comment = NULL // comment + ) + { + // + bool result = false; + + // + ENUM_TIMEFRAMES mPeriod = ExtractPeriod(comment); + if (!IsValid(comment) || + !IsValid(mPeriod)) + { + // + string mPeriodStr = GeneratePeriodTag(period); + + // + comment += mPeriodStr; + } + + // + result = mTrader.SellLimit( + volume, + price, + symbol, + sl, + tp, + typeTime, + expiration, + comment + // + ); + + // + return result; + } + + // + // Send SELL STOP order ... + bool SellStop( + string symbol, // Specified Symbol + ENUM_TIMEFRAMES period, // Specified Trade's Period + double volume, // order volume + double price, // order price + double sl = 0.0, // stop loss price + double tp = 0.0, // take profit price + ENUM_ORDER_TYPE_TIME typeTime = ORDER_TIME_GTC, // order lifetime + datetime expiration = 0, // order expiration time + string comment = NULL // comment + ) + { + // + bool result = false; + + // + ENUM_TIMEFRAMES mPeriod = ExtractPeriod(comment); + if (!IsValid(comment) || + !IsValid(mPeriod)) + { + // + string mPeriodStr = GeneratePeriodTag(period); + + // + comment += mPeriodStr; + } + + // + result = mTrader.SellStop( + volume, + price, + symbol, + sl, + tp, + typeTime, + expiration, + comment + // + ); + + // + return result; + } + + // + // Check a Position is Exists Open or not ... + bool IsOpen( + ulong ticket // Specified Position Ticket + ) + { + // + bool result = false; + + // + result = mPositionInfo + .SelectByTicket(ticket); + + // + return result; + } + + // + // Modify Position ... + bool Modify( + const ulong ticket, // position ticket + double sl = 0, // stop loss price + double tp = 0, // take profit + string comment = NULL // comment + ) + { + // + bool result = false; + + // + // Validate Args ... + XPosition position; + result = + GetPosition( + ticket, + position // + ) && + (tp >= 0 || sl >= 0); + if (!result) + { + return result; + } + + // + // Use Position Comment when there isn't new One ... + if (!IsValid(comment) == 0) + { + // + // if there isn't provided Comment + // Use Position Comment for default ... + comment = "Modify " + GetPositionComment(ticket); + } + + // + result = mTrader.PositionModify( + ticket, + sl, + tp, + comment + // + ); + if (result) + { + // + NotifyModifyEvent( + ticket, + position.profit, + comment // + ); + } + + // + return result; + } + + // + // Close Position By Ticket ... + bool Close( + ulong ticket, // Position Ticket + string comment = NULL // Close Position By Specific Comment + ) + { + // + bool result = false; + + // + // Check Position Open ... + XPosition position; + result = GetPosition( + ticket, + position // + ); + if (!result) + { + return result; + } + + // + // Use Default Position Comment if it's Not Provided ... + if (!IsValid(comment)) + { + comment = "Close " + GetPositionComment(ticket); + } + + // + // Close Position By Specific Comment ... + result = mTrader.PositionClose( + ticket, + mSlippage, + comment + // + ); + if (result) + { + // + NotifyForceCloseEvent( + ticket, + position, + comment // + ); + } + + // + return result; + } + + // + // Close Specified Positions ... + int Close( + string comment = NULL, // Close Position By Specific Comment + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) + bool filterByMagic = true // Get Only Self Open Positions + ) + { + // + int result = 0; + + // + XPosition positions[]; + int positionsCount = GetPositions( + positions, + symbol, + provider, + period, + type, + filterByMagic); + if (positionsCount <= 0) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + bool isClosed = Close( + iPosition.ticket, + comment + // + ); + if (isClosed) + { + result++; + } + } + + // + return result; + } + + // + // Close a Collection of Positions ... + int Close( + XPosition &positions[], // Collection of Positions + string comment // Close Comment + ) + { + // + int result = 0; + + // + int positionsCount = ArraySize(positions); + if (positionsCount <= 0) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + bool isClosed = Close( + iPosition.ticket, + comment + // + ); + if (isClosed) + { + result++; + } + } + + // + return result; + } + + // + // Close Partial By Ticket ... + bool ClosePartial( + ulong ticket, // Position Ticket + double volume, // Volume Size for Partial Closing + string comment = NULL // Close Position By Specific Comment + ) + { + // + bool result = false; + + // + XPosition position; + result = GetPosition( + ticket, + position // + ); + if (!result) + { + return result; + } + + // + // Use Default Partial Close Comment ... + if (!IsValid(comment)) + { + // + comment += "PClose " + GetPositionComment(ticket); + } + + // + result = mTrader.PositionClosePartial( + ticket, + volume, + mSlippage, + comment + // + ); + if (result) + { + // + NotifyPartialCloseEvent( + ticket, + position.profit, + comment // + ); + } + + // + return result; + } + + // + // Cancel Specific Order ... + bool CancelOrder(ulong ticket) + { + return mTrader + .OrderDelete(ticket); + } + + // + // Cancel Specific Orders ... + int CancelOrders( + XOrder &orders[] // Specified Orders ... + ) + { + // + int result = 0; + + // + int ordersCount = ArraySize(orders); + if (ordersCount <= 0) + { + return result; + } + + // + for (int i = 0; i < ordersCount; i++) + { + // + XOrder iOrder = orders[i]; + + // + bool isDeleted = mTrader + .OrderDelete(iOrder.ticket); + if (isDeleted && !result) + { + result++; + } + } + + // + return result; + } + + // + // Extractors ... + + // + // Positions ... + + // + // Calculate Positions Profit ... + double Profit( + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) + bool filterByMagic = true // Get Only Self Open Positions + ) + { + // + double result = 0; + + // + // Retrieve Positions ... + XPosition positions[]; + int positionsCount = GetPositions( + positions, + symbol, + provider, + period, + type, + filterByMagic + // + ); + if (positionsCount <= 0) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + result += positions[i].profit; + } + + // + return result; + } + + // + // Retrieve Specific Position by Index ... + bool GetPosition( + int index, // Specified Index + XPosition &result // Hold's Result + ) + { + // + return result + .ByIndex(index); + } + + // + // Retrieve Specific Position by Ticket ... + bool GetPosition( + ulong ticket, // Specified Ticket + XPosition &result // Hold's Result + ) + { + // + return result + .ByTicket(ticket); + } + + // + double GetPositionCommission( + ulong ticket // Specified Ticket + ) + { + // + double result = 0; + + // + XPosition position; + bool hasPosition = GetPosition( + ticket, + position // + ); + if (!hasPosition) + { + return result; + } + + // + XDeal deals[]; + int dealsCount = GetDeals( + deals, + position.symbol, + position.provider, + position.period, + NULL, + DEAL_ENTRY_IN // + ); + if (IsValidSize(dealsCount)) + { + // + for (int i = 0; i < dealsCount; i++) + { + // + XDeal iDeal = deals[i]; + if (iDeal.positionId == ticket) + { + // + result = iDeal.commission; + break; + } + } + } + + // + return result; + } + + // + // Retrieve Positions ... + int GetPositions( + XPosition &result[], // Hold's Result + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) + bool filterByMagic = true, // Get Only Self Open Positions + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + int before = ArraySize(result); + + // + if (forceClean) + { + Clean(result); + } + + // + // Count Positions ... + int itemsCount = PositionsTotal(); + if (itemsCount <= 0) + { + return mResult; + } + + // + // Loop Through all Positions ... + for (int i = itemsCount - 1; i >= 0; i--) + { + // + XPosition iItem; + bool isLoaded = iItem.ByIndex(i); + if (!isLoaded) + { + continue; + } + + // + // Now we have to Check Given Filters ... + bool isFiltersPassed = + iItem.IsFiltersPassed( + symbol, + provider, + period, + type, + mMagicNumber, + filterByMagic + // + ); + if (!isFiltersPassed) + { + continue; + } + + // + // Add Filtered Item into Result ... + AddRef( + iItem, + result + // + ); + } + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; + } + + // + void GetPositions( + XPosition &longs[], // Hold's Longs Result + XPosition &shorts[], // Hold's Shorts Result + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + bool filterByMagic = true, // Get Only Self Open Positions + bool forceClean = true // Clean Result Array + ) + { + // + // Retrieve Long Positions ... + GetPositions( + longs, + symbol, + provider, + period, + X_POSITION_TYPE_LONG, + filterByMagic, + forceClean // + ); + + // + // Retrieve Short Positions ... + GetPositions( + shorts, + symbol, + provider, + period, + X_POSITION_TYPE_SHORT, + filterByMagic, + forceClean // + ); + } + + // + // Select In Profit Positions ... + int GetInProfitPositions( + XPosition &result[], // Hold's Result + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_SELECT_METHODS method = NULL, // Selection Method + bool filterByMagic = true, // Get Only Self Open Positions + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + int before = ArraySize(result); + + // + if (forceClean) + { + Clean(result); + } + + // + XPosition positions[]; + int positionsCount = GetPositions( + positions, + symbol, + provider, + period, + type, + filterByMagic, + forceClean); + if (positionsCount <= 0) + { + return mResult; + } + + // + XPosition min; + XPosition max; + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (iPosition.profit <= 0) + { + continue; + } + + // + // Calculate Min and Max ... + + // + // Min ... + if (!min.IsValid() || min.profit <= 0 || min.profit > iPosition.profit) + { + min = iPosition; + } + + // + // Max ... + if (!max.IsValid() || max.profit <= 0 || max.profit < iPosition.profit) + { + max = iPosition; + } + + // + bool isSelectionMethodFilterPassed = + // + (method == NULL || + method == X_POSITION_SELECT_ALL) + ? true + : false; + // + ; + if (!isSelectionMethodFilterPassed) + { + continue; + } + + // + AddRef( + iPosition, + result + // + ); + } + + // + if (min.IsValid() && + (method == X_POSITION_SELECT_MIN || + method == X_POSITION_SELECT_BOTH)) + { + // + AddRef( + min, + result + // + ); + } + + // + if (max.IsValid() && + (method == X_POSITION_SELECT_MAX || + method == X_POSITION_SELECT_BOTH)) + { + // + AddRef( + max, + result + // + ); + } + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; + } + + // + // Select In Drawdown Positions ... + int GetInDrawdownPositions( + XPosition &result[], // Hold's Result + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) + ENUM_X_POSITION_SELECT_METHODS method = NULL, // Selection Method + bool filterByMagic = true, // Get Only Self Open Positions + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + int before = ArraySize(result); + + // + if (forceClean) + { + Clean(result); + } + + // + XPosition positions[]; + int positionsCount = GetPositions( + positions, + symbol, + provider, + period, + type, + filterByMagic, + forceClean); + if (positionsCount <= 0) + { + return mResult; + } + + // + XPosition min; + XPosition max; + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (iPosition.profit >= 0) + { + continue; + } + + // + // Calculate Min and Max ... + + // + // Min ... + if (!min.IsValid() || min.profit <= 0 || min.profit > iPosition.profit) + { + min = iPosition; + } + + // + // Max ... + if (!max.IsValid() || max.profit <= 0 || max.profit < iPosition.profit) + { + max = iPosition; + } + + // + bool isSelectionMethodFilterPassed = + // + (method == NULL || + method == X_POSITION_SELECT_ALL) + ? true + : false; + // + ; + if (!isSelectionMethodFilterPassed) + { + continue; + } + + // + AddRef( + iPosition, + result + // + ); + } + + // + if (min.IsValid() && + (method == X_POSITION_SELECT_MIN || + method == X_POSITION_SELECT_BOTH)) + { + // + AddRef( + min, + result + // + ); + } + + // + if (max.IsValid() && + (method == X_POSITION_SELECT_MAX || + method == X_POSITION_SELECT_BOTH)) + { + // + AddRef( + max, + result + // + ); + } + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; + } + + // + // Orders ... + + // + // Retrieve Specific Order by Index ... + bool GetOrder( + int index, // Specified Index + XOrder &result // Hold's Result + ) + { + // + return result + .ByIndex(index); + } + + // + // Retrieve Specific Positions Orders ... + int GetOrders( + ulong ticket, // Positions Ticket + XOrder &result[], // Hold's Result + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + // Select History by Specified Ticket ... + bool isHistorySelected = HistorySelectByPosition(ticket); + if (!isHistorySelected) + { + return mResult; + } + + // + int ordersCount = HistoryOrdersTotal(); + if (ordersCount <= 0) + { + return mResult; + } + + // + int before = ArraySize(result); + + // + if (forceClean) + { + Clean(result); + } + + // + for (int i = 0; i < ordersCount; i++) + { + // + XOrder iOrder; + bool isLoaded = iOrder.HistoryByIndex(i); + if (!isLoaded) + { + continue; + } + + // + bool isTicketFilterPassed = + // + iOrder.ticket = ticket + // + ; + if (!isTicketFilterPassed) + { + continue; + } + + // + AddRef( + iOrder, + result + // + ); + } + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; + } + + // + // Retrieve All Orders ... + int GetOrders( + XOrder &result[], // Hold's Result + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) + ENUM_ORDER_STATE state = NULL, // Order State + bool filterByMagic = true, // Get Only Self Open Positions + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + int before = ArraySize(result); + + // + if (forceClean) + { + Clean(result); + } + + // + // Count Positions ... + int itemsCount = OrdersTotal(); + if (itemsCount <= 0) + { + return mResult; + } + + // + // Loop Through all Positions ... + for (int i = itemsCount - 1; i >= 0; i--) + { + // + XOrder iItem; + bool isLoaded = iItem.ByIndex(i); + if (!isLoaded) + { + continue; + } + + // + // Now we have to Check Given Filters ... + bool isFiltersPassed = + iItem.IsFiltersPassed( + symbol, + provider, + period, + type, + state, + mMagicNumber, + filterByMagic + // + ); + if (!isFiltersPassed) + { + continue; + } + + // + // Add Filtered Item into Result ... + AddRef( + iItem, + result + // + ); + } + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; + } + + // + // Retrieve Historical Orders ... + int GetOrders( + XOrder &result[], // Hold's Result + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_X_POSITION_TYPES type = NULL, // Long (Buy) or Short (Sell) + ENUM_ORDER_STATE state = NULL, // Order State + datetime startDate = NULL, // Specify Start Date + datetime endDate = NULL, // Specify End Date + bool filterByMagic = true, // Get Only Self Open Positions + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + endDate = NormalizeTime(endDate); + + // + if (!IsValid(startDate)) + { + startDate = endDate - PeriodSeconds(PERIOD_D1); + } + + // + bool isHistorySelected = HistorySelect( + startDate, + endDate); + if (!isHistorySelected) + { + return mResult; + } + + // + int before = ArraySize(result); + + // + if (forceClean) + { + Clean(result); + } + + // + // Count Positions ... + int itemsCount = OrdersTotal(); + if (itemsCount <= 0) + { + return mResult; + } + + // + // Loop Through all Positions ... + for (int i = itemsCount - 1; i >= 0; i--) + { + // + XOrder iItem; + bool isLoaded = iItem.HistoryByIndex(i); + if (!isLoaded) + { + continue; + } + + // + // Now we have to Check Given Filters ... + bool isFiltersPassed = + iItem.IsFiltersPassed( + symbol, + provider, + period, + type, + state, + mMagicNumber, + filterByMagic + // + ); + if (!isFiltersPassed) + { + continue; + } + + // + // Add Filtered Item into Result ... + AddRef( + iItem, + result + // + ); + } + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; + } + + // + // Deals ... + + // + // Retrieve Specific Deal by Index ... + bool GetDeal( + int index, // Specified Index + XDeal &result // Hold's Result + ) + { + // + return result + .ByIndex(index); + } + + // + bool GetLastDeal( + XDeal &result // Hold's Result + ) + { + // + bool mResult = false; + + // + mResult = HistorySelect(0, TimeCurrent()); + if (!mResult) + { + return mResult; + } + + // + int lastDealIndex = HistoryDealsTotal() - 1; + + // + mResult = GetDeal( + lastDealIndex, + result // + ); + + // + return mResult; + } + + // + // Retrieve Specified Deal's History ... + int GetDealsHistory( + XDeal &deal, // Specified Deal + XOrder &history[], // Deals History + bool forceClean = true // Clean Result Array + ) + { + // + int result = 0; + + // + if (!deal.IsValid()) + { + return result; + } + + // + result = GetOrders( + deal.positionId, + history, + forceClean); + + // + return result; + } + + // + // Retrieve All Deals ... + int GetDeals( + XDeal &result[], // Hold's Result + string symbol = NULL, // Trading Symbol + string provider = NULL, // Signal Provider + ENUM_TIMEFRAMES period = NULL, // Trading Period + ENUM_DEAL_TYPE type = NULL, // Deal Type + ENUM_DEAL_ENTRY entry = NULL, // Deal Entry + ENUM_DEAL_REASON reason = NULL, // Deal Reason + datetime startDate = NULL, // Specify Start Date + datetime endDate = NULL, // Specify End Date + bool filterByMagic = true, // Get Only Self Open Positions + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + endDate = NormalizeTime(endDate); + + // + if (!IsValid(startDate)) + { + startDate = endDate - PeriodSeconds(PERIOD_D1); + } + + // + bool isHistorySelected = HistorySelect( + startDate, + endDate); + if (!isHistorySelected) + { + return mResult; + } + + // + int before = ArraySize(result); + + // + if (forceClean) + { + Clean(result); + } + + // + // Count Positions ... + int itemsCount = HistoryDealsTotal(); + if (itemsCount <= 0) + { + return mResult; + } + + // + // Loop Through all Positions ... + for (int i = itemsCount - 1; i >= 0; i--) + { + // + XDeal iItem; + bool isLoaded = iItem.ByIndex(i); + if (!isLoaded) + { + continue; + } + + // + // Now we have to Check Given Filters ... + bool isFiltersPassed = + iItem.IsFiltersPassed( + symbol, + provider, + period, + type, + entry, + reason, + mMagicNumber, + filterByMagic + // + ); + if (!isFiltersPassed) + { + continue; + } + + // + // Add Filtered Item into Result ... + AddRef( + iItem, + result + // + ); + } + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; + } + + // + // Support Functions ... + + // + // Check a Position has Support or not ... + bool HasSupport( + ulong ticket, + bool forceOpen = true // + ) + { + // + bool result = false; + + // + result = ticket > 0; + if (!result) + { + return result; + } + + // + if (forceOpen) + { + // + result = IsOpen(ticket); + if (!result) + { + return result; + } + } + + // + XPosition positions[]; + int positionsCount = GetPositions(positions); + result = IsValidSize(positionsCount); + if (!result) + { + return result; + } + + // + // Extract Support Positions ... + XPosition supports[]; + int supportsCount = ExtractSupports( + positions, + supports // + ); + result = IsValidSize(supportsCount); + if (!result) + { + return result; + } + + // + // Loop Through Supports ... + for (int i = 0; i < supportsCount; i++) + { + // + XPosition iSupport = supports[i]; + + // + ulong supportedTicket = ExtractSupportedTicket(iSupport.comment); + ulong eqmSupportedTicket = ExtractEQMSupportedTicket(iSupport.comment); + + // + result = + // + (supportedTicket > 0 && ticket == supportedTicket) + // + || + // + (eqmSupportedTicket > 0 && ticket == eqmSupportedTicket) + // + ; + if (result) + { + break; + } + } + + // + return result; + } + + // + // Retrieve Specific Position's Supports ... + int GetSupports( + ulong ticket, + XPosition &dest[], // Result ... + bool forceOpen = true // + ) + { + // + int result = 0; + + // + Clean(dest); + + // + bool hasSupport = HasSupport( + ticket, + forceOpen // + ); + if (!hasSupport) + { + return result; + } + + // + XPosition positions[]; + int positionsCount = GetPositions(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + // Extract Support Positions ... + XPosition supports[]; + int supportsCount = ExtractSupports( + positions, + supports // + ); + if (!IsValidSize(supportsCount)) + { + return result; + } + + // + // Loop Through Supports ... + for (int i = 0; i < supportsCount; i++) + { + // + XPosition iSupport = supports[i]; + + // + ulong supportedTicket = ExtractSupportedTicket(iSupport.comment); + ulong eqmSupportedTicket = ExtractEQMSupportedTicket(iSupport.comment); + + // + bool isOwn = + // + (supportedTicket > 0 && ticket == supportedTicket) + // + || + // + (eqmSupportedTicket > 0 && ticket == eqmSupportedTicket) + // + ; + if (isOwn) + { + // + AddRef( + iSupport, + dest // + ); + } + } + + // + result = ArraySize(dest); + + // + return result; + } + + // + // Retrieve Specific Position's Supports ... + int GetSupports( + ulong ticket, + XOrder &dest[], // Result ... + bool forceOpen = true // + ) + { + // + int result = 0; + + // + Clean(dest); + + // + bool hasSupport = HasSupport( + ticket, + forceOpen // + ); + if (!hasSupport) + { + return result; + } + + // + XOrder orders[]; + int ordersCount = GetOrders( + orders, + NULL, // All Symbols ... + NULL, // All Providers ... + NULL, // All Periods ... + X_POSITION_TYPE_ALL, // All Types ... + ORDER_STATE_PLACED, // Untriggere Orders ... + true // + ); + if (!IsValidSize(ordersCount)) + { + return result; + } + + // + // Extract Support Positions ... + XOrder supports[]; + int supportsCount = ExtractSupports( + orders, + supports // + ); + if (!IsValidSize(supportsCount)) + { + return result; + } + + // + // Loop Through Supports ... + for (int i = 0; i < supportsCount; i++) + { + // + XOrder iSupport = supports[i]; + + // + ulong supportedTicket = ExtractSupportedTicket(iSupport.comment); + ulong eqmSupportedTicket = ExtractEQMSupportedTicket(iSupport.comment); + + // + bool isOwn = + // + (supportedTicket > 0 && ticket == supportedTicket) + // + || + // + (eqmSupportedTicket > 0 && ticket == eqmSupportedTicket) + // + ; + if (isOwn) + { + // + AddRef( + iSupport, + dest // + ); + } + } + + // + result = ArraySize(dest); + + // + return result; + } + + // + // Tools ... + + // + // Retrieve Last Open Position Ticket ... + ulong GetLastOpenPositionTicket() + { + // + ulong result = 0; + + int positionsCount = PositionsTotal(); + if (positionsCount <= 0) + { + return result; + } + + // + result = PositionGetTicket(PositionsTotal() - 1); + + // + return result; + } + + // + // Retrieve Last Placed Order Ticket ... + ulong GetLastPlacedOrderTicket() + { + // + ulong result = 0; + + int ordersCount = OrdersTotal(); + if (ordersCount <= 0) + { + return result; + } + + // + if (mOrderInfo.SelectByIndex(ordersCount - 1)) + { + result = mOrderInfo.Ticket(); + } + + // + return result; + } + + // + // Prepare Dynamic Volume ... + double GetDynamicVolume( + string _symbol, + double _balanceFactor, + double _volumeStep // + ) + { + // + double result = 0; + + // + // Validate Inputs ... + if (!IsValid(_symbol) || + _volumeStep <= 0 || + _balanceFactor <= 0) + { + return result; + } + + // + // Retrieve Account Balance ... + double balance = mAccount.GetBalance(); + + // + double bStep = balance / _balanceFactor; + bStep = MathFloor(bStep); + if (bStep == 0) + { + bStep = 1; + } + + // + result = bStep * _volumeStep; + + // + result = NormalizeVolume( + result, + _symbol // + ); + + // + return result; + } + + // + // Protected ... +protected: + // + // Props ... + + // + // Event Listener Notifiers ... + + // + // State ... + void NotifyTradeStateChangeEvent(const XOnTradeHandlerState &state) + { + // + int count = ArraySize(mTradeStateChangedEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnTradeStateChanged iHandler = mTradeStateChangedEventHandlers[i]; + iHandler(state); + } + } + + // + // Deals ... + void NotifyDealsChangeEvent(int changes) + { + // + int count = ArraySize(mDealsChangedEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnDealsChanged iHandler = mDealsChangedEventHandlers[i]; + iHandler(changes); + } + } + + // + // Orders ... + void NotifyOrdersChangeEvent(int changes) + { + // + int count = ArraySize(mOrdersChangedEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnOrdersChanged iHandler = mOrdersChangedEventHandlers[i]; + iHandler(changes); + } + } + + // + // Positions ... + void NotifyPositionsChangeEvent(int changes) + { + // + int count = ArraySize(mPositionsChangedEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnPositionsChanged iHandler = mPositionsChangedEventHandlers[i]; + iHandler(changes); + } + } + + // + // StopLoss ... + void NotifyStopLossEvent(const XDeal &deal) + { + // + int count = ArraySize(mStopLossEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnStopLoss iHandler = mStopLossEventHandlers[i]; + iHandler(deal); + } + } + + // + // Take Profit ... + void NotifyTakeProfitEvent(const XDeal &deal) + { + // + int count = ArraySize(mTakeProfitEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnTakeProfit iHandler = mTakeProfitEventHandlers[i]; + iHandler(deal); + } + } + + // + void NotifyModifyEvent( + ulong ticket, + double profit, + string comment // + ) + { + // + int count = ArraySize(mOnModifyEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnModify iHandler = mOnModifyEventHandlers[i]; + iHandler( + ticket, + profit, + comment // + ); + } + } + + // + void NotifyForceCloseEvent( + ulong ticket, + XPosition &position, + string comment // + ) + { + // + int count = ArraySize(mOnForceCloseEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnForceClose iHandler = mOnForceCloseEventHandlers[i]; + iHandler( + ticket, + position, + comment // + ); + } + } + + // + void NotifyPartialCloseEvent( + ulong ticket, + double profit, + string comment // + ) + { + // + int count = ArraySize(mOnPartialCloseEventHandlers); + if (count <= 0) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TOnModify iHandler = mOnPartialCloseEventHandlers[i]; + iHandler( + ticket, + profit, + comment // + ); + } + } + + // + // Tools ... + + // + // Retrieve Specified Position Comment ... + string GetPositionComment(ulong ticket) + { + // + string result = NULL; + + // + if (!IsOpen(ticket)) + { + return result; + } + + // + XPosition position; + bool isLoaded = position.ByTicket(ticket); + if (!isLoaded) + { + return result; + } + + // + result = position.comment; + + // + return result; + } + + // + ENUM_TIMEFRAMES GetDealPeriod(XDeal &deal) + { + // + ENUM_TIMEFRAMES result = NULL; + + // + XOrder orders[]; + int ordersCount = GetDealsHistory( + deal, + orders); + if (!ordersCount) + { + return result; + } + + // + for (int i = 0; i < ordersCount; i++) + { + // + XOrder iOrder = orders[i]; + + // + if (IsValid(iOrder.comment)) + { + // + ENUM_TIMEFRAMES iPeriod = ExtractPeriod(iOrder.comment); + if (IsValid(iPeriod)) + { + result = iPeriod; + break; + } + } + } + + // + return result; + } + + // + double GetMaxAllowedEquity() + { + // + double equity = mAccount.GetEquity(); + double balance = mAccount.GetBalance(); + + // + double balanceForFactor = MathAbs(equity - balance); + if (balanceForFactor <= 0) + { + balanceForFactor = balance; + } + else + { + balanceForFactor = equity; + } + + // + double result = balanceForFactor * mMaxAllowedDrawdownFactor; + + // + return result; + } + + // + // Private ... +private: + // + // Props ... + + // + int mSlippage; // Slippage ... + ulong mMagicNumber; // Magic Number (Unique Identifier) ... + + // + double mMaxAllowedSpread; // Max Allowed Spred for Opening Trades + int mMaxAllowedPositions; // Max Allowed Same Positions + double mMaxAllowedDrawdownFactor; // Max Allowed Drawdown Factor + + // + XSCTradeBase *mTrader; // Base CTrade Manipulated Instance ... + + // + CDealInfo mDealInfo; // Deals Info ... + COrderInfo mOrderInfo; // Order Info ... + CPositionInfo mPositionInfo; // Positions Info + CHistoryOrderInfo mHistoryOrderInfo; // History Orders Info ... + + // + // Position Info Collector ... + + // + // Tools ... + + // + // OnTrade Event Handlers Section ... + + // + // Props ... + + // + int mDaysForRead; // Reading Dates for Trade History Checker ... + datetime mEndDate; // End Date for Trade history Checking ... + datetime mStartDate; // Start Date for Trade history Checking ... ... + int mOrdersCount; // Number of Active orders ... + int mPositionsCount; // Number of Open positions ... + int mDealsCount; // Number of Deals in the Trade History Checking ... + int mHistoryOrdersCount; // Number of Orders in the Trade History Checking ... + bool mScanStarted; // a Flag of counter relevance ... + + // + // Event Listeners ... + + // + // Deals Changed Event Handlers ... + TOnDealsChanged mDealsChangedEventHandlers[]; + + // + // Orders Changed Event Handlers ... + TOnOrdersChanged mOrdersChangedEventHandlers[]; + + // + // Positions Changed Event Handlers ... + TOnPositionsChanged mPositionsChangedEventHandlers[]; + + // + // Trade State Changed Event Handlers ... + TOnTradeStateChanged mTradeStateChangedEventHandlers[]; + + // + TOnModify mOnModifyEventHandlers[]; + TOnForceClose mOnForceCloseEventHandlers[]; + TOnPartialClose mOnPartialCloseEventHandlers[]; + + // + // TPSL ... + TOnStopLoss mStopLossEventHandlers[]; + TOnTakeProfit mTakeProfitEventHandlers[]; + + // + // Reset On Trade Scanner Context ... + void ResetOnTradeContext() + { + // + mEndDate = TimeCurrent(); + mStartDate = mEndDate - (mDaysForRead * PeriodSeconds(PERIOD_D1)); + } + + // + // Initial Context Of Trade Scanner ... + void InitOnTradeContext() + { + // + ResetLastError(); + + // + mOrdersCount = OrdersTotal(); + mPositionsCount = PositionsTotal(); + + // + // load history ... + bool selected = HistorySelect(mStartDate, mEndDate); + if (!selected) + { + return; + } + + // + // get the current value ... + mDealsCount = HistoryDealsTotal(); + mHistoryOrdersCount = HistoryOrdersTotal(); + + // + mScanStarted = true; + } + + // + // Check Statrt Date In Trade History ... + void CheckStartDateInTradeHistory() + { + // + // initial interval, if we were to start working right now .. + datetime currStart = TimeCurrent() - (mDaysForRead * PeriodSeconds(PERIOD_D1)); + + // + // make sure that the start limit of the trade history has not gone + // more than 1 day over the intended date ... + if (currStart - mStartDate > PeriodSeconds(PERIOD_D1)) + { + // + // correct the start date of history to be loaded in the cache ... + mStartDate = currStart; + + // + // now reload the trade history for the updated interval ... + HistorySelect(mStartDate, mEndDate); + + // + // correct the deal and order counters in history for further comparison + mHistoryOrdersCount = HistoryOrdersTotal(); + mDealsCount = HistoryDealsTotal(); + } + } + + // + // Process On Trade Context ... + void ProcessOnTradeContext( + XOnTradeHandlerState &result // Hold's Result + ) + { + // + mEndDate = TimeCurrent(); + + // + ResetLastError(); + + // + // download trading history from the specified interval to the program cache ... + bool selected = HistorySelect(mStartDate, mEndDate); + if (!selected) + { + return; + } + + // + // get the current values ... + int currOrders = OrdersTotal(); + int currPositions = PositionsTotal(); + int currDeals = HistoryDealsTotal(); + int currHistoryOrders = HistoryOrdersTotal(); + + // + // Orders ... + // check if the number of active orders has been changed ... + if (currOrders != mOrdersCount) + { + // + // number of active orders has been changed ... + result.hasNewOrder = true; + result.newOrders = currOrders - mOrdersCount; + + // + // update the value ... + mOrdersCount = currOrders; + } + + // + // Positions ... + // changes in the number of open positions ... + if (currPositions != mPositionsCount) + { + // + // number of open positions has been changed ... + result.hasNewPosition = true; + result.newPositions = currPositions - mPositionsCount; + + // + // update the value ... + mPositionsCount = currPositions; + } + + // + // Deals ... + // changes in the number of deals in the trade history cache ... + if (currDeals != mDealsCount) + { + // + // number of deals in the trade history cache has been changed ... + result.hasNewDeal = true; + result.newDeals = currDeals - mDealsCount; + + // + // update the value ... + mDealsCount = currDeals; + } + + // + // History Orders ... + // changes in the number of history orders in the trade history cache ... + if (currHistoryOrders != mHistoryOrdersCount) + { + // + // number of history orders in the trade history cache has been changed ... + result.hasNewHistoryOrder = true; + result.newHistoryOrders = currHistoryOrders - mHistoryOrdersCount; + + // + // update the value ... + mHistoryOrdersCount = currHistoryOrders; + } + + // + // checking if it is necessary to change the limits of the trade history to be requested in cache ... + CheckStartDateInTradeHistory(); + } +}; + +// +// a Class For Read and Write Trade Info Data in Files ... +class XTradeCollector +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor(s) ... + void XTradeCollector( + string _path = NULL // Base Path + ) + { + // + mAccount = new XSCAccount(); + + // + if (IsValid(_path)) + { + mPath = _path; + } + else + { + mPath = "XTradeData" + "\\" + mAccount.GetCompany(); + } + } + + // + // Deconstructor ... + void ~XTradeCollector() {} + + // + bool IsExists(XTradeData &item) + { + // + bool result = false; + + // + int mHandler = GetFileHandlerForRead(item); + result = mHandler != INVALID_HANDLE; + FileClose(mHandler); + + // + return result; + } + + // + bool Save(XTradeData &item) + { + // + bool result = false; + + // + // Check info is Valid ... + result = item.IsValid(); + if (!result) + { + return result; + } + + // + string content = item.ToString(); + content += "\n" + "-----------" + "\n" + "Signal: " + "\n" + "-----------" + "\n" + item.ToString(true); + + // + result = IsValid(content); + if (!result) + { + return result; + } + + // + int mHandler = GetFileHandlerForWrite(item); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + FileWrite(mHandler, content); + FileFlush(mHandler); + FileClose(mHandler); + + // + return result; + } + + // + bool SaveSignal(XTradeData &item) + { + // + bool result = false; + + // + string content = item.ToString(true); + result = IsValid(content); + if (!result) + { + return result; + } + + // + int mHandler = GetSignalFileHandlerForWrite(item); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + FileWrite(mHandler, content); + FileFlush(mHandler); + FileClose(mHandler); + + // + return result; + } + + // + // Conditions only save for Loss Signals ... + // this means the profit must be Lower than Zero ... + // ans also message Contains SL ... + bool SaveConditions(XTradeData &item) + { + // + bool result = false; + + // + // Validate Item ... + result = + // + item.profit < 0 && + Contains("SL", item.message) + // + ; + if (!result) + { + return result; + } + + // + string content = item.signal.conditions; + result = IsValid(content); + if (!result) + { + return result; + } + + // + int mHandler = GetConditionsFileHandlerForWrite(item); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + FileSeek(mHandler, 0, SEEK_END); + FileWrite(mHandler, content); + FileFlush(mHandler); + FileClose(mHandler); + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + + // + string mPath; // Base Path ... + + // + XSCAccount *mAccount; + + // + string GetFilePath(XTradeData &item) + { + // + string fileName = item.GetFileName(); + + // + return GetFilePath(fileName); + } + string GetFilePath(string fileName) + { + // + string result = ""; + + // + result = + // + mPath + "\\" + "Trades" + "\\" + fileName + ".x121.log" + // + ; + + // + return result; + } + + // + string GetSignalFilePath(XTradeData &item) + { + // + string fileName = item.GetSignalFileName(); + + // + return GetSignalFilePath(fileName); + } + string GetSignalFilePath(string fileName) + { + // + string result = ""; + + // + result = + // + mPath + "\\" + "Signals" + "\\" + fileName + ".x121.log" + // + ; + + // + return result; + } + + // + string GetConditionsFilePath(XTradeData &item) + { + // + bool isLong = IsLong(item.type); + + // + string fileName = + item.symbol + "\\" + + (isLong + ? "Longs" + : "Shorts"); + + // + return GetConditionsFilePath(fileName); + } + string GetConditionsFilePath(string fileName) + { + // + string result = ""; + + // + result = + // + mPath + "\\" + "Conditions" + "\\" + fileName + ".x121.log" + // + ; + + // + return result; + } + + // + int GetFileHandlerForRead(XTradeData &item) + { + // + int result = INVALID_HANDLE; + + // + string filePath = GetFilePath(item); + if (!IsValid(filePath)) + { + return result; + } + + // + result = FileOpen( + filePath, + FILE_READ | FILE_TXT // + ); + + // + return result; + } + int GetFileHandlerForWrite(XTradeData &item) + { + // + int result = INVALID_HANDLE; + + // + string filePath = GetFilePath(item); + if (!IsValid(filePath)) + { + return result; + } + + // + result = FileOpen( + filePath, + FILE_READ | FILE_WRITE | FILE_TXT // + ); + + // + return result; + } + + // + int GetSignalFileHandlerForRead(XTradeData &item) + { + // + int result = INVALID_HANDLE; + + // + string filePath = GetSignalFilePath(item); + if (!IsValid(filePath)) + { + return result; + } + + // + result = FileOpen( + filePath, + FILE_READ | FILE_TXT // + ); + + // + return result; + } + int GetSignalFileHandlerForWrite(XTradeData &item) + { + // + int result = INVALID_HANDLE; + + // + string filePath = GetSignalFilePath(item); + if (!IsValid(filePath)) + { + return result; + } + + // + result = FileOpen( + filePath, + FILE_READ | FILE_WRITE | FILE_TXT // + ); + + // + return result; + } + + // + int GetConditionsFileHandlerForRead(XTradeData &item) + { + // + int result = INVALID_HANDLE; + + // + string filePath = GetConditionsFilePath(item); + if (!IsValid(filePath)) + { + return result; + } + + // + result = FileOpen( + filePath, + FILE_READ | FILE_TXT // + ); + + // + return result; + } + int GetConditionsFileHandlerForWrite(XTradeData &item) + { + // + int result = INVALID_HANDLE; + + // + string filePath = GetConditionsFilePath(item); + if (!IsValid(filePath)) + { + return result; + } + + // + result = FileOpen( + filePath, + FILE_READ | FILE_WRITE | FILE_TXT // + ); + + // + return result; + } +}; + +// +// Trade Handler Class ... +class XSCXTradeHandler : public XSCBaseAlert +{ + // + // Public ... +public: + // + + // + // Constructor(s) ... + void XSCXTradeHandler(XSCTrade *trader) + { + // + mTrader = trader; + mCollector = new XTradeCollector(); + } + + // + // Deconstructor ... + void ~XSCXTradeHandler() + { + // + delete mTrader; + delete mCollector; + } + + // + // Getter(s) / Setter(s) ... + + // + bool SaveSignals() + { + return mSaveSignals; + } + + // + void SaveSignals(bool value) + { + mSaveSignals = value; + } + + // + bool SaveTrades() + { + return mSaveTrades; + } + + // + void SaveTrades(bool value) + { + mSaveTrades = value; + } + + // + bool SaveConditions() + { + return mSaveConditions; + } + + // + void SaveConditions(bool value) + { + mSaveConditions = value; + } + + // + int MaxSameTimeTrades() + { + return maxSameTimeTrades; + } + + // + bool AllowLong() + { + return mAllowLong; + } + + // + void AllowLong(bool value) + { + mAllowLong = value; + } + + // + bool AllowShort() + { + return mAllowShort; + } + + // + void AllowShort(bool value) + { + mAllowShort = value; + } + + // + int MaxAllowedLongs() + { + return mMaxAllowedLongs; + } + + // + void MaxAllowedLongs(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxAllowedLongs = value; + } + + // + int MaxAllowedShorts() + { + return mMaxAllowedShorts; + } + + // + void MaxAllowedShorts(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxAllowedShorts = value; + } + + // + bool UseMaxAllowedTradesPerSymbol() + { + return mUseMaxAllowedTradesPerSymbol; + } + + // + void UseMaxAllowedTradesPerSymbol(bool value) + { + mUseMaxAllowedTradesPerSymbol = value; + } + + // + double MaxDrawdownPercentForOpenTrades() + { + return mMaxDrawdownPercentForOpenTrades; + } + + // + void MaxDrawdownPercentForOpenTrades(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxDrawdownPercentForOpenTrades = value; + } + + // + // Trailling ... + + // + bool AllowTrailStops() + { + return mAllowTrailStops; + } + + // + void AllowTrailStops(bool value) + { + mAllowTrailStops = value; + } + + // + bool IgnoreTPOnTrail() + { + return mIgnoreTPOnTrail; + } + + // + void IgnoreTPOnTrail(bool value) + { + mIgnoreTPOnTrail = value; + } + + // + double TrailStartInPoint() + { + return mTrailStartInPoint; + } + + // + void TrailStartInPoint(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mTrailStartInPoint = value; + } + + // + double TrailStepInPoint() + { + return mTrailStepInPoint; + } + + // + void TrailStepInPoint(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mTrailStepInPoint = value; + } + + // + bool TrailBasedOnProfit() + { + return mTrailBasedOnProfit; + } + + // + void TrailBasedOnProfit(bool value) + { + mTrailBasedOnProfit = value; + } + + // + // Recovery ... + + // + bool AllowRecover() + { + return mAllowRecover; + } + + // + void AllowRecover(bool value) + { + mAllowRecover = value; + } + + // + double RecoveryTPPoint() + { + return mRecoveryTPPoint; + } + + // + void RecoveryTPPoint(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mRecoveryTPPoint = value; + } + + // + double RecoverySLPoint() + { + return mRecoverySLPoint; + } + + // + void RecoverySLPoint(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mRecoverySLPoint = value; + } + + // + int MaxAllowedRecover() + { + return mMaxAllowedRecover; + } + + // + void MaxAllowedRecover(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxAllowedRecover = value; + } + + // + double MaxAllowedRecoveryVolume() + { + return mMaxAllowedRecoveryVolume; + } + + // + void MaxAllowedRecoveryVolume(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxAllowedRecoveryVolume = value; + } + + // + double RecoveryVolumeMultiplier() + { + return mRecoveryVolumeMultiplier; + } + + // + void RecoveryVolumeMultiplier(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mRecoveryVolumeMultiplier = value; + } + + // + bool ForcePressuresInRecovery() + { + return mForcePressuresInRecovery; + } + + // + void ForcePressuresInRecovery(bool value) + { + mForcePressuresInRecovery = value; + } + + // + // Hedging ... + + // + bool AllowHedging() + { + return mAllowHedging; + } + + // + void AllowHedging(bool value) + { + mAllowHedging = value; + } + + // + double HedgeVolumeFactor() + { + return mHedgeVolumeFactor; + } + + // + void HedgeVolumeFactor(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mHedgeVolumeFactor = value; + } + + // + int MinTradesForHedge() + { + return mMinTradesForHedge; + } + + // + void MinTradesForHedge(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMinTradesForHedge = value; + } + + // + double HedgeMinProfitPerVolumeFactor() + { + return mHedgeMinProfitPerVolumeFactor; + } + + // + void HedgeMinProfitPerVolumeFactor(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mHedgeMinProfitPerVolumeFactor = value; + } + + // + // Position Protecting ... + + // + bool AllowProtectPositions() + { + return mAllowProtectPositions; + } + + // + void AllowProtectPositions(bool value) + { + mAllowProtectPositions = value; + } + + // + // Tools ... + + // + // Calculate Max Drawdown and it's Percent ... + double GetMaxDrawdown() + { + // + XPosition positions[]; + int positionsCount = mTrader.GetPositions(positions); + if (IsValidSize(positionsCount)) + { + double mEquity = mTrader.mAccount.GetEquity(); + if (mEquity > maxDrawdown) + { + maxDrawdown = mEquity; + } + + // + drawdownPercent = (maxDrawdown - mEquity) / (staticBalanceForCalculateDrawdown > 0 ? staticBalanceForCalculateDrawdown : maxDrawdown) * 100; + drawdownPercent = NormalizeDouble(drawdownPercent, 3); + } + else + { + // + maxDrawdown = 0.0; + drawdownPercent = 0.0; + } + + // + return drawdownPercent; + } + + // + // Trade Handling Functions ... + + // + // First Step of Trade Handling ... + // Since Must Call when a Signal Executed ... + void AddData( + XSignal &signal, // Executed Signal + double commission = 0, // Commission + bool forceTrail = false, // Force Signal Trailling Stop + bool forceRecover = false // Force Signal Recovery + ) + { + // + // Check Signal Valid ... + if (!signal.IsValid()) + { + return; + } + + // + // Check Signal Support or Recovery ... + bool isSupport = IsSupport(signal.comment); + bool isRecovery = ExtractRecoveredTicket(signal.comment) > 0; + + // + XTradeData item; + bool isFilled = item.Fill(signal); + if (!isFilled) + { + return; + } + + // + item.commission = commission; + + // + // Trailling Configuration ... + + // + // Force Trail used to implement Trailing for + // Custom Positions ... + if (mAllowTrailStops || forceTrail) + { + // + if (!isSupport && !isRecovery) + { + item.allowTrailStop = true; + } + + // + item.ignoreTPOnTrail = mIgnoreTPOnTrail; + item.trailStepInPoint = mTrailStepInPoint; + item.trailStartInPoint = mTrailStartInPoint; + item.trailBasedOnProfit = mTrailBasedOnProfit; + } + + // + // Recovery Configuration ... + + // + // Force Recovery used to implement Recovery for + // Custom Positions ... + if (mAllowRecover || forceRecover) + { + // + if (!isSupport && !isRecovery) + { + item.allowRecover = true; + } + + // + item.recoveryTPPoint = mRecoveryTPPoint; + item.recoverySLPoint = mRecoverySLPoint; + item.maxAllowedRecover = mMaxAllowedRecover; + item.recoveryVolumeMultiplier = mRecoveryVolumeMultiplier; + + // + ENUM_POSITION_TYPE _type; + bool isConverted = ToPositionType( + _type, + item.type // + ); + if (isConverted) + { + item.recoveryLookingType = GetOppositPositionType(_type); + } + } + + // + Add(item); + + // + SaveSignal(item); + } + + // + void Finish(const XDeal &deal) + { + // + int idx = -1; + bool hasItem = HasItem( + deal.positionId, + idx // + ); + if (!hasItem) + { + return; + } + + // + // Update Item Info ... + mData[idx].swap = deal.swap; + mData[idx].endTime = deal.time; + mData[idx].profit = deal.profit; + + // + mData[idx].message = + deal.reason == DEAL_REASON_TP + ? "TP" + : "SL"; + + // + Save(idx); + } + + // + void Finish( + const ulong ticket, + const XPosition &position, + const string comment // + ) + { + // + int idx = -1; + bool hasItem = HasItem( + ticket, + idx // + ); + if (!hasItem) + { + return; + } + + // + // Update Item Info ... + mData[idx].swap = position.swap; + mData[idx].endTime = TimeCurrent(); + mData[idx].profit = position.profit; + + // + mData[idx].message = comment; + + // + Save(idx); + } + + // + // this Method call's by a Timer, + // or in OnTick for Update Positions, + // Data ... + void UpdateData() + { + // + XPosition positions[]; + int count = mTrader.GetPositions(positions); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = positions[i]; + + // + int idx = -1; + bool isExists = HasItem( + iPosition.ticket, + idx // + ); + if (!isExists) + { + // + // Add New Data ... + + // + // Find Executed Signal Deal History ... + XDeal deals[]; + double commission = 0; + int dealsCount = mTrader.GetDeals( + deals, + iPosition.symbol, + iPosition.provider, + iPosition.period, + NULL, + DEAL_ENTRY_IN // + ); + if (IsValidSize(dealsCount)) + { + // + for (int i = 0; i < dealsCount; i++) + { + // + XDeal iDeal = deals[i]; + if (iDeal.positionId == iPosition.ticket) + { + // + commission = iDeal.commission; + break; + } + } + } + + // + XTradeData iData; + iData.Fill( + iPosition // + ); + + // + iData.ticket = iPosition.ticket; + + // + Add(iData); + } + else + { + // + // Update Exists ... + mData[idx].Update(iPosition); + } + } + + // + count = Count(); + if (count > maxSameTimeTrades) + { + maxSameTimeTrades = count; + } + + // + GetMaxDrawdown(); + } + + // + void UpdateSignal(XSignal &signal) + { + // + if (!signal.IsValid()) + { + return; + } + + // + int count = Count(); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isOwn = mData[i].IsOwn( + signal.symbol, + signal.provider, + signal.period, + ToPositionType(signal.type) // + ); + if (isOwn) + { + mData[i].Fill(signal); + } + } + } + + // + void RemoveSignal(XSignal &signal) + { + // + if (!signal.IsValid()) + { + return; + } + + // + int signalIDX = -1; + ENUM_X_POSITION_TYPES xType = ToPositionType(signal.type); + bool hasSignal = HasItem( + signal.symbol, + signal.provider, + signal.period, + xType, + signalIDX // + ); + if (!hasSignal || !IsValidIndex(signalIDX)) + { + return; + } + + // + // Remove Item From List ... + ArrayRemove( + mData, + signalIDX, + 1 // + ); + } + + // + // Do all Protections ... + void HandleProtection() + { + // + int count = Count(); + if (!IsValidSize(count)) + { + return; + } + + // + // Do Hedging ... + if (mAllowHedging) + { + // + // Retrieve Positions ... + XPosition positions[]; + int positionsCount = mTrader.GetPositions( + positions // + ); + + // + bool isParamsValid = + mHedgeVolumeFactor > 0 && + mHedgeMinProfitPerVolumeFactor > 0; + + // + bool isCountValid = mMinTradesForHedge <= 0 + ? positionsCount >= 1 + : positionsCount >= mMinTradesForHedge; + + // + // Validate State ... + if (isParamsValid && isCountValid) + { + // + double swaps = 0; + double profits = 0; + double volumes = 0; + double commissions = 0; + double requiredProfitsForHedge = 0; + CalculateHedgeData( + positions, + swaps, + profits, + volumes, + commissions, + requiredProfitsForHedge // + ); + + // + bool canHedge = profits >= requiredProfitsForHedge; + if (canHedge) + { + // + string comment = "Hedging ..."; + + // + if (IsValidSize(positionsCount)) + { + // + int closeds = mTrader.Close( + positions, + comment // + ); + if (IsValidSize(closeds)) + { + // + string msg = ToString(positionsCount) + " Closed Due Hedge Action in: " + ToString(profits) + " ..."; + Alert(msg); + + // + return; + } + } + } + } + } + + // + // Do Force Closing ... + + // + // Loop through Data ... + for (int i = 0; i < count; i++) + { + // + ulong ticket = mData[i].ticket; + double profit = mData[i].profit; + double volume = mData[i].volume; + string symbol = mData[i].symbol; + string provider = mData[i].provider; + bool isLong = IsLong(mData[i].type); + ENUM_TIMEFRAMES period = mData[i].period; + double points = GetPoints(mData[i].symbol); + bool ignoreTPOnTrail = mData[i].ignoreTPOnTrail; + double recoveryTPPoint = mData[i].recoveryTPPoint; + double recoverySLPoint = mData[i].recoverySLPoint; + int maxAllowedRecover = mData[i].maxAllowedRecover; + double trailStepInPoints = mData[i].trailStepInPoint; + double trailStartInPoint = mData[i].trailStartInPoint; + bool trailBasedOnProfit = mData[i].trailBasedOnProfit; + double recoveryVolumeMultiplier = mData[i].recoveryVolumeMultiplier; + + // + XPosition iPosition; + bool hasPosition = mTrader.GetPosition( + ticket, + iPosition // + ); + if (!hasPosition) + { + continue; + } + + // + // Allow Trail Only for Positions Which + // doesnt Have Any Support ... + bool iHasSupport = mTrader.HasSupport( + ticket // + ); + if (iHasSupport) + { + continue; + } + + // + // Try to Detect Recovered Positions ... + + // + XPosition positions[]; + XPosition recoveries[]; + int recoveriesCount = 0; + int positionsCount = mTrader.GetPositions( + positions, + symbol, + provider, + period // + ); + if (positionsCount > 0) + { + // + recoveriesCount = ExtractRecoveries( + ticket, + positions, + recoveries // + ); + } + + // + // Handle Recovery Break Event if Hedging is Disabled ... + if (mData[i].allowRecover) + { + // + if (mData[i].recoveryLevel <= 0) + { + // + if (profit > 0 && iPosition.tp == 0) + { + // + double proftiInPoints = profit / volume; + bool canClose = proftiInPoints >= recoveryTPPoint; + if (canClose) + { + // + string comment = "Recovery TP ..."; + bool isClosed = mTrader.Close( + ticket, + comment // + ); + if (isClosed) + { + // + string msg = "Position (" + ToString(ticket) + ") Hit's Recovery TP ..."; + Alert(msg); + break; + } + } + } + } + else + { + // + if (recoveriesCount > 0 && !mAllowHedging) + { + // + XPosition mustClose[]; + AddRef( + iPosition, + mustClose // + ); + + // + // Summary Calculations ... + double rVolume = volume; + double rProfit = profit; + bool hasMaxVolume = false; + double rSwap = mData[i].swap; + double rCommission = mData[i].commission; + for (int j = 0; j < recoveriesCount; j++) + { + // + rSwap += recoveries[j].swap; + rProfit += recoveries[j].profit; + rVolume += recoveries[j].volume; + rCommission += mTrader.GetPositionCommission(recoveries[j].ticket); + + // + if (!hasMaxVolume && + mMaxAllowedRecoveryVolume > 0 && + recoveries[j].volume >= mMaxAllowedRecoveryVolume) + { + hasMaxVolume = true; + } + + // + AddRef( + recoveries[j], + mustClose // + ); + } + double profitSummary = + rProfit + (-1 * rSwap) - MathAbs(rCommission); + + // + double requiredProfitPoints = recoveriesCount * recoveryTPPoint; + // if (mData[i].recoveryLevel >= 2) + // { + // // + // requiredProfitPoints /= mData[i].recoveryLevel; + // if (requiredProfitPoints < recoveryTPPoint) + // { + // requiredProfitPoints = recoveryTPPoint; + // } + // } + + // + if (profitSummary > 0) + { + // + double rProfitInPoints = profitSummary / volume; + + // + bool canFinishRecovery = rProfitInPoints >= requiredProfitPoints; + if (canFinishRecovery) + { + // + // Here we Have to close All Recoveries + // and Position it Self ... + + // + string comment = "Recovery Done ..."; + + // + int closeds = mTrader.Close( + mustClose, + comment // + ); + if (closeds > 0) + { + // + string msg = "EQM Done Recovery (" + ToString(closeds) + ") Positions ..."; + Alert(msg); + + // + break; + } + } + } + + // + Clean(mustClose); + Clean(positions); + Clean(recoveries); + } + } + } + + // + // Retriece CIndex Bar ... + XOHCL cBar; + bool isBarInited = cBar.Init( + symbol, + period, + 1 // + ); + if (!isBarInited) + { + continue; + } + + // + // For Trend ... + XOHCL tmpHSW[]; + XOHCL tmpLSW[]; + + // + // Detect Bullish/Bearish Patterns and Trends ... + + // + // Bullish ... + bool hasBullishPower = cBar.HasBullishPower(); + bool hasBullishPattern = HasBullishPattern(cBar); + bool hasBullishPressure = cBar.HasBullishPressure(); + bool isBullishTrend = cBar.HasBullishTrend( + tmpHSW, + tmpLSW, + true // + ); + bool hasBullishSigns = + // + // isBullishTrend && + cBar.IsBullish() && + hasBullishPattern && + (hasBullishPower && + hasBullishPressure) + // + ; + + // + // Bearish ... + bool hasBearishPower = cBar.HasBearishPower(); + bool hasBearishPattern = HasBearishPattern(cBar); + bool hasBearishPressure = cBar.HasBearishPressure(); + bool isBearishTrend = cBar.HasBearishTrend( + tmpHSW, + tmpLSW, + true // + ); + bool hasBearishSigns = + // + // isBearishTrend && + cBar.IsBearish() && + hasBearishPressure && + (hasBearishPower && + hasBearishPattern) + // + ; + + // + // Trail ... + if (mData[i].allowTrailStop) + { + // + // Do Trail ... + + // + // Only Can Trail if Position In Profit ... + if (profit > 0) + { + // + // Current Profit ... + double profitInPoints = (profit / volume); + + // + // Check Trailling Method ... + if (trailBasedOnProfit) + { + // + // if Trailling Method is Based on Profits Growing + // these Values must Greater than 0 ... + if (trailStartInPoint > 0 && trailStepInPoints > 0) + { + // + double requiredProfit = trailStartInPoint + (mData[i].trailLevel * trailStepInPoints); + bool isProfitPassed = profitInPoints >= requiredProfit; + if (isProfitPassed) + { + // + // Calculate new Level SL ... + double sl = + isLong + ? iPosition.entry + (mData[i].trailLevel * (trailStepInPoints * points)) + : iPosition.entry - (mData[i].trailLevel * (trailStepInPoints * points)); + sl = NormalizePrice( + sl, + symbol // + ); + + // + // Calculate TP ... + double tp = + ignoreTPOnTrail + ? 0 + : iPosition.tp; + + // + if (sl != iPosition.sl) + { + // + bool isModified = mTrader.Modify( + ticket, + sl, + tp // + ); + if (isModified) + { + // + // Increase Trail Level ... + mData[i].trailLevel++; + + // + string msg = "Position (" + ToString(ticket) + ") Stops in Level: " + ToString(mData[i].trailLevel) + " Trailed Successfully ..."; + Alert(msg); + } + } + } + } + } + else + { + // + // Handle Trailling Based On Bars ... + + // + bool canTrail = true; + if (trailStartInPoint > 0) + { + // + // Check Profit ... + canTrail = profitInPoints >= trailStartInPoint; + } + + // + if (canTrail) + { + // + // Zero Index Bar ... + XOHCL zBar; + bool isInited = zBar.Init( + symbol, + period, + 0 // + ); + if (isInited) + { + // + // Get Previous Bar ... + XOHCL cBar; + isInited = zBar.GetPreviousBar(cBar); + if (isInited) + { + // + // Get Prev of Previous Bar ... + XOHCL pBar; + isInited = cBar.GetPreviousBar(pBar); + if (isInited) + { + // + // Here we have to Check Bar Closes for + // Trailling Stops ... + canTrail = + // + isLong + ? cBar.IsBullish() && + cBar.close > pBar.open + : cBar.IsBearish() && + cBar.close < pBar.open + // + ; + if (canTrail) + { + // + // Calculate new Level SL ... + double sl = + isLong + ? cBar.low + : cBar.high; + sl = NormalizePrice( + sl, + symbol // + ); + + // + // Calculate TP ... + double tp = + ignoreTPOnTrail + ? 0 + : iPosition.tp; + + // + if (sl != iPosition.sl) + { + // + bool isModified = mTrader.Modify( + ticket, + sl, + tp // + ); + if (isModified) + { + // + // Increase Trail Level ... + mData[i].trailLevel++; + + // + string msg = "Position (" + ToString(ticket) + ") Stops in Level: " + ToString(mData[i].trailLevel) + " Trailed Successfully ..."; + Alert(msg); + } + } + } + } + } + } + } + } + } + } + + // + // Recovery ... + if (mData[i].allowRecover) + { + // + // Do Recovery ... + + // + // Check Looking for Direction ... + ENUM_X_POSITION_TYPES recoveryLookingType = mData[i].recoveryLookingType; + if (recoveryLookingType == X_POSITION_TYPE_ALL || + recoveryLookingType == X_POSITION_TYPE_NONE) + { + continue; + } + + // + bool isDirectional = recoveryLookingType == mData[i].type; + + // + bool hasPressure = + !mForcePressuresInRecovery + ? true + : isDirectional + // + // Looking For Directional Pressure ... + ? isLong + ? hasBullishSigns + : hasBearishSigns + // + // Looking For InDirectional Pressure ... + : isLong + ? hasBearishSigns + : hasBullishSigns; + + // + // Check Required Properties Validation ... + if ( + recoveryTPPoint > 0 && + recoverySLPoint > 0 && + (maxAllowedRecover <= 0 + ? true + : mData[i].recoveryLevel < maxAllowedRecover)) + { + // + // Calculate requirements ... + double distanceInPoints = (MathAbs(profit) / volume); + // double _volumeMultiplier = ((mData[i].recoveryLevel + 1) * recoveryVolumeMultiplier); + // double _volume = + // volume * (_volumeMultiplier <= 0 ? 1 : _volumeMultiplier); + double _volume = + mData[i].recoveryVolume <= 0 + ? volume * recoveryVolumeMultiplier + : mData[i].recoveryVolume; + if (mMaxAllowedRecoveryVolume > 0 && _volume > mMaxAllowedRecoveryVolume) + { + _volume = mMaxAllowedRecoveryVolume; + } + + // + string _comment = GenerateRecoveryTag(ticket); + + // + XSignal rSignal; + bool isPrepared = false; + + // + if (profit < 0 && + hasPressure && + !isDirectional && + distanceInPoints >= recoverySLPoint) + { + // + FixRecoveredPositionTPSL(iPosition); + + // + ENUM_POSITION_TYPE _type = + isLong + ? POSITION_TYPE_SELL + : POSITION_TYPE_BUY; + double _entry = GetEntry(symbol, _type); + + // + isPrepared = rSignal.Prepare( + symbol, + provider, + period, + _type, + X_ORDER_MODE_MARKET, + _entry, + _volume, + 0, + 0 // + ); + } + else if (profit >= 0 && + hasPressure && + isDirectional) + { + // + FixRecoveredPositionTPSL(iPosition); + + // + ENUM_POSITION_TYPE _type = + isLong + ? POSITION_TYPE_BUY + : POSITION_TYPE_SELL; + double _entry = GetEntry(symbol, _type); + + // + isPrepared = rSignal.Prepare( + symbol, + provider, + period, + _type, + X_ORDER_MODE_MARKET, + _entry, + _volume, + 0, + 0 // + ); + } + + // + if (isPrepared && rSignal.IsValid()) + { + // + // Attach Recovery Tag ... + rSignal.comment = _comment; + + // + // Execute Recovery Signal ... + bool isExecuted = ExecuteRecoverySignal(rSignal); + if (isExecuted) + { + // + // Increase Recovery Level ... + mData[i].recoveryLevel++; + mData[i].recoveryVolume = _volume * recoveryVolumeMultiplier; + + // + // Try to Reverse Looking for Next Recovery + // Position Type ... + ENUM_POSITION_TYPE _type; + bool isConverted = ToPositionType( + _type, + recoveryLookingType // + ); + if (isConverted) + { + mData[i].recoveryLookingType = GetOppositPositionType(_type); + } + } + } + } + } + } + } + + // + // Do Position Protecting ... + void HandlePositionProtecting() + { + // + if (!mAllowProtectPositions) + { + return; + } + + // + XPosition mainPositions[]; + + // + XPosition positions[]; + int positionsCount = mTrader.GetPositions( + positions, + NULL, // All Symbols ... + NULL, // All Providers ... + NULL, // All Periods ... + NULL, // All Types ... + true // Filter By Magic ... + ); + if (!IsValidSize(positions)) + { + return; + } + + // + // Filter Main Positions ... + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + if (!iPosition.IsValid()) + { + continue; + } + + // + // Check Support or Recovery ... + bool isSupport = IsSupport(iPosition.comment); + bool isRecovery = ExtractRecoveredTicket(iPosition.comment) > 0; + if (isSupport || isRecovery) + { + continue; + } + + // + AddRef( + iPosition, + mainPositions // + ); + } + + // + int mainPositionsCount = ArraySize(mainPositions); + if (!IsValidSize(mainPositionsCount)) + { + return; + } + + // + // Loop Through Main Positions ... + for (int i = 0; i < mainPositionsCount; i++) + { + // + XPosition iPosition = mainPositions[i]; + if (!iPosition.IsValid()) + { + continue; + } + + // + // Find iPosition Related TradeData ... + int idx = -1; + bool hasItem = HasItem( + iPosition.ticket, + idx // + ); + if (!hasItem) + { + continue; + } + + // + XTradeData iData = mData[idx]; + if (!iData.IsValid()) + { + continue; + } + + // + // Now we Have a Main Positions and + // we Make Sure this Position has a TradeData Model ... + // Next things is Extract it's Support Positions ... + XPosition supports[]; + for (int j = 0; j < positionsCount; j++) + { + // + XPosition jPosition = positions[j]; + + // + bool isSupport = IsSupport(jPosition.comment); + if (!isSupport) + { + continue; + } + + // + ulong parentTicket = ExtractSupportedTicket(jPosition.comment); + if (parentTicket != iPosition.ticket) + { + continue; + } + + // + AddRef( + jPosition, + supports // + ); + } + + // + int supportsCount = ArraySize(supports); + + // + // Collect Main Position Related Data ... + + // + // Hold a Position and All of it's Supports ... + XPosition iPack[]; + + // + // Fill Pack ... + AddRef( + iPosition, + iPack // + ); + + // + if (IsValidSize(supportsCount)) + { + // + Copy( + supports, + iPack // + ); + } + + // + int iPackCount = ArraySize(iPack); + if (!IsValidSize(iPackCount)) + { + continue; + } + + // + double volume = 0; + double profit = 0; + double commission = 0; + + // + // Calculate Required Datas ... + for (int j = 0; j < iPackCount; j++) + { + // + XPosition jPosition = iPack[j]; + if (!jPosition.IsValid()) + { + continue; + } + + // + XPosition uPosition; + bool hasPosition = mTrader.GetPosition( + jPosition.ticket, + uPosition // + ); + if (!hasPosition) + { + continue; + } + + // + volume += uPosition.volume; + profit += uPosition.profit; + + // + double jCommission = mTrader.GetPositionCommission(jPosition.ticket); + commission += jCommission; + } + + // + // here we have to Check Protection Conditions ... + + // + // Check Position State ... + bool isInProfit = profit > 0; + + // + // Based On Single Position ... + if (iPackCount == 1) + { + // + // Based on Profit ... + if (isInProfit) + { + } + // + // Based On DrawDown ... + else + { + } + } + // + // Multiple Protected Positions ... + else + { + // + // Based on Profit ... + if (isInProfit) + { + } + // + // Based On DrawDown ... + else + { + } + } + } + } + + // + // Validate Signal For Execution ... + bool CanExecute(XSignal &signal) + { + // + bool result = false; + + // + // Validate Signal ... + result = signal.IsValid(); + if (!result) + { + return result; + } + + // + // TODO: + // Here we can apply Same type or Opposit Type + // Signals behaviour ... + // also check For Market Open ... + + // + // Check Market ... + // TODO: Fix this ... + // result = mSymbolSession.CanTrade(signal.symbol); + // if (!result) { + // return result; + // } + + // + return result; + } + + // + bool ExecuteSignal( + XSignal &signal, // Signal for Execution + ENUM_X_SIGNAL_EXECUTION_RESULT &state, // Execution State + bool ignorePolicies = false // Ignore Execution Policies + ) + { + // + bool result = false; + + // + // Check Signal Validation ... + result = signal.IsValid(); + if (!result) + { + return result; + } + + // + // Filter Signals if Necessary ... + result = CanExecute(signal); + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS; + return result; + } + + // + // Check Policies ... + if (!ignorePolicies) + { + // + bool isLong = IsLong(signal.type); + + // + // Check Allow Trade Type ... + result = + isLong + ? mAllowLong + : mAllowShort; + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED; + return result; + } + + // + // Check Trades Count ... + if (mMaxAllowedLongs > 0 || mMaxAllowedShorts > 0) + { + // + XPosition longs[]; + XPosition shorts[]; + + // + // Counting Positions ... + if (mUseMaxAllowedTradesPerSymbol) + { + // + mTrader.GetPositions( + longs, + shorts, + signal.symbol // + ); + } + else + { + // + mTrader.GetPositions( + longs, + shorts, + NULL // All Symbols ... + ); + } + + // + int longsCount = ArraySize(longs); + int shortsCount = ArraySize(shorts); + + // + result = + // + // Long ... + isLong + ? mMaxAllowedLongs <= 0 + ? true + : longsCount < mMaxAllowedLongs + // + // Short ... + : mMaxAllowedShorts <= 0 + ? true + : shortsCount < mMaxAllowedShorts + // + ; + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_MAX_REACHED; + return result; + } + } + + // + // Check Drawdown ... + if (mMaxDrawdownPercentForOpenTrades > 0) + { + // + drawdownPercent = GetMaxDrawdown(); + + // + result = + drawdownPercent <= 0 + ? true + : drawdownPercent < mMaxDrawdownPercentForOpenTrades; + if (!result) + { + // + state = X_SIGNAL_EXECUTION_FAILED_NO_EQUITY; + return result; + } + } + } + + // + // Execute Signal ... + result = mTrader.ExecuteSignal( + signal, + state // + ); + if (result) + { + // + double commission = mTrader.GetPositionCommission(signal.positionId); + + // + // Add Signal to Trade Handler ... + AddData( + signal, + commission // + ); + + // + string msg = (signal.type == POSITION_TYPE_BUY ? "Long" : "Short") + + " Signal Provided by: " + signal.provider + + (signal.pushers > 1 ? " Pushers: " + ToString(signal.pushers) : "") + + " on: " + signal.symbol + + " in: " + ToString(signal.period) + + " Executed Successfully ..."; + Alert(msg); + } + + // + return result; + } + + // + // Protected ... +protected: + // + // Props ... + + // + bool mSaveSignals; // Save Signals + bool mSaveTrades; // Save Trades + bool mSaveConditions; // Save SL Conditions + + // + XSymbolSessionParser mSymbolSession; // Check Symbol Session + + // + bool mAllowLong; // Allow Long/Buy Trade Type + bool mAllowShort; // Allow Short/Sell Trade Type + int mMaxAllowedLongs; // Max Allowe Long/Buy Trades + int mMaxAllowedShorts; // Max Allowe Short/Sell Trades + bool mUseMaxAllowedTradesPerSymbol; // Use Max Allowed Trades Per Symbol + double mMaxDrawdownPercentForOpenTrades; // Max Drawdown Percent for Open Trades + + // + XSCTrade *mTrader; // Instance of Trader Class + XTradeCollector *mCollector; // Instance of Trade Collector Class + + // + // Trailling ... + bool mAllowTrailStops; // Trail All Trades Stops + bool mIgnoreTPOnTrail; // Ignore SL Trailed TP + bool mTrailBasedOnProfit; // Do Trail Based on Profit Points + double mTrailStartInPoint; // Trail Starts in Points of Profit + double mTrailStepInPoint; // Profit Must Grows Point to do Trailling + + // + // Recovery ... + bool mAllowRecover; // Allow Signal Recovery + int mMaxAllowedRecover; // Max Allowed Recovery + double mRecoveryTPPoint; // Recovery TP in Points + double mRecoverySLPoint; // Recovery SL in Points + bool mForcePressuresInRecovery; // Use Direction Pressures In Recovery + double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier + double mMaxAllowedRecoveryVolume; // Max Allowed Recovery Volume + + // + // Hedging ... + bool mAllowHedging; // Hedge Trades + int mMinTradesForHedge; // Minimum Open Trades for Do Hedge + double mHedgeVolumeFactor; // Hedging Volume Factor + double mHedgeMinProfitPerVolumeFactor; // Hedging Min Required Profit Per Volume Factor + + // + // Position Protecting ... + + // + bool mAllowProtectPositions; // Allow Protect Positions + + // + XTradeData mData[]; // Hold Trade Data + + // + // Private ... +private: + // + // Props ... + int maxSameTimeTrades; // Max Same Time Trades + double maxDrawdown; // Max Drawdown + double drawdownPercent; // Drawdown Percent + double staticBalanceForCalculateDrawdown; // Static Balance for Max Drawdown Calculation + + // + // Count Data ... + int Count() + { + return ArraySize(mData); + } + + // + // Add Item ... + bool Add(XTradeData &item) + { + // + bool result = false; + + // + result = item.IsValid(); + if (!result) + { + return result; + } + + // + int index = -1; + if (item.ticket > 0) + { + // + result = !HasItem( + item.ticket, + index // + ); + } + else + { + // + result = !HasItem( + item.symbol, + item.provider, + item.period, + item.type, + index // + ); + } + if (!result || IsValidIndex(index)) + { + // + result = false; + return result; + } + + // + AddRef( + item, + mData // + ); + + // + return result; + } + + // + // Find Item Index ... + bool HasItem( + ulong ticket, + int &index // + ) + { + // + bool result = false; + + // + index = -1; + + // + int count = Count(); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + result = mData[i].IsOwn(ticket); + if (result) + { + // + index = i; + break; + } + } + + // + return result; + } + + // + // Find Item Index ... + bool HasItem( + string symbol, + string provider, + ENUM_TIMEFRAMES period, + ENUM_X_POSITION_TYPES type, + int &index // + ) + { + // + bool result = false; + + // + index = -1; + + // + // Validate ... + result = + // + IsValid(symbol) && + IsValid(period) && + IsValid(provider) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE + // + ; + if (!result) + { + return result; + } + + // + int count = Count(); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + result = mData[i].IsOwn( + symbol, + provider, + period, + type // + ); + if (result) + { + // + index = i; + break; + } + } + + // + return result; + } + + // + void Save(int index) + { + // + int count = Count(); + if (!IsValidIndex(index) || index > count - 1) + { + return; + } + + // + // Save Trade ... + if (mSaveTrades) + { + mCollector.Save(mData[index]); + } + + // + if (mSaveConditions) + { + mCollector.SaveConditions(mData[index]); + } + + // + // Remove Item From List ... + ArrayRemove( + mData, + index, + 1 // + ); + } + + // + void SaveSignal(XTradeData &item) + { + // + if (!mSaveSignals) + { + return; + } + + // + // Save Signal ... + mCollector.SaveSignal(item); + } + + // + // Calculate Required Data for Hedging ... + void CalculateHedgeData( + double &profits, + double &commissions, + double &requiredProfitsForHedge // + ) + { + // + // Reset Values ... + profits = 0; + commissions = 0; + requiredProfitsForHedge = 0; + + // + // Validate Configurations ... + if (mHedgeVolumeFactor <= 0 || + mHedgeMinProfitPerVolumeFactor <= 0) + { + return; + } + + // + // Check Positions Exists For Hedging ... + int count = Count(); + if (!IsValidSize(count)) + { + return; + } + + // + double swaps = 0; + double volumes = 0; + for (int i = 0; i < count; i++) + { + // + swaps += mData[i].swap; + profits += mData[i].profit; + volumes += mData[i].volume; + commissions += mData[i].commission; + } + + // + // Calculate required Profits for Hedging ... + requiredProfitsForHedge = ((volumes / mHedgeVolumeFactor) * mHedgeMinProfitPerVolumeFactor); + requiredProfitsForHedge += -1 * (swaps); + requiredProfitsForHedge -= commissions; + } + + // + // Calculate Required Data for Hedging ... + void CalculateHedgeData( + XPosition &positions[], + double &swaps, + double &profits, + double &volumes, + double &commissions, + double &requiredProfitsForHedge // + ) + { + // + // Reset Values ... + swaps = 0; + profits = 0; + volumes = 0; + commissions = 0; + requiredProfitsForHedge = 0; + + // + // Validate Configurations ... + if (mHedgeVolumeFactor <= 0 || + mHedgeMinProfitPerVolumeFactor <= 0) + { + return; + } + + // + // Check Positions Exists For Hedging ... + int count = ArraySize(positions); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = positions[i]; + double iCommission = mTrader.GetPositionCommission(iPosition.ticket); + + // + swaps += iPosition.swap; + profits += iPosition.profit; + volumes += iPosition.volume; + commissions += MathAbs(iCommission); + } + + // + // Calculate required Profits for Hedging ... + requiredProfitsForHedge = ((volumes / mHedgeVolumeFactor) * mHedgeMinProfitPerVolumeFactor); + requiredProfitsForHedge += commissions; + requiredProfitsForHedge += -1 * (swaps); + } + + // + bool FixRecoveredPositionTPSL(XPosition &position) + { + // + bool result = false; + + // + result = position.IsValid(); + if (!result) + { + return result; + } + + // + double points = GetPoints(position.symbol); + + // // + // // Try to Remove SL and TP of Recovery Signals ... + // if (position.sl > 0 || position.tp > 0) + // { + // // + // string comment = "EQM Recover Remove TP/SL"; + // result = mTrader.Modify( + // position.ticket, + // 0, + // 0, + // comment // + // ); + // } + + // + // Try to Remove TP of Recovery Signals ... + if (position.tp > 0) + { + // + double tp = 0; + bool isLong = IsLong(position.type); + double reward = MathAbs(position.tp - position.entry) / points; + if (reward <= mRecoveryTPPoint) + { + // + reward = (mRecoveryTPPoint * 2 * points); + tp = + isLong + ? position.entry + reward + : position.entry - reward; + tp = NormalizePrice(tp, position.symbol); + } + + // + string comment = "EQM Recover Fix TP/SL"; + result = mTrader.Modify( + position.ticket, + position.sl, + tp, + comment // + ); + } + + // + return result; + } + + // + bool ExecuteRecoverySignal(XSignal &signal) + { + // + bool result = false; + + // + ENUM_X_SIGNAL_EXECUTION_RESULT state; + result = mTrader.ExecuteSignal( + signal, + state, + ORDER_TIME_GTC, + NULL, + false // + ); + + // + return result; + } + + // +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Classes/x-saherelm.zone.class.mq5 b/Documents/BKP/14030802-X121/Classes/x-saherelm.zone.class.mq5 new file mode 100644 index 00000000..5951af81 --- /dev/null +++ b/Documents/BKP/14030802-X121/Classes/x-saherelm.zone.class.mq5 @@ -0,0 +1,79 @@ +/////////////////////////////////////////////////////// +// +// 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 +#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: +}; diff --git a/Experts/x-saherelm.x121.ea.mq5 b/Documents/BKP/14030802-X121/Experts/x-saherelm.x121.ea.mq5 similarity index 100% rename from Experts/x-saherelm.x121.ea.mq5 rename to Documents/BKP/14030802-X121/Experts/x-saherelm.x121.ea.mq5 diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xcc.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xcc.helper.mq5 new file mode 100644 index 00000000..98bec867 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xcc.helper.mq5 @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCCHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +// Input Models ... +struct XCCInputs +{ + // + // Props ... + + // + // Chart Style ... + ENUM_CHART_MODE mode; // Mode + color upColor; // Up Color + color downColor; // Down Color + color lineColor; // Line mode and Doji candlestick Color + color bearishColor; // Bullish Color + color bullishColor; // Bearish Color + color volumesColor; // Volumes Color + + // + // Presentation ... + bool showCandles; // Show Candles + + // + // Constructor(s) ... + XCCInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + mode = CHART_CANDLES; + + // + upColor = CLR_NONE; + downColor = CLR_NONE; + lineColor = CLR_NONE; + bearishColor = CLR_NONE; + bullishColor = CLR_NONE; + volumesColor = CLR_NONE; + + // + showCandles = false; + } + + // + // Default ... + void Default() + { + // + mode = CHART_CANDLES; + + // + upColor = clrLime; + downColor = clrRed; + lineColor = clrLime; + bearishColor = clrRed; + bullishColor = clrLime; + volumesColor = clrGreen; + // + showCandles = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + true + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(0, 0); + + // + return result; + } +}; + +// +// Class ... +class XSCXCCHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCCHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCCInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xcc", + // + // Inputs ... + // + // Chart Style ... + "", + mInputs.mode, // Mode + mInputs.upColor, // Up Color + mInputs.downColor, // Down Color + mInputs.lineColor, // Line mode and Doji candlestick Color + mInputs.bearishColor, // Bullish Color + mInputs.bullishColor, // Bearish Color + mInputs.volumesColor, // Volumes Color + // + // Presentation ... + "", + mInputs.showCandles // Show Candles + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCCInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCCInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCCInputs mInputs; // Inputs ... +}; + +// +// Tools ... \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchche.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchche.helper.mq5 new file mode 100644 index 00000000..7ab733af --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchche.helper.mq5 @@ -0,0 +1,4743 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHCHEHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHCHE_BUFFERS +{ + // + // Current ... + XCHCHE_CLE1_LINE = 0, + XCHCHE_CSE1_LINE = 1, + XCHCHE_CLE2_LINE = 2, + XCHCHE_CSE2_LINE = 3, + // + // Short ... + XCHCHE_SLE1_LINE = 4, + XCHCHE_SSE1_LINE = 5, + XCHCHE_SLE2_LINE = 6, + XCHCHE_SSE2_LINE = 7, + // + // Medium ... + XCHCHE_MLE1_LINE = 8, + XCHCHE_MSE1_LINE = 9, + XCHCHE_MLE2_LINE = 10, + XCHCHE_MSE2_LINE = 11, + // + // Long ... + XCHCHE_LLE1_LINE = 12, + XCHCHE_LSE1_LINE = 13, + XCHCHE_LLE2_LINE = 14, + XCHCHE_LSE2_LINE = 15, + // + // Hind ... + XCHCHE_HLE1_LINE = 16, + XCHCHE_HSE1_LINE = 17, + XCHCHE_HLE2_LINE = 18, + XCHCHE_HSE2_LINE = 19, +}; + +// +// Input Models ... +struct XCHCHEInputs +{ + // + // Props ... + + // + // Market ... + int length; // Length + int loopback; // Loopback + double multiplier1; // 1st Multiplier + double multiplier2; // 2nd Multiplier + + // + // Calculation ... + ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to + ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + + // + bool showLE1; // Show Long Exit 1 + bool showLE2; // Show Long Exit 2 + bool showSE1; // Show Short Exit 1 + bool showSE2; // Show Short Exit 2 + + // + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHCHEInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + length = 0; + loopback = 0; + multiplier1 = 0; + multiplier2 = 0; + + // + upAppliedTo = PRICE_HIGH; + downAppliedTo = PRICE_LOW; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showLE1 = false; + showLE2 = false; + showSE1 = false; + showSE2 = false; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + length = 35; + loopback = 26; + multiplier1 = 3.0; + multiplier2 = 3.5; + + // + upAppliedTo = PRICE_HIGH; + downAppliedTo = PRICE_LOW; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showLE1 = true; + showLE2 = true; + showSE1 = true; + showSE2 = true; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length >= 2 && + loopback >= 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(0, length) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHCHEConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cLE1[]; + double cLE2[]; + double cSE1[]; + double cSE2[]; + + // + // Short ... + double sLE1[]; + double sLE2[]; + double sSE1[]; + double sSE2[]; + + // + // Medium ... + double mLE1[]; + double mLE2[]; + double mSE1[]; + double mSE2[]; + + // + // Long ... + double lLE1[]; + double lLE2[]; + double lSE1[]; + double lSE2[]; + + // + // Hind ... + double hLE1[]; + double hLE2[]; + double hSE1[]; + double hSE2[]; + + // + // Conditions ... + + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + + // + // Current ... + bool isCBullish; + bool isCBearish; + bool isCStrongBullish; + bool isCStrongBearish; + bool isCSwitchedToBullish; + bool isCSwitchedToBearish; + bool isCStrongSwitchedToBullish; + bool isCStrongSwitchedToBearish; + + // + // Short ... + bool isSBullish; + bool isSBearish; + bool isSStrongBullish; + bool isSStrongBearish; + bool isSSwitchedToBullish; + bool isSSwitchedToBearish; + bool isSStrongSwitchedToBullish; + bool isSStrongSwitchedToBearish; + + // + // Medium ... + bool isMBullish; + bool isMBearish; + bool isMStrongBullish; + bool isMStrongBearish; + bool isMSwitchedToBullish; + bool isMSwitchedToBearish; + bool isMStrongSwitchedToBullish; + bool isMStrongSwitchedToBearish; + + // + // Long ... + bool isLBullish; + bool isLBearish; + bool isLStrongBullish; + bool isLStrongBearish; + bool isLSwitchedToBullish; + bool isLSwitchedToBearish; + bool isLStrongSwitchedToBullish; + bool isLStrongSwitchedToBearish; + + // + // Hind ... + bool isHBullish; + bool isHBearish; + bool isHStrongBullish; + bool isHStrongBearish; + bool isHSwitchedToBullish; + bool isHSwitchedToBearish; + bool isHStrongSwitchedToBullish; + bool isHStrongSwitchedToBearish; + + // + void Clean() + { + // + Clean(cLE1); + Clean(cLE2); + Clean(cSE1); + Clean(cSE2); + Clean(sLE1); + Clean(sLE2); + Clean(sSE1); + Clean(sSE2); + Clean(mLE1); + Clean(mLE2); + Clean(mSE1); + Clean(mSE2); + Clean(lLE1); + Clean(lLE2); + Clean(lSE1); + Clean(lSE2); + Clean(hLE1); + Clean(hLE2); + Clean(hSE1); + Clean(hSE2); + + // + ArraySetAsSeries(cLE1, true); + ArraySetAsSeries(cLE2, true); + ArraySetAsSeries(cSE1, true); + ArraySetAsSeries(cSE2, true); + ArraySetAsSeries(sLE1, true); + ArraySetAsSeries(sLE2, true); + ArraySetAsSeries(sSE1, true); + ArraySetAsSeries(sSE2, true); + ArraySetAsSeries(mLE1, true); + ArraySetAsSeries(mLE2, true); + ArraySetAsSeries(mSE1, true); + ArraySetAsSeries(mSE2, true); + ArraySetAsSeries(lLE1, true); + ArraySetAsSeries(lLE2, true); + ArraySetAsSeries(lSE1, true); + ArraySetAsSeries(lSE2, true); + ArraySetAsSeries(hLE1, true); + ArraySetAsSeries(hLE2, true); + ArraySetAsSeries(hSE1, true); + ArraySetAsSeries(hSE2, true); + + // + // Conditions ... + + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + + // + // Current ... + isCBullish = false; + isCBearish = false; + isCStrongBullish = false; + isCStrongBearish = false; + isCSwitchedToBullish = false; + isCSwitchedToBearish = false; + isCStrongSwitchedToBullish = false; + isCStrongSwitchedToBearish = false; + + // + // Short ... + isSBullish = false; + isSBearish = false; + isSStrongBullish = false; + isSStrongBearish = false; + isSSwitchedToBullish = false; + isSSwitchedToBearish = false; + isSStrongSwitchedToBullish = false; + isSStrongSwitchedToBearish = false; + + // + // Medium ... + isMBullish = false; + isMBearish = false; + isMStrongBullish = false; + isMStrongBearish = false; + isMSwitchedToBullish = false; + isMSwitchedToBearish = false; + isMStrongSwitchedToBullish = false; + isMStrongSwitchedToBearish = false; + + // + // Long ... + isLBullish = false; + isLBearish = false; + isLStrongBullish = false; + isLStrongBearish = false; + isLSwitchedToBullish = false; + isLSwitchedToBearish = false; + isLStrongSwitchedToBullish = false; + isLStrongSwitchedToBearish = false; + + // + // Hind ... + isHBullish = false; + isHBearish = false; + isHStrongBullish = false; + isHStrongBearish = false; + isHSwitchedToBullish = false; + isHSwitchedToBearish = false; + isHStrongSwitchedToBullish = false; + isHStrongSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Conditions ... + + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + + // + // Current ... + + // + if (isCBullish) + { + bullishScore++; + } + if (isCStrongBullish) + { + bullishScore++; + } + if (isCSwitchedToBullish) + { + bullishScore++; + } + if (isCStrongSwitchedToBullish) + { + bullishScore++; + } + + // + if (isCBearish) + { + bearishScore++; + } + if (isCStrongBearish) + { + bearishScore++; + } + if (isCSwitchedToBearish) + { + bearishScore++; + } + if (isCStrongSwitchedToBearish) + { + bearishScore++; + } + + // + // Short ... + + // + if (isSBullish) + { + bullishScore++; + } + if (isSStrongBullish) + { + bullishScore++; + } + if (isSSwitchedToBullish) + { + bullishScore++; + } + if (isSStrongSwitchedToBullish) + { + bullishScore++; + } + + // + if (isSBearish) + { + bearishScore++; + } + if (isSStrongBearish) + { + bearishScore++; + } + if (isSSwitchedToBearish) + { + bearishScore++; + } + if (isSStrongSwitchedToBearish) + { + bearishScore++; + } + + // + // Medium ... + + // + if (isMBullish) + { + bullishScore++; + } + if (isMStrongBullish) + { + bullishScore++; + } + if (isMSwitchedToBullish) + { + bullishScore++; + } + if (isMStrongSwitchedToBullish) + { + bullishScore++; + } + + // + if (isMBearish) + { + bearishScore++; + } + if (isMStrongBearish) + { + bearishScore++; + } + if (isMSwitchedToBearish) + { + bearishScore++; + } + if (isMStrongSwitchedToBearish) + { + bearishScore++; + } + + // + // Long ... + + // + if (isLBullish) + { + bullishScore++; + } + if (isLStrongBullish) + { + bullishScore++; + } + if (isLSwitchedToBullish) + { + bullishScore++; + } + if (isLStrongSwitchedToBullish) + { + bullishScore++; + } + + // + if (isLBearish) + { + bearishScore++; + } + if (isLStrongBearish) + { + bearishScore++; + } + if (isLSwitchedToBearish) + { + bearishScore++; + } + if (isLStrongSwitchedToBearish) + { + bearishScore++; + } + + // + // Hind ... + + // + if (isHBullish) + { + bullishScore++; + } + if (isHStrongBullish) + { + bullishScore++; + } + if (isHSwitchedToBullish) + { + bullishScore++; + } + if (isHStrongSwitchedToBullish) + { + bullishScore++; + } + + // + if (isHBearish) + { + bearishScore++; + } + if (isHStrongBearish) + { + bearishScore++; + } + if (isHSwitchedToBearish) + { + bearishScore++; + } + if (isHStrongSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + + ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) + + ToString("isCStrongBullish", isCStrongBullish, ignoreFalseConditions, separator) + + ToString("isCStrongBearish", isCStrongBearish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isCStrongSwitchedToBullish", isCStrongSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isCStrongSwitchedToBearish", isCStrongSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + + ToString("isSStrongBullish", isSStrongBullish, ignoreFalseConditions, separator) + + ToString("isSStrongBearish", isSStrongBearish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isSStrongSwitchedToBullish", isSStrongSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSStrongSwitchedToBearish", isSStrongSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + + ToString("isMStrongBullish", isMStrongBullish, ignoreFalseConditions, separator) + + ToString("isMStrongBearish", isMStrongBearish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isMStrongSwitchedToBullish", isMStrongSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMStrongSwitchedToBearish", isMStrongSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + + ToString("isLStrongBullish", isLStrongBullish, ignoreFalseConditions, separator) + + ToString("isLStrongBearish", isLStrongBearish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isLStrongSwitchedToBullish", isLStrongSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLStrongSwitchedToBearish", isLStrongSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + + ToString("isHStrongBullish", isHStrongBullish, ignoreFalseConditions, separator) + + ToString("isHStrongBearish", isHStrongBearish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isHStrongSwitchedToBullish", isHStrongSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHStrongSwitchedToBearish", isHStrongSwitchedToBearish, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHCHE"; + } +}; + +// +// Class ... +class XSCXCHCHEHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHCHEHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHCHEHelper() + { + // + Clean(cLE1Buffer); + Clean(cLE2Buffer); + Clean(cSE1Buffer); + Clean(cSE2Buffer); + Clean(sLE1Buffer); + Clean(sLE2Buffer); + Clean(sSE1Buffer); + Clean(sSE2Buffer); + Clean(mLE1Buffer); + Clean(mLE2Buffer); + Clean(mSE1Buffer); + Clean(mSE2Buffer); + Clean(lLE1Buffer); + Clean(lLE2Buffer); + Clean(lSE1Buffer); + Clean(lSE2Buffer); + Clean(hLE1Buffer); + Clean(hLE2Buffer); + Clean(hSE1Buffer); + Clean(hSE2Buffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHCHEInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cLE1Buffer, true); + ArraySetAsSeries(cLE2Buffer, true); + ArraySetAsSeries(cSE1Buffer, true); + ArraySetAsSeries(cSE2Buffer, true); + ArraySetAsSeries(sLE1Buffer, true); + ArraySetAsSeries(sLE2Buffer, true); + ArraySetAsSeries(sSE1Buffer, true); + ArraySetAsSeries(sSE2Buffer, true); + ArraySetAsSeries(mLE1Buffer, true); + ArraySetAsSeries(mLE2Buffer, true); + ArraySetAsSeries(mSE1Buffer, true); + ArraySetAsSeries(mSE2Buffer, true); + ArraySetAsSeries(lLE1Buffer, true); + ArraySetAsSeries(lLE2Buffer, true); + ArraySetAsSeries(lSE1Buffer, true); + ArraySetAsSeries(lSE2Buffer, true); + ArraySetAsSeries(hLE1Buffer, true); + ArraySetAsSeries(hLE2Buffer, true); + ArraySetAsSeries(hSE1Buffer, true); + ArraySetAsSeries(hSE2Buffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchche", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, + mInputs.loopback, + mInputs.multiplier1, + mInputs.multiplier2, + // + // Calculations ... + "", + mInputs.upAppliedTo, + mInputs.downAppliedTo, + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + // + mInputs.showLE1, + mInputs.showLE2, + mInputs.showSE1, + mInputs.showSE2, + // + mInputs.showCurrent, + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHCHEInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHCHEInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Current ... + + // + double GetCLE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cLE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cLE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCLE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cLE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetCLE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cLE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cLE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCLE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cLE2Buffer, + buffer, + forceClean + // + ); + } + + // + double GetCSE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cSE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cSE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCSE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetCSE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cSE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cSE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCSE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSE2Buffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + double GetSLE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sLE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sLE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySLE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sLE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetSLE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sLE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sLE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySLE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sLE2Buffer, + buffer, + forceClean + // + ); + } + + // + double GetSSE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sSE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sSE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySSE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetSSE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sSE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sSE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySSE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSE2Buffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + double GetMLE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mLE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mLE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMLE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mLE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetMLE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mLE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mLE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMLE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mLE2Buffer, + buffer, + forceClean + // + ); + } + + // + double GetMSE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mSE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mSE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMSE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetMSE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mSE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mSE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMSE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSE2Buffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + double GetLLE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lLE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lLE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLLE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lLE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetLLE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lLE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lLE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLLE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lLE2Buffer, + buffer, + forceClean + // + ); + } + + // + double GetLSE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lSE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lSE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLSE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetLSE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lSE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lSE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLSE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSE2Buffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + double GetHLE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hLE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hLE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHLE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hLE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetHLE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hLE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hLE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHLE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hLE2Buffer, + buffer, + forceClean + // + ); + } + + // + double GetHSE1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hSE1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hSE1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHSE1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSE1Buffer, + buffer, + forceClean + // + ); + } + + // + double GetHSE2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hSE2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hSE2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHSE2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSE2Buffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + bool IsCycleBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + bool result = false; + + // + double le1 = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + le1 = GetCLE1(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + le1 = GetSLE1(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + le1 = GetMLE1(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + le1 = GetLLE1(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + le1 = GetHLE1(barIndex); + break; + } + + // + result = le1 != EMPTY_VALUE && + le1 > 0; + + // + return result; + } + + // + bool IsCycleStrongBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + bool result = false; + + // + double le1 = 0; + double le2 = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + le1 = GetCLE1(barIndex); + le2 = GetCLE2(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + le1 = GetSLE1(barIndex); + le2 = GetSLE2(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + le1 = GetMLE1(barIndex); + le2 = GetMLE2(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + le1 = GetLLE1(barIndex); + le2 = GetLLE2(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + le1 = GetHLE1(barIndex); + le2 = GetHLE2(barIndex); + break; + } + + // + result = le1 != EMPTY_VALUE && + le1 > 0 && + le2 != EMPTY_VALUE && + le2 > 0; + + // + return result; + } + + // + bool IsCycleBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + bool result = false; + + // + double se1 = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + se1 = GetCSE1(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + se1 = GetSSE1(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + se1 = GetMSE1(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + se1 = GetLSE1(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + se1 = GetHSE1(barIndex); + break; + } + + // + result = se1 != EMPTY_VALUE && + se1 > 0; + + // + return result; + } + + // + bool IsCycleStrongBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + bool result = false; + + // + double se1 = 0; + double se2 = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + se1 = GetCSE1(barIndex); + se2 = GetCSE2(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + se1 = GetSSE1(barIndex); + se2 = GetSSE2(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + se1 = GetMSE1(barIndex); + se2 = GetMSE2(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + se1 = GetLSE1(barIndex); + se2 = GetLSE2(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + se1 = GetHSE1(barIndex); + se2 = GetHSE2(barIndex); + break; + } + + // + result = se1 != EMPTY_VALUE && + se1 > 0 && + se2 != EMPTY_VALUE && + se2 > 0; + + // + return result; + } + + // + int GetCycleValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle, + double &values[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + double le1 = 0; + double le2 = 0; + double se1 = 0; + double se2 = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + le1 = GetCLE1(barIndex); + le2 = GetCLE2(barIndex); + se1 = GetCSE1(barIndex); + se2 = GetCSE2(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + le1 = GetSLE1(barIndex); + le2 = GetSLE2(barIndex); + se1 = GetSSE1(barIndex); + se2 = GetSSE2(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + le1 = GetMLE1(barIndex); + le2 = GetMLE2(barIndex); + se1 = GetMSE1(barIndex); + se2 = GetMSE2(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + le1 = GetLLE1(barIndex); + le2 = GetLLE2(barIndex); + se1 = GetLSE1(barIndex); + se2 = GetLSE2(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + le1 = GetHLE1(barIndex); + le2 = GetHLE2(barIndex); + se1 = GetHSE1(barIndex); + se2 = GetHSE2(barIndex); + break; + } + + // + if (le1 > 0 && le1 != EMPTY_VALUE) + { + // + Add( + le1, + values // + ); + } + + // + if (le2 > 0 && le2 != EMPTY_VALUE) + { + // + Add( + le2, + values // + ); + } + + // + if (se1 > 0 && se1 != EMPTY_VALUE) + { + // + Add( + se1, + values // + ); + } + + // + if (se2 > 0 && se2 != EMPTY_VALUE) + { + // + Add( + se2, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCycleBullishValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle, + double &values[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + double le1 = 0; + double le2 = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + le1 = GetCLE1(barIndex); + le2 = GetCLE2(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + le1 = GetSLE1(barIndex); + le2 = GetSLE2(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + le1 = GetMLE1(barIndex); + le2 = GetMLE2(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + le1 = GetLLE1(barIndex); + le2 = GetLLE2(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + le1 = GetHLE1(barIndex); + le2 = GetHLE2(barIndex); + break; + } + + // + if (le1 > 0 && le1 != EMPTY_VALUE) + { + // + Add( + le1, + values // + ); + } + + // + if (le2 > 0 && le2 != EMPTY_VALUE) + { + // + Add( + le2, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCycleBearishValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle, + double &values[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + double se1 = 0; + double se2 = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + se1 = GetCSE1(barIndex); + se2 = GetCSE2(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + se1 = GetSSE1(barIndex); + se2 = GetSSE2(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + se1 = GetMSE1(barIndex); + se2 = GetMSE2(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + se1 = GetLSE1(barIndex); + se2 = GetLSE2(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + se1 = GetHSE1(barIndex); + se2 = GetHSE2(barIndex); + break; + } + + // + if (se1 > 0 && se1 != EMPTY_VALUE) + { + // + Add( + se1, + values // + ); + } + + // + if (se2 > 0 && se2 != EMPTY_VALUE) + { + // + Add( + se2, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + double GetCycleMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double values[]; + int valuesCount = GetCycleValues( + barIndex, + cycle, + values // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCycleMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double values[]; + int valuesCount = GetCycleValues( + barIndex, + cycle, + values // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclePower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCycleValues( + barIndex, + cycle, + values // + ); + + // + double max = GetSpecifiedMax(values); + double min = GetSpecifiedMin(values); + + // + result = MathAbs(max - min); + + // + return result; + } + + // + int GetBullishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + bool isBullish = IsCycleBullish( + barIndex, + allCycles[i] // + ); + if (isBullish) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetStrongBullishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + bool isBullish = IsCycleStrongBullish( + barIndex, + allCycles[i] // + ); + if (isBullish) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetBearishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + bool isBearish = IsCycleBearish( + barIndex, + allCycles[i] // + ); + if (isBearish) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetStrongBearishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + bool isBearish = IsCycleStrongBearish( + barIndex, + allCycles[i] // + ); + if (isBearish) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + double GetMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetAllMarketCycles(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValues[]; + int iValuesCount = GetCycleValues( + barIndex, + cycles[i], + iValues // + ); + if (IsValidSize(iValuesCount)) + { + // + Copy( + iValues, + values, + false // + ); + } + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetAllMarketCycles(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValues[]; + int iValuesCount = GetCycleValues( + barIndex, + cycles[i], + iValues // + ); + if (IsValidSize(iValuesCount)) + { + // + Copy( + iValues, + values, + false // + ); + } + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetBullishMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBullishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValues[]; + int iValuesCount = GetCycleValues( + barIndex, + cycles[i], + iValues // + ); + if (IsValidSize(iValuesCount)) + { + // + Copy( + iValues, + values, + false // + ); + } + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetBullishMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBullishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValues[]; + int iValuesCount = GetCycleValues( + barIndex, + cycles[i], + iValues // + ); + if (IsValidSize(iValuesCount)) + { + // + Copy( + iValues, + values, + false // + ); + } + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetBearishMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBearishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValues[]; + int iValuesCount = GetCycleValues( + barIndex, + cycles[i], + iValues // + ); + if (IsValidSize(iValuesCount)) + { + // + Copy( + iValues, + values, + false // + ); + } + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetBearishMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBearishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValues[]; + int iValuesCount = GetCycleValues( + barIndex, + cycles[i], + iValues // + ); + if (IsValidSize(iValuesCount)) + { + // + Copy( + iValues, + values, + false // + ); + } + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCycleBullishMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // Cycle + ) + { + // + double result = 0; + + // + bool isBullish = IsCycleBullish( + barIndex, + cycle // + ); + if (!isBullish) + { + return result; + } + + // + double values[]; + int count = GetCycleBullishValues( + barIndex, + cycle, + values // + ); + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCycleBullishMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // Cycle + ) + { + // + double result = 0; + + // + bool isBullish = IsCycleBullish( + barIndex, + cycle // + ); + if (!isBullish) + { + return result; + } + + // + double values[]; + int count = GetCycleBullishValues( + barIndex, + cycle, + values // + ); + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCycleBearishMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // Cycle + ) + { + // + double result = 0; + + // + bool isBearish = IsCycleBearish( + barIndex, + cycle // + ); + if (!isBearish) + { + return result; + } + + // + double values[]; + int count = GetCycleBearishValues( + barIndex, + cycle, + values // + ); + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCycleBearishMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // Cycle + ) + { + // + double result = 0; + + // + bool isBearish = IsCycleBearish( + barIndex, + cycle // + ); + if (!isBearish) + { + return result; + } + + // + double values[]; + int count = GetCycleBearishValues( + barIndex, + cycle, + values // + ); + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBullishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + result += GetCyclePower( + barIndex, + cycles[i] // + ); + } + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBearishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + result += GetCyclePower( + barIndex, + cycles[i] // + ); + } + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isBullish = IsCycleBullish( + barIndex, + cycles[i] // + ); + + // + if (isBullish) + { + // + result += GetCyclePower( + barIndex, + cycles[i] // + ); + } + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isBearish = IsCycleBearish( + barIndex, + cycles[i] // + ); + + // + if (isBearish) + { + // + result += GetCyclePower( + barIndex, + cycles[i] // + ); + } + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHCHEConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // CURRENT ... + + // + CopyCLE1( + zIndex, + loopback, + conditions.cLE1 // + ); + + // + CopyCLE2( + zIndex, + loopback, + conditions.cLE2 // + ); + + // + CopyCSE1( + zIndex, + loopback, + conditions.cSE1 // + ); + + // + CopyCSE2( + zIndex, + loopback, + conditions.cSE2 // + ); + + // + // SHORT ... + + // + CopySLE1( + zIndex, + loopback, + conditions.sLE1 // + ); + + // + CopySLE2( + zIndex, + loopback, + conditions.sLE2 // + ); + + // + CopySSE1( + zIndex, + loopback, + conditions.sSE1 // + ); + + // + CopySSE2( + zIndex, + loopback, + conditions.sSE2 // + ); + + // + // MEDIUM ... + + // + CopyMLE1( + zIndex, + loopback, + conditions.mLE1 // + ); + + // + CopyMLE2( + zIndex, + loopback, + conditions.mLE2 // + ); + + // + CopyMSE1( + zIndex, + loopback, + conditions.mSE1 // + ); + + // + CopyMSE2( + zIndex, + loopback, + conditions.mSE2 // + ); + + // + // LONG ... + + // + CopyLLE1( + zIndex, + loopback, + conditions.lLE1 // + ); + + // + CopyLLE2( + zIndex, + loopback, + conditions.lLE2 // + ); + + // + CopyLSE1( + zIndex, + loopback, + conditions.lSE1 // + ); + + // + CopyLSE2( + zIndex, + loopback, + conditions.lSE2 // + ); + + // + // HIND ... + + // + CopyHLE1( + zIndex, + loopback, + conditions.hLE1 // + ); + + // + CopyHLE2( + zIndex, + loopback, + conditions.hLE2 // + ); + + // + CopyHSE1( + zIndex, + loopback, + conditions.hSE1 // + ); + + // + CopyHSE2( + zIndex, + loopback, + conditions.hSE2 // + ); + + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + + // + // Current ... + + // + bool isCBullish = NotEmptyZero(conditions.cLE1[cIndex]); + bool isCBearish = NotEmptyZero(conditions.cSE1[cIndex]); + + // + bool isCBullishPrev = NotEmptyZero(conditions.cLE1[pIndex]); + bool isCBearishPrev = NotEmptyZero(conditions.cSE1[pIndex]); + + // + bool isCStrongBullish = isCBullish && + NotEmptyZero(conditions.cLE2[cIndex]); + bool isCStrongBearish = isCBearish && + NotEmptyZero(conditions.cSE2[cIndex]); + + // + bool isCStrongBullishPrev = isCBullishPrev && + NotEmptyZero(conditions.cLE2[pIndex]); + bool isCStrongBearishPrev = isCBearishPrev && + NotEmptyZero(conditions.cSE2[pIndex]); + + // + bool isCSwitchedToBullish = isCBullish && + !isCBullishPrev; + bool isCSwitchedToBearish = isCBearish && + !isCBearishPrev; + + // + bool isCStrongSwitchedToBullish = isCStrongBullish && + !isCStrongBullishPrev; + bool isCStrongSwitchedToBearish = isCStrongBearish && + !isCStrongBearishPrev; + + // + conditions.isCBullish = isCBullish; + conditions.isCBearish = isCBearish; + conditions.isCStrongBullish = isCStrongBullish; + conditions.isCStrongBearish = isCStrongBearish; + conditions.isCSwitchedToBullish = isCSwitchedToBullish; + conditions.isCSwitchedToBearish = isCSwitchedToBearish; + conditions.isCStrongSwitchedToBullish = isCStrongSwitchedToBullish; + conditions.isCStrongSwitchedToBearish = isCStrongSwitchedToBearish; + + // + // Short ... + + // + bool isSBullish = NotEmptyZero(conditions.sLE1[cIndex]); + bool isSBearish = NotEmptyZero(conditions.sSE1[cIndex]); + + // + bool isSBullishPrev = NotEmptyZero(conditions.sLE1[pIndex]); + bool isSBearishPrev = NotEmptyZero(conditions.sSE1[pIndex]); + + // + bool isSStrongBullish = isSBullish && + NotEmptyZero(conditions.sLE2[cIndex]); + bool isSStrongBearish = isSBearish && + NotEmptyZero(conditions.sSE2[cIndex]); + + // + bool isSStrongBullishPrev = isSBullishPrev && + NotEmptyZero(conditions.sLE2[pIndex]); + bool isSStrongBearishPrev = isSBearishPrev && + NotEmptyZero(conditions.sSE2[pIndex]); + + // + bool isSSwitchedToBullish = isSBullish && + !isSBullishPrev; + bool isSSwitchedToBearish = isSBearish && + !isSBearishPrev; + + // + bool isSStrongSwitchedToBullish = isSStrongBullish && + !isSStrongBullishPrev; + bool isSStrongSwitchedToBearish = isSStrongBearish && + !isSStrongBearishPrev; + + // + conditions.isSBullish = isSBullish; + conditions.isSBearish = isSBearish; + conditions.isSStrongBullish = isSStrongBullish; + conditions.isSStrongBearish = isSStrongBearish; + conditions.isSSwitchedToBullish = isSSwitchedToBullish; + conditions.isSSwitchedToBearish = isSSwitchedToBearish; + conditions.isSStrongSwitchedToBullish = isSStrongSwitchedToBullish; + conditions.isSStrongSwitchedToBearish = isSStrongSwitchedToBearish; + + // + // Medium ... + + // + bool isMBullish = NotEmptyZero(conditions.mLE1[cIndex]); + bool isMBearish = NotEmptyZero(conditions.mSE1[cIndex]); + + // + bool isMBullishPrev = NotEmptyZero(conditions.mLE1[pIndex]); + bool isMBearishPrev = NotEmptyZero(conditions.mSE1[pIndex]); + + // + bool isMStrongBullish = isMBullish && + NotEmptyZero(conditions.mLE2[cIndex]); + bool isMStrongBearish = isMBearish && + NotEmptyZero(conditions.mSE2[cIndex]); + + // + bool isMStrongBullishPrev = isMBullishPrev && + NotEmptyZero(conditions.mLE2[pIndex]); + bool isMStrongBearishPrev = isMBearishPrev && + NotEmptyZero(conditions.mSE2[pIndex]); + + // + bool isMSwitchedToBullish = isMBullish && + !isMBullishPrev; + bool isMSwitchedToBearish = isMBearish && + !isMBearishPrev; + + // + bool isMStrongSwitchedToBullish = isMStrongBullish && + !isMStrongBullishPrev; + bool isMStrongSwitchedToBearish = isMStrongBearish && + !isMStrongBearishPrev; + + // + conditions.isMBullish = isMBullish; + conditions.isMBearish = isMBearish; + conditions.isMStrongBullish = isMStrongBullish; + conditions.isMStrongBearish = isMStrongBearish; + conditions.isMSwitchedToBullish = isMSwitchedToBullish; + conditions.isMSwitchedToBearish = isMSwitchedToBearish; + conditions.isMStrongSwitchedToBullish = isMStrongSwitchedToBullish; + conditions.isMStrongSwitchedToBearish = isMStrongSwitchedToBearish; + + // + // Long ... + + // + bool isLBullish = NotEmptyZero(conditions.lLE1[cIndex]); + bool isLBearish = NotEmptyZero(conditions.lSE1[cIndex]); + + // + bool isLBullishPrev = NotEmptyZero(conditions.lLE1[pIndex]); + bool isLBearishPrev = NotEmptyZero(conditions.lSE1[pIndex]); + + // + bool isLStrongBullish = isLBullish && + NotEmptyZero(conditions.lLE2[cIndex]); + bool isLStrongBearish = isLBearish && + NotEmptyZero(conditions.lSE2[cIndex]); + + // + bool isLStrongBullishPrev = isLBullishPrev && + NotEmptyZero(conditions.lLE2[pIndex]); + bool isLStrongBearishPrev = isLBearishPrev && + NotEmptyZero(conditions.lSE2[pIndex]); + + // + bool isLSwitchedToBullish = isLBullish && + !isLBullishPrev; + bool isLSwitchedToBearish = isLBearish && + !isLBearishPrev; + + // + bool isLStrongSwitchedToBullish = isLStrongBullish && + !isLStrongBullishPrev; + bool isLStrongSwitchedToBearish = isLStrongBearish && + !isLStrongBearishPrev; + + // + conditions.isLBullish = isLBullish; + conditions.isLBearish = isLBearish; + conditions.isLStrongBullish = isLStrongBullish; + conditions.isLStrongBearish = isLStrongBearish; + conditions.isLSwitchedToBullish = isLSwitchedToBullish; + conditions.isLSwitchedToBearish = isLSwitchedToBearish; + conditions.isLStrongSwitchedToBullish = isLStrongSwitchedToBullish; + conditions.isLStrongSwitchedToBearish = isLStrongSwitchedToBearish; + + // + // Hind ... + + // + bool isHBullish = NotEmptyZero(conditions.hLE1[cIndex]); + bool isHBearish = NotEmptyZero(conditions.hSE1[cIndex]); + + // + bool isHBullishPrev = NotEmptyZero(conditions.hLE1[pIndex]); + bool isHBearishPrev = NotEmptyZero(conditions.hSE1[pIndex]); + + // + bool isHStrongBullish = isHBullish && + NotEmptyZero(conditions.hLE2[cIndex]); + bool isHStrongBearish = isHBearish && + NotEmptyZero(conditions.hSE2[cIndex]); + + // + bool isHStrongBullishPrev = isHBullishPrev && + NotEmptyZero(conditions.hLE2[pIndex]); + bool isHStrongBearishPrev = isHBearishPrev && + NotEmptyZero(conditions.hSE2[pIndex]); + + // + bool isHSwitchedToBullish = isHBullish && + !isHBullishPrev; + bool isHSwitchedToBearish = isHBearish && + !isHBearishPrev; + + // + bool isHStrongSwitchedToBullish = isHStrongBullish && + !isHStrongBullishPrev; + bool isHStrongSwitchedToBearish = isHStrongBearish && + !isHStrongBearishPrev; + + // + conditions.isHBullish = isHBullish; + conditions.isHBearish = isHBearish; + conditions.isHStrongBullish = isHStrongBullish; + conditions.isHStrongBearish = isHStrongBearish; + conditions.isHSwitchedToBullish = isHSwitchedToBullish; + conditions.isHSwitchedToBearish = isHSwitchedToBearish; + conditions.isHStrongSwitchedToBullish = isHStrongSwitchedToBullish; + conditions.isHStrongSwitchedToBearish = isHStrongSwitchedToBearish; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHCHEInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cLE1Buffer[]; + double cLE2Buffer[]; + double cSE1Buffer[]; + double cSE2Buffer[]; + + // + // Short ... + double sLE1Buffer[]; + double sLE2Buffer[]; + double sSE1Buffer[]; + double sSE2Buffer[]; + + // + // Medium ... + double mLE1Buffer[]; + double mLE2Buffer[]; + double mSE1Buffer[]; + double mSE2Buffer[]; + + // + // Long ... + double lLE1Buffer[]; + double lLE2Buffer[]; + double lSE1Buffer[]; + double lSE2Buffer[]; + + // + // Hind ... + double hLE1Buffer[]; + double hLE2Buffer[]; + double hSE1Buffer[]; + double hSE2Buffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + + // + // LE1 ... + CopyBuffer( + mHandler, + XCHCHE_CLE1_LINE, + 0, + totalBars, + cLE1Buffer + // + ); + + // + // LE2 ... + CopyBuffer( + mHandler, + XCHCHE_CLE2_LINE, + 0, + totalBars, + cLE2Buffer + // + ); + + // + // SE1 ... + CopyBuffer( + mHandler, + XCHCHE_CSE1_LINE, + 0, + totalBars, + cSE1Buffer + // + ); + + // + // SE2 ... + CopyBuffer( + mHandler, + XCHCHE_CSE2_LINE, + 0, + totalBars, + cSE2Buffer + // + ); + + // + // Short ... + + // + // LE1 ... + CopyBuffer( + mHandler, + XCHCHE_SLE1_LINE, + 0, + totalBars, + sLE1Buffer + // + ); + + // + // LE2 ... + CopyBuffer( + mHandler, + XCHCHE_SLE2_LINE, + 0, + totalBars, + sLE2Buffer + // + ); + + // + // SE1 ... + CopyBuffer( + mHandler, + XCHCHE_SSE1_LINE, + 0, + totalBars, + sSE1Buffer + // + ); + + // + // SE2 ... + CopyBuffer( + mHandler, + XCHCHE_SSE2_LINE, + 0, + totalBars, + sSE2Buffer + // + ); + + // + // Medium ... + + // + // LE1 ... + CopyBuffer( + mHandler, + XCHCHE_MLE1_LINE, + 0, + totalBars, + mLE1Buffer + // + ); + + // + // LE2 ... + CopyBuffer( + mHandler, + XCHCHE_MLE2_LINE, + 0, + totalBars, + mLE2Buffer + // + ); + + // + // SE1 ... + CopyBuffer( + mHandler, + XCHCHE_MSE1_LINE, + 0, + totalBars, + mSE1Buffer + // + ); + + // + // SE2 ... + CopyBuffer( + mHandler, + XCHCHE_MSE2_LINE, + 0, + totalBars, + mSE2Buffer + // + ); + + // + // Long ... + + // + // LE1 ... + CopyBuffer( + mHandler, + XCHCHE_LLE1_LINE, + 0, + totalBars, + lLE1Buffer + // + ); + + // + // LE2 ... + CopyBuffer( + mHandler, + XCHCHE_LLE2_LINE, + 0, + totalBars, + lLE2Buffer + // + ); + + // + // SE1 ... + CopyBuffer( + mHandler, + XCHCHE_LSE1_LINE, + 0, + totalBars, + lSE1Buffer + // + ); + + // + // SE2 ... + CopyBuffer( + mHandler, + XCHCHE_LSE2_LINE, + 0, + totalBars, + lSE2Buffer + // + ); + + // + // Hind ... + + // + // LE1 ... + CopyBuffer( + mHandler, + XCHCHE_HLE1_LINE, + 0, + totalBars, + hLE1Buffer + // + ); + + // + // LE2 ... + CopyBuffer( + mHandler, + XCHCHE_HLE2_LINE, + 0, + totalBars, + hLE2Buffer + // + ); + + // + // SE1 ... + CopyBuffer( + mHandler, + XCHCHE_HSE1_LINE, + 0, + totalBars, + hSE1Buffer + // + ); + + // + // SE2 ... + CopyBuffer( + mHandler, + XCHCHE_HSE2_LINE, + 0, + totalBars, + hSE2Buffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchdon.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchdon.helper.mq5 new file mode 100644 index 00000000..2b054736 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchdon.helper.mq5 @@ -0,0 +1,3887 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHDONHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +enum ENUM_XCHDON_BUFFERS +{ + // + // Current ... + // + XCHDON_C_OPEN_UPPER_LINE = 0, + XCHDON_C_OPEN_LOWER_LINE = 1, + // + XCHDON_C_HIGH_UPPER_LINE = 2, + XCHDON_C_HIGH_LOWER_LINE = 3, + // + XCHDON_C_LOW_UPPER_LINE = 4, + XCHDON_C_LOW_LOWER_LINE = 5, + // + XCHDON_C_CLOSE_UPPER_LINE = 6, + XCHDON_C_CLOSE_LOWER_LINE = 7, + // + // Short ... + // + XCHDON_S_OPEN_UPPER_LINE = 8, + XCHDON_S_OPEN_LOWER_LINE = 9, + // + XCHDON_S_HIGH_UPPER_LINE = 10, + XCHDON_S_HIGH_LOWER_LINE = 11, + // + XCHDON_S_LOW_UPPER_LINE = 12, + XCHDON_S_LOW_LOWER_LINE = 13, + // + XCHDON_S_CLOSE_UPPER_LINE = 14, + XCHDON_S_CLOSE_LOWER_LINE = 15, + // + // Medium ... + // + XCHDON_M_OPEN_UPPER_LINE = 16, + XCHDON_M_OPEN_LOWER_LINE = 17, + // + XCHDON_M_HIGH_UPPER_LINE = 18, + XCHDON_M_HIGH_LOWER_LINE = 19, + // + XCHDON_M_LOW_UPPER_LINE = 20, + XCHDON_M_LOW_LOWER_LINE = 21, + // + XCHDON_M_CLOSE_UPPER_LINE = 22, + XCHDON_M_CLOSE_LOWER_LINE = 23, + // + // Long ... + // + XCHDON_L_OPEN_UPPER_LINE = 24, + XCHDON_L_OPEN_LOWER_LINE = 25, + // + XCHDON_L_HIGH_UPPER_LINE = 26, + XCHDON_L_HIGH_LOWER_LINE = 27, + // + XCHDON_L_LOW_UPPER_LINE = 28, + XCHDON_L_LOW_LOWER_LINE = 29, + // + XCHDON_L_CLOSE_UPPER_LINE = 30, + XCHDON_L_CLOSE_LOWER_LINE = 31, + // + // Hind ... + // + XCHDON_H_OPEN_UPPER_LINE = 32, + XCHDON_H_OPEN_LOWER_LINE = 33, + // + XCHDON_H_HIGH_UPPER_LINE = 34, + XCHDON_H_HIGH_LOWER_LINE = 35, + // + XCHDON_H_LOW_UPPER_LINE = 36, + XCHDON_H_LOW_LOWER_LINE = 37, + // + XCHDON_H_CLOSE_UPPER_LINE = 38, + XCHDON_H_CLOSE_LOWER_LINE = 39, +}; + +// +// Input Models ... +struct XCHDONInputs +{ + // + // Props ... + + // + // Market ... + int length; // Market Length + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + + // + bool showUpper; // Show Upper Band + bool showLower; // Show Lower Band + + // + bool showOpen; // Show Open + bool showHigh; // Show High + bool showClose; // Show Close + bool showLow; // Show Low + + // + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHDONInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + length = 0; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showUpper = false; + showLower = false; + + // + showOpen = false; + showHigh = false; + showClose = false; + showLow = false; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + length = 52; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showUpper = true; + showLower = true; + + // + showOpen = true; + showHigh = true; + showClose = true; + showLow = true; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length > 2 + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(result, length); + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHDONConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cOpenUpper[]; + double cOpenLower[]; + double cHighUpper[]; + double cHighLower[]; + double cLowUpper[]; + double cLowLower[]; + double cCloseUpper[]; + double cCloseLower[]; + + // + // Short ... + double sOpenUpper[]; + double sOpenLower[]; + double sHighUpper[]; + double sHighLower[]; + double sLowUpper[]; + double sLowLower[]; + double sCloseUpper[]; + double sCloseLower[]; + + // + // Medium ... + double mOpenUpper[]; + double mOpenLower[]; + double mHighUpper[]; + double mHighLower[]; + double mLowUpper[]; + double mLowLower[]; + double mCloseUpper[]; + double mCloseLower[]; + + // + // Long ... + double lOpenUpper[]; + double lOpenLower[]; + double lHighUpper[]; + double lHighLower[]; + double lLowUpper[]; + double lLowLower[]; + double lCloseUpper[]; + double lCloseLower[]; + + // + // Hind ... + double hOpenUpper[]; + double hOpenLower[]; + double hHighUpper[]; + double hHighLower[]; + double hLowUpper[]; + double hLowLower[]; + double hCloseUpper[]; + double hCloseLower[]; + + // + // Conditions ... + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + + // + void Clean() + { + // + // Buffers ... + + // + Clean(cOpenUpper); + Clean(cOpenLower); + Clean(cHighUpper); + Clean(cHighLower); + Clean(cLowUpper); + Clean(cLowLower); + Clean(cCloseUpper); + Clean(cCloseLower); + Clean(sOpenUpper); + Clean(sOpenLower); + Clean(sHighUpper); + Clean(sHighLower); + Clean(sLowUpper); + Clean(sLowLower); + Clean(sCloseUpper); + Clean(sCloseLower); + Clean(mOpenUpper); + Clean(mOpenLower); + Clean(mHighUpper); + Clean(mHighLower); + Clean(mLowUpper); + Clean(mLowLower); + Clean(mCloseUpper); + Clean(mCloseLower); + Clean(lOpenUpper); + Clean(lOpenLower); + Clean(lHighUpper); + Clean(lHighLower); + Clean(lLowUpper); + Clean(lLowLower); + Clean(lCloseUpper); + Clean(lCloseLower); + Clean(hOpenUpper); + Clean(hOpenLower); + Clean(hHighUpper); + Clean(hHighLower); + Clean(hLowUpper); + Clean(hLowLower); + Clean(hCloseUpper); + Clean(hCloseLower); + + // + ArraySetAsSeries(cOpenUpper, true); + ArraySetAsSeries(cOpenLower, true); + ArraySetAsSeries(cHighUpper, true); + ArraySetAsSeries(cHighLower, true); + ArraySetAsSeries(cLowUpper, true); + ArraySetAsSeries(cLowLower, true); + ArraySetAsSeries(cCloseUpper, true); + ArraySetAsSeries(cCloseLower, true); + ArraySetAsSeries(sOpenUpper, true); + ArraySetAsSeries(sOpenLower, true); + ArraySetAsSeries(sHighUpper, true); + ArraySetAsSeries(sHighLower, true); + ArraySetAsSeries(sLowUpper, true); + ArraySetAsSeries(sLowLower, true); + ArraySetAsSeries(sCloseUpper, true); + ArraySetAsSeries(sCloseLower, true); + ArraySetAsSeries(mOpenUpper, true); + ArraySetAsSeries(mOpenLower, true); + ArraySetAsSeries(mHighUpper, true); + ArraySetAsSeries(mHighLower, true); + ArraySetAsSeries(mLowUpper, true); + ArraySetAsSeries(mLowLower, true); + ArraySetAsSeries(mCloseUpper, true); + ArraySetAsSeries(mCloseLower, true); + ArraySetAsSeries(lOpenUpper, true); + ArraySetAsSeries(lOpenLower, true); + ArraySetAsSeries(lHighUpper, true); + ArraySetAsSeries(lHighLower, true); + ArraySetAsSeries(lLowUpper, true); + ArraySetAsSeries(lLowLower, true); + ArraySetAsSeries(lCloseUpper, true); + ArraySetAsSeries(lCloseLower, true); + ArraySetAsSeries(hOpenUpper, true); + ArraySetAsSeries(hOpenLower, true); + ArraySetAsSeries(hHighUpper, true); + ArraySetAsSeries(hHighLower, true); + ArraySetAsSeries(hLowUpper, true); + ArraySetAsSeries(hLowLower, true); + ArraySetAsSeries(hCloseUpper, true); + ArraySetAsSeries(hCloseLower, true); + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Current ... + // + // Short ... + // + // Medium ... + // + // Long ... + // + // Hind ... + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHDON"; + } +}; + +// +// Class ... +class XSCXCHDONHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHDONHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHDONHelper() + { + // + Clean(cOpenUpperBuffer); + Clean(cOpenLowerBuffer); + Clean(cHighUpperBuffer); + Clean(cHighLowerBuffer); + Clean(cLowUpperBuffer); + Clean(cLowLowerBuffer); + Clean(cCloseUpperBuffer); + Clean(cCloseLowerBuffer); + Clean(sOpenUpperBuffer); + Clean(sOpenLowerBuffer); + Clean(sHighUpperBuffer); + Clean(sHighLowerBuffer); + Clean(sLowUpperBuffer); + Clean(sLowLowerBuffer); + Clean(sCloseUpperBuffer); + Clean(sCloseLowerBuffer); + Clean(mOpenUpperBuffer); + Clean(mOpenLowerBuffer); + Clean(mHighUpperBuffer); + Clean(mHighLowerBuffer); + Clean(mLowUpperBuffer); + Clean(mLowLowerBuffer); + Clean(mCloseUpperBuffer); + Clean(mCloseLowerBuffer); + Clean(lOpenUpperBuffer); + Clean(lOpenLowerBuffer); + Clean(lHighUpperBuffer); + Clean(lHighLowerBuffer); + Clean(lLowUpperBuffer); + Clean(lLowLowerBuffer); + Clean(lCloseUpperBuffer); + Clean(lCloseLowerBuffer); + Clean(hOpenUpperBuffer); + Clean(hOpenLowerBuffer); + Clean(hHighUpperBuffer); + Clean(hHighLowerBuffer); + Clean(hLowUpperBuffer); + Clean(hLowLowerBuffer); + Clean(hCloseUpperBuffer); + Clean(hCloseLowerBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHDONInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cOpenUpperBuffer, true); + ArraySetAsSeries(cOpenLowerBuffer, true); + ArraySetAsSeries(cHighUpperBuffer, true); + ArraySetAsSeries(cHighLowerBuffer, true); + ArraySetAsSeries(cLowUpperBuffer, true); + ArraySetAsSeries(cLowLowerBuffer, true); + ArraySetAsSeries(cCloseUpperBuffer, true); + ArraySetAsSeries(cCloseLowerBuffer, true); + ArraySetAsSeries(sOpenUpperBuffer, true); + ArraySetAsSeries(sOpenLowerBuffer, true); + ArraySetAsSeries(sHighUpperBuffer, true); + ArraySetAsSeries(sHighLowerBuffer, true); + ArraySetAsSeries(sLowUpperBuffer, true); + ArraySetAsSeries(sLowLowerBuffer, true); + ArraySetAsSeries(sCloseUpperBuffer, true); + ArraySetAsSeries(sCloseLowerBuffer, true); + ArraySetAsSeries(mOpenUpperBuffer, true); + ArraySetAsSeries(mOpenLowerBuffer, true); + ArraySetAsSeries(mHighUpperBuffer, true); + ArraySetAsSeries(mHighLowerBuffer, true); + ArraySetAsSeries(mLowUpperBuffer, true); + ArraySetAsSeries(mLowLowerBuffer, true); + ArraySetAsSeries(mCloseUpperBuffer, true); + ArraySetAsSeries(mCloseLowerBuffer, true); + ArraySetAsSeries(lOpenUpperBuffer, true); + ArraySetAsSeries(lOpenLowerBuffer, true); + ArraySetAsSeries(lHighUpperBuffer, true); + ArraySetAsSeries(lHighLowerBuffer, true); + ArraySetAsSeries(lLowUpperBuffer, true); + ArraySetAsSeries(lLowLowerBuffer, true); + ArraySetAsSeries(lCloseUpperBuffer, true); + ArraySetAsSeries(lCloseLowerBuffer, true); + ArraySetAsSeries(hOpenUpperBuffer, true); + ArraySetAsSeries(hOpenLowerBuffer, true); + ArraySetAsSeries(hHighUpperBuffer, true); + ArraySetAsSeries(hHighLowerBuffer, true); + ArraySetAsSeries(hLowUpperBuffer, true); + ArraySetAsSeries(hLowLowerBuffer, true); + ArraySetAsSeries(hCloseUpperBuffer, true); + ArraySetAsSeries(hCloseLowerBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchdon", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + // + mInputs.showUpper, // Show Upper Band + mInputs.showLower, // Show Lower Band + // + mInputs.showOpen, // Show Open + mInputs.showHigh, // Show High + mInputs.showClose, // Show Close + mInputs.showLow, // Show Low + // + // Cycles ... + mInputs.showCurrent, // Show Current Cycle + mInputs.showShort, // Show Short Cycle + mInputs.showMedium, // Show Medium Cycle + mInputs.showLong, // Show Long Cycle + mInputs.showHind // Show Hind Cycle + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Buffers ... + + // + // Current ... + + // + // Open ... + + // + double GetCOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCOpenUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCOpenLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetCHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCHighUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCHighLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetCLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCLowUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCLowLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetCCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCCloseUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCCloseLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + // Open ... + + // + double GetSOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySOpenUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySOpenLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetSHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySHighUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySHighLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetSLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySLowUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySLowLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetSCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySCloseUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySCloseLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + // Open ... + + // + double GetMOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMOpenUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMOpenLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetMHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMHighUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMHighLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetMLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMLowUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMLowLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetMCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMCloseUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMCloseLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + // Open ... + + // + double GetLOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLOpenUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLOpenLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetLHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLHighUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLHighLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetLLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLLowUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLLowLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetLCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLCloseUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLCloseLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + // Open ... + + // + double GetHOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHOpenUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHOpenLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetHHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHHighUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHHighLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetHLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHLowUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHLowLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetHCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHCloseUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHCloseLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + void GetCycleValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle, // Cycle + // + double &openUpper, + double &openLower, + double &highUpper, + double &highLower, + double &lowUpper, + double &lowLower, + double &closeUpper, + double &closeLower // + ) + { + // + openUpper = 0; + openLower = 0; + highUpper = 0; + highLower = 0; + lowUpper = 0; + lowLower = 0; + closeUpper = 0; + closeLower = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + switch (cycle) + { + // + // Current ... + case X_MARKET_CYCLE_UNKNOWN: + // + openUpper = GetCOpenUpper(barIndex); + openLower = GetCOpenLower(barIndex); + highUpper = GetCHighUpper(barIndex); + highLower = GetCHighLower(barIndex); + lowUpper = GetCLowUpper(barIndex); + lowLower = GetCLowLower(barIndex); + closeUpper = GetCCloseUpper(barIndex); + closeLower = GetCCloseLower(barIndex); + break; + + // + // Short ... + case X_MARKET_CYCLE_SHORT: + // + openUpper = GetSOpenUpper(barIndex); + openLower = GetSOpenLower(barIndex); + highUpper = GetSHighUpper(barIndex); + highLower = GetSHighLower(barIndex); + lowUpper = GetSLowUpper(barIndex); + lowLower = GetSLowLower(barIndex); + closeUpper = GetSCloseUpper(barIndex); + closeLower = GetSCloseLower(barIndex); + break; + + // + // Medium ... + case X_MARKET_CYCLE_MEDIUM: + // + openUpper = GetMOpenUpper(barIndex); + openLower = GetMOpenLower(barIndex); + highUpper = GetMHighUpper(barIndex); + highLower = GetMHighLower(barIndex); + lowUpper = GetMLowUpper(barIndex); + lowLower = GetMLowLower(barIndex); + closeUpper = GetMCloseUpper(barIndex); + closeLower = GetMCloseLower(barIndex); + break; + + // + // Long ... + case X_MARKET_CYCLE_LONG: + // + openUpper = GetLOpenUpper(barIndex); + openLower = GetLOpenLower(barIndex); + highUpper = GetLHighUpper(barIndex); + highLower = GetLHighLower(barIndex); + lowUpper = GetLLowUpper(barIndex); + lowLower = GetLLowLower(barIndex); + closeUpper = GetLCloseUpper(barIndex); + closeLower = GetLCloseLower(barIndex); + break; + + // + // Hind ... + case X_MARKET_CYCLE_HIND: + // + openUpper = GetHOpenUpper(barIndex); + openLower = GetHOpenLower(barIndex); + highUpper = GetHHighUpper(barIndex); + highLower = GetHHighLower(barIndex); + lowUpper = GetHLowUpper(barIndex); + lowLower = GetHLowLower(barIndex); + closeUpper = GetHCloseUpper(barIndex); + closeLower = GetHCloseLower(barIndex); + break; + } + } + + // + int GetCyclesUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenUpper, + values // + ); + + // + Add( + iHighUpper, + values // + ); + + // + Add( + iLowUpper, + values // + ); + + // + Add( + iCloseUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesOpenUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesOpenLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesHighUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iHighUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesHighLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iHighLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesLowUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iLowUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesLowLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iLowLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesCloseUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iCloseUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesCloseLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iCloseLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenLower, + values // + ); + + // + Add( + iHighLower, + values // + ); + + // + Add( + iLowLower, + values // + ); + + // + Add( + iCloseLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + double GetCyclesUpperMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesUpperValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesUpperMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesUpperValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesLowerMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesLowerValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesLowerMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesLowerValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHDONConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + // CopyCTenkanSen( + // zIndex, + // loopback, + // conditions.cTK // + // ); + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Conditions ... + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHDONInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cOpenUpperBuffer[]; + double cOpenLowerBuffer[]; + double cHighUpperBuffer[]; + double cHighLowerBuffer[]; + double cLowUpperBuffer[]; + double cLowLowerBuffer[]; + double cCloseUpperBuffer[]; + double cCloseLowerBuffer[]; + + // + // Short ... + double sOpenUpperBuffer[]; + double sOpenLowerBuffer[]; + double sHighUpperBuffer[]; + double sHighLowerBuffer[]; + double sLowUpperBuffer[]; + double sLowLowerBuffer[]; + double sCloseUpperBuffer[]; + double sCloseLowerBuffer[]; + + // + // Medium ... + double mOpenUpperBuffer[]; + double mOpenLowerBuffer[]; + double mHighUpperBuffer[]; + double mHighLowerBuffer[]; + double mLowUpperBuffer[]; + double mLowLowerBuffer[]; + double mCloseUpperBuffer[]; + double mCloseLowerBuffer[]; + + // + // Long ... + double lOpenUpperBuffer[]; + double lOpenLowerBuffer[]; + double lHighUpperBuffer[]; + double lHighLowerBuffer[]; + double lLowUpperBuffer[]; + double lLowLowerBuffer[]; + double lCloseUpperBuffer[]; + double lCloseLowerBuffer[]; + + // + // Hind ... + double hOpenUpperBuffer[]; + double hOpenLowerBuffer[]; + double hHighUpperBuffer[]; + double hHighLowerBuffer[]; + double hLowUpperBuffer[]; + double hLowLowerBuffer[]; + double hCloseUpperBuffer[]; + double hCloseLowerBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + CopyBuffer( + mHandler, + XCHDON_C_OPEN_UPPER_LINE, + 0, + totalBars, + cOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_OPEN_LOWER_LINE, + 0, + totalBars, + cOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_HIGH_UPPER_LINE, + 0, + totalBars, + cHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_HIGH_LOWER_LINE, + 0, + totalBars, + cHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_LOW_UPPER_LINE, + 0, + totalBars, + cLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_LOW_LOWER_LINE, + 0, + totalBars, + cLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_CLOSE_UPPER_LINE, + 0, + totalBars, + cCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_CLOSE_LOWER_LINE, + 0, + totalBars, + cCloseLowerBuffer // + ); + + // + // Short ... + CopyBuffer( + mHandler, + XCHDON_S_OPEN_UPPER_LINE, + 0, + totalBars, + sOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_OPEN_LOWER_LINE, + 0, + totalBars, + sOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_HIGH_UPPER_LINE, + 0, + totalBars, + sHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_HIGH_LOWER_LINE, + 0, + totalBars, + sHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_LOW_UPPER_LINE, + 0, + totalBars, + sLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_LOW_LOWER_LINE, + 0, + totalBars, + sLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_CLOSE_UPPER_LINE, + 0, + totalBars, + sCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_CLOSE_LOWER_LINE, + 0, + totalBars, + sCloseLowerBuffer // + ); + + // + // Medium ... + CopyBuffer( + mHandler, + XCHDON_M_OPEN_UPPER_LINE, + 0, + totalBars, + mOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_OPEN_LOWER_LINE, + 0, + totalBars, + mOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_HIGH_UPPER_LINE, + 0, + totalBars, + mHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_HIGH_LOWER_LINE, + 0, + totalBars, + mHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_LOW_UPPER_LINE, + 0, + totalBars, + mLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_LOW_LOWER_LINE, + 0, + totalBars, + mLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_CLOSE_UPPER_LINE, + 0, + totalBars, + mCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_CLOSE_LOWER_LINE, + 0, + totalBars, + mCloseLowerBuffer // + ); + + // + // Long ... + CopyBuffer( + mHandler, + XCHDON_L_OPEN_UPPER_LINE, + 0, + totalBars, + lOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_OPEN_LOWER_LINE, + 0, + totalBars, + lOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_HIGH_UPPER_LINE, + 0, + totalBars, + lHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_HIGH_LOWER_LINE, + 0, + totalBars, + lHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_LOW_UPPER_LINE, + 0, + totalBars, + lLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_LOW_LOWER_LINE, + 0, + totalBars, + lLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_CLOSE_UPPER_LINE, + 0, + totalBars, + lCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_CLOSE_LOWER_LINE, + 0, + totalBars, + lCloseLowerBuffer // + ); + + // + // Hind ... + CopyBuffer( + mHandler, + XCHDON_H_OPEN_UPPER_LINE, + 0, + totalBars, + hOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_OPEN_LOWER_LINE, + 0, + totalBars, + hOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_HIGH_UPPER_LINE, + 0, + totalBars, + hHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_HIGH_LOWER_LINE, + 0, + totalBars, + hHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_LOW_UPPER_LINE, + 0, + totalBars, + hLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_LOW_LOWER_LINE, + 0, + totalBars, + hLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_CLOSE_UPPER_LINE, + 0, + totalBars, + hCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_CLOSE_LOWER_LINE, + 0, + totalBars, + hCloseLowerBuffer // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchhk.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchhk.helper.mq5 new file mode 100644 index 00000000..1291254f --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchhk.helper.mq5 @@ -0,0 +1,5980 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHHKHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHHK_BUFFERS +{ + // + // Current ... + XCHHK_CO_LINE = 0, + XCHHK_CH_LINE = 1, + XCHHK_CL_LINE = 2, + XCHHK_CC_LINE = 3, + // + // Short ... + XCHHK_SO_LINE = 5, + XCHHK_SH_LINE = 6, + XCHHK_SL_LINE = 7, + XCHHK_SC_LINE = 8, + // + // Medium ... + XCHHK_MO_LINE = 10, + XCHHK_MH_LINE = 11, + XCHHK_ML_LINE = 12, + XCHHK_MC_LINE = 13, + // + // Long ... + XCHHK_LO_LINE = 15, + XCHHK_LH_LINE = 16, + XCHHK_LL_LINE = 17, + XCHHK_LC_LINE = 18, + // + // Hind ... + XCHHK_HO_LINE = 20, + XCHHK_HH_LINE = 21, + XCHHK_HL_LINE = 22, + XCHHK_HC_LINE = 23, +}; + +// +// Input Models ... +struct XCHHKInputs +{ + // + // Props ... + + // + // Market ... + int cSmoothingLength; // Smoothing Length + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + bool ignoreShadows; // Ignore Bar Shadows + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHHKInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + cSmoothingLength = 0; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + ignoreShadows = false; + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + cSmoothingLength = 14; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + ignoreShadows = false; + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + cSmoothingLength > 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(0, cSmoothingLength) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHHKConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + XOHCL cBars[]; + + // + // Short ... + XOHCL sBars[]; + + // + // Medium ... + XOHCL mBars[]; + + // + // Long ... + XOHCL lBars[]; + + // + // Hind ... + XOHCL hBars[]; + + // + // Conditions ... + + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + + // + // Current ... + + // + bool isCBullish; + bool isCSwitchedToBullish; + bool isCBearish; + bool isCSwitchedToBearish; + + // + bool isCloseOverCHigh; + bool isCloseUnderCLow; + + // + // Short ... + + // + bool isSBullish; + bool isSSwitchedToBullish; + bool isSBearish; + bool isSSwitchedToBearish; + + // + bool isCloseOverSHigh; + bool isCloseUnderSLow; + + // + // Medium ... + + // + bool isMBullish; + bool isMSwitchedToBullish; + bool isMBearish; + bool isMSwitchedToBearish; + + // + bool isCloseOverMHigh; + bool isCloseUnderMLow; + + // + // Long ... + + // + bool isLBullish; + bool isLSwitchedToBullish; + bool isLBearish; + bool isLSwitchedToBearish; + + // + bool isCloseOverLHigh; + bool isCloseUnderLLow; + + // + // Hind ... + + // + bool isHBullish; + bool isHSwitchedToBullish; + bool isHBearish; + bool isHSwitchedToBearish; + + // + bool isCloseOverHHigh; + bool isCloseUnderHLow; + + // + void Clean() + { + // + Clean(cBars); + Clean(sBars); + Clean(mBars); + Clean(lBars); + Clean(hBars); + + // + ArraySetAsSeries(cBars, true); + ArraySetAsSeries(sBars, true); + ArraySetAsSeries(mBars, true); + ArraySetAsSeries(lBars, true); + ArraySetAsSeries(hBars, true); + + // + // Conditions ... + + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + + // + // Current ... + + // + isCBullish = false; + isCSwitchedToBullish = false; + isCBearish = false; + isCSwitchedToBearish = false; + + // + isCloseOverCHigh = false; + isCloseUnderCLow = false; + + // + // Short ... + + // + isSBullish = false; + isSSwitchedToBullish = false; + isSBearish = false; + isSSwitchedToBearish = false; + + // + isCloseOverSHigh = false; + isCloseUnderSLow = false; + + // + // Medium ... + + // + isMBullish = false; + isMSwitchedToBullish = false; + isMBearish = false; + isMSwitchedToBearish = false; + + // + isCloseOverMHigh = false; + isCloseUnderMLow = false; + + // + // Long ... + + // + isLBullish = false; + isLSwitchedToBullish = false; + isLBearish = false; + isLSwitchedToBearish = false; + + // + isCloseOverLHigh = false; + isCloseUnderLLow = false; + + // + // Hind ... + + // + isHBullish = false; + isHSwitchedToBullish = false; + isHBearish = false; + isHSwitchedToBearish = false; + + // + isCloseOverHHigh = false; + isCloseUnderHLow = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Conditions ... + + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + + // + // Current ... + if (isCBullish) + { + bullishScore++; + } + if (isCSwitchedToBullish) + { + bullishScore++; + } + if (isCBearish) + { + bearishScore++; + } + if (isCSwitchedToBearish) + { + bearishScore++; + } + if (isCloseOverCHigh) + { + bullishScore++; + } + if (isCloseUnderCLow) + { + bearishScore++; + } + + // + // Short ... + if (isSBullish) + { + bullishScore++; + } + if (isSSwitchedToBullish) + { + bullishScore++; + } + if (isSBearish) + { + bearishScore++; + } + if (isSSwitchedToBearish) + { + bearishScore++; + } + if (isCloseOverSHigh) + { + bullishScore++; + } + if (isCloseUnderSLow) + { + bearishScore++; + } + + // + // Medium ... + if (isMBullish) + { + bullishScore++; + } + if (isMSwitchedToBullish) + { + bullishScore++; + } + if (isMBearish) + { + bearishScore++; + } + if (isMSwitchedToBearish) + { + bearishScore++; + } + if (isCloseOverMHigh) + { + bullishScore++; + } + if (isCloseUnderMLow) + { + bearishScore++; + } + + // + // Long ... + if (isLBullish) + { + bullishScore++; + } + if (isLSwitchedToBullish) + { + bullishScore++; + } + if (isLBearish) + { + bearishScore++; + } + if (isLSwitchedToBearish) + { + bearishScore++; + } + if (isCloseOverLHigh) + { + bullishScore++; + } + if (isCloseUnderLLow) + { + bearishScore++; + } + + // + // Hind ... + if (isHBullish) + { + bullishScore++; + } + if (isHSwitchedToBullish) + { + bullishScore++; + } + if (isHBearish) + { + bearishScore++; + } + if (isHSwitchedToBearish) + { + bearishScore++; + } + if (isCloseOverHHigh) + { + bullishScore++; + } + if (isCloseUnderHLow) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isCloseOverCHigh", isCloseOverCHigh, ignoreFalseConditions, separator) + + ToString("isCloseUnderCLow", isCloseUnderCLow, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isCloseOverSHigh", isCloseOverSHigh, ignoreFalseConditions, separator) + + ToString("isCloseUnderSLow", isCloseUnderSLow, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isCloseOverMHigh", isCloseOverMHigh, ignoreFalseConditions, separator) + + ToString("isCloseUnderMLow", isCloseUnderMLow, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isCloseOverLHigh", isCloseOverLHigh, ignoreFalseConditions, separator) + + ToString("isCloseUnderLLow", isCloseUnderLLow, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isCloseOverHHigh", isCloseOverHHigh, ignoreFalseConditions, separator) + + ToString("isCloseUnderHLow", isCloseUnderHLow, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHHK"; + } +}; + +// +// Class ... +class XSCXCHHKHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHHKHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHHKHelper() + { + // + Clean(cOpenBuffer); + Clean(cHighBuffer); + Clean(cLowBuffer); + Clean(cCloseBuffer); + Clean(sOpenBuffer); + Clean(sHighBuffer); + Clean(sLowBuffer); + Clean(sCloseBuffer); + Clean(mOpenBuffer); + Clean(mHighBuffer); + Clean(mLowBuffer); + Clean(mCloseBuffer); + Clean(lOpenBuffer); + Clean(lHighBuffer); + Clean(lLowBuffer); + Clean(lCloseBuffer); + Clean(hOpenBuffer); + Clean(hHighBuffer); + Clean(hLowBuffer); + Clean(hCloseBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHHKInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cOpenBuffer, true); + ArraySetAsSeries(cHighBuffer, true); + ArraySetAsSeries(cLowBuffer, true); + ArraySetAsSeries(cCloseBuffer, true); + ArraySetAsSeries(sOpenBuffer, true); + ArraySetAsSeries(sHighBuffer, true); + ArraySetAsSeries(sLowBuffer, true); + ArraySetAsSeries(sCloseBuffer, true); + ArraySetAsSeries(mOpenBuffer, true); + ArraySetAsSeries(mHighBuffer, true); + ArraySetAsSeries(mLowBuffer, true); + ArraySetAsSeries(mCloseBuffer, true); + ArraySetAsSeries(lOpenBuffer, true); + ArraySetAsSeries(lHighBuffer, true); + ArraySetAsSeries(lLowBuffer, true); + ArraySetAsSeries(lCloseBuffer, true); + ArraySetAsSeries(hOpenBuffer, true); + ArraySetAsSeries(hHighBuffer, true); + ArraySetAsSeries(hLowBuffer, true); + ArraySetAsSeries(hCloseBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchhk", + // + // Inputs ... + // + // Market ... + "", + mInputs.cSmoothingLength, + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + mInputs.ignoreShadows, + mInputs.showCurrent, + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHHKInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHHKInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Current ... + + // + double GetCOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cOpenBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cHighBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cLowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cCloseBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cCloseBuffer, + buffer, + forceClean + // + ); + } + + // + // Get XOHCL ... + bool CAsOHCL( + XOHCL &bar, // Holds Result + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + double open = GetCOpen(barIndex); + double high = GetCHigh(barIndex); + double close = GetCClose(barIndex); + double low = GetCLow(barIndex); + + // + result = bar.Init( + mSymbol, + mPeriod, + open, + high, + close, + low, + barIndex + // + ); + + // + return result; + } + + // + // Copy Required Items ... + int CopyCAsOHCL( + int start, // Start + int count, // Number of Items for read + XOHCL &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int result = 0; + + // + // Update Calculations ... + Calculate(); + + // + if (forceClean) + { + Clean(buffer); + } + + // + int before = ArraySize(buffer); + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(cOpenBuffer)) + { + start = ArraySize(cOpenBuffer) - 1; + } + + // + bool asSeriesBuffer = ArrayGetAsSeries(buffer); + ArraySetAsSeries(buffer, true); + + // + for (int i = start; i < start + count; i++) + { + // + XOHCL iBar; + bool isInit = CAsOHCL(iBar, i); + + // + if (isInit) + { + // + AddRef( + iBar, + buffer + // + ); + } + } + + // + ArraySetAsSeries(buffer, asSeriesBuffer); + + // + int after = ArraySize(buffer); + + // + result = after - before; + + // + return result; + } + + // + // Short ... + + // + double GetSOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sOpenBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sHighBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sLowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sCloseBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sCloseBuffer, + buffer, + forceClean + // + ); + } + + // + // Get XOHCL ... + bool SAsOHCL( + XOHCL &bar, // Holds Result + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + double open = GetSOpen(barIndex); + double high = GetSHigh(barIndex); + double close = GetSClose(barIndex); + double low = GetSLow(barIndex); + + // + result = bar.Init( + mSymbol, + mPeriod, + open, + high, + close, + low, + barIndex + // + ); + + // + return result; + } + + // + // Copy Required Items ... + int CopySAsOHCL( + int start, // Start + int count, // Number of Items for read + XOHCL &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int result = 0; + + // + // Update Calculations ... + Calculate(); + + // + if (forceClean) + { + Clean(buffer); + } + + // + int before = ArraySize(buffer); + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(sOpenBuffer)) + { + start = ArraySize(sOpenBuffer) - 1; + } + + // + bool asSeriesBuffer = ArrayGetAsSeries(buffer); + ArraySetAsSeries(buffer, true); + + // + for (int i = start; i < start + count; i++) + { + // + XOHCL iBar; + bool isInit = SAsOHCL(iBar, i); + + // + if (isInit) + { + // + AddRef( + iBar, + buffer + // + ); + } + } + + // + ArraySetAsSeries(buffer, asSeriesBuffer); + + // + int after = ArraySize(buffer); + + // + result = after - before; + + // + return result; + } + + // + // Medium ... + + // + double GetMOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mOpenBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mHighBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mLowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mCloseBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mCloseBuffer, + buffer, + forceClean + // + ); + } + + // + // Get XOHCL ... + bool MAsOHCL( + XOHCL &bar, // Holds Result + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + double open = GetMOpen(barIndex); + double high = GetMHigh(barIndex); + double close = GetMClose(barIndex); + double low = GetMLow(barIndex); + + // + result = bar.Init( + mSymbol, + mPeriod, + open, + high, + close, + low, + barIndex + // + ); + + // + return result; + } + + // + // Copy Required Items ... + int CopyMAsOHCL( + int start, // Start + int count, // Number of Items for read + XOHCL &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int result = 0; + + // + // Update Calculations ... + Calculate(); + + // + if (forceClean) + { + Clean(buffer); + } + + // + int before = ArraySize(buffer); + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(mOpenBuffer)) + { + start = ArraySize(mOpenBuffer) - 1; + } + + // + bool asSeriesBuffer = ArrayGetAsSeries(buffer); + ArraySetAsSeries(buffer, true); + + // + for (int i = start; i < start + count; i++) + { + // + XOHCL iBar; + bool isInit = MAsOHCL(iBar, i); + + // + if (isInit) + { + // + AddRef( + iBar, + buffer + // + ); + } + } + + // + ArraySetAsSeries(buffer, asSeriesBuffer); + + // + int after = ArraySize(buffer); + + // + result = after - before; + + // + return result; + } + + // + // Long ... + + // + double GetLOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lOpenBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lHighBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lLowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lCloseBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lCloseBuffer, + buffer, + forceClean + // + ); + } + + // + // Get XOHCL ... + bool LAsOHCL( + XOHCL &bar, // Holds Result + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + double open = GetLOpen(barIndex); + double high = GetLHigh(barIndex); + double close = GetLClose(barIndex); + double low = GetLLow(barIndex); + + // + result = bar.Init( + mSymbol, + mPeriod, + open, + high, + close, + low, + barIndex + // + ); + + // + return result; + } + + // + // Copy Required Items ... + int CopyLAsOHCL( + int start, // Start + int count, // Number of Items for read + XOHCL &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int result = 0; + + // + // Update Calculations ... + Calculate(); + + // + if (forceClean) + { + Clean(buffer); + } + + // + int before = ArraySize(buffer); + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(lOpenBuffer)) + { + start = ArraySize(lOpenBuffer) - 1; + } + + // + bool asSeriesBuffer = ArrayGetAsSeries(buffer); + ArraySetAsSeries(buffer, true); + + // + for (int i = start; i < start + count; i++) + { + // + XOHCL iBar; + bool isInit = LAsOHCL(iBar, i); + + // + if (isInit) + { + // + AddRef( + iBar, + buffer + // + ); + } + } + + // + ArraySetAsSeries(buffer, asSeriesBuffer); + + // + int after = ArraySize(buffer); + + // + result = after - before; + + // + return result; + } + + // + // Hind ... + + // + double GetHOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hOpenBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hHighBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hLowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hCloseBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hCloseBuffer, + buffer, + forceClean + // + ); + } + + // + // Get XOHCL ... + bool HAsOHCL( + XOHCL &bar, // Holds Result + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + double open = GetHOpen(barIndex); + double high = GetHHigh(barIndex); + double close = GetHClose(barIndex); + double low = GetHLow(barIndex); + + // + result = bar.Init( + mSymbol, + mPeriod, + open, + high, + close, + low, + barIndex + // + ); + + // + return result; + } + + // + // Copy Required Items ... + int CopyHAsOHCL( + int start, // Start + int count, // Number of Items for read + XOHCL &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int result = 0; + + // + // Update Calculations ... + Calculate(); + + // + if (forceClean) + { + Clean(buffer); + } + + // + int before = ArraySize(buffer); + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(hOpenBuffer)) + { + start = ArraySize(hOpenBuffer) - 1; + } + + // + bool asSeriesBuffer = ArrayGetAsSeries(buffer); + ArraySetAsSeries(buffer, true); + + // + for (int i = start; i < start + count; i++) + { + // + XOHCL iBar; + bool isInit = HAsOHCL(iBar, i); + + // + if (isInit) + { + // + AddRef( + iBar, + buffer + // + ); + } + } + + // + ArraySetAsSeries(buffer, asSeriesBuffer); + + // + int after = ArraySize(buffer); + + // + result = after - before; + + // + return result; + } + + // + // Tools ... + + // + int GetBars( + XOHCL &bars[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(bars); + + // + XOHCL bar; + bool hasBar = false; + + // + // CURRENT ... + bar.Clean(); + hasBar = CAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // SHORT ... + bar.Clean(); + hasBar = SAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // MEDIUM ... + bar.Clean(); + hasBar = MAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // LONG ... + bar.Clean(); + hasBar = LAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // HIND ... + bar.Clean(); + hasBar = HAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetBullishBars( + XOHCL &bars[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(bars); + + // + XOHCL bar; + bool hasBar = false; + + // + // CURRENT ... + bar.Clean(); + hasBar = CAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // SHORT ... + bar.Clean(); + hasBar = SAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // MEDIUM ... + bar.Clean(); + hasBar = MAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // LONG ... + bar.Clean(); + hasBar = LAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // HIND ... + bar.Clean(); + hasBar = HAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetBearishBars( + XOHCL &bars[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(bars); + + // + XOHCL bar; + bool hasBar = false; + + // + // CURRENT ... + bar.Clean(); + hasBar = CAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // SHORT ... + bar.Clean(); + hasBar = SAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // MEDIUM ... + bar.Clean(); + hasBar = MAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // LONG ... + bar.Clean(); + hasBar = LAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // HIND ... + bar.Clean(); + hasBar = HAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetCyclesBars( + XOHCL &bars[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(bars); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + XOHCL iBar; + bool hasBar = false; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + hasBar = CAsOHCL(iBar, barIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + hasBar = SAsOHCL(iBar, barIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + hasBar = MAsOHCL(iBar, barIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + hasBar = LAsOHCL(iBar, barIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + hasBar = HAsOHCL(iBar, barIndex); + break; + } + + // + if (hasBar && iBar.IsValid()) + { + // + AddRef( + iBar, + bars // + ); + } + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetCyclesBullishBars( + XOHCL &bars[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(bars); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + XOHCL iBar; + bool hasBar = false; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + hasBar = CAsOHCL(iBar, barIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + hasBar = SAsOHCL(iBar, barIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + hasBar = MAsOHCL(iBar, barIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + hasBar = LAsOHCL(iBar, barIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + hasBar = HAsOHCL(iBar, barIndex); + break; + } + + // + if (hasBar && + iBar.IsValid() && + iBar.IsBullish()) + { + // + AddRef( + iBar, + bars // + ); + } + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetCyclesBearishBars( + XOHCL &bars[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(bars); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + XOHCL iBar; + bool hasBar = false; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + hasBar = CAsOHCL(iBar, barIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + hasBar = SAsOHCL(iBar, barIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + hasBar = MAsOHCL(iBar, barIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + hasBar = LAsOHCL(iBar, barIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + hasBar = HAsOHCL(iBar, barIndex); + break; + } + + // + if (hasBar && + iBar.IsValid() && + iBar.IsBearish()) + { + // + AddRef( + iBar, + bars // + ); + } + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + double GetMaxHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Bullish ... + + // + double GetMaxBullishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBullishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxBullishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBullishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Bearish ... + + // + double GetMaxBearishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBearishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxBearishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBearishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Cycles Bullish ... + + // + double GetMaxCyclesBullishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBullishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxCyclesBullishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBullishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Cycles Bearish ... + + // + double GetMaxCyclesBearishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBearishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxCyclesBearishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBearishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + result += bars[i].GetBody(); + } + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + result += bars[i].GetBody(); + } + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + result += bars[i].GetBody(); + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + result += bars[i].GetBody(); + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Cycles Switched to Bullish or not ... + bool IsCyclesSwitchedToBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + int cyclesCount = ArraySize(cycles); + result = IsValidSize(cyclesCount); + if (!result) + { + return result; + } + + // + int cIndex = barIndex; + int pIndex = cIndex + 1; + + // + XOHCL cBars[]; + XOHCL pBars[]; + for (int i = 0; i < cyclesCount; i++) + { + // + XOHCL iCBar; + XOHCL iPBar; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + result = CAsOHCL(iCBar, cIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + result = SAsOHCL(iCBar, cIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + result = MAsOHCL(iCBar, cIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + result = LAsOHCL(iCBar, cIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + result = HAsOHCL(iCBar, cIndex); + break; + } + if (!result) + { + break; + } + AddRef( + iCBar, + cBars // + ); + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + result = CAsOHCL(iPBar, pIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + result = SAsOHCL(iPBar, pIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + result = MAsOHCL(iPBar, pIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + result = LAsOHCL(iPBar, pIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + result = HAsOHCL(iPBar, pIndex); + break; + } + if (!result) + { + break; + } + AddRef( + iPBar, + pBars // + ); + } + + // + int cBarsCount = ArraySize(cBars); + int pBarsCount = ArraySize(pBars); + result = + // + IsValidSize(cBarsCount) && + cBarsCount == cyclesCount && + // + IsValidSize(pBarsCount) && + pBarsCount == cyclesCount + // + ; + if (!result) + { + return result; + } + + // + bool isCIndexBullish = true; + for (int i = 0; i < cBarsCount; i++) + { + isCIndexBullish = isCIndexBullish && cBars[i].IsBullish(); + } + + // + bool isPIndexBullish = true; + for (int i = 0; i < pBarsCount; i++) + { + isPIndexBullish = isPIndexBullish && pBars[i].IsBullish(); + } + + // + result = isCIndexBullish && + !isPIndexBullish; + + // + return result; + } + + // + // Check Cycles Switched to Bearish or not ... + bool IsCyclesSwitchedToBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + int cyclesCount = ArraySize(cycles); + result = IsValidSize(cyclesCount); + if (!result) + { + return result; + } + + // + int cIndex = barIndex; + int pIndex = cIndex + 1; + + // + XOHCL cBars[]; + XOHCL pBars[]; + for (int i = 0; i < cyclesCount; i++) + { + // + XOHCL iCBar; + XOHCL iPBar; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + result = CAsOHCL(iCBar, cIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + result = SAsOHCL(iCBar, cIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + result = MAsOHCL(iCBar, cIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + result = LAsOHCL(iCBar, cIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + result = HAsOHCL(iCBar, cIndex); + break; + } + if (!result) + { + break; + } + AddRef( + iCBar, + cBars // + ); + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + result = CAsOHCL(iPBar, pIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + result = SAsOHCL(iPBar, pIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + result = MAsOHCL(iPBar, pIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + result = LAsOHCL(iPBar, pIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + result = HAsOHCL(iPBar, pIndex); + break; + } + if (!result) + { + break; + } + AddRef( + iPBar, + pBars // + ); + } + + // + int cBarsCount = ArraySize(cBars); + int pBarsCount = ArraySize(pBars); + result = + // + IsValidSize(cBarsCount) && + cBarsCount == cyclesCount && + // + IsValidSize(pBarsCount) && + pBarsCount == cyclesCount + // + ; + if (!result) + { + return result; + } + + // + bool isCIndexBearish = true; + for (int i = 0; i < cBarsCount; i++) + { + isCIndexBearish = isCIndexBearish && cBars[i].IsBearish(); + } + + // + bool isPIndexBearish = true; + for (int i = 0; i < pBarsCount; i++) + { + isPIndexBearish = isPIndexBearish && pBars[i].IsBearish(); + } + + // + result = isCIndexBearish && + !isPIndexBearish; + + // + return result; + } + + // + bool IsBullishSorted( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + int cIndex = barIndex; + int pIndex = cIndex + 1; + + // + // Current ... + + // + XOHCL cCBar; + result = CAsOHCL(cCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL cPBar; + result = CAsOHCL(cPBar, pIndex); + if (!result) + { + return result; + } + + // + // Short ... + + // + XOHCL sCBar; + result = SAsOHCL(sCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL sPBar; + result = SAsOHCL(sPBar, pIndex); + if (!result) + { + return result; + } + + // + // Medium ... + + // + XOHCL mCBar; + result = MAsOHCL(mCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL mPBar; + result = MAsOHCL(mPBar, pIndex); + if (!result) + { + return result; + } + + // + // Long ... + + // + XOHCL lCBar; + result = LAsOHCL(lCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL lPBar; + result = LAsOHCL(lPBar, pIndex); + if (!result) + { + return result; + } + + // + // Hind ... + + // + XOHCL hCBar; + result = HAsOHCL(hCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL hPBar; + result = HAsOHCL(hPBar, pIndex); + if (!result) + { + return result; + } + + // + bool isCBullish = + // + cCBar.IsBullish() && + sCBar.IsBullish() && + mCBar.IsBullish() && + lCBar.IsBullish() && + hCBar.IsBullish() + // + ; + + // + bool isCSorted = + // + cCBar.high > sCBar.high && + sCBar.high > mCBar.high && + mCBar.high > lCBar.high && + lCBar.high > hCBar.high + // + ; + + // + bool isCPrepred = isCBullish && + isCSorted; + + // + bool isPBullish = + // + cPBar.IsBullish() && + sPBar.IsBullish() && + mPBar.IsBullish() && + lPBar.IsBullish() && + hPBar.IsBullish() + // + ; + + // + bool isPSorted = + // + cPBar.high > sPBar.high && + sPBar.high > mPBar.high && + mPBar.high > lPBar.high && + lPBar.high > hPBar.high + // + ; + + // + bool isPPrepred = isPBullish && + isPSorted; + + // + result = isCPrepred && + !isPPrepred; + + // + return result; + } + + // + bool IsBearishSorted( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + int cIndex = barIndex; + int pIndex = cIndex + 1; + + // + // Current ... + + // + XOHCL cCBar; + result = CAsOHCL(cCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL cPBar; + result = CAsOHCL(cPBar, pIndex); + if (!result) + { + return result; + } + + // + // Short ... + + // + XOHCL sCBar; + result = SAsOHCL(sCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL sPBar; + result = SAsOHCL(sPBar, pIndex); + if (!result) + { + return result; + } + + // + // Medium ... + + // + XOHCL mCBar; + result = MAsOHCL(mCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL mPBar; + result = MAsOHCL(mPBar, pIndex); + if (!result) + { + return result; + } + + // + // Long ... + + // + XOHCL lCBar; + result = LAsOHCL(lCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL lPBar; + result = LAsOHCL(lPBar, pIndex); + if (!result) + { + return result; + } + + // + // Hind ... + + // + XOHCL hCBar; + result = HAsOHCL(hCBar, cIndex); + if (!result) + { + return result; + } + + // + XOHCL hPBar; + result = HAsOHCL(hPBar, pIndex); + if (!result) + { + return result; + } + + // + bool isCBearish = + // + cCBar.IsBearish() && + sCBar.IsBearish() && + mCBar.IsBearish() && + lCBar.IsBearish() && + hCBar.IsBearish() + // + ; + + // + bool isCSorted = + // + cCBar.low < sCBar.low && + sCBar.low < mCBar.low && + mCBar.low < lCBar.low && + lCBar.low < hCBar.low + // + ; + + // + bool isCPrepred = isCBearish && + isCSorted; + + // + bool isPBearish = + // + cPBar.IsBearish() && + sPBar.IsBearish() && + mPBar.IsBearish() && + lPBar.IsBearish() && + hPBar.IsBearish() + // + ; + + // + bool isPSorted = + // + cPBar.low < sPBar.low && + sPBar.low < mPBar.low && + mPBar.low < lPBar.low && + lPBar.low < hPBar.low + // + ; + + // + bool isPPrepred = isPBearish && + isPSorted; + + // + result = isCPrepred && + !isPPrepred; + + // + return result; + } + + // + // Check All Cycles Switched to Bullish or not ... + bool IsSwitchedToBullish( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + result = IsValidSize(cyclesCount); + if (!result) + { + return result; + } + + // + result = IsCyclesSwitchedToBullish( + barIndex, + cycles // + ); + + // + return result; + } + + // + // Check All Cycles Switched to Bearish or not ... + bool IsSwitchedToBearish( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + result = IsValidSize(cyclesCount); + if (!result) + { + return result; + } + + // + result = IsCyclesSwitchedToBearish( + barIndex, + cycles // + ); + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHHKConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + CopyCAsOHCL( + zIndex, + loopback, + conditions.cBars // + ); + + // + // Short ... + CopySAsOHCL( + zIndex, + loopback, + conditions.sBars // + ); + + // + // Medium ... + CopyMAsOHCL( + zIndex, + loopback, + conditions.mBars // + ); + + // + // Long ... + CopyLAsOHCL( + zIndex, + loopback, + conditions.lBars // + ); + + // + // Hind ... + CopyHAsOHCL( + zIndex, + loopback, + conditions.hBars // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + + // + // Current ... + + // + bool isCBullish = conditions.cBars[cIndex].IsBullish(); + bool isCBullishPrev = conditions.cBars[pIndex].IsBullish(); + + // + bool isCBearish = conditions.cBars[cIndex].IsBearish(); + bool isCBearishPrev = conditions.cBars[pIndex].IsBearish(); + + // + bool isCSwitchedToBullish = isCBullish && + !isCBullishPrev; + bool isCSwitchedToBearish = isCBearish && + !isCBearishPrev; + + // + bool isCloseOverCHigh = cBar.close > conditions.cBars[cIndex].high; + bool isCloseUnderCLow = cBar.close < conditions.cBars[cIndex].low; + + // + conditions.isCBullish = isCBullish; + conditions.isCSwitchedToBullish = isCSwitchedToBullish; + conditions.isCBearish = isCBearish; + conditions.isCSwitchedToBearish = isCSwitchedToBearish; + + // + conditions.isCloseOverCHigh = isCloseOverCHigh; + conditions.isCloseUnderCLow = isCloseUnderCLow; + + // + // Short ... + + // + bool isSBullish = conditions.sBars[cIndex].IsBullish(); + bool isSBullishPrev = conditions.sBars[pIndex].IsBullish(); + + // + bool isSBearish = conditions.sBars[cIndex].IsBearish(); + bool isSBearishPrev = conditions.sBars[pIndex].IsBearish(); + + // + bool isSSwitchedToBullish = isSBullish && + !isSBullishPrev; + bool isSSwitchedToBearish = isSBearish && + !isSBearishPrev; + + // + bool isCloseOverSHigh = cBar.close > conditions.sBars[cIndex].high; + bool isCloseUnderSLow = cBar.close < conditions.sBars[cIndex].low; + + // + conditions.isSBullish = isSBullish; + conditions.isSSwitchedToBullish = isSSwitchedToBullish; + conditions.isSBearish = isSBearish; + conditions.isSSwitchedToBearish = isSSwitchedToBearish; + + // + conditions.isCloseOverSHigh = isCloseOverSHigh; + conditions.isCloseUnderSLow = isCloseUnderSLow; + + // + // Medium ... + + // + bool isMBullish = conditions.mBars[cIndex].IsBullish(); + bool isMBullishPrev = conditions.mBars[pIndex].IsBullish(); + + // + bool isMBearish = conditions.mBars[cIndex].IsBearish(); + bool isMBearishPrev = conditions.mBars[pIndex].IsBearish(); + + // + bool isMSwitchedToBullish = isMBullish && + !isMBullishPrev; + bool isMSwitchedToBearish = isMBearish && + !isMBearishPrev; + + // + bool isCloseOverMHigh = cBar.close > conditions.mBars[cIndex].high; + bool isCloseUnderMLow = cBar.close < conditions.mBars[cIndex].low; + + // + conditions.isMBullish = isMBullish; + conditions.isMSwitchedToBullish = isMSwitchedToBullish; + conditions.isMBearish = isMBearish; + conditions.isMSwitchedToBearish = isMSwitchedToBearish; + + // + conditions.isCloseOverMHigh = isCloseOverMHigh; + conditions.isCloseUnderMLow = isCloseUnderMLow; + + // + // Long ... + + // + bool isLBullish = conditions.lBars[cIndex].IsBullish(); + bool isLBullishPrev = conditions.lBars[pIndex].IsBullish(); + + // + bool isLBearish = conditions.lBars[cIndex].IsBearish(); + bool isLBearishPrev = conditions.lBars[pIndex].IsBearish(); + + // + bool isLSwitchedToBullish = isLBullish && + !isLBullishPrev; + bool isLSwitchedToBearish = isLBearish && + !isLBearishPrev; + + // + bool isCloseOverLHigh = cBar.close > conditions.lBars[cIndex].high; + bool isCloseUnderLLow = cBar.close < conditions.lBars[cIndex].low; + + // + conditions.isLBullish = isLBullish; + conditions.isLSwitchedToBullish = isLSwitchedToBullish; + conditions.isLBearish = isLBearish; + conditions.isLSwitchedToBearish = isLSwitchedToBearish; + + // + conditions.isCloseOverLHigh = isCloseOverLHigh; + conditions.isCloseUnderLLow = isCloseUnderLLow; + + // + // Hind ... + + // + bool isHBullish = conditions.hBars[cIndex].IsBullish(); + bool isHBullishPrev = conditions.hBars[pIndex].IsBullish(); + + // + bool isHBearish = conditions.hBars[cIndex].IsBearish(); + bool isHBearishPrev = conditions.hBars[pIndex].IsBearish(); + + // + bool isHSwitchedToBullish = isHBullish && + !isHBullishPrev; + bool isHSwitchedToBearish = isHBearish && + !isHBearishPrev; + + // + bool isCloseOverHHigh = cBar.close > conditions.hBars[cIndex].high; + bool isCloseUnderHLow = cBar.close < conditions.hBars[cIndex].low; + + // + conditions.isHBullish = isHBullish; + conditions.isHSwitchedToBullish = isHSwitchedToBullish; + conditions.isHBearish = isHBearish; + conditions.isHSwitchedToBearish = isHSwitchedToBearish; + + // + conditions.isCloseOverHHigh = isCloseOverHHigh; + conditions.isCloseUnderHLow = isCloseUnderHLow; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHHKInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cOpenBuffer[]; + double cHighBuffer[]; + double cLowBuffer[]; + double cCloseBuffer[]; + + // + // Short ... + double sOpenBuffer[]; + double sHighBuffer[]; + double sLowBuffer[]; + double sCloseBuffer[]; + + // + // Medium ... + double mOpenBuffer[]; + double mHighBuffer[]; + double mLowBuffer[]; + double mCloseBuffer[]; + + // + // Long ... + double lOpenBuffer[]; + double lHighBuffer[]; + double lLowBuffer[]; + double lCloseBuffer[]; + + // + // Hind ... + double hOpenBuffer[]; + double hHighBuffer[]; + double hLowBuffer[]; + double hCloseBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + + // + // Open ... + CopyBuffer( + mHandler, + XCHHK_CO_LINE, + 0, + totalBars, + cOpenBuffer + // + ); + + // + // High ... + CopyBuffer( + mHandler, + XCHHK_CH_LINE, + 0, + totalBars, + cHighBuffer + // + ); + + // + // Low ... + CopyBuffer( + mHandler, + XCHHK_CL_LINE, + 0, + totalBars, + cLowBuffer + // + ); + + // + // Close ... + CopyBuffer( + mHandler, + XCHHK_CC_LINE, + 0, + totalBars, + cCloseBuffer + // + ); + + // + // Short ... + + // + // Open ... + CopyBuffer( + mHandler, + XCHHK_SO_LINE, + 0, + totalBars, + sOpenBuffer + // + ); + + // + // High ... + CopyBuffer( + mHandler, + XCHHK_SH_LINE, + 0, + totalBars, + sHighBuffer + // + ); + + // + // Low ... + CopyBuffer( + mHandler, + XCHHK_SL_LINE, + 0, + totalBars, + sLowBuffer + // + ); + + // + // Close ... + CopyBuffer( + mHandler, + XCHHK_SC_LINE, + 0, + totalBars, + sCloseBuffer + // + ); + + // + // Medium ... + + // + // Open ... + CopyBuffer( + mHandler, + XCHHK_MO_LINE, + 0, + totalBars, + mOpenBuffer + // + ); + + // + // High ... + CopyBuffer( + mHandler, + XCHHK_MH_LINE, + 0, + totalBars, + mHighBuffer + // + ); + + // + // Low ... + CopyBuffer( + mHandler, + XCHHK_ML_LINE, + 0, + totalBars, + mLowBuffer + // + ); + + // + // Close ... + CopyBuffer( + mHandler, + XCHHK_MC_LINE, + 0, + totalBars, + mCloseBuffer + // + ); + + // + // Long ... + + // + // Open ... + CopyBuffer( + mHandler, + XCHHK_LO_LINE, + 0, + totalBars, + lOpenBuffer + // + ); + + // + // High ... + CopyBuffer( + mHandler, + XCHHK_LH_LINE, + 0, + totalBars, + lHighBuffer + // + ); + + // + // Low ... + CopyBuffer( + mHandler, + XCHHK_LL_LINE, + 0, + totalBars, + lLowBuffer + // + ); + + // + // Close ... + CopyBuffer( + mHandler, + XCHHK_LC_LINE, + 0, + totalBars, + lCloseBuffer + // + ); + + // + // Hind ... + + // + // Open ... + CopyBuffer( + mHandler, + XCHHK_HO_LINE, + 0, + totalBars, + hOpenBuffer + // + ); + + // + // High ... + CopyBuffer( + mHandler, + XCHHK_HH_LINE, + 0, + totalBars, + hHighBuffer + // + ); + + // + // Low ... + CopyBuffer( + mHandler, + XCHHK_HL_LINE, + 0, + totalBars, + hLowBuffer + // + ); + + // + // Close ... + CopyBuffer( + mHandler, + XCHHK_HC_LINE, + 0, + totalBars, + hCloseBuffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchich.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchich.helper.mq5 new file mode 100644 index 00000000..e12bb338 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchich.helper.mq5 @@ -0,0 +1,5718 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHICHHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Ichimoku Lines Calculator Mode ... +enum ENUM_X_ICHIMOKU_CALCULATION_MODE +{ + // + X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low + X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close +}; + +// +enum ENUM_XCHICH_BUFFERS +{ + // + // Current ... + XCHICH_C_TK_LINE = 0, + XCHICH_C_KJ_LINE = 1, + XCHICH_C_CH_LINE = 2, + XCHICH_C_SSA_LINE = 3, + XCHICH_C_SSB_LINE = 4, + // + // Short ... + XCHICH_S_TK_LINE = 5, + XCHICH_S_KJ_LINE = 6, + XCHICH_S_CH_LINE = 7, + XCHICH_S_SSA_LINE = 8, + XCHICH_S_SSB_LINE = 9, + // + // Medium ... + XCHICH_M_TK_LINE = 10, + XCHICH_M_KJ_LINE = 11, + XCHICH_M_CH_LINE = 12, + XCHICH_M_SSA_LINE = 13, + XCHICH_M_SSB_LINE = 14, + // + // Long ... + XCHICH_L_TK_LINE = 15, + XCHICH_L_KJ_LINE = 16, + XCHICH_L_CH_LINE = 17, + XCHICH_L_SSA_LINE = 18, + XCHICH_L_SSB_LINE = 19, + // + // Hind ... + XCHICH_H_TK_LINE = 20, + XCHICH_H_KJ_LINE = 21, + XCHICH_H_CH_LINE = 22, + XCHICH_H_SSA_LINE = 23, + XCHICH_H_SSB_LINE = 24, +}; + +// +// Input Models ... +struct XCHICHInputs +{ + // + // Props ... + + // + // Market ... + + // + // TENKANSEN ... + + // + // Tenkan Sen ... + int tenkanSenLength; // Length + ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode; // Calculation Mode + + // + // KIJUNSEN ... + + // + // Kijun Sen ... + int kijunSenLength; // Length + ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode; // Calculation Mode + + // + // SENKOUSPANB ... + + // + // Senkou Span B ... + int senkouSpanBLength; // Length + ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode; // Calculation Mode + + // + // CHIKOUSPAN ... + + // + // Chikou Span ... + ENUM_APPLIED_PRICE chikuoSpanAppliedTo; // Price Type + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + + // + // Ichimoku ... + bool showTenkanSen; // Show Tenkan Sen + bool showKijunSen; // Show Kijun Sen + bool showChikouSpan; // Show Chikou Span + bool showSenkouSpanA; // Show Senkou Span A + bool showSenkouSpanB; // Show Senkou Span B + bool showKumo; // Show Kumo + bool shiftKumo; // Shift Kumo to Future + + // + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHICHInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + kijunSenLength = 0; + tenkanSenLength = 0; + senkouSpanBLength = 0; + kijunSenMode = X_XICH_HH_LL_MODE; + tenkanSenMode = X_XICH_HH_LL_MODE; + chikuoSpanAppliedTo = PRICE_CLOSE; + senkouSpanBMode = X_XICH_HH_LL_MODE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showTenkanSen = false; + showKijunSen = false; + showChikouSpan = false; + showSenkouSpanA = false; + showSenkouSpanB = false; + showKumo = false; + shiftKumo = true; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + kijunSenLength = 26; + tenkanSenLength = 9; + senkouSpanBLength = 52; + kijunSenMode = X_XICH_HH_LL_MODE; + tenkanSenMode = X_XICH_HH_LL_MODE; + chikuoSpanAppliedTo = PRICE_CLOSE; + senkouSpanBMode = X_XICH_HH_LL_MODE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showTenkanSen = true; + showKijunSen = true; + showChikouSpan = true; + showSenkouSpanA = true; + showSenkouSpanB = true; + showKumo = true; + shiftKumo = true; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + (tenkanSenLength > 2 && + kijunSenLength > tenkanSenLength && + senkouSpanBLength > kijunSenLength) + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(tenkanSenLength, kijunSenLength); + result = MathMax(result, senkouSpanBLength); + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHICHConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cTK[]; + double cKJ[]; + double cChik[]; + double cSSA[]; + double cSSB[]; + double cFSSA[]; + double cFSSB[]; + + // + // Short ... + double sTK[]; + double sKJ[]; + double sChik[]; + double sSSA[]; + double sSSB[]; + double sFSSA[]; + double sFSSB[]; + + // + // Medium ... + double mTK[]; + double mKJ[]; + double mChik[]; + double mSSA[]; + double mSSB[]; + double mFSSA[]; + double mFSSB[]; + + // + // Long ... + double lTK[]; + double lKJ[]; + double lChik[]; + double lSSA[]; + double lSSB[]; + double lFSSA[]; + double lFSSB[]; + + // + // Hind ... + double hTK[]; + double hKJ[]; + double hChik[]; + double hSSA[]; + double hSSB[]; + double hFSSA[]; + double hFSSB[]; + + // + // Conditions ... + + // + // Current ... + + // + bool isCClosedOverKijunSen; + bool isCClosedUnderKijunSen; + bool isCTenkanSenOverKijunSen; + bool isCTenkanSenUnderKijunSen; + bool isCTenkanSenCrossedOverKijunSen; + bool isCTenkanSenCrossedUnderKijunSen; + + // + bool isCSenkouSpanAOverB; + bool isCSenkouSpanAUnderB; + bool isCSenkouSpanAOverLast; + bool isCSenkouSpanAUnderLast; + bool isCFutureSenkouSpanAOverB; + bool isCFutureSenkouSpanAUnderB; + bool isCFutureSenkouSpanAOverLast; + bool isCFutureSenkouSpanAUnderLast; + + // + bool isCSenkouSpanACrossedOverB; + bool isCSenkouSpanACrossedUnderB; + bool isCSenkouSpanACrossedOverLast; + bool isCSenkouSpanACrossedUnderLast; + bool isCFutureSenkouSpanACrossedOverB; + bool isCFutureSenkouSpanACrossedUnderB; + bool isCFutureSenkouSpanACrossedOverLast; + bool isCFutureSenkouSpanACrossedUnderLast; + + // + // Short ... + + // + bool isSClosedOverKijunSen; + bool isSClosedUnderKijunSen; + bool isSTenkanSenOverKijunSen; + bool isSTenkanSenUnderKijunSen; + bool isSTenkanSenCrossedOverKijunSen; + bool isSTenkanSenCrossedUnderKijunSen; + + // + bool isSSenkouSpanAOverB; + bool isSSenkouSpanAUnderB; + bool isSSenkouSpanAOverLast; + bool isSSenkouSpanAUnderLast; + bool isSFutureSenkouSpanAOverB; + bool isSFutureSenkouSpanAUnderB; + bool isSFutureSenkouSpanAOverLast; + bool isSFutureSenkouSpanAUnderLast; + + // + bool isSSenkouSpanACrossedOverB; + bool isSSenkouSpanACrossedUnderB; + bool isSSenkouSpanACrossedOverLast; + bool isSSenkouSpanACrossedUnderLast; + bool isSFutureSenkouSpanACrossedOverB; + bool isSFutureSenkouSpanACrossedUnderB; + bool isSFutureSenkouSpanACrossedOverLast; + bool isSFutureSenkouSpanACrossedUnderLast; + + // + // Medium ... + + // + bool isMClosedOverKijunSen; + bool isMClosedUnderKijunSen; + bool isMTenkanSenOverKijunSen; + bool isMTenkanSenUnderKijunSen; + bool isMTenkanSenCrossedOverKijunSen; + bool isMTenkanSenCrossedUnderKijunSen; + + // + bool isMSenkouSpanAOverB; + bool isMSenkouSpanAUnderB; + bool isMSenkouSpanAOverLast; + bool isMSenkouSpanAUnderLast; + bool isMFutureSenkouSpanAOverB; + bool isMFutureSenkouSpanAUnderB; + bool isMFutureSenkouSpanAOverLast; + bool isMFutureSenkouSpanAUnderLast; + + // + bool isMSenkouSpanACrossedOverB; + bool isMSenkouSpanACrossedUnderB; + bool isMSenkouSpanACrossedOverLast; + bool isMSenkouSpanACrossedUnderLast; + bool isMFutureSenkouSpanACrossedOverB; + bool isMFutureSenkouSpanACrossedUnderB; + bool isMFutureSenkouSpanACrossedOverLast; + bool isMFutureSenkouSpanACrossedUnderLast; + + // + // Long ... + + // + bool isLClosedOverKijunSen; + bool isLClosedUnderKijunSen; + bool isLTenkanSenOverKijunSen; + bool isLTenkanSenUnderKijunSen; + bool isLTenkanSenCrossedOverKijunSen; + bool isLTenkanSenCrossedUnderKijunSen; + + // + bool isLSenkouSpanAOverB; + bool isLSenkouSpanAUnderB; + bool isLSenkouSpanAOverLast; + bool isLSenkouSpanAUnderLast; + bool isLFutureSenkouSpanAOverB; + bool isLFutureSenkouSpanAUnderB; + bool isLFutureSenkouSpanAOverLast; + bool isLFutureSenkouSpanAUnderLast; + + // + bool isLSenkouSpanACrossedOverB; + bool isLSenkouSpanACrossedUnderB; + bool isLSenkouSpanACrossedOverLast; + bool isLSenkouSpanACrossedUnderLast; + bool isLFutureSenkouSpanACrossedOverB; + bool isLFutureSenkouSpanACrossedUnderB; + bool isLFutureSenkouSpanACrossedOverLast; + bool isLFutureSenkouSpanACrossedUnderLast; + + // + // Hind ... + + // + bool isHClosedOverKijunSen; + bool isHClosedUnderKijunSen; + bool isHTenkanSenOverKijunSen; + bool isHTenkanSenUnderKijunSen; + bool isHTenkanSenCrossedOverKijunSen; + bool isHTenkanSenCrossedUnderKijunSen; + + // + bool isHSenkouSpanAOverB; + bool isHSenkouSpanAUnderB; + bool isHSenkouSpanAOverLast; + bool isHSenkouSpanAUnderLast; + bool isHFutureSenkouSpanAOverB; + bool isHFutureSenkouSpanAUnderB; + bool isHFutureSenkouSpanAOverLast; + bool isHFutureSenkouSpanAUnderLast; + + // + bool isHSenkouSpanACrossedOverB; + bool isHSenkouSpanACrossedUnderB; + bool isHSenkouSpanACrossedOverLast; + bool isHSenkouSpanACrossedUnderLast; + bool isHFutureSenkouSpanACrossedOverB; + bool isHFutureSenkouSpanACrossedUnderB; + bool isHFutureSenkouSpanACrossedOverLast; + bool isHFutureSenkouSpanACrossedUnderLast; + + // + void Clean() + { + // + // Buffers ... + Clean(cTK); + Clean(cKJ); + Clean(cChik); + Clean(cSSA); + Clean(cSSB); + Clean(cFSSA); + Clean(cFSSB); + Clean(sTK); + Clean(sKJ); + Clean(sChik); + Clean(sSSA); + Clean(sSSB); + Clean(sFSSA); + Clean(sFSSB); + Clean(mTK); + Clean(mKJ); + Clean(mChik); + Clean(mSSA); + Clean(mSSB); + Clean(mFSSA); + Clean(mFSSB); + Clean(lTK); + Clean(lKJ); + Clean(lChik); + Clean(lSSA); + Clean(lSSB); + Clean(lFSSA); + Clean(lFSSB); + Clean(hTK); + Clean(hKJ); + Clean(hChik); + Clean(hSSA); + Clean(hSSB); + Clean(hFSSA); + Clean(hFSSB); + + // + ArraySetAsSeries(cTK, true); + ArraySetAsSeries(cKJ, true); + ArraySetAsSeries(cChik, true); + ArraySetAsSeries(cSSA, true); + ArraySetAsSeries(cSSB, true); + ArraySetAsSeries(cFSSA, true); + ArraySetAsSeries(cFSSB, true); + ArraySetAsSeries(sTK, true); + ArraySetAsSeries(sKJ, true); + ArraySetAsSeries(sChik, true); + ArraySetAsSeries(sSSA, true); + ArraySetAsSeries(sSSB, true); + ArraySetAsSeries(sFSSA, true); + ArraySetAsSeries(sFSSB, true); + ArraySetAsSeries(mTK, true); + ArraySetAsSeries(mKJ, true); + ArraySetAsSeries(mChik, true); + ArraySetAsSeries(mSSA, true); + ArraySetAsSeries(mSSB, true); + ArraySetAsSeries(mFSSA, true); + ArraySetAsSeries(mFSSB, true); + ArraySetAsSeries(lTK, true); + ArraySetAsSeries(lKJ, true); + ArraySetAsSeries(lChik, true); + ArraySetAsSeries(lSSA, true); + ArraySetAsSeries(lSSB, true); + ArraySetAsSeries(lFSSA, true); + ArraySetAsSeries(lFSSB, true); + ArraySetAsSeries(hTK, true); + ArraySetAsSeries(hKJ, true); + ArraySetAsSeries(hChik, true); + ArraySetAsSeries(hSSA, true); + ArraySetAsSeries(hSSB, true); + ArraySetAsSeries(hFSSA, true); + ArraySetAsSeries(hFSSB, true); + + // + // Current ... + + // + isCClosedOverKijunSen = false; + isCClosedUnderKijunSen = false; + isCTenkanSenOverKijunSen = false; + isCTenkanSenUnderKijunSen = false; + isCTenkanSenCrossedOverKijunSen = false; + isCTenkanSenCrossedUnderKijunSen = false; + isCSenkouSpanAOverB = false; + isCSenkouSpanAUnderB = false; + isCSenkouSpanAOverLast = false; + isCSenkouSpanAUnderLast = false; + isCFutureSenkouSpanAOverB = false; + isCFutureSenkouSpanAUnderB = false; + isCFutureSenkouSpanAOverLast = false; + isCFutureSenkouSpanAUnderLast = false; + isCSenkouSpanACrossedOverB = false; + isCSenkouSpanACrossedUnderB = false; + isCSenkouSpanACrossedOverLast = false; + isCSenkouSpanACrossedUnderLast = false; + isCFutureSenkouSpanACrossedOverB = false; + isCFutureSenkouSpanACrossedUnderB = false; + isCFutureSenkouSpanACrossedOverLast = false; + isCFutureSenkouSpanACrossedUnderLast = false; + + // + // Short ... + + // + isSClosedOverKijunSen = false; + isSClosedUnderKijunSen = false; + isSTenkanSenOverKijunSen = false; + isSTenkanSenUnderKijunSen = false; + isSTenkanSenCrossedOverKijunSen = false; + isSTenkanSenCrossedUnderKijunSen = false; + isSSenkouSpanAOverB = false; + isSSenkouSpanAUnderB = false; + isSSenkouSpanAOverLast = false; + isSSenkouSpanAUnderLast = false; + isSFutureSenkouSpanAOverB = false; + isSFutureSenkouSpanAUnderB = false; + isSFutureSenkouSpanAOverLast = false; + isSFutureSenkouSpanAUnderLast = false; + isSSenkouSpanACrossedOverB = false; + isSSenkouSpanACrossedUnderB = false; + isSSenkouSpanACrossedOverLast = false; + isSSenkouSpanACrossedUnderLast = false; + isSFutureSenkouSpanACrossedOverB = false; + isSFutureSenkouSpanACrossedUnderB = false; + isSFutureSenkouSpanACrossedOverLast = false; + isSFutureSenkouSpanACrossedUnderLast = false; + + // + // Medium ... + + // + isMClosedOverKijunSen = false; + isMClosedUnderKijunSen = false; + isMTenkanSenOverKijunSen = false; + isMTenkanSenUnderKijunSen = false; + isMTenkanSenCrossedOverKijunSen = false; + isMTenkanSenCrossedUnderKijunSen = false; + isMSenkouSpanAOverB = false; + isMSenkouSpanAUnderB = false; + isMSenkouSpanAOverLast = false; + isMSenkouSpanAUnderLast = false; + isMFutureSenkouSpanAOverB = false; + isMFutureSenkouSpanAUnderB = false; + isMFutureSenkouSpanAOverLast = false; + isMFutureSenkouSpanAUnderLast = false; + isMSenkouSpanACrossedOverB = false; + isMSenkouSpanACrossedUnderB = false; + isMSenkouSpanACrossedOverLast = false; + isMSenkouSpanACrossedUnderLast = false; + isMFutureSenkouSpanACrossedOverB = false; + isMFutureSenkouSpanACrossedUnderB = false; + isMFutureSenkouSpanACrossedOverLast = false; + isMFutureSenkouSpanACrossedUnderLast = false; + + // + // Long ... + + // + isLClosedOverKijunSen = false; + isLClosedUnderKijunSen = false; + isLTenkanSenOverKijunSen = false; + isLTenkanSenUnderKijunSen = false; + isLTenkanSenCrossedOverKijunSen = false; + isLTenkanSenCrossedUnderKijunSen = false; + isLSenkouSpanAOverB = false; + isLSenkouSpanAUnderB = false; + isLSenkouSpanAOverLast = false; + isLSenkouSpanAUnderLast = false; + isLFutureSenkouSpanAOverB = false; + isLFutureSenkouSpanAUnderB = false; + isLFutureSenkouSpanAOverLast = false; + isLFutureSenkouSpanAUnderLast = false; + isLSenkouSpanACrossedOverB = false; + isLSenkouSpanACrossedUnderB = false; + isLSenkouSpanACrossedOverLast = false; + isLSenkouSpanACrossedUnderLast = false; + isLFutureSenkouSpanACrossedOverB = false; + isLFutureSenkouSpanACrossedUnderB = false; + isLFutureSenkouSpanACrossedOverLast = false; + isLFutureSenkouSpanACrossedUnderLast = false; + + // + // Hind ... + + // + isHClosedOverKijunSen = false; + isHClosedUnderKijunSen = false; + isHTenkanSenOverKijunSen = false; + isHTenkanSenUnderKijunSen = false; + isHTenkanSenCrossedOverKijunSen = false; + isHTenkanSenCrossedUnderKijunSen = false; + isHSenkouSpanAOverB = false; + isHSenkouSpanAUnderB = false; + isHSenkouSpanAOverLast = false; + isHSenkouSpanAUnderLast = false; + isHFutureSenkouSpanAOverB = false; + isHFutureSenkouSpanAUnderB = false; + isHFutureSenkouSpanAOverLast = false; + isHFutureSenkouSpanAUnderLast = false; + isHSenkouSpanACrossedOverB = false; + isHSenkouSpanACrossedUnderB = false; + isHSenkouSpanACrossedOverLast = false; + isHSenkouSpanACrossedUnderLast = false; + isHFutureSenkouSpanACrossedOverB = false; + isHFutureSenkouSpanACrossedUnderB = false; + isHFutureSenkouSpanACrossedOverLast = false; + isHFutureSenkouSpanACrossedUnderLast = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Current ... + + // + if (isCClosedOverKijunSen) + { + bullishScore++; + } + if (isCTenkanSenOverKijunSen) + { + bullishScore++; + } + if (isCTenkanSenCrossedOverKijunSen) + { + bullishScore++; + } + if (isCSenkouSpanAOverB) + { + bullishScore++; + } + if (isCSenkouSpanAOverLast) + { + bullishScore++; + } + if (isCFutureSenkouSpanAOverB) + { + bullishScore++; + } + if (isCFutureSenkouSpanAOverLast) + { + bullishScore++; + } + if (isCSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isCSenkouSpanACrossedOverLast) + { + bullishScore++; + } + if (isCFutureSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isCFutureSenkouSpanACrossedOverLast) + { + bullishScore++; + } + + // + if (isCClosedUnderKijunSen) + { + bearishScore++; + } + if (isCTenkanSenUnderKijunSen) + { + bearishScore++; + } + if (isCTenkanSenCrossedUnderKijunSen) + { + bearishScore++; + } + if (isCSenkouSpanAUnderB) + { + bearishScore++; + } + if (isCSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isCFutureSenkouSpanAUnderB) + { + bearishScore++; + } + if (isCFutureSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isCSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isCSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + if (isCFutureSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isCFutureSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + + // + // Short ... + + // + if (isSClosedOverKijunSen) + { + bullishScore++; + } + if (isSTenkanSenOverKijunSen) + { + bullishScore++; + } + if (isSTenkanSenCrossedOverKijunSen) + { + bullishScore++; + } + if (isSSenkouSpanAOverB) + { + bullishScore++; + } + if (isSSenkouSpanAOverLast) + { + bullishScore++; + } + if (isSFutureSenkouSpanAOverB) + { + bullishScore++; + } + if (isSFutureSenkouSpanAOverLast) + { + bullishScore++; + } + if (isSSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isSSenkouSpanACrossedOverLast) + { + bullishScore++; + } + if (isSFutureSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isSFutureSenkouSpanACrossedOverLast) + { + bullishScore++; + } + + // + if (isSClosedUnderKijunSen) + { + bearishScore++; + } + if (isSTenkanSenUnderKijunSen) + { + bearishScore++; + } + if (isSTenkanSenCrossedUnderKijunSen) + { + bearishScore++; + } + if (isSSenkouSpanAUnderB) + { + bearishScore++; + } + if (isSSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isSFutureSenkouSpanAUnderB) + { + bearishScore++; + } + if (isSFutureSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isSSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isSSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + if (isSFutureSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isSFutureSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + + // + // Medium ... + + // + if (isMClosedOverKijunSen) + { + bullishScore++; + } + if (isMTenkanSenOverKijunSen) + { + bullishScore++; + } + if (isMTenkanSenCrossedOverKijunSen) + { + bullishScore++; + } + if (isMSenkouSpanAOverB) + { + bullishScore++; + } + if (isMSenkouSpanAOverLast) + { + bullishScore++; + } + if (isMFutureSenkouSpanAOverB) + { + bullishScore++; + } + if (isMFutureSenkouSpanAOverLast) + { + bullishScore++; + } + if (isMSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isMSenkouSpanACrossedOverLast) + { + bullishScore++; + } + if (isMFutureSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isMFutureSenkouSpanACrossedOverLast) + { + bullishScore++; + } + + // + if (isMClosedUnderKijunSen) + { + bearishScore++; + } + if (isMTenkanSenUnderKijunSen) + { + bearishScore++; + } + if (isMTenkanSenCrossedUnderKijunSen) + { + bearishScore++; + } + if (isMSenkouSpanAUnderB) + { + bearishScore++; + } + if (isMSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isMFutureSenkouSpanAUnderB) + { + bearishScore++; + } + if (isMFutureSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isMSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isMSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + if (isMFutureSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isMFutureSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + + // + // Long ... + + // + if (isLClosedOverKijunSen) + { + bullishScore++; + } + if (isLTenkanSenOverKijunSen) + { + bullishScore++; + } + if (isLTenkanSenCrossedOverKijunSen) + { + bullishScore++; + } + if (isLSenkouSpanAOverB) + { + bullishScore++; + } + if (isLSenkouSpanAOverLast) + { + bullishScore++; + } + if (isLFutureSenkouSpanAOverB) + { + bullishScore++; + } + if (isLFutureSenkouSpanAOverLast) + { + bullishScore++; + } + if (isLSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isLSenkouSpanACrossedOverLast) + { + bullishScore++; + } + if (isLFutureSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isLFutureSenkouSpanACrossedOverLast) + { + bullishScore++; + } + + // + if (isLClosedUnderKijunSen) + { + bearishScore++; + } + if (isLTenkanSenUnderKijunSen) + { + bearishScore++; + } + if (isLTenkanSenCrossedUnderKijunSen) + { + bearishScore++; + } + if (isLSenkouSpanAUnderB) + { + bearishScore++; + } + if (isLSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isLFutureSenkouSpanAUnderB) + { + bearishScore++; + } + if (isLFutureSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isLSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isLSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + if (isLFutureSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isLFutureSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + + // + // Hind ... + + // + if (isHClosedOverKijunSen) + { + bullishScore++; + } + if (isHTenkanSenOverKijunSen) + { + bullishScore++; + } + if (isHTenkanSenCrossedOverKijunSen) + { + bullishScore++; + } + if (isHSenkouSpanAOverB) + { + bullishScore++; + } + if (isHSenkouSpanAOverLast) + { + bullishScore++; + } + if (isHFutureSenkouSpanAOverB) + { + bullishScore++; + } + if (isHFutureSenkouSpanAOverLast) + { + bullishScore++; + } + if (isHSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isHSenkouSpanACrossedOverLast) + { + bullishScore++; + } + if (isHFutureSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isHFutureSenkouSpanACrossedOverLast) + { + bullishScore++; + } + + // + if (isHClosedUnderKijunSen) + { + bearishScore++; + } + if (isHTenkanSenUnderKijunSen) + { + bearishScore++; + } + if (isHTenkanSenCrossedUnderKijunSen) + { + bearishScore++; + } + if (isHSenkouSpanAUnderB) + { + bearishScore++; + } + if (isHSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isHFutureSenkouSpanAUnderB) + { + bearishScore++; + } + if (isHFutureSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isHSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isHSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + if (isHFutureSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isHFutureSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Current ... + ToString("isCClosedOverKijunSen", isCClosedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isCClosedUnderKijunSen", isCClosedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isCTenkanSenOverKijunSen", isCTenkanSenOverKijunSen, ignoreFalseConditions, separator) + + ToString("isCTenkanSenUnderKijunSen", isCTenkanSenUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isCTenkanSenCrossedOverKijunSen", isCTenkanSenCrossedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isCTenkanSenCrossedUnderKijunSen", isCTenkanSenCrossedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanAOverB", isCSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanAUnderB", isCSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanAOverLast", isCSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanAUnderLast", isCSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanAOverB", isCFutureSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanAUnderB", isCFutureSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanAOverLast", isCFutureSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanAUnderLast", isCFutureSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanACrossedOverB", isCSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanACrossedUnderB", isCSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanACrossedOverLast", isCSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isCSenkouSpanACrossedUnderLast", isCSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanACrossedOverB", isCFutureSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanACrossedUnderB", isCFutureSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanACrossedOverLast", isCFutureSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isCFutureSenkouSpanACrossedUnderLast", isCFutureSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSClosedOverKijunSen", isSClosedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isSClosedUnderKijunSen", isSClosedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isSTenkanSenOverKijunSen", isSTenkanSenOverKijunSen, ignoreFalseConditions, separator) + + ToString("isSTenkanSenUnderKijunSen", isSTenkanSenUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isSTenkanSenCrossedOverKijunSen", isSTenkanSenCrossedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isSTenkanSenCrossedUnderKijunSen", isSTenkanSenCrossedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanAOverB", isSSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanAUnderB", isSSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanAOverLast", isSSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanAUnderLast", isSSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanAOverB", isSFutureSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanAUnderB", isSFutureSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanAOverLast", isSFutureSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanAUnderLast", isSFutureSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanACrossedOverB", isSSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanACrossedUnderB", isSSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanACrossedOverLast", isSSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isSSenkouSpanACrossedUnderLast", isSSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanACrossedOverB", isSFutureSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanACrossedUnderB", isSFutureSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanACrossedOverLast", isSFutureSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isSFutureSenkouSpanACrossedUnderLast", isSFutureSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMClosedOverKijunSen", isMClosedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isMClosedUnderKijunSen", isMClosedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isMTenkanSenOverKijunSen", isMTenkanSenOverKijunSen, ignoreFalseConditions, separator) + + ToString("isMTenkanSenUnderKijunSen", isMTenkanSenUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isMTenkanSenCrossedOverKijunSen", isMTenkanSenCrossedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isMTenkanSenCrossedUnderKijunSen", isMTenkanSenCrossedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanAOverB", isMSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanAUnderB", isMSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanAOverLast", isMSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanAUnderLast", isMSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanAOverB", isMFutureSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanAUnderB", isMFutureSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanAOverLast", isMFutureSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanAUnderLast", isMFutureSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanACrossedOverB", isMSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanACrossedUnderB", isMSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanACrossedOverLast", isMSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isMSenkouSpanACrossedUnderLast", isMSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanACrossedOverB", isMFutureSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanACrossedUnderB", isMFutureSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanACrossedOverLast", isMFutureSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isMFutureSenkouSpanACrossedUnderLast", isMFutureSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLClosedOverKijunSen", isLClosedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isLClosedUnderKijunSen", isLClosedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isLTenkanSenOverKijunSen", isLTenkanSenOverKijunSen, ignoreFalseConditions, separator) + + ToString("isLTenkanSenUnderKijunSen", isLTenkanSenUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isLTenkanSenCrossedOverKijunSen", isLTenkanSenCrossedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isLTenkanSenCrossedUnderKijunSen", isLTenkanSenCrossedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanAOverB", isLSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanAUnderB", isLSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanAOverLast", isLSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanAUnderLast", isLSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanAOverB", isLFutureSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanAUnderB", isLFutureSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanAOverLast", isLFutureSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanAUnderLast", isLFutureSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanACrossedOverB", isLSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanACrossedUnderB", isLSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanACrossedOverLast", isLSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isLSenkouSpanACrossedUnderLast", isLSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanACrossedOverB", isLFutureSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanACrossedUnderB", isLFutureSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanACrossedOverLast", isLFutureSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isLFutureSenkouSpanACrossedUnderLast", isLFutureSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHClosedOverKijunSen", isHClosedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isHClosedUnderKijunSen", isHClosedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isHTenkanSenOverKijunSen", isHTenkanSenOverKijunSen, ignoreFalseConditions, separator) + + ToString("isHTenkanSenUnderKijunSen", isHTenkanSenUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isHTenkanSenCrossedOverKijunSen", isHTenkanSenCrossedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isHTenkanSenCrossedUnderKijunSen", isHTenkanSenCrossedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanAOverB", isHSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanAUnderB", isHSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanAOverLast", isHSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanAUnderLast", isHSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanAOverB", isHFutureSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanAUnderB", isHFutureSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanAOverLast", isHFutureSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanAUnderLast", isHFutureSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanACrossedOverB", isHSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanACrossedUnderB", isHSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanACrossedOverLast", isHSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isHSenkouSpanACrossedUnderLast", isHSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanACrossedOverB", isHFutureSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanACrossedUnderB", isHFutureSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanACrossedOverLast", isHFutureSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isHFutureSenkouSpanACrossedUnderLast", isHFutureSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHICH"; + } +}; + +// +// Class ... +class XSCXCHICHHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHICHHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHICHHelper() + { + // + Clean(cTKBuffer); + Clean(cKJBuffer); + Clean(cChikBuffer); + Clean(cSSABuffer); + Clean(cSSBBuffer); + Clean(sTKBuffer); + Clean(sKJBuffer); + Clean(sChikBuffer); + Clean(sSSABuffer); + Clean(sSSBBuffer); + Clean(mTKBuffer); + Clean(mKJBuffer); + Clean(mChikBuffer); + Clean(mSSABuffer); + Clean(mSSBBuffer); + Clean(lTKBuffer); + Clean(lKJBuffer); + Clean(lChikBuffer); + Clean(lSSABuffer); + Clean(lSSBBuffer); + Clean(hTKBuffer); + Clean(hKJBuffer); + Clean(hChikBuffer); + Clean(hSSABuffer); + Clean(hSSBBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHICHInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cTKBuffer, true); + ArraySetAsSeries(cKJBuffer, true); + ArraySetAsSeries(cChikBuffer, true); + ArraySetAsSeries(cSSABuffer, true); + ArraySetAsSeries(cSSBBuffer, true); + ArraySetAsSeries(sTKBuffer, true); + ArraySetAsSeries(sKJBuffer, true); + ArraySetAsSeries(sChikBuffer, true); + ArraySetAsSeries(sSSABuffer, true); + ArraySetAsSeries(sSSBBuffer, true); + ArraySetAsSeries(mTKBuffer, true); + ArraySetAsSeries(mKJBuffer, true); + ArraySetAsSeries(mChikBuffer, true); + ArraySetAsSeries(mSSABuffer, true); + ArraySetAsSeries(mSSBBuffer, true); + ArraySetAsSeries(lTKBuffer, true); + ArraySetAsSeries(lKJBuffer, true); + ArraySetAsSeries(lChikBuffer, true); + ArraySetAsSeries(lSSABuffer, true); + ArraySetAsSeries(lSSBBuffer, true); + ArraySetAsSeries(hTKBuffer, true); + ArraySetAsSeries(hKJBuffer, true); + ArraySetAsSeries(hChikBuffer, true); + ArraySetAsSeries(hSSABuffer, true); + ArraySetAsSeries(hSSBBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchich", + // + // Inputs ... + // + // Market ... + "", + // + // TENKANSEN ... + "", + mInputs.tenkanSenLength, // Length + mInputs.tenkanSenMode, // Calculation Mode + // + // KIJUNSEN ... + "", + mInputs.kijunSenLength, // Length + mInputs.kijunSenMode, // Calculation Mode + // + // SENKOUSPANB ... + "", + mInputs.senkouSpanBLength, // Length + mInputs.senkouSpanBMode, // Calculation Mode + // + // CHIKOUSPAN ... + "", + mInputs.chikuoSpanAppliedTo, // Price Type + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + // + // Ichimoku ... + mInputs.showTenkanSen, // Show Tenkan Sen + mInputs.showKijunSen, // Show Kijun Sen + mInputs.showChikouSpan, // Show Chikou Span + mInputs.showSenkouSpanA, // Show Senkou Span A + mInputs.showSenkouSpanB, // Show Senkou Span B + mInputs.showKumo, // Show Kumo + mInputs.shiftKumo, // Shift Kumo to Future + // + // Cycles ... + mInputs.showCurrent, // Show Current Cycle + mInputs.showShort, // Show Short Cycle + mInputs.showMedium, // Show Medium Cycle + mInputs.showLong, // Show Long Cycle + mInputs.showHind // Show Hind Cycle + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Buffers ... + + // + // Current ... + + // + // TENKANSEN ... + + // + double GetCTenkanSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cTKBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCTenkanSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cTKBuffer, + buffer, + forceClean + // + ); + } + + // + // KIJUNSEN ... + + // + double GetCKijunSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cKJBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCKijunSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cKJBuffer, + buffer, + forceClean + // + ); + } + + // + // CHIKOUSPAN ... + + // + double GetCChikouSpan( + int barIndex // Bar Index + ) + { + // + barIndex -= mInputs.kijunSenLength; + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cChikBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCChikouSpan( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - mInputs.kijunSenLength, + count, + cChikBuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANA ... + + // + double GetCSenkouSpanA( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSSABuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANB ... + + // + double GetCSenkouSpanB( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANA ... + + // + double GetCFutureSenkouSpanA( + int barIndex // Bar Index + ) + { + // + barIndex -= mInputs.kijunSenLength; + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCFutureSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - mInputs.kijunSenLength, + count, + cSSABuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANB ... + + // + double GetCFutureSenkouSpanB( + int barIndex // Bar Index + ) + { + // + barIndex -= mInputs.kijunSenLength; + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCFutureSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - mInputs.kijunSenLength, + count, + cSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + // TENKANSEN ... + + // + double GetSTenkanSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sTKBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySTenkanSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sTKBuffer, + buffer, + forceClean + // + ); + } + + // + // KIJUNSEN ... + + // + double GetSKijunSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sKJBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySKijunSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sKJBuffer, + buffer, + forceClean + // + ); + } + + // + // CHIKOUSPAN ... + + // + double GetSChikouSpan( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_SHORT, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sChikBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySChikouSpan( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_SHORT, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + sChikBuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANA ... + + // + double GetSSenkouSpanA( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSSABuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANB ... + + // + double GetSSenkouSpanB( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANA ... + + // + double GetSFutureSenkouSpanA( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_SHORT, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySFutureSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_SHORT, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + sSSABuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANB ... + + // + double GetSFutureSenkouSpanB( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_SHORT, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySFutureSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_SHORT, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + sSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + // TENKANSEN ... + + // + double GetMTenkanSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mTKBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMTenkanSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mTKBuffer, + buffer, + forceClean + // + ); + } + + // + // KIJUNSEN ... + + // + double GetMKijunSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mKJBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMKijunSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mKJBuffer, + buffer, + forceClean + // + ); + } + + // + // CHIKOUSPAN ... + + // + double GetMChikouSpan( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_MEDIUM, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mChikBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMChikouSpan( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_MEDIUM, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + mChikBuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANA ... + + // + double GetMSenkouSpanA( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSSABuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANB ... + + // + double GetMSenkouSpanB( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANA ... + + // + double GetMFutureSenkouSpanA( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_MEDIUM, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMFutureSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_MEDIUM, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + mSSABuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANB ... + + // + double GetMFutureSenkouSpanB( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_MEDIUM, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMFutureSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_MEDIUM, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + mSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + // TENKANSEN ... + + // + double GetLTenkanSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lTKBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLTenkanSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lTKBuffer, + buffer, + forceClean + // + ); + } + + // + // KIJUNSEN ... + + // + double GetLKijunSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lKJBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLKijunSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lKJBuffer, + buffer, + forceClean + // + ); + } + + // + // CHIKOUSPAN ... + + // + double GetLChikouSpan( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_LONG, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lChikBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLChikouSpan( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_LONG, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + lChikBuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANA ... + + // + double GetLSenkouSpanA( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSSABuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANB ... + + // + double GetLSenkouSpanB( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANA ... + + // + double GetLFutureSenkouSpanA( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_LONG, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLFutureSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_LONG, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + lSSABuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANB ... + + // + double GetLFutureSenkouSpanB( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_LONG, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLFutureSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_LONG, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + lSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + // TENKANSEN ... + + // + double GetHTenkanSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hTKBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHTenkanSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hTKBuffer, + buffer, + forceClean + // + ); + } + + // + // KIJUNSEN ... + + // + double GetHKijunSen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hKJBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHKijunSen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hKJBuffer, + buffer, + forceClean + // + ); + } + + // + // CHIKOUSPAN ... + + // + double GetHChikouSpan( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_HIND, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hChikBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHChikouSpan( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_HIND, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + hChikBuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANA ... + + // + double GetHSenkouSpanA( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSSABuffer, + buffer, + forceClean + // + ); + } + + // + // SENKOUSPANB ... + + // + double GetHSenkouSpanB( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANA ... + + // + double GetHFutureSenkouSpanA( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_HIND, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hSSABuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHFutureSenkouSpanA( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_HIND, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + hSSABuffer, + buffer, + forceClean + // + ); + } + + // + // FUTURESENKOUSPANB ... + + // + double GetHFutureSenkouSpanB( + int barIndex // Bar Index + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_HIND, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + barIndex -= (mInputs.kijunSenLength * cycleLength); + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hSSBBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHFutureSenkouSpanB( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int cycleLength = GetCycleLengthOn( + mPeriod, // Host + X_MARKET_CYCLE_HIND, // Cycle + mInputs.scMethod, // Method + mInputs.scPeriod // Period + ); + if (cycleLength <= 0) + { + cycleLength = 1; + } + + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start - (mInputs.kijunSenLength * cycleLength), + count, + hSSBBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + void GetCycleValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle, // Cycle + // + double &tenkanSen, + double &kijunSen, + double &chikouSpan, + double &senkouSpanA, + double &senkouSpanB, + double &futureSenkouSpanA, + double &futureSenkouSpanB // + ) + { + // + tenkanSen = 0; + kijunSen = 0; + chikouSpan = 0; + senkouSpanA = 0; + senkouSpanB = 0; + futureSenkouSpanA = 0; + futureSenkouSpanB = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + switch (cycle) + { + // + // Current ... + case X_MARKET_CYCLE_UNKNOWN: + // + tenkanSen = GetCTenkanSen(barIndex); + kijunSen = GetCKijunSen(barIndex); + chikouSpan = GetCChikouSpan(barIndex); + senkouSpanA = GetCSenkouSpanA(barIndex); + senkouSpanB = GetCSenkouSpanB(barIndex); + futureSenkouSpanA = GetCFutureSenkouSpanA(barIndex); + futureSenkouSpanB = GetCFutureSenkouSpanB(barIndex); + break; + + // + // Short ... + case X_MARKET_CYCLE_SHORT: + // + tenkanSen = GetSTenkanSen(barIndex); + kijunSen = GetSKijunSen(barIndex); + chikouSpan = GetSChikouSpan(barIndex); + senkouSpanA = GetSSenkouSpanA(barIndex); + senkouSpanB = GetSSenkouSpanB(barIndex); + futureSenkouSpanA = GetSFutureSenkouSpanA(barIndex); + futureSenkouSpanB = GetSFutureSenkouSpanB(barIndex); + break; + + // + // Medium ... + case X_MARKET_CYCLE_MEDIUM: + // + tenkanSen = GetMTenkanSen(barIndex); + kijunSen = GetMKijunSen(barIndex); + chikouSpan = GetMChikouSpan(barIndex); + senkouSpanA = GetMSenkouSpanA(barIndex); + senkouSpanB = GetMSenkouSpanB(barIndex); + futureSenkouSpanA = GetMFutureSenkouSpanA(barIndex); + futureSenkouSpanB = GetMFutureSenkouSpanB(barIndex); + break; + + // + // Long ... + case X_MARKET_CYCLE_LONG: + // + tenkanSen = GetLTenkanSen(barIndex); + kijunSen = GetLKijunSen(barIndex); + chikouSpan = GetLChikouSpan(barIndex); + senkouSpanA = GetLSenkouSpanA(barIndex); + senkouSpanB = GetLSenkouSpanB(barIndex); + futureSenkouSpanA = GetLFutureSenkouSpanA(barIndex); + futureSenkouSpanB = GetLFutureSenkouSpanB(barIndex); + break; + + // + // Hind ... + case X_MARKET_CYCLE_HIND: + // + tenkanSen = GetHTenkanSen(barIndex); + kijunSen = GetHKijunSen(barIndex); + chikouSpan = GetHChikouSpan(barIndex); + senkouSpanA = GetHSenkouSpanA(barIndex); + senkouSpanB = GetHSenkouSpanB(barIndex); + futureSenkouSpanA = GetHFutureSenkouSpanA(barIndex); + futureSenkouSpanB = GetHFutureSenkouSpanB(barIndex); + break; + } + } + + // + int GetTenkanSenOverKijunSenCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + allCycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + bool isPassed = + iTenkanSen > iKijunSen; + if (isPassed) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetTenkanSenUnderKijunSenCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + allCycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + bool isPassed = + iTenkanSen < iKijunSen; + if (isPassed) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetSenkouSpanAOverBCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + allCycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + bool isPassed = + iSenkouSpanA > iSenkouSpanB; + if (isPassed) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetSenkouSpanAUnderBCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + allCycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + bool isPassed = + iSenkouSpanA < iSenkouSpanB; + if (isPassed) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetFutureSenkouSpanAOverBCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + allCycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + bool isPassed = + iFutureSenkouSpanA > iFutureSenkouSpanB; + if (isPassed) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetFutureSenkouSpanAUnderBCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + allCycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + bool isPassed = + iFutureSenkouSpanA < iFutureSenkouSpanB; + if (isPassed) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + double GetCyclesTenkanSensMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iTenkanSen, + values // + ); + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesTenkanSensMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iTenkanSen, + values // + ); + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesKijunSensMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iKijunSen, + values // + ); + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesKijunSensMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iKijunSen, + values // + ); + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesSenkouSpanAMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iSenkouSpanA, + values // + ); + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesSenkouSpanAMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iSenkouSpanA, + values // + ); + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesSenkouSpanBMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iSenkouSpanB, + values // + ); + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesSenkouSpanBMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iSenkouSpanB, + values // + ); + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesFutureSenkouSpanAMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iFutureSenkouSpanA, + values // + ); + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesFutureSenkouSpanAMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iFutureSenkouSpanA, + values // + ); + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesFutureSenkouSpanBMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iFutureSenkouSpanB, + values // + ); + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesFutureSenkouSpanBMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + double result = 0; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + double values[]; + + // + for (int i = 0; i < count; i++) + { + // + double iTenkanSen = 0; + double iKijunSen = 0; + double iChikouSpan = 0; + double iSenkouSpanA = 0; + double iSenkouSpanB = 0; + double iFutureSenkouSpanA = 0; + double iFutureSenkouSpanB = 0; + GetCycleValues( + barIndex, + cycles[i], + iTenkanSen, + iKijunSen, + iChikouSpan, + iSenkouSpanA, + iSenkouSpanB, + iFutureSenkouSpanA, + iFutureSenkouSpanB // + ); + + // + Add( + iFutureSenkouSpanB, + values // + ); + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHICHConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + CopyCTenkanSen( + zIndex, + loopback, + conditions.cTK // + ); + CopyCKijunSen( + zIndex, + loopback, + conditions.cKJ // + ); + CopyCChikouSpan( + zIndex, + loopback, + conditions.cChik // + ); + CopyCSenkouSpanA( + zIndex, + loopback, + conditions.cSSA // + ); + CopyCSenkouSpanB( + zIndex, + loopback, + conditions.cSSB // + ); + CopyCFutureSenkouSpanA( + zIndex, + loopback, + conditions.cFSSA // + ); + CopyCFutureSenkouSpanB( + zIndex, + loopback, + conditions.cFSSB // + ); + + // + // Short ... + CopySTenkanSen( + zIndex, + loopback, + conditions.sTK // + ); + CopySKijunSen( + zIndex, + loopback, + conditions.sKJ // + ); + CopySChikouSpan( + zIndex, + loopback, + conditions.sChik // + ); + CopySSenkouSpanA( + zIndex, + loopback, + conditions.sSSA // + ); + CopySSenkouSpanB( + zIndex, + loopback, + conditions.sSSB // + ); + CopySFutureSenkouSpanA( + zIndex, + loopback, + conditions.sFSSA // + ); + CopySFutureSenkouSpanB( + zIndex, + loopback, + conditions.sFSSB // + ); + + // + // Medium ... + CopyMTenkanSen( + zIndex, + loopback, + conditions.mTK // + ); + CopyMKijunSen( + zIndex, + loopback, + conditions.mKJ // + ); + CopyMChikouSpan( + zIndex, + loopback, + conditions.mChik // + ); + CopyMSenkouSpanA( + zIndex, + loopback, + conditions.mSSA // + ); + CopyMSenkouSpanB( + zIndex, + loopback, + conditions.mSSB // + ); + CopyMFutureSenkouSpanA( + zIndex, + loopback, + conditions.mFSSA // + ); + CopyMFutureSenkouSpanB( + zIndex, + loopback, + conditions.mFSSB // + ); + + // + // Long ... + CopyLTenkanSen( + zIndex, + loopback, + conditions.lTK // + ); + CopyLKijunSen( + zIndex, + loopback, + conditions.lKJ // + ); + CopyLChikouSpan( + zIndex, + loopback, + conditions.lChik // + ); + CopyLSenkouSpanA( + zIndex, + loopback, + conditions.lSSA // + ); + CopyLSenkouSpanB( + zIndex, + loopback, + conditions.lSSB // + ); + CopyLFutureSenkouSpanA( + zIndex, + loopback, + conditions.lFSSA // + ); + CopyLFutureSenkouSpanB( + zIndex, + loopback, + conditions.lFSSB // + ); + + // + // Hind ... + CopyHTenkanSen( + zIndex, + loopback, + conditions.hTK // + ); + CopyHKijunSen( + zIndex, + loopback, + conditions.hKJ // + ); + CopyHChikouSpan( + zIndex, + loopback, + conditions.hChik // + ); + CopyHSenkouSpanA( + zIndex, + loopback, + conditions.hSSA // + ); + CopyHSenkouSpanB( + zIndex, + loopback, + conditions.hSSB // + ); + CopyHFutureSenkouSpanA( + zIndex, + loopback, + conditions.hFSSA // + ); + CopyHFutureSenkouSpanB( + zIndex, + loopback, + conditions.hFSSB // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Conditions ... + + // + // Current ... + + // + bool isCClosedOverKijunSen = cBar.low > conditions.cTK[cIndex]; + bool isCClosedUnderKijunSen = cBar.high < conditions.cTK[cIndex]; + + // + bool isCTenkanSenOverKijunSen = conditions.cTK[cIndex] > conditions.cKJ[cIndex]; + bool isCTenkanSenOverKijunSenPrev = conditions.cTK[pIndex] > conditions.cKJ[pIndex]; + + // + bool isCTenkanSenUnderKijunSen = conditions.cTK[cIndex] < conditions.cKJ[cIndex]; + bool isCTenkanSenUnderKijunSenPrev = conditions.cTK[pIndex] < conditions.cKJ[pIndex]; + + // + bool isCTenkanSenCrossedOverKijunSen = isCTenkanSenOverKijunSen && + !isCTenkanSenOverKijunSenPrev; + bool isCTenkanSenCrossedUnderKijunSen = isCTenkanSenUnderKijunSen && + !isCTenkanSenUnderKijunSenPrev; + + // + bool isCSenkouSpanAOverB = conditions.cSSA[cIndex] > conditions.cSSB[cIndex]; + bool isCSenkouSpanAOverBPrev = conditions.cSSA[pIndex] > conditions.cSSB[pIndex]; + + // + bool isCSenkouSpanAUnderB = conditions.cSSA[cIndex] < conditions.cSSB[cIndex]; + bool isCSenkouSpanAUnderBPrev = conditions.cSSA[pIndex] < conditions.cSSB[pIndex]; + + // + bool isCSenkouSpanAOverLast = conditions.cSSA[cIndex] > conditions.cSSA[pIndex]; + bool isCSenkouSpanAOverLastPrev = conditions.cSSA[pIndex] > conditions.cSSA[ppIndex]; + + // + bool isCSenkouSpanAUnderLast = conditions.cSSA[cIndex] < conditions.cSSA[pIndex]; + bool isCSenkouSpanAUnderLastPrev = conditions.cSSA[pIndex] < conditions.cSSA[ppIndex]; + + // + bool isCFutureSenkouSpanAOverB = conditions.cFSSA[cIndex] > conditions.cFSSB[cIndex]; + bool isCFutureSenkouSpanAOverBPrev = conditions.cFSSA[pIndex] > conditions.cFSSB[pIndex]; + + // + bool isCFutureSenkouSpanAUnderB = conditions.cFSSA[cIndex] < conditions.cFSSB[cIndex]; + bool isCFutureSenkouSpanAUnderBPrev = conditions.cFSSA[pIndex] < conditions.cFSSB[pIndex]; + + // + bool isCFutureSenkouSpanAOverLast = conditions.cFSSA[cIndex] > conditions.cFSSA[pIndex]; + bool isCFutureSenkouSpanAOverLastPrev = conditions.cFSSA[pIndex] > conditions.cFSSA[ppIndex]; + + // + bool isCFutureSenkouSpanAUnderLast = conditions.cFSSA[cIndex] < conditions.cFSSA[pIndex]; + bool isCFutureSenkouSpanAUnderLastPrev = conditions.cFSSA[pIndex] < conditions.cFSSA[ppIndex]; + + // + bool isCSenkouSpanACrossedOverB = isCSenkouSpanAOverB && + !isCSenkouSpanAOverBPrev; + bool isCSenkouSpanACrossedUnderB = isCSenkouSpanAUnderB && + !isCSenkouSpanAUnderBPrev; + bool isCSenkouSpanACrossedOverLast = isCSenkouSpanAOverLast && + !isCSenkouSpanAOverLastPrev; + bool isCSenkouSpanACrossedUnderLast = isCSenkouSpanAUnderLast && + !isCSenkouSpanAUnderLastPrev; + bool isCFutureSenkouSpanACrossedOverB = isCFutureSenkouSpanAOverB && + !isCFutureSenkouSpanAOverBPrev; + bool isCFutureSenkouSpanACrossedUnderB = isCFutureSenkouSpanAUnderB && + !isCFutureSenkouSpanAUnderBPrev; + bool isCFutureSenkouSpanACrossedOverLast = isCFutureSenkouSpanAOverLast && + !isCFutureSenkouSpanAOverLastPrev; + bool isCFutureSenkouSpanACrossedUnderLast = isCFutureSenkouSpanAUnderLast && + !isCFutureSenkouSpanAUnderLastPrev; + + // + conditions.isCClosedOverKijunSen = isCClosedOverKijunSen; + conditions.isCClosedUnderKijunSen = isCClosedUnderKijunSen; + conditions.isCTenkanSenOverKijunSen = isCTenkanSenOverKijunSen; + conditions.isCTenkanSenUnderKijunSen = isCTenkanSenUnderKijunSen; + conditions.isCTenkanSenCrossedOverKijunSen = isCTenkanSenCrossedOverKijunSen; + conditions.isCTenkanSenCrossedUnderKijunSen = isCTenkanSenCrossedUnderKijunSen; + + // + conditions.isCSenkouSpanAOverB = isCSenkouSpanAOverB; + conditions.isCSenkouSpanAUnderB = isCSenkouSpanAUnderB; + conditions.isCSenkouSpanAOverLast = isCSenkouSpanAOverLast; + conditions.isCSenkouSpanAUnderLast = isCSenkouSpanAUnderLast; + conditions.isCFutureSenkouSpanAOverB = isCFutureSenkouSpanAOverB; + conditions.isCFutureSenkouSpanAUnderB = isCFutureSenkouSpanAUnderB; + conditions.isCFutureSenkouSpanAOverLast = isCFutureSenkouSpanAOverLast; + conditions.isCFutureSenkouSpanAUnderLast = isCFutureSenkouSpanAUnderLast; + + // + conditions.isCSenkouSpanACrossedOverB = isCSenkouSpanACrossedOverB; + conditions.isCSenkouSpanACrossedUnderB = isCSenkouSpanACrossedUnderB; + conditions.isCSenkouSpanACrossedOverLast = isCSenkouSpanACrossedOverLast; + conditions.isCSenkouSpanACrossedUnderLast = isCSenkouSpanACrossedUnderLast; + conditions.isCFutureSenkouSpanACrossedOverB = isCFutureSenkouSpanACrossedOverB; + conditions.isCFutureSenkouSpanACrossedUnderB = isCFutureSenkouSpanACrossedUnderB; + conditions.isCFutureSenkouSpanACrossedOverLast = isCFutureSenkouSpanACrossedOverLast; + conditions.isCFutureSenkouSpanACrossedUnderLast = isCFutureSenkouSpanACrossedUnderLast; + + // + // Short ... + + // + bool isSClosedOverKijunSen = cBar.low > conditions.sTK[cIndex]; + bool isSClosedUnderKijunSen = cBar.high < conditions.sTK[cIndex]; + + // + bool isSTenkanSenOverKijunSen = conditions.sTK[cIndex] > conditions.sKJ[cIndex]; + bool isSTenkanSenOverKijunSenPrev = conditions.sTK[pIndex] > conditions.sKJ[pIndex]; + + // + bool isSTenkanSenUnderKijunSen = conditions.sTK[cIndex] < conditions.sKJ[cIndex]; + bool isSTenkanSenUnderKijunSenPrev = conditions.sTK[pIndex] < conditions.sKJ[pIndex]; + + // + bool isSTenkanSenCrossedOverKijunSen = isSTenkanSenOverKijunSen && + !isSTenkanSenOverKijunSenPrev; + bool isSTenkanSenCrossedUnderKijunSen = isSTenkanSenUnderKijunSen && + !isSTenkanSenUnderKijunSenPrev; + + // + bool isSSenkouSpanAOverB = conditions.sSSA[cIndex] > conditions.sSSB[cIndex]; + bool isSSenkouSpanAOverBPrev = conditions.sSSA[pIndex] > conditions.sSSB[pIndex]; + + // + bool isSSenkouSpanAUnderB = conditions.sSSA[cIndex] < conditions.sSSB[cIndex]; + bool isSSenkouSpanAUnderBPrev = conditions.sSSA[pIndex] < conditions.sSSB[pIndex]; + + // + bool isSSenkouSpanAOverLast = conditions.sSSA[cIndex] > conditions.sSSA[pIndex]; + bool isSSenkouSpanAOverLastPrev = conditions.sSSA[pIndex] > conditions.sSSA[ppIndex]; + + // + bool isSSenkouSpanAUnderLast = conditions.sSSA[cIndex] < conditions.sSSA[pIndex]; + bool isSSenkouSpanAUnderLastPrev = conditions.sSSA[pIndex] < conditions.sSSA[ppIndex]; + + // + bool isSFutureSenkouSpanAOverB = conditions.sFSSA[cIndex] > conditions.sFSSB[cIndex]; + bool isSFutureSenkouSpanAOverBPrev = conditions.sFSSA[pIndex] > conditions.sFSSB[pIndex]; + + // + bool isSFutureSenkouSpanAUnderB = conditions.sFSSA[cIndex] < conditions.sFSSB[cIndex]; + bool isSFutureSenkouSpanAUnderBPrev = conditions.sFSSA[pIndex] < conditions.sFSSB[pIndex]; + + // + bool isSFutureSenkouSpanAOverLast = conditions.sFSSA[cIndex] > conditions.sFSSA[pIndex]; + bool isSFutureSenkouSpanAOverLastPrev = conditions.sFSSA[pIndex] > conditions.sFSSA[ppIndex]; + + // + bool isSFutureSenkouSpanAUnderLast = conditions.sFSSA[cIndex] < conditions.sFSSA[pIndex]; + bool isSFutureSenkouSpanAUnderLastPrev = conditions.sFSSA[pIndex] < conditions.sFSSA[ppIndex]; + + // + bool isSSenkouSpanACrossedOverB = isSSenkouSpanAOverB && + !isSSenkouSpanAOverBPrev; + bool isSSenkouSpanACrossedUnderB = isSSenkouSpanAUnderB && + !isSSenkouSpanAUnderBPrev; + bool isSSenkouSpanACrossedOverLast = isSSenkouSpanAOverLast && + !isSSenkouSpanAOverLastPrev; + bool isSSenkouSpanACrossedUnderLast = isSSenkouSpanAUnderLast && + !isSSenkouSpanAUnderLastPrev; + bool isSFutureSenkouSpanACrossedOverB = isSFutureSenkouSpanAOverB && + !isSFutureSenkouSpanAOverBPrev; + bool isSFutureSenkouSpanACrossedUnderB = isSFutureSenkouSpanAUnderB && + !isSFutureSenkouSpanAUnderBPrev; + bool isSFutureSenkouSpanACrossedOverLast = isSFutureSenkouSpanAOverLast && + !isSFutureSenkouSpanAOverLastPrev; + bool isSFutureSenkouSpanACrossedUnderLast = isSFutureSenkouSpanAUnderLast && + !isSFutureSenkouSpanAUnderLastPrev; + + // + conditions.isSClosedOverKijunSen = isSClosedOverKijunSen; + conditions.isSClosedUnderKijunSen = isSClosedUnderKijunSen; + conditions.isSTenkanSenOverKijunSen = isSTenkanSenOverKijunSen; + conditions.isSTenkanSenUnderKijunSen = isSTenkanSenUnderKijunSen; + conditions.isSTenkanSenCrossedOverKijunSen = isSTenkanSenCrossedOverKijunSen; + conditions.isSTenkanSenCrossedUnderKijunSen = isSTenkanSenCrossedUnderKijunSen; + + // + conditions.isSSenkouSpanAOverB = isSSenkouSpanAOverB; + conditions.isSSenkouSpanAUnderB = isSSenkouSpanAUnderB; + conditions.isSSenkouSpanAOverLast = isSSenkouSpanAOverLast; + conditions.isSSenkouSpanAUnderLast = isSSenkouSpanAUnderLast; + conditions.isSFutureSenkouSpanAOverB = isSFutureSenkouSpanAOverB; + conditions.isSFutureSenkouSpanAUnderB = isSFutureSenkouSpanAUnderB; + conditions.isSFutureSenkouSpanAOverLast = isSFutureSenkouSpanAOverLast; + conditions.isSFutureSenkouSpanAUnderLast = isSFutureSenkouSpanAUnderLast; + + // + conditions.isSSenkouSpanACrossedOverB = isSSenkouSpanACrossedOverB; + conditions.isSSenkouSpanACrossedUnderB = isSSenkouSpanACrossedUnderB; + conditions.isSSenkouSpanACrossedOverLast = isSSenkouSpanACrossedOverLast; + conditions.isSSenkouSpanACrossedUnderLast = isSSenkouSpanACrossedUnderLast; + conditions.isSFutureSenkouSpanACrossedOverB = isSFutureSenkouSpanACrossedOverB; + conditions.isSFutureSenkouSpanACrossedUnderB = isSFutureSenkouSpanACrossedUnderB; + conditions.isSFutureSenkouSpanACrossedOverLast = isSFutureSenkouSpanACrossedOverLast; + conditions.isSFutureSenkouSpanACrossedUnderLast = isSFutureSenkouSpanACrossedUnderLast; + + // + // Medium ... + + // + bool isMClosedOverKijunSen = cBar.low > conditions.mTK[cIndex]; + bool isMClosedUnderKijunSen = cBar.high < conditions.mTK[cIndex]; + + // + bool isMTenkanSenOverKijunSen = conditions.mTK[cIndex] > conditions.mKJ[cIndex]; + bool isMTenkanSenOverKijunSenPrev = conditions.mTK[pIndex] > conditions.mKJ[pIndex]; + + // + bool isMTenkanSenUnderKijunSen = conditions.mTK[cIndex] < conditions.mKJ[cIndex]; + bool isMTenkanSenUnderKijunSenPrev = conditions.mTK[pIndex] < conditions.mKJ[pIndex]; + + // + bool isMTenkanSenCrossedOverKijunSen = isMTenkanSenOverKijunSen && + !isMTenkanSenOverKijunSenPrev; + bool isMTenkanSenCrossedUnderKijunSen = isMTenkanSenUnderKijunSen && + !isMTenkanSenUnderKijunSenPrev; + + // + bool isMSenkouSpanAOverB = conditions.mSSA[cIndex] > conditions.mSSB[cIndex]; + bool isMSenkouSpanAOverBPrev = conditions.mSSA[pIndex] > conditions.mSSB[pIndex]; + + // + bool isMSenkouSpanAUnderB = conditions.mSSA[cIndex] < conditions.mSSB[cIndex]; + bool isMSenkouSpanAUnderBPrev = conditions.mSSA[pIndex] < conditions.mSSB[pIndex]; + + // + bool isMSenkouSpanAOverLast = conditions.mSSA[cIndex] > conditions.mSSA[pIndex]; + bool isMSenkouSpanAOverLastPrev = conditions.mSSA[pIndex] > conditions.mSSA[ppIndex]; + + // + bool isMSenkouSpanAUnderLast = conditions.mSSA[cIndex] < conditions.mSSA[pIndex]; + bool isMSenkouSpanAUnderLastPrev = conditions.mSSA[pIndex] < conditions.mSSA[ppIndex]; + + // + bool isMFutureSenkouSpanAOverB = conditions.mFSSA[cIndex] > conditions.mFSSB[cIndex]; + bool isMFutureSenkouSpanAOverBPrev = conditions.mFSSA[pIndex] > conditions.mFSSB[pIndex]; + + // + bool isMFutureSenkouSpanAUnderB = conditions.mFSSA[cIndex] < conditions.mFSSB[cIndex]; + bool isMFutureSenkouSpanAUnderBPrev = conditions.mFSSA[pIndex] < conditions.mFSSB[pIndex]; + + // + bool isMFutureSenkouSpanAOverLast = conditions.mFSSA[cIndex] > conditions.mFSSA[pIndex]; + bool isMFutureSenkouSpanAOverLastPrev = conditions.mFSSA[pIndex] > conditions.mFSSA[ppIndex]; + + // + bool isMFutureSenkouSpanAUnderLast = conditions.mFSSA[cIndex] < conditions.mFSSA[pIndex]; + bool isMFutureSenkouSpanAUnderLastPrev = conditions.mFSSA[pIndex] < conditions.mFSSA[ppIndex]; + + // + bool isMSenkouSpanACrossedOverB = isMSenkouSpanAOverB && + !isMSenkouSpanAOverBPrev; + bool isMSenkouSpanACrossedUnderB = isMSenkouSpanAUnderB && + !isMSenkouSpanAUnderBPrev; + bool isMSenkouSpanACrossedOverLast = isMSenkouSpanAOverLast && + !isMSenkouSpanAOverLastPrev; + bool isMSenkouSpanACrossedUnderLast = isMSenkouSpanAUnderLast && + !isMSenkouSpanAUnderLastPrev; + bool isMFutureSenkouSpanACrossedOverB = isMFutureSenkouSpanAOverB && + !isMFutureSenkouSpanAOverBPrev; + bool isMFutureSenkouSpanACrossedUnderB = isMFutureSenkouSpanAUnderB && + !isMFutureSenkouSpanAUnderBPrev; + bool isMFutureSenkouSpanACrossedOverLast = isMFutureSenkouSpanAOverLast && + !isMFutureSenkouSpanAOverLastPrev; + bool isMFutureSenkouSpanACrossedUnderLast = isMFutureSenkouSpanAUnderLast && + !isMFutureSenkouSpanAUnderLastPrev; + + // + conditions.isMClosedOverKijunSen = isMClosedOverKijunSen; + conditions.isMClosedUnderKijunSen = isMClosedUnderKijunSen; + conditions.isMTenkanSenOverKijunSen = isMTenkanSenOverKijunSen; + conditions.isMTenkanSenUnderKijunSen = isMTenkanSenUnderKijunSen; + conditions.isMTenkanSenCrossedOverKijunSen = isMTenkanSenCrossedOverKijunSen; + conditions.isMTenkanSenCrossedUnderKijunSen = isMTenkanSenCrossedUnderKijunSen; + + // + conditions.isMSenkouSpanAOverB = isMSenkouSpanAOverB; + conditions.isMSenkouSpanAUnderB = isMSenkouSpanAUnderB; + conditions.isMSenkouSpanAOverLast = isMSenkouSpanAOverLast; + conditions.isMSenkouSpanAUnderLast = isMSenkouSpanAUnderLast; + conditions.isMFutureSenkouSpanAOverB = isMFutureSenkouSpanAOverB; + conditions.isMFutureSenkouSpanAUnderB = isMFutureSenkouSpanAUnderB; + conditions.isMFutureSenkouSpanAOverLast = isMFutureSenkouSpanAOverLast; + conditions.isMFutureSenkouSpanAUnderLast = isMFutureSenkouSpanAUnderLast; + + // + conditions.isMSenkouSpanACrossedOverB = isMSenkouSpanACrossedOverB; + conditions.isMSenkouSpanACrossedUnderB = isMSenkouSpanACrossedUnderB; + conditions.isMSenkouSpanACrossedOverLast = isMSenkouSpanACrossedOverLast; + conditions.isMSenkouSpanACrossedUnderLast = isMSenkouSpanACrossedUnderLast; + conditions.isMFutureSenkouSpanACrossedOverB = isMFutureSenkouSpanACrossedOverB; + conditions.isMFutureSenkouSpanACrossedUnderB = isMFutureSenkouSpanACrossedUnderB; + conditions.isMFutureSenkouSpanACrossedOverLast = isMFutureSenkouSpanACrossedOverLast; + conditions.isMFutureSenkouSpanACrossedUnderLast = isMFutureSenkouSpanACrossedUnderLast; + + // + // Long ... + + // + bool isLClosedOverKijunSen = cBar.low > conditions.lTK[cIndex]; + bool isLClosedUnderKijunSen = cBar.high < conditions.lTK[cIndex]; + + // + bool isLTenkanSenOverKijunSen = conditions.lTK[cIndex] > conditions.lKJ[cIndex]; + bool isLTenkanSenOverKijunSenPrev = conditions.lTK[pIndex] > conditions.lKJ[pIndex]; + + // + bool isLTenkanSenUnderKijunSen = conditions.lTK[cIndex] < conditions.lKJ[cIndex]; + bool isLTenkanSenUnderKijunSenPrev = conditions.lTK[pIndex] < conditions.lKJ[pIndex]; + + // + bool isLTenkanSenCrossedOverKijunSen = isLTenkanSenOverKijunSen && + !isLTenkanSenOverKijunSenPrev; + bool isLTenkanSenCrossedUnderKijunSen = isLTenkanSenUnderKijunSen && + !isLTenkanSenUnderKijunSenPrev; + + // + bool isLSenkouSpanAOverB = conditions.lSSA[cIndex] > conditions.lSSB[cIndex]; + bool isLSenkouSpanAOverBPrev = conditions.lSSA[pIndex] > conditions.lSSB[pIndex]; + + // + bool isLSenkouSpanAUnderB = conditions.lSSA[cIndex] < conditions.lSSB[cIndex]; + bool isLSenkouSpanAUnderBPrev = conditions.lSSA[pIndex] < conditions.lSSB[pIndex]; + + // + bool isLSenkouSpanAOverLast = conditions.lSSA[cIndex] > conditions.lSSA[pIndex]; + bool isLSenkouSpanAOverLastPrev = conditions.lSSA[pIndex] > conditions.lSSA[ppIndex]; + + // + bool isLSenkouSpanAUnderLast = conditions.lSSA[cIndex] < conditions.lSSA[pIndex]; + bool isLSenkouSpanAUnderLastPrev = conditions.lSSA[pIndex] < conditions.lSSA[ppIndex]; + + // + bool isLFutureSenkouSpanAOverB = conditions.lFSSA[cIndex] > conditions.lFSSB[cIndex]; + bool isLFutureSenkouSpanAOverBPrev = conditions.lFSSA[pIndex] > conditions.lFSSB[pIndex]; + + // + bool isLFutureSenkouSpanAUnderB = conditions.lFSSA[cIndex] < conditions.lFSSB[cIndex]; + bool isLFutureSenkouSpanAUnderBPrev = conditions.lFSSA[pIndex] < conditions.lFSSB[pIndex]; + + // + bool isLFutureSenkouSpanAOverLast = conditions.lFSSA[cIndex] > conditions.lFSSA[pIndex]; + bool isLFutureSenkouSpanAOverLastPrev = conditions.lFSSA[pIndex] > conditions.lFSSA[ppIndex]; + + // + bool isLFutureSenkouSpanAUnderLast = conditions.lFSSA[cIndex] < conditions.lFSSA[pIndex]; + bool isLFutureSenkouSpanAUnderLastPrev = conditions.lFSSA[pIndex] < conditions.lFSSA[ppIndex]; + + // + bool isLSenkouSpanACrossedOverB = isLSenkouSpanAOverB && + !isLSenkouSpanAOverBPrev; + bool isLSenkouSpanACrossedUnderB = isLSenkouSpanAUnderB && + !isLSenkouSpanAUnderBPrev; + bool isLSenkouSpanACrossedOverLast = isLSenkouSpanAOverLast && + !isLSenkouSpanAOverLastPrev; + bool isLSenkouSpanACrossedUnderLast = isLSenkouSpanAUnderLast && + !isLSenkouSpanAUnderLastPrev; + bool isLFutureSenkouSpanACrossedOverB = isLFutureSenkouSpanAOverB && + !isLFutureSenkouSpanAOverBPrev; + bool isLFutureSenkouSpanACrossedUnderB = isLFutureSenkouSpanAUnderB && + !isLFutureSenkouSpanAUnderBPrev; + bool isLFutureSenkouSpanACrossedOverLast = isLFutureSenkouSpanAOverLast && + !isLFutureSenkouSpanAOverLastPrev; + bool isLFutureSenkouSpanACrossedUnderLast = isLFutureSenkouSpanAUnderLast && + !isLFutureSenkouSpanAUnderLastPrev; + + // + conditions.isLClosedOverKijunSen = isLClosedOverKijunSen; + conditions.isLClosedUnderKijunSen = isLClosedUnderKijunSen; + conditions.isLTenkanSenOverKijunSen = isLTenkanSenOverKijunSen; + conditions.isLTenkanSenUnderKijunSen = isLTenkanSenUnderKijunSen; + conditions.isLTenkanSenCrossedOverKijunSen = isLTenkanSenCrossedOverKijunSen; + conditions.isLTenkanSenCrossedUnderKijunSen = isLTenkanSenCrossedUnderKijunSen; + + // + conditions.isLSenkouSpanAOverB = isLSenkouSpanAOverB; + conditions.isLSenkouSpanAUnderB = isLSenkouSpanAUnderB; + conditions.isLSenkouSpanAOverLast = isLSenkouSpanAOverLast; + conditions.isLSenkouSpanAUnderLast = isLSenkouSpanAUnderLast; + conditions.isLFutureSenkouSpanAOverB = isLFutureSenkouSpanAOverB; + conditions.isLFutureSenkouSpanAUnderB = isLFutureSenkouSpanAUnderB; + conditions.isLFutureSenkouSpanAOverLast = isLFutureSenkouSpanAOverLast; + conditions.isLFutureSenkouSpanAUnderLast = isLFutureSenkouSpanAUnderLast; + + // + conditions.isLSenkouSpanACrossedOverB = isLSenkouSpanACrossedOverB; + conditions.isLSenkouSpanACrossedUnderB = isLSenkouSpanACrossedUnderB; + conditions.isLSenkouSpanACrossedOverLast = isLSenkouSpanACrossedOverLast; + conditions.isLSenkouSpanACrossedUnderLast = isLSenkouSpanACrossedUnderLast; + conditions.isLFutureSenkouSpanACrossedOverB = isLFutureSenkouSpanACrossedOverB; + conditions.isLFutureSenkouSpanACrossedUnderB = isLFutureSenkouSpanACrossedUnderB; + conditions.isLFutureSenkouSpanACrossedOverLast = isLFutureSenkouSpanACrossedOverLast; + conditions.isLFutureSenkouSpanACrossedUnderLast = isLFutureSenkouSpanACrossedUnderLast; + + // + // Hind ... + + // + bool isHClosedOverKijunSen = cBar.low > conditions.hTK[cIndex]; + bool isHClosedUnderKijunSen = cBar.high < conditions.hTK[cIndex]; + + // + bool isHTenkanSenOverKijunSen = conditions.hTK[cIndex] > conditions.hKJ[cIndex]; + bool isHTenkanSenOverKijunSenPrev = conditions.hTK[pIndex] > conditions.hKJ[pIndex]; + + // + bool isHTenkanSenUnderKijunSen = conditions.hTK[cIndex] < conditions.hKJ[cIndex]; + bool isHTenkanSenUnderKijunSenPrev = conditions.hTK[pIndex] < conditions.hKJ[pIndex]; + + // + bool isHTenkanSenCrossedOverKijunSen = isHTenkanSenOverKijunSen && + !isHTenkanSenOverKijunSenPrev; + bool isHTenkanSenCrossedUnderKijunSen = isHTenkanSenUnderKijunSen && + !isHTenkanSenUnderKijunSenPrev; + + // + bool isHSenkouSpanAOverB = conditions.hSSA[cIndex] > conditions.hSSB[cIndex]; + bool isHSenkouSpanAOverBPrev = conditions.hSSA[pIndex] > conditions.hSSB[pIndex]; + + // + bool isHSenkouSpanAUnderB = conditions.hSSA[cIndex] < conditions.hSSB[cIndex]; + bool isHSenkouSpanAUnderBPrev = conditions.hSSA[pIndex] < conditions.hSSB[pIndex]; + + // + bool isHSenkouSpanAOverLast = conditions.hSSA[cIndex] > conditions.hSSA[pIndex]; + bool isHSenkouSpanAOverLastPrev = conditions.hSSA[pIndex] > conditions.hSSA[ppIndex]; + + // + bool isHSenkouSpanAUnderLast = conditions.hSSA[cIndex] < conditions.hSSA[pIndex]; + bool isHSenkouSpanAUnderLastPrev = conditions.hSSA[pIndex] < conditions.hSSA[ppIndex]; + + // + bool isHFutureSenkouSpanAOverB = conditions.hFSSA[cIndex] > conditions.hFSSB[cIndex]; + bool isHFutureSenkouSpanAOverBPrev = conditions.hFSSA[pIndex] > conditions.hFSSB[pIndex]; + + // + bool isHFutureSenkouSpanAUnderB = conditions.hFSSA[cIndex] < conditions.hFSSB[cIndex]; + bool isHFutureSenkouSpanAUnderBPrev = conditions.hFSSA[pIndex] < conditions.hFSSB[pIndex]; + + // + bool isHFutureSenkouSpanAOverLast = conditions.hFSSA[cIndex] > conditions.hFSSA[pIndex]; + bool isHFutureSenkouSpanAOverLastPrev = conditions.hFSSA[pIndex] > conditions.hFSSA[ppIndex]; + + // + bool isHFutureSenkouSpanAUnderLast = conditions.hFSSA[cIndex] < conditions.hFSSA[pIndex]; + bool isHFutureSenkouSpanAUnderLastPrev = conditions.hFSSA[pIndex] < conditions.hFSSA[ppIndex]; + + // + bool isHSenkouSpanACrossedOverB = isHSenkouSpanAOverB && + !isHSenkouSpanAOverBPrev; + bool isHSenkouSpanACrossedUnderB = isHSenkouSpanAUnderB && + !isHSenkouSpanAUnderBPrev; + bool isHSenkouSpanACrossedOverLast = isHSenkouSpanAOverLast && + !isHSenkouSpanAOverLastPrev; + bool isHSenkouSpanACrossedUnderLast = isHSenkouSpanAUnderLast && + !isHSenkouSpanAUnderLastPrev; + bool isHFutureSenkouSpanACrossedOverB = isHFutureSenkouSpanAOverB && + !isHFutureSenkouSpanAOverBPrev; + bool isHFutureSenkouSpanACrossedUnderB = isHFutureSenkouSpanAUnderB && + !isHFutureSenkouSpanAUnderBPrev; + bool isHFutureSenkouSpanACrossedOverLast = isHFutureSenkouSpanAOverLast && + !isHFutureSenkouSpanAOverLastPrev; + bool isHFutureSenkouSpanACrossedUnderLast = isHFutureSenkouSpanAUnderLast && + !isHFutureSenkouSpanAUnderLastPrev; + + // + conditions.isHClosedOverKijunSen = isHClosedOverKijunSen; + conditions.isHClosedUnderKijunSen = isHClosedUnderKijunSen; + conditions.isHTenkanSenOverKijunSen = isHTenkanSenOverKijunSen; + conditions.isHTenkanSenUnderKijunSen = isHTenkanSenUnderKijunSen; + conditions.isHTenkanSenCrossedOverKijunSen = isHTenkanSenCrossedOverKijunSen; + conditions.isHTenkanSenCrossedUnderKijunSen = isHTenkanSenCrossedUnderKijunSen; + + // + conditions.isHSenkouSpanAOverB = isHSenkouSpanAOverB; + conditions.isHSenkouSpanAUnderB = isHSenkouSpanAUnderB; + conditions.isHSenkouSpanAOverLast = isHSenkouSpanAOverLast; + conditions.isHSenkouSpanAUnderLast = isHSenkouSpanAUnderLast; + conditions.isHFutureSenkouSpanAOverB = isHFutureSenkouSpanAOverB; + conditions.isHFutureSenkouSpanAUnderB = isHFutureSenkouSpanAUnderB; + conditions.isHFutureSenkouSpanAOverLast = isHFutureSenkouSpanAOverLast; + conditions.isHFutureSenkouSpanAUnderLast = isHFutureSenkouSpanAUnderLast; + + // + conditions.isHSenkouSpanACrossedOverB = isHSenkouSpanACrossedOverB; + conditions.isHSenkouSpanACrossedUnderB = isHSenkouSpanACrossedUnderB; + conditions.isHSenkouSpanACrossedOverLast = isHSenkouSpanACrossedOverLast; + conditions.isHSenkouSpanACrossedUnderLast = isHSenkouSpanACrossedUnderLast; + conditions.isHFutureSenkouSpanACrossedOverB = isHFutureSenkouSpanACrossedOverB; + conditions.isHFutureSenkouSpanACrossedUnderB = isHFutureSenkouSpanACrossedUnderB; + conditions.isHFutureSenkouSpanACrossedOverLast = isHFutureSenkouSpanACrossedOverLast; + conditions.isHFutureSenkouSpanACrossedUnderLast = isHFutureSenkouSpanACrossedUnderLast; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHICHInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cTKBuffer[]; + double cKJBuffer[]; + double cChikBuffer[]; + double cSSABuffer[]; + double cSSBBuffer[]; + + // + // Short ... + double sTKBuffer[]; + double sKJBuffer[]; + double sChikBuffer[]; + double sSSABuffer[]; + double sSSBBuffer[]; + + // + // Medium ... + double mTKBuffer[]; + double mKJBuffer[]; + double mChikBuffer[]; + double mSSABuffer[]; + double mSSBBuffer[]; + + // + // Long ... + double lTKBuffer[]; + double lKJBuffer[]; + double lChikBuffer[]; + double lSSABuffer[]; + double lSSBBuffer[]; + + // + // Hind ... + double hTKBuffer[]; + double hKJBuffer[]; + double hChikBuffer[]; + double hSSABuffer[]; + double hSSBBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + CopyBuffer( + mHandler, + XCHICH_C_TK_LINE, + 0, + totalBars, + cTKBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_C_KJ_LINE, + 0, + totalBars, + cKJBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_C_CH_LINE, + 0, + totalBars, + cChikBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_C_SSA_LINE, + 0, + totalBars, + cSSABuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_C_SSB_LINE, + 0, + totalBars, + cSSBBuffer + // + ); + + // + // Short ... + CopyBuffer( + mHandler, + XCHICH_S_TK_LINE, + 0, + totalBars, + sTKBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_S_KJ_LINE, + 0, + totalBars, + sKJBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_S_CH_LINE, + 0, + totalBars, + sChikBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_S_SSA_LINE, + 0, + totalBars, + sSSABuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_S_SSB_LINE, + 0, + totalBars, + sSSBBuffer + // + ); + + // + // Medium ... + CopyBuffer( + mHandler, + XCHICH_M_TK_LINE, + 0, + totalBars, + mTKBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_M_KJ_LINE, + 0, + totalBars, + mKJBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_M_CH_LINE, + 0, + totalBars, + mChikBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_M_SSA_LINE, + 0, + totalBars, + mSSABuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_M_SSB_LINE, + 0, + totalBars, + mSSBBuffer + // + ); + + // + // Long ... + CopyBuffer( + mHandler, + XCHICH_L_TK_LINE, + 0, + totalBars, + lTKBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_L_KJ_LINE, + 0, + totalBars, + lKJBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_L_CH_LINE, + 0, + totalBars, + lChikBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_L_SSA_LINE, + 0, + totalBars, + lSSABuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_L_SSB_LINE, + 0, + totalBars, + lSSBBuffer + // + ); + + // + // Hind ... + CopyBuffer( + mHandler, + XCHICH_H_TK_LINE, + 0, + totalBars, + hTKBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_H_KJ_LINE, + 0, + totalBars, + hKJBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_H_CH_LINE, + 0, + totalBars, + hChikBuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_H_SSA_LINE, + 0, + totalBars, + hSSABuffer + // + ); + CopyBuffer( + mHandler, + XCHICH_H_SSB_LINE, + 0, + totalBars, + hSSBBuffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchm.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchm.helper.mq5 new file mode 100644 index 00000000..a4598fac --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchm.helper.mq5 @@ -0,0 +1,4126 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHMHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHM_BUFFERS +{ + // + // Main ... + XCHM_FAST_LINE = 0, + XCHM_SLOW_LINE = 1, + // + // Current ... + XCHM_CFAST_LINE = 2, + XCHM_CSLOW_LINE = 3, + // + // Short ... + XCHM_SFAST_LINE = 4, + XCHM_SSLOW_LINE = 5, + // + // Medium ... + XCHM_MFAST_LINE = 6, + XCHM_MSLOW_LINE = 7, + // + // Long ... + XCHM_LFAST_LINE = 8, + XCHM_LSLOW_LINE = 9, + // + // Hind ... + XCHM_HFAST_LINE = 10, + XCHM_HSLOW_LINE = 11, +}; + +// +// Input Models ... +struct XCHMInputs +{ + // + // Props ... + + // + // Market ... + int fastLength; // Fast Length + int slowLength; // Slow Length + ENUM_MA_METHOD method; // Mode + ENUM_APPLIED_PRICE appliedTo; // Applied To + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + + // + bool showFast; // Show Fast + bool showSlow; // Show Slow + + // + bool showAVG; // Show Average + + // + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHMInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + fastLength = 0; + slowLength = 0; + method = MODE_EMA; + appliedTo = PRICE_CLOSE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showFast = false; + showSlow = false; + + // + showAVG = false; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + fastLength = 9; + slowLength = 18; + method = MODE_EMA; + appliedTo = PRICE_CLOSE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showFast = true; + showSlow = true; + + // + showAVG = true; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + fastLength > 2 && + slowLength > fastLength && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(fastLength, slowLength) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHMConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + double fast[]; + double slow[]; + + // + // Current ... + double cFast[]; + double cSlow[]; + + // + // Short ... + double sFast[]; + double sSlow[]; + + // + // Medium ... + double mFast[]; + double mSlow[]; + + // + // Long ... + double lFast[]; + double lSlow[]; + + // + // Hind ... + double hFast[]; + double hSlow[]; + + // + // Conditions ... + + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + + // + // AVG ... + + // + bool isFastOverSlow; + bool isFastUnderSlow; + + // + bool isFastCrossedOverSlow; + bool isFastCrossedUnderSlow; + + // + bool isClosedOverFast; + bool isClosedUnderFast; + + // + // Current ... + + // + bool isCFastOverSlow; + bool isCFastUnderSlow; + + // + bool isCFastCrossedOverSlow; + bool isCFastCrossedUnderSlow; + + // + bool isClosedOverCFast; + bool isClosedUnderCFast; + + // + // Short ... + + // + bool isSFastOverSlow; + bool isSFastUnderSlow; + + // + bool isSFastCrossedOverSlow; + bool isSFastCrossedUnderSlow; + + // + bool isClosedOverSFast; + bool isClosedUnderSFast; + + // + // Medium ... + + // + bool isMFastOverSlow; + bool isMFastUnderSlow; + + // + bool isMFastCrossedOverSlow; + bool isMFastCrossedUnderSlow; + + // + bool isClosedOverMFast; + bool isClosedUnderMFast; + + // + // Long ... + + // + bool isLFastOverSlow; + bool isLFastUnderSlow; + + // + bool isLFastCrossedOverSlow; + bool isLFastCrossedUnderSlow; + + // + bool isClosedOverLFast; + bool isClosedUnderLFast; + + // + // Hind ... + + // + bool isHFastOverSlow; + bool isHFastUnderSlow; + + // + bool isHFastCrossedOverSlow; + bool isHFastCrossedUnderSlow; + + // + bool isClosedOverHFast; + bool isClosedUnderHFast; + + // + void Clean() + { + // + Clean(fast); + Clean(slow); + Clean(cFast); + Clean(cSlow); + Clean(sFast); + Clean(sSlow); + Clean(mFast); + Clean(mSlow); + Clean(lFast); + Clean(lSlow); + Clean(hFast); + Clean(hSlow); + + // + ArraySetAsSeries(fast, true); + ArraySetAsSeries(slow, true); + ArraySetAsSeries(cFast, true); + ArraySetAsSeries(cSlow, true); + ArraySetAsSeries(sFast, true); + ArraySetAsSeries(sSlow, true); + ArraySetAsSeries(mFast, true); + ArraySetAsSeries(mSlow, true); + ArraySetAsSeries(lFast, true); + ArraySetAsSeries(lSlow, true); + ArraySetAsSeries(hFast, true); + ArraySetAsSeries(hSlow, true); + + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + + // + // AVG ... + + // + isFastOverSlow = false; + isFastUnderSlow = false; + + // + isFastCrossedOverSlow = false; + isFastCrossedUnderSlow = false; + + // + isClosedOverFast = false; + isClosedUnderFast = false; + + // + // Current ... + + // + isCFastOverSlow = false; + isCFastUnderSlow = false; + + // + isCFastCrossedOverSlow = false; + isCFastCrossedUnderSlow = false; + + // + isClosedOverCFast = false; + isClosedUnderCFast = false; + + // + // Short ... + + // + isSFastOverSlow = false; + isSFastUnderSlow = false; + + // + isSFastCrossedOverSlow = false; + isSFastCrossedUnderSlow = false; + + // + isClosedOverSFast = false; + isClosedUnderSFast = false; + + // + // Medium ... + + // + isMFastOverSlow = false; + isMFastUnderSlow = false; + + // + isMFastCrossedOverSlow = false; + isMFastCrossedUnderSlow = false; + + // + isClosedOverMFast = false; + isClosedUnderMFast = false; + + // + // Long ... + + // + isLFastOverSlow = false; + isLFastUnderSlow = false; + + // + isLFastCrossedOverSlow = false; + isLFastCrossedUnderSlow = false; + + // + isClosedOverLFast = false; + isClosedUnderLFast = false; + + // + // Hind ... + + // + isHFastOverSlow = false; + isHFastUnderSlow = false; + + // + isHFastCrossedOverSlow = false; + isHFastCrossedUnderSlow = false; + + // + isClosedOverHFast = false; + isClosedUnderHFast = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + + // + // AVG ... + + // + if (isFastOverSlow) + { + bullishScore++; + } + if (isFastUnderSlow) + { + bearishScore++; + } + if (isFastCrossedOverSlow) + { + bullishScore++; + } + if (isFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverFast) + { + bullishScore++; + } + if (isClosedUnderFast) + { + bearishScore++; + } + + // + // Current ... + + // + if (isCFastOverSlow) + { + bullishScore++; + } + if (isCFastUnderSlow) + { + bearishScore++; + } + if (isCFastCrossedOverSlow) + { + bullishScore++; + } + if (isCFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverCFast) + { + bullishScore++; + } + if (isClosedUnderCFast) + { + bearishScore++; + } + + // + // Short ... + + // + if (isSFastOverSlow) + { + bullishScore++; + } + if (isSFastUnderSlow) + { + bearishScore++; + } + if (isSFastCrossedOverSlow) + { + bullishScore++; + } + if (isSFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverSFast) + { + bullishScore++; + } + if (isClosedUnderSFast) + { + bearishScore++; + } + + // + // Medium ... + + // + if (isMFastOverSlow) + { + bullishScore++; + } + if (isMFastUnderSlow) + { + bearishScore++; + } + if (isMFastCrossedOverSlow) + { + bullishScore++; + } + if (isMFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverMFast) + { + bullishScore++; + } + if (isClosedUnderMFast) + { + bearishScore++; + } + + // + // Long ... + + // + if (isLFastOverSlow) + { + bullishScore++; + } + if (isLFastUnderSlow) + { + bearishScore++; + } + if (isLFastCrossedOverSlow) + { + bullishScore++; + } + if (isLFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverLFast) + { + bullishScore++; + } + if (isClosedUnderLFast) + { + bearishScore++; + } + + // + // Hind ... + + // + if (isHFastOverSlow) + { + bullishScore++; + } + if (isHFastUnderSlow) + { + bearishScore++; + } + if (isHFastCrossedOverSlow) + { + bullishScore++; + } + if (isHFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverHFast) + { + bullishScore++; + } + if (isClosedUnderHFast) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + + // + // AVG ... + ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) + + ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverFast", isClosedOverFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderFast", isClosedUnderFast, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCFastOverSlow", isCFastOverSlow, ignoreFalseConditions, separator) + + ToString("isCFastUnderSlow", isCFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isCFastCrossedOverSlow", isCFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isCFastCrossedUnderSlow", isCFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverCFast", isClosedOverCFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderCFast", isClosedUnderCFast, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSFastOverSlow", isSFastOverSlow, ignoreFalseConditions, separator) + + ToString("isSFastUnderSlow", isSFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isSFastCrossedOverSlow", isSFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isSFastCrossedUnderSlow", isSFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverSFast", isClosedOverSFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderSFast", isClosedUnderSFast, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMFastOverSlow", isMFastOverSlow, ignoreFalseConditions, separator) + + ToString("isMFastUnderSlow", isMFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isMFastCrossedOverSlow", isMFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isMFastCrossedUnderSlow", isMFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverMFast", isClosedOverMFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderMFast", isClosedUnderMFast, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLFastOverSlow", isLFastOverSlow, ignoreFalseConditions, separator) + + ToString("isLFastUnderSlow", isLFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isLFastCrossedOverSlow", isLFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isLFastCrossedUnderSlow", isLFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverLFast", isClosedOverLFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderLFast", isClosedUnderLFast, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHFastOverSlow", isHFastOverSlow, ignoreFalseConditions, separator) + + ToString("isHFastUnderSlow", isHFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isHFastCrossedOverSlow", isHFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isHFastCrossedUnderSlow", isHFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverHFast", isClosedOverHFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderHFast", isClosedUnderHFast, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHM"; + } +}; + +// +// Class ... +class XSCXCHMHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHMHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHMHelper() + { + // + Clean(fastBuffer); + Clean(slowBuffer); + Clean(cFastBuffer); + Clean(cSlowBuffer); + Clean(sFastBuffer); + Clean(sSlowBuffer); + Clean(mFastBuffer); + Clean(mSlowBuffer); + Clean(lFastBuffer); + Clean(lSlowBuffer); + Clean(hFastBuffer); + Clean(hSlowBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHMInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(fastBuffer, true); + ArraySetAsSeries(slowBuffer, true); + ArraySetAsSeries(cFastBuffer, true); + ArraySetAsSeries(cSlowBuffer, true); + ArraySetAsSeries(sFastBuffer, true); + ArraySetAsSeries(sSlowBuffer, true); + ArraySetAsSeries(mFastBuffer, true); + ArraySetAsSeries(mSlowBuffer, true); + ArraySetAsSeries(lFastBuffer, true); + ArraySetAsSeries(lSlowBuffer, true); + ArraySetAsSeries(hFastBuffer, true); + ArraySetAsSeries(hSlowBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchm", + // + // Inputs ... + // + // Market ... + "", + mInputs.fastLength, + mInputs.slowLength, + mInputs.method, + mInputs.appliedTo, + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + // + mInputs.showFast, + mInputs.showSlow, + // + mInputs.showAVG, + // + mInputs.showCurrent, + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHMInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHMInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // AVG ... + + // + double GetFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(slowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return slowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + slowBuffer, + buffer, + forceClean + // + ); + } + + // + // Current ... + + // + double GetCFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + double GetSFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + double GetMFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + double GetLFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + double GetHFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + void GetCycle( + double &fast, + double &slow, + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + fast = 0; + slow = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + fast = GetCFast(barIndex); + slow = GetCSlow(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + fast = GetSFast(barIndex); + slow = GetSSlow(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + fast = GetMFast(barIndex); + slow = GetMSlow(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + fast = GetLFast(barIndex); + slow = GetLSlow(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + fast = GetHFast(barIndex); + slow = GetHSlow(barIndex); + break; + } + } + + // + double GetCyclePower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); + + // + result = MathAbs(fast - slow); + + // + return result; + } + + // + double GetCycleFast( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); + + // + result = fast; + + // + return result; + } + + // + double GetCycleSlow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); + + // + result = slow; + + // + return result; + } + + // + double GetCycleMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); + + // + result = MathMax(fast, slow); + + // + return result; + } + + // + double GetCycleMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); + + // + result = MathMin(fast, slow); + + // + return result; + } + + // + int GetFasts( + double &values[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleFast( + barIndex, + cycles[i] // + ); + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetSlows( + double &values[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleSlow( + barIndex, + cycles[i] // + ); + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesFast( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleFast( + barIndex, + cycles[i] // + ); + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesSlow( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleSlow( + barIndex, + cycles[i] // + ); + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBullishCycles( + ENUM_X_MARKET_CYCLES &cycles[], // Holds Result + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES mCycles[]; + int cyclesCount = GetAllMarketCycles( + mCycles // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + mCycles[i] // + ); + + // + bool isBullish = fast > slow; + if (isBullish) + { + // + Add( + mCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetBearishCycles( + ENUM_X_MARKET_CYCLES &cycles[], // Holds Result + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES mCycles[]; + int cyclesCount = GetAllMarketCycles( + mCycles // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + mCycles[i] // + ); + + // + bool isBearish = fast < slow; + if (isBearish) + { + // + Add( + mCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + double GetMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } + + // + return result; + } + + // + double GetCyclesMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } + + // + return result; + } + + // + double GetCyclesMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMaxBullish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMinBullish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMaxBearish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMinBearish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMaxBullishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBullishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBullishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBullishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBearishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBearishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBearishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBearishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + if (iPower > 0) + { + result += iPower; + } + } + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + if (iPower > 0) + { + result += iPower; + } + } + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycles[i] // + ); + + // + if (fast > slow) + { + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + if (iPower > 0) + { + result += iPower; + } + } + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycles[i] // + ); + + // + if (fast < slow) + { + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + if (iPower > 0) + { + result += iPower; + } + } + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHMConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // AVG ... + + // + // Fast ... + CopyFast( + zIndex, + loopback, + conditions.fast // + ); + + // + // Slow ... + CopySlow( + zIndex, + loopback, + conditions.slow // + ); + + // + // Current ... + + // + // Fast ... + CopyCFast( + zIndex, + loopback, + conditions.cFast // + ); + + // + // Slow ... + CopyCSlow( + zIndex, + loopback, + conditions.cSlow // + ); + + // + // Short ... + + // + // Fast ... + CopySFast( + zIndex, + loopback, + conditions.sFast // + ); + + // + // Slow ... + CopySSlow( + zIndex, + loopback, + conditions.sSlow // + ); + + // + // Medium ... + + // + // Fast ... + CopyMFast( + zIndex, + loopback, + conditions.mFast // + ); + + // + // Slow ... + CopyMSlow( + zIndex, + loopback, + conditions.mSlow // + ); + + // + // Long ... + + // + // Fast ... + CopyLFast( + zIndex, + loopback, + conditions.lFast // + ); + + // + // Slow ... + CopyLSlow( + zIndex, + loopback, + conditions.lSlow // + ); + + // + // Hind ... + + // + // Fast ... + CopyHFast( + zIndex, + loopback, + conditions.hFast // + ); + + // + // Slow ... + CopyHSlow( + zIndex, + loopback, + conditions.hSlow // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + double hhValue = pBar.FindHighest( + loopback, + MODE_HIGH // + ); + double llValue = pBar.FindLowest( + loopback, + MODE_LOW // + ); + + // + XOHCL ppBar; + result = ppBar.Init( + mSymbol, + mPeriod, + ppIndex // + ); + if (!result) + { + return result; + } + double phhValue = ppBar.FindHighest( + loopback * 2, + MODE_HIGH // + ); + double pllValue = ppBar.FindLowest( + loopback * 2, + MODE_LOW // + ); + + // + double allValues[]; + double maxValue = 0; + double minValue = 0; + double maxValuePrev = 0; + double minValuePrev = 0; + + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + + // + // AVG ... + + // + bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex]; + bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex]; + + // + bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex]; + bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex]; + + // + bool isFastCrossedOverSlow = isFastOverSlow && + !isFastOverSlowPrev; + bool isFastCrossedUnderSlow = isFastUnderSlow && + !isFastUnderSlowPrev; + + // + bool isClosedOverFast = cBar.close > conditions.fast[cIndex]; + bool isClosedUnderFast = cBar.close < conditions.fast[cIndex]; + + // + conditions.isFastOverSlow = isFastOverSlow; + conditions.isFastUnderSlow = isFastUnderSlow; + + // + conditions.isFastCrossedOverSlow = isFastCrossedOverSlow; + conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow; + + // + conditions.isClosedOverFast = isClosedOverFast; + conditions.isClosedUnderFast = isClosedUnderFast; + + // + // Current ... + + // + bool isCFastOverSlow = conditions.cFast[cIndex] > conditions.cSlow[cIndex]; + bool isCFastOverSlowPrev = conditions.cFast[pIndex] > conditions.cSlow[pIndex]; + + // + bool isCFastUnderSlow = conditions.cFast[cIndex] < conditions.cSlow[cIndex]; + bool isCFastUnderSlowPrev = conditions.cFast[pIndex] < conditions.cSlow[pIndex]; + + // + bool isCFastCrossedOverSlow = isCFastOverSlow && + !isCFastOverSlowPrev; + bool isCFastCrossedUnderSlow = isCFastUnderSlow && + !isCFastUnderSlowPrev; + + // + bool isClosedOverCFast = cBar.close > conditions.cFast[cIndex]; + bool isClosedUnderCFast = cBar.close < conditions.cFast[cIndex]; + + // + conditions.isCFastOverSlow = isCFastOverSlow; + conditions.isCFastUnderSlow = isCFastUnderSlow; + + // + conditions.isCFastCrossedOverSlow = isCFastCrossedOverSlow; + conditions.isCFastCrossedUnderSlow = isCFastCrossedUnderSlow; + + // + conditions.isClosedOverCFast = isClosedOverCFast; + conditions.isClosedUnderCFast = isClosedUnderCFast; + + // + // Short ... + + // + bool isSFastOverSlow = conditions.sFast[cIndex] > conditions.sSlow[cIndex]; + bool isSFastOverSlowPrev = conditions.sFast[pIndex] > conditions.sSlow[pIndex]; + + // + bool isSFastUnderSlow = conditions.sFast[cIndex] < conditions.sSlow[cIndex]; + bool isSFastUnderSlowPrev = conditions.sFast[pIndex] < conditions.sSlow[pIndex]; + + // + bool isSFastCrossedOverSlow = isSFastOverSlow && + !isSFastOverSlowPrev; + bool isSFastCrossedUnderSlow = isSFastUnderSlow && + !isSFastUnderSlowPrev; + + // + bool isClosedOverSFast = cBar.close > conditions.sFast[cIndex]; + bool isClosedUnderSFast = cBar.close < conditions.sFast[cIndex]; + + // + conditions.isSFastOverSlow = isSFastOverSlow; + conditions.isSFastUnderSlow = isSFastUnderSlow; + + // + conditions.isSFastCrossedOverSlow = isSFastCrossedOverSlow; + conditions.isSFastCrossedUnderSlow = isSFastCrossedUnderSlow; + + // + conditions.isClosedOverSFast = isClosedOverSFast; + conditions.isClosedUnderSFast = isClosedUnderSFast; + + // + // Medium ... + + // + bool isMFastOverSlow = conditions.mFast[cIndex] > conditions.mSlow[cIndex]; + bool isMFastOverSlowPrev = conditions.mFast[pIndex] > conditions.mSlow[pIndex]; + + // + bool isMFastUnderSlow = conditions.mFast[cIndex] < conditions.mSlow[cIndex]; + bool isMFastUnderSlowPrev = conditions.mFast[pIndex] < conditions.mSlow[pIndex]; + + // + bool isMFastCrossedOverSlow = isMFastOverSlow && + !isMFastOverSlowPrev; + bool isMFastCrossedUnderSlow = isMFastUnderSlow && + !isMFastUnderSlowPrev; + + // + bool isClosedOverMFast = cBar.close > conditions.mFast[cIndex]; + bool isClosedUnderMFast = cBar.close < conditions.mFast[cIndex]; + + // + conditions.isMFastOverSlow = isMFastOverSlow; + conditions.isMFastUnderSlow = isMFastUnderSlow; + + // + conditions.isMFastCrossedOverSlow = isMFastCrossedOverSlow; + conditions.isMFastCrossedUnderSlow = isMFastCrossedUnderSlow; + + // + conditions.isClosedOverMFast = isClosedOverMFast; + conditions.isClosedUnderMFast = isClosedUnderMFast; + + // + // Long ... + + // + bool isLFastOverSlow = conditions.lFast[cIndex] > conditions.lSlow[cIndex]; + bool isLFastOverSlowPrev = conditions.lFast[pIndex] > conditions.lSlow[pIndex]; + + // + bool isLFastUnderSlow = conditions.lFast[cIndex] < conditions.lSlow[cIndex]; + bool isLFastUnderSlowPrev = conditions.lFast[pIndex] < conditions.lSlow[pIndex]; + + // + bool isLFastCrossedOverSlow = isLFastOverSlow && + !isLFastOverSlowPrev; + bool isLFastCrossedUnderSlow = isLFastUnderSlow && + !isLFastUnderSlowPrev; + + // + bool isClosedOverLFast = cBar.close > conditions.lFast[cIndex]; + bool isClosedUnderLFast = cBar.close < conditions.lFast[cIndex]; + + // + conditions.isLFastOverSlow = isLFastOverSlow; + conditions.isLFastUnderSlow = isLFastUnderSlow; + + // + conditions.isLFastCrossedOverSlow = isLFastCrossedOverSlow; + conditions.isLFastCrossedUnderSlow = isLFastCrossedUnderSlow; + + // + conditions.isClosedOverLFast = isClosedOverLFast; + conditions.isClosedUnderLFast = isClosedUnderLFast; + + // + // Hind ... + + // + bool isHFastOverSlow = conditions.hFast[cIndex] > conditions.hSlow[cIndex]; + bool isHFastOverSlowPrev = conditions.hFast[pIndex] > conditions.hSlow[pIndex]; + + // + bool isHFastUnderSlow = conditions.hFast[cIndex] < conditions.hSlow[cIndex]; + bool isHFastUnderSlowPrev = conditions.hFast[pIndex] < conditions.hSlow[pIndex]; + + // + bool isHFastCrossedOverSlow = isHFastOverSlow && + !isHFastOverSlowPrev; + bool isHFastCrossedUnderSlow = isHFastUnderSlow && + !isHFastUnderSlowPrev; + + // + bool isClosedOverHFast = cBar.close > conditions.hFast[cIndex]; + bool isClosedUnderHFast = cBar.close < conditions.hFast[cIndex]; + + // + conditions.isHFastOverSlow = isHFastOverSlow; + conditions.isHFastUnderSlow = isHFastUnderSlow; + + // + conditions.isHFastCrossedOverSlow = isHFastCrossedOverSlow; + conditions.isHFastCrossedUnderSlow = isHFastCrossedUnderSlow; + + // + conditions.isClosedOverHFast = isClosedOverHFast; + conditions.isClosedUnderHFast = isClosedUnderHFast; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHMInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // AVG ... + double fastBuffer[]; + double slowBuffer[]; + + // + // Current ... + double cFastBuffer[]; + double cSlowBuffer[]; + + // + // Short ... + double sFastBuffer[]; + double sSlowBuffer[]; + + // + // Medium ... + double mFastBuffer[]; + double mSlowBuffer[]; + + // + // Long ... + double lFastBuffer[]; + double lSlowBuffer[]; + + // + // Hind ... + double hFastBuffer[]; + double hSlowBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_FAST_LINE, + 0, + totalBars, + fastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_SLOW_LINE, + 0, + totalBars, + slowBuffer + // + ); + + // + // Current ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_CFAST_LINE, + 0, + totalBars, + cFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_CSLOW_LINE, + 0, + totalBars, + cSlowBuffer + // + ); + + // + // Short ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_SFAST_LINE, + 0, + totalBars, + sFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_SSLOW_LINE, + 0, + totalBars, + sSlowBuffer + // + ); + + // + // Medium ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_MFAST_LINE, + 0, + totalBars, + mFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_MSLOW_LINE, + 0, + totalBars, + mSlowBuffer + // + ); + + // + // Long ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_LFAST_LINE, + 0, + totalBars, + lFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_LSLOW_LINE, + 0, + totalBars, + lSlowBuffer + // + ); + + // + // Hind ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_HFAST_LINE, + 0, + totalBars, + hFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_HSLOW_LINE, + 0, + totalBars, + hSlowBuffer + // + ); + } +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchstr.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchstr.helper.mq5 new file mode 100644 index 00000000..6ccda110 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchstr.helper.mq5 @@ -0,0 +1,3240 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHSTRHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHSTR_BUFFERS +{ + // + XCHSTR_C_LINE = 0, + XCHSTR_C_STATE_LINE = 11, + // + XCHSTR_S_LINE = 2, + XCHSTR_S_STATE_LINE = 16, + // + XCHSTR_M_LINE = 4, + XCHSTR_M_STATE_LINE = 21, + // + XCHSTR_L_LINE = 6, + XCHSTR_L_STATE_LINE = 26, + // + XCHSTR_H_LINE = 8, + XCHSTR_H_STATE_LINE = 31, +}; + +// +enum ENUM_XCHSTR_TREND_STATES +{ + X_STR_BULLISH = 1, // Bullish + X_STR_BEARISH = -1, // Bearish +}; + +// +// Input Models ... +struct XCHSTRInputs +{ + // + // Props ... + + // + // Market ... + int length; // Length + double multiplier; // Multiplier + ENUM_APPLIED_PRICE appliedTo; // Applied To + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHSTRInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + length = 0; + multiplier = 0; + appliedTo = PRICE_CLOSE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + length = 14; + multiplier = 3.5; + appliedTo = PRICE_MEDIAN; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length > 0 && + multiplier > 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(0, length) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHSTRConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cTrend[]; + double cState[]; + + // + // Short ... + double sTrend[]; + double sState[]; + + // + // Medium ... + double mTrend[]; + double mState[]; + + // + // Long ... + double lTrend[]; + double lState[]; + + // + // Hind ... + double hTrend[]; + double hState[]; + + // + // Conditions ... + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + + // + // Current ... + bool isCBullish; + bool isCBearish; + bool isCSwitchedToBullish; + bool isCSwitchedToBearish; + + // + // Short ... + bool isSBullish; + bool isSBearish; + bool isSSwitchedToBullish; + bool isSSwitchedToBearish; + + // + // Medium ... + bool isMBullish; + bool isMBearish; + bool isMSwitchedToBullish; + bool isMSwitchedToBearish; + + // + // Long ... + bool isLBullish; + bool isLBearish; + bool isLSwitchedToBullish; + bool isLSwitchedToBearish; + + // + // Hind ... + bool isHBullish; + bool isHBearish; + bool isHSwitchedToBullish; + bool isHSwitchedToBearish; + + // + void Clean() + { + // + Clean(cTrend); + Clean(cState); + Clean(sTrend); + Clean(sState); + Clean(mTrend); + Clean(mState); + Clean(lTrend); + Clean(lState); + Clean(hTrend); + Clean(hState); + + // + ArraySetAsSeries(cTrend, true); + ArraySetAsSeries(cState, true); + ArraySetAsSeries(sTrend, true); + ArraySetAsSeries(sState, true); + ArraySetAsSeries(mTrend, true); + ArraySetAsSeries(mState, true); + ArraySetAsSeries(lTrend, true); + ArraySetAsSeries(lState, true); + ArraySetAsSeries(hTrend, true); + ArraySetAsSeries(hState, true); + + // + // Conditions ... + + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + + // + // Current ... + isCBullish = false; + isCBearish = false; + isCSwitchedToBullish = false; + isCSwitchedToBearish = false; + + // + // Short ... + isSBullish = false; + isSBearish = false; + isSSwitchedToBullish = false; + isSSwitchedToBearish = false; + + // + // Medium ... + isMBullish = false; + isMBearish = false; + isMSwitchedToBullish = false; + isMSwitchedToBearish = false; + + // + // Long ... + isLBullish = false; + isLBearish = false; + isLSwitchedToBullish = false; + isLSwitchedToBearish = false; + + // + // Hind ... + isHBullish = false; + isHBearish = false; + isHSwitchedToBullish = false; + isHSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Conditions ... + + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + + // + // Current ... + if (isCBullish) + { + bullishScore++; + } + if (isCBearish) + { + bearishScore++; + } + if (isCSwitchedToBullish) + { + bullishScore++; + } + if (isCSwitchedToBearish) + { + bearishScore++; + } + + // + // Short ... + if (isSBullish) + { + bullishScore++; + } + if (isSBearish) + { + bearishScore++; + } + if (isSSwitchedToBullish) + { + bullishScore++; + } + if (isSSwitchedToBearish) + { + bearishScore++; + } + + // + // Medium ... + if (isMBullish) + { + bullishScore++; + } + if (isMBearish) + { + bearishScore++; + } + if (isMSwitchedToBullish) + { + bullishScore++; + } + if (isMSwitchedToBearish) + { + bearishScore++; + } + + // + // Long ... + if (isLBullish) + { + bullishScore++; + } + if (isLBearish) + { + bearishScore++; + } + if (isLSwitchedToBullish) + { + bullishScore++; + } + if (isLSwitchedToBearish) + { + bearishScore++; + } + + // + // Hind ... + if (isHBullish) + { + bullishScore++; + } + if (isHBearish) + { + bearishScore++; + } + if (isHSwitchedToBullish) + { + bullishScore++; + } + if (isHSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + + ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHSTR"; + } +}; + +// +// Class ... +class XSCXCHSTRHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHSTRHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHSTRHelper() + { + // + Clean(cTrendBuffer); + Clean(cStateBuffer); + Clean(sTrendBuffer); + Clean(sStateBuffer); + Clean(mTrendBuffer); + Clean(mStateBuffer); + Clean(lTrendBuffer); + Clean(lStateBuffer); + Clean(hTrendBuffer); + Clean(hStateBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHSTRInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cTrendBuffer, true); + ArraySetAsSeries(cStateBuffer, true); + ArraySetAsSeries(sTrendBuffer, true); + ArraySetAsSeries(sStateBuffer, true); + ArraySetAsSeries(mTrendBuffer, true); + ArraySetAsSeries(mStateBuffer, true); + ArraySetAsSeries(lTrendBuffer, true); + ArraySetAsSeries(lStateBuffer, true); + ArraySetAsSeries(hTrendBuffer, true); + ArraySetAsSeries(hStateBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchstr", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, // Length + mInputs.multiplier, // Multiplier + mInputs.appliedTo, // Applied To + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + mInputs.showCurrent, + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHSTRInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHSTRInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Current ... + + // + // Trend ... + + // + double GetCTrend( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cTrendBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCTrend( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cTrendBuffer, + buffer, + forceClean + // + ); + } + + // + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetCState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return (ENUM_XCHSTR_TREND_STATES)((int)cStateBuffer[barIndex]); + } + + // + // Copy Required Buffer ... + int CopyCState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + // Trend ... + + // + double GetSTrend( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sTrendBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySTrend( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sTrendBuffer, + buffer, + forceClean + // + ); + } + + // + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetSState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return (ENUM_XCHSTR_TREND_STATES)((int)sStateBuffer[barIndex]); + } + + // + // Copy Required Buffer ... + int CopySState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + // Trend ... + + // + double GetMTrend( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mTrendBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMTrend( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mTrendBuffer, + buffer, + forceClean + // + ); + } + + // + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetMState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return (ENUM_XCHSTR_TREND_STATES)((int)mStateBuffer[barIndex]); + } + + // + // Copy Required Buffer ... + int CopyMState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + // Trend ... + + // + double GetLTrend( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lTrendBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLTrend( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lTrendBuffer, + buffer, + forceClean + // + ); + } + + // + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetLState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return (ENUM_XCHSTR_TREND_STATES)((int)lStateBuffer[barIndex]); + } + + // + // Copy Required Buffer ... + int CopyLState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + // Trend ... + + // + double GetHTrend( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hTrendBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHTrend( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hTrendBuffer, + buffer, + forceClean + // + ); + } + + // + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetHState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return (ENUM_XCHSTR_TREND_STATES)((int)hStateBuffer[barIndex]); + } + + // + // Copy Required Buffer ... + int CopyHState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + ENUM_XCHSTR_TREND_STATES ToState(double state) + { + return (ENUM_XCHSTR_TREND_STATES)((int)state); + } + + // + bool IsBullish(double state) + { + // + bool result = false; + + // + result = + // + ToState(state) == X_STR_BULLISH; + // + ; + + // + return result; + } + + // + bool IsBearish(double state) + { + // + bool result = false; + + // + result = + // + ToState(state) == X_STR_BEARISH; + // + ; + + // + return result; + } + + // + int GetTrends( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = 0; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + iValue = GetCTrend(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + iValue = GetSTrend(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + iValue = GetMTrend(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + iValue = GetLTrend(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + iValue = GetHTrend(barIndex); + break; + } + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBullishTrends( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = 0; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + if (IsBullish((double)GetCState(barIndex))) + { + iValue = GetCTrend(barIndex); + } + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + if (IsBullish((double)GetSState(barIndex))) + { + iValue = GetSTrend(barIndex); + } + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + if (IsBullish((double)GetMState(barIndex))) + { + iValue = GetMTrend(barIndex); + } + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + if (IsBullish((double)GetLState(barIndex))) + { + iValue = GetLTrend(barIndex); + } + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + if (IsBullish((double)GetHState(barIndex))) + { + iValue = GetHTrend(barIndex); + } + break; + } + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBearishTrends( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = 0; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + if (IsBearish((double)GetCState(barIndex))) + { + iValue = GetCTrend(barIndex); + } + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + if (IsBearish((double)GetSState(barIndex))) + { + iValue = GetSTrend(barIndex); + } + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + if (IsBearish((double)GetMState(barIndex))) + { + iValue = GetMTrend(barIndex); + } + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + if (IsBearish((double)GetLState(barIndex))) + { + iValue = GetLTrend(barIndex); + } + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + if (IsBearish((double)GetHState(barIndex))) + { + iValue = GetHTrend(barIndex); + } + break; + } + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + double GetMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + result = GetCyclesMax( + barIndex, + cycles // + ); + + // + return result; + } + + // + double GetMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + result = GetCyclesMin( + barIndex, + cycles // + ); + + // + return result; + } + + // + double GetMaxBullish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetBullishTrends( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBullish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetBullishTrends( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBearish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetBearishTrends( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBearish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetBearishTrends( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetSpecifiedMax(trends); + + // + return result; + } + + // + double GetCyclesMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetSpecifiedMin(trends); + + // + return result; + } + + // + double GetCyclesMaxBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBullishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetSpecifiedMax(trends); + + // + return result; + } + + // + double GetCyclesMinBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBullishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetSpecifiedMin(trends); + + // + return result; + } + + // + double GetCyclesMaxBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBearishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetSpecifiedMax(trends); + + // + return result; + } + + // + double GetCyclesMinBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBearishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetSpecifiedMin(trends); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double power = 0; + double state = -100; + + // + // CURRENT ... + power = GetCTrend(barIndex); + state = (double)GetCState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // SHORT ... + power = GetSTrend(barIndex); + state = (double)GetSState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // MEDIUM ... + power = GetMTrend(barIndex); + state = (double)GetMState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // LONG ... + power = GetLTrend(barIndex); + state = (double)GetLState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // HIND ... + power = GetHTrend(barIndex); + state = (double)GetHState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double power = 0; + double state = -100; + + // + // CURRENT ... + power = GetCTrend(barIndex); + state = (double)GetCState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // SHORT ... + power = GetSTrend(barIndex); + state = (double)GetSState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // MEDIUM ... + power = GetMTrend(barIndex); + state = (double)GetMState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // LONG ... + power = GetLTrend(barIndex); + state = (double)GetLState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // HIND ... + power = GetHTrend(barIndex); + state = (double)GetHState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = 0; + double state = -100; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + power = GetCTrend(barIndex); + state = GetCState(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + power = GetSTrend(barIndex); + state = GetSState(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + power = GetMTrend(barIndex); + state = GetMState(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + power = GetLTrend(barIndex); + state = GetLState(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + power = GetHTrend(barIndex); + state = GetHState(barIndex); + break; + } + + // + if (power > 0 && state != -100) + { + // + if (IsBullish(state)) + { + result += power; + } + } + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = 0; + double state = -100; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + power = GetCTrend(barIndex); + state = GetCState(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + power = GetSTrend(barIndex); + state = GetSState(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + power = GetMTrend(barIndex); + state = GetMState(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + power = GetLTrend(barIndex); + state = GetLState(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + power = GetHTrend(barIndex); + state = GetHState(barIndex); + break; + } + + // + if (power > 0 && state != -100) + { + // + if (IsBearish(state)) + { + result += power; + } + } + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHSTRConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + CopyCTrend( + zIndex, + loopback, + conditions.cTrend // + ); + CopyCState( + zIndex, + loopback, + conditions.cState // + ); + + // + // Short ... + CopySTrend( + zIndex, + loopback, + conditions.sTrend // + ); + CopySState( + zIndex, + loopback, + conditions.sState // + ); + + // + // Medium ... + CopyMTrend( + zIndex, + loopback, + conditions.mTrend // + ); + CopyMState( + zIndex, + loopback, + conditions.mState // + ); + + // + // Long ... + CopyLTrend( + zIndex, + loopback, + conditions.lTrend // + ); + CopyLState( + zIndex, + loopback, + conditions.lState // + ); + + // + // Hind ... + CopyHTrend( + zIndex, + loopback, + conditions.hTrend // + ); + CopyHState( + zIndex, + loopback, + conditions.hState // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + + // + // Current ... + + // + bool isCBullish = IsBullish(conditions.cState[cIndex]); + bool isCBullishPrev = IsBullish(conditions.cState[pIndex]); + + // + bool isCBearish = IsBearish(conditions.cState[cIndex]); + bool isCBearishPrev = IsBearish(conditions.cState[pIndex]); + + // + bool isCSwitchedToBullish = isCBullish && + !isCBullishPrev; + bool isCSwitchedToBearish = isCBearish && + !isCBearishPrev; + + // + conditions.isCBullish = isCBullish; + conditions.isCBearish = isCBearish; + conditions.isCSwitchedToBullish = isCSwitchedToBullish; + conditions.isCSwitchedToBearish = isCSwitchedToBearish; + + // + // Short ... + + // + bool isSBullish = IsBullish(conditions.sState[cIndex]); + bool isSBullishPrev = IsBullish(conditions.sState[pIndex]); + + // + bool isSBearish = IsBearish(conditions.sState[cIndex]); + bool isSBearishPrev = IsBearish(conditions.sState[pIndex]); + + // + bool isSSwitchedToBullish = isSBullish && + !isSBullishPrev; + bool isSSwitchedToBearish = isSBearish && + !isSBearishPrev; + + // + conditions.isSBullish = isSBullish; + conditions.isSBearish = isSBearish; + conditions.isSSwitchedToBullish = isSSwitchedToBullish; + conditions.isSSwitchedToBearish = isSSwitchedToBearish; + + // + // Medium ... + + // + bool isMBullish = IsBullish(conditions.mState[cIndex]); + bool isMBullishPrev = IsBullish(conditions.mState[pIndex]); + + // + bool isMBearish = IsBearish(conditions.mState[cIndex]); + bool isMBearishPrev = IsBearish(conditions.mState[pIndex]); + + // + bool isMSwitchedToBullish = isMBullish && + !isMBullishPrev; + bool isMSwitchedToBearish = isMBearish && + !isMBearishPrev; + + // + conditions.isMBullish = isMBullish; + conditions.isMBearish = isMBearish; + conditions.isMSwitchedToBullish = isMSwitchedToBullish; + conditions.isMSwitchedToBearish = isMSwitchedToBearish; + + // + // Long ... + + // + bool isLBullish = IsBullish(conditions.lState[cIndex]); + bool isLBullishPrev = IsBullish(conditions.lState[pIndex]); + + // + bool isLBearish = IsBearish(conditions.lState[cIndex]); + bool isLBearishPrev = IsBearish(conditions.lState[pIndex]); + + // + bool isLSwitchedToBullish = isLBullish && + !isLBullishPrev; + bool isLSwitchedToBearish = isLBearish && + !isLBearishPrev; + + // + conditions.isLBullish = isLBullish; + conditions.isLBearish = isLBearish; + conditions.isLSwitchedToBullish = isLSwitchedToBullish; + conditions.isLSwitchedToBearish = isLSwitchedToBearish; + + // + // Hind ... + + // + bool isHBullish = IsBullish(conditions.hState[cIndex]); + bool isHBullishPrev = IsBullish(conditions.hState[pIndex]); + + // + bool isHBearish = IsBearish(conditions.hState[cIndex]); + bool isHBearishPrev = IsBearish(conditions.hState[pIndex]); + + // + bool isHSwitchedToBullish = isHBullish && + !isHBullishPrev; + bool isHSwitchedToBearish = isHBearish && + !isHBearishPrev; + + // + conditions.isHBullish = isHBullish; + conditions.isHBearish = isHBearish; + conditions.isHSwitchedToBullish = isHSwitchedToBullish; + conditions.isHSwitchedToBearish = isHSwitchedToBearish; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHSTRInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cTrendBuffer[]; + double cStateBuffer[]; + + // + // Short ... + double sTrendBuffer[]; + double sStateBuffer[]; + + // + // Medium ... + double mTrendBuffer[]; + double mStateBuffer[]; + + // + // Long ... + double lTrendBuffer[]; + double lStateBuffer[]; + + // + // Hind ... + double hTrendBuffer[]; + double hStateBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + + // + // Trend ... + CopyBuffer( + mHandler, + XCHSTR_C_LINE, + 0, + totalBars, + cTrendBuffer + // + ); + + // + // State ... + CopyBuffer( + mHandler, + XCHSTR_C_STATE_LINE, + 0, + totalBars, + cStateBuffer + // + ); + + // + // Short ... + + // + // Trend ... + CopyBuffer( + mHandler, + XCHSTR_S_LINE, + 0, + totalBars, + sTrendBuffer + // + ); + + // + // State ... + CopyBuffer( + mHandler, + XCHSTR_S_STATE_LINE, + 0, + totalBars, + sStateBuffer + // + ); + + // + // Medium ... + + // + // Trend ... + CopyBuffer( + mHandler, + XCHSTR_M_LINE, + 0, + totalBars, + mTrendBuffer + // + ); + + // + // State ... + CopyBuffer( + mHandler, + XCHSTR_M_STATE_LINE, + 0, + totalBars, + mStateBuffer + // + ); + + // + // Long ... + + // + // Trend ... + CopyBuffer( + mHandler, + XCHSTR_L_LINE, + 0, + totalBars, + lTrendBuffer + // + ); + + // + // State ... + CopyBuffer( + mHandler, + XCHSTR_L_STATE_LINE, + 0, + totalBars, + lStateBuffer + // + ); + + // + // Hind ... + + // + // Trend ... + CopyBuffer( + mHandler, + XCHSTR_H_LINE, + 0, + totalBars, + hTrendBuffer + // + ); + + // + // State ... + CopyBuffer( + mHandler, + XCHSTR_H_STATE_LINE, + 0, + totalBars, + hStateBuffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchswings.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchswings.helper.mq5 new file mode 100644 index 00000000..7fb79949 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchswings.helper.mq5 @@ -0,0 +1,1423 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHSwingsHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHSwings_BUFFERS +{ + // + // Current ... + XCHSwings_C_SH_LINE = 0, + XCHSwings_C_SL_LINE = 1, + // + // Short ... + XCHSwings_S_SH_LINE = 2, + XCHSwings_S_SL_LINE = 3, + // + // Medium ... + XCHSwings_M_SH_LINE = 4, + XCHSwings_M_SL_LINE = 5, + // + // Long ... + XCHSwings_L_SH_LINE = 6, + XCHSwings_L_SL_LINE = 7, + // + // Hind ... + XCHSwings_H_SH_LINE = 8, + XCHSwings_H_SL_LINE = 9, +}; + +// +// Input Models ... +struct XCHSwingsInputs +{ + // + // Props ... + + // + // Market ... + int length; // Length + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + bool showSwingHighs; // Show Swing Highs + bool showSwingLows; // Show Swing Lows + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHSwingsInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + length = 0; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showSwingHighs = false; + showSwingLows = false; + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + length = 14; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showSwingHighs = true; + showSwingLows = true; + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length > 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(0, length) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHSwingsConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cSH[]; + double cSL[]; + + // + // Short ... + double sSH[]; + double sSL[]; + + // + // Medium ... + double mSH[]; + double mSL[]; + + // + // Long ... + double lSH[]; + double lSL[]; + + // + // Hind ... + double hSH[]; + double hSL[]; + + // + // Conditions ... + + // + // Current ... + bool isCSwingHigh; + bool isCSwingLow; + + // + // Short ... + bool isSSwingHigh; + bool isSSwingLow; + + // + // Medium ... + bool isMSwingHigh; + bool isMSwingLow; + + // + // Long ... + bool isLSwingHigh; + bool isLSwingLow; + + // + // Hind ... + bool isHSwingHigh; + bool isHSwingLow; + + // + void Clean() + { + // + Clean(cSH); + Clean(cSL); + Clean(sSH); + Clean(sSL); + Clean(mSH); + Clean(mSL); + Clean(lSH); + Clean(lSL); + Clean(hSH); + Clean(hSL); + + // + ArraySetAsSeries(cSH, true); + ArraySetAsSeries(cSL, true); + ArraySetAsSeries(sSH, true); + ArraySetAsSeries(sSL, true); + ArraySetAsSeries(mSH, true); + ArraySetAsSeries(mSL, true); + ArraySetAsSeries(lSH, true); + ArraySetAsSeries(lSL, true); + ArraySetAsSeries(hSH, true); + ArraySetAsSeries(hSL, true); + + // + // Conditions ... + + // + // Current ... + isCSwingHigh = false; + isCSwingLow = false; + + // + // Short ... + isSSwingHigh = false; + isSSwingLow = false; + + // + // Medium ... + isMSwingHigh = false; + isMSwingLow = false; + + // + // Long ... + isLSwingHigh = false; + isLSwingLow = false; + + // + // Hind ... + isHSwingHigh = false; + isHSwingLow = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Conditions ... + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Current ... + ToString("isCSwingHigh", isCSwingHigh, ignoreFalseConditions, separator) + + ToString("isCSwingLow", isCSwingLow, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSSwingHigh", isSSwingHigh, ignoreFalseConditions, separator) + + ToString("isSSwingLow", isSSwingLow, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMSwingHigh", isMSwingHigh, ignoreFalseConditions, separator) + + ToString("isMSwingLow", isMSwingLow, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLSwingHigh", isLSwingHigh, ignoreFalseConditions, separator) + + ToString("isLSwingLow", isLSwingLow, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHSwingHigh", isHSwingHigh, ignoreFalseConditions, separator) + + ToString("isHSwingLow", isHSwingLow, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHSwings"; + } +}; + +// +// Class ... +class XSCXCHSwingsHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHSwingsHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHSwingsHelper() + { + // + Clean(cSHBuffer); + Clean(cSLBuffer); + Clean(sSHBuffer); + Clean(sSLBuffer); + Clean(mSHBuffer); + Clean(mSLBuffer); + Clean(lSHBuffer); + Clean(lSLBuffer); + Clean(hSHBuffer); + Clean(hSLBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHSwingsInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cSHBuffer, true); + ArraySetAsSeries(cSLBuffer, true); + ArraySetAsSeries(sSHBuffer, true); + ArraySetAsSeries(sSLBuffer, true); + ArraySetAsSeries(mSHBuffer, true); + ArraySetAsSeries(mSLBuffer, true); + ArraySetAsSeries(lSHBuffer, true); + ArraySetAsSeries(lSLBuffer, true); + ArraySetAsSeries(hSHBuffer, true); + ArraySetAsSeries(hSLBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchswings", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, // Length + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + mInputs.showSwingHighs, + mInputs.showSwingLows, + mInputs.showCurrent, + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHSwingsInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHSwingsInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Current ... + + // + double GetCSH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cSHBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCSH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSHBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCSL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cSLBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCSL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSLBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + double GetSSH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sSHBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySSH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSHBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSSL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sSLBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySSL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSLBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + double GetMSH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mSHBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMSH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSHBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMSL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mSLBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMSL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSLBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + double GetLSH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lSHBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLSH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSHBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLSL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lSLBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLSL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSLBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + double GetHSH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hSHBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHSH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSHBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHSL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hSLBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHSL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSLBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + // Conditions ... + + // + bool GetConditions( + XCHSwingsConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + CopyCSH( + zIndex, + loopback, + conditions.cSH // + ); + CopyCSL( + zIndex, + loopback, + conditions.cSL // + ); + + // + // Short ... + CopySSH( + zIndex, + loopback, + conditions.sSH // + ); + CopySSL( + zIndex, + loopback, + conditions.sSL // + ); + + // + // Medium ... + CopyMSH( + zIndex, + loopback, + conditions.mSH // + ); + CopyMSL( + zIndex, + loopback, + conditions.mSL // + ); + + // + // Long ... + CopyLSH( + zIndex, + loopback, + conditions.lSH // + ); + CopyLSL( + zIndex, + loopback, + conditions.lSL // + ); + + // + // Hind ... + CopyHSH( + zIndex, + loopback, + conditions.hSH // + ); + CopyHSL( + zIndex, + loopback, + conditions.hSL // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Current ... + + // + bool isCSwingHigh = + cSHBuffer[cIndex] != 0 && + cSHBuffer[cIndex] != EMPTY_VALUE; + + // + bool isCSwingLow = + cSLBuffer[cIndex] != 0 && + cSLBuffer[cIndex] != EMPTY_VALUE; + + // + conditions.isCSwingHigh = isCSwingHigh; + conditions.isCSwingLow = isCSwingLow; + + // + // Short ... + + // + bool isSSwingHigh = + sSHBuffer[cIndex] != 0 && + sSHBuffer[cIndex] != EMPTY_VALUE; + + // + bool isSSwingLow = + sSLBuffer[cIndex] != 0 && + sSLBuffer[cIndex] != EMPTY_VALUE; + + // + conditions.isSSwingHigh = isSSwingHigh; + conditions.isSSwingLow = isSSwingLow; + + // + // Medium ... + + // + bool isMSwingHigh = + mSHBuffer[cIndex] != 0 && + mSHBuffer[cIndex] != EMPTY_VALUE; + + // + bool isMSwingLow = + mSLBuffer[cIndex] != 0 && + mSLBuffer[cIndex] != EMPTY_VALUE; + + // + conditions.isMSwingHigh = isMSwingHigh; + conditions.isMSwingLow = isMSwingLow; + + // + // Long ... + + // + bool isLSwingHigh = + lSHBuffer[cIndex] != 0 && + lSHBuffer[cIndex] != EMPTY_VALUE; + + // + bool isLSwingLow = + lSLBuffer[cIndex] != 0 && + lSLBuffer[cIndex] != EMPTY_VALUE; + + // + conditions.isLSwingHigh = isLSwingHigh; + conditions.isLSwingLow = isLSwingLow; + + // + // Hind ... + + // + bool isHSwingHigh = + hSHBuffer[cIndex] != 0 && + hSHBuffer[cIndex] != EMPTY_VALUE; + + // + bool isHSwingLow = + hSLBuffer[cIndex] != 0 && + hSLBuffer[cIndex] != EMPTY_VALUE; + + // + conditions.isHSwingHigh = isHSwingHigh; + conditions.isHSwingLow = isHSwingLow; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHSwingsInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cSHBuffer[]; + double cSLBuffer[]; + + // + double sSHBuffer[]; + double sSLBuffer[]; + // Short ... + + // + // Medium ... + double mSHBuffer[]; + double mSLBuffer[]; + + // + // Long ... + double lSHBuffer[]; + double lSLBuffer[]; + + // + // Hind ... + double hSHBuffer[]; + double hSLBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + CopyBuffer( + mHandler, + XCHSwings_C_SH_LINE, + 0, + totalBars, + cSHBuffer + // + ); + CopyBuffer( + mHandler, + XCHSwings_C_SL_LINE, + 0, + totalBars, + cSLBuffer + // + ); + + // + // Short ... + CopyBuffer( + mHandler, + XCHSwings_S_SH_LINE, + 0, + totalBars, + sSHBuffer + // + ); + CopyBuffer( + mHandler, + XCHSwings_S_SL_LINE, + 0, + totalBars, + sSLBuffer + // + ); + + // + // Medium ... + CopyBuffer( + mHandler, + XCHSwings_M_SH_LINE, + 0, + totalBars, + mSHBuffer + // + ); + CopyBuffer( + mHandler, + XCHSwings_M_SL_LINE, + 0, + totalBars, + mSLBuffer + // + ); + + // + // Long ... + CopyBuffer( + mHandler, + XCHSwings_L_SH_LINE, + 0, + totalBars, + lSHBuffer + // + ); + CopyBuffer( + mHandler, + XCHSwings_L_SL_LINE, + 0, + totalBars, + lSLBuffer + // + ); + + // + // Hind ... + CopyBuffer( + mHandler, + XCHSwings_H_SH_LINE, + 0, + totalBars, + hSHBuffer + // + ); + CopyBuffer( + mHandler, + XCHSwings_H_SL_LINE, + 0, + totalBars, + hSLBuffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchtd.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchtd.helper.mq5 new file mode 100644 index 00000000..92ade3ad --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchtd.helper.mq5 @@ -0,0 +1,2956 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHTDHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +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 +}; + +// +enum ENUM_XCHTD_BUFFERS +{ + // + XCHTD_C_BULL_LINE = 0, + XCHTD_C_BEAR_LINE = 1, + // + XCHTD_S_BULL_LINE = 2, + XCHTD_S_BEAR_LINE = 3, + // + XCHTD_M_BULL_LINE = 4, + XCHTD_M_BEAR_LINE = 5, + // + XCHTD_L_BULL_LINE = 6, + XCHTD_L_BEAR_LINE = 7, + // + XCHTD_H_BULL_LINE = 8, + XCHTD_H_BEAR_LINE = 9, +}; + +// +// Input Models ... +struct XCHTDInputs +{ + // + // Props ... + + // + // Market ... + int length; // Length + ENUM_XCHTD_MODE mode; // Mode + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHTDInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + length = 0; + mode = XCHTD_POWER_MODE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + length = 14; + mode = XCHTD_POWER_MODE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length > 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(0, length) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHTDConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cBull[]; + double cBear[]; + + // + // Short ... + double sBull[]; + double sBear[]; + + // + // Medium ... + double mBull[]; + double mBear[]; + + // + // Long ... + double lBull[]; + double lBear[]; + + // + // Hind ... + double hBull[]; + double hBear[]; + + // + // Conditions ... + + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + + // + // Current ... + bool isCBullish; + bool isCBearish; + bool isCSwitchedToBullish; + bool isCSwitchedToBearish; + + // + // Short ... + bool isSBullish; + bool isSBearish; + bool isSSwitchedToBullish; + bool isSSwitchedToBearish; + + // + // Medium ... + bool isMBullish; + bool isMBearish; + bool isMSwitchedToBullish; + bool isMSwitchedToBearish; + + // + // Long ... + bool isLBullish; + bool isLBearish; + bool isLSwitchedToBullish; + bool isLSwitchedToBearish; + + // + // Hind ... + bool isHBullish; + bool isHBearish; + bool isHSwitchedToBullish; + bool isHSwitchedToBearish; + + // + void Clean() + { + // + Clean(cBull); + Clean(cBear); + Clean(sBull); + Clean(sBear); + Clean(mBull); + Clean(mBear); + Clean(lBull); + Clean(lBear); + Clean(hBull); + Clean(hBear); + + // + ArraySetAsSeries(cBull, true); + ArraySetAsSeries(cBear, true); + ArraySetAsSeries(sBull, true); + ArraySetAsSeries(sBear, true); + ArraySetAsSeries(mBull, true); + ArraySetAsSeries(mBear, true); + ArraySetAsSeries(lBull, true); + ArraySetAsSeries(lBear, true); + ArraySetAsSeries(hBull, true); + ArraySetAsSeries(hBear, true); + + // + // Conditions ... + + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + + // + // Current ... + isCBullish = false; + isCBearish = false; + isCSwitchedToBullish = false; + isCSwitchedToBearish = false; + + // + // Short ... + isSBullish = false; + isSBearish = false; + isSSwitchedToBullish = false; + isSSwitchedToBearish = false; + + // + // Medium ... + isMBullish = false; + isMBearish = false; + isMSwitchedToBullish = false; + isMSwitchedToBearish = false; + + // + // Long ... + isLBullish = false; + isLBearish = false; + isLSwitchedToBullish = false; + isLSwitchedToBearish = false; + + // + // Hind ... + isHBullish = false; + isHBearish = false; + isHSwitchedToBullish = false; + isHSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Conditions ... + + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + + // + // Current ... + if (isCBullish) + { + bullishScore++; + } + if (isCBearish) + { + bearishScore++; + } + if (isCSwitchedToBullish) + { + bullishScore++; + } + if (isCSwitchedToBearish) + { + bearishScore++; + } + + // + // Short ... + if (isSBullish) + { + bullishScore++; + } + if (isSBearish) + { + bearishScore++; + } + if (isSSwitchedToBullish) + { + bullishScore++; + } + if (isSSwitchedToBearish) + { + bearishScore++; + } + + // + // Medium ... + if (isMBullish) + { + bullishScore++; + } + if (isMBearish) + { + bearishScore++; + } + if (isMSwitchedToBullish) + { + bullishScore++; + } + if (isMSwitchedToBearish) + { + bearishScore++; + } + + // + // Long ... + if (isLBullish) + { + bullishScore++; + } + if (isLBearish) + { + bearishScore++; + } + if (isLSwitchedToBullish) + { + bullishScore++; + } + if (isLSwitchedToBearish) + { + bearishScore++; + } + + // + // Hind ... + if (isHBullish) + { + bullishScore++; + } + if (isHBearish) + { + bearishScore++; + } + if (isHSwitchedToBullish) + { + bullishScore++; + } + if (isHSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + + ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHTD"; + } +}; + +// +// Class ... +class XSCXCHTDHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHTDHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHTDHelper() + { + // + Clean(cBullBuffer); + Clean(cBearBuffer); + Clean(sBullBuffer); + Clean(sBearBuffer); + Clean(mBullBuffer); + Clean(mBearBuffer); + Clean(lBullBuffer); + Clean(lBearBuffer); + Clean(hBullBuffer); + Clean(hBearBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHTDInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cBullBuffer, true); + ArraySetAsSeries(cBearBuffer, true); + ArraySetAsSeries(sBullBuffer, true); + ArraySetAsSeries(sBearBuffer, true); + ArraySetAsSeries(mBullBuffer, true); + ArraySetAsSeries(mBearBuffer, true); + ArraySetAsSeries(lBullBuffer, true); + ArraySetAsSeries(lBearBuffer, true); + ArraySetAsSeries(hBullBuffer, true); + ArraySetAsSeries(hBearBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchtd", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, // Length + mInputs.mode, // Mode + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + mInputs.showCurrent, + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHTDInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHTDInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Current ... + + // + double GetCBull( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cBullBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCBull( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cBullBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCBear( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cBearBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCBear( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cBearBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + double GetSBull( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sBullBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySBull( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sBullBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSBear( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sBearBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySBear( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sBearBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + double GetMBull( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mBullBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMBull( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mBullBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMBear( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mBearBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMBear( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mBearBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + double GetLBull( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lBullBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLBull( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lBullBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLBear( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lBearBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLBear( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lBearBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + double GetHBull( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hBullBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHBull( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hBullBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHBear( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hBearBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHBear( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hBearBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + void GetCycle( + int barIndex, // Bar Index + double &bull, + double &bear, + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + bull = 0; + bear = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + bull = GetCBull(barIndex); + bear = GetCBear(barIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + bull = GetSBull(barIndex); + bear = GetSBear(barIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + bull = GetMBull(barIndex); + bear = GetMBear(barIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + bull = GetLBull(barIndex); + bear = GetLBear(barIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + bull = GetHBull(barIndex); + bear = GetHBear(barIndex); + break; + } + } + + // + bool IsCycleBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + bool result = false; + + // + double bull = 0; + double bear = 0; + GetCycle( + barIndex, + bull, + bear, + cycle // + ); + + // + result = bull > bear; + + // + return result; + } + + // + bool IsCycleBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + bool result = false; + + // + double bull = 0; + double bear = 0; + GetCycle( + barIndex, + bull, + bear, + cycle // + ); + + // + result = bull < bear; + + // + return result; + } + + // + double GetCyclePower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double bull = 0; + double bear = 0; + GetCycle( + barIndex, + bull, + bear, + cycle // + ); + + // + result = MathAbs(bull - bear); + + // + return result; + } + + // + int GetPowers( + int barIndex, // Bar Index + double &values[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int count = GetAllMarketCycles(allCycles); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetCyclesPowers( + barIndex, + values, + allCycles // + ); + + // + return result; + } + + // + int GetCyclesPowers( + int barIndex, // Bar Index + double &values[], + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValue = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + Add( + iValue, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBullishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int count = GetAllMarketCycles(allCycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isBullish = IsCycleBullish( + barIndex, + allCycles[i] // + ); + + // + if (isBullish) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetBearishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int count = GetAllMarketCycles(allCycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isBearish = IsCycleBearish( + barIndex, + allCycles[i] // + ); + + // + if (isBearish) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetBullishCyclesPowers( + int barIndex, // Bar Index + double &values[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBullishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetCyclesPowers( + barIndex, + values, + cycles // + ); + + // + return result; + } + + // + int GetBearishCyclesPowers( + int barIndex, // Bar Index + double &values[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBearishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetCyclesPowers( + barIndex, + values, + cycles // + ); + + // + return result; + } + + // + double GetMaxPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesMaxPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesPowers( + barIndex, + values, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesMinPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesPowers( + barIndex, + values, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBullishCyclesPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBullishCyclesPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBearishCyclesPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBearishCyclesPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBullishCyclesPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSum(values); + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBearishCyclesPowers( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSum(values); + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + bool isBullish = IsCycleBullish( + barIndex, + cycles[i] // + ); + if (isBullish) + { + // + double power = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + result += MathAbs(power); + } + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + bool isBearish = IsCycleBearish( + barIndex, + cycles[i] // + ); + if (isBearish) + { + // + double power = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + result += MathAbs(power); + } + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHTDConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + CopyCBull( + zIndex, + loopback, + conditions.cBull // + ); + CopyCBear( + zIndex, + loopback, + conditions.cBear // + ); + + // + // Short ... + CopySBull( + zIndex, + loopback, + conditions.sBull // + ); + CopySBear( + zIndex, + loopback, + conditions.sBear // + ); + + // + // Medium ... + CopyMBull( + zIndex, + loopback, + conditions.mBull // + ); + CopyMBear( + zIndex, + loopback, + conditions.mBear // + ); + + // + // Long ... + CopyLBull( + zIndex, + loopback, + conditions.lBull // + ); + CopyLBear( + zIndex, + loopback, + conditions.lBear // + ); + + // + // Hind ... + CopyHBull( + zIndex, + loopback, + conditions.hBull // + ); + CopyHBear( + zIndex, + loopback, + conditions.hBear // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + + // + // Current ... + + // + bool isCBullish = conditions.cBull[cIndex] > conditions.cBear[cIndex]; + bool isCBullishPrev = conditions.cBull[pIndex] > conditions.cBear[pIndex]; + + // + bool isCBearish = conditions.cBull[cIndex] < conditions.cBear[cIndex]; + bool isCBearishPrev = conditions.cBull[pIndex] < conditions.cBear[pIndex]; + + // + bool isCSwitchedToBullish = isCBullish && + !isCBullishPrev; + bool isCSwitchedToBearish = isCBearish && + !isCBearishPrev; + + // + conditions.isCBullish = isCBullish; + conditions.isCBearish = isCBearish; + conditions.isCSwitchedToBullish = isCSwitchedToBullish; + conditions.isCSwitchedToBearish = isCSwitchedToBearish; + + // + // Short ... + + // + bool isSBullish = conditions.sBull[cIndex] > conditions.sBear[cIndex]; + bool isSBullishPrev = conditions.sBull[pIndex] > conditions.sBear[pIndex]; + + // + bool isSBearish = conditions.sBull[cIndex] < conditions.sBear[cIndex]; + bool isSBearishPrev = conditions.sBull[pIndex] < conditions.sBear[pIndex]; + + // + bool isSSwitchedToBullish = isSBullish && + !isSBullishPrev; + bool isSSwitchedToBearish = isSBearish && + !isSBearishPrev; + + // + conditions.isSBullish = isSBullish; + conditions.isSBearish = isSBearish; + conditions.isSSwitchedToBullish = isSSwitchedToBullish; + conditions.isSSwitchedToBearish = isSSwitchedToBearish; + + // + // Medium ... + + // + bool isMBullish = conditions.mBull[cIndex] > conditions.mBear[cIndex]; + bool isMBullishPrev = conditions.mBull[pIndex] > conditions.mBear[pIndex]; + + // + bool isMBearish = conditions.mBull[cIndex] < conditions.mBear[cIndex]; + bool isMBearishPrev = conditions.mBull[pIndex] < conditions.mBear[pIndex]; + + // + bool isMSwitchedToBullish = isMBullish && + !isMBullishPrev; + bool isMSwitchedToBearish = isMBearish && + !isMBearishPrev; + + // + conditions.isMBullish = isMBullish; + conditions.isMBearish = isMBearish; + conditions.isMSwitchedToBullish = isMSwitchedToBullish; + conditions.isMSwitchedToBearish = isMSwitchedToBearish; + + // + // Long ... + + // + bool isLBullish = conditions.lBull[cIndex] > conditions.lBear[cIndex]; + bool isLBullishPrev = conditions.lBull[pIndex] > conditions.lBear[pIndex]; + + // + bool isLBearish = conditions.lBull[cIndex] < conditions.lBear[cIndex]; + bool isLBearishPrev = conditions.lBull[pIndex] < conditions.lBear[pIndex]; + + // + bool isLSwitchedToBullish = isLBullish && + !isLBullishPrev; + bool isLSwitchedToBearish = isLBearish && + !isLBearishPrev; + + // + conditions.isLBullish = isLBullish; + conditions.isLBearish = isLBearish; + conditions.isLSwitchedToBullish = isLSwitchedToBullish; + conditions.isLSwitchedToBearish = isLSwitchedToBearish; + + // + // Hind ... + + // + bool isHBullish = conditions.hBull[cIndex] > conditions.hBear[cIndex]; + bool isHBullishPrev = conditions.hBull[pIndex] > conditions.hBear[pIndex]; + + // + bool isHBearish = conditions.hBull[cIndex] < conditions.hBear[cIndex]; + bool isHBearishPrev = conditions.hBull[pIndex] < conditions.hBear[pIndex]; + + // + bool isHSwitchedToBullish = isHBullish && + !isHBullishPrev; + bool isHSwitchedToBearish = isHBearish && + !isHBearishPrev; + + // + conditions.isHBullish = isHBullish; + conditions.isHBearish = isHBearish; + conditions.isHSwitchedToBullish = isHSwitchedToBullish; + conditions.isHSwitchedToBearish = isHSwitchedToBearish; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHTDInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cBullBuffer[]; + double cBearBuffer[]; + + // + // Short ... + double sBullBuffer[]; + double sBearBuffer[]; + + // + // Medium ... + double mBullBuffer[]; + double mBearBuffer[]; + + // + // Long ... + double lBullBuffer[]; + double lBearBuffer[]; + + // + // Hind ... + double hBullBuffer[]; + double hBearBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + + // + // Bull ... + CopyBuffer( + mHandler, + XCHTD_C_BULL_LINE, + 0, + totalBars, + cBullBuffer + // + ); + + // + // Bear ... + CopyBuffer( + mHandler, + XCHTD_C_BEAR_LINE, + 0, + totalBars, + cBearBuffer + // + ); + + // + // Short ... + + // + // Bull ... + CopyBuffer( + mHandler, + XCHTD_S_BULL_LINE, + 0, + totalBars, + sBullBuffer + // + ); + + // + // Bear ... + CopyBuffer( + mHandler, + XCHTD_S_BEAR_LINE, + 0, + totalBars, + sBearBuffer + // + ); + + // + // Medium ... + + // + // Bull ... + CopyBuffer( + mHandler, + XCHTD_M_BULL_LINE, + 0, + totalBars, + mBullBuffer + // + ); + + // + // Bear ... + CopyBuffer( + mHandler, + XCHTD_M_BEAR_LINE, + 0, + totalBars, + mBearBuffer + // + ); + + // + // Long ... + + // + // Bull ... + CopyBuffer( + mHandler, + XCHTD_L_BULL_LINE, + 0, + totalBars, + lBullBuffer + // + ); + + // + // Bear ... + CopyBuffer( + mHandler, + XCHTD_L_BEAR_LINE, + 0, + totalBars, + lBearBuffer + // + ); + + // + // Hind ... + + // + // Bull ... + CopyBuffer( + mHandler, + XCHTD_H_BULL_LINE, + 0, + totalBars, + hBullBuffer + // + ); + + // + // Bear ... + CopyBuffer( + mHandler, + XCHTD_H_BEAR_LINE, + 0, + totalBars, + hBearBuffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchvlm.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchvlm.helper.mq5 new file mode 100644 index 00000000..e4bc4c82 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchvlm.helper.mq5 @@ -0,0 +1,2465 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHVLMHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHVLM_BUFFERS +{ + // + XCHVLM_C_LINE = 0, + // + XCHVLM_S_LINE = 2, + // + XCHVLM_M_LINE = 4, + // + XCHVLM_L_LINE = 6, + // + XCHVLM_H_LINE = 8, +}; + +// +enum ENUM_XCHVLM_STATES +{ + // + XCHVLM_BULLISH_STATE = 0, + XCHVLM_BEARISH_STATE = 1, +}; + +// +// Input Models ... +struct XCHVLMInputs +{ + // + // Props ... + + // + // Market ... + int length; // Length + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHVLMInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + length = 0; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + length = 14; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length > 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(0, length) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHVLMConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cVolume[]; + + // + // Short ... + double sVolume[]; + + // + // Medium ... + double mVolume[]; + + // + // Long ... + double lVolume[]; + + // + // Hind ... + double hVolume[]; + + // + // Conditions ... + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + + // + // Current ... + bool isCBullish; + bool isCBearish; + bool isCSwitchedToBullish; + bool isCSwitchedToBearish; + + // + // Short ... + bool isSBullish; + bool isSBearish; + bool isSSwitchedToBullish; + bool isSSwitchedToBearish; + + // + // Medium ... + bool isMBullish; + bool isMBearish; + bool isMSwitchedToBullish; + bool isMSwitchedToBearish; + + // + // Long ... + bool isLBullish; + bool isLBearish; + bool isLSwitchedToBullish; + bool isLSwitchedToBearish; + + // + // Hind ... + bool isHBullish; + bool isHBearish; + bool isHSwitchedToBullish; + bool isHSwitchedToBearish; + + // + void Clean() + { + // + Clean(cVolume); + Clean(sVolume); + Clean(mVolume); + Clean(lVolume); + Clean(hVolume); + + // + ArraySetAsSeries(cVolume, true); + ArraySetAsSeries(sVolume, true); + ArraySetAsSeries(mVolume, true); + ArraySetAsSeries(lVolume, true); + ArraySetAsSeries(hVolume, true); + + // + // Conditions ... + + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + + // + // Current ... + isCBullish = false; + isCBearish = false; + isCSwitchedToBullish = false; + isCSwitchedToBearish = false; + + // + // Short ... + isSBullish = false; + isSBearish = false; + isSSwitchedToBullish = false; + isSSwitchedToBearish = false; + + // + // Medium ... + isMBullish = false; + isMBearish = false; + isMSwitchedToBullish = false; + isMSwitchedToBearish = false; + + // + // Long ... + isLBullish = false; + isLBearish = false; + isLSwitchedToBullish = false; + isLSwitchedToBearish = false; + + // + // Hind ... + isHBullish = false; + isHBearish = false; + isHSwitchedToBullish = false; + isHSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Conditions ... + + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + + // + // Current ... + if (isCBullish) + { + bullishScore++; + } + if (isCBearish) + { + bearishScore++; + } + if (isCSwitchedToBullish) + { + bullishScore++; + } + if (isCSwitchedToBearish) + { + bearishScore++; + } + + // + // Short ... + if (isSBullish) + { + bullishScore++; + } + if (isSBearish) + { + bearishScore++; + } + if (isSSwitchedToBullish) + { + bullishScore++; + } + if (isSSwitchedToBearish) + { + bearishScore++; + } + + // + // Medium ... + if (isMBullish) + { + bullishScore++; + } + if (isMBearish) + { + bearishScore++; + } + if (isMSwitchedToBullish) + { + bullishScore++; + } + if (isMSwitchedToBearish) + { + bearishScore++; + } + + // + // Long ... + if (isLBullish) + { + bullishScore++; + } + if (isLBearish) + { + bearishScore++; + } + if (isLSwitchedToBullish) + { + bullishScore++; + } + if (isLSwitchedToBearish) + { + bearishScore++; + } + + // + // Hind ... + if (isHBullish) + { + bullishScore++; + } + if (isHBearish) + { + bearishScore++; + } + if (isHSwitchedToBullish) + { + bullishScore++; + } + if (isHSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + + ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHVLM"; + } +}; + +// +// Class ... +class XSCXCHVLMHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHVLMHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHVLMHelper() + { + // + Clean(cVolumeBuffer); + Clean(sVolumeBuffer); + Clean(mVolumeBuffer); + Clean(lVolumeBuffer); + Clean(hVolumeBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHVLMInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cVolumeBuffer, true); + ArraySetAsSeries(sVolumeBuffer, true); + ArraySetAsSeries(mVolumeBuffer, true); + ArraySetAsSeries(lVolumeBuffer, true); + ArraySetAsSeries(hVolumeBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchvlm", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, // Length + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + mInputs.showCurrent, + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHVLMInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHVLMInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Current ... + + // + double GetC( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cVolumeBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyC( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + double GetS( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sVolumeBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyS( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + double GetM( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mVolumeBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyM( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + double GetL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lVolumeBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + double GetH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hVolumeBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hVolumeBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + ENUM_XCHVLM_STATES ToState(double value) + { + // + ENUM_XCHVLM_STATES result = value >= 0 + ? XCHVLM_BULLISH_STATE + : XCHVLM_BEARISH_STATE; + + // + return result; + } + + // + bool IsBullish(double value) + { + // + bool result = false; + + // + result = + // + ToState(value) == XCHVLM_BULLISH_STATE; + // + ; + + // + return result; + } + + // + bool IsBearish(double value) + { + // + bool result = false; + + // + result = + // + ToState(value) == XCHVLM_BEARISH_STATE; + // + ; + + // + return result; + } + + // + int GetValues( + int barIndex, // Bar Index + double &values[] // Result + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + Add( + iValue, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + double GetCycleValue( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // Cycle + ) + { + // + double result = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + result = GetC(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + result = GetS(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + result = GetM(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + result = GetL(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + result = GetH(barIndex); + break; + } + + // + return result; + } + + // + int GetBullishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double cValue = GetCycleValue( + barIndex, + allCycles[i] // + ); + + // + if (IsBullish(cValue)) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetBearishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double cValue = GetCycleValue( + barIndex, + allCycles[i] // + ); + + // + if (IsBearish(cValue)) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetCyclesValues( + int barIndex, // Bar Index + double &values[], // Values + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + Clean(values); + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValue = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + Add( + iValue, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBullishCyclesValues( + int barIndex, // Bar Index + double &values[] // Values + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBullishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetCyclesValues( + barIndex, + values, + cycles // + ); + + // + return result; + } + + // + int GetBearishCyclesValues( + int barIndex, // Bar Index + double &values[] // Values + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBearishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetCyclesValues( + barIndex, + values, + cycles // + ); + + // + return result; + } + + // + double GetCyclesMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesValues( + barIndex, + values, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesValues( + barIndex, + values, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int valuesCount = GetValues( + barIndex, + values // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int valuesCount = GetValues( + barIndex, + values // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBullishCyclesValues( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = MathAbs(GetSum(values)); + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBearishCyclesValues( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = MathAbs(GetSum(values)); + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + if (IsBullish(power)) + { + result += MathAbs(power); + } + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + if (IsBearish(power)) + { + result += MathAbs(power); + } + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHVLMConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + CopyC( + zIndex, + loopback, + conditions.cVolume // + ); + + // + // Short ... + CopyS( + zIndex, + loopback, + conditions.sVolume // + ); + + // + // Medium ... + CopyM( + zIndex, + loopback, + conditions.mVolume // + ); + + // + // Long ... + CopyL( + zIndex, + loopback, + conditions.lVolume // + ); + + // + // Hind ... + CopyH( + zIndex, + loopback, + conditions.hVolume // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + + // + // Current ... + + // + bool isCBullish = IsBullish(conditions.cVolume[cIndex]); + bool isCBullishPrev = IsBullish(conditions.cVolume[pIndex]); + + // + bool isCBearish = IsBearish(conditions.cVolume[cIndex]); + bool isCBearishPrev = IsBearish(conditions.cVolume[pIndex]); + + // + bool isCSwitchedToBullish = isCBullish && + !isCBullishPrev; + bool isCSwitchedToBearish = isCBearish && + !isCBearishPrev; + + // + conditions.isCBullish = isCBullish; + conditions.isCBearish = isCBearish; + conditions.isCSwitchedToBullish = isCSwitchedToBullish; + conditions.isCSwitchedToBearish = isCSwitchedToBearish; + + // + // Short ... + + // + bool isSBullish = IsBullish(conditions.sVolume[cIndex]); + bool isSBullishPrev = IsBullish(conditions.sVolume[pIndex]); + + // + bool isSBearish = IsBearish(conditions.sVolume[cIndex]); + bool isSBearishPrev = IsBearish(conditions.sVolume[pIndex]); + + // + bool isSSwitchedToBullish = isSBullish && + !isSBullishPrev; + bool isSSwitchedToBearish = isSBearish && + !isSBearishPrev; + + // + conditions.isSBullish = isSBullish; + conditions.isSBearish = isSBearish; + conditions.isSSwitchedToBullish = isSSwitchedToBullish; + conditions.isSSwitchedToBearish = isSSwitchedToBearish; + + // + // Medium ... + + // + bool isMBullish = IsBullish(conditions.mVolume[cIndex]); + bool isMBullishPrev = IsBullish(conditions.mVolume[pIndex]); + + // + bool isMBearish = IsBearish(conditions.mVolume[cIndex]); + bool isMBearishPrev = IsBearish(conditions.mVolume[pIndex]); + + // + bool isMSwitchedToBullish = isMBullish && + !isMBullishPrev; + bool isMSwitchedToBearish = isMBearish && + !isMBearishPrev; + + // + conditions.isMBullish = isMBullish; + conditions.isMBearish = isMBearish; + conditions.isMSwitchedToBullish = isMSwitchedToBullish; + conditions.isMSwitchedToBearish = isMSwitchedToBearish; + + // + // Long ... + + // + bool isLBullish = IsBullish(conditions.lVolume[cIndex]); + bool isLBullishPrev = IsBullish(conditions.lVolume[pIndex]); + + // + bool isLBearish = IsBearish(conditions.lVolume[cIndex]); + bool isLBearishPrev = IsBearish(conditions.lVolume[pIndex]); + + // + bool isLSwitchedToBullish = isLBullish && + !isLBullishPrev; + bool isLSwitchedToBearish = isLBearish && + !isLBearishPrev; + + // + conditions.isLBullish = isLBullish; + conditions.isLBearish = isLBearish; + conditions.isLSwitchedToBullish = isLSwitchedToBullish; + conditions.isLSwitchedToBearish = isLSwitchedToBearish; + + // + // Hind ... + + // + bool isHBullish = IsBullish(conditions.hVolume[cIndex]); + bool isHBullishPrev = IsBullish(conditions.hVolume[pIndex]); + + // + bool isHBearish = IsBearish(conditions.hVolume[cIndex]); + bool isHBearishPrev = IsBearish(conditions.hVolume[pIndex]); + + // + bool isHSwitchedToBullish = isHBullish && + !isHBullishPrev; + bool isHSwitchedToBearish = isHBearish && + !isHBearishPrev; + + // + conditions.isHBullish = isHBullish; + conditions.isHBearish = isHBearish; + conditions.isHSwitchedToBullish = isHSwitchedToBullish; + conditions.isHSwitchedToBearish = isHSwitchedToBearish; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHVLMInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cVolumeBuffer[]; + + // + // Short ... + double sVolumeBuffer[]; + + // + // Medium ... + double mVolumeBuffer[]; + + // + // Long ... + double lVolumeBuffer[]; + + // + // Hind ... + double hVolumeBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + CopyBuffer( + mHandler, + XCHVLM_C_LINE, + 0, + totalBars, + cVolumeBuffer + // + ); + + // + // Short ... + CopyBuffer( + mHandler, + XCHVLM_S_LINE, + 0, + totalBars, + sVolumeBuffer + // + ); + + // + // Medium ... + CopyBuffer( + mHandler, + XCHVLM_M_LINE, + 0, + totalBars, + mVolumeBuffer + // + ); + + // + // Long ... + CopyBuffer( + mHandler, + XCHVLM_L_LINE, + 0, + totalBars, + lVolumeBuffer + // + ); + + // + // Hind ... + CopyBuffer( + mHandler, + XCHVLM_H_LINE, + 0, + totalBars, + hVolumeBuffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchvwap.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchvwap.helper.mq5 new file mode 100644 index 00000000..dda8248a --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xchvwap.helper.mq5 @@ -0,0 +1,2702 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHVWAPHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHVWAP_BUFFERS +{ + // + XCHVWAP_S_LINE = 0, + XCHVWAP_S_STATE_LINE = 10, + // + XCHVWAP_M_LINE = 2, + XCHVWAP_M_STATE_LINE = 11, + // + XCHVWAP_L_LINE = 4, + XCHVWAP_L_STATE_LINE = 12, + // + XCHVWAP_H_LINE = 6, + XCHVWAP_H_STATE_LINE = 13, +}; + +// +enum ENUM_XCHVWAP_STATES +{ + // + XCHVWAP_BULLISH_STATE = 1, + XCHVWAP_BEARISH_STATE = 2, + XCHVWAP_NEUTURAL_STATE = 3, +}; + +// +// Input Models ... +struct XCHVWAPInputs +{ + // + // Props ... + + // + // Market ... + ENUM_APPLIED_PRICE appliedTo; // Applied To + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHVWAPInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + appliedTo = PRICE_CLOSE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + appliedTo = PRICE_CLOSE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(0, 0) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHVWAPConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Short ... + double s[]; + double sState[]; + + // + // Medium ... + double m[]; + double mState[]; + + // + // Long ... + double l[]; + double lState[]; + + // + // Hind ... + double h[]; + double hState[]; + + // + // Conditions ... + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + + // + // Short ... + bool isSBullish; + bool isSBearish; + bool isSSwitchedToBullish; + bool isSSwitchedToBearish; + + // + // Medium ... + bool isMBullish; + bool isMBearish; + bool isMSwitchedToBullish; + bool isMSwitchedToBearish; + + // + // Long ... + bool isLBullish; + bool isLBearish; + bool isLSwitchedToBullish; + bool isLSwitchedToBearish; + + // + // Hind ... + bool isHBullish; + bool isHBearish; + bool isHSwitchedToBullish; + bool isHSwitchedToBearish; + + // + void Clean() + { + // + Clean(s); + Clean(sState); + Clean(m); + Clean(mState); + Clean(l); + Clean(lState); + Clean(h); + Clean(hState); + + // + ArraySetAsSeries(s, true); + ArraySetAsSeries(sState, true); + ArraySetAsSeries(m, true); + ArraySetAsSeries(mState, true); + ArraySetAsSeries(l, true); + ArraySetAsSeries(lState, true); + ArraySetAsSeries(h, true); + ArraySetAsSeries(hState, true); + + // + // Conditions ... + + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + + // + // Short ... + isSBullish = false; + isSBearish = false; + isSSwitchedToBullish = false; + isSSwitchedToBearish = false; + + // + // Medium ... + isMBullish = false; + isMBearish = false; + isMSwitchedToBullish = false; + isMSwitchedToBearish = false; + + // + // Long ... + isLBullish = false; + isLBearish = false; + isLSwitchedToBullish = false; + isLSwitchedToBearish = false; + + // + // Hind ... + isHBullish = false; + isHBearish = false; + isHSwitchedToBullish = false; + isHSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // Conditions ... + + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + + // + // Short ... + if (isSBullish) + { + bullishScore++; + } + if (isSBearish) + { + bearishScore++; + } + if (isSSwitchedToBullish) + { + bullishScore++; + } + if (isSSwitchedToBearish) + { + bearishScore++; + } + + // + // Medium ... + if (isMBullish) + { + bullishScore++; + } + if (isMBearish) + { + bearishScore++; + } + if (isMSwitchedToBullish) + { + bullishScore++; + } + if (isMSwitchedToBearish) + { + bearishScore++; + } + + // + // Long ... + if (isLBullish) + { + bullishScore++; + } + if (isLBearish) + { + bearishScore++; + } + if (isLSwitchedToBullish) + { + bullishScore++; + } + if (isLSwitchedToBearish) + { + bearishScore++; + } + + // + // Hind ... + if (isHBullish) + { + bullishScore++; + } + if (isHBearish) + { + bearishScore++; + } + if (isHSwitchedToBullish) + { + bullishScore++; + } + if (isHSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHVWAP"; + } +}; + +// +// Class ... +class XSCXCHVWAPHelper : public XSCBaseHelper +{ + // + // Public ... + public: + // + // Props ... + + // + // Constructors ... + XSCXCHVWAPHelper() + : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHVWAPHelper() + { + // + Clean(sBuffer); + Clean(sStateBuffer); + Clean(mBuffer); + Clean(mStateBuffer); + Clean(lBuffer); + Clean(lStateBuffer); + Clean(hBuffer); + Clean(hStateBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHVWAPInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(sBuffer, true); + ArraySetAsSeries(sStateBuffer, true); + ArraySetAsSeries(mBuffer, true); + ArraySetAsSeries(mStateBuffer, true); + ArraySetAsSeries(lBuffer, true); + ArraySetAsSeries(lStateBuffer, true); + ArraySetAsSeries(hBuffer, true); + ArraySetAsSeries(hStateBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchvwap", + // + // Inputs ... + // + // Market ... + "", + mInputs.appliedTo, + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + mInputs.showShort, + mInputs.showMedium, + mInputs.showLong, + mInputs.showHind + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHVWAPInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHVWAPInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Short ... + + // + double GetS( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyS( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sStateBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + double GetM( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyM( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mStateBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + double GetL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lStateBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + double GetH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHState( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hStateBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHState( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hStateBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + ENUM_XCHVWAP_STATES ToState(double value) + { + // + ENUM_XCHVWAP_STATES result = value == 1 + ? XCHVWAP_BULLISH_STATE + : value == 2 + ? XCHVWAP_BEARISH_STATE + : XCHVWAP_NEUTURAL_STATE; + + // + return result; + } + + // + bool IsBullish(double value) + { + // + bool result = false; + + // + result = + // + ToState(value) == XCHVWAP_BULLISH_STATE; + // + ; + + // + return result; + } + + // + bool IsBearish(double value) + { + // + bool result = false; + + // + result = + // + ToState(value) == XCHVWAP_BEARISH_STATE; + // + ; + + // + return result; + } + + // + int GetValues( + int barIndex, // Bar Index + double &values[] // Result + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + Add( + iValue, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + double GetCycleValue( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // Cycle + ) + { + // + double result = 0; + + // + switch (cycle) + { + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + result = GetS(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + result = GetM(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + result = GetL(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + result = GetH(barIndex); + break; + } + + // + return result; + } + + // + double GetCycleState( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // Cycle + ) + { + // + double result = 0; + + // + switch (cycle) + { + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + result = GetSState(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + result = GetMState(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + result = GetLState(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + result = GetHState(barIndex); + break; + } + + // + return result; + } + + // + int GetBullishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double cState = GetCycleState( + barIndex, + allCycles[i] // + ); + + // + if (IsBullish(cState)) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetBearishCycles( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Result + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES allCycles[]; + int allCyclesCount = GetAllMarketCycles(allCycles); + if (!IsValidSize(allCyclesCount)) + { + return result; + } + + // + for (int i = 0; i < allCyclesCount; i++) + { + // + double cState = GetCycleState( + barIndex, + allCycles[i] // + ); + + // + if (IsBearish(cState)) + { + // + Add( + allCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetCyclesValues( + int barIndex, // Bar Index + double &values[], // Values + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + Clean(values); + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iValue = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + Add( + iValue, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBullishCyclesValues( + int barIndex, // Bar Index + double &values[] // Values + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBullishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetCyclesValues( + barIndex, + values, + cycles // + ); + + // + return result; + } + + // + int GetBearishCyclesValues( + int barIndex, // Bar Index + double &values[] // Values + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetBearishCycles( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetCyclesValues( + barIndex, + values, + cycles // + ); + + // + return result; + } + + // + double GetCyclesMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesValues( + barIndex, + values, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesValues( + barIndex, + values, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int valuesCount = GetValues( + barIndex, + values // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int valuesCount = GetValues( + barIndex, + values // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBullishCyclesValues( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = MathAbs(GetSum(values)); + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double values[]; + int count = GetBearishCyclesValues( + barIndex, + values // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = MathAbs(GetSum(values)); + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + if (IsBullish(power)) + { + result += MathAbs(power); + } + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = GetCycleValue( + barIndex, + cycles[i] // + ); + + // + if (IsBearish(power)) + { + result += MathAbs(power); + } + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Order of VWaps ... + + // + // Only Check Orders of VWap Buffers + // not State of them ... + bool IsBullishOrder( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double shortVWap = GetS(barIndex); + double mediumVWap = GetM(barIndex); + double longVWap = GetL(barIndex); + double hindVWap = GetH(barIndex); + + // + result = shortVWap > mediumVWap && + mediumVWap > longVWap && + longVWap > hindVWap; + + // + return result; + } + + bool IsSwitchedToBullishOrder( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + bool isCBullishOrder = IsBullishOrder(barIndex); + bool isPBullishOrder = IsBullishOrder(barIndex + 1); + + // + result = + isCBullishOrder && + !isPBullishOrder; + + // + return result; + } + + // + // Only Check Orders of VWap Buffers + // not State of them ... + bool IsBearishOrder( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double shortVWap = GetS(barIndex); + double mediumVWap = GetM(barIndex); + double longVWap = GetL(barIndex); + double hindVWap = GetH(barIndex); + + // + result = shortVWap < mediumVWap && + mediumVWap < longVWap && + longVWap < hindVWap; + + // + return result; + } + + bool IsSwitchedToBearishOrder( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + bool isCBearishOrder = IsBearishOrder(barIndex); + bool isPBearishOrder = IsBearishOrder(barIndex + 1); + + // + result = + isCBearishOrder && + !isPBearishOrder; + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHVWAPConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Short ... + CopyS( + zIndex, + loopback, + conditions.s // + ); + CopySState( + zIndex, + loopback, + conditions.sState // + ); + + // + // Medium ... + CopyM( + zIndex, + loopback, + conditions.m // + ); + CopyMState( + zIndex, + loopback, + conditions.mState // + ); + + // + // Long ... + CopyL( + zIndex, + loopback, + conditions.l // + ); + CopyLState( + zIndex, + loopback, + conditions.lState // + ); + + // + // Hind ... + CopyH( + zIndex, + loopback, + conditions.h // + ); + CopyHState( + zIndex, + loopback, + conditions.hState // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + + // + // Short ... + + // + bool isSBullish = IsBullish(conditions.sState[cIndex]); + bool isSBullishPrev = IsBullish(conditions.sState[pIndex]); + + // + bool isSBearish = IsBearish(conditions.sState[cIndex]); + bool isSBearishPrev = IsBearish(conditions.sState[pIndex]); + + // + bool isSSwitchedToBullish = isSBullish && + !isSBullishPrev; + bool isSSwitchedToBearish = isSBearish && + !isSBearishPrev; + + // + conditions.isSBullish = isSBullish; + conditions.isSBearish = isSBearish; + conditions.isSSwitchedToBullish = isSSwitchedToBullish; + conditions.isSSwitchedToBearish = isSSwitchedToBearish; + + // + // Medium ... + + // + bool isMBullish = IsBullish(conditions.mState[cIndex]); + bool isMBullishPrev = IsBullish(conditions.mState[pIndex]); + + // + bool isMBearish = IsBearish(conditions.mState[cIndex]); + bool isMBearishPrev = IsBearish(conditions.mState[pIndex]); + + // + bool isMSwitchedToBullish = isMBullish && + !isMBullishPrev; + bool isMSwitchedToBearish = isMBearish && + !isMBearishPrev; + + // + conditions.isMBullish = isMBullish; + conditions.isMBearish = isMBearish; + conditions.isMSwitchedToBullish = isMSwitchedToBullish; + conditions.isMSwitchedToBearish = isMSwitchedToBearish; + + // + // Long ... + + // + bool isLBullish = IsBullish(conditions.lState[cIndex]); + bool isLBullishPrev = IsBullish(conditions.lState[pIndex]); + + // + bool isLBearish = IsBearish(conditions.lState[cIndex]); + bool isLBearishPrev = IsBearish(conditions.lState[pIndex]); + + // + bool isLSwitchedToBullish = isLBullish && + !isLBullishPrev; + bool isLSwitchedToBearish = isLBearish && + !isLBearishPrev; + + // + conditions.isLBullish = isLBullish; + conditions.isLBearish = isLBearish; + conditions.isLSwitchedToBullish = isLSwitchedToBullish; + conditions.isLSwitchedToBearish = isLSwitchedToBearish; + + // + // Hind ... + + // + bool isHBullish = IsBullish(conditions.hState[cIndex]); + bool isHBullishPrev = IsBullish(conditions.hState[pIndex]); + + // + bool isHBearish = IsBearish(conditions.hState[cIndex]); + bool isHBearishPrev = IsBearish(conditions.hState[pIndex]); + + // + bool isHSwitchedToBullish = isHBullish && + !isHBullishPrev; + bool isHSwitchedToBearish = isHBearish && + !isHBearishPrev; + + // + conditions.isHBullish = isHBullish; + conditions.isHBearish = isHBearish; + conditions.isHSwitchedToBullish = isHSwitchedToBullish; + conditions.isHSwitchedToBearish = isHSwitchedToBearish; + + // + return result; + } + + // + // Protected ... + protected: + // + // Private ... + private: + // + // Props ... + XCHVWAPInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Short ... + double sBuffer[]; + double sStateBuffer[]; + + // + // Medium ... + double mBuffer[]; + double mStateBuffer[]; + + // + // Long ... + double lBuffer[]; + double lStateBuffer[]; + + // + // Hind ... + double hBuffer[]; + double hStateBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Short ... + CopyBuffer( + mHandler, + XCHVWAP_S_LINE, + 0, + totalBars, + sBuffer + // + ); + CopyBuffer( + mHandler, + XCHVWAP_S_STATE_LINE, + 0, + totalBars, + sStateBuffer + // + ); + + // + // Medium ... + CopyBuffer( + mHandler, + XCHVWAP_M_LINE, + 0, + totalBars, + mBuffer + // + ); + CopyBuffer( + mHandler, + XCHVWAP_M_STATE_LINE, + 0, + totalBars, + mStateBuffer + // + ); + + // + // Long ... + CopyBuffer( + mHandler, + XCHVWAP_L_LINE, + 0, + totalBars, + lBuffer + // + ); + CopyBuffer( + mHandler, + XCHVWAP_L_STATE_LINE, + 0, + totalBars, + lStateBuffer + // + ); + + // + // Hind ... + CopyBuffer( + mHandler, + XCHVWAP_H_LINE, + 0, + totalBars, + hBuffer + // + ); + CopyBuffer( + mHandler, + XCHVWAP_H_STATE_LINE, + 0, + totalBars, + hStateBuffer + // + ); + }; +}; + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xct.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xct.helper.mq5 new file mode 100644 index 00000000..315857a4 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xct.helper.mq5 @@ -0,0 +1,220 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCTHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +// Input Models ... +struct XCTInputs +{ + // + // Props ... + + // + color clr; // Text Color + ENUM_BASE_CORNER corner; // Text Position + + // + // Presentation ... + bool showCandleTime; // Show Candle Time + + // + // Constructor(s) ... + XCTInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + clr = CLR_NONE; + corner = CORNER_RIGHT_LOWER; + + // + // Presentation ... + showCandleTime = false; + } + + // + // Default ... + void Default() + { + // + clr = clrYellow; + corner = CORNER_RIGHT_LOWER; + + // + // Presentation ... + showCandleTime = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + true + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(0, 0); + + // + return result; + } +}; + +// +// Class ... +class XSCXCTHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCTHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCTInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xct", + // + // Inputs ... + mInputs.clr, // Text Color + mInputs.corner, // Text Position + // + // Presentation ... + "", + mInputs.showCandleTime // Show Candle Time + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCTInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCTInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCTInputs mInputs; // Inputs ... +}; + +// +// Tools ... \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xosc.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xosc.helper.mq5 new file mode 100644 index 00000000..2d2da01e --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xosc.helper.mq5 @@ -0,0 +1,1342 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXOSCHelper +// Description: provides all Indicator +// Helper 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 + +// +#include "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XOSC_BUFFERS +{ + X_OSC_ATR_LINE = 0, + X_OSC_RVI_MAIN_LINE = 1, + X_OSC_RVI_SIGNAL_LINE = 2, + X_OSC_BULL_POWER_LINE = 3, + X_OSC_BEAR_POWER_LINE = 4, + X_OSC_VOLUME_LINE = 5, + X_OSC_RSI_LINE = 6, + X_OSC_CCI_LINE = 7, + X_OSC_MOMENTUM_LINE = 8, + X_OSC_SAR_LINE = 9, + X_OSC_MACD_MAIN_LINE = 10, + X_OSC_MACD_SIGNAL_LINE = 11, + X_OSC_STOCH_MAIN_LINE = 12, + X_OSC_STOCH_SIGNAL_LINE = 13, + X_OSC_STDDEV_LINE = 14, +}; + +// +// Input Models ... +struct XOSCInputs +{ + // + // Props ... + + // + // ATR ... + int atrLength; // Length + + // + // RVI ... + int rviLength; // Length + + // + // BULLPOWER ... + int bullpLength; // Length + + // + // BEARPOWER ... + int bearpLength; // Length + + // + // VOLUME ... + ENUM_APPLIED_VOLUME volumeAppliedTo; // Applied To + + // + // RSI ... + int rsiLength; // Length + ENUM_APPLIED_PRICE rsiAppliedTo; // Applied To + + // + // CCI ... + int cciLength; // Length + ENUM_APPLIED_PRICE cciAppliedTo; // Applied To + + // + // STDDEV ... + int stddevLength; // Length + int stddevShift; // Shift + ENUM_MA_METHOD stddevMethod; // Mode + ENUM_APPLIED_PRICE stddevAppliedTo; // AppliedTo + + // + // MOMENTUM ... + int momentumLength; // Length + ENUM_APPLIED_PRICE momentumAppliedTo; // Applied To + + // + // SAR ... + double sarStep; // Step + double sarMaximum; // Maximum + + // + // MACD ... + int macdFastLength; // Fast Length + int macdSlowLength; // Slow Length + int macdSignaLength; // Signal Length + ENUM_APPLIED_PRICE macdAppliedTo; // Applied To + + // + // STOCHASTIC ... + // The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE. + int stochKLength; // K Length + int stochDLength; // D Length + int stochSlowing; // Slowing + ENUM_MA_METHOD stochMaMethod; // Ma Method + ENUM_STO_PRICE stochMode; // Calculation Mode + + // + // Constructor(s) ... + XOSCInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + atrLength = 0; // Length + rviLength = 0; // Length + bullpLength = 0; // Length + bearpLength = 0; // Length + volumeAppliedTo = VOLUME_TICK; // Applied To + rsiLength = 0; // Length + rsiAppliedTo = PRICE_CLOSE; // Applied To + cciLength = 0; // Length + cciAppliedTo = PRICE_TYPICAL; // Applied To + stddevLength = 0; // Length + stddevShift = 0; // Shift + stddevMethod = MODE_SMA; // Mode + stddevAppliedTo = PRICE_CLOSE; // AppliedTo + momentumLength = 0; // Length + momentumAppliedTo = PRICE_CLOSE; // Applied To + sarStep = 0; // Step + sarMaximum = 0; // Maximum + macdFastLength = 0; // Fast Length + macdSlowLength = 0; // Slow Length + macdSignaLength = 0; // Signal Length + macdAppliedTo = PRICE_CLOSE; // Applied To + stochKLength = 0; // K Length + stochDLength = 0; // D Length + stochSlowing = 0; // Slowing + stochMaMethod = MODE_SMA; // Ma Method + stochMode = STO_LOWHIGH; // Calculation Mode + } + + // + // Default ... + void Default() + { + // + atrLength = 14; // Length + rviLength = 10; // Length + bullpLength = 13; // Length + bearpLength = 13; // Length + volumeAppliedTo = VOLUME_TICK; // Applied To + rsiLength = 14; // Length + rsiAppliedTo = PRICE_CLOSE; // Applied To + cciLength = 14; // Length + cciAppliedTo = PRICE_TYPICAL; // Applied To + stddevLength = 20; // Length + stddevShift = 0; // Shift + stddevMethod = MODE_SMA; // Mode + stddevAppliedTo = PRICE_CLOSE; // AppliedTo + momentumLength = 14; // Length + momentumAppliedTo = PRICE_CLOSE; // Applied To + sarStep = 0.02; // Step + sarMaximum = 0.2; // Maximum + macdFastLength = 12; // Fast Length + macdSlowLength = 26; // Slow Length + macdSignaLength = 9; // Signal Length + macdAppliedTo = PRICE_CLOSE; // Applied To + stochKLength = 5; // K Length + stochDLength = 3; // D Length + stochSlowing = 3; // Slowing + stochMaMethod = MODE_SMA; // Ma Method + stochMode = STO_LOWHIGH; // Calculation Mode + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + atrLength >= 2 && + rviLength >= 2 && + bullpLength >= 2 && + bearpLength >= 2 && + rsiLength >= 2 && + cciLength >= 2 && + momentumLength >= 2 && + sarStep > 0 && + sarStep < sarMaximum && + macdFastLength >= 2 && + macdSlowLength > macdFastLength && + macdSignaLength >= 2 && + stochKLength >= 2 && + stochDLength >= 2 && + stochSlowing >= 2 && + stddevLength >= 2 && + stddevShift >= 0 + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(atrLength, rviLength); + result = MathMax(result, bullpLength); + result = MathMax(result, bearpLength); + result = MathMax(result, rsiLength); + result = MathMax(result, cciLength); + result = MathMax(result, momentumLength); + result = MathMax(result, macdFastLength); + result = MathMax(result, macdSlowLength); + result = MathMax(result, macdSignaLength); + result = MathMax(result, stochKLength); + result = MathMax(result, stochDLength); + result = MathMax(result, stochSlowing); + result = MathMax(result, stddevLength); + + // + return result; + } +}; + +// +// Class ... +class XSCXOSCHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXOSCHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXOSCHelper() + { + // + Clean(atrBuffer); + Clean(rsiBuffer); + Clean(cciBuffer); + Clean(sarBuffer); + Clean(bullPBuffer); + Clean(bearPBuffer); + Clean(stddevBuffer); + Clean(volumeBuffer); + Clean(rviMainBuffer); + Clean(momentumBuffer); + Clean(macdMainBuffer); + Clean(rviSignalBuffer); + Clean(stochMainBuffer); + Clean(macdSignalBuffer); + Clean(stochSignalBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XOSCInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(atrBuffer, true); + ArraySetAsSeries(rviMainBuffer, true); + ArraySetAsSeries(rviSignalBuffer, true); + ArraySetAsSeries(bullPBuffer, true); + ArraySetAsSeries(bearPBuffer, true); + ArraySetAsSeries(volumeBuffer, true); + ArraySetAsSeries(rsiBuffer, true); + ArraySetAsSeries(cciBuffer, true); + ArraySetAsSeries(momentumBuffer, true); + ArraySetAsSeries(sarBuffer, true); + ArraySetAsSeries(macdMainBuffer, true); + ArraySetAsSeries(macdSignalBuffer, true); + ArraySetAsSeries(stochMainBuffer, true); + ArraySetAsSeries(stochSignalBuffer, true); + ArraySetAsSeries(stddevBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xosc", + // + // Inputs ... + // + // ATR ... + "", + mInputs.atrLength, + // + // RVI ... + "", + mInputs.rviLength, + // + // Bulls Power ... + "", + mInputs.bullpLength, + // + // Bears Power ... + "", + mInputs.bearpLength, + // + // Voluem ... + "", + mInputs.volumeAppliedTo, + // + // RSI ... + "", + mInputs.rsiLength, + mInputs.rsiAppliedTo, + // + // CCI ... + "", + mInputs.cciLength, + mInputs.cciAppliedTo, + // + // STDDev ... + "", + mInputs.stddevLength, + mInputs.stddevShift, + mInputs.stddevMethod, + mInputs.stddevAppliedTo, + // + // Momentum ... + "", + mInputs.momentumLength, + mInputs.momentumAppliedTo, + // + // SAR ... + "", + mInputs.sarStep, + mInputs.sarMaximum, + // + // MACD ... + "", + mInputs.macdFastLength, + mInputs.macdSlowLength, + mInputs.macdSignaLength, + mInputs.macdAppliedTo, + // + // Stochastic ... + "", + mInputs.stochKLength, + mInputs.stochDLength, + mInputs.stochSlowing, + mInputs.stochMaMethod, + mInputs.stochMode + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XOSCInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XOSCInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs); + } + + // + // Buffers ... + + // + // ATR ... + + // + double GetATR( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return atrBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyATR( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + atrBuffer, + buffer, + forceClean + // + ); + } + + // + // RVI ... + + // + double GetRVI( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return rviMainBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyRVI( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + rviMainBuffer, + buffer, + forceClean + // + ); + } + + // + double GetRVISignal( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return rviSignalBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyRVISignal( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + rviSignalBuffer, + buffer, + forceClean + // + ); + } + + // + // BULLP ... + + // + double GetBullPower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return bullPBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyBullPower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + bullPBuffer, + buffer, + forceClean + // + ); + } + + // + // BEARP ... + + // + double GetBearPower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return bearPBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyBearPower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + bearPBuffer, + buffer, + forceClean + // + ); + } + + // + // VOLUME ... + + // + double GetVolume( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return volumeBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyVolume( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + volumeBuffer, + buffer, + forceClean + // + ); + } + + // + // RSI ... + + // + double GetRSI( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return rsiBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyRSI( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + rsiBuffer, + buffer, + forceClean + // + ); + } + + // + // CCI ... + + // + double GetCCI( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cciBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCCI( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cciBuffer, + buffer, + forceClean + // + ); + } + + // + // MOMENTUM ... + + // + double GetMomentum( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return momentumBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMomentum( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + momentumBuffer, + buffer, + forceClean + // + ); + } + + // + // SAR ... + + // + double GetSAR( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sarBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySAR( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sarBuffer, + buffer, + forceClean + // + ); + } + + // + // STDDEV ... + + // + double GetSTDDEV( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return stddevBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySTDDEV( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + stddevBuffer, + buffer, + forceClean + // + ); + } + + // + // MACD ... + + // + double GetMACD( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return macdMainBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMACD( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + macdMainBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMACDSignal( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return macdSignalBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMACDSignal( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + macdSignalBuffer, + buffer, + forceClean + // + ); + } + + // + // STOCH ... + + // + double GetSTOCH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return stochMainBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySTOCH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + stochMainBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSTOCHSignal( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return stochSignalBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySTOCHSignal( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + stochSignalBuffer, + buffer, + forceClean + // + ); + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XOSCInputs mInputs; // Inputs ... + + // + // Buffers ... + double atrBuffer[]; + double rviMainBuffer[]; + double rviSignalBuffer[]; + double bullPBuffer[]; + double bearPBuffer[]; + double volumeBuffer[]; + double rsiBuffer[]; + double cciBuffer[]; + double momentumBuffer[]; + double sarBuffer[]; + double macdMainBuffer[]; + double macdSignalBuffer[]; + double stochMainBuffer[]; + double stochSignalBuffer[]; + double stddevBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // ATR ... + CopyBuffer( + mHandler, + X_OSC_ATR_LINE, + 0, + totalBars, + atrBuffer + // + ); + + // + // BULLP ... + CopyBuffer( + mHandler, + X_OSC_BULL_POWER_LINE, + 0, + totalBars, + bullPBuffer + // + ); + + // + // BEARP ... + CopyBuffer( + mHandler, + X_OSC_BEAR_POWER_LINE, + 0, + totalBars, + bearPBuffer + // + ); + + // + // VOLUME ... + CopyBuffer( + mHandler, + X_OSC_VOLUME_LINE, + 0, + totalBars, + volumeBuffer + // + ); + + // + // RSI ... + CopyBuffer( + mHandler, + X_OSC_RSI_LINE, + 0, + totalBars, + rsiBuffer + // + ); + + // + // CCI ... + CopyBuffer( + mHandler, + X_OSC_CCI_LINE, + 0, + totalBars, + cciBuffer + // + ); + + // + // MOMENTUM ... + CopyBuffer( + mHandler, + X_OSC_MOMENTUM_LINE, + 0, + totalBars, + momentumBuffer + // + ); + + // + // SAR ... + CopyBuffer( + mHandler, + X_OSC_SAR_LINE, + 0, + totalBars, + sarBuffer + // + ); + + // + // STDDEV ... + CopyBuffer( + mHandler, + X_OSC_STDDEV_LINE, + 0, + totalBars, + stddevBuffer + // + ); + + // + // RVI ... + + // + // RVI Main ... + CopyBuffer( + mHandler, + X_OSC_RVI_MAIN_LINE, + 0, + totalBars, + rviMainBuffer + // + ); + + // + // RVI Signal ... + CopyBuffer( + mHandler, + X_OSC_RVI_SIGNAL_LINE, + 0, + totalBars, + rviSignalBuffer + // + ); + + // + // MACD ... + + // + // MACD Main ... + CopyBuffer( + mHandler, + X_OSC_MACD_MAIN_LINE, + 0, + totalBars, + macdMainBuffer + // + ); + + // + // MACD Signal ... + CopyBuffer( + mHandler, + X_OSC_MACD_SIGNAL_LINE, + 0, + totalBars, + macdSignalBuffer + // + ); + + // + // STOCH ... + + // + // STOCH Main ... + CopyBuffer( + mHandler, + X_OSC_STOCH_MAIN_LINE, + 0, + totalBars, + stochMainBuffer + // + ); + + // + // STOCH Signal ... + CopyBuffer( + mHandler, + X_OSC_STOCH_SIGNAL_LINE, + 0, + totalBars, + stochSignalBuffer + // + ); + } +}; + +// +// Tools ... diff --git a/Documents/BKP/14030802-X121/Helpers/x-saherelm.xpv.helper.mq5 b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xpv.helper.mq5 new file mode 100644 index 00000000..a9860a49 --- /dev/null +++ b/Documents/BKP/14030802-X121/Helpers/x-saherelm.xpv.helper.mq5 @@ -0,0 +1,3237 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXPVHelper +// Description: provides all Indicator +// Helper 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 "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XPV_BUFFERS +{ + // + // Peaks and Vales ... + XPV_PEAKS_LINE = 0, + XPV_VALES_LINE = 1, + // + // Support and Resistances ... + XPV_RESISTANCE_LINE = 2, + XPV_SUPPORT_LINE = 4, + // + // Fibonacci ... + XPV_FIB_1_LINE = 6, + XPV_FIB_2_LINE = 8, + XPV_FIB_3_LINE = 10, + XPV_FIB_4_LINE = 12, + XPV_FIB_5_LINE = 14, + // + // Short ... + XPV_SC_HH_LINE = 16, + XPV_SC_LL_LINE = 18, + // + // Medium ... + XPV_MC_HH_LINE = 20, + XPV_MC_LL_LINE = 22, + // + // Long ... + XPV_LC_HH_LINE = 24, + XPV_LC_LL_LINE = 26, + // + // Hind ... + XPV_HC_HH_LINE = 28, + XPV_HC_LL_LINE = 30, +}; + +// +// Input Models ... +struct XPVInputs +{ + // + // Props ... + + // + // Makret Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Fibonacci ... + double fiboLevel1; // Fibio 1st Level + double fiboLevel2; // Fibio 2st Level + double fiboLevel3; // Fibio 3rd Level + double fiboLevel4; // Fibio 4th Level + double fiboLevel5; // Fibio 5th Level + + // + // Boundary Detection Modes ... + ENUM_SERIESMODE hhMode; // Highest High Calculation Method + ENUM_SERIESMODE llMode; // Lowest Low Calculation Method + + // + // Presentation ... + bool showPeaksAndVales; // Show Peaks and Vales + bool showLevels; // Show Levels + bool showConsolidations; // Show Consolidations + bool showFibo1Levels; // Show Fibo 1st Level + bool showFibo2Levels; // Show Fibo 2nd Level + bool showFibo3Levels; // Show Fibo 3rd Level + bool showFibo4Levels; // Show Fibo 4th Level + bool showFibo5Levels; // Show Fibo 5th Level + + // + // Constructor(s) ... + XPVInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + // Makret Cycles ... + + // + // Short ... + scMethod = X_PERIOD_NOTHING; + scPeriod = NULL; + + // + // Medium ... + mcMethod = X_PERIOD_NOTHING; + mcPeriod = NULL; + + // + // Long ... + lcMethod = X_PERIOD_NOTHING; + lcPeriod = NULL; + + // + // Hind ... + hcMethod = X_PERIOD_NOTHING; + hcPeriod = NULL; + + // + // Fibonacci ... + fiboLevel1 = 0; + fiboLevel2 = 0; + fiboLevel3 = 0; + fiboLevel4 = 0; + fiboLevel5 = 0; + + // + // Boundary Detection Modes ... + hhMode = MODE_HIGH; + llMode = MODE_LOW; + + // + // Presentation ... + showPeaksAndVales = false; + showLevels = false; + showConsolidations = false; + showFibo1Levels = false; + showFibo2Levels = false; + showFibo3Levels = false; + showFibo4Levels = false; + showFibo5Levels = false; + } + + // + // Default ... + void Default() + { + // + // Makret Cycles ... + + // + // Short ... + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + + // + // Medium ... + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + + // + // Long ... + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + + // + // Hind ... + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + // Fibonacci ... + fiboLevel1 = 0.236; + fiboLevel2 = 0.382; + fiboLevel3 = 0.5; + fiboLevel4 = 0.618; + fiboLevel5 = 0.764; + + // + // Boundary Detection Modes ... + hhMode = MODE_HIGH; + llMode = MODE_LOW; + + // + // Presentation ... + showPeaksAndVales = true; + showLevels = false; + showConsolidations = false; + showFibo1Levels = true; + showFibo2Levels = true; + showFibo3Levels = true; + showFibo4Levels = true; + showFibo5Levels = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(result, 0); + + // + return result; + } +}; + +// +// Conditions ... +struct XPVConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double peaks[]; + double vales[]; + double resistances[]; + double supports[]; + double fib1s[]; + double fib2s[]; + double fib3s[]; + double fib4s[]; + double fib5s[]; + double sCHHs[]; + double sCLLs[]; + double mCHHs[]; + double mCLLs[]; + double lCHHs[]; + double lCLLs[]; + double hCHHs[]; + double hCLLs[]; + + // + // Conditions ... + + // + bool isNewPeak; + bool isNewPeakOverLast; + bool isNewPeakUnderLast; + + // + bool isNewVale; + bool isNewValeOverLast; + bool isNewValeUnderLast; + + // + bool isFiboIncreased; + bool isFiboDecreased; + bool isFiboSectionChanged; + + // + // SC ... + + // + bool isSCBullish; + bool isSCHHBullish; + bool isSCLLBullish; + bool isSCSwitchedToBullish; + bool isSCHHSwitchedToBullish; + bool isSCLLSwitchedToBullish; + + // + bool isSCBearish; + bool isSCHHBearish; + bool isSCLLBearish; + bool isSCSwitchedToBearish; + bool isSCHHSwitchedToBearish; + bool isSCLLSwitchedToBeraish; + + // + // MC ... + + // + bool isMCBullish; + bool isMCHHBullish; + bool isMCLLBullish; + bool isMCSwitchedToBullish; + bool isMCHHSwitchedToBullish; + bool isMCLLSwitchedToBullish; + + // + bool isMCBearish; + bool isMCHHBearish; + bool isMCLLBearish; + bool isMCSwitchedToBearish; + bool isMCHHSwitchedToBearish; + bool isMCLLSwitchedToBeraish; + + // + // LC ... + + // + bool isLCBullish; + bool isLCHHBullish; + bool isLCLLBullish; + bool isLCSwitchedToBullish; + bool isLCHHSwitchedToBullish; + bool isLCLLSwitchedToBullish; + // + bool isLCBearish; + bool isLCHHBearish; + bool isLCLLBearish; + bool isLCSwitchedToBearish; + bool isLCHHSwitchedToBearish; + bool isLCLLSwitchedToBeraish; + + // + // HC ... + + // + bool isHCBullish; + bool isHCHHBullish; + bool isHCLLBullish; + bool isHCSwitchedToBullish; + bool isHCHHSwitchedToBullish; + bool isHCLLSwitchedToBullish; + + // + bool isHCBearish; + bool isHCHHBearish; + bool isHCLLBearish; + bool isHCSwitchedToBearish; + bool isHCHHSwitchedToBearish; + bool isHCLLSwitchedToBeraish; + + // + // Fibonachi Conditions ... + + // + bool isCloseOverFib1; + bool isCloseOverFib2; + bool isCloseOverFib3; + bool isCloseOverFib4; + bool isCloseOverFib5; + + // + bool isCloseUnderFib1; + bool isCloseUnderFib2; + bool isCloseUnderFib3; + bool isCloseUnderFib4; + bool isCloseUnderFib5; + + // + bool isCloseCrossedOverFib1; + bool isCloseCrossedOverFib2; + bool isCloseCrossedOverFib3; + bool isCloseCrossedOverFib4; + bool isCloseCrossedOverFib5; + + // + bool isCloseCrossedUnderFib1; + bool isCloseCrossedUnderFib2; + bool isCloseCrossedUnderFib3; + bool isCloseCrossedUnderFib4; + bool isCloseCrossedUnderFib5; + + // + void Clean() + { + // + Clean(peaks); + Clean(vales); + Clean(resistances); + Clean(supports); + Clean(fib1s); + Clean(fib2s); + Clean(fib3s); + Clean(fib4s); + Clean(fib5s); + Clean(sCHHs); + Clean(sCLLs); + Clean(mCHHs); + Clean(mCLLs); + Clean(lCHHs); + Clean(lCLLs); + Clean(hCHHs); + Clean(hCLLs); + + // + ArraySetAsSeries(peaks, true); + ArraySetAsSeries(vales, true); + ArraySetAsSeries(resistances, true); + ArraySetAsSeries(supports, true); + ArraySetAsSeries(fib1s, true); + ArraySetAsSeries(fib2s, true); + ArraySetAsSeries(fib3s, true); + ArraySetAsSeries(fib4s, true); + ArraySetAsSeries(fib5s, true); + ArraySetAsSeries(sCHHs, true); + ArraySetAsSeries(sCLLs, true); + ArraySetAsSeries(mCHHs, true); + ArraySetAsSeries(mCLLs, true); + ArraySetAsSeries(lCHHs, true); + ArraySetAsSeries(lCLLs, true); + ArraySetAsSeries(hCHHs, true); + ArraySetAsSeries(hCLLs, true); + + // + isNewPeak = false; + isNewPeakOverLast = false; + isNewPeakUnderLast = false; + isNewVale = false; + isNewValeOverLast = false; + isNewValeUnderLast = false; + isFiboIncreased = false; + isFiboDecreased = false; + isFiboSectionChanged = false; + isCloseOverFib1 = false; + isCloseOverFib2 = false; + isCloseOverFib3 = false; + isCloseOverFib4 = false; + isCloseOverFib5 = false; + isCloseUnderFib1 = false; + isCloseUnderFib2 = false; + isCloseUnderFib3 = false; + isCloseUnderFib4 = false; + isCloseUnderFib5 = false; + isCloseCrossedOverFib1 = false; + isCloseCrossedOverFib2 = false; + isCloseCrossedOverFib3 = false; + isCloseCrossedOverFib4 = false; + isCloseCrossedOverFib5 = false; + isCloseCrossedUnderFib1 = false; + isCloseCrossedUnderFib2 = false; + isCloseCrossedUnderFib3 = false; + isCloseCrossedUnderFib4 = false; + isCloseCrossedUnderFib5 = false; + isSCBullish = false; + isSCHHBullish = false; + isSCLLBullish = false; + isSCSwitchedToBullish = false; + isSCHHSwitchedToBullish = false; + isSCLLSwitchedToBullish = false; + isSCBearish = false; + isSCHHBearish = false; + isSCLLBearish = false; + isSCSwitchedToBearish = false; + isSCHHSwitchedToBearish = false; + isSCLLSwitchedToBeraish = false; + isMCBullish = false; + isMCHHBullish = false; + isMCLLBullish = false; + isMCSwitchedToBullish = false; + isMCHHSwitchedToBullish = false; + isMCLLSwitchedToBullish = false; + isMCBearish = false; + isMCHHBearish = false; + isMCLLBearish = false; + isMCSwitchedToBearish = false; + isMCHHSwitchedToBearish = false; + isMCLLSwitchedToBeraish = false; + isLCBullish = false; + isLCHHBullish = false; + isLCLLBullish = false; + isLCSwitchedToBullish = false; + isLCHHSwitchedToBullish = false; + isLCLLSwitchedToBullish = false; + isLCBearish = false; + isLCHHBearish = false; + isLCLLBearish = false; + isLCSwitchedToBearish = false; + isLCHHSwitchedToBearish = false; + isLCLLSwitchedToBeraish = false; + isHCBullish = false; + isHCHHBullish = false; + isHCLLBullish = false; + isHCSwitchedToBullish = false; + isHCHHSwitchedToBullish = false; + isHCLLSwitchedToBullish = false; + isHCBearish = false; + isHCHHBearish = false; + isHCLLBearish = false; + isHCSwitchedToBearish = false; + isHCHHSwitchedToBearish = false; + isHCLLSwitchedToBeraish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isNewPeak) + { + } + if (isNewPeakOverLast) + { + } + if (isNewPeakUnderLast) + { + } + + // + if (isNewVale) + { + } + if (isNewValeOverLast) + { + } + if (isNewValeUnderLast) + { + } + + // + if (isFiboIncreased) + { + } + if (isFiboDecreased) + { + } + if (isFiboSectionChanged) + { + } + + // + if (isSCBullish) + { + bullishScore++; + } + if (isSCHHBullish) + { + bullishScore++; + } + if (isSCLLBullish) + { + bullishScore++; + } + if (isSCSwitchedToBullish) + { + bullishScore++; + } + if (isSCHHSwitchedToBullish) + { + bullishScore++; + } + if (isSCLLSwitchedToBullish) + { + bullishScore++; + } + + // + if (isSCBearish) + { + bearishScore++; + } + if (isSCHHBearish) + { + bearishScore++; + } + if (isSCLLBearish) + { + bearishScore++; + } + if (isSCSwitchedToBearish) + { + bearishScore++; + } + if (isSCHHSwitchedToBearish) + { + bearishScore++; + } + if (isSCLLSwitchedToBeraish) + { + bearishScore++; + } + + // + if (isMCBullish) + { + bullishScore++; + } + if (isMCHHBullish) + { + bullishScore++; + } + if (isMCLLBullish) + { + bullishScore++; + } + if (isMCSwitchedToBullish) + { + bullishScore++; + } + if (isMCHHSwitchedToBullish) + { + bullishScore++; + } + if (isMCLLSwitchedToBullish) + { + bullishScore++; + } + + // + if (isMCBearish) + { + bearishScore++; + } + if (isMCHHBearish) + { + bearishScore++; + } + if (isMCLLBearish) + { + bearishScore++; + } + if (isMCSwitchedToBearish) + { + bearishScore++; + } + if (isMCHHSwitchedToBearish) + { + bearishScore++; + } + if (isMCLLSwitchedToBeraish) + { + bearishScore++; + } + + // + if (isLCBullish) + { + bullishScore++; + } + if (isLCHHBullish) + { + bullishScore++; + } + if (isLCLLBullish) + { + bullishScore++; + } + if (isLCSwitchedToBullish) + { + bullishScore++; + } + if (isLCHHSwitchedToBullish) + { + bullishScore++; + } + if (isLCLLSwitchedToBullish) + { + bullishScore++; + } + + // + if (isLCBearish) + { + bearishScore++; + } + if (isLCHHBearish) + { + bearishScore++; + } + if (isLCLLBearish) + { + bearishScore++; + } + if (isLCSwitchedToBearish) + { + bearishScore++; + } + if (isLCHHSwitchedToBearish) + { + bearishScore++; + } + if (isLCLLSwitchedToBeraish) + { + bearishScore++; + } + + if (isHCBullish) + { + bullishScore++; + } + if (isHCHHBullish) + { + bullishScore++; + } + if (isHCLLBullish) + { + bullishScore++; + } + if (isHCSwitchedToBullish) + { + bullishScore++; + } + if (isHCHHSwitchedToBullish) + { + bullishScore++; + } + if (isHCLLSwitchedToBullish) + { + bullishScore++; + } + + // + if (isHCBearish) + { + bearishScore++; + } + if (isHCHHBearish) + { + bearishScore++; + } + if (isHCLLBearish) + { + bearishScore++; + } + if (isHCSwitchedToBearish) + { + bearishScore++; + } + if (isHCHHSwitchedToBearish) + { + bearishScore++; + } + if (isHCLLSwitchedToBeraish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) + + ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) + + ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) + + ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) + + ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + + ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + + ToString("isFiboIncreased", isFiboIncreased, ignoreFalseConditions, separator) + + ToString("isFiboDecreased", isFiboDecreased, ignoreFalseConditions, separator) + + ToString("isFiboSectionChanged", isFiboSectionChanged, ignoreFalseConditions, separator) + + ToString("isCloseOverFib1", isCloseOverFib1, ignoreFalseConditions, separator) + + ToString("isCloseOverFib2", isCloseOverFib2, ignoreFalseConditions, separator) + + ToString("isCloseOverFib3", isCloseOverFib3, ignoreFalseConditions, separator) + + ToString("isCloseOverFib4", isCloseOverFib4, ignoreFalseConditions, separator) + + ToString("isCloseOverFib5", isCloseOverFib5, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib1", isCloseUnderFib1, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib2", isCloseUnderFib2, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib3", isCloseUnderFib3, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib4", isCloseUnderFib4, ignoreFalseConditions, separator) + + ToString("isCloseUnderFib5", isCloseUnderFib5, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverFib1", isCloseCrossedOverFib1, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverFib2", isCloseCrossedOverFib2, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverFib3", isCloseCrossedOverFib3, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverFib4", isCloseCrossedOverFib4, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverFib5", isCloseCrossedOverFib5, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderFib1", isCloseCrossedUnderFib1, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderFib2", isCloseCrossedUnderFib2, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderFib3", isCloseCrossedUnderFib3, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderFib4", isCloseCrossedUnderFib4, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderFib5", isCloseCrossedUnderFib5, ignoreFalseConditions, separator) + + ToString("isSCBullish", isSCBullish, ignoreFalseConditions, separator) + + ToString("isSCHHBullish", isSCHHBullish, ignoreFalseConditions, separator) + + ToString("isSCLLBullish", isSCLLBullish, ignoreFalseConditions, separator) + + ToString("isSCSwitchedToBullish", isSCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSCHHSwitchedToBullish", isSCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSCLLSwitchedToBullish", isSCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSCBearish", isSCBearish, ignoreFalseConditions, separator) + + ToString("isSCHHBearish", isSCHHBearish, ignoreFalseConditions, separator) + + ToString("isSCLLBearish", isSCLLBearish, ignoreFalseConditions, separator) + + ToString("isSCSwitchedToBearish", isSCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isSCHHSwitchedToBearish", isSCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isSCLLSwitchedToBeraish", isSCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + ToString("isMCBullish", isMCBullish, ignoreFalseConditions, separator) + + ToString("isMCHHBullish", isMCHHBullish, ignoreFalseConditions, separator) + + ToString("isMCLLBullish", isMCLLBullish, ignoreFalseConditions, separator) + + ToString("isMCSwitchedToBullish", isMCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMCHHSwitchedToBullish", isMCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMCLLSwitchedToBullish", isMCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMCBearish", isMCBearish, ignoreFalseConditions, separator) + + ToString("isMCHHBearish", isMCHHBearish, ignoreFalseConditions, separator) + + ToString("isMCLLBearish", isMCLLBearish, ignoreFalseConditions, separator) + + ToString("isMCSwitchedToBearish", isMCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isMCHHSwitchedToBearish", isMCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isMCLLSwitchedToBeraish", isMCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + ToString("isLCBullish", isLCBullish, ignoreFalseConditions, separator) + + ToString("isLCHHBullish", isLCHHBullish, ignoreFalseConditions, separator) + + ToString("isLCLLBullish", isLCLLBullish, ignoreFalseConditions, separator) + + ToString("isLCSwitchedToBullish", isLCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLCHHSwitchedToBullish", isLCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLCLLSwitchedToBullish", isLCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLCBearish", isLCBearish, ignoreFalseConditions, separator) + + ToString("isLCHHBearish", isLCHHBearish, ignoreFalseConditions, separator) + + ToString("isLCLLBearish", isLCLLBearish, ignoreFalseConditions, separator) + + ToString("isLCSwitchedToBearish", isLCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isLCHHSwitchedToBearish", isLCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isLCLLSwitchedToBeraish", isLCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + ToString("isHCBullish", isHCBullish, ignoreFalseConditions, separator) + + ToString("isHCHHBullish", isHCHHBullish, ignoreFalseConditions, separator) + + ToString("isHCLLBullish", isHCLLBullish, ignoreFalseConditions, separator) + + ToString("isHCSwitchedToBullish", isHCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHCHHSwitchedToBullish", isHCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHCLLSwitchedToBullish", isHCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHCBearish", isHCBearish, ignoreFalseConditions, separator) + + ToString("isHCHHBearish", isHCHHBearish, ignoreFalseConditions, separator) + + ToString("isHCLLBearish", isHCLLBearish, ignoreFalseConditions, separator) + + ToString("isHCSwitchedToBearish", isHCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isHCHHSwitchedToBearish", isHCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isHCLLSwitchedToBeraish", isHCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XPV"; + } +}; + +// +// Class ... +class XSCXPVHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXPVHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXPVHelper() + { + // + Clean(fib1Buffer); + Clean(fib2Buffer); + Clean(fib3Buffer); + Clean(fib4Buffer); + Clean(fib5Buffer); + Clean(scHHBuffer); + Clean(scLLBuffer); + Clean(mcHHBuffer); + Clean(mcLLBuffer); + Clean(lcHHBuffer); + Clean(lcLLBuffer); + Clean(hcHHBuffer); + Clean(hcLLBuffer); + Clean(peaksBuffer); + Clean(valesBuffer); + Clean(supportBuffer); + Clean(resistanceBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XPVInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(peaksBuffer, true); + ArraySetAsSeries(valesBuffer, true); + ArraySetAsSeries(resistanceBuffer, true); + ArraySetAsSeries(supportBuffer, true); + ArraySetAsSeries(fib1Buffer, true); + ArraySetAsSeries(fib2Buffer, true); + ArraySetAsSeries(fib3Buffer, true); + ArraySetAsSeries(fib4Buffer, true); + ArraySetAsSeries(fib5Buffer, true); + ArraySetAsSeries(scHHBuffer, true); + ArraySetAsSeries(scLLBuffer, true); + ArraySetAsSeries(mcHHBuffer, true); + ArraySetAsSeries(mcLLBuffer, true); + ArraySetAsSeries(lcHHBuffer, true); + ArraySetAsSeries(lcLLBuffer, true); + ArraySetAsSeries(hcHHBuffer, true); + ArraySetAsSeries(hcLLBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xpv", + // + // Inputs ... + // + // Makret Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, // How to Find Period + mInputs.scPeriod, // Time Period + // + // Medium ... + "", + mInputs.mcMethod, // How to Find Period + mInputs.mcPeriod, // Time Period + // + // Long ... + "", + mInputs.lcMethod, // How to Find Period + mInputs.lcPeriod, // Time Period + // + // Hind ... + "", + mInputs.hcMethod, // How to Find Period + mInputs.hcPeriod, // Time Period + // + // Fibonacci ... + "", + mInputs.fiboLevel1, // Fibio 1st Level + mInputs.fiboLevel2, // Fibio 2st Level + mInputs.fiboLevel3, // Fibio 3rd Level + mInputs.fiboLevel4, // Fibio 4th Level + mInputs.fiboLevel5, // Fibio 5th Level + // + // Boundary Detection Modes ... + "", + mInputs.hhMode, // Highest High Calculation Method + mInputs.llMode, // Lowest Low Calculation Method + // + // Presentation ... + "", + mInputs.showPeaksAndVales, // Show Peaks and Vales + mInputs.showLevels, // Show Levels + mInputs.showConsolidations, // Show Consolidations + mInputs.showFibo1Levels, // Show Fibo 1st Level + mInputs.showFibo2Levels, // Show Fibo 2nd Level + mInputs.showFibo3Levels, // Show Fibo 3rd Level + mInputs.showFibo4Levels, // Show Fibo 4th Level + mInputs.showFibo5Levels // Show Fibo 5th Level + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XPVInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XPVInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Peaks ... + + // + double GetPeak( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(peaksBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return peaksBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyPeak( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + peaksBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSamePeak( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + peaksBuffer, + verifier, + barIndex // + ); + } + + // + // Vales ... + + // + double GetVale( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(valesBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return valesBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyVale( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + valesBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameVale( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + valesBuffer, + verifier, + barIndex // + ); + } + + // + // Resistance ... + + // + double GetResistance( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(resistanceBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return resistanceBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyResistance( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + resistanceBuffer, + buffer, + forceClean + // + ); + } + + // + // Support ... + + // + double GetSupport( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(supportBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return supportBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySupport( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + supportBuffer, + buffer, + forceClean + // + ); + } + + // + // Fibonacci ... + + // + // Level 1 ... + + // + double GetFib1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib1Buffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameFib1( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + fib1Buffer, + verifier, + barIndex // + ); + } + + // + // Level 2 ... + + // + double GetFib2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib2Buffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameFib2( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + fib2Buffer, + verifier, + barIndex // + ); + } + + // + // Level 3 ... + + // + double GetFib3( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib3Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib3Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib3( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib3Buffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameFib3( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + fib3Buffer, + verifier, + barIndex // + ); + } + + // + // Level 4 ... + + // + double GetFib4( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib4Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib4Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib4( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib4Buffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameFib4( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + fib4Buffer, + verifier, + barIndex // + ); + } + + // + // Level 5 ... + + // + double GetFib5( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib5Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib5Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib5( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib5Buffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameFib5( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + fib5Buffer, + verifier, + barIndex // + ); + } + + // + // Cycles ... + + // + // Short ... + + // + // HH ... + + // + double GetSCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(scHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return scHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + scHHBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameSCHH( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + scHHBuffer, + verifier, + barIndex // + ); + } + + // + // LL ... + + // + double GetSCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(scLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return scLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + scLLBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameSCLL( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + scLLBuffer, + verifier, + barIndex // + ); + } + + // + // Medium ... + + // + // HH ... + + // + double GetMCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mcHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mcHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mcHHBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameMCHH( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + mcHHBuffer, + verifier, + barIndex // + ); + } + + // + // LL ... + + // + double GetMCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mcLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mcLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mcLLBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameMCLL( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + mcLLBuffer, + verifier, + barIndex // + ); + } + + // + // Long ... + + // + // HH ... + + // + double GetLCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lcHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lcHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lcHHBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameLCHH( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + lcHHBuffer, + verifier, + barIndex // + ); + } + + // + // LL ... + + // + double GetLCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lcLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lcLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lcLLBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameLCLL( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + lcLLBuffer, + verifier, + barIndex // + ); + } + + // + // Hind ... + + // + // HH ... + + // + double GetHCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hcHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hcHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hcHHBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameHCHH( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + hcHHBuffer, + verifier, + barIndex // + ); + } + + // + // LL ... + + // + double GetHCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hcLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hcLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hcLLBuffer, + buffer, + forceClean + // + ); + } + + // + bool IsSameHCLL( + int barIndex, // Start Bar Index + int verifier = 71 // Number of Verifiers + ) + { + // + // Update Calculations ... + Calculate(); + + // + return IsSame( + hcLLBuffer, + verifier, + barIndex // + ); + } + + // + bool GetConditions( + XPVConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + CopyPeak( + zIndex, + loopback, + conditions.peaks // + ); + + // + CopyVale( + zIndex, + loopback, + conditions.vales // + ); + + // + CopySupport( + zIndex, + loopback, + conditions.supports // + ); + + // + CopyResistance( + zIndex, + loopback, + conditions.resistances // + ); + + // + CopyFib1( + zIndex, + loopback, + conditions.fib1s // + ); + + // + CopyFib2( + zIndex, + loopback, + conditions.fib2s // + ); + + // + CopyFib3( + zIndex, + loopback, + conditions.fib3s // + ); + + // + CopyFib4( + zIndex, + loopback, + conditions.fib4s // + ); + + // + CopyFib5( + zIndex, + loopback, + conditions.fib5s // + ); + + // + CopySCHH( + zIndex, + loopback, + conditions.sCHHs // + ); + + // + CopySCLL( + zIndex, + loopback, + conditions.sCLLs // + ); + + // + CopyMCHH( + zIndex, + loopback, + conditions.mCHHs // + ); + + // + CopyMCLL( + zIndex, + loopback, + conditions.mCLLs // + ); + + // + CopyLCHH( + zIndex, + loopback, + conditions.lCHHs // + ); + + // + CopyLCLL( + zIndex, + loopback, + conditions.lCLLs // + ); + + // + CopyHCHH( + zIndex, + loopback, + conditions.hCHHs // + ); + + // + CopyHCLL( + zIndex, + loopback, + conditions.hCLLs // + ); + + // + // Conditions ... + + // + bool isNewPeak = conditions.peaks[cIndex] != conditions.peaks[pIndex]; + bool isNewPeakOverLast = isNewPeak && + conditions.peaks[cIndex] > conditions.peaks[pIndex]; + bool isNewPeakUnderLast = isNewPeak && + conditions.peaks[cIndex] < conditions.peaks[pIndex]; + + // + bool isNewVale = conditions.vales[cIndex] != conditions.vales[pIndex]; + bool isNewValeOverLast = isNewVale && + conditions.vales[cIndex] > conditions.vales[pIndex]; + bool isNewValeUnderLast = isNewVale && + conditions.vales[cIndex] < conditions.vales[pIndex]; + + // + bool isFiboIncreased = + // + conditions.fib1s[cIndex] > conditions.fib1s[pIndex] && + conditions.fib2s[cIndex] > conditions.fib2s[pIndex] && + conditions.fib3s[cIndex] > conditions.fib3s[pIndex] && + conditions.fib4s[cIndex] > conditions.fib4s[pIndex] && + conditions.fib5s[cIndex] > conditions.fib5s[pIndex] + // + ; + bool isFiboDecreased = + // + conditions.fib1s[cIndex] < conditions.fib1s[pIndex] && + conditions.fib2s[cIndex] < conditions.fib2s[pIndex] && + conditions.fib3s[cIndex] < conditions.fib3s[pIndex] && + conditions.fib4s[cIndex] < conditions.fib4s[pIndex] && + conditions.fib5s[cIndex] < conditions.fib5s[pIndex] + // + ; + bool isFiboSectionChanged = + // + (isFiboDecreased && + isNewPeakUnderLast) + // + || + // + (isFiboIncreased && + isNewValeOverLast) + // + ; + + // + // SC ... + + // + bool isSCHHBullish = conditions.sCHHs[cIndex] > conditions.sCHHs[pIndex]; + bool isSCLLBullish = conditions.sCLLs[cIndex] > conditions.sCLLs[pIndex]; + + // + bool isSCHHBullishPrev = conditions.sCHHs[pIndex] > conditions.sCHHs[ppIndex]; + bool isSCLLBullishPrev = conditions.sCLLs[pIndex] > conditions.sCLLs[ppIndex]; + + // + bool isSCBullish = isSCHHBullish && + isSCLLBullish; + + // + bool isSCBullishPrev = isSCHHBullishPrev && + isSCLLBullishPrev; + + // + bool isSCHHSwitchedToBullish = isSCHHBullish && + !isSCHHBullishPrev; + bool isSCLLSwitchedToBullish = isSCLLBullish && + !isSCLLBullishPrev; + + // + bool isSCHHBearish = conditions.sCHHs[cIndex] < conditions.sCHHs[pIndex]; + bool isSCLLBearish = conditions.sCLLs[cIndex] < conditions.sCLLs[pIndex]; + + // + bool isSCHHBearishPrev = conditions.sCHHs[pIndex] < conditions.sCHHs[ppIndex]; + bool isSCLLBearishPrev = conditions.sCLLs[pIndex] < conditions.sCLLs[ppIndex]; + + // + bool isSCBearish = isSCHHBearish && + isSCLLBearish; + + // + bool isSCBearishPrev = isSCHHBearishPrev && + isSCLLBearishPrev; + + // + bool isSCHHSwitchedToBearish = isSCHHBearish && + !isSCHHBearishPrev; + bool isSCLLSwitchedToBeraish = isSCLLBearish && + !isSCLLBearishPrev; + + // + bool isSCSwitchedToBullish = + // + (isSCHHSwitchedToBullish && + !isSCLLBearish) + // + || + // + (isSCLLSwitchedToBullish && + !isSCHHBearish) + // + ; + + // + bool isSCSwitchedToBearish = + // + (isSCHHSwitchedToBearish && + !isSCLLBullish) + // + || + // + (isSCLLSwitchedToBeraish && + !isSCHHBullish) + // + ; + + // + // MC ... + + // + bool isMCHHBullish = conditions.mCHHs[cIndex] > conditions.mCHHs[pIndex]; + bool isMCLLBullish = conditions.mCLLs[cIndex] > conditions.mCLLs[pIndex]; + + // + bool isMCHHBullishPrev = conditions.mCHHs[pIndex] > conditions.mCHHs[ppIndex]; + bool isMCLLBullishPrev = conditions.mCLLs[pIndex] > conditions.mCLLs[ppIndex]; + + // + bool isMCBullish = isMCHHBullish && + isMCLLBullish; + + // + bool isMCBullishPrev = isMCHHBullishPrev && + isMCLLBullishPrev; + + // + bool isMCHHSwitchedToBullish = isMCHHBullish && + !isMCHHBullishPrev; + bool isMCLLSwitchedToBullish = isMCLLBullish && + !isMCLLBullishPrev; + + // + bool isMCHHBearish = conditions.mCHHs[cIndex] < conditions.mCHHs[pIndex]; + bool isMCLLBearish = conditions.mCLLs[cIndex] < conditions.mCLLs[pIndex]; + + // + bool isMCHHBearishPrev = conditions.mCHHs[pIndex] < conditions.mCHHs[ppIndex]; + bool isMCLLBearishPrev = conditions.mCLLs[pIndex] < conditions.mCLLs[ppIndex]; + + // + bool isMCBearish = isMCHHBearish && + isMCLLBearish; + + // + bool isMCBearishPrev = isMCHHBearishPrev && + isMCLLBearishPrev; + + // + bool isMCHHSwitchedToBearish = isMCHHBearish && + !isMCHHBearishPrev; + bool isMCLLSwitchedToBeraish = isMCLLBearish && + !isMCLLBearishPrev; + + // + bool isMCSwitchedToBullish = + // + (isMCHHSwitchedToBullish && + !isMCLLBearish) + // + || + // + (isMCLLSwitchedToBullish && + !isMCHHBearish) + // + ; + + // + bool isMCSwitchedToBearish = + // + (isMCHHSwitchedToBearish && + !isMCLLBullish) + // + || + // + (isMCLLSwitchedToBeraish && + !isMCHHBullish) + // + ; + + // + // LC ... + + // + bool isLCHHBullish = conditions.lCHHs[cIndex] > conditions.lCHHs[pIndex]; + bool isLCLLBullish = conditions.lCLLs[cIndex] > conditions.lCLLs[pIndex]; + + // + bool isLCHHBullishPrev = conditions.lCHHs[pIndex] > conditions.lCHHs[ppIndex]; + bool isLCLLBullishPrev = conditions.lCLLs[pIndex] > conditions.lCLLs[ppIndex]; + + // + bool isLCBullish = isLCHHBullish && + isLCLLBullish; + + // + bool isLCBullishPrev = isLCHHBullishPrev && + isLCLLBullishPrev; + + // + bool isLCHHSwitchedToBullish = isLCHHBullish && + !isLCHHBullishPrev; + bool isLCLLSwitchedToBullish = isLCLLBullish && + !isLCLLBullishPrev; + + // + bool isLCHHBearish = conditions.lCHHs[cIndex] < conditions.lCHHs[pIndex]; + bool isLCLLBearish = conditions.lCLLs[cIndex] < conditions.lCLLs[pIndex]; + + // + bool isLCHHBearishPrev = conditions.lCHHs[pIndex] < conditions.lCHHs[ppIndex]; + bool isLCLLBearishPrev = conditions.lCLLs[pIndex] < conditions.lCLLs[ppIndex]; + + // + bool isLCBearish = isLCHHBearish && + isLCLLBearish; + + // + bool isLCBearishPrev = isLCHHBearishPrev && + isLCLLBearishPrev; + + // + bool isLCHHSwitchedToBearish = isLCHHBearish && + !isLCHHBearishPrev; + bool isLCLLSwitchedToBeraish = isLCLLBearish && + !isLCLLBearishPrev; + + // + bool isLCSwitchedToBullish = + // + (isLCHHSwitchedToBullish && + !isLCLLBearish) + // + || + // + (isLCLLSwitchedToBullish && + !isLCHHBearish) + // + ; + + // + bool isLCSwitchedToBearish = + // + (isLCHHSwitchedToBearish && + !isLCLLBullish) + // + || + // + (isLCLLSwitchedToBeraish && + !isLCHHBullish) + // + ; + + // + // HC ... + + // + bool isHCHHBullish = conditions.hCHHs[cIndex] > conditions.hCHHs[pIndex]; + bool isHCLLBullish = conditions.hCLLs[cIndex] > conditions.hCLLs[pIndex]; + + // + bool isHCHHBullishPrev = conditions.hCHHs[pIndex] > conditions.hCHHs[ppIndex]; + bool isHCLLBullishPrev = conditions.hCLLs[pIndex] > conditions.hCLLs[ppIndex]; + + // + bool isHCBullish = isHCHHBullish && + isHCLLBullish; + + // + bool isHCBullishPrev = isHCHHBullishPrev && + isHCLLBullishPrev; + + // + bool isHCHHSwitchedToBullish = isHCHHBullish && + !isHCHHBullishPrev; + bool isHCLLSwitchedToBullish = isHCLLBullish && + !isHCLLBullishPrev; + + // + bool isHCHHBearish = conditions.hCHHs[cIndex] < conditions.hCHHs[pIndex]; + bool isHCLLBearish = conditions.hCLLs[cIndex] < conditions.hCLLs[pIndex]; + + // + bool isHCHHBearishPrev = conditions.hCHHs[pIndex] < conditions.hCHHs[ppIndex]; + bool isHCLLBearishPrev = conditions.hCLLs[pIndex] < conditions.hCLLs[ppIndex]; + + // + bool isHCBearish = isHCHHBearish && + isHCLLBearish; + + // + bool isHCBearishPrev = isHCHHBearishPrev && + isHCLLBearishPrev; + + // + bool isHCHHSwitchedToBearish = isHCHHBearish && + !isHCHHBearishPrev; + bool isHCLLSwitchedToBeraish = isHCLLBearish && + !isHCLLBearishPrev; + + // + bool isHCSwitchedToBullish = + // + (isHCHHSwitchedToBullish && + !isHCLLBearish) + // + || + // + (isHCLLSwitchedToBullish && + !isHCHHBearish) + // + ; + + // + bool isHCSwitchedToBearish = + // + (isHCHHSwitchedToBearish && + !isHCLLBullish) + // + || + // + (isHCLLSwitchedToBeraish && + !isHCHHBullish) + // + ; + + // + // Define Bars For Calculations ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + bool isCloseOverFib1 = cBar.close > conditions.fib1s[cIndex]; + bool isCloseOverFib1Prev = pBar.close > conditions.fib1s[pIndex]; + + // + bool isCloseOverFib2 = cBar.close > conditions.fib2s[cIndex]; + bool isCloseOverFib2Prev = pBar.close > conditions.fib2s[pIndex]; + + // + bool isCloseOverFib3 = cBar.close > conditions.fib3s[cIndex]; + bool isCloseOverFib3Prev = pBar.close > conditions.fib3s[pIndex]; + + // + bool isCloseOverFib4 = cBar.close > conditions.fib4s[cIndex]; + bool isCloseOverFib4Prev = pBar.close > conditions.fib4s[pIndex]; + + // + bool isCloseOverFib5 = cBar.close > conditions.fib5s[cIndex]; + bool isCloseOverFib5Prev = pBar.close > conditions.fib5s[pIndex]; + + // + bool isCloseUnderFib1 = cBar.close < conditions.fib1s[cIndex]; + bool isCloseUnderFib1Prev = pBar.close < conditions.fib1s[pIndex]; + + // + bool isCloseUnderFib2 = cBar.close < conditions.fib2s[cIndex]; + bool isCloseUnderFib2Prev = pBar.close < conditions.fib2s[pIndex]; + + // + bool isCloseUnderFib3 = cBar.close < conditions.fib3s[cIndex]; + bool isCloseUnderFib3Prev = pBar.close < conditions.fib3s[pIndex]; + + // + bool isCloseUnderFib4 = cBar.close < conditions.fib4s[cIndex]; + bool isCloseUnderFib4Prev = pBar.close < conditions.fib4s[pIndex]; + + // + bool isCloseUnderFib5 = cBar.close < conditions.fib5s[cIndex]; + bool isCloseUnderFib5Prev = pBar.close < conditions.fib5s[pIndex]; + + // + bool isCloseCrossedOverFib1 = isCloseOverFib1 && + !isCloseOverFib1Prev; + bool isCloseCrossedOverFib2 = isCloseOverFib2 && + !isCloseOverFib2Prev; + bool isCloseCrossedOverFib3 = isCloseOverFib3 && + !isCloseOverFib3Prev; + bool isCloseCrossedOverFib4 = isCloseOverFib4 && + !isCloseOverFib4Prev; + bool isCloseCrossedOverFib5 = isCloseOverFib5 && + !isCloseOverFib5Prev; + + // + bool isCloseCrossedUnderFib1 = isCloseUnderFib1 && + !isCloseUnderFib1Prev; + bool isCloseCrossedUnderFib2 = isCloseUnderFib2 && + !isCloseUnderFib2Prev; + bool isCloseCrossedUnderFib3 = isCloseUnderFib3 && + !isCloseUnderFib3Prev; + bool isCloseCrossedUnderFib4 = isCloseUnderFib4 && + !isCloseUnderFib4Prev; + bool isCloseCrossedUnderFib5 = isCloseUnderFib5 && + !isCloseUnderFib5Prev; + + // + conditions.isNewPeak = isNewPeak; + conditions.isNewPeakOverLast = isNewPeakOverLast; + conditions.isNewPeakUnderLast = isNewPeakUnderLast; + conditions.isNewVale = isNewVale; + conditions.isNewValeOverLast = isNewValeOverLast; + conditions.isNewValeUnderLast = isNewValeUnderLast; + conditions.isFiboIncreased = isFiboIncreased; + conditions.isFiboDecreased = isFiboDecreased; + conditions.isFiboSectionChanged = isFiboSectionChanged; + conditions.isCloseOverFib1 = isCloseOverFib1; + conditions.isCloseOverFib2 = isCloseOverFib2; + conditions.isCloseOverFib3 = isCloseOverFib3; + conditions.isCloseOverFib4 = isCloseOverFib4; + conditions.isCloseOverFib5 = isCloseOverFib5; + conditions.isCloseUnderFib1 = isCloseUnderFib1; + conditions.isCloseUnderFib2 = isCloseUnderFib2; + conditions.isCloseUnderFib3 = isCloseUnderFib3; + conditions.isCloseUnderFib4 = isCloseUnderFib4; + conditions.isCloseUnderFib5 = isCloseUnderFib5; + conditions.isCloseCrossedOverFib1 = isCloseCrossedOverFib1; + conditions.isCloseCrossedOverFib2 = isCloseCrossedOverFib2; + conditions.isCloseCrossedOverFib3 = isCloseCrossedOverFib3; + conditions.isCloseCrossedOverFib4 = isCloseCrossedOverFib4; + conditions.isCloseCrossedOverFib5 = isCloseCrossedOverFib5; + conditions.isCloseCrossedUnderFib1 = isCloseCrossedUnderFib1; + conditions.isCloseCrossedUnderFib2 = isCloseCrossedUnderFib2; + conditions.isCloseCrossedUnderFib3 = isCloseCrossedUnderFib3; + conditions.isCloseCrossedUnderFib4 = isCloseCrossedUnderFib4; + conditions.isCloseCrossedUnderFib5 = isCloseCrossedUnderFib5; + conditions.isSCBullish = isSCBullish; + conditions.isSCHHBullish = isSCHHBullish; + conditions.isSCLLBullish = isSCLLBullish; + conditions.isSCSwitchedToBullish = isSCSwitchedToBullish; + conditions.isSCHHSwitchedToBullish = isSCHHSwitchedToBullish; + conditions.isSCLLSwitchedToBullish = isSCLLSwitchedToBullish; + conditions.isSCBearish = isSCBearish; + conditions.isSCHHBearish = isSCHHBearish; + conditions.isSCLLBearish = isSCLLBearish; + conditions.isSCSwitchedToBearish = isSCSwitchedToBearish; + conditions.isSCHHSwitchedToBearish = isSCHHSwitchedToBearish; + conditions.isSCLLSwitchedToBeraish = isSCLLSwitchedToBeraish; + conditions.isMCBullish = isMCBullish; + conditions.isMCHHBullish = isMCHHBullish; + conditions.isMCLLBullish = isMCLLBullish; + conditions.isMCSwitchedToBullish = isMCSwitchedToBullish; + conditions.isMCHHSwitchedToBullish = isMCHHSwitchedToBullish; + conditions.isMCLLSwitchedToBullish = isMCLLSwitchedToBullish; + conditions.isMCBearish = isMCBearish; + conditions.isMCHHBearish = isMCHHBearish; + conditions.isMCLLBearish = isMCLLBearish; + conditions.isMCSwitchedToBearish = isMCSwitchedToBearish; + conditions.isMCHHSwitchedToBearish = isMCHHSwitchedToBearish; + conditions.isMCLLSwitchedToBeraish = isMCLLSwitchedToBeraish; + conditions.isLCBullish = isLCBullish; + conditions.isLCHHBullish = isLCHHBullish; + conditions.isLCLLBullish = isLCLLBullish; + conditions.isLCSwitchedToBullish = isLCSwitchedToBullish; + conditions.isLCHHSwitchedToBullish = isLCHHSwitchedToBullish; + conditions.isLCLLSwitchedToBullish = isLCLLSwitchedToBullish; + conditions.isLCBearish = isLCBearish; + conditions.isLCHHBearish = isLCHHBearish; + conditions.isLCLLBearish = isLCLLBearish; + conditions.isLCSwitchedToBearish = isLCSwitchedToBearish; + conditions.isLCHHSwitchedToBearish = isLCHHSwitchedToBearish; + conditions.isLCLLSwitchedToBeraish = isLCLLSwitchedToBeraish; + conditions.isHCBullish = isHCBullish; + conditions.isHCHHBullish = isHCHHBullish; + conditions.isHCLLBullish = isHCLLBullish; + conditions.isHCSwitchedToBullish = isHCSwitchedToBullish; + conditions.isHCHHSwitchedToBullish = isHCHHSwitchedToBullish; + conditions.isHCLLSwitchedToBullish = isHCLLSwitchedToBullish; + conditions.isHCBearish = isHCBearish; + conditions.isHCHHBearish = isHCHHBearish; + conditions.isHCLLBearish = isHCLLBearish; + conditions.isHCSwitchedToBearish = isHCSwitchedToBearish; + conditions.isHCHHSwitchedToBearish = isHCHHSwitchedToBearish; + conditions.isHCLLSwitchedToBeraish = isHCLLSwitchedToBeraish; + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XPVInputs mInputs; // Inputs ... + + // + // Buffers ... + double peaksBuffer[]; + double valesBuffer[]; + double resistanceBuffer[]; + double supportBuffer[]; + double fib1Buffer[]; + double fib2Buffer[]; + double fib3Buffer[]; + double fib4Buffer[]; + double fib5Buffer[]; + double scHHBuffer[]; + double scLLBuffer[]; + double mcHHBuffer[]; + double mcLLBuffer[]; + double lcHHBuffer[]; + double lcLLBuffer[]; + double hcHHBuffer[]; + double hcLLBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Peaks and Vales ... + + // + // Peaks Buffer ... + CopyBuffer( + mHandler, + XPV_PEAKS_LINE, + 0, + totalBars, + peaksBuffer + // + ); + + // + // Vales Buffer ... + CopyBuffer( + mHandler, + XPV_VALES_LINE, + 0, + totalBars, + valesBuffer + // + ); + + // + // Support and Resistances ... + + // + // Resistances Buffer ... + CopyBuffer( + mHandler, + XPV_RESISTANCE_LINE, + 0, + totalBars, + resistanceBuffer + // + ); + + // + // Supports Buffer ... + CopyBuffer( + mHandler, + XPV_SUPPORT_LINE, + 0, + totalBars, + supportBuffer + // + ); + + // + // Fibonacci ... + + // + // Level 1 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_1_LINE, + 0, + totalBars, + fib1Buffer + // + ); + + // + // Level 2 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_2_LINE, + 0, + totalBars, + fib2Buffer + // + ); + + // + // Level 3 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_3_LINE, + 0, + totalBars, + fib3Buffer + // + ); + + // + // Level 4 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_4_LINE, + 0, + totalBars, + fib4Buffer + // + ); + + // + // Level 5 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_5_LINE, + 0, + totalBars, + fib5Buffer + // + ); + + // + // Cycles ... + + // + // Short ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_SC_HH_LINE, + 0, + totalBars, + scHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_SC_LL_LINE, + 0, + totalBars, + scLLBuffer + // + ); + + // + // Medium ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_MC_HH_LINE, + 0, + totalBars, + mcHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_MC_LL_LINE, + 0, + totalBars, + mcLLBuffer + // + ); + + // + // Long ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_LC_HH_LINE, + 0, + totalBars, + lcHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_LC_LL_LINE, + 0, + totalBars, + lcLLBuffer + // + ); + + // + // Hind ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_HC_HH_LINE, + 0, + totalBars, + hcHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_HC_LL_LINE, + 0, + totalBars, + hcLLBuffer + // + ); + } +}; + +// +// Tools ... \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.x-time.indicator.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.x-time.indicator.mq5 new file mode 100644 index 00000000..d2edf38a --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.x-time.indicator.mq5 @@ -0,0 +1,237 @@ +/////////////////////////////////////////////////////// +// +// 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 ... +// diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xcc.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xcc.mq5 new file mode 100644 index 00000000..ebc45174 --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xcc.mq5 @@ -0,0 +1,437 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Candle Styles +// --------------------------------------------------- +// Name: XCC +// Description: Candle Styles ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCC Indicator" +#property strict + +// +// START Constants ... +// + +// +// Indicator Short Name ... +#define ShortName "XCC" + +// +// Holds an SnapShot of Charts Configuration ... +struct XChartStyle +{ + // + // chart's ID ... + long chartId; + // + // chart's mode ... + ENUM_CHART_MODE mode; + // + // show bid line ... + bool showBidLine; + // + // show ask line ... + bool showAskLine; + // + // show grids on chart ... + bool showGrid; + // + // show volumes ... + bool showVolumes; + // + // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ... + bool showTradeLevels; + // + // chart autoscroll ... + bool autoScroll; + // + // chart quick navigation state ... + bool quickNavigation; + // + // chart's foreground color ... + color foreGroundColor; + // + // chart's background color ... + color backGroundColor; + // + // Up Color ... + color upColor; + // + // Down Color ... + color downColor; + // + // Bullish color ... + color bullishColor; + // + // Bearish color ... + color bearishColor; + // + // grid color ... + color gridColor; + // + // bid line color ... + color bidLineColor; + // + // ask line color ... + color askLineColor; + // + // line mode and doji candlestick color ... + color lineColor; + // + // Color of stop order levels (Stop Loss and Take Profit) ... + color stopColor; + // + // volumes color ... + color volumesColor; +}; + +// +// END Constants ... +// + +// +// START Inputs ... +// + +// +input group "Chart Style"; +input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode +input color upColor = clrLime; // Up Color +input color downColor = clrRed; // Down Color +input color lineColor = clrLime; // Line mode and Doji candlestick Color +input color bearishColor = clrRed; // Bullish Color +input color bullishColor = clrLime; // Bearish Color +input color volumesColor = clrGreen; // Volumes Color + +// +input group "Presentation"; +input bool showCandles = true; // Show Candles + +// +// END Inputs ... +// + +// +// START Includes and Imports ... +// + +// +// Includes Draw Library ... +#include "../Libraries/x-saherelm.draw.lib.mq5" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// END Includes and Imports ... +// + +// +// START Buffers ... +// + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + +// +// END Buffers ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// + +// +int maxLength; + +// +XChartStyle chartStyle; +XChartStyle clearStyle; + +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// START Event Handlers ... +// + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + drawPrefix = ShortName; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Apply Chart Style ... + ApplyCustomChartStyle(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + 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; + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// END Event Handlers ... +// + +// +// START Functions ... +// + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = true; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index // Selected Bar Index +) +{ +} + +// +// Apply Custom Chart Style ... +void ApplyCustomChartStyle() +{ + // + // Read Current Chart Config and Store it ... + ReadChartStyle(); + + // + // After Reading Current Chart Style ... + // we have to Save Configs and Change Styles ... + clearStyle = chartStyle; + + // + clearStyle.upColor = CLR_NONE; + clearStyle.downColor = CLR_NONE; + clearStyle.lineColor = CLR_NONE; + clearStyle.bullishColor = CLR_NONE; + clearStyle.bearishColor = CLR_NONE; + + // + // Decide to Show or not Candles based on User Input ... + if (showCandles) + { + SetChartStyle(chartStyle); + } + else + { + SetChartStyle(clearStyle); + } +} + +// +// Read Previous Chart Style ... +void ReadChartStyle() +{ + // + // Retrieve Current Chart ID ... + long chartId = ChartID(); + chartStyle.chartId = chartId; + + // + // Retrieve Chart Mode ... + chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE); + + // + chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE); + chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE); + chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID); + chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES); + chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS); + chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL); + chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION); + + // + chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND); + chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND); + chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP); + chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN); + chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL); + chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR); + chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID); + chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID); + chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK); + chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL); + chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE); + chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME); + + // + chartStyle.mode = mode; + chartStyle.upColor = upColor; + chartStyle.downColor = downColor; + chartStyle.lineColor = lineColor; + chartStyle.bearishColor = bearishColor; + chartStyle.bullishColor = bullishColor; + chartStyle.volumesColor = volumesColor; +} + +// +// Set Chart Style ... +void SetChartStyle( + XChartStyle &mChartStyle // Chart Style to Apply +) +{ + // + ApplyChartStyle( + mChartStyle.chartId, + mChartStyle.mode, + mChartStyle.showBidLine, + mChartStyle.showAskLine, + mChartStyle.showGrid, + mChartStyle.showVolumes, + mChartStyle.showTradeLevels, + mChartStyle.autoScroll, + mChartStyle.quickNavigation, + mChartStyle.foreGroundColor, + mChartStyle.backGroundColor, + mChartStyle.upColor, + mChartStyle.downColor, + mChartStyle.bullishColor, + mChartStyle.bearishColor, + mChartStyle.gridColor, + mChartStyle.bidLineColor, + mChartStyle.askLineColor, + mChartStyle.lineColor, + mChartStyle.stopColor, + mChartStyle.volumesColor); +} + +// +// END Functions ... +// diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchche.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchche.mq5 new file mode 100644 index 00000000..9b6b3892 --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchche.mq5 @@ -0,0 +1,1190 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHCHE +// Description: XCHCHE 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 XCHCHE Indicator" +#property strict + +// +#define ShortName "XCHCHE" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 35; // Length +input int loopback = 26; // Loopback +input double multiplier1 = 3.0; // 1st Multiplier +input double multiplier2 = 3.5; // 2nd Multiplier + +// +input group "Calculation"; +input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to +input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to + +// +input group "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 showLE1 = true; // Show Long Exit 1 +input bool showLE2 = true; // Show Long Exit 2 +input bool showSE1 = true; // Show Short Exit 1 +input bool showSE2 = true; // Show Short Exit 2 + +// +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 20 +#property indicator_plots 20 + +// +// Current ... + +// +// Long Exit 1 ... +#define cLE1BufferIndex 0 +double cLE1Buffer[]; + +// +#property indicator_label1 "XCHCHE C LE 1" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT + +// +// Short Exit 1 ... +#define cSE1BufferIndex 1 +double cSE1Buffer[]; + +// +#property indicator_label2 "XCHCHE C SE 1" +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT +#property indicator_color2 clrRed + +// +// Long Exit 2 ... +#define cLE2BufferIndex 2 +double cLE2Buffer[]; + +// +#property indicator_label3 "XCHCHE C LE 2" +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT +#property indicator_color3 clrAqua + +// +// Short Exit 2 ... +#define cSE2BufferIndex 3 +double cSE2Buffer[]; + +// +#property indicator_label4 "XCHCHE C SE 2" +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_DOT +#property indicator_color4 clrMagenta + +// +// Short ... + +// +// Long Exit 1 ... +#define sLE1BufferIndex 4 +double sLE1Buffer[]; + +// +#property indicator_label5 "XCHCHE S LE 1" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLime +#property indicator_style5 STYLE_DOT + +// +// Short Exit 1 ... +#define sSE1BufferIndex 5 +double sSE1Buffer[]; + +// +#property indicator_label6 "XCHCHE S SE 1" +#property indicator_type6 DRAW_LINE +#property indicator_style6 STYLE_DOT +#property indicator_color6 clrRed + +// +// Long Exit 2 ... +#define sLE2BufferIndex 6 +double sLE2Buffer[]; + +// +#property indicator_label7 "XCHCHE S LE 2" +#property indicator_type7 DRAW_LINE +#property indicator_style7 STYLE_DOT +#property indicator_color7 clrAqua + +// +// Short Exit 2 ... +#define sSE2BufferIndex 7 +double sSE2Buffer[]; + +// +#property indicator_label8 "XCHCHE S SE 2" +#property indicator_type8 DRAW_LINE +#property indicator_style8 STYLE_DOT +#property indicator_color8 clrMagenta + +// +// Medium ... + +// +// Long Exit 1 ... +#define mLE1BufferIndex 8 +double mLE1Buffer[]; + +// +#property indicator_label9 "XCHCHE M LE 1" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLime +#property indicator_style9 STYLE_DOT + +// +// Short Exit 1 ... +#define mSE1BufferIndex 9 +double mSE1Buffer[]; + +// +#property indicator_label10 "XCHCHE M SE 1" +#property indicator_type10 DRAW_LINE +#property indicator_style10 STYLE_DOT +#property indicator_color10 clrRed + +// +// Long Exit 2 ... +#define mLE2BufferIndex 10 +double mLE2Buffer[]; + +// +#property indicator_label11 "XCHCHE M LE 2" +#property indicator_type11 DRAW_LINE +#property indicator_style11 STYLE_DOT +#property indicator_color11 clrAqua + +// +// Short Exit 2 ... +#define mSE2BufferIndex 11 +double mSE2Buffer[]; + +// +#property indicator_label12 "XCHCHE M SE 2" +#property indicator_type12 DRAW_LINE +#property indicator_style12 STYLE_DOT +#property indicator_color12 clrMagenta + +// +// Long ... + +// +// Long Exit 1 ... +#define lLE1BufferIndex 12 +double lLE1Buffer[]; + +// +#property indicator_label13 "XCHCHE L LE 1" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrLime +#property indicator_style13 STYLE_DOT + +// +// Short Exit 1 ... +#define lSE1BufferIndex 13 +double lSE1Buffer[]; + +// +#property indicator_label14 "XCHCHE L SE 1" +#property indicator_type14 DRAW_LINE +#property indicator_style14 STYLE_DOT +#property indicator_color14 clrRed + +// +// Long Exit 2 ... +#define lLE2BufferIndex 14 +double lLE2Buffer[]; + +// +#property indicator_label15 "XCHCHE L LE 2" +#property indicator_type15 DRAW_LINE +#property indicator_style15 STYLE_DOT +#property indicator_color15 clrAqua + +// +// Short Exit 2 ... +#define lSE2BufferIndex 15 +double lSE2Buffer[]; + +// +#property indicator_label16 "XCHCHE L SE 2" +#property indicator_type16 DRAW_LINE +#property indicator_style16 STYLE_DOT +#property indicator_color16 clrMagenta + +// +// Hind ... + +// +// Long Exit 1 ... +#define hLE1BufferIndex 16 +double hLE1Buffer[]; + +// +#property indicator_label17 "XCHCHE H LE 1" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrLime +#property indicator_style17 STYLE_DOT + +// +// Short Exit 1 ... +#define hSE1BufferIndex 17 +double hSE1Buffer[]; + +// +#property indicator_label18 "XCHCHE H SE 1" +#property indicator_type18 DRAW_LINE +#property indicator_style18 STYLE_DOT +#property indicator_color18 clrRed + +// +// Long Exit 2 ... +#define hLE2BufferIndex 18 +double hLE2Buffer[]; + +// +#property indicator_label19 "XCHCHE H LE 2" +#property indicator_type19 DRAW_LINE +#property indicator_style19 STYLE_DOT +#property indicator_color19 clrAqua + +// +// Short Exit 2 ... +#define hSE2BufferIndex 19 +double hSE2Buffer[]; + +// +#property indicator_label20 "XCHCHE H SE 2" +#property indicator_type20 DRAW_LINE +#property indicator_style20 STYLE_DOT +#property indicator_color20 clrMagenta + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +#define hi1Idx 0 +#define lo1Idx 1 +#define hi2Idx 2 +#define lo2Idx 3 +#define trend1Idx 4 +#define trend2Idx 5 + +// +// Current ... +int mCSMLength = length; +double cWork[][6]; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +double sWork[][6]; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +double mWork[][6]; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +double lWork[][6]; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +double hWork[][6]; + +// +// 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 ... +) +{ + // + if (Bars(_Symbol, _Period) < rates_total) + { + return (prev_calculated); + } + + // + if (ArrayRange(cWork, 0) != rates_total) + { + // + ArrayResize(cWork, rates_total); + ArrayResize(sWork, rates_total); + ArrayResize(mWork, rates_total); + ArrayResize(lWork, rates_total); + ArrayResize(hWork, rates_total); + } + + // + // this counts Available Bars ... + int limit; + + // + limit = prev_calculated - 1; + if (limit < 0) + { + limit = 0; + } + + // + // Main Loop ... + for (int i = limit; i < rates_total && !IsStopped(); i++) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + low, + close // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + loopback >= 0 && + // + (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; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 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; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 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; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 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; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 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(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // Long Exit 1 ... + bool canShowCLE1 = showCurrent && showLE1; + ENUM_DRAW_TYPE cLE1DrawType = canShowCLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLE1BufferIndex, cLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cLE1BufferIndex, PLOT_SHOW_DATA, canShowCLE1); + PlotIndexSetInteger(cLE1BufferIndex, PLOT_DRAW_TYPE, cLE1DrawType); + + // + // Long Exit 2 ... + bool canShowCLE2 = showCurrent && showLE2; + ENUM_DRAW_TYPE cLE2DrawType = canShowCLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLE2BufferIndex, cLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cLE2BufferIndex, PLOT_SHOW_DATA, canShowCLE2); + PlotIndexSetInteger(cLE2BufferIndex, PLOT_DRAW_TYPE, cLE2DrawType); + + // + // Short Exit 1 ... + bool canShowCSE1 = showCurrent && showSE1; + ENUM_DRAW_TYPE cSE1DrawType = canShowCSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cSE1BufferIndex, cSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cSE1BufferIndex, PLOT_SHOW_DATA, canShowCSE1); + PlotIndexSetInteger(cSE1BufferIndex, PLOT_DRAW_TYPE, cSE1DrawType); + + // + // Short Exit 2 ... + bool canShowCSE2 = showCurrent && showSE2; + ENUM_DRAW_TYPE cSE2DrawType = canShowCSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cSE2BufferIndex, cSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cSE2BufferIndex, PLOT_SHOW_DATA, canShowCSE2); + PlotIndexSetInteger(cSE2BufferIndex, PLOT_DRAW_TYPE, cSE2DrawType); + + // + // Short ... + + // + // Long Exit 1 ... + bool canShowSLE1 = showShort && showLE1; + ENUM_DRAW_TYPE sLE1DrawType = canShowSLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLE1BufferIndex, sLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sLE1BufferIndex, PLOT_SHOW_DATA, canShowSLE1); + PlotIndexSetInteger(sLE1BufferIndex, PLOT_DRAW_TYPE, sLE1DrawType); + + // + // Long Exit 2 ... + bool canShowSLE2 = showShort && showLE2; + ENUM_DRAW_TYPE sLE2DrawType = canShowSLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLE2BufferIndex, sLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sLE2BufferIndex, PLOT_SHOW_DATA, canShowSLE2); + PlotIndexSetInteger(sLE2BufferIndex, PLOT_DRAW_TYPE, sLE2DrawType); + + // + bool canShowSSE1 = showShort && showSE1; + // Short Exit 1 ... + ENUM_DRAW_TYPE sSE1DrawType = canShowSSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sSE1BufferIndex, sSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sSE1BufferIndex, PLOT_SHOW_DATA, canShowSSE1); + PlotIndexSetInteger(sSE1BufferIndex, PLOT_DRAW_TYPE, sSE1DrawType); + + // + // Short Exit 2 ... + bool canShowSSE2 = showShort && showSE2; + ENUM_DRAW_TYPE sSE2DrawType = canShowSSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sSE2BufferIndex, sSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sSE2BufferIndex, PLOT_SHOW_DATA, canShowSSE2); + PlotIndexSetInteger(sSE2BufferIndex, PLOT_DRAW_TYPE, sSE2DrawType); + + // + // Medium ... + + // + // Long Exit 1 ... + bool canShowMLE1 = showMedium && showLE1; + ENUM_DRAW_TYPE mLE1DrawType = canShowMLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLE1BufferIndex, mLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mLE1BufferIndex, PLOT_SHOW_DATA, canShowMLE1); + PlotIndexSetInteger(mLE1BufferIndex, PLOT_DRAW_TYPE, mLE1DrawType); + + // + // Long Exit 2 ... + bool canShowMLE2 = showMedium && showLE2; + ENUM_DRAW_TYPE mLE2DrawType = canShowMLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLE2BufferIndex, mLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mLE2BufferIndex, PLOT_SHOW_DATA, canShowMLE2); + PlotIndexSetInteger(mLE2BufferIndex, PLOT_DRAW_TYPE, mLE2DrawType); + + // + // Short Exit 1 ... + bool canShowMSE1 = showMedium && showSE1; + ENUM_DRAW_TYPE mSE1DrawType = canShowMSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mSE1BufferIndex, mSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mSE1BufferIndex, PLOT_SHOW_DATA, canShowMSE1); + PlotIndexSetInteger(mSE1BufferIndex, PLOT_DRAW_TYPE, mSE1DrawType); + + // + // Short Exit 2 ... + bool canShowMSE2 = showMedium && showSE2; + ENUM_DRAW_TYPE mSE2DrawType = canShowMSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mSE2BufferIndex, mSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mSE2BufferIndex, PLOT_SHOW_DATA, canShowMSE2); + PlotIndexSetInteger(mSE2BufferIndex, PLOT_DRAW_TYPE, mSE2DrawType); + + // + // Long ... + + // + // Long Exit 1 ... + bool canShowLLE1 = showLong && showLE1; + ENUM_DRAW_TYPE lLE1DrawType = canShowLLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLE1BufferIndex, lLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lLE1BufferIndex, PLOT_SHOW_DATA, canShowLLE1); + PlotIndexSetInteger(lLE1BufferIndex, PLOT_DRAW_TYPE, lLE1DrawType); + + // + // Long Exit 2 ... + bool canShowLLE2 = showLong && showLE2; + ENUM_DRAW_TYPE lLE2DrawType = canShowLLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLE2BufferIndex, lLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lLE2BufferIndex, PLOT_SHOW_DATA, canShowLLE2); + PlotIndexSetInteger(lLE2BufferIndex, PLOT_DRAW_TYPE, lLE2DrawType); + + // + // Short Exit 1 ... + bool canShowLSE1 = showLong && showSE1; + ENUM_DRAW_TYPE lSE1DrawType = canShowLSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lSE1BufferIndex, lSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lSE1BufferIndex, PLOT_SHOW_DATA, canShowLSE1); + PlotIndexSetInteger(lSE1BufferIndex, PLOT_DRAW_TYPE, lSE1DrawType); + + // + // Short Exit 2 ... + bool canShowLSE2 = showLong && showSE2; + ENUM_DRAW_TYPE lSE2DrawType = canShowLSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lSE2BufferIndex, lSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lSE2BufferIndex, PLOT_SHOW_DATA, canShowLSE2); + PlotIndexSetInteger(lSE2BufferIndex, PLOT_DRAW_TYPE, lSE2DrawType); + + // + // Hind ... + + // + // Long Exit 1 ... + bool canShowHLE1 = showHind && showLE1; + ENUM_DRAW_TYPE hLE1DrawType = canShowHLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLE1BufferIndex, hLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hLE1BufferIndex, PLOT_SHOW_DATA, canShowHLE1); + PlotIndexSetInteger(hLE1BufferIndex, PLOT_DRAW_TYPE, hLE1DrawType); + + // + // Long Exit 2 ... + bool canShowHLE2 = showHind && showLE2; + ENUM_DRAW_TYPE hLE2DrawType = canShowHLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLE2BufferIndex, hLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hLE2BufferIndex, PLOT_SHOW_DATA, canShowHLE2); + PlotIndexSetInteger(hLE2BufferIndex, PLOT_DRAW_TYPE, hLE2DrawType); + + // + // Short Exit 1 ... + bool canShowHSE1 = showHind && showSE1; + ENUM_DRAW_TYPE hSE1DrawType = canShowHSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hSE1BufferIndex, hSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hSE1BufferIndex, PLOT_SHOW_DATA, canShowHSE1); + PlotIndexSetInteger(hSE1BufferIndex, PLOT_DRAW_TYPE, hSE1DrawType); + + // + // Short Exit 2 ... + bool canShowHSE2 = showHind && showSE2; + ENUM_DRAW_TYPE hSE2DrawType = canShowHSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hSE2BufferIndex, hSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hSE2BufferIndex, PLOT_SHOW_DATA, canShowHSE2); + PlotIndexSetInteger(hSE2BufferIndex, PLOT_DRAW_TYPE, hSE2DrawType); +} + +// +// 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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low // + ); +} + +// +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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mCSMLength, + cWork, + cLE1Buffer, + cLE2Buffer, + cSE1Buffer, + cSE2Buffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mSSMLength, + sWork, + sLE1Buffer, + sLE2Buffer, + sSE1Buffer, + sSE2Buffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mMSMLength, + mWork, + mLE1Buffer, + mLE2Buffer, + mSE1Buffer, + mSE2Buffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mLSMLength, + lWork, + lLE1Buffer, + lLE2Buffer, + lSE1Buffer, + lSE2Buffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mHSMLength, + hWork, + hLE1Buffer, + hLE2Buffer, + hSE1Buffer, + hSE2Buffer // + ); +} + +// +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[], + // + int _length, // Calculation Length + double &work[][], // Working Array + // + double &le1[], + double &le2[], + double &se1[], + double &se2[] // +) +{ + // + // Cleanup Buffers ... + le1[bar_index] = se1[bar_index] = EMPTY_VALUE; + le2[bar_index] = se2[bar_index] = EMPTY_VALUE; + + // + int start = MathMax(bar_index - loopback, 0); + + // + // Calculate ATR Value ... + double atrValue = 0; + for (int k = 1; k <= _length && (bar_index - k - 1) >= 0; k++) + { + // + atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) - + MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]); + } + atrValue /= (double)_length; + + // + // Retrieve Highest High and Lowest Lows ... + double loopbackMax = high[ArrayMaximum(high, start, loopback)]; + double loopbackMin = low[ArrayMinimum(low, start, loopback)]; + + // + // Fill Multi Dimesional Working Array ... + work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue; + work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue; + work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue; + work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue; + work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0; + work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0; + + // + if (bar_index > 0) + { + // + // Calculate Trends ... + if (close[bar_index] > work[bar_index - 1][lo1Idx]) + { + work[bar_index][trend1Idx] = 1; + } + + // + if (close[bar_index] < work[bar_index - 1][hi1Idx]) + { + work[bar_index][trend1Idx] = -1; + } + + // + if (close[bar_index] > work[bar_index - 1][lo2Idx]) + { + work[bar_index][trend2Idx] = 1; + } + + // + if (close[bar_index] < work[bar_index - 1][hi2Idx]) + { + work[bar_index][trend2Idx] = -1; + } + + // + // Calculate Exit Values ... + + // + // Exit 1 ... + + // + // Long ... + if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1) + { + // + if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx]) + { + work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx]; + } + + // + le1[bar_index] = work[bar_index][hi1Idx]; + + // // + // if (le1[bar_index - 1] == EMPTY_VALUE) + // { + // longExit1StartBuffer[bar_index] = le1[bar_index]; + // } + } + + // + // Short ... + if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1) + { + // + if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx]) + { + work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx]; + } + + // + se1[bar_index] = work[bar_index][lo1Idx]; + + // // + // if (se1[bar_index - 1] == EMPTY_VALUE) + // { + // shortExit1StartBuffer[bar_index] = se1[bar_index]; + // } + } + + // + // Exit 2 ... + + // + // Long ... + if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1) + { + if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx]) + { + work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx]; + } + + // + le2[bar_index] = work[bar_index][hi2Idx]; + + // // + // if (le2[bar_index - 1] == EMPTY_VALUE) + // { + // longExit2StartBuffer[bar_index] = le2[bar_index]; + // } + } + + // + // Short ... + if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1) + { + // + if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx]) + { + work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx]; + } + + // + se2[bar_index] = work[bar_index][lo2Idx]; + + // // + // if (se2[bar_index - 1] == EMPTY_VALUE) + // { + // shortExit2StartBuffer[bar_index] = se2[bar_index]; + // } + } + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchdon.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchdon.mq5 new file mode 100644 index 00000000..64f53ece --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchdon.mq5 @@ -0,0 +1,1603 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XCHDON +// Description: Donchain on 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 XCHDON Indicator" +#property strict + +// +#define ShortName "XCHDON" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 52; // Market 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 + +// +input group "Presentation"; + +// +input bool showUpper = true; // Show Upper Band +input bool showLower = true; // Show Lower Band + +// +input bool showOpen = true; // Show Open +input bool showHigh = true; // Show High +input bool showClose = true; // Show Close +input bool showLow = true; // Show Low + +// +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 40 +#property indicator_plots 40 + +// +// Current ... + +// +// Open ... + +// +#define cOpenUpperBufferIndex 0 +double cOpenUpperBuffer[]; + +// +#property indicator_label1 "XCHDON C O U" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrCornflowerBlue +#property indicator_width1 1 + +// +#define cOpenLowerBufferIndex 1 +double cOpenLowerBuffer[]; + +// +#property indicator_label2 "XCHDON C O L" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrCornflowerBlue +#property indicator_width2 1 + +// +// High ... + +// +#define cHighUpperBufferIndex 2 +double cHighUpperBuffer[]; + +// +#property indicator_label3 "XCHDON C H U" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAquamarine +#property indicator_width3 1 + +// +#define cHighLowerBufferIndex 3 +double cHighLowerBuffer[]; + +// +#property indicator_label4 "XCHDON C H L" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrAquamarine +#property indicator_width4 1 + +// +// Low ... + +// +#define cLowUpperBufferIndex 4 +double cLowUpperBuffer[]; + +// +#property indicator_label5 "XCHDON C L U" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrDarkOrchid +#property indicator_width5 1 + +// +#define cLowLowerBufferIndex 5 +double cLowLowerBuffer[]; + +// +#property indicator_label6 "XCHDON C L L" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrDarkOrchid +#property indicator_width6 1 + +// +// Close ... + +// +#define cCloseUpperBufferIndex 6 +double cCloseUpperBuffer[]; + +// +#property indicator_label7 "XCHDON C C U" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrCoral +#property indicator_width7 1 + +// +#define cCloseLowerBufferIndex 7 +double cCloseLowerBuffer[]; + +// +#property indicator_label8 "XCHDON C C L" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrCoral +#property indicator_width8 1 + +// +// Short ... + +// +// Open ... + +// +#define sOpenUpperBufferIndex 8 +double sOpenUpperBuffer[]; + +// +#property indicator_label9 "XCHDON S O U" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrCornflowerBlue +#property indicator_width9 1 + +// +#define sOpenLowerBufferIndex 9 +double sOpenLowerBuffer[]; + +// +#property indicator_label10 "XCHDON S O L" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrCornflowerBlue +#property indicator_width10 1 + +// +// High ... + +// +#define sHighUpperBufferIndex 10 +double sHighUpperBuffer[]; + +// +#property indicator_label11 "XCHDON S H U" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAquamarine +#property indicator_width11 1 + +// +#define sHighLowerBufferIndex 11 +double sHighLowerBuffer[]; + +// +#property indicator_label12 "XCHDON S H L" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrAquamarine +#property indicator_width12 1 + +// +// Low ... + +// +#define sLowUpperBufferIndex 12 +double sLowUpperBuffer[]; + +// +#property indicator_label13 "XCHDON S L U" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkOrchid +#property indicator_width13 1 + +// +#define sLowLowerBufferIndex 13 +double sLowLowerBuffer[]; + +// +#property indicator_label14 "XCHDON S L L" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrDarkOrchid +#property indicator_width14 1 + +// +// Close ... + +// +#define sCloseUpperBufferIndex 14 +double sCloseUpperBuffer[]; + +// +#property indicator_label15 "XCHDON S C U" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrCoral +#property indicator_width15 1 + +// +#define sCloseLowerBufferIndex 15 +double sCloseLowerBuffer[]; + +// +#property indicator_label16 "XCHDON S C L" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrCoral +#property indicator_width16 1 + +// +// Medium ... + +// +// Open ... + +// +#define mOpenUpperBufferIndex 16 +double mOpenUpperBuffer[]; + +// +#property indicator_label17 "XCHDON M O U" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrCornflowerBlue +#property indicator_width17 1 + +// +#define mOpenLowerBufferIndex 17 +double mOpenLowerBuffer[]; + +// +#property indicator_label18 "XCHDON M O L" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrCornflowerBlue +#property indicator_width18 1 + +// +// High ... + +// +#define mHighUpperBufferIndex 18 +double mHighUpperBuffer[]; + +// +#property indicator_label19 "XCHDON M H U" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrAquamarine +#property indicator_width19 1 + +// +#define mHighLowerBufferIndex 19 +double mHighLowerBuffer[]; + +// +#property indicator_label20 "XCHDON M H L" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrAquamarine +#property indicator_width20 1 + +// +// Low ... + +// +#define mLowUpperBufferIndex 20 +double mLowUpperBuffer[]; + +// +#property indicator_label21 "XCHDON M L U" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrDarkOrchid +#property indicator_width21 1 + +// +#define mLowLowerBufferIndex 21 +double mLowLowerBuffer[]; + +// +#property indicator_label22 "XCHDON M L L" +#property indicator_type22 DRAW_LINE +#property indicator_color22 clrDarkOrchid +#property indicator_width22 1 + +// +// Close ... + +// +#define mCloseUpperBufferIndex 22 +double mCloseUpperBuffer[]; + +// +#property indicator_label23 "XCHDON M C U" +#property indicator_type23 DRAW_LINE +#property indicator_color23 clrCoral +#property indicator_width23 1 + +// +#define mCloseLowerBufferIndex 23 +double mCloseLowerBuffer[]; + +// +#property indicator_label24 "XCHDON M C L" +#property indicator_type24 DRAW_LINE +#property indicator_color24 clrCoral +#property indicator_width24 1 + +// +// Long ... + +// +// Open ... + +// +#define lOpenUpperBufferIndex 24 +double lOpenUpperBuffer[]; + +// +#property indicator_label25 "XCHDON L O U" +#property indicator_type25 DRAW_LINE +#property indicator_color25 clrCornflowerBlue +#property indicator_width25 1 + +// +#define lOpenLowerBufferIndex 25 +double lOpenLowerBuffer[]; + +// +#property indicator_label26 "XCHDON L O L" +#property indicator_type26 DRAW_LINE +#property indicator_color26 clrCornflowerBlue +#property indicator_width26 1 + +// +// High ... + +// +#define lHighUpperBufferIndex 26 +double lHighUpperBuffer[]; + +// +#property indicator_label27 "XCHDON L H U" +#property indicator_type27 DRAW_LINE +#property indicator_color27 clrAquamarine +#property indicator_width27 1 + +// +#define lHighLowerBufferIndex 27 +double lHighLowerBuffer[]; + +// +#property indicator_label28 "XCHDON L H L" +#property indicator_type28 DRAW_LINE +#property indicator_color28 clrAquamarine +#property indicator_width28 1 + +// +// Low ... + +// +#define lLowUpperBufferIndex 28 +double lLowUpperBuffer[]; + +// +#property indicator_label29 "XCHDON L L U" +#property indicator_type29 DRAW_LINE +#property indicator_color29 clrDarkOrchid +#property indicator_width29 1 + +// +#define lLowLowerBufferIndex 29 +double lLowLowerBuffer[]; + +// +#property indicator_label30 "XCHDON L L L" +#property indicator_type30 DRAW_LINE +#property indicator_color30 clrDarkOrchid +#property indicator_width30 1 + +// +// Close ... + +// +#define lCloseUpperBufferIndex 30 +double lCloseUpperBuffer[]; + +// +#property indicator_label31 "XCHDON L C U" +#property indicator_type31 DRAW_LINE +#property indicator_color31 clrCoral +#property indicator_width31 1 + +// +#define lCloseLowerBufferIndex 31 +double lCloseLowerBuffer[]; + +// +#property indicator_label32 "XCHDON L C L" +#property indicator_type32 DRAW_LINE +#property indicator_color32 clrCoral +#property indicator_width32 1 + +// +// Hind ... + +// +// Open ... + +// +#define hOpenUpperBufferIndex 32 +double hOpenUpperBuffer[]; + +// +#property indicator_label33 "XCHDON H O U" +#property indicator_type33 DRAW_LINE +#property indicator_color33 clrCornflowerBlue +#property indicator_width33 1 + +// +#define hOpenLowerBufferIndex 33 +double hOpenLowerBuffer[]; + +// +#property indicator_label34 "XCHDON H O L" +#property indicator_type34 DRAW_LINE +#property indicator_color34 clrCornflowerBlue +#property indicator_width34 1 + +// +// High ... + +// +#define hHighUpperBufferIndex 34 +double hHighUpperBuffer[]; + +// +#property indicator_label35 "XCHDON H H U" +#property indicator_type35 DRAW_LINE +#property indicator_color35 clrAquamarine +#property indicator_width35 1 + +// +#define hHighLowerBufferIndex 35 +double hHighLowerBuffer[]; + +// +#property indicator_label36 "XCHDON H H L" +#property indicator_type36 DRAW_LINE +#property indicator_color36 clrAquamarine +#property indicator_width36 1 + +// +// Low ... + +// +#define hLowUpperBufferIndex 36 +double hLowUpperBuffer[]; + +// +#property indicator_label37 "XCHDON H L U" +#property indicator_type37 DRAW_LINE +#property indicator_color37 clrDarkOrchid +#property indicator_width37 1 + +// +#define hLowLowerBufferIndex 37 +double hLowLowerBuffer[]; + +// +#property indicator_label38 "XCHDON H L L" +#property indicator_type38 DRAW_LINE +#property indicator_color38 clrDarkOrchid +#property indicator_width38 1 + +// +// Close ... + +// +#define hCloseUpperBufferIndex 38 +double hCloseUpperBuffer[]; + +// +#property indicator_label39 "XCHDON H C U" +#property indicator_type39 DRAW_LINE +#property indicator_color39 clrCoral +#property indicator_width39 1 + +// +#define hCloseLowerBufferIndex 39 +double hCloseLowerBuffer[]; + +// +#property indicator_label40 "XCHDON H C L" +#property indicator_type40 DRAW_LINE +#property indicator_color40 clrCoral +#property indicator_width40 1 + +// +// 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 ... +) +{ + // + if (rates_total < maxLength - 1) + { + return prev_calculated; + } + + // + int start = prev_calculated == 0 + ? maxLength + : prev_calculated - 1; + + // + // Main Loop ... + for (int i = start; i < rates_total; 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; + + // + // Current ... + 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); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // CURRENT ... + + // + // Open ... + + // + // UPPER ... + bool canShowCOpenUpper = showUpper && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenUpperBufferIndex, cOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_DRAW_TYPE, cOpenUpperDrawType); + + // + // LOWER ... + bool canShowCOpenLower = showLower && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenLowerBufferIndex, cOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_DRAW_TYPE, cOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowCCloseUpper = showUpper && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseUpperBufferIndex, cCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_DRAW_TYPE, cCloseUpperDrawType); + + // + // LOWER ... + bool canShowCCloseLower = showLower && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseLowerBufferIndex, cCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_DRAW_TYPE, cCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowCHighUpper = showUpper && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighUpperBufferIndex, cHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_DRAW_TYPE, cHighUpperDrawType); + + // + // LOWER ... + bool canShowCHighLower = showLower && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighLowerBufferIndex, cHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_SHOW_DATA, canShowCHighLower); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_DRAW_TYPE, cHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowCLowUpper = showUpper && showLow && showCurrent; + ENUM_DRAW_TYPE cLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowUpperBufferIndex, cLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_DRAW_TYPE, cLowUpperDrawType); + + // + // LOWER ... + bool canShowCLowLower = showLower && showLow && showCurrent; + ENUM_DRAW_TYPE cLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowLowerBufferIndex, cLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_DRAW_TYPE, cLowLowerDrawType); + + // + // SHORT ... + + // + // Open ... + + // + // UPPER ... + bool canShowSOpenUpper = showUpper && showOpen && showShort; + ENUM_DRAW_TYPE sOpenUpperDrawType = canShowSOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenUpperBufferIndex, sOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowSOpenUpper); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_DRAW_TYPE, sOpenUpperDrawType); + + // + // LOWER ... + bool canShowSOpenLower = showLower && showOpen && showShort; + ENUM_DRAW_TYPE sOpenLowerDrawType = canShowSOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenLowerBufferIndex, sOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowSOpenLower); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_DRAW_TYPE, sOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowSCloseUpper = showUpper && showClose && showShort; + ENUM_DRAW_TYPE sCloseUpperDrawType = canShowSCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseUpperBufferIndex, sCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowSCloseUpper); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_DRAW_TYPE, sCloseUpperDrawType); + + // + // LOWER ... + bool canShowSCloseLower = showLower && showClose && showShort; + ENUM_DRAW_TYPE sCloseLowerDrawType = canShowSCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseLowerBufferIndex, sCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowSCloseLower); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_DRAW_TYPE, sCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowSHighUpper = showUpper && showHigh && showShort; + ENUM_DRAW_TYPE sHighUpperDrawType = canShowSHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighUpperBufferIndex, sHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_SHOW_DATA, canShowSHighUpper); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_DRAW_TYPE, sHighUpperDrawType); + + // + // LOWER ... + bool canShowSHighLower = showLower && showHigh && showShort; + ENUM_DRAW_TYPE sHighLowerDrawType = canShowSHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighLowerBufferIndex, sHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_SHOW_DATA, canShowSHighLower); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_DRAW_TYPE, sHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowSLowUpper = showUpper && showLow && showShort; + ENUM_DRAW_TYPE sLowUpperDrawType = canShowSLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowUpperBufferIndex, sLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_SHOW_DATA, canShowSLowUpper); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_DRAW_TYPE, sLowUpperDrawType); + + // + // LOWER ... + bool canShowSLowLower = showLower && showLow && showShort; + ENUM_DRAW_TYPE sLowLowerDrawType = canShowSLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowLowerBufferIndex, sLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_SHOW_DATA, canShowSLowLower); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_DRAW_TYPE, sLowLowerDrawType); + + // + // MEDIUM ... + + // + // Open ... + + // + // UPPER ... + bool canShowMOpenUpper = showUpper && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenUpperDrawType = canShowMOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenUpperBufferIndex, mOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowMOpenUpper); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_DRAW_TYPE, mOpenUpperDrawType); + + // + // LOWER ... + bool canShowMOpenLower = showLower && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenLowerDrawType = canShowMOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenLowerBufferIndex, mOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowMOpenLower); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_DRAW_TYPE, mOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowMCloseUpper = showUpper && showClose && showMedium; + ENUM_DRAW_TYPE mCloseUpperDrawType = canShowMCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseUpperBufferIndex, mCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowMCloseUpper); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_DRAW_TYPE, mCloseUpperDrawType); + + // + // LOWER ... + bool canShowMCloseLower = showLower && showClose && showMedium; + ENUM_DRAW_TYPE mCloseLowerDrawType = canShowMCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseLowerBufferIndex, mCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowMCloseLower); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_DRAW_TYPE, mCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowMHighUpper = showUpper && showHigh && showMedium; + ENUM_DRAW_TYPE mHighUpperDrawType = canShowMHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighUpperBufferIndex, mHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_SHOW_DATA, canShowMHighUpper); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_DRAW_TYPE, mHighUpperDrawType); + + // + // LOWER ... + bool canShowMHighLower = showLower && showHigh && showMedium; + ENUM_DRAW_TYPE mHighLowerDrawType = canShowMHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighLowerBufferIndex, mHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_SHOW_DATA, canShowMHighLower); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_DRAW_TYPE, mHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowMLowUpper = showUpper && showLow && showMedium; + ENUM_DRAW_TYPE mLowUpperDrawType = canShowMLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowUpperBufferIndex, mLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_SHOW_DATA, canShowMLowUpper); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_DRAW_TYPE, mLowUpperDrawType); + + // + // LOWER ... + bool canShowMLowLower = showLower && showLow && showMedium; + ENUM_DRAW_TYPE mLowLowerDrawType = canShowMLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowLowerBufferIndex, mLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_SHOW_DATA, canShowMLowLower); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_DRAW_TYPE, mLowLowerDrawType); + + // + // LONG ... + + // + // Open ... + + // + // UPPER ... + bool canShowLOpenUpper = showUpper && showOpen && showLong; + ENUM_DRAW_TYPE lOpenUpperDrawType = canShowLOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenUpperBufferIndex, lOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowLOpenUpper); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_DRAW_TYPE, lOpenUpperDrawType); + + // + // LOWER ... + bool canShowLOpenLower = showLower && showOpen && showLong; + ENUM_DRAW_TYPE lOpenLowerDrawType = canShowLOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenLowerBufferIndex, lOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowLOpenLower); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_DRAW_TYPE, lOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowLCloseUpper = showUpper && showClose && showLong; + ENUM_DRAW_TYPE lCloseUpperDrawType = canShowLCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseUpperBufferIndex, lCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowLCloseUpper); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_DRAW_TYPE, lCloseUpperDrawType); + + // + // LOWER ... + bool canShowLCloseLower = showLower && showClose && showLong; + ENUM_DRAW_TYPE lCloseLowerDrawType = canShowLCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseLowerBufferIndex, lCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowLCloseLower); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_DRAW_TYPE, lCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowLHighUpper = showUpper && showHigh && showLong; + ENUM_DRAW_TYPE lHighUpperDrawType = canShowLHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighUpperBufferIndex, lHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_SHOW_DATA, canShowLHighUpper); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_DRAW_TYPE, lHighUpperDrawType); + + // + // LOWER ... + bool canShowLHighLower = showLower && showHigh && showLong; + ENUM_DRAW_TYPE lHighLowerDrawType = canShowLHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighLowerBufferIndex, lHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_SHOW_DATA, canShowLHighLower); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_DRAW_TYPE, lHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowLLowUpper = showUpper && showLow && showLong; + ENUM_DRAW_TYPE lLowUpperDrawType = canShowLLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowUpperBufferIndex, lLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_SHOW_DATA, canShowLLowUpper); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_DRAW_TYPE, lLowUpperDrawType); + + // + // LOWER ... + bool canShowLLowLower = showLower && showLow && showLong; + ENUM_DRAW_TYPE lLowLowerDrawType = canShowLLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowLowerBufferIndex, lLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_SHOW_DATA, canShowLLowLower); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_DRAW_TYPE, lLowLowerDrawType); + + // + // HIND ... + + // + // Open ... + + // + // UPPER ... + bool canShowHOpenUpper = showUpper && showOpen && showHind; + ENUM_DRAW_TYPE hOpenUpperDrawType = canShowHOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenUpperBufferIndex, hOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowHOpenUpper); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_DRAW_TYPE, hOpenUpperDrawType); + + // + // LOWER ... + bool canShowHOpenLower = showLower && showOpen && showHind; + ENUM_DRAW_TYPE hOpenLowerDrawType = canShowHOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenLowerBufferIndex, hOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowHOpenLower); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_DRAW_TYPE, hOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowHCloseUpper = showUpper && showClose && showHind; + ENUM_DRAW_TYPE hCloseUpperDrawType = canShowHCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseUpperBufferIndex, hCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowHCloseUpper); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_DRAW_TYPE, hCloseUpperDrawType); + + // + // LOWER ... + bool canShowHCloseLower = showLower && showClose && showHind; + ENUM_DRAW_TYPE hCloseLowerDrawType = canShowHCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseLowerBufferIndex, hCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowHCloseLower); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_DRAW_TYPE, hCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowHHighUpper = showUpper && showHigh && showHind; + ENUM_DRAW_TYPE hHighUpperDrawType = canShowHHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighUpperBufferIndex, hHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_SHOW_DATA, canShowHHighUpper); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_DRAW_TYPE, hHighUpperDrawType); + + // + // LOWER ... + bool canShowHHighLower = showLower && showHigh && showHind; + ENUM_DRAW_TYPE hHighLowerDrawType = canShowHHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighLowerBufferIndex, hHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_SHOW_DATA, canShowHHighLower); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_DRAW_TYPE, hHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowHLowUpper = showUpper && showLow && showHind; + ENUM_DRAW_TYPE hLowUpperDrawType = canShowHLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowUpperBufferIndex, hLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_SHOW_DATA, canShowHLowUpper); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_DRAW_TYPE, hLowUpperDrawType); + + // + // LOWER ... + bool canShowHLowLower = showLower && showLow && showHind; + ENUM_DRAW_TYPE hLowLowerDrawType = canShowHLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowLowerBufferIndex, hLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_SHOW_DATA, canShowHLowLower); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_DRAW_TYPE, hLowLowerDrawType); +} + +// +// 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, + // + cOpenUpperBuffer, + cOpenLowerBuffer, + cHighUpperBuffer, + cHighLowerBuffer, + cLowUpperBuffer, + cLowLowerBuffer, + cCloseUpperBuffer, + cCloseLowerBuffer // + ); + + // + // SHORT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + // + sOpenUpperBuffer, + sOpenLowerBuffer, + sHighUpperBuffer, + sHighLowerBuffer, + sLowUpperBuffer, + sLowLowerBuffer, + sCloseUpperBuffer, + sCloseLowerBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + // + mOpenUpperBuffer, + mOpenLowerBuffer, + mHighUpperBuffer, + mHighLowerBuffer, + mLowUpperBuffer, + mLowLowerBuffer, + mCloseUpperBuffer, + mCloseLowerBuffer // + ); + + // + // LONG ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + // + lOpenUpperBuffer, + lOpenLowerBuffer, + lHighUpperBuffer, + lHighLowerBuffer, + lLowUpperBuffer, + lLowLowerBuffer, + lCloseUpperBuffer, + lCloseLowerBuffer // + ); + + // + // HIND ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + // + hOpenUpperBuffer, + hOpenLowerBuffer, + hHighUpperBuffer, + hHighLowerBuffer, + hLowUpperBuffer, + hLowLowerBuffer, + hCloseUpperBuffer, + hCloseLowerBuffer // + ); +} + +// +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, + // + double &_ouBuffer[], + double &_olBuffer[], + double &_huBuffer[], + double &_hlBuffer[], + double &_luBuffer[], + double &_llBuffer[], + double &_cuBuffer[], + double &_clBuffer[] // +) +{ + // + double iUpper = 0; + double iLower = 0; + + // + // OPEN ... + + // + iUpper = open[ArrayMaximum(open, bar_index - _length + 1, _length)]; + iLower = open[ArrayMinimum(open, bar_index - _length + 1, _length)]; + + // + _ouBuffer[bar_index] = iUpper; + _olBuffer[bar_index] = iLower; + + // + // HIGH ... + + // + iUpper = high[ArrayMaximum(high, bar_index - _length + 1, _length)]; + iLower = high[ArrayMinimum(high, bar_index - _length + 1, _length)]; + + // + _huBuffer[bar_index] = iUpper; + _hlBuffer[bar_index] = iLower; + + // + // LOW ... + + // + iUpper = low[ArrayMaximum(low, bar_index - _length + 1, _length)]; + iLower = low[ArrayMinimum(low, bar_index - _length + 1, _length)]; + + // + _luBuffer[bar_index] = iUpper; + _llBuffer[bar_index] = iLower; + + // + // CLOSE ... + + // + iUpper = close[ArrayMaximum(close, bar_index - _length + 1, _length)]; + iLower = close[ArrayMinimum(close, bar_index - _length + 1, _length)]; + + // + _cuBuffer[bar_index] = iUpper; + _clBuffer[bar_index] = iLower; +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchhk.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchhk.mq5 new file mode 100644 index 00000000..ff6fae86 --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchhk.mq5 @@ -0,0 +1,1070 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHHK +// Description: Smoothed HikenAshi 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 XCHHK Indicator" +#property strict + +// +#define ShortName "XCHHK" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; + +// +input int cSmoothingLength = 14; // Smoothing 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 ignoreShadows = false; // Ignore Bar Shadows + +// +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 29 +#property indicator_plots 25 + +// +// Current ... + +// +#define cOpenBufferIndex 0 +double cOpenBuffer[]; + +// +#define cHighBufferIndex 1 +double cHighBuffer[]; + +// +#define cLowBufferIndex 2 +double cLowBuffer[]; + +// +#define cCloseBufferIndex 3 +double cCloseBuffer[]; + +// +#define cColorBufferIndex 4 +double cColorBuffer[]; + +// +#define cBufferIndex 0 +#property indicator_label1 "C Open;C High;C Low;C Close" +#property indicator_type1 DRAW_COLOR_CANDLES +#property indicator_color1 CLR_NONE, clrAqua, clrMagenta + +// +// Short ... + +// +#define sOpenBufferIndex 5 +double sOpenBuffer[]; + +// +#define sHighBufferIndex 6 +double sHighBuffer[]; + +// +#define sLowBufferIndex 7 +double sLowBuffer[]; + +// +#define sCloseBufferIndex 8 +double sCloseBuffer[]; + +// +#define sColorBufferIndex 9 +double sColorBuffer[]; + +// +#define sBufferIndex 1 +#property indicator_label2 "S Open;S High;S Low;S Close" +#property indicator_type2 DRAW_COLOR_CANDLES +#property indicator_color2 CLR_NONE, clrAqua, clrMagenta + +// +// Medium ... + +// +#define mOpenBufferIndex 10 +double mOpenBuffer[]; + +// +#define mHighBufferIndex 11 +double mHighBuffer[]; + +// +#define mLowBufferIndex 12 +double mLowBuffer[]; + +// +#define mCloseBufferIndex 13 +double mCloseBuffer[]; + +// +#define mColorBufferIndex 14 +double mColorBuffer[]; + +// +#define mBufferIndex 2 +#property indicator_label3 "M Open;M High;M Low;M Close" +#property indicator_type3 DRAW_COLOR_CANDLES +#property indicator_color3 CLR_NONE, clrAqua, clrMagenta + +// +// Long ... + +// +#define lOpenBufferIndex 15 +double lOpenBuffer[]; + +// +#define lHighBufferIndex 16 +double lHighBuffer[]; + +// +#define lLowBufferIndex 17 +double lLowBuffer[]; + +// +#define lCloseBufferIndex 18 +double lCloseBuffer[]; + +// +#define lColorBufferIndex 19 +double lColorBuffer[]; + +// +#define lBufferIndex 3 +#property indicator_label4 "L Open;L High;L Low;L Close" +#property indicator_type4 DRAW_COLOR_CANDLES +#property indicator_color4 CLR_NONE, clrAqua, clrMagenta + +// +// Hind ... + +// +#define hOpenBufferIndex 20 +double hOpenBuffer[]; + +// +#define hHighBufferIndex 21 +double hHighBuffer[]; + +// +#define hLowBufferIndex 22 +double hLowBuffer[]; + +// +#define hCloseBufferIndex 23 +double hCloseBuffer[]; + +// +#define hColorBufferIndex 24 +double hColorBuffer[]; + +// +#define hBufferIndex 4 +#property indicator_label5 "H Open;H High;H Low;H Close" +#property indicator_type5 DRAW_COLOR_CANDLES +#property indicator_color5 CLR_NONE, clrAqua, clrMagenta + +// +// Data Buffers ... + +// +#define openBufferIndex 25 +double openBuffer[]; + +// +#define highBufferIndex 26 +double highBuffer[]; + +// +#define lowBufferIndex 27 +double lowBuffer[]; + +// +#define closeBufferIndex 28 +double closeBuffer[]; + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCSMLength = cSmoothingLength; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 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; + + // + 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--) + { + CalculateHK(i, prev_calculated, rates_total, open, high, close, low); + } + + // + CalculateCycles(rates_total, prev_calculated); + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + cSmoothingLength > 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; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 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; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 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; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 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; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 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(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Data Buffers ... + + // + // Open ... + ArraySetAsSeries(openBuffer, true); + SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_CALCULATIONS); + + // + // High ... + ArraySetAsSeries(highBuffer, true); + SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_CALCULATIONS); + + // + // Low ... + ArraySetAsSeries(lowBuffer, true); + SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_CALCULATIONS); + + // + // Close ... + ArraySetAsSeries(closeBuffer, true); + SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_CALCULATIONS); + + // + // Current ... + + // + // Color ... + ArraySetAsSeries(cColorBuffer, true); + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(cBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(cBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(cColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(cOpenBuffer, true); + PlotIndexSetInteger(cOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cOpenBufferIndex, cOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(cHighBuffer, true); + PlotIndexSetInteger(cHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cHighBufferIndex, cHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(cCloseBuffer, true); + PlotIndexSetInteger(cCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cCloseBufferIndex, cCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(cLowBuffer, true); + PlotIndexSetInteger(cLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cLowBufferIndex, cLowBuffer, INDICATOR_DATA); + + // + // Short ... + + // + // Color ... + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(sBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(sBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(sColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(sOpenBuffer, true); + PlotIndexSetInteger(sOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sOpenBufferIndex, sOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(sHighBuffer, true); + PlotIndexSetInteger(sHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sHighBufferIndex, sHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(sCloseBuffer, true); + PlotIndexSetInteger(sCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sCloseBufferIndex, sCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(sLowBuffer, true); + PlotIndexSetInteger(sLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sLowBufferIndex, sLowBuffer, INDICATOR_DATA); + + // + // Medium ... + + // + // Color ... + ArraySetAsSeries(mColorBuffer, true); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(mBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(mBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(mColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(mOpenBuffer, true); + PlotIndexSetInteger(mOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mOpenBufferIndex, mOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(mHighBuffer, true); + PlotIndexSetInteger(mHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mHighBufferIndex, mHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(mCloseBuffer, true); + PlotIndexSetInteger(mCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mCloseBufferIndex, mCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(mLowBuffer, true); + PlotIndexSetInteger(mLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mLowBufferIndex, mLowBuffer, INDICATOR_DATA); + + // + // Long ... + + // + // Color ... + ArraySetAsSeries(lColorBuffer, true); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(lBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(lBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(lColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(lOpenBuffer, true); + PlotIndexSetInteger(lOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lOpenBufferIndex, lOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(lHighBuffer, true); + PlotIndexSetInteger(lHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lHighBufferIndex, lHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(lCloseBuffer, true); + PlotIndexSetInteger(lCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lCloseBufferIndex, lCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(lLowBuffer, true); + PlotIndexSetInteger(lLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lLowBufferIndex, lLowBuffer, INDICATOR_DATA); + + // + // Hind ... + + // + // Color ... + ArraySetAsSeries(hColorBuffer, true); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(hBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(hBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(hColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(hOpenBuffer, true); + PlotIndexSetInteger(hOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hOpenBufferIndex, hOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(hHighBuffer, true); + PlotIndexSetInteger(hHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hHighBufferIndex, hHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(hCloseBuffer, true); + PlotIndexSetInteger(hCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hCloseBufferIndex, hCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(hLowBuffer, true); + PlotIndexSetInteger(hLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hLowBufferIndex, hLowBuffer, INDICATOR_DATA); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Hiken Ashi ... +void CalculateHK( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + double mPrevHKOpenValue; + double mPrevHKCloseValue; + + // + if (ArraySize(open) <= bar_index + 1) + { + // + mPrevHKOpenValue = 0; + mPrevHKCloseValue = 0; + } + else + { + // + mPrevHKOpenValue = openBuffer[bar_index + 1]; + mPrevHKCloseValue = closeBuffer[bar_index + 1]; + } + + // + double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2; + double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4; + double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue)); + double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue)); + + // + openBuffer[bar_index] = mHKOpenValue; + highBuffer[bar_index] = mHKHighValue; + lowBuffer[bar_index] = mHKLowValue; + closeBuffer[bar_index] = mHKCloseValue; +} + +// +void CalculateCycles( + int ratesTotal, // Total Bars + int prevCalculated // Calculated Bars +) +{ + // + // Current ... + CalculateCycle( + cOpenBuffer, + cHighBuffer, + cLowBuffer, + cCloseBuffer, + cColorBuffer, + mCSMLength, + showCurrent, + ratesTotal, + prevCalculated // + ); + + // + // Short ... + CalculateCycle( + sOpenBuffer, + sHighBuffer, + sLowBuffer, + sCloseBuffer, + sColorBuffer, + mSSMLength, + showShort, + ratesTotal, + prevCalculated // + ); + + // + // Medium ... + CalculateCycle( + mOpenBuffer, + mHighBuffer, + mLowBuffer, + mCloseBuffer, + mColorBuffer, + mMSMLength, + showMedium, + ratesTotal, + prevCalculated // + ); + + // + // Long ... + CalculateCycle( + lOpenBuffer, + lHighBuffer, + lLowBuffer, + lCloseBuffer, + lColorBuffer, + mLSMLength, + showLong, + ratesTotal, + prevCalculated // + ); + + // + // Hind ... + CalculateCycle( + hOpenBuffer, + hHighBuffer, + hLowBuffer, + hCloseBuffer, + hColorBuffer, + mHSMLength, + showHind, + ratesTotal, + prevCalculated // + ); +} + +// +void CalculateCycle( + double &open[], + double &high[], + double &low[], + double &close[], + double &clr[], // Color Index Buffer + int length, // Calculation Length + bool show, // Show or not + int ratesTotal, // Total Bars + int prevCalculated // Calculated Bars +) +{ + // + // Open ... + int calculatedSMOpens = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + openBuffer, + open // + ); + + // + // Close ... + int calculatedSMCloses = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + closeBuffer, + close // + ); + + // + int calculatedSMLows = 0; + int calculatedSMHighs = 0; + if (!ignoreShadows) + { + // + // High ... + calculatedSMHighs = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + highBuffer, + high // + ); + + // + // Low ... + calculatedSMLows = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + lowBuffer, + low // + ); + } + else + { + // + // High ... + calculatedSMHighs = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + openBuffer, + high // + ); + + // + // Low ... + calculatedSMLows = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + closeBuffer, + low // + ); + } + + // + // Find Calculated Items for Colors Calculations ... + int mNumberOfItems = MathMin(calculatedSMOpens, calculatedSMHighs); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMLows); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMCloses); + + // + // Create a Loop for Color of Candles ... + for (int i = 0; i < mNumberOfItems; i++) + { + // + bool isBearish = + // + open[i] > close[i] + // + ; + + // + if (show) + { + // + clr[i] = isBearish + ? bearishColorIDX + : bullishColorIDX; + } + else + { + // + clr[i] = hideColorIDX; + } + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchich.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchich.mq5 new file mode 100644 index 00000000..f468e31d --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchich.mq5 @@ -0,0 +1,1826 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XCHICH +// Description: Ichimoku Kinko Hyo on 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 XCHICH Indicator" +#property strict + +// +#define ShortName "XCHICH" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Ichimoku Lines Calculator Mode ... +enum ENUM_X_ICHIMOKU_CALCULATION_MODE +{ + // + X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low + X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close +}; + +// +// Inputs ... + +// +input group "Market"; + +// +// TENKANSEN ... +input group "Tenkan Sen"; +input int tenkanSenLength = 9; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// KIJUNSEN ... +input group "Kijun Sen"; +input int kijunSenLength = 26; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// SENKOUSPANB ... +input group "Senkou Span B"; +input int senkouSpanBLength = 52; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// CHIKOUSPAN ... +input group "Chikou Span"; +input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type + +// +input group "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 + +// +input group "Presentation"; + +// +input bool showTenkanSen = true; // Show Tenkan Sen +input bool showKijunSen = true; // Show Kijun Sen +input bool showChikouSpan = true; // Show Chikou Span +input bool showSenkouSpanA = true; // Show Senkou Span A +input bool showSenkouSpanB = true; // Show Senkou Span B +input bool showKumo = true; // Show Kumo +input bool shiftKumo = true; // Shift Kumo to Future + +// +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 40 +#property indicator_plots 30 + +// +// CURRENT ... + +// +#define cTenBufferIndex 0 +double cTenBuffer[]; + +// +#property indicator_label1 "XICH C TK" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrBrown +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +#define cKijBufferIndex 1 +double cKijBuffer[]; + +// +#property indicator_label2 "XICH C KJ" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrDodgerBlue +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +#define cChikBufferIndex 2 +double cChikBuffer[]; + +// +#property indicator_label3 "XICH C CS" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrDarkGreen +#property indicator_style3 STYLE_SOLID +#property indicator_width3 1 + +// +#define cSSABufferIndex 3 +double cSSABuffer[]; + +// +#property indicator_label4 "XICH C SSA" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrLightGray +#property indicator_style4 STYLE_DASHDOTDOT +#property indicator_width4 1 + +// +#define cSSBBufferIndex 4 +double cSSBBuffer[]; + +// +#property indicator_label5 "XICH C SSB" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLightGray +#property indicator_style5 STYLE_DASHDOTDOT +#property indicator_width5 1 + +// +// SHORT ... + +// +#define sTenBufferIndex 5 +double sTenBuffer[]; + +// +#property indicator_label6 "XICH S TK" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrBrown +#property indicator_style6 STYLE_SOLID +#property indicator_width6 1 + +// +#define sKijBufferIndex 6 +double sKijBuffer[]; + +// +#property indicator_label7 "XICH S KJ" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrDodgerBlue +#property indicator_style7 STYLE_SOLID +#property indicator_width7 1 + +// +#define sChikBufferIndex 7 +double sChikBuffer[]; + +// +#property indicator_label8 "XICH S CS" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrDarkGreen +#property indicator_style8 STYLE_SOLID +#property indicator_width8 1 + +// +#define sSSABufferIndex 8 +double sSSABuffer[]; + +// +#property indicator_label9 "XICH S SSA" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLightGray +#property indicator_style9 STYLE_DASHDOTDOT +#property indicator_width9 1 + +// +#define sSSBBufferIndex 9 +double sSSBBuffer[]; + +// +#property indicator_label10 "XICH S SSB" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrLightGray +#property indicator_style10 STYLE_DASHDOTDOT +#property indicator_width10 1 + +// +// MEDIUM ... + +// +#define mTenBufferIndex 10 +double mTenBuffer[]; + +// +#property indicator_label11 "XICH M TK" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrBrown +#property indicator_style11 STYLE_SOLID +#property indicator_width11 1 + +// +#define mKijBufferIndex 11 +double mKijBuffer[]; + +// +#property indicator_label12 "XICH M KJ" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrDodgerBlue +#property indicator_style12 STYLE_SOLID +#property indicator_width12 1 + +// +#define mChikBufferIndex 12 +double mChikBuffer[]; + +// +#property indicator_label13 "XICH M CS" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkGreen +#property indicator_style13 STYLE_SOLID +#property indicator_width13 1 + +// +#define mSSABufferIndex 13 +double mSSABuffer[]; + +// +#property indicator_label14 "XICH M SSA" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrLightGray +#property indicator_style14 STYLE_DASHDOTDOT +#property indicator_width14 1 + +// +#define mSSBBufferIndex 14 +double mSSBBuffer[]; + +// +#property indicator_label15 "XICH M SSB" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrLightGray +#property indicator_style15 STYLE_DASHDOTDOT +#property indicator_width15 1 + +// +// LONG ... + +// +#define lTenBufferIndex 15 +double lTenBuffer[]; + +// +#property indicator_label16 "XICH L TK" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrBrown +#property indicator_style16 STYLE_SOLID +#property indicator_width16 1 + +// +#define lKijBufferIndex 16 +double lKijBuffer[]; + +// +#property indicator_label17 "XICH L KJ" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrDodgerBlue +#property indicator_style17 STYLE_SOLID +#property indicator_width17 1 + +// +#define lChikBufferIndex 17 +double lChikBuffer[]; + +// +#property indicator_label18 "XICH L CS" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrDarkGreen +#property indicator_style18 STYLE_SOLID +#property indicator_width18 1 + +// +#define lSSABufferIndex 18 +double lSSABuffer[]; + +// +#property indicator_label19 "XICH L SSA" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrLightGray +#property indicator_style19 STYLE_DASHDOTDOT +#property indicator_width19 1 + +// +#define lSSBBufferIndex 19 +double lSSBBuffer[]; + +// +#property indicator_label20 "XICH L SSB" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrLightGray +#property indicator_style20 STYLE_DASHDOTDOT +#property indicator_width20 1 + +// +// HIND ... + +// +#define hTenBufferIndex 20 +double hTenBuffer[]; + +// +#property indicator_label21 "XICH H TK" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrBrown +#property indicator_style21 STYLE_SOLID +#property indicator_width21 1 + +// +#define hKijBufferIndex 21 +double hKijBuffer[]; + +// +#property indicator_label22 "XICH H KJ" +#property indicator_type22 DRAW_LINE +#property indicator_color22 clrDodgerBlue +#property indicator_style22 STYLE_SOLID +#property indicator_width22 1 + +// +#define hChikBufferIndex 22 +double hChikBuffer[]; + +// +#property indicator_label23 "XICH H CS" +#property indicator_type23 DRAW_LINE +#property indicator_color23 clrDarkGreen +#property indicator_style23 STYLE_SOLID +#property indicator_width23 1 + +// +#define hSSABufferIndex 23 +double hSSABuffer[]; + +// +#property indicator_label24 "XICH H SSA" +#property indicator_type24 DRAW_LINE +#property indicator_color24 clrLightGray +#property indicator_style24 STYLE_DASHDOTDOT +#property indicator_width24 1 + +// +#define hSSBBufferIndex 24 +double hSSBBuffer[]; + +// +#property indicator_label25 "XICH H SSB" +#property indicator_type25 DRAW_LINE +#property indicator_color25 clrLightGray +#property indicator_style25 STYLE_DASHDOTDOT +#property indicator_width25 1 + +// +// +// + +// +// CURRENT ... + +// +#define cSSAKCBufferIndex 25 +double cSSAKCBuffer[]; + +// +#define cSSBKCBufferIndex 26 +double cSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define cKCBufferIndex 25 + +// +#property indicator_label26 "XICH C Kumo" +#property indicator_type26 DRAW_FILLING +#property indicator_color26 clrAqua, clrMagenta +#property indicator_style26 STYLE_SOLID +#property indicator_width26 1 + +// +// SHORT ... + +// +#define sSSAKCBufferIndex 27 +double sSSAKCBuffer[]; + +// +#define sSSBKCBufferIndex 28 +double sSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define sKCBufferIndex 26 + +// +#property indicator_label27 "XICH S Kumo" +#property indicator_type27 DRAW_FILLING +#property indicator_color27 clrAqua, clrMagenta +#property indicator_style27 STYLE_SOLID +#property indicator_width27 1 + +// +// MEDIUM ... + +// +#define mSSAKCBufferIndex 29 +double mSSAKCBuffer[]; + +// +#define mSSBKCBufferIndex 30 +double mSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define mKCBufferIndex 27 + +// +#property indicator_label28 "XICH M Kumo" +#property indicator_type28 DRAW_FILLING +#property indicator_color28 clrAqua, clrMagenta +#property indicator_style28 STYLE_SOLID +#property indicator_width28 1 + +// +// LONG ... + +// +#define lSSAKCBufferIndex 31 +double lSSAKCBuffer[]; + +// +#define lSSBKCBufferIndex 32 +double lSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define lKCBufferIndex 28 + +// +#property indicator_label29 "XICH L Kumo" +#property indicator_type29 DRAW_FILLING +#property indicator_color29 clrAqua, clrMagenta +#property indicator_style29 STYLE_SOLID +#property indicator_width29 1 + +// +// HIND ... + +// +#define hSSAKCBufferIndex 33 +double hSSAKCBuffer[]; + +// +#define hSSBKCBufferIndex 34 +double hSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define hKCBufferIndex 29 + +// +#property indicator_label30 "XICH H Kumo" +#property indicator_type30 DRAW_FILLING +#property indicator_color30 clrAqua, clrMagenta +#property indicator_style30 STYLE_SOLID +#property indicator_width30 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCTenkanSenLength = tenkanSenLength; +int mCKijunSenLength = kijunSenLength; +int mCSenkouSpanBLength = senkouSpanBLength; + +// +// Short ... +int mSCycleLength = 0; +int mSTenkanSenLength = 0; +int mSKijunSenLength = 0; +int mSSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMTenkanSenLength = 0; +int mMKijunSenLength = 0; +int mMSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLTenkanSenLength = 0; +int mLKijunSenLength = 0; +int mLSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHTenkanSenLength = 0; +int mHKijunSenLength = 0; +int mHSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +ENUM_SERIESMODE mTenkanSenTopMode = NULL; +ENUM_SERIESMODE mTenkanSenBottomMode = NULL; + +// +ENUM_SERIESMODE mKijunSenTopMode = NULL; +ENUM_SERIESMODE mKijunSenBottomMode = NULL; + +// +ENUM_SERIESMODE mSenkouSpanBTopMode = NULL; +ENUM_SERIESMODE mSenkouSpanBBottomMode = 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; + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume + // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + (tenkanSenLength > 2 && + kijunSenLength > tenkanSenLength && + senkouSpanBLength > kijunSenLength) + // + && + // + (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; + mSTenkanSenLength = mSCycleLength * mCTenkanSenLength; + mSKijunSenLength = mSCycleLength * mCKijunSenLength; + mSSenkouSpanBLength = mSCycleLength * mCSenkouSpanBLength; + 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; + mMTenkanSenLength = mMCycleLength * mCTenkanSenLength; + mMKijunSenLength = mMCycleLength * mCKijunSenLength; + mMSenkouSpanBLength = mMCycleLength * mCSenkouSpanBLength; + 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; + mLTenkanSenLength = mLCycleLength * mCTenkanSenLength; + mLKijunSenLength = mLCycleLength * mCKijunSenLength; + mLSenkouSpanBLength = mLCycleLength * mCSenkouSpanBLength; + 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; + mHTenkanSenLength = mHCycleLength * mCTenkanSenLength; + mHKijunSenLength = mHCycleLength * mCKijunSenLength; + mHSenkouSpanBLength = mHCycleLength * mCSenkouSpanBLength; + 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; + + // + // Current ... + result = MathMax(mCTenkanSenLength, mCKijunSenLength); + result = MathMax(result, mCSenkouSpanBLength); + + // + // Short ... + result = MathMax(mSTenkanSenLength, mSKijunSenLength); + result = MathMax(result, mSSenkouSpanBLength); + + // + // Medium ... + result = MathMax(mMTenkanSenLength, mMKijunSenLength); + result = MathMax(result, mMSenkouSpanBLength); + + // + // Long ... + result = MathMax(mLTenkanSenLength, mLKijunSenLength); + result = MathMax(result, mLSenkouSpanBLength); + + // + // Hind ... + result = MathMax(mHTenkanSenLength, mHKijunSenLength); + result = MathMax(result, mHSenkouSpanBLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // TENKANSEN ... + + // + bool canCShowTenkanSen = showTenkanSen && showCurrent; + ENUM_DRAW_TYPE cTenkanSenDrawType = canCShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cTenBuffer, true); + SetIndexBuffer(cTenBufferIndex, cTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cTenBufferIndex, PLOT_SHOW_DATA, canCShowTenkanSen); + PlotIndexSetInteger(cTenBufferIndex, PLOT_DRAW_TYPE, cTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canCShowKijunSen = showKijunSen && showCurrent; + ENUM_DRAW_TYPE cKijunSenDrawType = canCShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cKijBuffer, true); + SetIndexBuffer(cKijBufferIndex, cKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cKijBufferIndex, PLOT_SHOW_DATA, canCShowKijunSen); + PlotIndexSetInteger(cKijBufferIndex, PLOT_DRAW_TYPE, cKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canCShowChikouSpan = showChikouSpan && showCurrent; + ENUM_DRAW_TYPE cChikouSpanDrawType = canCShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cChikBuffer, true); + SetIndexBuffer(cChikBufferIndex, cChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cChikBufferIndex, PLOT_SHIFT, -mCKijunSenLength); + PlotIndexSetInteger(cChikBufferIndex, PLOT_SHOW_DATA, canCShowChikouSpan); + PlotIndexSetInteger(cChikBufferIndex, PLOT_DRAW_TYPE, cChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int cShiftSize = shiftKumo ? mCKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canCShowSenkouSpanA = showSenkouSpanA && showCurrent; + ENUM_DRAW_TYPE cSenkouSpanADrawType = canCShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cSSABuffer, true); + SetIndexBuffer(cSSABufferIndex, cSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSABufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cSSABufferIndex, PLOT_SHOW_DATA, canCShowSenkouSpanA); + PlotIndexSetInteger(cSSABufferIndex, PLOT_DRAW_TYPE, cSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canCShowSenkouSpanB = showSenkouSpanB && showCurrent; + ENUM_DRAW_TYPE cSenkouSpanBDrawType = canCShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cSSBBuffer, true); + SetIndexBuffer(cSSBBufferIndex, cSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_SHOW_DATA, canCShowSenkouSpanB); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_DRAW_TYPE, cSenkouSpanBDrawType); + + // + // Short ... + + // + // TENKANSEN ... + + // + bool canSShowTenkanSen = showTenkanSen && showShort; + ENUM_DRAW_TYPE sTenkanSenDrawType = canSShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sTenBuffer, true); + SetIndexBuffer(sTenBufferIndex, sTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sTenBufferIndex, PLOT_SHOW_DATA, canSShowTenkanSen); + PlotIndexSetInteger(sTenBufferIndex, PLOT_DRAW_TYPE, sTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canSShowKijunSen = showKijunSen && showShort; + ENUM_DRAW_TYPE sKijunSenDrawType = canSShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sKijBuffer, true); + SetIndexBuffer(sKijBufferIndex, sKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sKijBufferIndex, PLOT_SHOW_DATA, canSShowKijunSen); + PlotIndexSetInteger(sKijBufferIndex, PLOT_DRAW_TYPE, sKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canSShowChikouSpan = showChikouSpan && showShort; + ENUM_DRAW_TYPE sChikouSpanDrawType = canSShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sChikBuffer, true); + SetIndexBuffer(sChikBufferIndex, sChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sChikBufferIndex, PLOT_SHIFT, -mSKijunSenLength); + PlotIndexSetInteger(sChikBufferIndex, PLOT_SHOW_DATA, canSShowChikouSpan); + PlotIndexSetInteger(sChikBufferIndex, PLOT_DRAW_TYPE, sChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int sShiftSize = shiftKumo ? mSKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canSShowSenkouSpanA = showSenkouSpanA && showShort; + ENUM_DRAW_TYPE sSenkouSpanADrawType = canSShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sSSABuffer, true); + SetIndexBuffer(sSSABufferIndex, sSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSABufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sSSABufferIndex, PLOT_SHOW_DATA, canSShowSenkouSpanA); + PlotIndexSetInteger(sSSABufferIndex, PLOT_DRAW_TYPE, sSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canSShowSenkouSpanB = showSenkouSpanB && showShort; + ENUM_DRAW_TYPE sSenkouSpanBDrawType = canSShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sSSBBuffer, true); + SetIndexBuffer(sSSBBufferIndex, sSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_SHOW_DATA, canSShowSenkouSpanB); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_DRAW_TYPE, sSenkouSpanBDrawType); + + // + // Medium ... + + // + // TENKANSEN ... + + // + bool canMShowTenkanSen = showTenkanSen && showMedium; + ENUM_DRAW_TYPE mTenkanSenDrawType = canMShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mTenBuffer, true); + SetIndexBuffer(mTenBufferIndex, mTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mTenBufferIndex, PLOT_SHOW_DATA, canMShowTenkanSen); + PlotIndexSetInteger(mTenBufferIndex, PLOT_DRAW_TYPE, mTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canMShowKijunSen = showKijunSen && showMedium; + ENUM_DRAW_TYPE mKijunSenDrawType = canMShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mKijBuffer, true); + SetIndexBuffer(mKijBufferIndex, mKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mKijBufferIndex, PLOT_SHOW_DATA, canMShowKijunSen); + PlotIndexSetInteger(mKijBufferIndex, PLOT_DRAW_TYPE, mKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canMShowChikouSpan = showChikouSpan && showMedium; + ENUM_DRAW_TYPE mChikouSpanDrawType = canMShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mChikBuffer, true); + SetIndexBuffer(mChikBufferIndex, mChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mChikBufferIndex, PLOT_SHIFT, -mMKijunSenLength); + PlotIndexSetInteger(mChikBufferIndex, PLOT_SHOW_DATA, canMShowChikouSpan); + PlotIndexSetInteger(mChikBufferIndex, PLOT_DRAW_TYPE, mChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int mShiftSize = shiftKumo ? mMKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canMShowSenkouSpanA = showSenkouSpanA && showMedium; + ENUM_DRAW_TYPE mSenkouSpanADrawType = canMShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mSSABuffer, true); + SetIndexBuffer(mSSABufferIndex, mSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSABufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mSSABufferIndex, PLOT_SHOW_DATA, canMShowSenkouSpanA); + PlotIndexSetInteger(mSSABufferIndex, PLOT_DRAW_TYPE, mSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canMShowSenkouSpanB = showSenkouSpanB && showMedium; + ENUM_DRAW_TYPE mSenkouSpanBDrawType = canMShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mSSBBuffer, true); + SetIndexBuffer(mSSBBufferIndex, mSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_SHOW_DATA, canMShowSenkouSpanB); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_DRAW_TYPE, mSenkouSpanBDrawType); + + // + // Long ... + + // + // TENKANSEN ... + + // + bool canLShowTenkanSen = showTenkanSen && showLong; + ENUM_DRAW_TYPE lTenkanSenDrawType = canLShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lTenBuffer, true); + SetIndexBuffer(lTenBufferIndex, lTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lTenBufferIndex, PLOT_SHOW_DATA, canLShowTenkanSen); + PlotIndexSetInteger(lTenBufferIndex, PLOT_DRAW_TYPE, lTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canLShowKijunSen = showKijunSen && showLong; + ENUM_DRAW_TYPE lKijunSenDrawType = canLShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lKijBuffer, true); + SetIndexBuffer(lKijBufferIndex, lKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lKijBufferIndex, PLOT_SHOW_DATA, canLShowKijunSen); + PlotIndexSetInteger(lKijBufferIndex, PLOT_DRAW_TYPE, lKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canLShowChikouSpan = showChikouSpan && showLong; + ENUM_DRAW_TYPE lChikouSpanDrawType = canLShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lChikBuffer, true); + SetIndexBuffer(lChikBufferIndex, lChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lChikBufferIndex, PLOT_SHIFT, -mLKijunSenLength); + PlotIndexSetInteger(lChikBufferIndex, PLOT_SHOW_DATA, canLShowChikouSpan); + PlotIndexSetInteger(lChikBufferIndex, PLOT_DRAW_TYPE, lChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int lShiftSize = shiftKumo ? mLKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canLShowSenkouSpanA = showSenkouSpanA && showLong; + ENUM_DRAW_TYPE lSenkouSpanADrawType = canLShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lSSABuffer, true); + SetIndexBuffer(lSSABufferIndex, lSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSABufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lSSABufferIndex, PLOT_SHOW_DATA, canLShowSenkouSpanA); + PlotIndexSetInteger(lSSABufferIndex, PLOT_DRAW_TYPE, lSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canLShowSenkouSpanB = showSenkouSpanB && showLong; + ENUM_DRAW_TYPE lSenkouSpanBDrawType = canLShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lSSBBuffer, true); + SetIndexBuffer(lSSBBufferIndex, lSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_SHOW_DATA, canLShowSenkouSpanB); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_DRAW_TYPE, lSenkouSpanBDrawType); + + // + // Hind ... + + // + // TENKANSEN ... + + // + bool canHShowTenkanSen = showTenkanSen && showHind; + ENUM_DRAW_TYPE hTenkanSenDrawType = canHShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hTenBuffer, true); + SetIndexBuffer(hTenBufferIndex, hTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hTenBufferIndex, PLOT_SHOW_DATA, canHShowTenkanSen); + PlotIndexSetInteger(hTenBufferIndex, PLOT_DRAW_TYPE, hTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canHShowKijunSen = showKijunSen && showHind; + ENUM_DRAW_TYPE hKijunSenDrawType = canHShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hKijBuffer, true); + SetIndexBuffer(hKijBufferIndex, hKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hKijBufferIndex, PLOT_SHOW_DATA, canHShowKijunSen); + PlotIndexSetInteger(hKijBufferIndex, PLOT_DRAW_TYPE, hKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canHShowChikouSpan = showChikouSpan && showHind; + ENUM_DRAW_TYPE hChikouSpanDrawType = canHShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hChikBuffer, true); + SetIndexBuffer(hChikBufferIndex, hChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hChikBufferIndex, PLOT_SHIFT, -mHKijunSenLength); + PlotIndexSetInteger(hChikBufferIndex, PLOT_SHOW_DATA, canHShowChikouSpan); + PlotIndexSetInteger(hChikBufferIndex, PLOT_DRAW_TYPE, hChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int hShiftSize = shiftKumo ? mHKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canHShowSenkouSpanA = showSenkouSpanA && showHind; + ENUM_DRAW_TYPE hSenkouSpanADrawType = canHShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hSSABuffer, true); + SetIndexBuffer(hSSABufferIndex, hSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSABufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hSSABufferIndex, PLOT_SHOW_DATA, canHShowSenkouSpanA); + PlotIndexSetInteger(hSSABufferIndex, PLOT_DRAW_TYPE, hSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canHShowSenkouSpanB = showSenkouSpanB && showHind; + ENUM_DRAW_TYPE hSenkouSpanBDrawType = canHShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hSSBBuffer, true); + SetIndexBuffer(hSSBBufferIndex, hSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_SHOW_DATA, canHShowSenkouSpanB); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_DRAW_TYPE, hSenkouSpanBDrawType); + + // + // Here we Create KUMO CLOUD Buffers ... + + // + // int lastBufferIndex = hSSBBufferIndex; + + // + // Current ... + bool cCanShowKumo = showKumo && showCurrent; + ENUM_DRAW_TYPE cKumoDrawType = cCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(cSSAKCBuffer, true); + SetIndexBuffer(cSSAKCBufferIndex, cSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(cSSBKCBuffer, true); + SetIndexBuffer(cSSBKCBufferIndex, cSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(cKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(cKCBufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cKCBufferIndex, PLOT_DRAW_TYPE, cKumoDrawType); + + // + // Short ... + bool sCanShowKumo = showKumo && showShort; + ENUM_DRAW_TYPE sKumoDrawType = sCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(sSSAKCBuffer, true); + SetIndexBuffer(sSSAKCBufferIndex, sSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(sSSBKCBuffer, true); + SetIndexBuffer(sSSBKCBufferIndex, sSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(sKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(sKCBufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sKCBufferIndex, PLOT_DRAW_TYPE, sKumoDrawType); + + // + // Medium ... + bool mCanShowKumo = showKumo && showMedium; + ENUM_DRAW_TYPE mKumoDrawType = mCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(mSSAKCBuffer, true); + SetIndexBuffer(mSSAKCBufferIndex, mSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(mSSBKCBuffer, true); + SetIndexBuffer(mSSBKCBufferIndex, mSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(mKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(mKCBufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mKCBufferIndex, PLOT_DRAW_TYPE, mKumoDrawType); + + // + // Long ... + bool lCanShowKumo = showKumo && showLong; + ENUM_DRAW_TYPE lKumoDrawType = lCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(lSSAKCBuffer, true); + SetIndexBuffer(lSSAKCBufferIndex, lSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(lSSBKCBuffer, true); + SetIndexBuffer(lSSBKCBufferIndex, lSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(lKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(lKCBufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lKCBufferIndex, PLOT_DRAW_TYPE, lKumoDrawType); + + // + // Hind ... + bool hCanShowKumo = showKumo && showHind; + ENUM_DRAW_TYPE hKumoDrawType = hCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(hSSAKCBuffer, true); + SetIndexBuffer(hSSAKCBufferIndex, hSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(hSSBKCBuffer, true); + SetIndexBuffer(hSSBKCBufferIndex, hSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(hKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(hKCBufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hKCBufferIndex, PLOT_DRAW_TYPE, hKumoDrawType); +} + +// +// 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, + // + mCTenkanSenLength, + mCKijunSenLength, + mCSenkouSpanBLength, + // + cTenBuffer, + cKijBuffer, + cChikBuffer, + cSSABuffer, + cSSBBuffer, + cSSAKCBuffer, + cSSBKCBuffer + // + ); + + // + // SHORT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mSTenkanSenLength, + mSKijunSenLength, + mSSenkouSpanBLength, + // + sTenBuffer, + sKijBuffer, + sChikBuffer, + sSSABuffer, + sSSBBuffer, + sSSAKCBuffer, + sSSBKCBuffer + // + ); + + // + // MEDIUM ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mMTenkanSenLength, + mMKijunSenLength, + mMSenkouSpanBLength, + // + mTenBuffer, + mKijBuffer, + mChikBuffer, + mSSABuffer, + mSSBBuffer, + mSSAKCBuffer, + mSSBKCBuffer + // + ); + + // + // LONG ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mLTenkanSenLength, + mLKijunSenLength, + mLSenkouSpanBLength, + // + lTenBuffer, + lKijBuffer, + lChikBuffer, + lSSABuffer, + lSSBBuffer, + lSSAKCBuffer, + lSSBKCBuffer + // + ); + + // + // HIND ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mHTenkanSenLength, + mHKijunSenLength, + mHSenkouSpanBLength, + // + hTenBuffer, + hKijBuffer, + hChikBuffer, + hSSABuffer, + hSSBBuffer, + hSSAKCBuffer, + hSSBKCBuffer + // + ); +} + +// +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 _tenkanSenLength, + int _kijunSenLength, + int _senkouSpanBLength, + // + double &_tenkanSenBuffer[], + double &_kijunSenBuffer[], + double &_chikouSpanBuffer[], + double &_senkouABuffer[], + double &_senkouBBuffer[], + double &_cloudSenkouSpanABuffer[], + double &_cloudSenkouSpanBBuffer[] + // +) +{ + // + double topValue; + double bottomValue; + + // + // TENKANSEN ... + + // + // Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ... + if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL) + { + // + switch (tenkanSenMode) + { + // + case X_XICH_HH_LL_MODE: + // + mTenkanSenTopMode = MODE_HIGH; + mTenkanSenBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mTenkanSenTopMode = MODE_OPEN; + mTenkanSenBottomMode = MODE_CLOSE; + break; + } + } + + // + XOHCL bar; + bar.Init( + _Symbol, + _Period, + bar_index + // + ); + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _tenkanSenLength, + mTenkanSenTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _tenkanSenLength, + mTenkanSenBottomMode + // + ); + + // + double tenkanSenValue = (topValue + bottomValue) / 2; + _tenkanSenBuffer[bar_index] = tenkanSenValue; + + // + // KIJUNSEN ... + + // + // Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ... + if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL) + { + // + switch (kijunSenMode) + { + // + case X_XICH_HH_LL_MODE: + // + mKijunSenTopMode = MODE_HIGH; + mKijunSenBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mKijunSenTopMode = MODE_OPEN; + mKijunSenBottomMode = MODE_CLOSE; + break; + } + } + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _kijunSenLength, + mKijunSenTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _kijunSenLength, + mKijunSenBottomMode + // + ); + + // + double kijunSenValue = (topValue + bottomValue) / 2; + _kijunSenBuffer[bar_index] = kijunSenValue; + + // + // CHIKOUSPAN ... + double chikouSpanValue = bar + .GetPrice(chikuoSpanAppliedTo); + + // + _chikouSpanBuffer[bar_index] = chikouSpanValue; + + // + // KUMO ... + + // + // SENKOUSPANA ... + double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2; + _senkouABuffer[bar_index] = senkouSpanAValue; + _cloudSenkouSpanABuffer[bar_index] = senkouSpanAValue; + + // + // SENKOUSPANB ... + + // + // Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ... + if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL) + { + // + switch (senkouSpanBMode) + { + // + case X_XICH_HH_LL_MODE: + // + mSenkouSpanBTopMode = MODE_HIGH; + mSenkouSpanBBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mSenkouSpanBTopMode = MODE_OPEN; + mSenkouSpanBBottomMode = MODE_CLOSE; + break; + } + } + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _senkouSpanBLength, + mSenkouSpanBTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _senkouSpanBLength, + mSenkouSpanBBottomMode + // + ); + + // + double senkouSpanBValue = (topValue + bottomValue) / 2; + _senkouBBuffer[bar_index] = senkouSpanBValue; + _cloudSenkouSpanBBuffer[bar_index] = senkouSpanBValue; + + // +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchm.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchm.mq5 new file mode 100644 index 00000000..cb3572d2 --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchm.mq5 @@ -0,0 +1,1089 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHM +// Description: XCHMrend 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 XCHM Indicator" +#property strict + +// +#define ShortName "XCHM" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input int fastLength = 9; // Fast Length +input int slowLength = 18; // Slow Length +input ENUM_MA_METHOD method = MODE_SMA; // Mode +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"; + +// +// Parts ... +input bool showFast = true; // Show Fast +input bool showSlow = true; // Show Slow + +// +// AVG ... +input bool showAVG = true; // Show Average + +// +// Cycles ... +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 12 +#property indicator_plots 12 + +// +// AVG ... + +// +// Fast ... +#define avgFastBufferIndex 0 +double avgFastBuffer[]; + +// +#property indicator_label1 "XCHM AF" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Slow ... +#define avgSlowBufferIndex 1 +double avgSlowBuffer[]; + +// +#property indicator_label2 "XCHM AS" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// Current ... + +// +// Fast ... +#define cFastBufferIndex 2 +double cFastBuffer[]; + +// +#property indicator_label3 "XCHM CF" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Slow ... +#define cSlowBufferIndex 3 +double cSlowBuffer[]; + +// +#property indicator_label4 "XCHM CS" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrMagenta +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Short ... + +// +// Fast ... +#define sFastBufferIndex 4 +double sFastBuffer[]; + +// +#property indicator_label5 "XCHM SF" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrAqua +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Slow ... +#define sSlowBufferIndex 5 +double sSlowBuffer[]; + +// +#property indicator_label6 "XCHM SS" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrMagenta +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Medium ... + +// +// Fast ... +#define mFastBufferIndex 6 +double mFastBuffer[]; + +// +#property indicator_label7 "XCHM MF" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrAqua +#property indicator_style7 STYLE_DOT +#property indicator_width7 1 + +// +// Slow ... +#define mSlowBufferIndex 7 +double mSlowBuffer[]; + +// +#property indicator_label8 "XCHM MS" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrMagenta +#property indicator_style8 STYLE_DOT +#property indicator_width8 1 + +// +// Long ... + +// +// Fast ... +#define lFastBufferIndex 8 +double lFastBuffer[]; + +// +#property indicator_label9 "XCHM LF" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrAqua +#property indicator_style9 STYLE_DOT +#property indicator_width9 1 + +// +// Slow ... +#define lSlowBufferIndex 9 +double lSlowBuffer[]; + +// +#property indicator_label10 "XCHM LS" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrMagenta +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +// +// Hind ... + +// +// Fast ... +#define hFastBufferIndex 10 +double hFastBuffer[]; + +// +#property indicator_label11 "XCHM HF" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAqua +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +// Slow ... +#define hSlowBufferIndex 11 +double hSlowBuffer[]; + +// +#property indicator_label12 "XCHM HS" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrMagenta +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +// Variables ... + +// +int maxLength; + +// +// Current ... +int cFastHandler = INVALID_HANDLE; +int cSlowHandler = INVALID_HANDLE; + +// +// Short ... +int mSCLength = 0; +int mSCFastLength = 0; +int mSCSlowLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +int sFastHandler = INVALID_HANDLE; +int sSlowHandler = INVALID_HANDLE; + +// +// Medium ... +int mMCLength = 0; +int mMCFastLength = 0; +int mMCSlowLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +int mFastHandler = INVALID_HANDLE; +int mSlowHandler = INVALID_HANDLE; + +// +// Long ... +int mLCLength = 0; +int mLCFastLength = 0; +int mLCSlowLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +int lFastHandler = INVALID_HANDLE; +int lSlowHandler = INVALID_HANDLE; + +// +// Hind ... +int mHCLength = 0; +int mHCFastLength = 0; +int mHCSlowLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +int hFastHandler = INVALID_HANDLE; +int hSlowHandler = INVALID_HANDLE; + +// +// 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 + + // + // Current ... + IndicatorRelease(cFastHandler); + IndicatorRelease(cSlowHandler); + + // + // Short ... + IndicatorRelease(sFastHandler); + IndicatorRelease(sSlowHandler); + + // + // Medium ... + IndicatorRelease(mFastHandler); + IndicatorRelease(mSlowHandler); + + // + // Long ... + IndicatorRelease(lFastHandler); + IndicatorRelease(lSlowHandler); + + // + // Hind ... + IndicatorRelease(hFastHandler); + IndicatorRelease(hSlowHandler); +} + +// +// 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); + + // + // this counts Available Bars ... + int limit; + + // + // Validate Calculated Bars ... + bool isPassedRequiredCalculatedBars = + // + // Current ... + BarsCalculated(cFastHandler) >= maxLength && + BarsCalculated(cSlowHandler) >= maxLength && + // + // Short ... + BarsCalculated(sFastHandler) >= maxLength && + BarsCalculated(sSlowHandler) >= maxLength && + // + // Medium ... + BarsCalculated(mFastHandler) >= maxLength && + BarsCalculated(mSlowHandler) >= maxLength && + // + // Long ... + BarsCalculated(lFastHandler) >= maxLength && + BarsCalculated(lSlowHandler) >= maxLength && + // + // Hind ... + BarsCalculated(hFastHandler) >= maxLength && + BarsCalculated(hSlowHandler) >= maxLength + // + ; + if (!isPassedRequiredCalculatedBars) + { + return prev_calculated; + } + + // + limit = + (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Buffers Copy ... + + // + // Current ... + int copiedCFasts = CopyBuffer(cFastHandler, 0, 0, limit, cFastBuffer); + int copiedCSlows = CopyBuffer(cSlowHandler, 0, 0, limit, cSlowBuffer); + + // + // Short ... + int copiedSFasts = CopyBuffer(sFastHandler, 0, 0, limit, sFastBuffer); + int copiedSSlows = CopyBuffer(sSlowHandler, 0, 0, limit, sSlowBuffer); + + // + // Medium ... + int copiedMFasts = CopyBuffer(mFastHandler, 0, 0, limit, mFastBuffer); + int copiedMSlows = CopyBuffer(mSlowHandler, 0, 0, limit, mSlowBuffer); + + // + // Long ... + int copiedLFasts = CopyBuffer(lFastHandler, 0, 0, limit, lFastBuffer); + int copiedLSlows = CopyBuffer(lSlowHandler, 0, 0, limit, lSlowBuffer); + + // + // Hind ... + int copiedHFasts = CopyBuffer(hFastHandler, 0, 0, limit, hFastBuffer); + int copiedHSlows = CopyBuffer(hSlowHandler, 0, 0, limit, hSlowBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // + // Current ... + copiedCFasts > 0 && + copiedCSlows > 0 && + // + // Short ... + copiedSFasts > 0 && + copiedSSlows > 0 && + // + // Medium ... + copiedMFasts > 0 && + copiedMSlows > 0 && + // + // Long ... + copiedLFasts > 0 && + copiedLSlows > 0 && + // + // Hind ... + copiedHFasts > 0 && + copiedHSlows > 0 + // + ; + if (!isPassedRequiredCopiedItems) + { + return prev_calculated; + } + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// CUSTOM Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + fastLength > 2 && + slowLength > fastLength && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(fastLength, slowLength); + + // + // Short ... + result = MathMax(result, mSCFastLength); + result = MathMax(result, mSCSlowLength); + + // + // Medium ... + result = MathMax(result, mMCFastLength); + result = MathMax(result, mMCSlowLength); + + // + // Long ... + result = MathMax(result, mLCFastLength); + result = MathMax(result, mLCSlowLength); + + // + // Hind ... + result = MathMax(result, mHCFastLength); + result = MathMax(result, mHCSlowLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // AVG ... + + // + // Fast ... + bool canShowAVGFast = showAVG && showFast; + ENUM_DRAW_TYPE avgFastDrawType = canShowAVGFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgFastBuffer, true); + SetIndexBuffer(avgFastBufferIndex, avgFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_SHOW_DATA, canShowAVGFast); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_TYPE, avgFastDrawType); + + // + // Slow ... + bool canShowAVGSlow = showAVG && showSlow; + ENUM_DRAW_TYPE avgSlowDrawType = canShowAVGSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgSlowBuffer, true); + SetIndexBuffer(avgSlowBufferIndex, avgSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_SHOW_DATA, canShowAVGSlow); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_TYPE, avgSlowDrawType); + + // + // Current ... + + // + // Fast ... + bool canShowCFast = showCurrent && showFast; + ENUM_DRAW_TYPE cFastDrawType = canShowCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cFastBuffer, true); + SetIndexBuffer(cFastBufferIndex, cFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cFastBufferIndex, PLOT_SHOW_DATA, canShowCFast); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_TYPE, cFastDrawType); + + // + // Slow ... + bool canShowCSlow = showCurrent && showSlow; + ENUM_DRAW_TYPE cSlowDrawType = canShowCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cSlowBuffer, true); + SetIndexBuffer(cSlowBufferIndex, cSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_SHOW_DATA, canShowCSlow); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_TYPE, cSlowDrawType); + + // + // Short ... + + // + // Fast ... + bool canShowSFast = showShort && showFast; + ENUM_DRAW_TYPE sFastDrawType = canShowSFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sFastBuffer, true); + SetIndexBuffer(sFastBufferIndex, sFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sFastBufferIndex, PLOT_SHOW_DATA, canShowSFast); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_TYPE, sFastDrawType); + + // + // Slow ... + bool canShowSSlow = showShort && showSlow; + ENUM_DRAW_TYPE sSlowDrawType = canShowSSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sSlowBuffer, true); + SetIndexBuffer(sSlowBufferIndex, sSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_SHOW_DATA, canShowSSlow); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_TYPE, sSlowDrawType); + + // + // Medium ... + + // + // Fast ... + bool canShowMFast = showMedium && showFast; + ENUM_DRAW_TYPE mFastDrawType = canShowMFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mFastBuffer, true); + SetIndexBuffer(mFastBufferIndex, mFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mFastBufferIndex, PLOT_SHOW_DATA, canShowMFast); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_TYPE, mFastDrawType); + + // + // Slow ... + bool canShowMSlow = showMedium && showSlow; + ENUM_DRAW_TYPE mSlowDrawType = canShowMSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mSlowBuffer, true); + SetIndexBuffer(mSlowBufferIndex, mSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_SHOW_DATA, canShowMSlow); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_TYPE, mSlowDrawType); + + // + // Long ... + + // + // Fast ... + bool canShowLFast = showLong && showFast; + ENUM_DRAW_TYPE lFastDrawType = canShowLFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lFastBuffer, true); + SetIndexBuffer(lFastBufferIndex, lFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lFastBufferIndex, PLOT_SHOW_DATA, canShowLFast); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_TYPE, lFastDrawType); + + // + // Slow ... + bool canShowLSlow = showLong && showSlow; + ENUM_DRAW_TYPE lSlowDrawType = canShowLSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lSlowBuffer, true); + SetIndexBuffer(lSlowBufferIndex, lSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_SHOW_DATA, canShowLSlow); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_TYPE, lSlowDrawType); + + // + // Hind ... + + // + // Fast ... + bool canShowHFast = showHind && showFast; + ENUM_DRAW_TYPE hFastDrawType = canShowHFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hFastBuffer, true); + SetIndexBuffer(hFastBufferIndex, hFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hFastBufferIndex, PLOT_SHOW_DATA, canShowHFast); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_TYPE, hFastDrawType); + + // + // Slow ... + bool canShowHSlow = showHind && showSlow; + ENUM_DRAW_TYPE hSlowDrawType = canShowHSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hSlowBuffer, true); + SetIndexBuffer(hSlowBufferIndex, hSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_SHOW_DATA, canShowHSlow); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_TYPE, hSlowDrawType); +} + +// +// Initial Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Initialize Handlers ... + cFastHandler = iMA( + _Symbol, + _Period, + fastLength, + 0, + method, + appliedTo // + ); + cSlowHandler = iMA( + _Symbol, + _Period, + slowLength, + 0, + method, + appliedTo // + ); + result = + // + cFastHandler != INVALID_HANDLE && + cSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // 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; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSCFastLength = fastLength * mSCLength; + mSCSlowLength = slowLength * mSCLength; + + // + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + sFastHandler = iMA( + _Symbol, + _Period, + mSCFastLength, + 0, + method, + appliedTo // + ); + sSlowHandler = iMA( + _Symbol, + _Period, + mSCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + sFastHandler != INVALID_HANDLE && + sSlowHandler != INVALID_HANDLE + // + ; + 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; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMCFastLength = fastLength * mMCLength; + mMCSlowLength = slowLength * mMCLength; + + // + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + mFastHandler = iMA( + _Symbol, + _Period, + mMCFastLength, + 0, + method, + appliedTo // + ); + mSlowHandler = iMA( + _Symbol, + _Period, + mMCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + mFastHandler != INVALID_HANDLE && + mSlowHandler != INVALID_HANDLE + // + ; + 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; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLCFastLength = fastLength * mLCLength; + mLCSlowLength = slowLength * mLCLength; + + // + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + lFastHandler = iMA( + _Symbol, + _Period, + mLCFastLength, + 0, + method, + appliedTo // + ); + lSlowHandler = iMA( + _Symbol, + _Period, + mLCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + lFastHandler != INVALID_HANDLE && + lSlowHandler != INVALID_HANDLE + // + ; + 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; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHCFastLength = fastLength * mHCLength; + mHCSlowLength = slowLength * mHCLength; + + // + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + hFastHandler = iMA( + _Symbol, + _Period, + mHCFastLength, + 0, + method, + appliedTo // + ); + hSlowHandler = iMA( + _Symbol, + _Period, + mHCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + hFastHandler != INVALID_HANDLE && + hSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Do all Custom Calculations ... +void CalculateBuffers(int barIndex) +{ + // + double cFast = cFastBuffer[barIndex]; + double sFast = sFastBuffer[barIndex]; + double mFast = mFastBuffer[barIndex]; + double lFast = lFastBuffer[barIndex]; + double hFast = hFastBuffer[barIndex]; + + // + double fast = + cFast + + sFast + + mFast + + lFast + + hFast; + avgFastBuffer[barIndex] = fast / 5; + + // + double cSlow = cSlowBuffer[barIndex]; + double sSlow = sSlowBuffer[barIndex]; + double mSlow = mSlowBuffer[barIndex]; + double lSlow = lSlowBuffer[barIndex]; + double hSlow = hSlowBuffer[barIndex]; + + // + double slow = + cSlow + + sSlow + + mSlow + + lSlow + + hSlow; + avgSlowBuffer[barIndex] = slow / 5; +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchstr.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchstr.mq5 new file mode 100644 index 00000000..b67b000c --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchstr.mq5 @@ -0,0 +1,1246 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHSTR +// Description: Smoothed HikenAshi 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 XCHSTR Indicator" +#property strict + +// +#define ShortName "XCHSTR" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; + +// +input int atrLength = 14; // Length +input double atrMultiplier = 3.0; // Multiplier +input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // 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 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 35 +#property indicator_plots 10 + +// +// Current ... + +// +#define cBufferIndex 0 +#define cPlotBufferIndex 0 +double cBuffer[]; + +// +#define cColorBufferIndex 1 +double cColorBuffer[]; + +// +#property indicator_label1 "C XSTR" +#property indicator_type1 DRAW_COLOR_LINE +#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style1 STYLE_DOT + +// +// Short ... + +// +#define sBufferIndex 2 +#define sPlotBufferIndex 1 +double sBuffer[]; + +// +#define sColorBufferIndex 3 +double sColorBuffer[]; + +// +#property indicator_label2 "S XSTR" +#property indicator_type2 DRAW_COLOR_LINE +#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style2 STYLE_DOT + +// +// Medium ... + +// +#define mBufferIndex 4 +#define mPlotBufferIndex 2 +double mBuffer[]; + +// +#define mColorBufferIndex 5 +double mColorBuffer[]; + +// +#property indicator_label3 "M XSTR" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style3 STYLE_DOT + +// +// Long ... + +// +#define lBufferIndex 6 +#define lPlotBufferIndex 3 +double lBuffer[]; + +// +#define lColorBufferIndex 7 +double lColorBuffer[]; + +// +#property indicator_label4 "L XSTR" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style4 STYLE_DOT + +// +// Hind ... + +// +#define hBufferIndex 8 +#define hPlotBufferIndex 4 +double hBuffer[]; + +// +#define hColorBufferIndex 9 +double hColorBuffer[]; + +// +#property indicator_label5 "H XSTR" +#property indicator_type5 DRAW_COLOR_LINE +#property indicator_color5 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style5 STYLE_DOT + +// +// Data Buffers ... + +// +// Current ... + +// +#define cAtrBufferIndex 10 +double cAtrBuffer[]; + +// +#define cTrendBufferIndex 11 +double cTrendBuffer[]; + +// +#define cUpBufferIndex 12 +double cUpBuffer[]; + +// +#define cDownBufferIndex 13 +double cDownBuffer[]; + +// +#define cPriceBufferIndex 14 +double cPriceBuffer[]; + +// +// Short ... + +// +#define sAtrBufferIndex 15 +double sAtrBuffer[]; + +// +#define sTrendBufferIndex 16 +double sTrendBuffer[]; + +// +#define sUpBufferIndex 17 +double sUpBuffer[]; + +// +#define sDownBufferIndex 18 +double sDownBuffer[]; + +// +#define sPriceBufferIndex 19 +double sPriceBuffer[]; + +// +// Medium ... + +// +#define mAtrBufferIndex 20 +double mAtrBuffer[]; + +// +#define mTrendBufferIndex 21 +double mTrendBuffer[]; + +// +#define mUpBufferIndex 22 +double mUpBuffer[]; + +// +#define mDownBufferIndex 23 +double mDownBuffer[]; + +// +#define mPriceBufferIndex 24 +double mPriceBuffer[]; + +// +// Long ... + +// +#define lAtrBufferIndex 25 +double lAtrBuffer[]; + +// +#define lTrendBufferIndex 26 +double lTrendBuffer[]; + +// +#define lUpBufferIndex 27 +double lUpBuffer[]; + +// +#define lDownBufferIndex 28 +double lDownBuffer[]; + +// +#define lPriceBufferIndex 29 +double lPriceBuffer[]; + +// +// Hind ... + +// +#define hAtrBufferIndex 30 +double hAtrBuffer[]; + +// +#define hTrendBufferIndex 31 +double hTrendBuffer[]; + +// +#define hUpBufferIndex 32 +double hUpBuffer[]; + +// +#define hDownBufferIndex 33 +double hDownBuffer[]; + +// +#define hPriceBufferIndex 34 +double hPriceBuffer[]; + +// +// Variables, Properties and etc ... + +// +int changeOfTrend; +int startBearishTrend; +int startBullishTrend; + +// +int maxLength; + +// +// Current ... +int mCSMLength = atrLength; +int mCAtrHandler = INVALID_HANDLE; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +int mSAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +int mMAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +int mLAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +int mHAtrHandler = INVALID_HANDLE; +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 ... +) +{ + // + int numOfRequiredAtrs; + if (prev_calculated > rates_total || prev_calculated < 0) + { + numOfRequiredAtrs = rates_total; + } + else + { + // + numOfRequiredAtrs = rates_total - prev_calculated; + if (prev_calculated > 0) + { + numOfRequiredAtrs++; + } + } + + // + // Checking for stop ... + if (IsStopped()) + { + return 0; + } + + // + // Check Number of items Copy or not ... + int copiedCATRs = CopyBuffer(mCAtrHandler, 0, 0, numOfRequiredAtrs, cAtrBuffer); + int copiedSATRs = CopyBuffer(mSAtrHandler, 0, 0, numOfRequiredAtrs, sAtrBuffer); + int copiedMATRs = CopyBuffer(mMAtrHandler, 0, 0, numOfRequiredAtrs, mAtrBuffer); + int copiedLATRs = CopyBuffer(mLAtrHandler, 0, 0, numOfRequiredAtrs, lAtrBuffer); + int copiedHATRs = CopyBuffer(mHAtrHandler, 0, 0, numOfRequiredAtrs, hAtrBuffer); + if (copiedCATRs <= 0 || + copiedSATRs <= 0 || + copiedMATRs <= 0 || + copiedLATRs <= 0 || + copiedHATRs <= 0) + { + return 0; + } + + // + int limit; + + // + // checking for the limit start of calculation of an indicator ... + if (prev_calculated > rates_total || prev_calculated <= 0) + { + // + // starting index for calculation of all bars ... + limit = maxLength; + } + else + { + // + // starting number for calculation of new bars + limit = prev_calculated - 1; + } + + // + // Main Loop ... + for (int i = limit; i < rates_total && !IsStopped(); i++) + { + // + CalculateBuffers( + open, + high, + low, + close, + i // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + atrLength >= 2 && + atrMultiplier > 0 && + // + (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); + + // + mCAtrHandler = iATR( + _Symbol, + _Period, + mCSMLength // + ); + result = mCAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // 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; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + mSAtrHandler = iATR( + _Symbol, + _Period, + mSSMLength // + ); + result = mSAtrHandler != INVALID_HANDLE; + 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; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + mMAtrHandler = iATR( + _Symbol, + _Period, + mMSMLength // + ); + result = mMAtrHandler != INVALID_HANDLE; + 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; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + mLAtrHandler = iATR( + _Symbol, + _Period, + mLSMLength // + ); + result = mLAtrHandler != INVALID_HANDLE; + 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; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + mHAtrHandler = iATR( + _Symbol, + _Period, + mHSMLength // + ); + result = mHAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // CURRENT Cycle ... + + // + // STR ... + SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(cPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(cAtrBufferIndex, cAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(cPriceBufferIndex, cPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(cTrendBufferIndex, cTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(cUpBufferIndex, cUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(cDownBufferIndex, cDownBuffer, INDICATOR_CALCULATIONS); + + // + // SHORT Cycle ... + + // + // STR ... + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(sPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(sAtrBufferIndex, sAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(sPriceBufferIndex, sPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(sTrendBufferIndex, sTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(sUpBufferIndex, sUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(sDownBufferIndex, sDownBuffer, INDICATOR_CALCULATIONS); + + // + // MEDIUM Cycle ... + + // + // STR ... + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(mPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(mAtrBufferIndex, mAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(mPriceBufferIndex, mPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(mTrendBufferIndex, mTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(mUpBufferIndex, mUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(mDownBufferIndex, mDownBuffer, INDICATOR_CALCULATIONS); + + // + // LONG Cycle ... + + // + // STR ... + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(lPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(lAtrBufferIndex, lAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(lPriceBufferIndex, lPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(lTrendBufferIndex, lTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(lUpBufferIndex, lUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(lDownBufferIndex, lDownBuffer, INDICATOR_CALCULATIONS); + + // + // HIND Cycle ... + + // + // STR ... + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(hPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(hAtrBufferIndex, hAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(hPriceBufferIndex, hPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(hTrendBufferIndex, hTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(hUpBufferIndex, hUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(hDownBufferIndex, hDownBuffer, INDICATOR_CALCULATIONS); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Hiken Ashi ... +void CalculateBuffers( + const double &open[], + const double &high[], + const double &low[], + const double &close[], + int barIndex // +) +{ + // + // Current ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + cAtrBuffer, + cPriceBuffer, + cUpBuffer, + cDownBuffer, + cTrendBuffer, + cBuffer, + cColorBuffer, + showCurrent // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + sAtrBuffer, + sPriceBuffer, + sUpBuffer, + sDownBuffer, + sTrendBuffer, + sBuffer, + sColorBuffer, + showShort // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + mAtrBuffer, + mPriceBuffer, + mUpBuffer, + mDownBuffer, + mTrendBuffer, + mBuffer, + mColorBuffer, + showMedium // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + lAtrBuffer, + lPriceBuffer, + lUpBuffer, + lDownBuffer, + lTrendBuffer, + lBuffer, + lColorBuffer, + showLong // + ); + + // + // Hind ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + hAtrBuffer, + hPriceBuffer, + hUpBuffer, + hDownBuffer, + hTrendBuffer, + hBuffer, + hColorBuffer, + showHind // + ); +} + +// +void CalculateCycle( + const double &open[], + const double &high[], + const double &low[], + const double &close[], + int barIndex, + double &atr[], + double &price[], + double &up[], + double &down[], + double &trend[], + double &main[], + double &clr[], // Color Index Buffer + bool show // +) +{ + // + // Calculated Price ... + double _price = getPrice( + atrAppliedTo, + open, + high, + low, + close, + barIndex // + ); + price[barIndex] = _price; + + // + double _atr = atr[barIndex]; + + // + // Up ... + up[barIndex] = _price + (atrMultiplier * _atr); + + // + // Down ... + down[barIndex] = _price - (atrMultiplier * _atr); + + // + if (close[barIndex] > up[barIndex - 1]) + { + // + trend[barIndex] = 1; + if (trend[barIndex - 1] == -1) + { + changeOfTrend = 1; + } + } + else if (close[barIndex] < down[barIndex - 1]) + { + // + trend[barIndex] = -1; + if (trend[barIndex - 1] == 1) + { + changeOfTrend = 1; + } + } + else if (trend[barIndex - 1] == 1) + { + // + trend[barIndex] = 1; + changeOfTrend = 0; + } + else if (trend[barIndex - 1] == -1) + { + // + trend[barIndex] = -1; + changeOfTrend = 0; + } + + // + // Down Trend Starting ... + if (trend[barIndex] < 0 && trend[barIndex - 1] > 0) + { + startBearishTrend = 1; + } + else + { + startBearishTrend = 0; + } + + // + // Up Trend Starting ... + if (trend[barIndex] > 0 && trend[barIndex - 1] < 0) + { + startBullishTrend = 1; + } + else + { + startBullishTrend = 0; + } + + // + if (trend[barIndex] > 0 && down[barIndex] < down[barIndex - 1]) + { + down[barIndex] = down[barIndex - 1]; + } + + // + if (trend[barIndex] < 0 && up[barIndex] > up[barIndex - 1]) + { + up[barIndex] = up[barIndex - 1]; + } + + // + if (startBearishTrend == 1) + { + up[barIndex] = price[barIndex] + (atrMultiplier * _atr); + } + + // + if (startBullishTrend == 1) + { + down[barIndex] = price[barIndex] - (atrMultiplier * _atr); + } + + // + double colorIDX = hideColorIDX; + clr[barIndex] = colorIDX; + + // + if (trend[barIndex] == 1) + { + // + main[barIndex] = down[barIndex]; + if (changeOfTrend == 1) + { + // + main[barIndex - 1] = main[barIndex - 2]; + changeOfTrend = 0; + } + + // + colorIDX = bullishColorIDX; + } + else if (trend[barIndex] == -1) + { + // + main[barIndex] = up[barIndex]; + if (changeOfTrend == 1) + { + // + main[barIndex - 1] = main[barIndex - 2]; + changeOfTrend = 0; + } + + // + colorIDX = bearishColorIDX; + } + + // + if (show) + { + clr[barIndex] = colorIDX; + } + + // +} + +// +// TEMPLATE Function ... + +template +double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i) +{ + switch (tprice) + { + case PRICE_CLOSE: + return (close[i]); + case PRICE_OPEN: + return (open[i]); + case PRICE_HIGH: + return (high[i]); + case PRICE_LOW: + return (low[i]); + case PRICE_MEDIAN: + return ((high[i] + low[i]) / 2.0); + case PRICE_TYPICAL: + return ((high[i] + low[i] + close[i]) / 3.0); + case PRICE_WEIGHTED: + return ((high[i] + low[i] + close[i] + close[i]) / 4.0); + } + return (0); +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchswings.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchswings.mq5 new file mode 100644 index 00000000..15c5c4ff --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchswings.mq5 @@ -0,0 +1,993 @@ +/////////////////////////////////////////////////////// +// 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]; + } + } +} \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchtd.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchtd.mq5 new file mode 100644 index 00000000..86ec2b54 --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchtd.mq5 @@ -0,0 +1,900 @@ +/////////////////////////////////////////////////////// +// 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; + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchvlm.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchvlm.mq5 new file mode 100644 index 00000000..dd1105e9 --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchvlm.mq5 @@ -0,0 +1,814 @@ +/////////////////////////////////////////////////////// +// 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 +#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; +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchvwap.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchvwap.mq5 new file mode 100644 index 00000000..b98fafcf --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xchvwap.mq5 @@ -0,0 +1,830 @@ +/////////////////////////////////////////////////////// +// 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; + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xct.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xct.mq5 new file mode 100644 index 00000000..92fbb28b --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xct.mq5 @@ -0,0 +1,270 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// --------------------------------------------- +// Name: XCT +// Description: Trend Magic Indicator ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCT Indicator" +#property strict + +// +// START Constants ... +// + +// +#define ShortName "XCT" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// END Constants ... +// + +// +// START Inputs ... +// + +// +input color clr = clrYellow; // Text Color +input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position + +// +input group "Presentation"; +input bool showCandleTime = true; // Show Candle Time + +// +// END Inputs ... +// + +// +// START Buffers ... +// + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + +// +// END Buffers ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// + +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// START Event Handlers ... +// + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (showCandleTime) + { + CreateIndicatorObject(); + } + else + { + ObjectDelete(0, ShortName); + } + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + 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 (!showCandleTime) + { + return rates_total; + } + + // + ulong chID = FindChartID( + _Symbol, + _Period + // + ); + + // + XBarRemainsTime barRemains; + barRemains.Init( + _Symbol, + _Period + // + ); + + // + string msg = barRemains + .ToString( + "", + "", + "", + "", + "", + ":", + true + // + ); + + // + long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD); + + // + string _sp = ""; + if (mSpread < 10) + _sp = ".."; + else if (mSpread < 100) + _sp = "."; + + // + // int offset = TimeGMTOffset(); + // string timeString = + // ", Time: " + string(TimeCurrent()) + "\n" + + // ", ServerTime: " + string(TimeTradeServer()) + "\n" + + // ", GMT Offset: " + (string)offset; + // timeString = timeString; + // Comment(timeString); + + // + string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg; + + // + ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr); + ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText); + ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10); + ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier"); + + // + return rates_total; +} + +// +// END Event Handlers ... +// + +// +// START Functions ... +// + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +void CreateIndicatorObject() +{ + // + if (!showCandleTime) + { + return; + } + + // + ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0); + ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner); + ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10); + ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2); + + // + ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER; + switch (corner) + { + case CORNER_LEFT_UPPER: + Anchor = ANCHOR_LEFT_UPPER; + break; + case CORNER_RIGHT_UPPER: + Anchor = ANCHOR_RIGHT_UPPER; + break; + case CORNER_LEFT_LOWER: + Anchor = ANCHOR_LEFT_LOWER; + break; + case CORNER_RIGHT_LOWER: + Anchor = ANCHOR_RIGHT_LOWER; + break; + } + + // + ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor); +} + +// +// END Functions ... +// diff --git a/Documents/BKP/14030802-X121/Indicators/x-saherelm.xpv.mq5 b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xpv.mq5 new file mode 100644 index 00000000..e15924df --- /dev/null +++ b/Documents/BKP/14030802-X121/Indicators/x-saherelm.xpv.mq5 @@ -0,0 +1,1289 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XPV +// Description: Peaks and Vales ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XPV Indicator" +#property strict + +// +// Definitions ... + +// +#define ShortName "XPV" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Makret 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 + +// +input group "Fibonacci"; +input double fiboLevel1 = 0.236; // Fibio 1st Level +input double fiboLevel2 = 0.382; // Fibio 2st Level +input double fiboLevel3 = 0.5; // Fibio 3rd Level +input double fiboLevel4 = 0.618; // Fibio 4th Level +input double fiboLevel5 = 0.764; // Fibio 5th Level + +// +input group "Boundary Detection Modes"; +input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method +input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method + +// +input group "Presentation"; +input bool showPeaksAndVales = true; // Show Peaks and Vales +input bool showLevels = false; // Show Levels +input bool showConsolidations = false; // Show Consolidations +input bool showFibo1Levels = false; // Show Fibo 1st Level +input bool showFibo2Levels = false; // Show Fibo 2nd Level +input bool showFibo3Levels = false; // Show Fibo 3rd Level +input bool showFibo4Levels = false; // Show Fibo 4th Level +input bool showFibo5Levels = false; // Show Fibo 5th Level + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 32 +#property indicator_plots 32 + +// +// PEAKS ... + +// +#define peaksBufferIndex 0 +double peaksBuffer[]; + +// +#property indicator_label1 "XPV PEAKS" +#property indicator_type1 DRAW_ARROW +#property indicator_color1 clrAqua +#property indicator_width1 1 + +// +// VALES ... + +// +#define valesBufferIndex 1 +double valesBuffer[]; + +// +#property indicator_label2 "XPV VALES" +#property indicator_type2 DRAW_ARROW +#property indicator_color2 clrMagenta +#property indicator_width2 1 + +// +#define rBufferIndex 2 +double rBuffer[]; + +// +#define rColorBufferIndex 3 +double rColorBuffer[]; + +// +#property indicator_label3 "XPV R" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +#define sBufferIndex 4 +#define sBufferPlotIndex 3 +double sBuffer[]; + +// +#define sColorBufferIndex 5 +double sColorBuffer[]; + +// +#property indicator_label4 "XPV S" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrMagenta +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// FIBBO Level 1 ... + +// +#define fl1BufferIndex 6 +#define fl1BufferPlotIndex 4 +double fl1Buffer[]; + +// +#define fl1ColorBufferIndex 7 +double fl1ColorBuffer[]; + +// +#property indicator_label5 "XPV FL1" +#property indicator_type5 DRAW_COLOR_LINE +#property indicator_color5 CLR_NONE, clrGold +#property indicator_style5 STYLE_DASHDOTDOT +#property indicator_width5 1 + +// +// FIBBO Level 2 ... + +// +#define fl2BufferIndex 8 +#define fl2BufferPlotIndex 5 +double fl2Buffer[]; + +// +#define fl2ColorBufferIndex 9 +double fl2ColorBuffer[]; + +// +#property indicator_label6 "XPV FL2" +#property indicator_type6 DRAW_COLOR_LINE +#property indicator_color6 CLR_NONE, clrGold +#property indicator_style6 STYLE_DASHDOTDOT +#property indicator_width6 1 + +// +// FIBBO Level 3 ... + +// +#define fl3BufferIndex 10 +#define fl3BufferPlotIndex 6 +double fl3Buffer[]; + +// +#define fl3ColorBufferIndex 11 +double fl3ColorBuffer[]; + +// +#property indicator_label7 "XPV FL3" +#property indicator_type7 DRAW_COLOR_LINE +#property indicator_color7 CLR_NONE, clrGold +#property indicator_style7 STYLE_DASHDOTDOT +#property indicator_width7 1 + +// +// FIBBO Level 4 ... + +// +#define fl4BufferIndex 12 +#define fl4BufferPlotIndex 7 +double fl4Buffer[]; + +// +#define fl4ColorBufferIndex 13 +double fl4ColorBuffer[]; + +// +#property indicator_label8 "XPV FL4" +#property indicator_type8 DRAW_COLOR_LINE +#property indicator_color8 CLR_NONE, clrGold +#property indicator_style8 STYLE_DASHDOTDOT +#property indicator_width8 1 + +// +// FIBBO Level 5 ... + +// +#define fl5BufferIndex 14 +#define fl5BufferPlotIndex 8 +double fl5Buffer[]; + +// +#define fl5ColorBufferIndex 15 +double fl5ColorBuffer[]; + +// +#property indicator_label9 "XPV FL5" +#property indicator_type9 DRAW_COLOR_LINE +#property indicator_color9 CLR_NONE, clrGold +#property indicator_style9 STYLE_DASHDOTDOT +#property indicator_width9 1 + +// +// LEVELS ... + +// +#define scHHBufferIndex 16 +#define scHHBufferPlotIndex 9 +double scHHBuffer[]; + +// +#define scHHColorBufferIndex 17 +double scHHColorBuffer[]; + +// +#property indicator_label10 "XPV SHH" +#property indicator_type10 DRAW_COLOR_LINE +#property indicator_color10 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +#define scLLBufferIndex 18 +#define scLLBufferPlotIndex 10 +double scLLBuffer[]; + +// +#define scLLColorBufferIndex 19 +double scLLColorBuffer[]; + +// +#property indicator_label11 "XPV SLL" +#property indicator_type11 DRAW_COLOR_LINE +#property indicator_color11 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +#define mcHHBufferIndex 20 +#define mcHHBufferPlotIndex 11 +double mcHHBuffer[]; + +// +#define mcHHColorBufferIndex 21 +double mcHHColorBuffer[]; + +// +#property indicator_label12 "XPV MHH" +#property indicator_type12 DRAW_COLOR_LINE +#property indicator_color12 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +#define mcLLBufferIndex 22 +#define mcLLBufferPlotIndex 12 +double mcLLBuffer[]; + +// +#define mcLLColorBufferIndex 23 +double mcLLColorBuffer[]; + +// +#property indicator_label13 "XPV MLL" +#property indicator_type13 DRAW_COLOR_LINE +#property indicator_color13 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style13 STYLE_DOT +#property indicator_width13 1 + +// +#define lcHHBufferIndex 24 +#define lcHHBufferPlotIndex 13 +double lcHHBuffer[]; + +// +#define lcHHColorBufferIndex 25 +double lcHHColorBuffer[]; + +// +#property indicator_label14 "XPV LHH" +#property indicator_type14 DRAW_COLOR_LINE +#property indicator_color14 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style14 STYLE_DOT +#property indicator_width14 1 + +// +#define lcLLBufferIndex 26 +#define lcLLBufferPlotIndex 14 +double lcLLBuffer[]; + +// +#define lcLLColorBufferIndex 27 +double lcLLColorBuffer[]; + +// +#property indicator_label15 "XPV LLL" +#property indicator_type15 DRAW_COLOR_LINE +#property indicator_color15 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style15 STYLE_DOT +#property indicator_width15 1 + +// +#define hcHHBufferIndex 28 +#define hcHHBufferPlotIndex 15 +double hcHHBuffer[]; + +// +#define hcHHColorBufferIndex 29 +double hcHHColorBuffer[]; + +// +#property indicator_label16 "XPV HHH" +#property indicator_type16 DRAW_COLOR_LINE +#property indicator_color16 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style16 STYLE_DOT +#property indicator_width16 1 + +// +#define hcLLBufferIndex 30 +#define hcLLBufferPlotIndex 16 +double hcLLBuffer[]; + +// +#define hcLLColorBufferIndex 31 +double hcLLColorBuffer[]; + +// +#property indicator_label17 "XPV HLL" +#property indicator_type17 DRAW_COLOR_LINE +#property indicator_color17 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style17 STYLE_DOT +#property indicator_width17 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +double mHideColorIDX = 0; + +// +// XMarketCycle sc; +int mSCLength = 0; +double mLastSCHH = 0; +double mLastSCLL = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// XMarketCycle mc; +int mMCLength = 0; +double mLastMCHH = 0; +double mLastMCLL = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// XMarketCycle lc; +int mLCLength = 0; +double mLastLCHH = 0; +double mLastLCLL = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// XMarketCycle hc; +int mHCLength = 0; +double mLastHCHH = 0; +double mLastHCLL = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +double lastPeak = 0; +double lastVale = 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 ... + // +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // this counts Available Bars ... + int limit; + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mSCLength, mMCLength); + result = MathMax(result, mLCLength); + result = MathMax(result, mHCLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // PEAKS and VALES ... + ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; + + // + // PEAKS ... + ArraySetAsSeries(peaksBuffer, true); + SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA); + PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225); + PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); + PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + // VALES ... + ArraySetAsSeries(valesBuffer, true); + SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA); + PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225); + PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); + PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + // SUPPORT and RESISTANCE ... + // + + // + // RESISTANCE ... + ArraySetAsSeries(rBuffer, true); + SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA); + PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // RESISTANCE Color ... + ArraySetAsSeries(rColorBuffer, true); + SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX); + + // + // SUPPORT ... + ArraySetAsSeries(sBuffer, true); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false); + + // + // SUPPORT Color ... + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // FIBBO Levels ... + + // + // LEVEL 1 ... + + // + // Buffer ... + ArraySetAsSeries(fl1Buffer, true); + SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_SHOW_DATA, showFibo1Levels); + + // + // Color ... + ArraySetAsSeries(fl1ColorBuffer, true); + SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 2 ... + + // + // Buffer ... + ArraySetAsSeries(fl2Buffer, true); + SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_SHOW_DATA, showFibo2Levels); + + // + // Color ... + ArraySetAsSeries(fl2ColorBuffer, true); + SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 3 ... + + // + // Buffer ... + ArraySetAsSeries(fl3Buffer, true); + SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_SHOW_DATA, showFibo3Levels); + + // + // Color ... + ArraySetAsSeries(fl3ColorBuffer, true); + SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 4 ... + + // + // Buffer ... + ArraySetAsSeries(fl4Buffer, true); + SetIndexBuffer(fl4BufferIndex, fl4Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_SHOW_DATA, showFibo4Levels); + + // + // Color ... + ArraySetAsSeries(fl4ColorBuffer, true); + SetIndexBuffer(fl4ColorBufferIndex, fl4ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 5 ... + + // + // Buffer ... + ArraySetAsSeries(fl5Buffer, true); + SetIndexBuffer(fl5BufferIndex, fl5Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_SHOW_DATA, showFibo5Levels); + + // + // Color ... + ArraySetAsSeries(fl5ColorBuffer, true); + SetIndexBuffer(fl5ColorBufferIndex, fl5ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // SHORT Buffers ... + + // + // HIGH ... + ArraySetAsSeries(scHHBuffer, true); + SetIndexBuffer(scHHBufferIndex, scHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(scHHColorBuffer, true); + SetIndexBuffer(scHHColorBufferIndex, scHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(scLLBuffer, true); + SetIndexBuffer(scLLBufferIndex, scLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(scLLColorBuffer, true); + SetIndexBuffer(scLLColorBufferIndex, scLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // MEDIUM Buffer ... + + // + // HIGH ... + ArraySetAsSeries(mcHHBuffer, true); + SetIndexBuffer(mcHHBufferIndex, mcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(mcHHColorBuffer, true); + SetIndexBuffer(mcHHColorBufferIndex, mcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(mcLLBuffer, true); + SetIndexBuffer(mcLLBufferIndex, mcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(mcLLColorBuffer, true); + SetIndexBuffer(mcLLColorBufferIndex, mcLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LONG Buffer ... + + // + // HIGH ... + ArraySetAsSeries(lcHHBuffer, true); + SetIndexBuffer(lcHHBufferIndex, lcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(lcHHColorBuffer, true); + SetIndexBuffer(lcHHColorBufferIndex, lcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(lcLLBuffer, true); + SetIndexBuffer(lcLLBufferIndex, lcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(lcLLColorBuffer, true); + SetIndexBuffer(lcLLColorBufferIndex, lcLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // HIND Buffer ... + + // + // HIGH ... + ArraySetAsSeries(hcHHBuffer, true); + SetIndexBuffer(hcHHBufferIndex, hcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(hcHHColorBuffer, true); + SetIndexBuffer(hcHHColorBufferIndex, hcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(hcLLBuffer, true); + SetIndexBuffer(hcLLBufferIndex, hcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(hcLLColorBuffer, true); + SetIndexBuffer(hcLLColorBufferIndex, hcLLColorBuffer, INDICATOR_COLOR_INDEX); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index // Selected Bar Index +) +{ + // + // Calculate Cycles ... + CalculateCycles(bar_index); + + // + // Calculate Peaks and Vales ... + CalculatePeaksAndVales(bar_index); + + // + // Calculate Fibonnaci ... + CalculateFibonacci(bar_index); +} + +// +// Custom ... + +// +// Initial Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + if (IsValid(mSCPeriod)) + { + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + if (IsValid(mMCPeriod)) + { + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + if (IsValid(mLCPeriod)) + { + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + if (IsValid(mHCPeriod)) + { + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + } + + // + result = mSCLength > 0 && + mMCLength > mSCLength && + mLCLength > mMCLength && + mHCLength > mLCLength; + + // + return result; +} + +// +// Calculate Specified Cycles HH and LL ... +void CalculateCycle( + int barIndex, + ENUM_X_MARKET_CYCLES cycle, + double &lastHH, + double &hhBuffer[], + double &hhColorBuffer[], + double &lastLL, + double &llBuffer[], + double &llColorBuffer[] // +) +{ + // + XOHCL bar; + bar.Init( + _Symbol, + _Period, + barIndex + // + ); + + // + int mLength = 0; + switch (cycle) + { + // + case X_MARKET_CYCLE_SHORT: + mLength = mSCLength; + break; + + // + case X_MARKET_CYCLE_MEDIUM: + mLength = mMCLength; + break; + + // + case X_MARKET_CYCLE_LONG: + mLength = mLCLength; + break; + + // + case X_MARKET_CYCLE_HIND: + mLength = mHCLength; + break; + } + + // + if (mLength <= 0) + { + return; + } + + // + double hhValue = bar.FindHighest( + mLength, + hhMode + // + ); + hhBuffer[barIndex] = hhValue; + + // + double hhColorIDX = + !showLevels + ? mHideColorIDX + : (hhValue == lastHH) + ? !showConsolidations + ? mHideColorIDX + : 1 + : hhValue > lastHH + ? 2 + : hhValue < lastHH + ? 3 + : mHideColorIDX; + hhColorBuffer[barIndex] = hhColorIDX; + + // + lastHH = hhValue; + + // + double llValue = bar.FindLowest( + mLength, + llMode + // + ); + llBuffer[barIndex] = llValue; + + // + double llColorIDX = + !showLevels + ? mHideColorIDX + : (llValue == lastLL) + ? !showConsolidations + ? mHideColorIDX + : 1 + : llValue > lastLL + ? 2 + : llValue < lastLL + ? 3 + : mHideColorIDX; + llColorBuffer[barIndex] = llColorIDX; + + // + lastLL = llValue; +} + +// +// Calculate Cycles Up and Down Boundaries ... +void CalculateCycles( + int barIndex // Bar Index +) +{ + // + // Short ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_SHORT, + // + mLastSCHH, + scHHBuffer, + scHHColorBuffer, + // + mLastSCLL, + scLLBuffer, + scLLColorBuffer + // + ); + + // + // Medium ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_MEDIUM, + // + mLastMCHH, + mcHHBuffer, + mcHHColorBuffer, + // + mLastMCLL, + mcLLBuffer, + mcLLColorBuffer + // + ); + + // + // Long ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_LONG, + // + mLastLCHH, + lcHHBuffer, + lcHHColorBuffer, + // + mLastLCLL, + lcLLBuffer, + lcLLColorBuffer + // + ); + + // + // Hind ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_HIND, + // + mLastHCHH, + hcHHBuffer, + hcHHColorBuffer, + // + mLastHCLL, + hcLLBuffer, + hcLLColorBuffer + // + ); +} + +// +// Calculate Peaks and Values ... +void CalculatePeaksAndVales( + int barIndex // Bar Index +) +{ + // + // Retrieve Requirements ... + + // + // Short ... + double scHHValue = scHHBuffer[barIndex]; + double scLLValue = scLLBuffer[barIndex]; + + // + // Medium ... + double mcHHValue = mcHHBuffer[barIndex]; + double mcLLValue = mcLLBuffer[barIndex]; + + // + // Long ... + double lcHHValue = lcHHBuffer[barIndex]; + double lcLLValue = lcLLBuffer[barIndex]; + + // + // Hind ... + double hcHHValue = hcHHBuffer[barIndex]; + double hcLLValue = hcLLBuffer[barIndex]; + + // + double rColorIDX = mHideColorIDX; + double sColorIDX = mHideColorIDX; + + // + // RESISTANCE ... + double rValue = (scHHValue + mcHHValue + lcHHValue + hcHHValue) / 4; + + // + // PEAKS ... + bool isPeak = rValue == hcHHValue && + hcHHValue == lcHHValue && + lcHHValue == mcHHValue && + mcHHValue == scHHValue; + + // + if (isPeak && lastPeak != rValue) + { + // + rColorIDX = 1; + lastPeak = rValue; + } + + // + // SUPPORT ... + double sValue = (scLLValue + mcLLValue + lcLLValue + hcLLValue) / 4; + + // + // VALES ... + bool isVale = sValue == hcLLValue && + hcLLValue == lcLLValue && + lcLLValue == mcLLValue && + mcLLValue == scLLValue; + + // + if (isVale && lastVale != sValue) + { + // + sColorIDX = 1; + + // + lastVale = sValue; + } + + // + rBuffer[barIndex] = rValue; + sBuffer[barIndex] = sValue; + peaksBuffer[barIndex] = lastPeak; + valesBuffer[barIndex] = lastVale; + + // + if (showPeaksAndVales) + { + // + rColorBuffer[barIndex] = rColorIDX; + sColorBuffer[barIndex] = sColorIDX; + } + else + { + // + rColorBuffer[barIndex] = mHideColorIDX; + sColorBuffer[barIndex] = mHideColorIDX; + } +} + +// +// Calculate Fibonacci Level 1 ... +void CalculateFibonacci( + int barIndex // Bar Index +) +{ + // + // Select Requirements ... + double upPrice = peaksBuffer[barIndex]; + double downPrice = valesBuffer[barIndex]; + + // + // Level 1 ... + double fibLevel1Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel1, + 1); + // + // Level 2 ... + double fibLevel2Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel2, + 1); + + // + // Level 3 ... + double fibLevel3Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel3, + 1); + + // + // Level 4 ... + double fibLevel4Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel4, + 1); + + // + // Level 5 ... + double fibLevel5Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel5, + 1); + + // + fl1Buffer[barIndex] = fibLevel1Value; + fl2Buffer[barIndex] = fibLevel2Value; + fl3Buffer[barIndex] = fibLevel3Value; + fl4Buffer[barIndex] = fibLevel4Value; + fl5Buffer[barIndex] = fibLevel5Value; + + // + double fl1ColorIdx = showFibo1Levels ? 1 : mHideColorIDX; + double fl2ColorIdx = showFibo2Levels ? 1 : mHideColorIDX; + double fl3ColorIdx = showFibo3Levels ? 1 : mHideColorIDX; + double fl4ColorIdx = showFibo4Levels ? 1 : mHideColorIDX; + double fl5ColorIdx = showFibo5Levels ? 1 : mHideColorIDX; + + // + fl1ColorBuffer[barIndex] = fl1ColorIdx; + fl2ColorBuffer[barIndex] = fl2ColorIdx; + fl3ColorBuffer[barIndex] = fl3ColorIdx; + fl4ColorBuffer[barIndex] = fl4ColorIdx; + fl5ColorBuffer[barIndex] = fl5ColorIdx; +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Libraries/x-saherelm.common.lib.mq5 b/Documents/BKP/14030802-X121/Libraries/x-saherelm.common.lib.mq5 new file mode 100644 index 00000000..0dd9620f --- /dev/null +++ b/Documents/BKP/14030802-X121/Libraries/x-saherelm.common.lib.mq5 @@ -0,0 +1,12750 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Common Library +// -------------------------------------- +// Name: XCommonLib +// Description: provide all commonly used functions ... +// +// +// 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 "../Classes/x-saherelm.xmd5.class.mq5" + +// +// Models ... + +// +// Specified Price Type ... +enum ENUM_X_PRICE +{ + X_PRICE_HIGH, + X_PRICE_OPEN, + X_PRICE_CLOSE, + X_PRICE_LOW +}; + +// +// Swing Types Enum ... +enum ENUM_X_SWING_TYPE +{ + X_NO_SWING = 0, + X_SWING_HIGH = 1, + X_SWING_LOW = -1, +}; + +// +ENUM_SERIESMODE ToSeriesMode(ENUM_X_SWING_TYPE value) +{ + // + ENUM_SERIESMODE result = MODE_HIGH; + + // + switch (value) + { + // + case X_SWING_HIGH: + result = MODE_HIGH; + break; + + // + case X_SWING_LOW: + result = MODE_LOW; + break; + } + + // + return result; +} + +// +// Find Swing Points ... +int FindSwing( + string mSymbol, // Trading Symbol ... + ENUM_TIMEFRAMES mPeriod, // Trading Period ... + ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ... + int mLength, // Loopback ... + int bar_index // BarIndex ... +) +{ + // + int result = -1; + + // + if (StringLen(mSymbol) == 0 || (mMode != X_SWING_HIGH && mMode != X_SWING_LOW)) + { + return result; + } + + // + int current = bar_index; + int founded = FindNextSwing( + mSymbol, + mPeriod, + mMode, + (mLength * 2) + 1, + current - mLength); + + // + while (founded != current) + { + // + current = FindNextSwing( + mSymbol, + mPeriod, + mMode, + mLength, + current + 1); + + // + founded = FindNextSwing( + mSymbol, + mPeriod, + mMode, + (mLength * 2) + 1, + current - mLength); + } + + // + result = current; + + // + return result; +} + +// +// Find Next Swing ... +int FindNextSwing( + string mSymbol, // Trading Symbol ... + ENUM_TIMEFRAMES mPeriod, // Trading Period ... + ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ... + int mLength, // Loopback ... + int bar_index // BarIndex ... +) +{ + // + int result = -1; + + // + if (bar_index < 0) + { + mLength += bar_index; + bar_index = 0; + } + + // + ENUM_SERIESMODE mSeriesMode = ToSeriesMode(mMode); + + // + result = mMode == X_SWING_HIGH + ? iHighest( + mSymbol, + mPeriod, + mSeriesMode, + mLength, + bar_index) + : iLowest( + mSymbol, + mPeriod, + mSeriesMode, + mLength, + bar_index); + + // + return result; +} + +// +// XPERIOD Calculation Method ... +enum ENUM_X_PERIOD_METHOD +{ + // + X_PERIOD_NOTHING, // Nothing + X_PERIOD_AUTO, // Auto Select + X_PERIOD_MANUALLY // Manually +}; + +// +// Available Market Cycles ... +enum ENUM_X_MARKET_CYCLES +{ + // + X_MARKET_CYCLE_UNKNOWN, // Unknown Cycle + X_MARKET_CYCLE_SHORT, // Short Cycle + X_MARKET_CYCLE_MEDIUM, // Medium Cycle + X_MARKET_CYCLE_LONG, // Long Cycle + X_MARKET_CYCLE_HIND, // Hind Cycle +}; + +// +// Structs ... + +// +// Model a Bar Remains Time ... +struct XBarRemainsTime +{ + // + int days; + int hours; + int minutes; + int seconds; + + // + // Constructor ... + XBarRemainsTime() + { + Clean(); + } + + // + // Always Calculate Current 0 Bar Timing ... + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL // Trading Period + ) + { + // + bool result = false; + + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + int minuteSecoonds = 60; + int hourSeconds = minuteSecoonds * 60; + int daySeconds = 24 * hourSeconds; + + // + int periodSeconds = PeriodSeconds( + mPeriod); + datetime startTime = GetBarTime( + mSymbol, + mPeriod, + 0 + // + ); + + // + int secondsDiff = (int)startTime + periodSeconds - (int)TimeCurrent(); + + // + int mWorkingSecondsDiff = secondsDiff; + if (mWorkingSecondsDiff > daySeconds) + { + // + days = mWorkingSecondsDiff / daySeconds; + mWorkingSecondsDiff -= days * daySeconds; + } + if (mWorkingSecondsDiff > hourSeconds) + { + // + hours = mWorkingSecondsDiff / hourSeconds; + mWorkingSecondsDiff -= hours * hourSeconds; + } + if (mWorkingSecondsDiff > minuteSecoonds) + { + // + minutes = mWorkingSecondsDiff / minuteSecoonds; + mWorkingSecondsDiff -= minutes * minuteSecoonds; + } + seconds = mWorkingSecondsDiff; + + // + result = true; + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + days = 0; + hours = 0; + minutes = 0; + seconds = 0; + } + + // + // To String Representation ... + string ToString( + string dayId = "d", + string hourId = "h", + string minuteId = "m", + string secondId = "s", + string idSeparator = ": ", + string separator = ", ", + bool ignoreZeroValues = true + // + ) + { + // + string result = ""; + + // + // Days ... + if (!ignoreZeroValues || days > 0) + { + result += dayId + idSeparator + (string)days + separator; + } + + // + // Hours ... + if (!ignoreZeroValues || hours > 0) + { + // + string strHour = ToString(hours); + if (StringLen(strHour) == 1) + { + strHour = "0" + strHour; + } + + // + result += hourId + idSeparator + strHour + separator; + } + + // + // Minutes ... + if (!ignoreZeroValues || minutes > 0) + { + // + string strMinute = ToString(minutes); + if (StringLen(strMinute) == 1) + { + strMinute = "0" + strMinute; + } + + // + result += minuteId + idSeparator + strMinute + separator; + } + + // + // Seconds ... + if (!ignoreZeroValues || seconds > 0) + { + // + string strSec = ToString(seconds); + if (StringLen(strSec) == 1) + { + strSec = "0" + strSec; + } + + // + result += secondId + idSeparator + strSec; + } + + // + return result; + } +}; + +// +// Describe an Specific Candle ... +struct XOHCL +{ + // + // Props ... + + // + double high; + double open; + double close; + double low; + + // + string symbol; + datetime time; + ENUM_TIMEFRAMES period; + + // + // Constructor ... + XOHCL() + { + Clean(); + } + + // + // Init a Bar ... + // Using Bar Index ... + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period + int barIndex = 0 // Bar Index + ) + { + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + symbol = mSymbol; + period = mPeriod; + + // + time = iTime( + mSymbol, + mPeriod, + barIndex + // + ); + + // + open = iOpen( + mSymbol, + mPeriod, + barIndex + // + ); + + // + close = iClose( + mSymbol, + mPeriod, + barIndex + // + ); + + // + high = iHigh( + mSymbol, + mPeriod, + barIndex); + + // + low = iLow( + mSymbol, + mPeriod, + barIndex + // + ); + + // + bool result = IsValid(); + + // + return result; + } + + // + // Init a Bar ... + // Using Bar Time ... + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period + datetime mTime = NULL // Bar Time + ) + { + // + mTime = NormalizeTime(mTime); + + // + int barIndex = iBarShift( + mSymbol, + mPeriod, + mTime, + false // + ); + + // + bool result = Init( + mSymbol, + mPeriod, + barIndex + // + ); + + // + return result; + } + + // + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period + double mOpen = 0, // Open + double mHigh = 0, // High + double mClose = 0, // Close + double mLow = 0, // Low + int barIndex = 0 // Bar Index + ) + { + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + symbol = mSymbol; + period = mPeriod; + + // + time = iTime( + mSymbol, + mPeriod, + barIndex + // + ); + + // + open = mOpen; + high = mHigh; + close = mClose; + low = mLow; + + // + return IsValid(); + } + + // + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period + double mOpen = 0, // Open + double mHigh = 0, // High + double mClose = 0, // Close + double mLow = 0, // Low + datetime mTime = NULL // Bar Time + ) + { + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + symbol = mSymbol; + period = mPeriod; + + // + int barIndex = iBarShift( + symbol, + period, + mTime); + + // + time = iTime( + mSymbol, + mPeriod, + barIndex + // + ); + + // + open = mOpen; + high = mHigh; + close = mClose; + low = mLow; + + // + return IsValid(); + } + + // + // Tools ... + + // + void Clean() + { + // + high = 0; + open = 0; + close = 0; + low = 0; + + // + time = NULL; + symbol = NULL; + period = NULL; + } + + // + // Validate Bar ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + high > 0 && + open > 0 && + close > 0 && + low > 0 + // + ; + + // + return result; + } + + // + int TotalBars() + { + // + int result = 0; + + // + result = iBars( + symbol, + period // + ); + + // + return result; + } + + // + // Calculate X_PRICE Specified Type ... + double GetPrice(ENUM_X_PRICE mPType) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + switch (mPType) + { + // + case X_PRICE_OPEN: + result = open; + break; + // + case X_PRICE_HIGH: + result = high; + break; + // + case X_PRICE_CLOSE: + result = close; + break; + // + case X_PRICE_LOW: + result = low; + break; + } + + // + return result; + } + + // + // Retrieve Price base On Series Mode ... + double GetPrice(ENUM_SERIESMODE mMode) + { + // + ENUM_X_PRICE mXMode = ToPrice(mMode); + + // + return GetPrice(mXMode); + } + + // + // Calculate Applied Price ... + double GetPrice( + ENUM_APPLIED_PRICE mAppliedTo // Select Application Method + ) + { + // + double result = 0; + + // + // Calculate Applied Price ... + switch (mAppliedTo) + { + // + case PRICE_CLOSE: + result = close; + break; + + // + case PRICE_OPEN: + result = open; + break; + + // + case PRICE_HIGH: + result = high; + break; + + // + case PRICE_LOW: + result = low; + break; + + // + case PRICE_MEDIAN: + result = (high + low) / 2; + break; + + // + case PRICE_TYPICAL: + result = (high + low + close) / 3; + break; + + // + case PRICE_WEIGHTED: + result = (high + low + close + close) / 4; + break; + } + + // + return result; + } + + // + // Find Specific Price ... + bool FindHigherPriceBar( + XOHCL &bar, + double price, + ENUM_X_PRICE _type = X_PRICE_HIGH // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int totalBars = TotalBars(); + result = IsValidSize(totalBars); + if (!result) + { + return result; + } + + // + int start = Index(); + int maxAllowedLoopback = totalBars / 5; + for (int i = start; i < maxAllowedLoopback; i++) + { + // + result = bar.Init( + symbol, + period, + i // + ); + + // + if (!result) + { + break; + } + + // + double iPrice = bar.GetPrice(_type); + + // + result = + // + iPrice > 0 && + iPrice > price + // + ; + if (result) + { + break; + } + } + + // + if (!result) + { + bar.Clean(); + } + + // + return result; + } + + // + // Find Specific Price ... + bool FindLowerPriceBar( + XOHCL &bar, + double price, + ENUM_X_PRICE _type = X_PRICE_HIGH // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int totalBars = TotalBars(); + result = IsValidSize(totalBars); + if (!result) + { + return result; + } + + // + int start = Index(); + int maxAllowedLoopback = totalBars / 5; + for (int i = start; i < maxAllowedLoopback; i++) + { + // + result = bar.Init( + symbol, + period, + i // + ); + + // + if (!result) + { + break; + } + + // + double iPrice = bar.GetPrice(_type); + + // + result = + // + iPrice > 0 && + iPrice < price + // + ; + if (result) + { + break; + } + } + + // + if (!result) + { + bar.Clean(); + } + + // + return result; + } + + // + // Calculate Bar Mid Line ... + double GetMid() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = (high + low) / 2; + + // + return result; + } + + // + // Calculate up Price ... + double GetUp() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = MathMax(open, close); + + // + return result; + } + + // + // Calculate Down Price ... + double GetDown() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = MathMin(open, close); + + // + return result; + } + + // + // Calculate Bar Body ... + double GetBody() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetUp() - GetDown(); + + // + return result; + } + + // + // Calculate Bar Range ... + double GetRange() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = high - low; + + // + return result; + } + + // + // Calculate Bar Shadows ... + double GetShadows() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetRange() - GetBody(); + + // + return result; + } + + // + // Calculate Bar High Shadow ... + double GetHighShadow() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = + // + high - GetUp() + // + ; + + // + return result; + } + + // + // Calculate Bar Low Shadow ... + double GetLowShadow() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = + // + GetDown() - low; + // + ; + + // + return result; + } + + // + // Check Bar is Bullish ... + bool IsBullish() + { + // + bool result = false; + + // + if (!IsValid()) + { + return result; + } + + // + result = open < close; + + // + return result; + } + + // + // Check Bar is Bearish ... + bool IsBearish() + { + // + bool result = false; + + // + if (!IsValid()) + { + return result; + } + + // + result = open > close; + + // + return result; + } + + // + // Find Next Bar Time ... + datetime NextAt() + { + // + datetime result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + int prSeconds = PeriodSeconds(period); + + // + result = time + prSeconds; + + // + return result; + } + + // + // Find Prev Bar Time ... + datetime BeforeOn() + { + // + datetime result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + int prSeconds = PeriodSeconds(period); + + // + result = time - prSeconds; + + // + return result; + } + + // + // Calculate Last Bar Open Time in Smaller Period ... + datetime GetLastBarTimeOfPeriod( + ENUM_TIMEFRAMES smallerPeriod // + ) + { + // + datetime result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + int sourceSeconds = PeriodSeconds(period); + int destSeconds = PeriodSeconds(smallerPeriod); + if (destSeconds >= sourceSeconds) + { + return result; + } + + // + result = (datetime)((((int)time) + sourceSeconds) - destSeconds); + + // + return result; + } + + // + // Calculate Close Time ... + datetime GetCloseTime() + { + // + datetime result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + int seconds = PeriodSeconds(period); + + // + result = (datetime)(((int)time) + seconds); + + // + return result; + } + + // + // Find Current Bar Index on Chart ... + int Index() + { + // + int result = -1; + + // + if (!IsValid()) + { + return result; + } + + // + result = iBarShift( + symbol, + period, + time + // + ); + + // + return result; + } + + // + bool GetNextBar(XOHCL &bar) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int idx = Index(); + result = idx > 0; + if (!result) + { + return result; + } + + // + result = bar.Init( + this.symbol, + this.period, + idx - 1 // + ); + + // + if (!result) + { + bar.Clean(); + } + + // + return result; + } + + // + bool GetPreviousBar(XOHCL &bar) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int idx = Index(); + + // + result = bar.Init( + this.symbol, + this.period, + idx + 1 // + ); + + // + if (!result) + { + bar.Clean(); + } + + // + return result; + } + + // + bool IsStrong( + double percent = 50 // Percent of Body + ) + { + // + bool result = false; + + // + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + result = + (GetRange() * percent) / 100 <= GetBody(); + + // + return result; + } + + // + bool HasStrongLowShadow( + double percent = 50, // Percent of Body + int __loopback = 2, + double _sharpRatio = 2.5 // + ) + { + // + bool result = false; + + // + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + result = + (GetRange() * percent) / 100 <= GetLowShadow(); + if (!result) + { + return result; + } + + // + if (__loopback < 0) + { + __loopback = 2; + } + + // + if (_sharpRatio < 0) + { + _sharpRatio = 2.5; + } + + // + result = Index() > __loopback; + if (!result) + { + return result; + } + + // + // Get Highest High and Lowest Low in loopback Range ... + int startIndex = Index() - __loopback; + int endIndex = Index() + __loopback; + int requiredBars = MathAbs(endIndex - startIndex); + + // + // Highs ... + double highs[]; + int copiedHighs = CopyHigh( + symbol, + period, + startIndex, + requiredBars, + highs // + ); + + // + result = copiedHighs == requiredBars; + if (!result) + { + return result; + } + + // + int highestHighIDX = ArrayMaximum(highs); + result = IsValidIndex(highestHighIDX); + if (!result) + { + return result; + } + + // + double highestHigh = highs[highestHighIDX]; + + // + // Lows ... + double lows[]; + int copiedLows = CopyLow( + symbol, + period, + startIndex, + requiredBars, + lows // + ); + + // + result = copiedLows == requiredBars; + if (!result) + { + return result; + } + + // + int lowestLowIDX = ArrayMinimum(lows); + result = IsValidIndex(lowestLowIDX); + if (!result) + { + return result; + } + + // + double lowestLow = lows[lowestLowIDX]; + + // + result = low == lowestLow && + highestHigh > high; + if (!result) + { + return result; + } + + // + // Try to Validate Sharp Ratio ... + + // + Clean(highs); + Clean(lows); + + // + // Left Side ... + startIndex = Index() + 1; + endIndex = startIndex + (__loopback / 2) - 1; + requiredBars = MathAbs(endIndex - startIndex); + + // + copiedHighs = CopyHigh( + symbol, + period, + startIndex, + requiredBars, + highs // + ); + result = copiedHighs == requiredBars; + if (!result) + { + return result; + } + + // + highestHighIDX = ArrayMaximum(highs); + result = IsValidIndex(highestHighIDX); + if (!result) + { + return result; + } + + // + highestHigh = highs[highestHighIDX]; + + // + copiedLows = CopyLow( + symbol, + period, + startIndex, + requiredBars, + lows // + ); + result = copiedLows == requiredBars; + if (!result) + { + return result; + } + + // + lowestLowIDX = ArrayMinimum(lows); + result = IsValidIndex(lowestLowIDX); + if (!result) + { + return result; + } + + // + lowestLow = lows[lowestLowIDX]; + + // + double leftDiff = highestHigh - lowestLow; + + // + Clean(highs); + Clean(lows); + + // + // Right Side ... + startIndex = Index() - 1; + endIndex = startIndex - (__loopback / 2) + 1; + requiredBars = MathAbs(endIndex - startIndex); + + // + copiedHighs = CopyHigh( + symbol, + period, + startIndex, + requiredBars, + highs // + ); + result = copiedHighs == requiredBars; + if (!result) + { + return result; + } + + // + highestHighIDX = ArrayMaximum(highs); + result = IsValidIndex(highestHighIDX); + if (!result) + { + return result; + } + + // + highestHigh = highs[highestHighIDX]; + + // + copiedLows = CopyLow( + symbol, + period, + startIndex, + requiredBars, + lows // + ); + result = copiedLows == requiredBars; + if (!result) + { + return result; + } + + // + lowestLowIDX = ArrayMinimum(lows); + result = IsValidIndex(lowestLowIDX); + if (!result) + { + return result; + } + + // + lowestLow = lows[lowestLowIDX]; + + // + double rightDiff = highestHigh - lowestLow; + double diff = MathMax(leftDiff, rightDiff); + result = GetLowShadow() >= (diff / 100) * _sharpRatio; + + // + return result; + } + + // + bool HasStrongHighShadow( + double percent = 50, // Percent of Body + int __loopback = 2, + double _sharpRatio = 2.5 // + ) + { + // + bool result = false; + + // + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + result = + (GetRange() * percent) / 100 <= GetHighShadow(); + if (!result) + { + return result; + } + + // + if (__loopback < 0) + { + __loopback = 2; + } + + // + if (_sharpRatio < 0) + { + _sharpRatio = 2.5; + } + + // + result = Index() > __loopback; + if (!result) + { + return result; + } + + // + // Get Highest High and Lowest Low in loopback Range ... + int startIndex = Index() - __loopback; + int endIndex = Index() + __loopback; + int requiredBars = MathAbs(endIndex - startIndex); + + // + // Highs ... + double highs[]; + int copiedHighs = CopyHigh( + symbol, + period, + startIndex, + requiredBars, + highs // + ); + + // + result = copiedHighs == requiredBars; + if (!result) + { + return result; + } + + // + int highestHighIDX = ArrayMaximum(highs); + result = IsValidIndex(highestHighIDX); + if (!result) + { + return result; + } + + // + double highestHigh = highs[highestHighIDX]; + + // + // Lows ... + double lows[]; + int copiedLows = CopyLow( + symbol, + period, + startIndex, + requiredBars, + lows // + ); + + // + result = copiedLows == requiredBars; + if (!result) + { + return result; + } + + // + int lowestLowIDX = ArrayMinimum(lows); + result = IsValidIndex(lowestLowIDX); + if (!result) + { + return result; + } + + // + double lowestLow = lows[lowestLowIDX]; + + // + result = high == highestHigh && + lowestLow < low; + if (!result) + { + return result; + } + + // + // Try to Validate Sharp Ratio ... + + // + Clean(highs); + Clean(lows); + + // + // Left Side ... + startIndex = Index() + 1; + endIndex = startIndex + (__loopback / 2) - 1; + requiredBars = MathAbs(endIndex - startIndex); + + // + copiedHighs = CopyHigh( + symbol, + period, + startIndex, + requiredBars, + highs // + ); + result = copiedHighs == requiredBars; + if (!result) + { + return result; + } + + // + highestHighIDX = ArrayMaximum(highs); + result = IsValidIndex(highestHighIDX); + if (!result) + { + return result; + } + + // + highestHigh = highs[highestHighIDX]; + + // + copiedLows = CopyLow( + symbol, + period, + startIndex, + requiredBars, + lows // + ); + result = copiedLows == requiredBars; + if (!result) + { + return result; + } + + // + lowestLowIDX = ArrayMinimum(lows); + result = IsValidIndex(lowestLowIDX); + if (!result) + { + return result; + } + + // + lowestLow = lows[lowestLowIDX]; + + // + double leftDiff = highestHigh - lowestLow; + + // + Clean(highs); + Clean(lows); + + // + // Right Side ... + startIndex = Index() - 1; + endIndex = startIndex - (__loopback / 2) + 1; + requiredBars = MathAbs(endIndex - startIndex); + + // + copiedHighs = CopyHigh( + symbol, + period, + startIndex, + requiredBars, + highs // + ); + result = copiedHighs == requiredBars; + if (!result) + { + return result; + } + + // + highestHighIDX = ArrayMaximum(highs); + result = IsValidIndex(highestHighIDX); + if (!result) + { + return result; + } + + // + highestHigh = highs[highestHighIDX]; + + // + copiedLows = CopyLow( + symbol, + period, + startIndex, + requiredBars, + lows // + ); + result = copiedLows == requiredBars; + if (!result) + { + return result; + } + + // + lowestLowIDX = ArrayMinimum(lows); + result = IsValidIndex(lowestLowIDX); + if (!result) + { + return result; + } + + // + lowestLow = lows[lowestLowIDX]; + + // + double rightDiff = highestHigh - lowestLow; + double diff = MathMax(leftDiff, rightDiff); + result = GetHighShadow() >= (diff / 100) * _sharpRatio; + + // + return result; + } + + // + bool IsStrongBullish( + double percent = 50 // Percent of Body + ) + { + // + bool result = false; + + // + result = + IsStrong(percent) && IsBullish(); + + // + return result; + } + + // + bool IsStrongBearish( + double percent = 50 // Percent of Body + ) + { + // + bool result = false; + + // + result = + IsStrong(percent) && IsBearish(); + + // + return result; + } + + // + bool IsSharpBullish( + int __loopback = 2, + double _sharpRatio = 2.5 // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + if (__loopback < 0) + { + __loopback = 2; + } + + // + if (_sharpRatio < 0) + { + _sharpRatio = 2.5; + } + + // + int hIDX = FindHighestIndex( + __loopback, + MODE_HIGH // + ); + int lIDX = FindLowestIndex( + __loopback, + MODE_LOW // + ); + + // + result = + // + hIDX >= 0 && + lIDX >= 0 && + MathAbs(hIDX - Index()) < 2 + // + ; + + // + if (!result) + { + return result; + } + + // + XOHCL hBar; + result = hBar.Init( + symbol, + period, + hIDX // + ); + if (!result) + { + return result; + } + + // + XOHCL lBar; + result = lBar.Init( + symbol, + period, + lIDX // + ); + if (!result) + { + return result; + } + + // + double lhDif = hBar.high - lBar.low; + + // + int hhIDX = hBar.FindHighestIndex( + __loopback, + MODE_HIGH // + ); + + // + int llIDX = lBar.FindLowestIndex( + __loopback, + MODE_LOW // + ); + + // + XOHCL hhBar; + result = hhBar.Init( + symbol, + period, + hhIDX + hIDX // + ); + if (!result) + { + return result; + } + + // + XOHCL llBar; + result = llBar.Init( + symbol, + period, + llIDX + lIDX // + ); + if (!result) + { + return result; + } + + // + double llhhDif = hhBar.high - llBar.low; + + // + result = + // + lBar.low > llBar.low && + hBar.high > hhBar.high && + lhDif >= llhhDif * _sharpRatio + // + ; + + // + return result; + } + + // + bool IsSharpBearish( + int __loopback = 2, + double _sharpRatio = 2.5 // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + if (__loopback < 0) + { + __loopback = 2; + } + + // + if (_sharpRatio < 0) + { + _sharpRatio = 2.5; + } + + // + int hIDX = FindHighestIndex( + __loopback, + MODE_HIGH // + ); + int lIDX = FindLowestIndex( + __loopback, + MODE_LOW // + ); + + // + result = + // + hIDX >= 0 && + lIDX >= 0 && + MathAbs(hIDX - Index()) < 2 + // + ; + + // + if (!result) + { + return result; + } + + // + XOHCL hBar; + result = hBar.Init( + symbol, + period, + hIDX // + ); + if (!result) + { + return result; + } + + // + XOHCL lBar; + result = lBar.Init( + symbol, + period, + lIDX // + ); + if (!result) + { + return result; + } + + // + double lhDif = hBar.high - lBar.low; + + // + int hhIDX = hBar.FindHighestIndex( + __loopback, + MODE_HIGH // + ); + + // + int llIDX = lBar.FindLowestIndex( + __loopback, + MODE_LOW // + ); + + // + XOHCL hhBar; + result = hhBar.Init( + symbol, + period, + hhIDX + hIDX // + ); + if (!result) + { + return result; + } + + // + XOHCL llBar; + result = llBar.Init( + symbol, + period, + llIDX + lIDX // + ); + if (!result) + { + return result; + } + + // + double llhhDif = hhBar.high - llBar.low; + + // + result = + // + lBar.low < llBar.low && + hBar.high < hhBar.high && + lhDif >= llhhDif * _sharpRatio + // + ; + + // + return result; + } + + // + // Find Lowest Bar Index ... + int FindHighestIndex( + int mLength, // Loopback ... + ENUM_SERIESMODE mMode // Calculation mode + ) + { + // + int result = -1; + + // + if (!IsValid()) + { + return result; + } + + // + if (mLength < 2) + { + mLength = 2; + } + + // + result = iHighest( + symbol, + period, + mMode, + mLength, + Index()); + + // + return result; + } + + // + // Find Lowest ... + double FindHighest( + int mLength, // Loopback ... + ENUM_SERIESMODE mMode // Calculation mode + ) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + int idx = FindHighestIndex( + mLength, + mMode); + if (idx <= -1) + { + return result; + } + + // + XOHCL iH; + result = iH.Init( + symbol, + period, + idx + // + ); + if (!result) + { + return result; + } + + // + result = iH.GetPrice(mMode); + + // + return result; + } + + // + // Find Lowest Bar Index ... + int FindLowestIndex( + int mLength, // Loopback ... + ENUM_SERIESMODE mMode // Calculation mode + ) + { + // + int result = -1; + + // + if (!IsValid()) + { + return result; + } + + // + if (mLength < 2) + { + mLength = 2; + } + + // + result = iLowest( + symbol, + period, + mMode, + mLength, + Index()); + + // + return result; + } + + // + // Find Lowest ... + double FindLowest( + int mLength, // Loopback ... + ENUM_SERIESMODE mMode // Calculation mode + ) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + int idx = FindLowestIndex( + mLength, + mMode); + if (idx <= -1) + { + return result; + } + + // + XOHCL iL; + result = iL.Init( + symbol, + period, + idx + // + ); + if (!result) + { + return result; + } + + // + result = iL.GetPrice(mMode); + + // + return result; + } + + // + // Retrieve Bullish Pressure ... + double GetBullishPressure( + int __loopback = 7 // + ) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + symbol, + period, + Index(), + __loopback // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + result += bars[i].GetLowShadow(); + } + + // + return result; + } + + // + // Retrieve Bearish Pressure ... + double GetBearishPressure( + int __loopback = 7 // + ) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + symbol, + period, + Index(), + __loopback // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + result += bars[i].GetHighShadow(); + } + + // + return result; + } + + // + bool HasBullishPressure( + int __loopback = 7 // + ) + { + // + bool result = false; + + // + if (__loopback < 0) + { + __loopback = 7; + } + + // + double bullishPressure = GetBullishPressure(__loopback); + double bearishPressure = GetBearishPressure(__loopback); + + // + result = + // + bullishPressure > 0 && + bearishPressure >= 0 && + bullishPressure > bearishPressure + // + ; + + // + return result; + } + + // + bool HasBearishPressure( + int __loopback = 7 // + ) + { + // + bool result = false; + + // + if (__loopback < 0) + { + __loopback = 7; + } + + // + double bullishPressure = GetBullishPressure(__loopback); + double bearishPressure = GetBearishPressure(__loopback); + + // + result = + // + bearishPressure > 0 && + bullishPressure >= 0 && + bearishPressure > bullishPressure + // + ; + + // + return result; + } + + // + // Retrieve Bullish Power ... + double GetBullishPower( + int __loopback = 7 // + ) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + symbol, + period, + Index(), + __loopback // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + // + if (bars[i].IsBullish()) + { + result += bars[i].GetBody(); + } + } + + // + return result; + } + + // + // Retrieve Bearish Pressure ... + double GetBearishPower( + int __loopback = 7 // + ) + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + symbol, + period, + Index(), + __loopback // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + for (int i = 0; i < barsCount; i++) + { + // + if (bars[i].IsBearish()) + { + result += bars[i].GetBody(); + } + } + + // + return result; + } + + // + bool HasBullishPower( + int __loopback = 7 // + ) + { + // + bool result = false; + + // + if (__loopback < 0) + { + __loopback = 7; + } + + // + double bullishPressure = GetBullishPower(__loopback); + double bearishPressure = GetBearishPower(__loopback); + + // + result = + // + bullishPressure > 0 && + bearishPressure >= 0 && + bullishPressure > bearishPressure + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int __loopback = 7 // + ) + { + // + bool result = false; + + // + if (__loopback < 0) + { + __loopback = 7; + } + + // + double bullishPressure = GetBullishPower(__loopback); + double bearishPressure = GetBearishPower(__loopback); + + // + result = + // + bearishPressure > 0 && + bullishPressure >= 0 && + bearishPressure > bullishPressure + // + ; + + // + return result; + } + + // + // Decisions ... + + // + bool IsBullishDecision( + double percent = 70 // Percent of Body + ) + { + // + bool result = false; + + // + result = + // + IsValid() && + Index() > 0 && + IsBullish() && + (GetRange() * percent) / 100 <= GetBody() + // + ; + + // + return result; + } + + // + bool IsBearishDecision( + double percent = 70 // Percent of Body + ) + { + // + bool result = false; + + // + result = + // + IsValid() && + Index() > 0 && + IsBearish() && + (GetRange() * percent) / 100 <= GetBody() + // + ; + + // + return result; + } + + // + // Touches ... + + // + bool IsBullishTouched(double price) + { + // + bool result = false; + + // + result = + // + IsValid() + // + && + // + price > 0 + // + ; + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + result = + // + (pBar.low <= price || + pBar.GetDown() <= price) + // + && + // + (pBar.high > price || + pBar.GetUp() > price) + // + && + // + open > price && + low > price + // + ; + + // + return result; + } + + // + bool IsBearishTouched(double price) + { + // + bool result = false; + + // + result = + // + IsValid() + // + && + // + price > 0 + // + ; + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + result = + // + (pBar.high >= price || + pBar.GetUp() >= price) + // + && + // + (pBar.low < price || + pBar.GetDown() < price) + // + && + // + open < price && + high < price + // + ; + + // + return result; + } + + // + // Candlestic Patterns ... + + // + // Check Doji ... + bool IsDoji() + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + result = open == close; + + // + return result; + } + + // + // Check Hammer ... + bool IsHammer( + double _upShadowFactor = 0.1, + double _downShadowFactor = 0.6, + bool applyFib382Check = true, + bool applyPrevShadowCheck = true // + ) + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + if (_upShadowFactor < 0) + { + _upShadowFactor = 0.1; + } + + // + if (_downShadowFactor < 0) + { + _upShadowFactor = 0.6; + } + + // + double range = GetRange(); + + // + // Check Upper Shadow Must be 0 or Under 10% ... + double upShadow = GetHighShadow(); + result = upShadow < range * _upShadowFactor; + if (!result) + { + return result; + } + + // + // Check Down Shadow Must at least 60% ... + double downShadow = GetLowShadow(); + result = downShadow > range * _downShadowFactor; + if (!result) + { + return result; + } + + // + // Check Fib 382 ... + if (result && applyFib382Check) + { + // + double fib382 = GetFibonacciLevel( + high, + low, + 0.382, + -1 // + ); + result = GetDown() > fib382; + } + + // + // Check Shadow Based on Prev Bar ... + if (result && applyPrevShadowCheck) + { + // + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + result = low < pBar.low; + } + + // + return result; + } + + // + // Check Sgooting Star ... + // Reversal Hammer ... + bool IsShootingStar( + double _upShadowFactor = 0.6, + double _downShadowFactor = 0.1, + bool applyFib382Check = true, + bool applyPrevShadowCheck = true // + ) + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + if (_upShadowFactor < 0) + { + _upShadowFactor = 0.6; + } + + // + if (_downShadowFactor < 0) + { + _upShadowFactor = 0.1; + } + + // + double range = GetRange(); + + // + // Check Upper Shadow Must be 0 or Under 10% ... + double upShadow = GetHighShadow(); + result = upShadow > range * _upShadowFactor; + if (!result) + { + return result; + } + + // + // Check Down Shadow Must at least 60% ... + double downShadow = GetLowShadow(); + result = downShadow < range * _downShadowFactor; + if (!result) + { + return result; + } + + // + // Check Fib 382 ... + if (result && applyFib382Check) + { + // + double fib382 = GetFibonacciLevel( + high, + low, + 0.382, + 1 // + ); + result = GetUp() < fib382; + } + + // + // Check Shadow Based on Prev Bar ... + if (result && applyPrevShadowCheck) + { + // + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + result = high > pBar.high; + } + + // + return result; + } + + // + // Check Bullish Engulfing ... + bool IsBullishEngulfing( + double _engulfBarBodyFactor = 0.7 // + ) + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + if (_engulfBarBodyFactor < 0) + { + _engulfBarBodyFactor = 0.7; + } + + // + // Check Bar Is Bullish ... + result = IsBullish(); + if (!result) + { + return result; + } + + // + // Retrieve Previous Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + double range = GetRange(); + double body = GetBody(); + + // + // Check Prev Bar Must Bearish ... + result = pBar.IsBearish(); + if (!result) + { + return result; + } + + // + // Check Shadows Engulf Prev Bar ... + result = + // + high > pBar.high && + low <= pBar.low + // + ; + if (!result) + { + return result; + } + + // + // Check Engulfed Bar Must Inside Engulfer Body ... + result = + // + GetUp() > pBar.GetUp() && + GetDown() < pBar.GetDown() + // + ; + if (!result) + { + return result; + } + + // + // Check Body of Engulfing Bar ... + if (result && _engulfBarBodyFactor > 0) + { + result = body >= range * _engulfBarBodyFactor; + } + + // + return result; + } + + // + // Check Bearish Engulfing ... + bool IsBearishEngulfing( + double _engulfBarBodyFactor = 0.7 // + ) + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + if (_engulfBarBodyFactor < 0) + { + _engulfBarBodyFactor = 0.7; + } + + // + // Check Bar Is Bearish ... + result = IsBearish(); + if (!result) + { + return result; + } + + // + // Retrieve Previous Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + double range = GetRange(); + double body = GetBody(); + + // + // Check Prev Bar Must Bullish ... + result = pBar.IsBullish(); + if (!result) + { + return result; + } + + // + // Check Shadows Engulf Prev Bar ... + result = high >= pBar.high && low < pBar.low; + if (!result) + { + return result; + } + + // + // Check Engulfed Bar Must Inside Engulfer Body ... + result = + // + GetUp() > pBar.GetUp() && + GetDown() < pBar.GetDown() + // + ; + if (!result) + { + return result; + } + + // + // Check Body of Engulfing Bar ... + if (result && _engulfBarBodyFactor > 0) + { + result = body >= range * _engulfBarBodyFactor; + } + + // + return result; + } + + // + // Check Morning Star Pattern ... + bool IsMorningStar( + double _middleRangeFactor = 0.3, + double _startBodyFactor = 0.6, + bool forceCheckMiddleBarDirection = true, + bool forceCheckStartBody = true // + ) + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + if (_middleRangeFactor < 0) + { + _middleRangeFactor = 0.3; + } + + // + if (_startBodyFactor < 0) + { + _startBodyFactor = 0.6; + } + + // + // Current Bar Must be Bullish ... + result = IsBullish(); + if (!result) + { + return result; + } + + // + // Retrieve Previous Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar must be Bearish ... + if (result && forceCheckMiddleBarDirection) + { + // + result = pBar.IsBearish(); + if (!result) + { + return result; + } + } + + // + // Retrieve Previous Bar of Prev Bar ... + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + // Prev Of Prev Bar Must be Bearish ... + result = ppBar.IsBearish(); + if (!result) + { + return result; + } + + // + double range = GetRange(); + double pRange = pBar.GetRange(); + double ppRange = ppBar.GetRange(); + + // + // Middle Bar must be Smaller than Ratio of other ... + result = + // + pRange < range * _middleRangeFactor && + pRange < ppRange * _middleRangeFactor + // + ; + if (!result) + { + return result; + } + + // + if (result && forceCheckStartBody) + { + // + result = ppBar.GetBody() > ppRange * _startBodyFactor; + if (!result) + { + return result; + } + } + + // + return result; + } + + // + // Check Evening Star Pattern ... + bool IsEveningStar( + double _middleRangeFactor = 0.3, + double _startBodyFactor = 0.6, + bool forceCheckMiddleBarDirection = true, + bool forceCheckStartBody = true // + ) + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + if (_middleRangeFactor < 0) + { + _middleRangeFactor = 0.3; + } + + // + if (_startBodyFactor < 0) + { + _startBodyFactor = 0.6; + } + + // + // Current Bar Must be Bearish ... + result = IsBearish(); + if (!result) + { + return result; + } + + // + // Retrieve Previous Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar must be Bullish ... + if (result && forceCheckMiddleBarDirection) + { + // + result = pBar.IsBullish(); + if (!result) + { + return result; + } + } + + // + // Retrieve Previous Bar of Prev Bar ... + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + // Prev Of Prev Bar Must be Bullish ... + result = ppBar.IsBullish(); + if (!result) + { + return result; + } + + // + double range = GetRange(); + double pRange = pBar.GetRange(); + double ppRange = ppBar.GetRange(); + + // + // Middle Bar must be Smaller than Ratio of other ... + result = + // + pRange < range * _middleRangeFactor && + pRange < ppRange * _middleRangeFactor + // + ; + if (!result) + { + return result; + } + + // + if (result && forceCheckStartBody) + { + // + result = ppBar.GetBody() > ppRange * _startBodyFactor; + if (!result) + { + return result; + } + } + + // + return result; + } + + // + // Bullish Marubozu ... + bool IsBullishMarubozu() + { + // + bool result = false; + + // + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + result = IsBullish(); + if (!result) + { + return result; + } + + // + result = + // + GetUp() == high && + GetDown() == low + // + ; + + // + return result; + } + + // + // Bearish Marubozu ... + bool IsBearishMarubozu() + { + // + bool result = false; + + // + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + result = IsBearish(); + if (!result) + { + return result; + } + + // + result = + // + GetUp() == high && + GetDown() == low + // + ; + + // + return result; + } + + // + // Contextual Patterns ... + + // + // Check Swing High ... + bool IsSwingHigh() + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + // Current Bar Must be Bearish ... + result = IsBearish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar Must be Bullish ... + result = pBar.IsBullish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev of Prev Bar ... + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + // Prev of Prev Bar Must be Bullish ... + result = ppBar.IsBullish(); + if (!result) + { + return result; + } + + // + // Check All Highs ... + result = + // + high < pBar.high && + pBar.high > ppBar.high + // + ; + + // + return result; + } + + // + // Find Simple 3 Candle Based Swing High ... + bool IsSimpleSwingHigh(double thresholdInPoint = 1) + { + // + bool result = false; + + // + int index = Index(); + result = index > 0; + if (!result) + { + return result; + } + + // + XOHCL nextBar; + result = GetNextBar(nextBar); + if (!result) + { + return result; + } + + // + XOHCL prevBar; + result = GetPreviousBar(prevBar); + if (!result) + { + return result; + } + + // + double point = GetPoints(symbol); + double requiredOffset = point * thresholdInPoint; + + // + result = + high > nextBar.high && + high > prevBar.high && + (thresholdInPoint <= 0 + ? true + : MathAbs( + MathMax( + nextBar.high, + prevBar.high) - + high) >= requiredOffset); + + // + return result; + } + + // + // Find Last Swing High ... + bool FindLastSwingHigh(XOHCL &swing) + { + // + bool result = false; + + // + swing.Clean(); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int totalBars = iBars( + symbol, + period // + ); + int maxAllowed = MathMin(100, (totalBars / 100)); + + // + int idx = Index(); + for (int i = idx; i <= idx + maxAllowed; i++) + { + // + swing.Clean(); + result = swing.Init( + symbol, + period, + i // + ); + if (!result) + { + // + swing.Clean(); + break; + } + + // + result = swing.IsSwingHigh(); + if (result) + { + break; + } + } + + // + return result; + } + + // + // Check Swing Low ... + bool IsSwingLow() + { + // + bool result = false; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + // Current Bar Must be Bullish ... + result = IsBullish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar Must be Bearish ... + result = pBar.IsBearish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev of Prev Bar ... + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + // Prev of Prev Bar Must be Bearish ... + result = ppBar.IsBearish(); + if (!result) + { + return result; + } + + // + // Check All Lows ... + result = + // + low > pBar.low && + pBar.low < ppBar.low + // + ; + + // + return result; + } + + // + // Find Simple 3 Candle Based Swing Low ... + bool IsSimpleSwingLow(double thresholdInPoint = 1) + { + // + bool result = false; + + // + int index = Index(); + result = index > 0; + if (!result) + { + return result; + } + + // + XOHCL nextBar; + result = GetNextBar(nextBar); + if (!result) + { + return result; + } + + // + XOHCL prevBar; + result = GetPreviousBar(prevBar); + if (!result) + { + return result; + } + + // + double point = GetPoints(symbol); + double requiredOffset = point * thresholdInPoint; + + // + result = + low < nextBar.low && + low < prevBar.low && + (thresholdInPoint <= 0 + ? true + : MathAbs( + MathMax( + nextBar.low, + prevBar.low) - + low) >= requiredOffset); + + // + return result; + } + + // + // Find Last Swing Low ... + bool FindLastSwingLow(XOHCL &swing) + { + // + bool result = false; + + // + swing.Clean(); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int totalBars = iBars( + symbol, + period // + ); + int maxAllowed = MathMin(100, (totalBars / 100)); + + // + int idx = Index(); + for (int i = idx; i <= idx + maxAllowed; i++) + { + // + swing.Clean(); + result = swing.Init( + symbol, + period, + i // + ); + if (!result) + { + // + swing.Clean(); + break; + } + + // + result = swing.IsSwingLow(); + if (result) + { + break; + } + } + + // + return result; + } + + // + // Check Bullish FVG ... + bool HasBullishFVG( + double &upper, + double &lower, + bool forceMiddleBarCheck = true // + ) + { + // + bool result = false; + + // + upper = 0; + lower = 0; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + // Current Bar Must be Bullish ... + result = IsBullish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar Must be Bullish ... + result = pBar.IsBullish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev of Prev Bar ... + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + // Prev of Prev Bar Must be Bullish ... + result = ppBar.IsBullish(); + if (!result) + { + return result; + } + + // + // Other Conditions ... + result = + // + low > ppBar.high + // + ; + + // + // Check Middle Bar Range ... + if (result && forceMiddleBarCheck) + { + // + result = + // + pBar.high > low && + pBar.low < ppBar.high + // + ; + + // + if (!result) + { + return result; + } + } + + // + if (result) + { + // + upper = low; + lower = ppBar.high; + } + + // + return result; + } + + // + // Check Bearish FVG ... + bool HasBearishFVG( + double &upper, + double &lower, + bool forceMiddleBarCheck = true // + ) + { + // + bool result = false; + + // + upper = 0; + lower = 0; + + // + // Validate Content and Ignore 0 Bar + // since it is not Completed ... + result = IsValid() && Index() > 0; + if (!result) + { + return result; + } + + // + // Current Bar Must be Bearish ... + result = IsBearish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar Must be Bearish ... + result = pBar.IsBearish(); + if (!result) + { + return result; + } + + // + // Retrieve Prev of Prev Bar ... + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + // Prev of Prev Bar Must be Bearish ... + result = ppBar.IsBearish(); + if (!result) + { + return result; + } + + // + // Other Conditions ... + result = + // + high < ppBar.low + // + ; + + // + // Check Middle Bar Range ... + if (result && forceMiddleBarCheck) + { + // + result = + // + pBar.high > low && + pBar.low < ppBar.high + // + ; + + // + if (!result) + { + return result; + } + } + + // + if (result) + { + // + upper = ppBar.low; + lower = high; + } + + // + return result; + } + + // + // Find Support ... + bool HasSupport( + XOHCL &bar, + ENUM_X_PRICE type = X_PRICE_CLOSE, + int _loopback = 21, + int tries = 100 // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (_loopback < 0) + { + _loopback = 21; + } + + // + if (tries < 0) + { + tries = 100; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + double price = GetPrice(type); + + // + for (int i = 1; i < tries; i++) + { + // + int _length = _loopback * i; + + // + int lowestIDX = FindLowestIndex( + _length, + MODE_LOW // + ); + result = IsValidSize(lowestIDX); + if (!result) + { + break; + } + + // + XOHCL iLBar; + result = iLBar.Init( + symbol, + period, + lowestIDX // + ); + if (!result) + { + break; + } + + // + result = + // + price > iLBar.high + // + ; + if (result) + { + // + bar = iLBar; + break; + } + } + + // + return result; + } + + // + // Find Resistance ... + bool HasResistance( + XOHCL &bar, + ENUM_X_PRICE type = X_PRICE_CLOSE, + int _loopback = 21, + int tries = 100 // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (_loopback < 0) + { + _loopback = 21; + } + + // + if (tries < 0) + { + tries = 100; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + double price = GetPrice(type); + + // + for (int i = 1; i < tries; i++) + { + // + int _length = _loopback * i; + + // + int highestIDX = FindHighestIndex( + _length, + MODE_LOW // + ); + result = IsValidSize(highestIDX); + if (!result) + { + break; + } + + // + XOHCL iHBar; + result = iHBar.Init( + symbol, + period, + highestIDX // + ); + if (!result) + { + break; + } + + // + result = + // + price < iHBar.high + // + ; + if (result) + { + // + bar = iHBar; + break; + } + } + + // + return result; + } + + // + // Trend Detection ... + + // + // Find Bullish Trend ... + bool HasBullishTrend( + XOHCL &highSwingBars[], + XOHCL &lowSwingBars[], + bool forceMethod2 = false, + int _loopback = 3, + int tries = 3, + ENUM_X_PRICE type = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + Clean(lowSwingBars); + Clean(highSwingBars); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + double price = GetPrice(type); + + // + int lastIDX = Index(); + double lastH = 0; + double lastL = 0; + for (int i = 1; i < tries + 1; i++) + { + // + // Use Regular Method ... + if (!forceMethod2) + { + // + int iHIDX = FindSwing( + symbol, + period, + X_SWING_HIGH, + _loopback, + lastIDX // + ); + result = IsValidIndex(iHIDX); + if (!result) + { + break; + } + + // + XOHCL iHBar; + result = iHBar.Init( + symbol, + period, + iHIDX // + ); + if (!result) + { + break; + } + + // + double iH = iHBar.high; + bool isIHAccepted = + // + iH > 0 && + ( + // + lastH == 0 + ? true + : iH < lastH + // + ) + // + ; + if (isIHAccepted) + { + // + AddRef( + iHBar, + highSwingBars // + ); + + // + lastH = iH; + lastIDX = iHIDX; + } + + // + int iLIDX = FindSwing( + symbol, + period, + X_SWING_LOW, + _loopback, + lastIDX // + ); + result = IsValidIndex(iLIDX); + if (!result) + { + break; + } + + // + XOHCL iLBar; + result = iLBar.Init( + symbol, + period, + iLIDX // + ); + if (!result) + { + break; + } + + // + double iL = iLBar.low; + bool isILAccepted = + // + iL > 0 && + ( + // + lastL == 0 + ? true + : iL < lastL + // + ) + // + ; + if (isILAccepted) + { + // + AddRef( + iLBar, + lowSwingBars // + ); + + // + lastL = iL; + lastIDX = iLIDX; + } + } + // + // Use Other MEthod ... + else + { + // + int _length = i * _loopback; + int start = + // + i == 1 + ? 1 + : _length - _loopback + // + ; + + // + int iHIDX = iHighest( + symbol, + period, + MODE_HIGH, + _loopback, + start // + ); + result = IsValidIndex(iHIDX); + if (!result) + { + break; + } + + // + XOHCL iHBar; + result = iHBar.Init( + symbol, + period, + iHIDX // + ); + if (!result) + { + break; + } + + // + double iH = iHBar.high; + bool isIHAccepted = + // + iH > 0 && + ( + // + lastH == 0 + ? true + : iH < lastH + // + ) + // + ; + if (isIHAccepted) + { + // + AddRef( + iHBar, + highSwingBars // + ); + + // + lastH = iH; + lastIDX = iHIDX; + } + + // + int iLIDX = iLowest( + symbol, + period, + MODE_LOW, + _loopback, + start // + ); + result = IsValidIndex(iLIDX); + if (!result) + { + break; + } + + // + XOHCL iLBar; + result = iLBar.Init( + symbol, + period, + iLIDX // + ); + if (!result) + { + break; + } + + // + double iL = iLBar.low; + bool isILAccepted = + // + iL > 0 && + ( + // + lastL == 0 + ? true + : iL < lastL + // + ) + // + ; + if (isILAccepted) + { + // + AddRef( + iLBar, + lowSwingBars // + ); + + // + lastL = iL; + lastIDX = iLIDX; + } + } + } + + // + if (result) + { + // + result = + // + ArraySize(lowSwingBars) == tries && + ArraySize(highSwingBars) == tries + // + ; + } + + // + if (!result) + { + // + Clean(lowSwingBars); + Clean(highSwingBars); + } + + // + return result; + } + + // + // Find Bearish Trend ... + bool HasBearishTrend( + XOHCL &highSwingBars[], + XOHCL &lowSwingBars[], + bool forceMethod2 = false, + int _loopback = 3, + int tries = 3, + ENUM_X_PRICE type = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + Clean(lowSwingBars); + Clean(highSwingBars); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + double price = GetPrice(type); + + // + int lastIDX = Index(); + double lastH = 0; + double lastL = 0; + for (int i = 1; i < tries + 1; i++) + { + // + // Use Regular Method ... + if (!forceMethod2) + { + // + int iHIDX = FindSwing( + symbol, + period, + X_SWING_HIGH, + _loopback, + lastIDX // + ); + result = IsValidIndex(iHIDX); + if (!result) + { + break; + } + + // + XOHCL iHBar; + result = iHBar.Init( + symbol, + period, + iHIDX // + ); + if (!result) + { + break; + } + + // + double iH = iHBar.high; + bool isIHAccepted = + // + iH > 0 && + ( + // + lastH == 0 + ? true + : iH > lastH + // + ) + // + ; + if (isIHAccepted) + { + // + AddRef( + iHBar, + highSwingBars // + ); + + // + lastH = iH; + lastIDX = iHIDX; + } + + // + int iLIDX = FindSwing( + symbol, + period, + X_SWING_LOW, + _loopback, + lastIDX // + ); + result = IsValidIndex(iLIDX); + if (!result) + { + break; + } + + // + XOHCL iLBar; + result = iLBar.Init( + symbol, + period, + iLIDX // + ); + if (!result) + { + break; + } + + // + double iL = iLBar.low; + bool isILAccepted = + // + iL > 0 && + ( + // + lastL == 0 + ? true + : iL > lastL + // + ) + // + ; + if (isILAccepted) + { + // + AddRef( + iLBar, + lowSwingBars // + ); + + // + lastL = iL; + lastIDX = iLIDX; + } + } + // + // Use Other MEthod ... + else + { + // + int _length = i * _loopback; + int start = + // + i == 1 + ? 1 + : _length - _loopback + // + ; + + // + int iHIDX = iHighest( + symbol, + period, + MODE_HIGH, + _loopback, + start // + ); + result = IsValidIndex(iHIDX); + if (!result) + { + break; + } + + // + XOHCL iHBar; + result = iHBar.Init( + symbol, + period, + iHIDX // + ); + if (!result) + { + break; + } + + // + double iH = iHBar.high; + bool isIHAccepted = + // + iH > 0 && + ( + // + lastH == 0 + ? true + : iH > lastH + // + ) + // + ; + if (isIHAccepted) + { + // + AddRef( + iHBar, + highSwingBars // + ); + + // + lastH = iH; + lastIDX = iHIDX; + } + + // + int iLIDX = iLowest( + symbol, + period, + MODE_LOW, + _loopback, + start // + ); + result = IsValidIndex(iLIDX); + if (!result) + { + break; + } + + // + XOHCL iLBar; + result = iLBar.Init( + symbol, + period, + iLIDX // + ); + if (!result) + { + break; + } + + // + double iL = iLBar.low; + bool isILAccepted = + // + iL > 0 && + ( + // + lastL == 0 + ? true + : iL > lastL + // + ) + // + ; + if (isILAccepted) + { + // + AddRef( + iLBar, + lowSwingBars // + ); + + // + lastL = iL; + lastIDX = iLIDX; + } + } + } + + // + if (result) + { + // + result = + // + ArraySize(lowSwingBars) == tries && + ArraySize(highSwingBars) == tries + // + ; + } + + // + if (!result) + { + // + Clean(lowSwingBars); + Clean(highSwingBars); + } + + // + return result; + } + + // + // Order Blocks ... + + // + // Find Bullish Order Block ... + bool HasBullishOrderBlock( + XOHCL &orderBlock, + int _minimumSameBars = 4 // + ) + { + // + bool result = false; + + // + orderBlock.Clean(); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + if (_minimumSameBars < 0) + { + _minimumSameBars = 4; + } + + // + XOHCL cBar; + int founded = 0; + int cIDX = Index(); + bool isEnough = false; + while (!isEnough) + { + // + result = cBar.Init( + symbol, + period, + cIDX // + ); + if (!result) + { + break; + } + + // + result = cBar.IsBullish(); + if (!result && cBar.IsBearish()) + { + break; + } + + // + cIDX++; + founded++; + } + + // + // Here we have to check founded and if it's fill + // our requirements ... + // cIDX is Order Block Index ... + result = + // + cBar.IsValid() && + high > cBar.high && + founded >= _minimumSameBars + // + ; + if (!result) + { + return result; + } + + // + result = orderBlock.Init( + symbol, + period, + cIDX // + ); + if (!result) + { + // + orderBlock.Clean(); + return result; + } + + // + return result; + } + + // + // Find Bearish Order Block ... + bool HasBearishOrderBlock( + XOHCL &orderBlock, + int _minimumSameBars = 4 // + ) + { + // + bool result = false; + + // + orderBlock.Clean(); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + if (_minimumSameBars < 0) + { + _minimumSameBars = 4; + } + + // + XOHCL cBar; + int founded = 0; + int cIDX = Index(); + bool isEnough = false; + while (!isEnough) + { + // + bool isInited = cBar.Init( + symbol, + period, + cIDX // + ); + + // + result = cBar.IsBearish(); + if (!result && cBar.IsBullish()) + { + break; + } + + // + cIDX++; + founded++; + } + + // + // Here we have to check founded and if it's fill + // our requirements ... + // cIDX is Order Block Index ... + result = + // + cBar.IsValid() && + high < cBar.low && + founded >= _minimumSameBars + // + ; + if (!result) + { + return result; + } + + // + result = orderBlock.Init( + symbol, + period, + cIDX // + ); + if (!result) + { + // + orderBlock.Clean(); + return result; + } + + // + return result; + } + + // + // Order Blocks ... + + // + // Supply and Demand ... + + // + // Other ... + string GetTag(string prefix) + { + // + string result = NULL; + + // + result = + (IsValid(prefix) + ? prefix + "_" + : "") + + "XOHCL_" + symbol + "_" + ToString(period) + "_" + ToFormatString(time); + + // + return result; + } + + // + // Convert to String Representation ... + string ToString() + { + // + string result = ""; + + // + result = GetTypeName(this) + + "(O(" + ToString(open) + "),H(" + ToString(high) + "),C(" + ToString(close) + "),L(" + ToString(low) + "))"; + + // + return result; + } +}; + +// +// Tracking Times ... +struct XTimeTracker +{ + // + // Props ... + int xMonth; + int xDayOfWeek; + int xForWeekDay; + int xDay; + int xHour; + int xMinute; + + // + // Constructor ... + XTimeTracker() + { + Clean(); + } + + // + // Tools ... + + // + void Clean() + { + // + xDay = -1; + xHour = -1; + xMonth = -1; + xMinute = -1; + xDayOfWeek = -1; + xForWeekDay = -1; + } + + // + // Detecting New Minute ... + bool IsNewMinute() + { + // + bool result = false; + + // + // Retrieve Current Time as Struct ... + MqlDateTime timeStruct = GetCurrentTime(); + + // + // Check Houre ... + result = timeStruct.min != xMinute; + if (result) + { + xMinute = timeStruct.min; + } + + // + return result; + } + + // + // Detecting New Houre ... + bool IsNewHour() + { + // + bool result = false; + + // + // Retrieve Current Time as Struct ... + MqlDateTime timeStruct = GetCurrentTime(); + + // + // Check Houre ... + result = timeStruct.hour != xHour; + if (result) + { + xHour = timeStruct.hour; + } + + // + return result; + } + + // + // Detecting New Day ... + bool IsNewDay() + { + // + bool result = false; + + // + // Retrieve Current Time as Struct ... + MqlDateTime timeStruct = GetCurrentTime(); + + // + // Check Houre ... + result = timeStruct.day_of_year != xDay; + if (result) + { + xDay = timeStruct.day_of_year; + } + + // + return result; + } + + // + // Detecting New Week ... + bool IsNewWeek() + { + // + bool result = false; + + // + // Retrieve Current Time as Struct ... + MqlDateTime timeStruct = GetCurrentTime(); + + // + // Check Week ... + // Since Week Starts From Monday in Forex World ... + // we Calculate Start of Week by 1-Monday ... + result = + xDayOfWeek == -1 && + xForWeekDay == -1 + ? true + : timeStruct.day_of_week == 1 && + timeStruct.day_of_year > xForWeekDay; + + // + xForWeekDay = timeStruct.day_of_year; + xDayOfWeek = timeStruct.day_of_week; + + // + return result; + } + + // + // Detecting End Of Week ... + bool IsWeekEnd() + { + // + bool result = false; + + // + // Retrieve Current Time as Struct ... + MqlDateTime timeStruct = GetCurrentTime(); + + // + // Check WeekEnd ... + // Since Week Starts From Monday in Forex World ... + // we Calculate End of Week by 5-Friday ... + result = + xDayOfWeek != -1 && + timeStruct.day_of_week == 5 && + timeStruct.hour == 23 && + timeStruct.min == 59 && + timeStruct.sec == 59; + + // + return result; + } + + // + // Detecting New Month ... + bool IsNewMonth() + { + // + bool result = false; + + // + // Retrieve Current Time as Struct ... + MqlDateTime timeStruct = GetCurrentTime(); + + // + // Check Houre ... + result = timeStruct.mon != xMonth; + if (result) + { + xMonth = timeStruct.mon; + } + + // + return result; + } +}; + +// +// Tracking Bars on Specified Environment ... +struct XBarTracker +{ + // + string symbol; // Tracking Symbol + ENUM_TIMEFRAMES period; // Tracking Time Frame + + // + int lastTrackedBar; // Last Tracked Bar ... + + // + bool waitsUntilNext; // Waits Until Next Bar ... + + // + // Constructor ... + XBarTracker() + { + Clean(); + } + + // + // Initializer ... + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL // Trading Period + ) + { + // + bool result = false; + + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + this.symbol = mSymbol; + this.period = mPeriod; + + // + this.lastTrackedBar = 0; + + // + result = true; + + // + return result; + } + + // + // Retrieve all Bars ... + int CountBars() + { + // + return iBars( + symbol, + period + // + ); + } + + // + // Check if it's New Bar ... + bool IsNewBar() + { + // + bool result = false; + + // + int currentBars = CountBars(); + + // + result = currentBars > lastTrackedBar; + if (result) + { + lastTrackedBar = currentBars; + } + + // + return result; + } + + // + bool CanProcessBar() + { + // + bool _isInTestMode = IsRunningOnTestMode(); + + // + bool isNewBar = IsNewBar(); + + // + bool result = + _isInTestMode + ? isNewBar + : !waitsUntilNext + ? true + : isNewBar; + if (result && waitsUntilNext) + { + waitsUntilNext = false; + } + + // + return result; + } + + // + void Waits() + { + this.waitsUntilNext = true; + } + + // + // Tools ... + void Clean() + { + // + symbol = NormalizeSymbol(NULL); + period = NormalizePeriod(NULL); + } + + // + bool GetBar( + XOHCL &bar, + int index = 0 // + ) + { + // + bool result = false; + + // + result = bar.Init( + symbol, + period, + index // + ); + + // + return result; + } + + // + bool GetBar( + XOHCL &bar, + datetime time = NULL // + ) + { + // + bool result = false; + + // + NormalizeTime(time); + + // + int barIndex = iBarShift( + symbol, + period, + time, + false // + ); + + // + result = barIndex >= 0; + if (!result) + { + return result; + } + + // + result = bar.Init( + symbol, + period, + barIndex // + ); + + // + return result; + } + + // + int Index(datetime time = NULL) + { + // + int result = 0; + + // + NormalizeTime(time); + + // + result = iBarShift( + symbol, + period, + time, + false // + ); + + // + return result; + } +}; + +// +// Model a Market Cycle ... +struct XMarketCycle +{ + // + // Props ... + + // + string prefix; // Prefix Trag ... + + // + string symbol; // Market Symbol ... + + // + ENUM_TIMEFRAMES period; // Period of Cycle ... + ENUM_X_PERIOD_METHOD method; // Period Selection Method ... + ENUM_X_MARKET_CYCLES cycle; // Cycles of MArket ... + + // + int length; // Number Of Candles per Current Time Frame ... + ENUM_TIMEFRAMES hostPeriod; // Current Time Frame ... + + // + datetime lastStart; // Last Candle Bar Time ... + + // + XBarTracker barTracker; // Bar Tracker ... + XBarRemainsTime remains; // Current Bar Remains Model ... + + // + // Constructor ... + XMarketCycle() + { + Clean(); + } + + // + // Init Cycle ... + bool Init( + string mSymbol, // Trading Symbol + ENUM_TIMEFRAMES mHostPeriod, // Host Period + ENUM_X_MARKET_CYCLES mCycle, // Init Cycle + string mPrefix = "" // Prefix + ) + { + // + bool result = false; + + // + mSymbol = NormalizeSymbol(mSymbol); + mHostPeriod = NormalizePeriod(mHostPeriod); + + // + result = IsValid(mCycle); + if (!result) + { + return result; + } + + // + this.cycle = mCycle; + + // + // Set Automatically Prefix ... + if (StringLen(mPrefix) == 0) + { + this.prefix = ToString(cycle); + } + + // + result = IsValid( + method, + period // + ); + if (!result) + { + return result; + } + + // + this.symbol = mSymbol; + this.hostPeriod = mHostPeriod; + + // + // Find Cycle Period ... + if (method == X_PERIOD_AUTO) + { + // + // Select Period ... + this.period = GetCyclePeriod( + this.cycle, + this.hostPeriod); + } + + // + // Set Prefix if Provided ... + if (StringLen(mPrefix) > 0) + { + this.prefix = mPrefix; + } + + // + // Calculate Required Info ... + + // + // Length ... + this.length = PeriodSeconds(this.period) / PeriodSeconds(this.hostPeriod); + + // + // Update Additional Data ... + result = this.Update(0); + + // + return result; + } + + // + bool Init( + string mSymbol, // Trading Symbol + ENUM_TIMEFRAMES mHostPeriod, // Host Period + ENUM_X_MARKET_CYCLES mCycle, // Init Cycle + ENUM_X_PERIOD_METHOD mMethod, // Period Selection Method + ENUM_TIMEFRAMES mPeriod, // Provided Period + string mPrefix = "" // Prefix + ) + { + // + this.period = mPeriod; + this.method = mMethod; + + // + return Init( + mSymbol, + mHostPeriod, + mCycle, + mPrefix + // + ); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + length = 0; + lastStart = 0; + + // + cycle = NULL; + prefix = NULL; + symbol = NULL; + period = NULL; + method = NULL; + hostPeriod = NULL; + + // + remains.Clean(); + barTracker.Clean(); + } + + // + // Check Structure Valid ... + bool IsValid() + { + // + bool result = false; + + // + result = IsValid( + method, + period); + if (!result) + { + return result; + } + + // + result = + // + length > 0 && + symbol != NULL && + period != NULL && + method != NULL && + hostPeriod != NULL && + method != X_PERIOD_NOTHING + // + ; + + // + return result; + } + + // + // Update Market Cycle Additional Info ... + bool Update(int hostBarIndex) + { + // + bool result = false; + + // + result = this.IsValid(); + if (!result) + { + return result; + } + + // + // Init Remains ... + result = remains.Init( + this.symbol, + this.period); + if (!result) + { + return result; + } + + // + // Init Bar Tracker ... + result = barTracker.Init( + this.symbol, + this.period); + if (!result) + { + return result; + } + + // + return result; + } + + // + // Count Bars ... + int CountBars() + { + // + int result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = barTracker.CountBars(); + + // + return result; + } + + // + // Check New Bar ... + bool IsNewBar() + { + // + bool result = false; + + // + if (!IsValid()) + { + return result; + } + + // + result = barTracker.IsNewBar(); + + // + return result; + } + + // + // Retrieve Current Bar Index based on Host Period bar Index ... + int GetBarIndex(int barIndex) + { + // + int result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + if (barIndex < 0) + { + return result; + } + + // + int totalBars = CountBars(); + if (barIndex >= totalBars) + { + // + result = totalBars - 1; + return result; + } + + // + datetime hostBarTime = iTime( + this.symbol, + this.hostPeriod, + barIndex + // + ); + + // + result = iBarShift( + this.symbol, + this.period, + hostBarTime + // + ); + + // + return result; + } + + // + // Retrieve Current Cycles Specific Bar ... + XOHCL GetBar(int barIndex) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + int totalBars = CountBars(); + if (barIndex >= totalBars) + { + barIndex = totalBars - 1; + } + + // + XOHCL result; + result.Init( + this.symbol, + this.period, + barIndex + // + ); + + // + return result; + } + + // + // Extract Specific Range of Bars ... + // using Start Bar Index ... + int GetBars( + XOHCL &result[], // Hold Result + int from = 0, // Start Bar Index + int count = 1, // Number of Bars + bool forceClean = true // Clean Result Array + ) + { + // + int mResult = 0; + + // + if (from < 0) + { + from = 0; + } + + // + int total = Bars( + symbol, + period); + if (from > total - 2) + { + from = total - 2; + } + + // + if (count < 0) + { + count = 1; + } + + // + int start = from; + int end = start + count; + if (end > total - 1) + { + end = total - 1; + } + + // + if (forceClean) + { + Clean(result); + } + + // + int beforeSize = ArraySize(result); + + // + for (int i = start; i < end; i++) + { + // + XOHCL iBar; + bool isValid = iBar.Init( + symbol, + period, + i + // + ); + + // + if (isValid) + { + // + AddRef( + iBar, + result + // + ); + } + } + + // + int afterSize = ArraySize(result); + + // + mResult = afterSize - beforeSize; + + // + return mResult; + } + + // + // Extract Specific Range of Bars ... + // using Start Bar Time ... + int GetBars( + XOHCL &result[], // Hold Result + datetime from = NULL, // Start Bar Time + int count = 1, // Number of Bars + bool forceClean = true // Clean Result Array + ) + { + // + from = NormalizeTime(from); + + // + int barIndex = iBarShift( + symbol, + period, + from, + false + // + ); + + // + return GetBars( + result, + symbol, + period, + barIndex, + count, + forceClean + // + ); + } + + // + // Retrieve Bar Time ... + datetime GetBarTime(int barIndex) + { + // + datetime result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + int totalBars = CountBars(); + if (barIndex >= totalBars) + { + barIndex = totalBars - 1; + } + + // + result = iTime( + this.symbol, + this.period, + barIndex + // + ); + + // + return result; + } + + // + // Find Chart ID ... + ulong GetChartID() + { + // + ulong result = 0; + + // + long firstChart = ChartFirst(); + result = firstChart; + + // + while (result >= 0) + { + // + string chSymbol = ChartSymbol(result); + ENUM_TIMEFRAMES chPeriod = ChartPeriod(result); + + // + bool isOwnChart = + // + symbol == chSymbol && + period == chPeriod + // + ; + if (isOwnChart) + { + break; + } + + // + result = ChartNext(result); + if (result < 0) + { + break; + } + } + + // + return result; + } + + // + // Create and String Representation for Unique Taging ... + string ToString() + { + // + string result = ""; + + // + if (!IsValid()) + { + return result; + } + + // + result = + GetTypeName(this) + "(" + + "PRFX(" + this.prefix + ")" + + "SMBL(" + this.symbol + ")" + + "CYC(" + ToString(this.cycle) + ")" + + "PRD(" + ToString(this.period) + ")" + + "PRDHST(" + ToString(this.hostPeriod) + ")" + + "MTH(" + EnumToString(this.method) + ")" + + ")"; + + // + return result; + } + + // + // Here we Produce a Summary brief of + // state of Cycle ... + string GenerateSummary() + { + // + string result = ""; + + // + bool hasPrefix = + StringLen(this.prefix) > 0 && + this.prefix != ToString(this.cycle); + result += (hasPrefix ? this.prefix + "[" : "") + + ToString(this.cycle) + + (hasPrefix ? "]" : "") + "\n"; + + // + result += " - PR: " + ToString(this.period) + "\n"; + + // + XOHCL cBar = GetBar(0); + + // + result += " - State: " + (cBar.IsBullish() ? "Bullish" : cBar.IsBearish() ? "Bearish" + : "Neutural"); + + // + return result; + } +}; + +// +// Linear Regression ... + +// +struct XLinearRegressionWorkStruct +{ + // + struct sDataStruct + { + // + double value; + double sumY; + double sumXY; + }; + + // + sDataStruct data[]; + + // + int dataSize; + int period; + double sumX; + double sumXX; + double divisor; + + // + // Constructor ... + XLinearRegressionWorkStruct() + : dataSize(-1), period(-1) + { + } +}; + +// +struct XLinearRegression +{ + // + XLinearRegressionWorkStruct m_work; + + // + // Calculate Linear Regression ... + double Calculate( + double value, + int period, + double &_slope, + double &_intercept, + int r, + int bars // + ) + { + // + if (m_work.dataSize <= bars) + { + m_work.dataSize = ArrayResize(m_work.data, bars + 500, 2000); + } + + // + if (period < 1) + { + period = 1; + } + + // + if (m_work.period != (int)period) + { + // + m_work.period = (int)period; + m_work.sumX = m_work.period * (m_work.period - 1.0) / 2.0; + m_work.sumXX = m_work.period * (m_work.period - 1.0) * (2.0 * m_work.period - 1.0) / 6.0; + m_work.divisor = m_work.sumX * m_work.sumX - m_work.period * m_work.sumXX; + + // + if (m_work.divisor) + { + m_work.divisor = 1.0 / m_work.divisor; + } + } + + // + m_work.data[r].value = value; + + // + if (r >= m_work.period) + { + // + m_work.data[r].sumY = m_work.data[r - 1].sumY + value - m_work.data[r - m_work.period].value; + m_work.data[r].sumXY = m_work.data[r - 1].sumXY + m_work.data[r].sumY - m_work.data[r - m_work.period].value * (m_work.period - 1.0) - value; + } + else + { + // + m_work.data[r].sumY = value; + m_work.data[r].sumXY = 0; + + // + for (int _k = 1; _k < m_work.period && r >= _k; _k++) + { + // + m_work.data[r].sumY += m_work.data[r - _k].value; + m_work.data[r].sumXY += _k * m_work.data[r - _k].value; + } + } + + // + _slope = (m_work.period * m_work.data[r].sumXY - m_work.sumX * m_work.data[r].sumY) * m_work.divisor; + _intercept = (m_work.data[r].sumY - _slope * m_work.sumX) / (double)m_work.period; + + // + double result = (_intercept + _slope * (m_work.period - 1.0)); + + // + return result; + } + + // +}; + +// +// Use To Parse Symbols for +// Ignore Brokers Additional Suffixes ... +struct XSymbolParser +{ + // + string version; // Temp ... + + // + // Symbol Parsing ... + + // + // Forext ... + + // + bool IsEURUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsUSDJPY(string symbol) + { + // + string symbolIdentifiers[] = { + "USD", + "JPY" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURJPY(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "JPY" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsUSDCHF(string symbol) + { + // + string symbolIdentifiers[] = { + "USD", + "CHF" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURCHF(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "CHF" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsGBPUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "GBP", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURGBP(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "GBP" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsAUDUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "AUD", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURAUD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "AUD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsUSDCAD(string symbol) + { + // + string symbolIdentifiers[] = { + "USD", + "CAD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURCAD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "CAD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsNZDUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "NZD", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURNZD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "NZD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + // Metals ... + + // + bool IsXAUUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "XAU", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsXAGUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "XAG", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + // Indexes ... + + // + bool IsDowJones(string symbol) + { + // + bool result = Contains( + "DowJones30", + symbol // + ); + + // + return result; + } + + // + // Oil ... + + // + bool IsBrent(string symbol) + { + // + bool result = Contains( + "BRENT", + symbol // + ); + + // + return result; + } + + // + // Symbol Finder ... + string GetEURUSDSymbol() + { + // + string result = NULL; + + // + string symbols[]; + int symbolsCount = GetAllSymbols( + symbols // + ); + if (!IsValidSize(symbolsCount)) + { + return result; + } + + // + for (int i = 0; i < symbolsCount; i++) + { + // + string iSymbol = symbols[i]; + if (IsEURUSD(iSymbol)) + { + // + result = iSymbol; + break; + } + } + + // + return result; + } +}; + +// +struct XSymbolSessionParser +{ + // + string version; // Temp ... + + // + // Check Market Is Open for Specific Symbol + // in Current Time ... + bool CanTrade( + string symbol // Trading Symbol + ) + { + // + bool result = false; + + // + result = IsValid(symbol); + if (!result) + { + return result; + } + + // + MqlDateTime timeStruct; + result = TimeCurrent(timeStruct); + if (!result) + { + return result; + } + + // + ENUM_DAY_OF_WEEK dayOfWeek = (ENUM_DAY_OF_WEEK)timeStruct.day_of_week; + + // + datetime cTime = TimeCurrent(); + + // + datetime from; + datetime to; + result = SymbolInfoSessionTrade( + symbol, + dayOfWeek, + 0, // Session Index ... + from, + to // + ); + if (!result) + { + return result; + } + + // + result = cTime > from && cTime < to; + + // + return result; + } +}; + +// +// Parsing Market Names ... +struct XMarketParser +{ + // + string _version; // Temp ... + + // + bool IsIngot(string market) + { + // + bool result = false; + + // + // result = IsValid(market) && + // market == ""; + + // + return result; + } + + // + bool IsErrante(string market) + { + // + bool result = false; + + // + // result = IsValid(market) && + // market == ""; + + // + return result; + } + + // + bool IsAMarkets(string market) + { + // + bool result = false; + + // + result = IsValid(market) && + market == "AMarkets LLC"; + + // + return result; + } + + // + bool IsIFCMarkets(string market) + { + // + bool result = false; + + // + // result = IsValid(market) && + // market == ""; + + // + return result; + } + + // + bool IsOtetMarkets(string market) + { + // + bool result = false; + + // + // result = IsValid(market) && + // market == ""; + + // + return result; + } + + // +}; + +// +// Styling Buffers ... + +// +struct XBufferPlotStyle +{ + // + int width; // Width + color clr; // Color + uchar arrow; // Arrow Code + ENUM_DRAW_TYPE type; // Type + ENUM_LINE_STYLE style; // Style + + // + // Constructor ... + XBufferPlotStyle() + { + Default(); + } + + // + // Tools ... + + // + // Default ... + void Default() + { + // + width = 1; + arrow = 0; + clr = CLR_NONE; + type = DRAW_NONE; + style = STYLE_SOLID; + } +}; + +// +// Register a Buffer as Indexed Buffer ... +void SetIndexBuffer( + int &index, // the Index refrence for Buffer + double &buffer[], // Buffer to Set + XBufferPlotStyle &style, // Style to Apply to Buffer + double &colorBuffer[], // Color Buffer + string label = NULL, // Buffer Label + bool showData = true, // Show Data on Data Window + double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value + int drawBegin = -1 // if Set More Than -1 applied +) +{ + // + // Set Buffer Index ... + SetIndexBuffer(index, buffer, INDICATOR_DATA); + + // + // Show Date ... + PlotIndexSetInteger(index, PLOT_SHOW_DATA, showData); + + // + // Set Buffer Label ... + if (IsValid(label)) + { + PlotIndexSetString(index, PLOT_LABEL, label); + } + + // + if (empty == 0 || empty == EMPTY_VALUE) + { + PlotIndexSetDouble(index, PLOT_EMPTY_VALUE, empty); + } + + // + if (drawBegin > -1) + { + PlotIndexSetInteger(index, PLOT_DRAW_BEGIN, drawBegin); + } + + // + if (style.type == DRAW_ARROW) + { + PlotIndexSetInteger(index, PLOT_ARROW, style.arrow); + } + + // + PlotIndexSetInteger(index, PLOT_LINE_STYLE, style.style); + PlotIndexSetInteger(index, PLOT_LINE_WIDTH, style.width); + + // + string drawTypeStr = EnumToString(style.type); + bool hasColorBuffer = Contains("COLOR", drawTypeStr); + + // + if (!hasColorBuffer) + { + PlotIndexSetInteger(index, PLOT_LINE_COLOR, style.clr); + } + else + { + // + // Since Color Buffers must add as next Index of it's own Buffer + // here before applied Color Buffer increase index ... + index++; + + // + SetIndexBuffer(index, colorBuffer, INDICATOR_COLOR_INDEX); + } + + // + // Increase Index for Next Buffer ... + index++; +} + +// +void SetIndexCandleBuffers( + int &index, // the Index refrence for Buffer + string openLabel, // Open Label + double &open[], // Open Buffer + string highLabel, // High Label + double &high[], // High Buffer + string lowLabel, // Low Label + double &low[], // Low Buffer + string closeLabel, // Close Label + double &close[], // Close Buffer + bool showData = true, // Show Data on Data Window + double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value + int drawBegin = -1 // if Set More Than -1 applied +) +{ + // + bool hasLabel = + // + IsValid(openLabel) && + IsValid(highLabel) && + IsValid(lowLabel) && + IsValid(closeLabel) + // + ; + + // + string label = + !hasLabel + ? NULL + : openLabel + ";" + highLabel + ";" + lowLabel + ";" + closeLabel; + + // + // Set Buffer Index ... + SetIndexBuffer(index, open, INDICATOR_DATA); + + // + // Set Draw Candles Type ... + PlotIndexSetInteger(index, PLOT_LINE_STYLE, DRAW_CANDLES); + + // + // Show Date ... + PlotIndexSetInteger(index, PLOT_SHOW_DATA, showData); + + // + // Set Buffer Label ... + if (IsValid(label)) + { + PlotIndexSetString(index, PLOT_LABEL, label); + } + + // + if (empty == 0 || empty == EMPTY_VALUE) + { + PlotIndexSetDouble(index, PLOT_EMPTY_VALUE, empty); + } + + // + if (drawBegin > -1) + { + PlotIndexSetInteger(index, PLOT_DRAW_BEGIN, drawBegin); + } + + // + index++; + + // + // Set Buffer Index ... + SetIndexBuffer(index, high, INDICATOR_DATA); + index++; + + // + // Set Buffer Index ... + SetIndexBuffer(index, low, INDICATOR_DATA); + index++; + + // + // Set Buffer Index ... + SetIndexBuffer(index, close, INDICATOR_DATA); + index++; +} + +// +void SetIndexCandleBuffers( + int &index, // the Index refrence for Buffer + string openLabel, // Open Label + double &open[], // Open Buffer + string highLabel, // High Label + double &high[], // High Buffer + string lowLabel, // Low Label + double &low[], // Low Buffer + string closeLabel, // Close Label + double &close[], // Close Buffer + double &colorBuffer[], // Candle Color Buffer + bool showData = true, // Show Data on Data Window + double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value + int drawBegin = -1 // if Set More Than -1 applied +) +{ + // + SetIndexCandleBuffers( + index, + openLabel, + open, + highLabel, + high, + lowLabel, + low, + closeLabel, + close, + showData, + empty, + drawBegin // + ); + + // + int mFirstIndex = index - 4; + + // + // Set Draw Candles Type ... + PlotIndexSetInteger(mFirstIndex, PLOT_LINE_STYLE, DRAW_COLOR_CANDLES); + + // + // Set Color Buffer ... + SetIndexBuffer(index, colorBuffer, INDICATOR_COLOR_INDEX); + + // + index++; +} + +// +// Functions ... + +// +// Validators ... + +// +// Validate an String has length and not NULL ... +bool IsValid(string value) +{ + // + bool result = false; + + // + result = + // + value != NULL && + StringLen(value) > 0 + // + ; + + // + return result; +} +bool IsSpecifiedValid(string value) +{ + return IsValid(value); +} + +// +// Validate a Date ... +bool IsValid(datetime value) +{ + // + bool result = false; + + // + result = NotEmpty(value) && value != NULL; + + // + return result; +} +bool IsSpecifiedValid(datetime value) +{ + return IsValid(value); +} + +// +// Validate a Period Param ... +bool IsValid(ENUM_TIMEFRAMES value) +{ + // + bool result = false; + + // + result = + // + value != NULL + // + ; + + // + return result; +} +bool IsSpecifiedValid(ENUM_TIMEFRAMES value) +{ + // + return IsValid(value); +} + +// +// Validate Specified Cycle ... +bool IsValid(ENUM_X_MARKET_CYCLES value) +{ + // + bool result = false; + + // + result = + // + value != NULL && + value != X_MARKET_CYCLE_UNKNOWN + // + ; + + // + return result; +} + +// +// Validate Specific Period Mode ... +bool IsValid( + ENUM_X_PERIOD_METHOD mMethod, // Period Select Method + ENUM_TIMEFRAMES mPeriod // Selected Period +) +{ + // + bool result = false; + + // + result = + // + mMethod == X_PERIOD_NOTHING + ? false + : mMethod == X_PERIOD_MANUALLY + ? mPeriod != NULL + : mMethod == X_PERIOD_AUTO + ? true + : false + // + ; + + // + return result; +} + +// +bool IsSpecifiedValid( + ENUM_X_PERIOD_METHOD mMethod, // Period Select Method + ENUM_TIMEFRAMES mPeriod // Selected Period +) +{ + return IsValid(mMethod, + mPeriod // + ); +} + +// +// Validate Swing Mode ... +bool IsValid(ENUM_X_SWING_TYPE value) +{ + // + bool result = false; + + // + result = + // + value == X_SWING_HIGH || + value == X_SWING_LOW + // + ; + + // + return result; +} + +// +// As IS ... + +// +// Determine a Position type is Long or not ... +bool IsLong(ENUM_POSITION_TYPE type) +{ + // + bool result = type == POSITION_TYPE_BUY; + + // + return result; +} +bool IsLong(ENUM_ORDER_TYPE type) +{ + // + bool result = type == ORDER_TYPE_BUY; + + // + return result; +} + +// +// Determine a Position type is Short or not ... +bool IsShort(ENUM_POSITION_TYPE type) +{ + // + bool result = type == POSITION_TYPE_SELL; + + // + return result; +} +bool IsShort(ENUM_ORDER_TYPE type) +{ + // + bool result = type == ORDER_TYPE_SELL; + + // + return result; +} + +// +// Retrieve Opposit Direction Type ... +ENUM_POSITION_TYPE GetOpposit(ENUM_POSITION_TYPE type) +{ + // + ENUM_POSITION_TYPE result = NULL; + + // + bool isLong = IsLong(type); + result = isLong + ? POSITION_TYPE_SELL + : POSITION_TYPE_BUY; + + // + return result; +} +ENUM_ORDER_TYPE GetOpposit(ENUM_ORDER_TYPE type) +{ + // + ENUM_ORDER_TYPE result = NULL; + + // + bool isLong = IsLong(type); + result = isLong + ? ORDER_TYPE_SELL + : ORDER_TYPE_BUY; + + // + return result; +} + +// +string ToString(ENUM_POSITION_TYPE value) +{ + // + string result = NULL; + + // + result = + // + IsLong(value) + ? "Long" + : "Short" + // + ; + + // + return result; +} +string ToString(ENUM_ORDER_TYPE value) +{ + // + string result = NULL; + + // + result = + // + IsLong(value) + ? "Long" + : "Short" + // + ; + + // + return result; +} + +// +// Check Expert Running in Testing Mode or not ... +bool IsRunningOnTestMode() +{ + // + bool result = false; + + // + // check programm mode ... + result = MQL5InfoInteger(MQL5_TESTING); + + // + return result; +} + +// +// Find Chart ID ... +long FindChartID( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL // Trading Period +) +{ + // + long result = ChartFirst(); + long first = result; + + // + while (result > 0) + { + // + string chSymbol = ChartSymbol(result); + ENUM_TIMEFRAMES chPeriod = ChartPeriod(result); + + // + bool isOwn = + // + chSymbol == mSymbol && + chPeriod == mPeriod + // + ; + if (isOwn) + { + break; + } + + // + result = ChartNext(result); + } + + // + return result; +} + +// +// Normalizers ... + +// +// Check a Symbol provided or not ... +// if not use Default ... +string NormalizeSymbol(string value) +{ + // + string result = value; + + // + if (!IsValid(result)) + { + result = _Symbol; + } + + // + return result; +} + +// +// Check a Datetime provided or not ... +// if not use Current ... +datetime NormalizeTime(datetime value) +{ + // + datetime result = value; + + // + if (!IsValid(result)) + { + result = TimeCurrent(); + } + + // + return result; +} + +// +// Check a Period provided or not ... +// if not use Default ... +ENUM_TIMEFRAMES NormalizePeriod(ENUM_TIMEFRAMES value) +{ + // + ENUM_TIMEFRAMES result = value; + + // + if (!IsValid(value)) + { + result = _Period; + } + + // + return result; +} + +// +// Normalize Cycle ... +ENUM_X_MARKET_CYCLES NormalizeCycle(ENUM_X_MARKET_CYCLES value) +{ + // + ENUM_X_MARKET_CYCLES result = value; + + // + if (!IsValid(result)) + { + result = X_MARKET_CYCLE_SHORT; + } + + // + return value; +} + +// +// Validate a Buffer Size for Looping or etc ... +bool IsValidSize(int size) +{ + // + bool result = size > 0; + + // + return result; +} + +template +bool IsValidSize(T &buffer[]) +{ + // + bool result = false; + + // + result = + // + IsValidSize(ArraySize(buffer)) + // + ; + + // + return result; +} + +// +// Check a Given Index is Valid or not ... +bool IsValidIndex(int index) +{ + return index >= 0; +} + +// +// Normalize Index Based On Specified Buffer ... +template +void NormalizeIndex( + int &index, + T &buffer[] // +) +{ + // + int bufferSize = ArraySize(buffer); + + // + if (bufferSize <= 0) + { + index = 0; + } + + // + if (index <= 0) + { + index = 0; + } + + // + if (index > bufferSize - 1) + { + index = bufferSize - 1; + } +} + +// +// Normalize Start and Count based on Specified Buffer ... +template +void NormalizeCount( + int &start, + int &count, + T &buffer[] // +) +{ + // + // Validate Buffer Size ... + int bufferSize = ArraySize(buffer); + if (!IsValidSize(bufferSize)) + { + return; + } + + // + // Normalization Start ... + NormalizeIndex( + start, + buffer // + ); + + // + if (count < start) + { + count = (start - count); + } + + // + // Normalization Count ... + + // + if (count < 0) + { + count = start; + } + + // + if (count > bufferSize) + { + count = bufferSize; + } +} + +// +// Normalize a give Volume ... +double NormalizeVolume( + double mVolume, // desired volume to normalize + string mSymbol = NULL, // Trading Symbol + int mLength = 2 // Length of Digits +) +{ + // + double result = mVolume; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + // Normalize Digits ... + int digits = GetDigits(mSymbol); + + // + mLength = + mLength == 0 || mLength > digits + ? digits + : MathMin(mLength, digits); + + // + // Normalize Volume ... + result = NormalizeDouble(result, mLength); + + // + double maxAvailableVolume = SymbolInfoDouble(mSymbol, SYMBOL_VOLUME_MAX); + double minAvailableVolume = SymbolInfoDouble(mSymbol, SYMBOL_VOLUME_MIN); + + // + // Validate Result ... + if (result > maxAvailableVolume) + { + result = maxAvailableVolume; + } + else if (result < minAvailableVolume) + { + result = minAvailableVolume; + } + + // + return result; +} + +// +// Normallize Price ... +double NormalizePrice( + double mPrice, // desired Price for normalization + string mSymbol = NULL // Trading Symbol +) +{ + // + double result = 0; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + double tickSize = 0; + result = SymbolInfoDouble(mSymbol, SYMBOL_TRADE_TICK_SIZE, tickSize); + + // + int digits = GetDigits(mSymbol); + result = NormalizeDouble(MathRound(mPrice / tickSize) * tickSize, digits); + + // + return result; +} + +// +// Prices ... + +// +// Retrieve Ask Price ... +double GetAsk( + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + + // + double result = SymbolInfoDouble(mSymbol, SYMBOL_ASK); + + // + return result; +} + +// +// Retrieve Bid Price ... +double GetBid( + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + + // + double result = SymbolInfoDouble(mSymbol, SYMBOL_BID); + + // + return result; +} + +// +// Retrieve Spread Price ... +double GetSpread( + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + + // + double ask = GetAsk(mSymbol); + double bid = GetBid(mSymbol); + + // + double result = MathAbs(ask - bid); + + // + return result; +} + +// +// Retrieve Point Value ... +double GetPoints( + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + + // + double result = SymbolInfoDouble(mSymbol, SYMBOL_POINT); + + // + return result; +} + +// +// Retrieve Point Digits ... +int GetDigits( + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + + // + int result = (int)SymbolInfoInteger(mSymbol, SYMBOL_DIGITS); + + // + return result; +} + +// +// Retrieve Entry Price ... +double GetEntry( + string mSymbol = NULL, // Trading Symbol + ENUM_POSITION_TYPE type = POSITION_TYPE_BUY // Get entry price for Which direction trade ... +) +{ + // + double result = 0; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + result = + IsLong(type) + ? GetAsk(mSymbol) + : GetBid(mSymbol); + result = NormalizePrice(result, mSymbol); + + // + return result; +} + +// +// Retrieve Exit Price ... +double GetExit( + string mSymbol = NULL, // Trading Symbol + ENUM_POSITION_TYPE type = POSITION_TYPE_BUY // Get entry price for Which direction trade ... +) +{ + // + double result = 0; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + result = + IsLong(type) + ? GetBid(mSymbol) + : GetAsk(mSymbol); + result = NormalizePrice(result, mSymbol); + + // + return result; +} + +// +// Get 1 Pip in Price Value ... +double GetPipPrice( + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + + // + double symbolPoint = GetPoints(mSymbol); + int symbolDigits = GetDigits(mSymbol); + + // + double result = symbolPoint; + if (symbolDigits == 3 || symbolDigits == 5) + { + result *= 10; + } + + // + return result; +} + +// +// Converts Pips To Price ... +double PipsToPrice( + double mPips, // pips amount + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + + // + int digits = GetDigits(mSymbol); + double pipValue = GetPipPrice(mSymbol); + double result = mPips * pipValue; + + // + result = NormalizePrice(result, mSymbol); + + // + return result; +} + +// +// Converts Price to Pips ... +double PriceToPips( + double mPrice, // the price amount which required to calculate + string mSymbol = NULL // Trading Symbol +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + mPrice = NormalizePrice(mPrice, mSymbol); + + // + int digits = GetDigits(mSymbol); + double pipPrice = GetPipPrice(mSymbol); + + // + double result = mPrice / pipPrice; + + // + result = NormalizeDouble(result, digits); + + // + return result; +} + +// +// Convert Price to Point ... +double PriceToPoint( + double price, // the price amount which required to calculate + string mSymbol = NULL // Trading Symbol +) +{ + // + double result = 0; + + // + mSymbol = NormalizeSymbol(mSymbol); + price = NormalizePrice(price, mSymbol); + + // + double point = GetPoints(mSymbol); + result = price / point; + + // + return result; +} + +// +// Converts Point to Price ... +double PointToPrice( + double points, // Points Amount + string mSymbol = NULL // Trading Symbol +) +{ + // + double result = 0; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + double point = GetPoints(mSymbol); + result = points * point; + + // + result = NormalizePrice(result, mSymbol); + + // + return result; +} + +// +// Converts Series Mode to XPRICE ... +ENUM_X_PRICE ToPrice( + ENUM_SERIESMODE mMode // Specified Series Mode ... +) +{ + // + ENUM_X_PRICE result = X_PRICE_CLOSE; + + // + switch (mMode) + { + // + // High ... + case MODE_HIGH: + result = X_PRICE_HIGH; + break; + + // + // Open ... + case MODE_OPEN: + result = X_PRICE_OPEN; + break; + + // + // Low ... + case MODE_LOW: + result = X_PRICE_LOW; + break; + + // + // Close ... + // Default ... + case MODE_CLOSE: + default: + result = X_PRICE_CLOSE; + break; + } + + // + return result; +} + +// +// Retrieve Applied Price ... +template +double GetAppliedPrice( + ENUM_APPLIED_PRICE tprice, // Type of Price Selection + T &open[], // Open Prices + T &high[], // High Preices + T &low[], // Low Prices + T &close[], // Close Prices + int i // Bar Index +) +{ + switch (tprice) + { + case PRICE_CLOSE: + return (close[i]); + case PRICE_OPEN: + return (open[i]); + case PRICE_HIGH: + return (high[i]); + case PRICE_LOW: + return (low[i]); + case PRICE_MEDIAN: + return ((high[i] + low[i]) / 2.0); + case PRICE_TYPICAL: + return ((high[i] + low[i] + close[i]) / 3.0); + case PRICE_WEIGHTED: + return ((high[i] + low[i] + close[i] + close[i]) / 4.0); + } + return (0); +} + +// +double iGetPrice( + int tprice, + double open, + double high, + const double low, + const double close // +) +{ + // + switch (tprice) + { + case PRICE_CLOSE: + return (close); + case PRICE_OPEN: + return (open); + case PRICE_HIGH: + return (high); + case PRICE_LOW: + return (low); + case PRICE_MEDIAN: + return ((high + low) / 2.0); + case PRICE_TYPICAL: + return ((high + low + close) / 3.0); + case PRICE_WEIGHTED: + return ((high + low + close + close) / 4.0); + } + + // + return (0); +} + +// +// Calculate TP/SL for Specified Type of Positions ... +void CalculateTPSL( + double &mSL, // Hold SL + double &mTP, // Hold TP + ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) + double mEntry, // Entry Price + double mR2R = 1, // Provided Risk To Reward Ratio + double slPrice = 0, // Provided SL Price + double tpPrice = 0, // Provided TP Price + double priceToRisk = 0, // If Entry equal to Provided SL Price Risk Point + double priceToReward = 0 // If Entry equal to Provided TP Price Reward Point +) +{ + // + // if Both TP and SL Provided, ignore R2R and Calculate direct ... + // if SL provided, Calculate TP based on Provided R2R ... + // if TP provided, Calculate SL based on Provided R2R ... + // default R2R is set to 1 ... + + // + mSL = 0; + mTP = 0; + + // + bool isLong = IsLong(mType); + + // + // Set Default R2R ... + if (mR2R < 1) + { + mR2R = 1; + } + + // + if (mEntry <= 0 || + (tpPrice <= 0 && slPrice <= 0)) + { + return; + } + + // + double risk = 0; + double reward = 0; + + // + bool canCalculateBasedOnSL = slPrice > 0 && + (isLong + ? slPrice <= mEntry + : slPrice >= mEntry); + + // + bool canCalculateBasedOnTP = tpPrice > 0 && + (isLong + ? tpPrice >= mEntry + : tpPrice <= mEntry); + + // + if (canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + // + risk = MathAbs(mEntry - slPrice); + if (risk == 0) + { + risk = priceToRisk; + } + reward = risk * mR2R; + } + else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + reward = MathAbs(mEntry - tpPrice); + if (reward == 0) + { + reward = priceToReward; + } + risk = reward / mR2R; + } + else if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + // + bool canSetTPPrice = isLong + ? tpPrice > mEntry + : tpPrice < mEntry; + if (canSetTPPrice) + { + mTP = tpPrice; + } + + // + bool canSetSLPrice = isLong + ? slPrice < mEntry + : slPrice > mEntry; + if (canSetSLPrice) + { + mSL = slPrice; + } + + // + return; + } + else if (canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + bool canSetTPPrice = isLong + ? tpPrice > mEntry + : tpPrice < mEntry; + if (canSetTPPrice) + { + mTP = tpPrice; + } + + // + bool canSetSLPrice = isLong + ? slPrice < mEntry + : slPrice > mEntry; + if (canSetSLPrice) + { + mSL = slPrice; + } + + // + return; + } + + // + mTP = isLong + ? mEntry + reward + : mEntry - reward; + + // + mSL = isLong + ? mEntry - risk + : mEntry + risk; +} + +// +bool CalculateTPSLByPoint( + double &mSL, // Hold SL + double &mTP, // Hold TP + ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) + double mEntry, // Entry Price + double mPointValue, // Point Value + double mR2R = 1, // Provided Risk To Reward Ratio + double slPoint = 0, // Provided SL Point + double tpPoint = 0 // Provided TP Point +) +{ + // + bool result = false; + + // + mSL = 0; + mTP = 0; + + // + bool isLong = IsLong(mType); + + // + // Set Default R2R ... + if (mR2R < 1) + { + mR2R = 1; + } + + // + if (mEntry <= 0 || + mPointValue <= 0 || + (slPoint <= 0 && tpPoint <= 0)) + { + return result; + } + + // + double risk = 0; + double reward = 0; + + // + bool canCalculateBasedOnSL = slPoint > 0; + + // + bool canCalculateBasedOnTP = tpPoint > 0; + + // + if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + return result; + } + + // + if (canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + reward = tpPoint * mPointValue; + risk = slPoint * mPointValue; + } + else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + reward = tpPoint * mPointValue; + risk = reward / mR2R; + } + else if (canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + // + risk = slPoint * mPointValue; + reward = risk * mR2R; + } + + // + result = risk > 0 && reward > 0; + if (!result) + { + return result; + } + + // + mTP = isLong + ? mEntry + reward + : mEntry - reward; + + // + mSL = isLong + ? mEntry - risk + : mEntry + risk; + + // + return result; +} + +// +bool CalculateTPSLByPrice( + double &mSL, // Hold SL + double &mTP, // Hold TP + ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) + double mEntry, // Entry Price + double mR2R = 1 // Provided Risk To Reward Ratio +) +{ + // + bool result = false; + + // + bool isLong = IsLong(mType); + + // + // Set Default R2R ... + if (mR2R < 1) + { + mR2R = 1; + } + + // + if (mEntry <= 0 || + (mSL <= 0 && mTP <= 0)) + { + return result; + } + + // + double risk = 0; + double reward = 0; + + // + bool canCalculateBasedOnSL = mSL > 0; + bool canCalculateBasedOnTP = mTP > 0; + + // + if ( + !canCalculateBasedOnSL && + !canCalculateBasedOnTP) + { + return result; + } + + // + if (!canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + reward = MathAbs(mTP - mEntry); + risk = reward / mR2R; + } + else if (canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + // + risk = MathAbs(mEntry - mSL); + reward = risk * mR2R; + } + + // + result = risk > 0 && reward > 0; + if (!result) + { + return result; + } + + // + mTP = isLong + ? mEntry + reward + : mEntry - reward; + + // + mSL = isLong + ? mEntry - risk + : mEntry + risk; + + // + return result; +} + +/** + * Retrieve Current Tick ... + */ +bool GetTick( + string mSymbol, + MqlTick &tick // +) +{ + return SymbolInfoTick(mSymbol, tick); +} + +/** + * Retrieve Tick Entry ... + */ +double GetTickEntry( + MqlTick &mTick, + ENUM_POSITION_TYPE type, + string mSymbol = NULL // +) +{ + // + double result = 0; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + result = + IsLong(type) + ? mTick.ask + : mTick.bid; + result = NormalizePrice(result, mSymbol); + + // + return result; +} + +/** + * Retrieve Tick Exit ... + */ +double GetTickExit( + MqlTick &mTick, + ENUM_POSITION_TYPE type, + string mSymbol = NULL // +) +{ + // + double result = 0; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + result = + IsLong(type) + ? mTick.bid + : mTick.ask; + result = NormalizePrice(result, mSymbol); + + // + return result; +} + +/** + * Calculate Momentum Changes based on Given Price + */ +double CalculateMomentum( + double currentPrice, + double previousPrice // +) +{ + // + double result = 0; + + // + return result; +} + +/** + * Detect Possible Momentum Changes + * Using MqlTick ... + */ +bool DetectMomentumChange( + ENUM_POSITION_TYPE type, + string mSymbol = NULL, + int mLength = 14 // +) +{ + // + bool result = false; + + // + mSymbol = NormalizeSymbol(mSymbol); + + // + MqlTick ticks[]; + int copied = CopyTicks( + mSymbol, + ticks, + COPY_TICKS_ALL, + 0, + mLength + 1 // + ); + + // + result = copied > mLength; + if (!result) + { + return result; + } + + // + double previousPrice = GetTickExit( + ticks[mLength], + type, + mSymbol // + ); + for (int i = mLength - 1; i >= 0; i--) + { + // + double currentPrice = GetTickExit( + ticks[i], + type, + mSymbol // + ); + + // + double momentum = CalculateMomentum( + currentPrice, + previousPrice // + ); + + // + if (fabs(momentum) > 1.0) + { + // + result = true; + break; + } + } + + // + return result; +} + +// +// Symbols ... + +// +// Retrieve Available Symbols ... +int GetAllSymbols( + string &symbols[], // Hold Result + bool onlyInWatchList = false, // Specified Retrieve only Symbols which in Watch List + bool forceClean = true // Force To Clean Result Array +) +{ + // + int result = 0; + + // + if (forceClean) + { + Clean(symbols); + } + + // + int beforeSize = ArraySize(symbols); + + // + int symbolsCount = SymbolsTotal(onlyInWatchList); + if (symbolsCount <= 0) + { + return result; + } + + // + for (int i = 0; i < symbolsCount; i++) + { + // + string iSymbol = SymbolName( + i, + onlyInWatchList + // + ); + if (!IsValid(iSymbol)) + { + continue; + } + + // + Add( + iSymbol, + symbols + // + ); + } + + // + int afterSize = ArraySize(symbols); + + // + result = afterSize - beforeSize; + + // + return result; +} + +// +// This is a Global Way to Filter Symbols +// you can pass Specific string as Query or a List String for Filtering ... +int FilterSymbols( + string query, // Which Query to Search Symbol + string &symbols[], // Hold Result + bool onlyInWatchList = false, // Specified Retrieve only Symbols which in Watch List + bool forceClean = true, // Force To Clean Result Array + bool ignoreCase = true, // Ignore Case + string querySeparator = "," // If Provided means query is a COllection of Queries and need to be Splitted +) +{ + // + int result = 0; + + // + if (forceClean) + { + Clean(symbols); + } + + // + if (!IsValid(query)) + { + return result; + } + + // + // Check Query is an String array or not ... + string mQueries[]; + int queriesCount = 0; + if (IsValid(querySeparator) && Contains(querySeparator, query, true)) + { + // + queriesCount = SplitContent( + mQueries, + query, + querySeparator + // + ); + } + + // + int beforeSize = ArraySize(symbols); + + // + string allSymbols[]; + int allSymbolsCount = GetAllSymbols( + allSymbols, + onlyInWatchList, + forceClean); + if (allSymbolsCount <= 0) + { + return result; + } + + // + // Loop Through all Symbols ... + for (int i = 0; i < allSymbolsCount; i++) + { + // + string iSymbol = allSymbols[i]; + + // + bool isFilterPassed = false; + if (queriesCount == 0) + { + // + isFilterPassed = Contains( + query, + iSymbol, + ignoreCase + // + ); + } + else if (queriesCount > 0) + { + // + isFilterPassed = Contains( + mQueries, + iSymbol, + ignoreCase + // + ); + } + + // + if (isFilterPassed) + { + // + Add( + iSymbol, + symbols + // + ); + } + } + + // + int afterSize = ArraySize(symbols); + + // + result = afterSize - beforeSize; + + // + return result; +} + +// +int FilterUSDSymbols( + string &symbols[], // Hold Result + bool onlyInWatchList = false, // Specified Retrieve only Symbols which in Watch List + bool forceClean = true, // Force To Clean Result Array + bool ignoreCase = true, // Ignore Case + string querySeparator = "," // If Provided means query is a COllection of Queries and need to be Splitted +) +{ + // + return FilterSymbols( + "USD", + symbols, + onlyInWatchList, + forceClean, + ignoreCase, + querySeparator + // + ); +} + +// +// Time / Date ... + +// +// Representation of Time Struct ... +// struct MqlDateTime +// { +// int year; // Year +// int mon; // Month +// int day; // Day +// int hour; // Hour +// int min; // Minutes +// int sec; // Seconds +// int day_of_week; // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) +// int day_of_year; // Day number of the year (January 1st is assigned the number value of zero) +// }; + +// +// Converts Time to Seconds ... +ulong TimeToSeconds( + datetime time // Specify time to Convert ... +) +{ + // + ulong result = (ulong)time; + + // + return result; +} +ulong TimeToSeconds( + MqlDateTime &time // Specify time to Convert ... +) +{ + // + datetime dTime = StructToTime(time); + + // + ulong result = TimeToSeconds(dTime); + + // + return result; +} + +// +// Converts Seconds To Time ... +datetime SecondsToTime( + ulong seconds // Specify Seconds to Convert ... +) +{ + // + datetime result = (datetime)seconds; + + // + return result; +} +MqlDateTime SecondsToStruct( + ulong seconds // Specify Seconds to Convert ... +) +{ + // + datetime dTime = SecondsToTime(seconds); + + // + MqlDateTime result = {}; + TimeToStruct( + dTime, + result); + + // + return result; +} + +// +// Converts Time to MilliSeconds ... +ulong TimeToMilliSeconds( + datetime time // Specify time to Convert ... +) +{ + // + ulong result = TimeToSeconds(time) * 1000; + + // + return result; +} +ulong TimeToMilliSeconds( + MqlDateTime &time // Specify time to Convert ... +) +{ + // + datetime dTime = StructToTime(time); + + // + ulong result = TimeToMilliSeconds(dTime); + + // + return result; +} + +// +// Converts MillisSeconds to Time ... +datetime MilliSecondsToTiem( + ulong milliSeconds // Specify MilliSeconds to Convert ... +) +{ + // + ulong seconds = milliSeconds / 1000; + + // + datetime result = SecondsToTime(seconds); + + // + return result; +} +MqlDateTime MilliSecondsToStruct( + ulong milliSeconds // Specify MilliSeconds to Convert ... +) +{ + // + datetime dTime = MilliSecondsToTiem(milliSeconds); + + // + MqlDateTime result = {}; + TimeToStruct( + dTime, + result); + + // + return result; +} + +// +// Retrieve DateTime Structure ... +MqlDateTime GetCurrentTime() +{ + // + MqlDateTime result = {}; + + // + datetime cTime = TimeCurrent(); + TimeToStruct(cTime, result); + + // + return result; +} + +// +// Retrieve Current Time as Seconds ... +ulong GetCurrentTimeAsSeconds() +{ + // + datetime time = TimeCurrent(); + + // + ulong result = TimeToSeconds(time); + + // + return result; +} + +// +// Retrieve Current Time as MilliSeconds ... +ulong GetCurrentTimeAsMilliSeconds() +{ + // + datetime time = TimeCurrent(); + + // + ulong result = TimeToMilliSeconds(time); + + // + return result; +} + +// +int GetLocalOffset() +{ + // + MqlDateTime cTimeStruct; + datetime cTime = TimeCurrent(cTimeStruct); + + // + MqlDateTime cLTimeStruct; + datetime cLTime = TimeLocal(cLTimeStruct); + + // + cTimeStruct.sec = 0; + cTime = StructToTime(cTimeStruct); + + // + cLTimeStruct.sec = 0; + cLTime = StructToTime(cLTimeStruct); + + // + int result = ((int)cLTime - (int)cTime); + + // + return result; +} + +// +int GetUTCRequiredTimeOffset() +{ + // + int utcOffset = TimeGMTOffset(); + int localOffset = GetLocalOffset(); + + // + int result = utcOffset + localOffset; + + // + return result; +} + +// +datetime GetUTCTime( + datetime time = NULL, + bool applyTradeServerTime = false // +) +{ + // + datetime result = NULL; + + // + NormalizeTime(time); + + // + datetime cTime = TimeCurrent(); + datetime cTimeLocal = TimeLocal(); + + // + int cLocalOffset = ((int)cTimeLocal - (int)cTime); + int gmtOffset = TimeGMTOffset(); + int offsetDelte = gmtOffset + cLocalOffset; + int requiredUTCOffset = GetUTCRequiredTimeOffset(); + if (requiredUTCOffset > 0) + { + requiredUTCOffset = -1 * requiredUTCOffset; + } + + // + int timeSeconds = (int)time; + int resultSeconds = timeSeconds + requiredUTCOffset; + + // + result = (datetime)(resultSeconds); + + // + return result; +} + +// +// Retrieve only Hour and Minute as String ... +string GetTimeString( + datetime time = NULL // +) +{ + // + NormalizeTime(time); + + // + string result = NULL; + + // + MqlDateTime tStruct; + bool isStructed = TimeToStruct(time, tStruct); + if (!isStructed) + { + return result; + } + + // + string hour = ToString(tStruct.hour); + hour = + StringLen(hour) == 1 + ? "0" + hour + : hour; + + // + string minute = ToString(tStruct.min); + minute = + StringLen(minute) == 1 + ? "0" + minute + : minute; + + // + result = hour + ":" + minute; + + // + return result; +} + +// +// Converts a Date time to File Format ... +string ToFormatString( + datetime mTime, + string separator = "_" // +) +{ + // + string result = NULL; + + // + if (!IsValid(mTime)) + { + return result; + } + + // + MqlDateTime timeStruct; + bool isConverts = TimeToStruct( + mTime, + timeStruct // + ); + if (!isConverts) + { + return result; + } + + // + string year = ToString(timeStruct.year); + string month = ToString(timeStruct.mon); + string day = ToString(timeStruct.day); + string hour = ToString(timeStruct.hour); + string minute = ToString(timeStruct.min); + string second = ToString(timeStruct.sec); + + // + result = + // + // Year ... + year + separator + + // + // Month ... + (StringLen(month) == 1 + ? "0" + month + : month) + + separator + + // + // Day ... + (StringLen(day) == 1 + ? "0" + day + : day) + + separator + + // + // Hour ... + (StringLen(hour) == 1 + ? "0" + hour + : hour) + + separator + + // + // Minute ... + (StringLen(minute) == 1 + ? "0" + minute + : minute) + + separator + + // + // Seconds ... + (StringLen(second) == 1 + ? "0" + second + : second) + + separator + + // + "" + // + ; + + // + return result; +} + +// +// Check Specific Time in Range of another Time ... +bool IsTimeInRange( + datetime currentTime = NULL, + datetime startTime = NULL, + datetime stopTime = NULL // +) +{ + // + bool result = false; + + // + // Normallize Current Time ... + NormalizeTime(currentTime); + + // + result = !IsValid(startTime) && + !IsValid(stopTime); + if (result) + { + return result; + } + + // + result = IsValid(startTime) && + IsValid(stopTime); + if (!result) + { + // + result = IsValid(startTime) && + currentTime >= startTime; + + // + return result; + } + + // + result = currentTime >= startTime && + currentTime < stopTime; + + // + return result; +} + +// +// Bar Times ... + +// +// Retrieve Specified Bar Time ... +datetime GetBarTime( + string mSymbol = "", // Specify Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame + int barIndex = 0 // Specify Bar Index +) +{ + // + // Validate and Normalize Args ... + + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + // Retrieve Bar Time ... + datetime result = iTime( + mSymbol, + mPeriod, + barIndex); + + // + return result; +} + +// +// Retrieve Specified Bar Time ... +ulong GetBarTimeAsSeconds( + string mSymbol = "", // Specify Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame + int barIndex = 0 // Specify Bar Index +) +{ + // + // Retrieve Bar Time ... + datetime time = GetBarTime( + mSymbol, + mPeriod, + barIndex); + + // + ulong result = TimeToSeconds(time); + + // + return result; +} + +// +// Retrieve Specified Bar Time ... +ulong GetBarTimeAsMilliSeconds( + string mSymbol = "", // Specify Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame + int barIndex = 0 // Specify Bar Index +) +{ + // + // Retrieve Bar Time ... + datetime time = GetBarTime( + mSymbol, + mPeriod, + barIndex); + + // + ulong result = TimeToMilliSeconds(time); + + // + return result; +} + +// +// Retrieve a Bar Time Structure ... +MqlDateTime GetBarTimeStruct( + string mSymbol = "", // Specify Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame + int barIndex = 0 // Specify Bar Index +) +{ + // + MqlDateTime result = {}; + + // + // Retrieve Bar Time ... + datetime barTime = GetBarTime( + mSymbol, + mPeriod, + barIndex); + + // + // Convert to Structure ... + TimeToStruct(barTime, result); + + // + return result; +} + +// +// Retrieve Last Available Bar Time of +// Dest Period inside Source Period ... +datetime GetLastBarTime( + ENUM_TIMEFRAMES sourcePeriod, + ENUM_TIMEFRAMES destPeriod // +) +{ + // + datetime result = NULL; + + // + if (!IsValid(sourcePeriod) || + !IsValid(destPeriod)) + { + return result; + } + + // + int sourceSeconds = PeriodSeconds(sourcePeriod); + int destSeconds = PeriodSeconds(destPeriod); + if (sourceSeconds < destSeconds) + { + return result; + } + + // + XOHCL sourceBar; + bool isInited = sourceBar.Init( + _Symbol, + sourcePeriod, + 0 // + ); + if (!isInited) + { + return result; + } + + // + result = (datetime)((((int)sourceBar.time) + sourceSeconds) - destSeconds); + + // + return result; +} + +// +// Other Tools ... + +// +template +bool IsSame( + T &buffer[], // Search Buffer + int count = 5, // Number of Searchs + int start = 0 // Start ... +) +{ + // + bool result = false; + + // + int bufferSize = ArraySize(buffer); + result = bufferSize > 0; + if (!result) + { + return result; + } + + // + // Validate Count ... + result = start + count < bufferSize; + if (!result) + { + return result; + } + + // + T iTem = buffer[start]; + for (int i = start; i < start + count; i++) + { + // + if (iTem != buffer[i]) + { + result = false; + break; + } + + // + if (!result) + { + result = true; + } + } + + // + return result; +} + +// +// Check first Cross Over second at index ... +bool IsCrossedOver( + const double &first[], // the buffer which check crossing over second buffer + const double &second[], // first buffer checks based on this buffer + const int index = 0 // check crosses in specific index +) +{ + // + bool result = false; + + // + // Validate Args ... + if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) + { + return result; + } + + // + result = first[index] > second[index] && + !(first[index + 1] > second[index + 1]); + + // + return result; +} + +// +// Check first is Over second at index ... +bool IsOver( + const double &first[], // the buffer which check over second buffer + const double &second[], // first buffer checks based on this buffer + const int index = 0 // check crosses in specific index +) +{ + // + bool result = false; + + // + // Validate Args ... + if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) + { + return result; + } + + // + result = first[index] > second[index] && + first[index + 1] > second[index + 1]; + + // + return result; +} + +// +// Check first Cross Under second at index ... +bool IsCrossedUnder( + const double &first[], // the buffer which check crossing under second buffer + const double &second[], // first buffer checks based on this buffer + const int index = 0 // check crosses in specific index +) +{ + // + bool result = false; + + // + // Validate Args ... + if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) + { + return result; + } + + // + result = first[index] < second[index] && + !(first[index + 1] < second[index + 1]); + + // + return result; +} + +// +// Check first is Under second at index ... +bool IsUnder( + const double &first[], // the buffer which check under second buffer + const double &second[], // first buffer checks based on this buffer + const int index = 0 // check crosses in specific index +) +{ + // + bool result = false; + + // + // Validate Args ... + if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) + { + return result; + } + + // + result = first[index] < second[index] && + first[index + 1] < second[index + 1]; + + // + return result; +} + +// +// Check if a Value Increasing in Loopback ... +bool IsIncreasing( + const int from, // Last Time Index + const int to, // Fisrs Tima Index + const double &buffer[] // the Buffer which required to search +) +{ + // + bool result = false; + + // + // Validate Args ... + if ( + from <= to || + ArraySize(buffer) < from + 1) + { + return result; + } + + // + // Loop through Items ... + double toValue = buffer[to]; + double fromValue = buffer[from]; + result = toValue > fromValue; + for (int i = to + 1; i <= from - 1; i++) + { + // + double iValue = buffer[i]; + bool isPassed = toValue >= iValue; + + // + bool isIIncreasing = IsIncreasing( + from, + i, + buffer); + + // + // Check Result ... + result = result && isPassed && isIIncreasing; + if (!result) + { + break; + } + } + + // + return result; +} + +// +// Check if a Value Decreasing in Loopback ... +bool IsDecreasing( + const int from, // Last Time Index + const int to, // Fisr Tima Index + const double &buffer[] // the Buffer which required to search +) +{ + // + bool result = false; + + // + // Validate Args ... + if ( + from <= to || + ArraySize(buffer) < from + 1) + { + return result; + } + + // + // Loop through Items ... + double toValue = buffer[to]; + double fromValue = buffer[from]; + result = toValue < fromValue; + for (int i = to + 1; i <= from - 1; i++) + { + // + double iValue = buffer[i]; + bool isPassed = toValue <= iValue; + + // + bool isIDecreasing = IsDecreasing( + from, + i, + buffer); + + // + // Check Result ... + result = result && isPassed && isIDecreasing; + if (!result) + { + break; + } + } + + // + return result; +} + +// +bool IsTrendingUp( + const double &buffer1[], // First Buffer + const double &buffer2[] // Seccend Buffer +) +{ + // + bool result = false; + + // + int buffer1Count = ArraySize(buffer1); + int buffer2Count = ArraySize(buffer2); + if (buffer1Count <= 0 || buffer2Count <= 0) + { + return result; + } + + // + int count = MathMin(buffer1Count, buffer2Count); + if (count <= 1) + { + return result; + } + + // + int upCounts = 0; + int downCounts = 0; + double value = MathAbs(buffer1[0] - buffer2[0]); + for (int i = 1; i < count; i++) + { + // + double iValue = MathAbs(buffer1[i] - buffer2[i]); + + // + if (value > iValue) + { + upCounts++; + } + + // + if (value < iValue) + { + downCounts++; + } + } + + // + result = upCounts > 1 && upCounts > downCounts; + + // + return result; +} + +// +bool IsTrendingDown( + const double &buffer1[], // First Buffer + const double &buffer2[] // Seccend Buffer +) +{ + // + bool result = false; + + // + int buffer1Count = ArraySize(buffer1); + int buffer2Count = ArraySize(buffer2); + if (buffer1Count <= 0 || buffer2Count <= 0) + { + return result; + } + + // + int count = MathMin(buffer1Count, buffer2Count); + if (count <= 1) + { + return result; + } + + // + int upCounts = 0; + int downCounts = 0; + double value = MathAbs(buffer1[0] - buffer2[0]); + for (int i = 1; i < count; i++) + { + // + double iValue = MathAbs(buffer1[i] - buffer2[i]); + + // + if (value > iValue) + { + upCounts++; + } + + // + if (value < iValue) + { + downCounts++; + } + } + + // + result = downCounts > 1 && downCounts > upCounts; + + // + return result; +} + +// +// Calculate Slope of Specified Buffer at Specified Index ... +double GetSlope( + const double &buffer[], // Buffer + int from, // In Past Index ... + int to // In Past Index ... +) +{ + // + double result = 0; + + // + if (from > ArraySize(buffer) || to > ArraySize(buffer)) + { + return result; + } + + // + double toValue = buffer[to]; + double fromValue = buffer[from]; + double deltaValue = toValue - fromValue; + double deltaTime = from - to; + + // + result = deltaValue / deltaTime; + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, // Upper Bound + double downPrice, // Downer Bound + double level, // Level Multiplier Factor + int direction // From Down to Up < 0, other wise Vice Versa + // +) +{ + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? upPrice - pLevel : downPrice + pLevel; + + // + return result; +} + +// +double MAOnArray( + double &array[], + int total, + int period, + int ma_shift, + int ma_method, + int shift // +) +{ + // + double result = 0; + + // + double buf[]; + double arr[]; + + // + if (total == 0) + { + total = ArraySize(array); + } + + // + if (total > 0 && total <= period) + { + return result; + } + + // + if (shift > total - period - ma_shift) + { + return result; + } + + // + // MA Method ... + switch (ma_method) + { + // + // Mode SMA ... + case MODE_SMA: { + // + total = ArrayCopy(arr, array, 0, shift + ma_shift, period); + if (ArrayResize(buf, total) < 0) + { + return result; + } + + // + double sum = 0; + int i, pos = total - 1; + for (i = 1; i < period; i++, pos--) + { + sum += arr[pos]; + } + + // + while (pos >= 0) + { + // + sum += arr[pos]; + buf[pos] = sum / period; + sum -= arr[pos + period - 1]; + pos--; + } + + // + result = buf[0]; + return result; + } + + // + // Mode EMA ... + case MODE_EMA: { + // + if (ArrayResize(buf, total) < 0) + { + return result; + } + + // + int pos = total - 2; + double pr = 2.0 / (period + 1); + + // + while (pos >= 0) + { + // + if (pos == total - 2) + { + buf[pos + 1] = array[pos + 1]; + } + + // + buf[pos] = array[pos] * pr + buf[pos + 1] * (1 - pr); + pos--; + } + + // + result = buf[shift + ma_shift]; + return result; + } + + // + // Mode SMMA ... + case MODE_SMMA: { + // + if (ArrayResize(buf, total) < 0) + { + return result; + } + + // + int i, kk, pos; + double sum = 0; + pos = total - period; + + // + while (pos >= 0) + { + // + if (pos == total - period) + { + // + for (i = 0, kk = pos; i < period; i++, kk++) + { + // + sum += array[kk]; + buf[kk] = 0; + } + } + else + { + sum = buf[pos + 1] * (period - 1) + array[pos]; + } + + // + buf[pos] = sum / period; + pos--; + } + + // + result = buf[shift + ma_shift]; + return result; + } + + // + // Mode LWMA ... + case MODE_LWMA: { + // + if (ArrayResize(buf, total) < 0) + { + return result; + } + + // + double price; + double sum = 0.0, lsum = 0.0; + int i, weight = 0, pos = total - 1; + + // + for (i = 1; i <= period; i++, pos--) + { + // + price = array[pos]; + sum += price * i; + lsum += price; + weight += i; + } + + // + pos++; + i = pos + period; + while (pos >= 0) + { + // + buf[pos] = sum / weight; + if (pos == 0) + { + break; + } + + // + i--; + pos--; + price = array[pos]; + sum = sum - lsum + price * period; + lsum -= array[i]; + lsum += price; + } + + // + result = buf[shift + ma_shift]; + return result; + } + + // + default: + return result; + } + + // + return result; +} + +// +// Method 1 +// Normalize between 1 and 0 ... +template +double GetNormalizedValueMethod1( + T &buffer[], // Array which required to Normalize + int mLength, // Length of Normalization + int mStart = 0, // start index + int digits = 5 // Normalization Digits +) +{ + // + double result = 0; + + // + if (digits <= 5) + { + digits = 5; + } + + // + int bufferSize = ArraySize(buffer); + if (!IsValidSize(bufferSize)) + { + return result; + } + + // + // Normalize Count ... + NormalizeCount( + mStart, + mLength, + buffer // + ); + + // + T max = 0; + T min = 0; + + // + if (bufferSize != mLength) + { + // + T tmp[]; + Copy( + mStart, + mLength, + buffer, + tmp // + ); + + // + max = GetMax(tmp); + min = GetMin(tmp); + } + + // + if (bufferSize == mLength) + { + // + max = GetMax(buffer); + min = GetMin(buffer); + } + + // + T iValue = buffer[mStart]; + + // + double minMaxDiff = (max - min); + if (minMaxDiff <= 0) + { + return result; + } + + // + result = (iValue - min) / minMaxDiff; + + // + result = NormalizeDouble(result, digits); + + // + return result; +} + +// +// Method 2 +// Normalize Between Specified Upper and Lower ... +template +double GetNormalizedValueMethod2( + T &buffer[], // Array which required to Normalize + int mLength, // Length of Normalization + int mUpper, // Specified Upper Value + int mLower, // Specified Lower Value + int mStart = 0, // start index + int digits = 5 // Normalization Digits +) +{ + // + double result = 0; + + // + if (digits <= 5) + { + digits = 5; + } + + // + int bufferSize = ArraySize(buffer); + if (!IsValidSize(bufferSize)) + { + return result; + } + + // + // Normalize Count ... + NormalizeCount( + mStart, + mLength, + buffer // + ); + + // + T max = 0; + T min = 0; + + // + if (bufferSize != mLength) + { + // + T tmp[]; + Copy( + mStart, + mLength, + buffer, + tmp // + ); + + // + max = GetMax(tmp); + min = GetMin(tmp); + } + + // + if (bufferSize == mLength) + { + // + max = GetMax(buffer); + min = GetMin(buffer); + } + + // + T iValue = buffer[mStart]; + + // + double minMaxDiff = (max - min); + double boundaryDiff = (mUpper - mLower); + if (minMaxDiff <= 0 || boundaryDiff <= 0) + { + return result; + } + + // + result = boundaryDiff / (minMaxDiff * (iValue - max) + max); + + // + result = NormalizeDouble(result, digits); + + // + return result; +} + +// +void NormalizeBuffer( + double &source[], // Source Buffer + double &dest[], // Result Buffer + double upper = 100, // Upper Value to Normalize + double lower = -100, // Lower Value to Normalize + int size = -1, // Size Of Normalization + int digits = 5 // Digits for Result +) +{ + // + if (size <= 0) + { + size = ArraySize(source); + } + + // + bool asSeriesFlag = ArrayGetAsSeries(source); + + // + ArraySetAsSeries(source, false); + ArraySetAsSeries(dest, false); + + // + double min = ArrayMinimum(source, 0, size); + double max = ArrayMaximum(source, 0, size); + + // + for (int i = 0; i < size; i++) + { + // + double iNormal = lower + ((source[i] - min) / (max - min)) * (upper - lower); + + // + if (digits > 0) + { + iNormal = NormalizeDouble(iNormal, digits); + } + + // + dest[i] = iNormal; + } + + // + ArraySetAsSeries(source, asSeriesFlag); + ArraySetAsSeries(dest, asSeriesFlag); +} + +// +// Templates ... + +// +// Retrieve Specific Object Types Name ... +template +string GetTypeName(const T &t) +{ + return typename(T); +} + +// +template +string GetToken(T &item) +{ + // + string mType = GetTypeName(item); + + // + string result = mType; + + // + string parts[]; + int partsCount = SplitContent( + parts, + result, + " " + // + ); + if (partsCount <= 0) + { + // + result = mType; + return result; + } + + // + bool hasLastPart = GetLastItem( + result, + parts + // + ); + if (!hasLastPart) + { + // + result = mType; + return result; + } + + // + return result; +} + +// +// Same as Get Token for Use in Classes ... +template +string GetSpecificToken(T &item) +{ + // + string mType = GetTypeName(item); + + // + string result = mType; + + // + string parts[]; + int partsCount = SplitContent( + parts, + result, + " " + // + ); + if (partsCount <= 0) + { + // + result = mType; + return result; + } + + // + bool hasLastPart = GetLastItem( + result, + parts + // + ); + if (!hasLastPart) + { + // + result = mType; + return result; + } + + // + return result; +} + +// +// Generate Unique Tags ... +template +string GenerateTag(T &model) +{ + // + string result = ""; + + // + string tag = model.ToString(); + if (StringLen(tag) == 0) + { + return result; + } + + // + static XSCMD5 md5; + + // + result = md5.Hash(tag); + + // + return result; +} + +// +// Hash Specified Content ... +template +string ToMD5(T content) +{ + // + string result = ""; + + // + string strContent = ToString(content); + if (StringLen(strContent) == 0) + { + return result; + } + + // + static XSCMD5 md5; + + // + result = md5.Hash(strContent); + + // + return result; +} + +// +// Check a Value Not Empty ... +template +bool NotEmpty(T value) +{ + return value != EMPTY_VALUE; +} + +// +// Check a Value Not Empty and Zero ... +template +bool NotEmptyZero(T value) +{ + return value != EMPTY_VALUE && value != 0; +} + +// +// Add Specified Item to Array ... +template +int Add( + T item, // item want to add + T &buffer[] // Destination buffer +) +{ + // + int result = 0; + + // + ArrayResize( + buffer, + ArraySize(buffer) + 1); + + // + buffer[ArraySize(buffer) - 1] = item; + + // + result = ArraySize(buffer); + + // + return result; +} +template +int AddSpecific( + T item, // item want to add + T &buffer[] // Destination buffer +) +{ + // + return Add( + item, + buffer // + ); +} +template +int AddRef( + T &item, // item want to add + T &buffer[] // Destination buffer +) +{ + // + int result = 0; + + // + ArrayResize( + buffer, + ArraySize(buffer) + 1); + + // + buffer[ArraySize(buffer) - 1] = item; + + // + result = ArraySize(buffer); + + // + return result; +} + +// +// Remove Specified Item from an Array ... +template +bool Remove( + T item, + T &buffer[]) +{ + // + bool result = false; + + // + int itemIndex = FindIndex( + item, + buffer); + if (itemIndex < 0) + { + return result; + } + + // + result = ArrayRemove( + buffer, + itemIndex, + 1); + + // + return result; +} + +// +// Clean Specified Array ... +template +void Clean(T &buffer[]) +{ + // + ArrayFree(buffer); + ArrayResize(buffer, 0); +} +template +void SpecificClean(T &buffer[]) +{ + Clean(buffer); +} + +// +// Copy Whole Content of Source to Dest array ... +template +void Copy( + T &source[], // Source Buffer ... + T &dest[], // Dest Buffer ... + bool cleanDest = true // Force Clen Dest Buffer ... +) +{ + // + if (cleanDest) + { + Clean(dest); + } + + // + int sourceCount = ArraySize(source); + if (sourceCount <= 0) + { + return; + } + + // + for (int i = 0; i < sourceCount; i++) + { + // + T iSource = source[i]; + + // + AddRef( + iSource, + dest); + } +} + +// +// Copy Items from a Buffer ... +template +int Copy( + int start, // Start + int count, // Number of Items for read + T &source[], // Source Buffer + T &dest[], // Dest Buffer + bool forceClean = true, // Force To Clean buffer + bool forceStart = true // Force To Clean buffer +) +{ + // + int result = 0; + + // + if (forceClean) + { + Clean(dest); + } + + // + if (start < 0 && forceStart) + { + start = 0; + } + + // + if (start >= ArraySize(source)) + { + start = ArraySize(source) - 1; + } + + // + if (count == 0) + { + count = ArraySize(source) - 1 - start; + } + + // + if (start + count > ArraySize(source)) + { + return result; + } + + // + int beforeSize = ArraySize(dest); + + // + bool asSeriesDest = ArrayGetAsSeries(dest); + bool asSeriesSource = ArrayGetAsSeries(source); + + // + ArraySetAsSeries(dest, true); + ArraySetAsSeries(source, true); + + // + ArrayCopy( + dest, + source, + 0, + start, + count + // + ); + + // + int afterSize = ArraySize(dest); + + // + result = afterSize - beforeSize; + + // + ArraySetAsSeries(dest, asSeriesDest); + ArraySetAsSeries(source, asSeriesSource); + + // + return result; +} + +// +// Copy Items from a Buffer ... +template +int CopyRef( + int start, // Start + int count, // Number of Items for read + T &source[], // Source Buffer + T &dest[], // Dest Buffer + bool forceClean = true // Force To Clean buffer +) +{ + // + int result = 0; + + // + if (forceClean) + { + Clean(dest); + } + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(source)) + { + start = ArraySize(source) - 1; + } + + // + int beforeSize = ArraySize(dest); + + // + bool asSeriesDest = ArrayGetAsSeries(dest); + bool asSeriesSource = ArrayGetAsSeries(source); + + // + ArraySetAsSeries(dest, true); + ArraySetAsSeries(source, true); + + // + for (int i = start; i < start + count; i++) + { + // + AddRef( + source[i], + dest + // + ); + } + + // + int afterSize = ArraySize(dest); + + // + result = afterSize - beforeSize; + + // + ArraySetAsSeries(dest, asSeriesDest); + ArraySetAsSeries(source, asSeriesSource); + + // + return result; +} + +// +// Retrive Last Item of Specified Buffer ... +template +bool GetLastItem( + T &item, // Holds Result + T &buffer[] // Specified Buffer +) +{ + // + bool result = false; + + // + int bufferSize = ArraySize(buffer); + if (bufferSize <= 0) + { + return result; + } + + // + item = buffer[bufferSize - 1]; + + // + result = true; + return result; +} + +// +// Search Array For Specific Item ... +template +int FindIndex( + T item, // What is Search ... + T &buffer[] // Search in ... +) +{ + // + int result = -1; + + // + int count = ArraySize(buffer); + if (count <= 0) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + T iT = buffer[i]; + + // + if (iT == item) + { + // + result = i; + break; + } + } + + // + return result; +} + +// +// Check an Array Contains Specified Value ... +template +bool Contains( + T item, // What is Search ... + T &buffer[] // Search in ... +) +{ + // + bool result = false; + + // + int idx = FindIndex( + item, + buffer); + result = idx > -1; + + // + return result; +} + +// +// Calculate a Buffer's Sum ... +template +double GetSum( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + // + double result = 0; + + // + T tmp[]; + int tmpCount = Copy( + start, + count, + buffer, + tmp + // + ); + if (tmpCount <= 0) + { + return result; + } + + // + // Calculate Summary ... + for (int i = 0; i < tmpCount; i++) + { + result += buffer[i]; + } + + // + return result; +} + +// +// Calculate a Buffer's Average ... +template +double GetAverage( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + // + double result = 0; + + // + T tmp[]; + int tmpCount = Copy( + start, + count, + buffer, + tmp + // + ); + if (tmpCount <= 0) + { + return result; + } + + // + // Calculate Summary ... + for (int i = 0; i < tmpCount; i++) + { + result += buffer[i]; + } + + // + // Calculate Average ... + result = result / tmpCount; + + // + return result; +} + +// +// Get Max of Specific Loopback of a Buffer ... +template +T GetMax( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + // + T result = 0; + + // + if (count <= 0) + { + count = ArraySize(buffer); + } + + // + T tmp[]; + int tmpCount = Copy( + start, + count, + buffer, + tmp + // + ); + if (tmpCount <= 0) + { + return result; + } + + // + // Loop Through LoopBack ... + for (int i = 0; i < tmpCount; i++) + { + // + T iValue = tmp[i]; + + // + result = + // + result == 0 || result < iValue + // + ? iValue + // + : result + // + ; + } + + // + return result; +} +template +T GetSpecifiedMax( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + return GetMax( + buffer, + start, + count // + ); +} + +// +// Get Min of Specific Loopback of a Buffer ... +template +T GetMin( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + // + T result = 0; + + // + if (count <= 0) + { + count = ArraySize(buffer); + } + + // + T tmp[]; + int tmpCount = Copy( + start, + count, + buffer, + tmp + // + ); + if (tmpCount <= 0) + { + return result; + } + + // + // Loop Through LoopBack ... + for (int i = 0; i < tmpCount; i++) + { + // + T iValue = tmp[i]; + + // + result = + // + result == 0 || result > iValue + // + ? iValue + // + : result + // + ; + } + + // + return result; +} +template +T GetSpecifiedMin( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + return GetMin( + buffer, + start, + count // + ); +} + +// +// Find a Value less than Specified ... +template +T FindLesserThan( + T value, // Specified Value ... + const T &source[], // Source ... + bool isDescend = false // Find Biggest Lesser Value ... +) +{ + // + T result = -1; + + // + int itemsCount = ArraySize(source); + if (itemsCount <= 0) + { + return result; + } + + // + // Make a Copy of source ... + T tmp[]; + + // + ArrayResize( + tmp, + ArraySize(source)); + + // + ArrayCopy( + tmp, + source); + + // + // Sort Temp Buffer ... + ArraySort(tmp); + if (isDescend) + { + ArrayReverse(tmp); + } + + // + int tmpCount = ArraySize(tmp); + for (int i = 0; i < tmpCount; i++) + { + // + T iValue = tmp[i]; + + // + if (iValue < value) + { + // + result = iValue; + break; + } + } + + // + return result; +} + +// +// Find a Value less than Specified ... +template +T FindBiggerThan( + T value, // Specified Value ... + const T &source[], // Source ... + bool isDescend = false // Find Smallest Bigger Value ... +) +{ + // + T result = -1; + + // + int itemsCount = ArraySize(source); + if (itemsCount <= 0) + { + return result; + } + + // + // Make a Copy of source ... + T tmp[]; + + // + ArrayResize( + tmp, + ArraySize(source)); + + // + ArrayCopy( + tmp, + source); + + // + // Sort Temp Buffer ... + ArraySort(tmp); + if (!isDescend) + { + ArrayReverse(tmp); + } + + // + int tmpCount = ArraySize(tmp); + for (int i = 0; i < tmpCount; i++) + { + // + T iValue = tmp[i]; + + // + if (iValue > value) + { + // + result = iValue; + break; + } + } + + // + return result; +} + +// +// Find Same Values in Array ... +template +void FindSames( + T &result[], // Holds Result ... + T &source[], // Source ... + int verifications = 3 // Number of Consequence Repeat ... +) +{ + // + Clean(result); + + // + // TenkanSen Flats ... + int sourceCount = ArraySize(source); + if (sourceCount > verifications) + { + // + T mLast = 0; + int mVerified = 0; + for (int i = 0; i < sourceCount; i++) + { + // + T iVal = source[i]; + if (mLast == 0) + { + mLast = iVal; + } + else if (mLast == iVal) + { + mVerified++; + } + else + { + mLast = iVal; + mVerified = 0; + } + + // + if (iVal == mLast && mVerified >= verifications) + { + // + Add( + iVal, + result); + + // + mLast = 0; + mVerified = 0; + } + } + } +} + +// +// Add an Item to a Buffer if not Exists ... +void AddIfNotExists( + double value, + double &values[], + double smoothingPoint = 3) +{ + // + double smoothingValue = smoothingPoint * GetPoints(_Symbol); + + // + int valuesCount = ArraySize(values); + if (valuesCount <= 0) + { + // + Add(value, + values); + } + else + { + // + bool isExists = false; + for (int i = 0; i < valuesCount; i++) + { + // + double iVal = values[i]; + + // + double diff = MathAbs(iVal - value); + + // + if (iVal == value || diff < smoothingValue) + { + // + isExists = true; + break; + } + } + + // + if (!isExists) + { + // + Add(value, + values); + } + } +} + +// +// Add a Buffers Child to another Buffer +// if it's not Contains them ... +void AddsIfNotExists( + double &source[], + double &dest[], + double smoothingPoint = 3) +{ + // + double smoothingValue = smoothingPoint * GetPoints(_Symbol); + + // + int sourceCount = ArraySize(source); + if (sourceCount <= 0) + { + return; + } + + // + for (int i = 0; i < sourceCount; i++) + { + // + double iSource = source[i]; + + // + AddIfNotExists( + iSource, + dest, + smoothingPoint); + } +} + +// +// Bar XOHCL ... + +// +// Extract Specific Range of Bars ... +// using Start Bar Index ... +int GetBars( + XOHCL &result[], // Hold Result + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Time Frame + int from = 0, // Start Bar Index + int count = 1, // Number of Bars + bool forceClean = true // Clean Result Array +) +{ + // + int mResult = 0; + + // + if (from < 0) + { + from = 0; + } + + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + int total = Bars( + mSymbol, + mPeriod); + if (from > total - 2) + { + from = total - 2; + } + + // + if (count < 0) + { + count = 1; + } + + // + int start = from; + int end = start + count; + if (end > total - 1) + { + end = total - 1; + } + + // + if (forceClean) + { + Clean(result); + } + + // + int beforeSize = ArraySize(result); + + // + for (int i = start; i < end; i++) + { + // + XOHCL iBar; + bool isValid = iBar.Init( + mSymbol, + mPeriod, + i + // + ); + + // + if (isValid) + { + // + AddRef( + iBar, + result + // + ); + } + } + + // + int afterSize = ArraySize(result); + + // + mResult = afterSize - beforeSize; + + // + return mResult; +} + +// +// Extract Specific Range of Bars ... +// using Start Bar Time ... +int GetBars( + XOHCL &result[], // Hold Result + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Time Frame + datetime from = NULL, // Start Bar Time + int count = 1, // Number of Bars + bool forceClean = true // Clean Result Array +) +{ + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + from = NormalizeTime(from); + + // + int barIndex = iBarShift( + mSymbol, + mPeriod, + from, + false + // + ); + + // + return GetBars( + result, + mSymbol, + mPeriod, + barIndex, + count, + forceClean + // + ); +} + +// +// String ... + +// +// Search a Content Contains Specific String or not ... +bool Contains( + string mQuery, // Search String + string mContent, // Search Content + bool ignoreCase = true // Ignore Case +) +{ + // + bool result = false; + + // + // Validate Query ... + result = IsValid(mQuery); + if (!result) + { + return result; + } + + // + // Validate Content ... + result = IsValid(mContent); + if (!result) + { + return result; + } + + // + // Normalize Inputs ... + string query = mQuery; + string content = mContent; + if (ignoreCase) + { + // + StringToLower(query); + StringToLower(content); + } + + // + int queryIdx = StringFind( + content, + query); + + // + result = queryIdx >= 0; + + // + return result; +} + +// +bool Contains( + string &mQueries[], // Search Strings + string mContent, // Search Content + bool ignoreCase = true // Ignore Case +) +{ + // + bool result = false; + + // + // Validate Queries ... + int queriesCount = ArraySize(mQueries); + result = queriesCount > 0; + if (!result) + { + return result; + } + + // + // Validate Content ... + result = IsValid(mContent); + if (!result) + { + return result; + } + + // + int containsCount = 0; + for (int i = 0; i < queriesCount; i++) + { + // + bool isContains = Contains( + mQueries[i], + mContent, + ignoreCase); + + // + if (!isContains) + { + // + result = false; + break; + } + + // + containsCount++; + } + + // + result = containsCount == queriesCount; + + // + return result; +} + +// +int FindIndexes( + string mQuery, // Search String + string mContent, // Search Content + int &result[], // Holding Results + bool ignoreCase = false // Ignore Case +) +{ + // + int mResult = 0; + + // + Clean(result); + + // + // Validate Inputs ... + if (!IsValid(mQuery) || + !IsValid(mContent)) + { + return mResult; + } + + // + // Apply Ignore Case if Provided ... + if (ignoreCase) + { + // + bool isConverted = StringToLower(mQuery); + if (!isConverted) + { + return mResult; + } + + // + isConverted = StringToLower(mContent); + if (!isConverted) + { + return mResult; + } + } + + // + // Search First Index ... + int lastPos = 0; + int idx = StringFind( + mContent, + mQuery, + lastPos // + ); + while (idx >= 0) + { + // + // Add Position to Result ... + Add( + idx, + result // + ); + + // + lastPos = idx + StringLen(mQuery); + idx = StringFind( + mContent, + mQuery, + lastPos // + ); + } + + // + mResult = ArraySize(result); + + // + return mResult; +} + +// +// Convert From String ... +template +T FromString(string value) +{ + // + T result = NULL; + + // + if (!IsValid(value)) + { + return result; + } + + // + result = (T)value; + + // + return result; +} + +// +// Converts an item to String ... +template +string ToString(T value) +{ + return (string)value; +} + +// +// Used In Report or Summary Generators ... +string ToString( + string prefix, // Title + bool value, // Value + bool ignoreFalseConditions = true, // Ignore False Conditions + string lineSeparator = "\n", // Line Separator + string prefixSeparator = ":" // Title Separator +) +{ + // + string result = NULL; + + // + result = (value || !ignoreFalseConditions) + ? prefix + + prefixSeparator + " " + + ToString(value) + + lineSeparator + : ""; + + // + return result; +} + +// +template +string ToString( + string prefix, // Title + T value, // Value + string lineSeparator = "\n", // Line Separator + string prefixSeparator = ":" // Title Separator +) +{ + // + string result = NULL; + + // + result = prefix + + prefixSeparator + " " + + ToString(value) + + lineSeparator; + + // + return result; +} + +// +string SetLabel( + string mLabel, // Provided Label ... + string value, // Source Value ... + string separator = "\n", // Line Separator + bool addTopEmptyLine = true // Add Empty Line On top +) +{ + // + string result = value; + + // + if (StringLen(mLabel) <= 0) + { + return result; + } + + // + result = (StringLen(value) > 0) + ? (addTopEmptyLine ? separator : "") + + mLabel + + separator + + "-----------------------------" + + separator + + value + : value; + + // + return result; +} + +// +// Converts a Buffer to String Representation ... +template +string ToString( + const T &buffer[], // Specified Buffer + string separator = ",", // Specified Separator + bool addIndex = false, // Specified Add Items Indexes or Not + string indexLabel = "i:", // Specified Index Label + string indexSeparator = ">" // Specified Index Separator +) +{ + // + string result = ""; + + // + int bufferSize = ArraySize(buffer); + if (bufferSize <= 0) + { + return result; + } + + // + for (int i = 0; i < bufferSize; i++) + { + // + if (addIndex) + { + // + if (StringLen(indexLabel) > 0) + { + result += indexLabel + " "; + } + + // + result += (string)i + " "; + + // + if (StringLen(indexSeparator) > 0) + { + result += indexSeparator + " "; + } + } + + // + string iItemString = (string)buffer[i]; + + // + result += iItemString; + + // + if (i < bufferSize - 1) + { + result += separator; + } + } + + // + return result; +} + +// +// Converts String to boolean ... +bool ToBoolean(string value) +{ + // + bool result = false; + + // + if (StringLen(value) <= 0) + { + return result; + } + + // + StringToLower(value); + result = value == "true"; + + // + return result; +} + +// +// Split an String Representation of an Array ... +int SplitContent( + string &result[], // Hold Result ... + string content, // Source ... + string separator = ",", // Separator ... + bool forceCleanResult = true // Clean Result ... +) +{ + // + int mResult = 0; + + // + if (forceCleanResult) + { + Clean(result); + } + + // + int before = ArraySize(result); + + // + if (separator == NULL || StringLen(separator) == 0) + { + separator = ","; + } + + // + if (StringLen(content) == 0) + { + return mResult; + } + + // + StringSplit( + content, + StringGetCharacter( + separator, + 0), + result); + + // + int after = ArraySize(result); + + // + mResult = after - before; + + // + return mResult; +} + +// +// Extract Data from String ... +string ExtractString( + const string source, // Source String used for Extracting + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + string result = ""; + + // + // Validate String ... + if ( + StringLen(source) == 0 || + StringLen(endString) == 0 || + StringLen(startString) == 0) + { + return result; + } + + // + // Find Start String Position ... + int sPos = StringFind( + source, + startString); + if (sPos < 0) + { + return result; + } + + // + // Find End String Position after Start String ... + int searchEndFromPos = sPos + StringLen(startString); + int ePos = StringFind( + source, + endString, + searchEndFromPos); + if (ePos < 0) + { + return result; + } + + // + // Extract Data from Source ... + int dLength = ePos - searchEndFromPos; + result = StringSubstr( + source, + searchEndFromPos, + dLength); + + // + return result; +} + +// +// Extract an Array of Contents ... +int ExtractStrings( + string &result[], // Hold Result + const string source, // Source String used for Extracting + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + int mResult = 0; + + // + Clean(result); + + // + // Validate Args ... + int sourceLength = StringLen(source); + int startLength = StringLen(startString); + int endLength = StringLen(endString); + + // + int minRequiredLength = startLength + endLength; + + // + if ( + endLength <= 0 || + startLength <= 0 || + sourceLength <= 0 || + sourceLength < minRequiredLength) + { + return mResult; + } + + // + // Make a Copy of Source for Manipulating ... + string workStr = source; + + // + // Define a Loop ... + while (StringLen(workStr) > minRequiredLength) + { + // + // Find Item ... + string item = ExtractString( + workStr, + startString, + endString); + + // + // Breakout when couldn't find anymore item ... + int itemLength = StringLen(item); + if (itemLength <= 0) + { + break; + } + + // + // Prepare Item Source String for Replacing in Work String ... + string itemSource = startString + item + endString; + + // + // Add Item to Result Array ... + Add( + item, + result); + + // + // Replace Item Soure in Work String ... + StringReplace( + workStr, + itemSource, + ""); + } + + // + // Calculate Size of Array ... + mResult = ArraySize(result); + + // + return mResult; +} + +// +string ExtractSurrounded( + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + return ExtractString( + surrounded, + mToken + startString, + endString + // + ); +} + +// +int ParseIntSurrounded( + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + int result = NULL; + + // + string strContent = ExtractSurrounded( + surrounded, + mToken, + startString, + endString + // + ); + if (!IsValid(strContent)) + { + return result; + } + + // + result = (int)strContent; + + // + return result; +} +long ParseLongSurrounded( + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + long result = NULL; + + // + string strContent = ExtractSurrounded( + surrounded, + mToken, + startString, + endString + // + ); + if (!IsValid(strContent)) + { + return result; + } + + // + result = (long)strContent; + + // + return result; +} +string ParseStringSurrounded( + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + string result = NULL; + + // + string strContent = ExtractSurrounded( + surrounded, + mToken, + startString, + endString + // + ); + if (!IsValid(strContent)) + { + return result; + } + + // + result = (string)strContent; + + // + return result; +} +double ParseDoubleSurrounded( + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + double result = NULL; + + // + string strContent = ExtractSurrounded( + surrounded, + mToken, + startString, + endString + // + ); + if (!IsValid(strContent)) + { + return result; + } + + // + result = (double)strContent; + + // + return result; +} +datetime ParseTimeSurrounded( + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + const string startString = "(", // Expression Start String must be Unique + const string endString = ")" // Where to End Extraction, usually a Sign +) +{ + // + datetime result = NULL; + + // + string strContent = ExtractSurrounded( + surrounded, + mToken, + startString, + endString + // + ); + if (!IsValid(strContent)) + { + return result; + } + + // + result = (datetime)strContent; + + // + return result; +} + +// +int ParseIntArraySurrounded( + int &result[], // Holds Result + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + string separator = ",", // Separator ... + const string startString = "(", // Expression Start String must be Unique + const string endString = ")", // Where to End Extraction, usually a Sign + bool forceClean = true // Clean Result ... +) +{ + // + int count = 0; + + // + if (forceClean) + { + Clean(result); + } + + // + int before = ArraySize(result); + + // + string contentStr = ParseStringSurrounded(surrounded, mToken); + if (!IsValid(contentStr)) + { + return count; + } + + // + string tmps[]; + int tmpsCount = SplitContent( + tmps, + contentStr + // + ); + if (tmpsCount <= 0) + { + return count; + } + + // + for (int i = 0; i < tmpsCount; i++) + { + // + string iTMP = tmps[i]; + if (!IsValid(iTMP)) + { + continue; + } + + // + int iValue = (int)iTMP; + + // + Add( + iValue, + result + // + ); + } + + // + int after = ArraySize(result); + + // + count = after - before; + + // + return count; +} +int ParseLongArraySurrounded( + long &result[], // Holds Result + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + string separator = ",", // Separator ... + const string startString = "(", // Expression Start String must be Unique + const string endString = ")", // Where to End Extraction, usually a Sign + bool forceClean = true // Clean Result ... +) +{ + // + int count = 0; + + // + if (forceClean) + { + Clean(result); + } + + // + int before = ArraySize(result); + + // + string contentStr = ParseStringSurrounded(surrounded, mToken); + if (!IsValid(contentStr)) + { + return count; + } + + // + string tmps[]; + int tmpsCount = SplitContent( + tmps, + contentStr + // + ); + if (tmpsCount <= 0) + { + return count; + } + + // + for (int i = 0; i < tmpsCount; i++) + { + // + string iTMP = tmps[i]; + if (!IsValid(iTMP)) + { + continue; + } + + // + long iValue = (long)iTMP; + + // + Add( + iValue, + result + // + ); + } + + // + int after = ArraySize(result); + + // + count = after - before; + + // + return count; +} +int ParseDoubleArraySurrounded( + double &result[], // Holds Result + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + string separator = ",", // Separator ... + const string startString = "(", // Expression Start String must be Unique + const string endString = ")", // Where to End Extraction, usually a Sign + bool forceClean = true // Clean Result ... +) +{ + // + int count = 0; + + // + if (forceClean) + { + Clean(result); + } + + // + int before = ArraySize(result); + + // + string contentStr = ParseStringSurrounded(surrounded, mToken); + if (!IsValid(contentStr)) + { + return count; + } + + // + string tmps[]; + int tmpsCount = SplitContent( + tmps, + contentStr + // + ); + if (tmpsCount <= 0) + { + return count; + } + + // + for (int i = 0; i < tmpsCount; i++) + { + // + string iTMP = tmps[i]; + if (!IsValid(iTMP)) + { + continue; + } + + // + double iValue = (double)iTMP; + + // + Add( + iValue, + result + // + ); + } + + // + int after = ArraySize(result); + + // + count = after - before; + + // + return count; +} +int ParseTimeArraySurrounded( + datetime &result[], // Holds Result + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + string separator = ",", // Separator ... + const string startString = "(", // Expression Start String must be Unique + const string endString = ")", // Where to End Extraction, usually a Sign + bool forceClean = true // Clean Result ... +) +{ + // + int count = 0; + + // + if (forceClean) + { + Clean(result); + } + + // + int before = ArraySize(result); + + // + string contentStr = ParseStringSurrounded(surrounded, mToken); + if (!IsValid(contentStr)) + { + return count; + } + + // + string tmps[]; + int tmpsCount = SplitContent( + tmps, + contentStr + // + ); + if (tmpsCount <= 0) + { + return count; + } + + // + for (int i = 0; i < tmpsCount; i++) + { + // + string iTMP = tmps[i]; + if (!IsValid(iTMP)) + { + continue; + } + + // + datetime iValue = (datetime)iTMP; + + // + Add( + iValue, + result + // + ); + } + + // + int after = ArraySize(result); + + // + count = after - before; + + // + return count; +} + +// +// Surround an String by Specific Token ... +template +string Surround( + string mToken, // an String which used to Tokenize + T &value, // a Value for Tokenize it + string startString = "(", // Token Start Content + string endString = ")" // Token End Content +) +{ + // + string result = NULL; + + // + string strValue = ToString(value); + if (!IsValid(strValue)) + { + return result; + } + + // + result = + // + (IsValid(mToken) + ? mToken + : "") + + // + startString + + strValue + + endString + // + ; + + // + return result; +} + +// +template +string SurroundArray( + string mToken, + T &value[], + string startString = "(", // Token Start Content + string endString = ")" // Token End Content +) +{ + // + string result = NULL; + + // + string valueStr = ToString(value); + if (!IsValid(valueStr)) + { + return result; + } + + // + result = Surround( + mToken, + valueStr, + startString, + endString + // + ); + + // + return result; +} + +// +// Periods / Cycles ... + +// +// Converts an String to TimeFrame ... +ENUM_TIMEFRAMES ToPeriod(string value) +{ + // + if (StringLen(value) == 0) + { + return _Period; + } + + // + StringTrimLeft(value); + StringTrimRight(value); + + // + ENUM_TIMEFRAMES result = _Period; + + // + if (value == "M1") + { + result = PERIOD_M1; + } + else if (value == "M2") + { + result = PERIOD_M2; + } + else if (value == "M3") + { + result = PERIOD_M3; + } + else if (value == "M4") + { + result = PERIOD_M4; + } + else if (value == "M5") + { + result = PERIOD_M5; + } + else if (value == "M6") + { + result = PERIOD_M6; + } + else if (value == "M10") + { + result = PERIOD_M10; + } + else if (value == "M12") + { + result = PERIOD_M12; + } + else if (value == "M15") + { + result = PERIOD_M15; + } + else if (value == "M20") + { + result = PERIOD_M20; + } + else if (value == "M30") + { + result = PERIOD_M30; + } + else if (value == "H1") + { + result = PERIOD_H1; + } + else if (value == "H2") + { + result = PERIOD_H2; + } + else if (value == "H3") + { + result = PERIOD_H3; + } + else if (value == "H4") + { + result = PERIOD_H4; + } + else if (value == "H6") + { + result = PERIOD_H6; + } + else if (value == "H8") + { + result = PERIOD_H8; + } + else if (value == "H12") + { + result = PERIOD_H12; + } + else if (value == "D1") + { + result = PERIOD_D1; + } + else if (value == "W1") + { + result = PERIOD_W1; + } + else if (value == "MN1") + { + result = PERIOD_MN1; + } + + // + return result; +} + +// +// Converts Period to String ... +string ToString(ENUM_TIMEFRAMES mPeriod) +{ + // + string result = ""; + + // + string mPStr = EnumToString(mPeriod); + + string mPStrParts[]; + int partsCount = StringSplit( + mPStr, + StringGetCharacter("_", 0), + mPStrParts); + if (partsCount <= 0) + { + return result; + } + + // + result = mPStrParts[1]; + + // + return result; +} + +// +// Retrieve All Available Period as an Array ...s +int GetAllAvailablePeriods( + ENUM_TIMEFRAMES &result[] // Holds Result ... +) +{ + // + Clean(result); + + // + Add( + PERIOD_M1, + result + // + ); + + // + Add( + PERIOD_M2, + result + // + ); + + // + Add( + PERIOD_M3, + result + // + ); + + // + Add( + PERIOD_M4, + result + // + ); + + // + Add( + PERIOD_M5, + result + // + ); + + // + Add( + PERIOD_M6, + result + // + ); + + // + Add( + PERIOD_M10, + result + // + ); + + // + Add( + PERIOD_M12, + result + // + ); + + // + Add( + PERIOD_M15, + result + // + ); + + // + Add( + PERIOD_M20, + result + // + ); + + // + Add( + PERIOD_M30, + result + // + ); + + // + Add( + PERIOD_H1, + result + // + ); + + // + Add( + PERIOD_H2, + result + // + ); + + // + Add( + PERIOD_H3, + result + // + ); + + // + Add( + PERIOD_H4, + result + // + ); + + // + Add( + PERIOD_H6, + result + // + ); + + // + Add( + PERIOD_H8, + result + // + ); + + // + Add( + PERIOD_H12, + result + // + ); + + // + Add( + PERIOD_D1, + result + // + ); + + // + Add( + PERIOD_W1, + result + // + ); + + // + Add( + PERIOD_MN1, + result + // + ); + + // + int mResult = ArraySize(result); + + // + return mResult; +} + +// +// Get Specific Time Frame Start Candle Time ... +datetime GetPeriodStartTime( + string mSymbol = NULL, // Specified Symbol ... + ENUM_TIMEFRAMES mPeriod = NULL, // Specified Period ... + datetime mTime = NULL // Specified Bar Time of Host Period ... +) +{ + // + // Normalize Arg ... + mTime = NormalizeTime(mTime); + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + int barIndex = iBarShift( + mSymbol, + mPeriod, + mTime, + false + // + ); + + // + datetime result = GetBarTime( + mSymbol, + mPeriod, + barIndex + // + ); + + // + return result; +} + +// +// Converts an String to it's related Market Cycle ... +ENUM_X_MARKET_CYCLES ToCycle(string value) +{ + // + ENUM_X_MARKET_CYCLES result = X_MARKET_CYCLE_UNKNOWN; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int count = GetAllMarketCycles(cycles); + for (int i = 0; i < count; i++) + { + // + ENUM_X_MARKET_CYCLES iCycle = cycles[i]; + string iStr = ToString(iCycle); + + // + if (value == iStr) + { + // + result = iCycle; + break; + } + } + + // + return result; +} + +// +// Converts a Cycle to it's String Representation ... +string ToString(ENUM_X_MARKET_CYCLES cycle) +{ + // + string result = ""; + + // + string mPStr = EnumToString(cycle); + + string mPStrParts[]; + int partsCount = StringSplit( + mPStr, + StringGetCharacter("_", 0), + mPStrParts); + if (partsCount <= 0) + { + return result; + } + + // + result = mPStrParts[3]; + + // + return result; +} + +// +// Retrieve all Available Cycles ... +int GetAllMarketCycles(ENUM_X_MARKET_CYCLES &result[]) +{ + // + int mResult = 0; + + // + Clean(result); + + // + ENUM_X_MARKET_CYCLES tmp[] = { + X_MARKET_CYCLE_UNKNOWN, + X_MARKET_CYCLE_SHORT, + X_MARKET_CYCLE_MEDIUM, + X_MARKET_CYCLE_LONG, + X_MARKET_CYCLE_HIND}; + + // + Copy( + tmp, + result // + ); + + // + Clean(tmp); + + // + mResult = ArraySize(result); + + // + return mResult; +} + +// +// Retrieve Nearest Period base on Given Period ... +ENUM_TIMEFRAMES GetNearestPeriod(ENUM_TIMEFRAMES mPeriod) +{ + // + ENUM_TIMEFRAMES result = _Period; + + // + mPeriod = NormalizePeriod(mPeriod); + + // + switch (mPeriod) + { + // + case PERIOD_M1: + case PERIOD_M2: + result = PERIOD_M4; + break; + + // + case PERIOD_M3: + case PERIOD_M4: + result = PERIOD_M6; + break; + + // + case PERIOD_M5: + case PERIOD_M6: + case PERIOD_M10: + case PERIOD_M12: + result = PERIOD_M15; + break; + + // + case PERIOD_M15: + case PERIOD_M20: + result = PERIOD_M30; + break; + + // + case PERIOD_H1: + case PERIOD_H2: + case PERIOD_H3: + result = PERIOD_H4; + break; + + // + case PERIOD_H6: + case PERIOD_H8: + result = PERIOD_H12; + break; + + // + case PERIOD_H12: + result = PERIOD_D1; + break; + + // + case PERIOD_D1: + result = PERIOD_W1; + break; + + // + default: + result = PERIOD_MN1; + break; + } + + // + return result; +} + +// +// Retrieve Mediest Period base on Given Period ... +ENUM_TIMEFRAMES GetMediestPeriod(ENUM_TIMEFRAMES mPeriod) +{ + // + ENUM_TIMEFRAMES result = _Period; + + // + mPeriod = NormalizePeriod(mPeriod); + + // + switch (mPeriod) + { + // + case PERIOD_M1: + case PERIOD_M2: + result = PERIOD_M15; + break; + + // + case PERIOD_M3: + case PERIOD_M4: + result = PERIOD_M30; + break; + + // + case PERIOD_M5: + case PERIOD_M6: + case PERIOD_M10: + case PERIOD_M12: + result = PERIOD_H1; + break; + + // + case PERIOD_M15: + case PERIOD_M20: + result = PERIOD_H2; + break; + + // + case PERIOD_H1: + case PERIOD_H2: + case PERIOD_H3: + result = PERIOD_H8; + break; + + // + case PERIOD_H6: + case PERIOD_H8: + result = PERIOD_D1; + break; + + // + case PERIOD_H12: + result = PERIOD_W1; + break; + + // + case PERIOD_D1: + result = PERIOD_MN1; + break; + + // + default: + result = PERIOD_MN1; + break; + } + + // + return result; +} + +// +// Retrieve Longest Period base on Given Period ... +ENUM_TIMEFRAMES GetLongestPeriod(ENUM_TIMEFRAMES mPeriod) +{ + // + ENUM_TIMEFRAMES result = _Period; + + // + mPeriod = NormalizePeriod(mPeriod); + + // + switch (mPeriod) + { + // + case PERIOD_M1: + case PERIOD_M2: + result = PERIOD_M30; + break; + + // + case PERIOD_M3: + case PERIOD_M4: + result = PERIOD_H1; + break; + + // + case PERIOD_M5: + case PERIOD_M6: + case PERIOD_M10: + case PERIOD_M12: + result = PERIOD_H2; + break; + + // + case PERIOD_M15: + case PERIOD_M20: + result = PERIOD_H4; + break; + + // + case PERIOD_H1: + case PERIOD_H2: + case PERIOD_H3: + result = PERIOD_H12; + break; + + // + case PERIOD_H6: + case PERIOD_H8: + result = PERIOD_W1; + break; + + // + case PERIOD_H12: + result = PERIOD_MN1; + break; + + // + case PERIOD_D1: + result = PERIOD_MN1; + break; + + // + default: + result = PERIOD_MN1; + break; + } + + // + return result; +} + +// +// Retrieve Hindmost Period base on Given Period ... +ENUM_TIMEFRAMES GetHindMostPeriod(ENUM_TIMEFRAMES mPeriod) +{ + // + ENUM_TIMEFRAMES result = _Period; + + // + mPeriod = NormalizePeriod(mPeriod); + + // + switch (mPeriod) + { + // + case PERIOD_M1: + case PERIOD_M2: + result = PERIOD_H1; + break; + + // + case PERIOD_M3: + case PERIOD_M4: + result = PERIOD_H2; + break; + + // + case PERIOD_M5: + case PERIOD_M6: + case PERIOD_M10: + case PERIOD_M12: + result = PERIOD_H4; + break; + + // + case PERIOD_M15: + case PERIOD_M20: + result = PERIOD_H8; + break; + + // + case PERIOD_H1: + case PERIOD_H2: + case PERIOD_H3: + result = PERIOD_D1; + break; + + // + case PERIOD_H6: + case PERIOD_H8: + result = PERIOD_MN1; + break; + + // + case PERIOD_H12: + result = PERIOD_MN1; + break; + + // + case PERIOD_D1: + result = PERIOD_MN1; + break; + + // + default: + result = PERIOD_MN1; + break; + } + + // + return result; +} + +// +// Retrieve Specified Cycles Period related to Host Period ... +ENUM_TIMEFRAMES GetCyclePeriod( + ENUM_X_MARKET_CYCLES mCycle = NULL, // Specified Cycle + ENUM_TIMEFRAMES mPeriod = NULL // Host Period +) +{ + // + ENUM_TIMEFRAMES result = NULL; + + // + mPeriod = NormalizePeriod(mPeriod); + mCycle = NormalizeCycle(mCycle); + + // + switch (mCycle) + { + // + // Short ... + case X_MARKET_CYCLE_SHORT: + result = GetNearestPeriod(mPeriod); + break; + + // + // Medium ... + case X_MARKET_CYCLE_MEDIUM: + result = GetMediestPeriod(mPeriod); + break; + + // + // Long ... + case X_MARKET_CYCLE_LONG: + result = GetLongestPeriod(mPeriod); + break; + + // + // Hind ... + case X_MARKET_CYCLE_HIND: + result = GetHindMostPeriod(mPeriod); + break; + } + + // + return result; +} + +// +// Calculate a Cycle Length based on Host Period ... +int GetCycleLengthOn( + ENUM_TIMEFRAMES _hostPeriod, + ENUM_X_MARKET_CYCLES _cycle, + ENUM_X_PERIOD_METHOD _method, + ENUM_TIMEFRAMES _period // +) +{ + // + int result = 0; + + // + // Validate ... + bool isValid = + // + IsValid(_hostPeriod) && + IsValid(_method, _Period) + // + ; + if (!isValid) + { + return result; + } + + // + // Calculate Period ... + isValid = + _method != X_PERIOD_NOTHING && + _cycle != X_MARKET_CYCLE_UNKNOWN; + if (!isValid) + { + return result; + } + + // + if (_method == X_PERIOD_AUTO) + { + // + _period = GetCyclePeriod( + _cycle, + _hostPeriod // + ); + } + isValid = IsValid(_period); + if (!isValid) + { + return result; + } + + // + int _hostPeriodSeconds = PeriodSeconds(_hostPeriod); + int _periodSeconds = PeriodSeconds(_period); + + // + isValid = _periodSeconds >= _hostPeriodSeconds; + if (!isValid) + { + return result; + } + + // + result = _periodSeconds / _hostPeriodSeconds; + + // + return result; +} + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Libraries/x-saherelm.draw.lib.mq5 b/Documents/BKP/14030802-X121/Libraries/x-saherelm.draw.lib.mq5 new file mode 100644 index 00000000..aeb124ee --- /dev/null +++ b/Documents/BKP/14030802-X121/Libraries/x-saherelm.draw.lib.mq5 @@ -0,0 +1,2620 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Draw Library +// -------------------------------------- +// Name: XDraw +// Description: provides Draw abilities ... +// +// +// 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 + +// +// Global Definitions: Variables, Properties and etc ... + +// +// Retrieve Chart Size in Pixel ... +struct XSize +{ + long width; + long height; + + // + int x; + int y; + int w; + int h; + + // + int wStep; + int hStep; +}; + +// +// Define a Draw Specifications ... +struct XDrawSpecifications +{ + // + // Props ... + + // + bool draw; // Draw or Not ... + + // + int width; // Draw Witdth ... + color clr; // Draw Color ... + ENUM_LINE_STYLE style; // Draw Style ... + + // + bool back; // in the background + bool fill; // fill object if supported + bool selection; // highlight to move + bool rayRight; // line's continuation to the right + bool hidden; // hidden in the object list + long zOrder; // priority for mouse click + + // + string label; // Label ... + color labelColor; // Label Color ... + double labelAngel; // Label Angle ... + string labelFont; // Label Font ... + int labelFontSize; // Label Font Size ... + ENUM_ANCHOR_POINT labelAnchor; // Label Anchor Point ... + + // + // Constructor ... + XDrawSpecifications() + { + Clean(); + } + + // + // Operator ... + void operator=(const XDrawSpecifications &value) + { + // + clr = value.clr; + draw = value.draw; + width = value.width; + style = value.style; + + // + back = value.back; + hidden = value.hidden; + zOrder = value.zOrder; + rayRight = value.rayRight; + selection = value.selection; + + // + fill = value.fill; + + // + label = value.label; + labelColor = value.labelColor; + labelAngel = value.labelAngel; + labelFont = value.labelFont; + labelFontSize = value.labelFontSize; + labelAnchor = value.labelAnchor; + } + + // + // Functions ... + + // + void Clean() + { + // + draw = false; + width = 1; + clr = CLR_NONE; + style = STYLE_SOLID; + + // + back = false; + hidden = false; + rayRight = false; + selection = false; + fill = false; + + // + zOrder = 0; + + // + label = ""; + labelColor = CLR_NONE; + labelAngel = 0; + labelFont = "Arial"; + labelFontSize = 20; + labelAnchor = ANCHOR_LEFT_UPPER; + } + + // + void Label( + string mLabel = "", // Label ... + color mLabelColor = CLR_NONE, // Label Color ... + string mLabelFont = "Arial", // Label Font ... + int mLabelFontSize = 20, // Label Font Size ... + ENUM_ANCHOR_POINT mLabelAnchor = ANCHOR_LEFT_UPPER, // Label Anchor Point ... + double mLabelAngel = 0 // Label Angle ... + ) + { + // + label = mLabel; + labelFont = mLabelFont; + labelColor = mLabelColor; + labelAngel = mLabelAngel; + labelAnchor = mLabelAnchor; + labelFontSize = mLabelFontSize; + } +}; + +// +// Candle Draw Specifications ... +struct XOHCLDrawSpecification +{ + // + // Props ... + XDrawSpecifications openStyle; + XDrawSpecifications highStyle; + XDrawSpecifications closeStyle; + XDrawSpecifications lowStyle; + + // + // Constructors ... + XOHCLDrawSpecification() + { + Clean(); + } + + // + // Operators ... + void operator=(const XOHCLDrawSpecification &value) + { + // + lowStyle = value.lowStyle; + openStyle = value.openStyle; + highStyle = value.highStyle; + closeStyle = value.closeStyle; + } + + // + // Functions ... + + // + void Clean() + { + // + lowStyle.Clean(); + openStyle.Clean(); + highStyle.Clean(); + closeStyle.Clean(); + } + + // + void Default() + { + // + // Open ... + openStyle.width = 1; + openStyle.draw = true; + openStyle.clr = clrLime; + openStyle.style = STYLE_SOLID; + openStyle.Label( + "O", + openStyle.clr); + + // + // High ... + highStyle.width = 1; + highStyle.draw = true; + highStyle.clr = clrAqua; + highStyle.style = STYLE_SOLID; + highStyle.Label( + "H", + highStyle.clr); + + // + // Close ... + closeStyle.width = 1; + closeStyle.draw = true; + closeStyle.clr = clrRed; + closeStyle.style = STYLE_SOLID; + closeStyle.Label( + "C", + closeStyle.clr); + + // + // Low ... + lowStyle.width = 1; + lowStyle.draw = true; + lowStyle.clr = clrMagenta; + lowStyle.style = STYLE_SOLID; + lowStyle.Label( + "L", + lowStyle.clr); + } + + // + void Width(int value) + { + // + lowStyle.width = value; + openStyle.width = value; + highStyle.width = value; + closeStyle.width = value; + } + + // + void Style(ENUM_LINE_STYLE value) + { + // + lowStyle.style = value; + openStyle.style = value; + highStyle.style = value; + closeStyle.style = value; + } + + // + void Color(color value) + { + // + lowStyle.clr = value; + openStyle.clr = value; + highStyle.clr = value; + closeStyle.clr = value; + } + + // + void RayRight(bool value) + { + // + lowStyle.rayRight = value; + openStyle.rayRight = value; + highStyle.rayRight = value; + closeStyle.rayRight = value; + } + + // + void Draw(bool value) + { + // + lowStyle.draw = value; + openStyle.draw = value; + highStyle.draw = value; + closeStyle.draw = value; + } + + // + void Back(bool value) + { + // + lowStyle.back = value; + openStyle.back = value; + highStyle.back = value; + closeStyle.back = value; + } + + // + void Fill(bool value) + { + // + lowStyle.fill = value; + openStyle.fill = value; + highStyle.fill = value; + closeStyle.fill = value; + } + + // + void Label(string value) + { + // + lowStyle.Label(value); + openStyle.Label(value); + highStyle.Label(value); + closeStyle.Label(value); + } + + // + void SetLabelPrefix(string value) + { + // + lowStyle.label = value + " " + lowStyle.label; + openStyle.label = value + " " + openStyle.label; + highStyle.label = value + " " + highStyle.label; + closeStyle.label = value + " " + closeStyle.label; + } +}; + +// +string drawPrefix = "X-OBJ"; + +// +// Common Draw Functions ... + +// +// remove drawn objects ... +void RemoveDraws( + string tag = NULL, + long chartId = -1, + int subWindow = -1 // +) +{ + // + // Normalize Args ... + // + if (tag == NULL) + { + tag = drawPrefix; + } + + // + if (chartId == -1) + { + chartId = 0; + } + + // + if (subWindow == -1) + { + subWindow = 0; + } + + // + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + if (StringFind(on, tag) >= 0) + { + ObjectDelete(chartId, on); + } + } + + // + // Redraw Chart ... + ChartRedraw(); +} + +// +bool RemoveDraw( + string name, + long chartId = -1, + int subWindow = -1 // +) +{ + // + bool result = false; + + // + if (chartId == -1) + { + chartId = 0; + } + + // + if (subWindow == -1) + { + subWindow = 0; + } + + // + string objName = ""; + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + if (StringFind(on, name) >= 0) + { + // + objName = on; + break; + } + } + + // + if (StringLen(objName) > 0) + { + result = ObjectDelete(chartId, objName); + } + + // + return result; +} + +// +// Deselect All Draws ... +void DeselectAllDraws() +{ + // + int objs = ObjectsTotal(ChartID(), 0); + for (int o = 0; o < objs; o++) + { + ObjectSetInteger(ChartID(), ObjectName(ChartID(), o, 0), OBJPROP_SELECTED, false); + } + + // + ChartRedraw(); +} + +// +// Check Object Exists ... +bool IsDrawExists( + string name, + long chartId = -1, + int subWindow = -1 // +) +{ + // + bool result = false; + + // + if (chartId == -1) + { + chartId = 0; + } + + // + if (subWindow == -1) + { + subWindow = 0; + } + + // + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + result = StringFind(on, name) >= 0; + if (result) + { + break; + } + } + + // + return result; +} + +// +// Find Specific Object Name ... +string FindObjectName( + string suggest, + long chartId = 0, + int subWindow = 0 // +) +{ + // + string result = NULL; + + // + int objectsCount = ObjectsTotal(chartId, subWindow); + if (objectsCount <= 0) + { + return result; + } + + // + for (int i = objectsCount - 1; i >= 0; i--) + { + // + string iObjectName = ObjectName(chartId, i, subWindow); + bool isExists = StringFind(iObjectName, suggest) >= 0; + if (isExists) + { + // + result = iObjectName; + break; + } + } + + // + return result; +} + +// +// Regular Draws ... + +// +// Arrow Functions ... + +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = 252, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) +{ + // + bool result = false; + + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create an arrow ... + result = ObjectCreate(chartID, objName, OBJ_ARROW, subWindow, time, price); + if (!result) + { + return result; + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, objName, 0, time, price); + + // + return result; +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete an arrow ... + result = !ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change the arrow code ... + result = ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, code); + + // + return result; +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change anchor type ... + result = !ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + return result; +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price // +) +{ + // + // if the point's time is not set, it will be on the current bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} + +// +// Horizontal Line Functions ... + +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // if the price is not set, set it at the current Bid price level ... + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a horizontal line ... + result = ObjectCreate(chartID, objName, OBJ_HLINE, subWindow, 0, price); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if the line price is not set, move it to the current Bid price level ... + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // move a horizontal line ... + result = ObjectMove(chartID, objName, 0, 0, price); + + // + return result; +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete a horizontal line ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Vertical Line Functions ... + +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int subWindow = 0, // subwindow index + datetime time = 0, // line time + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // if the line time is not set, draw it via the last bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a vertical line ... + result = ObjectCreate(chartID, objName, OBJ_VLINE, subWindow, time, 0); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if line time is not set, move the line to the last bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // move the vertical line ... + result = ObjectMove(chartID, objName, 0, time, 0); + + // + return result; +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the vertical line ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Rectangle Functions ... + +// +// Create rectangle by the given coordinates ... +bool DrawRectangle( + const long chartID = 0, // chart's ID + const string name = "Rectangle", // rectangle name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // down first point time + double price1 = 0, // down first point price + datetime time2 = 0, // up second point time + double price2 = 0, // up second point price + const color clr = clrRed, // rectangle color + const ENUM_LINE_STYLE style = STYLE_SOLID, // style of rectangle lines + const int width = 1, // width of rectangle lines + const bool fill = false, // filling rectangle with color + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Set anchor points' coordinates if they are not set ... + ChangeRectangleEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create a rectangle by the given coordinates ... + result = ObjectCreate( + chartID, + objName, + OBJ_RECTANGLE, + subWindow, + time1, + price1, + time2, + price2 // + ); + if (!result) + { + return result; + } + + // + // Set rectangle color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // Set the style of rectangle lines + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // Set width of the rectangle lines ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // Enable (true) or disable (false) the mode of filling the rectangle ... + ObjectSetInteger(chartID, objName, OBJPROP_FILL, fill); + + // + // Display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // Enable (true) or disable (false) the mode of highlighting the rectangle for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + + // + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // Hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // Set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // Successful execution + return result; +} + +// +// Move the rectangle anchor point ...s +bool RectanglePointChange( + const long chartID = 0, // chart's ID + const string name = "Rectangle", // rectangle name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // Move the anchor point ... + result = ObjectMove(chartID, objName, pointIndex, time, price); + + // + return result; +} + +// +// Delete the rectangle ... +bool DeleteRectangle( + const long chartID = 0, // chart's ID + const string name = "Rectangle" // rectangle name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check the values of rectangle's anchor points and set default +// values for empty ones +void ChangeRectangleEmptyPoints( + datetime &time1, double &price1, + datetime &time2, double &price2 // +) +{ + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) + { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) + { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, move it 300 points lower than the first one ... + if (!price2) + { + price2 = price1 - 300 * SymbolInfoDouble(Symbol(), SYMBOL_POINT); + } +} + +// +// RectangleLabel Functions ... + +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color bgColor = clrWhiteSmoke, // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a rectangle label + result = ObjectCreate(chartID, objName, OBJ_RECTANGLE_LABEL, subWindow, 0, 0); + if (!result) + { + return result; + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor); + + // + // set border type ... + ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the label by mouse ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y = 0 // Y coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // move the rectangle label ... + result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + return result; +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the label ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change label size ... + result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + return result; +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change border type ... + result = ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border); + + // + return result; +} + +// +// TrendLine Funcions ... + +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a trend line by the given coordinates ... + result = ObjectCreate(chartID, objName, OBJ_TREND, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // move trend line's anchor point ... + result = ObjectMove(chartID, objName, pointindex, time, price); + + // + return result; +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete a trend line ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 // +) +{ + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) + { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) + { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) + { + price2 = price1; + } +} + +// +// Text Functions ... + +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time, price); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // + // create Text object + result = ObjectCreate(chartID, objName, OBJ_TEXT, subWindow, time, price); + if (!result) + { + return result; + } + + // + // set the text ... + ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, objName, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, objName, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the object by mouse ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // + // if point position is not set, move it to the current bar having Bid price + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, objName, 0, time, price); + + // + return result; +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change object text ... + result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the object ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price // +) +{ + // + // if the point's time is not set, it will be on the current bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} + +// +// Fibonacchi Functions ... + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create Fibonacci Retracement by the given coordinates ... + result = ObjectCreate(chartID, objName, OBJ_FIBO, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create Fibonacci Retracement by the given coordinates ... + result = ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + objName); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) +{ + // + bool result = false; + + // + // check array sizes ... + result = levels == ArraySize(colors) && + levels == ArraySize(styles) && + levels == ArraySize(widths) && + levels == ArraySize(widths); + if (!result) + { + return result; + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // set the number of levels ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for (int i = 0; i < levels; i++) + { + // + // level value ... + ObjectSetDouble(chartID, objName, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, objName, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return result; +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, objName, pointIndex, time, price); + + // + return result; +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the object ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 // +) +{ + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) + { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) + { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time2, 10, temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) + { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} + +// +// Event Functions ... + +// +// Create an Event ... +bool EventCreate( + const long chartID = 0, // chart's ID + const string name = "Event", // object name + const int subWindow = 0, // subwindow index + const string text = "Content", // event text + datetime time = 0, // anchor point time + const color clr = clrRed, // color + const int width = 1, // point width when highlighted + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + if (!time) + { + time = TimeCurrent(); + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectCreate(chartID, objName, OBJ_EVENT, subWindow, time, 0); + if (!result) + { + return result; + } + + // + // set event text + ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + // set color + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set anchor point width if the object is highlighted + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving event by mouse + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution + return result; +} + +// +// Change Event object text +bool EventTextChange( + const long chartID = 0, // chart's ID + const string name = "Event", // event name + const string text = "Content" // text +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change object text + result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Move Event object +bool EventMove( + const long chartID = 0, // chart's ID + const string name = "Event", // event name + datetime time = 0 // time +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if time is not set, move event to the last bar + if (!time) + { + time = TimeCurrent(); + } + + // + // move the object + result = ObjectMove(chartID, objName, 0, time, 0); + + // + return result; +} + +// +// Delete Event object +bool EventDelete( + const long chartID = 0, // chart's ID + const string name = "Event" // event name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the object + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Button Functions ... + +// +// Create the button ... +bool ButtonCreate( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // button width + const int height = 15, // button height + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const string text = "Button", // text + const string font = "Arial", // font + const int fontSize = 8, // font size + const color clr = clrBlack, // text color + const color bgColor = clrLightGray, // background color + const color borderColor = clrNONE, // border color + const bool state = false, // pressed/released + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create the button + result = ObjectCreate(chartID, objName, OBJ_BUTTON, subWindow, 0, 0); + if (!result) + { + return result; + } + + // + // set button coordinates + ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + // set button size + ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + // set the chart's corner, relative to which point coordinates are defined + ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); + + // + // set the text + ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + // set text font + ObjectSetString(chartID, objName, OBJPROP_FONT, font); + + // + // set font size + ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize); + + // + // set text color + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set background color + ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor); + + // + // set border color + ObjectSetInteger(chartID, objName, OBJPROP_BORDER_COLOR, borderColor); + + // + // display in the foreground false or background true + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // set button state + ObjectSetInteger(chartID, objName, OBJPROP_STATE, state); + + // + // enable true or disable false the mode of moving the button by mouse + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + return result; +} + +// +// Move the button ... +bool ButtonMove( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int x = 0, // X coordinate + const int y = 0 // Y coordinate +) +{ + // + bool result = false; + + // + // move the button + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + return result; +} + +// +// Change button size ... +bool ButtonChangeSize( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int width = 50, // button width + const int height = 18 // button height +) +{ + // + bool result = false; + + // + // change the button size + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + return result; +} + +// +// Change corner of the chart for binding the button ... +bool ButtonChangeCorner( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER // chart corner for anchoring +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change anchor corner + result = ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); + + // + return result; +} + +// +// Change button text ... +bool ButtonTextChange( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const string text = "Text" // text +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change object text + result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Delete the button ... +bool ButtonDelete( + const long chartID = 0, // chart's ID + const string name = "Button" // button name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the button + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Chart Style Drawers ... + +// +// Apply Styles On Chart ... +void ApplyChartStyle( + long mChartId = -1, // chart's ID + ENUM_CHART_MODE mMode = CHART_CANDLES, // chart's mMode + bool mShowBidLine = true, // show bid line + bool mShowAskLine = true, // show ask line + bool mShowGrid = false, // show grids on chart + bool mShowVolumes = false, // show volumes + bool mShowTradeLevels = true, // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) + bool mAutoScroll = true, // chart autoscroll + bool mQuickNavigation = true, // chart quick navigation state + color mForeGroundColor = clrWhite, // chart's foreground color + color mBackGroundColor = clrBlack, // chart's background color + color mUpColor = clrGreen, // Up Color + color mDownColor = clrRed, // Down Color + color mBullishColor = clrGreen, // Bullish color + color mBearishColor = clrRed, // Bearish color + color mGridColor = clrGray, // grid color + color mBidLineColor = clrGray, // bid line color + color mAskLineColor = clrRed, // ask line color + color mLineColor = clrLime, // line mMode and doji candlestick color + color mStopColor = clrGold, // Color of stop order levels (Stop Loss and Take Profit) + color mVolumesColor = clrGreen // volumes color +) +{ + // + // Validate Args ... + if (mChartId == -1) + { + mChartId = 0; + } + + // + ChartSetInteger(mChartId, CHART_MODE, mMode); + ChartSetInteger(mChartId, CHART_SHOW_BID_LINE, mShowBidLine); + ChartSetInteger(mChartId, CHART_SHOW_ASK_LINE, mShowAskLine); + ChartSetInteger(mChartId, CHART_SHOW_GRID, mShowGrid); + ChartSetInteger(mChartId, CHART_SHOW_VOLUMES, mShowVolumes); + ChartSetInteger(mChartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels); + ChartSetInteger(mChartId, CHART_AUTOSCROLL, mAutoScroll); + ChartSetInteger(mChartId, CHART_QUICK_NAVIGATION, mQuickNavigation); + ChartSetInteger(mChartId, CHART_COLOR_FOREGROUND, mForeGroundColor); + ChartSetInteger(mChartId, CHART_COLOR_BACKGROUND, mBackGroundColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_UP, mUpColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_DOWN, mDownColor); + ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BULL, mBullishColor); + ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BEAR, mBearishColor); + ChartSetInteger(mChartId, CHART_COLOR_GRID, mGridColor); + ChartSetInteger(mChartId, CHART_COLOR_BID, mBidLineColor); + ChartSetInteger(mChartId, CHART_COLOR_ASK, mAskLineColor); + ChartSetInteger(mChartId, CHART_COLOR_STOP_LEVEL, mStopColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_LINE, mLineColor); + ChartSetInteger(mChartId, CHART_COLOR_VOLUME, mVolumesColor); +} + +// +// Tools ... + +// +// Retrieve Chart Size ... +bool GetChartSize( + XSize &result, // Holds Result ... + long chartID = 0 // Specified Chart ID ... +) +{ + // + bool mResult = false; + + // + mResult = ChartGetInteger(0, CHART_WIDTH_IN_PIXELS, 0, result.width); + if (!mResult) + { + return mResult; + } + + // + mResult = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, 0, result.height); + + // + return mResult; +} diff --git a/Documents/BKP/14030802-X121/Libraries/x-saherelm.tools.lib.mq5 b/Documents/BKP/14030802-X121/Libraries/x-saherelm.tools.lib.mq5 new file mode 100644 index 00000000..f61a5a24 --- /dev/null +++ b/Documents/BKP/14030802-X121/Libraries/x-saherelm.tools.lib.mq5 @@ -0,0 +1,2193 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Tools Library +// -------------------------------------- +// Name: XToolsLib +// Description: provide all commonly used Tools ... +// +// +// 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 "../Libraries/x-saherelm.draw.lib.mq5" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Definitions ... +string XTLSHammerToken = "XHammer"; +string XTLSSupportToken = "XSupport"; +string XTLSSwingLowToken = "XSwingLow"; +string XTLSSwingHighToken = "XSwingHigh"; +string XTLSResistanceToken = "XResistance"; +string XTLSBullishFVGToken = "XBullishFVG"; +string XTLSBearishFVGToken = "XBearishFVG"; +string XTLSMorningStarToken = "XMorningStar"; +string XTLSEveningStarToken = "XEveningStar"; +string XTLSShootingStarToken = "XShootingStar"; +string XTLSBullishTrendToken = "XBullishTrend"; +string XTLSBearishTrendToken = "XBearishTrend"; +string XTLSBullishEngulfingToken = "XBullishEngulfing"; +string XTLSBearishEngulfingToken = "XBearishEngulfing"; +string XTLSBullishOrderBlockToken = "XBullishOrderBlock"; +string XTLSBearishOrderBlockToken = "XBearishOrderBlock"; + +// +// Helper Tools ... + +// +bool HasBullishPattern( + XOHCL &bar, + int loopback = 0, + int verifications = 1, + bool checkHammer = true, + bool checkMorningStar = true, + bool checkBullishMarubozu = true, + bool checkBullishEngulfing = true // +) +{ + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + if (verifications <= 0) + { + verifications = 1; + } + + // + int founded = 0; + + // + int idx = bar.Index(); + for (int i = idx; i <= idx + loopback; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + bool isHammer = + !checkHammer + ? false + : iBar.IsHammer(); + if (isHammer) + { + founded++; + } + + // + bool isMorningStar = + !checkMorningStar + ? false + : iBar.IsMorningStar(); + if (isMorningStar) + { + founded++; + } + + // + bool isBullishMarubozu = + !checkBullishMarubozu + ? false + : iBar.IsBullishMarubozu(); + if (isBullishMarubozu) + { + founded++; + } + + // + bool isBullishEngulfing = + !checkBullishEngulfing + ? false + : iBar.IsBullishEngulfing(); + if (isBullishEngulfing) + { + founded++; + } + + // + } + + // + result = + result && + founded >= verifications; + + // + return result; +} + +// +bool HasBearishPattern( + XOHCL &bar, + int loopback = 0, + int verifications = 1, + bool checkShootingStar = true, + bool checkEveningStar = true, + bool checkBearishMarubozu = true, + bool checkBearishEngulfing = true // +) +{ + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + if (verifications <= 0) + { + verifications = 1; + } + + // + int founded = 0; + + // + int idx = bar.Index(); + for (int i = idx - 1; i <= idx + loopback; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + bool isShootingStar = + !checkShootingStar + ? false + : iBar.IsShootingStar(); + if (isShootingStar) + { + founded++; + } + + // + bool isEveningStar = + !checkEveningStar + ? false + : iBar.IsEveningStar(); + if (isEveningStar) + { + founded++; + } + + // + bool isBearishMarubozu = + !checkBearishMarubozu + ? false + : iBar.IsBearishMarubozu(); + if (isBearishMarubozu) + { + founded++; + } + + // + bool isBearishEngulfing = + !checkBearishEngulfing + ? false + : iBar.IsBearishEngulfing(); + if (isBearishEngulfing) + { + founded++; + } + + // + } + + // + result = + result && + founded >= verifications; + + // + return result; +} + +// +bool IsSupportBreaked( + XOHCL &bar, // Support Bar + bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure + bool checkShootingStar = true, // Check Shooting Star Pattern for Pressure Verifications + bool checkEveningStar = true, // Check Evening Star Pattern for Pressure Verifications + bool checkBearishEngulfingStar = true, // Check Bearish Engulfing Pattern for Pressure Verifications + double _threshold = 0, // Upper and Lower threshold of Pivot + double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break + int _loopback = 3 // Verification Loopback +) +{ + // + bool result = false; + + // + if (_breakVerificationPoint < 0) + { + _breakVerificationPoint = 15; + } + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + double points = GetPoints(bar.symbol); + + // + double threshold = 0; + if (_threshold > 0) + { + threshold = _threshold * points; + } + + // + double price = GetBid(bar.symbol); + + // + // Check Price is Below of Support High ... + result = price < bar.high + threshold; + if (!result) + { + return result; + } + + // + // Check Break Verification ... + if (_breakVerificationPoint > 0) + { + // + result = (bar.high + threshold) - price >= _breakVerificationPoint * points; + if (!result) + { + return result; + } + } + + // + if (_verifyPressure && _loopback > 0) + { + // + // Verify Pressure by Candlestick Patterns ... + // We need last 3 Candle ... + + // + for (int i = 0; i < _loopback; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + // Shooting Star ... + bool isShootingStar = !checkShootingStar + ? false + : iBar.IsShootingStar(); + if (isShootingStar) + { + // + DrawShootingStar( + iBar, + ChartID() // + ); + } + + // + // Evening Star ... + bool isEveningStar = !checkEveningStar + ? false + : iBar.IsEveningStar(); + if (isEveningStar) + { + // + DrawEveningStar( + iBar, + ChartID() // + ); + } + + // + // BearishEngulfing ... + bool isBearishEngulfing = !checkBearishEngulfingStar + ? false + : iBar.IsBearishEngulfing(); + if (isBearishEngulfing) + { + // + DrawBearishEngulfing( + iBar, + ChartID() // + ); + } + + // + result = + // + isShootingStar + // + || + // + isEveningStar + // + || + // + isBearishEngulfing + // + ; + if (result) + { + break; + } + } + } + + // + return result; +} + +// +bool IsSupportRejected( + XOHCL &bar, // Support Bar + bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure + bool checkHammer = true, // Check Hammer Pattern for Pressure Verifications + bool checkMorningStar = true, // Check Morning Star Pattern for Pressure Verifications + bool checkBullishEngulfing = true, // Check Bullish Engulfing Pattern for Pressure Verifications + double _threshold = 0, // Upper and Lower threshold of Pivot + double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break + int _loopback = 3 // Verification Loopback +) +{ + // + bool result = false; + + // + if (_breakVerificationPoint < 0) + { + _breakVerificationPoint = 15; + } + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + double points = GetPoints(bar.symbol); + + // + double threshold = 0; + if (_threshold > 0) + { + threshold = _threshold * points; + } + + // + double price = GetBid(bar.symbol); + + // + XOHCL cBar; + result = cBar.Init( + bar.symbol, + bar.period, + 0 // + ); + if (!result) + { + return result; + } + + // + double ll2 = cBar.FindLowest( + 2, + MODE_LOW // + ); + + // + // Check Price is Below of Support High ... + result = + // + price > bar.high + threshold && + ( + // + ll2 < bar.high + // + || + // + ll2 < bar.high - threshold + // + || + // + (threshold > 0 && MathAbs(ll2 - price) > 0 && MathAbs(ll2 - price) <= threshold) + // + ) + // + ; + if (!result) + { + return result; + } + + // + // Check Break Verification ... + if (_breakVerificationPoint > 0) + { + // + result = MathAbs((bar.high + threshold) - price) >= _breakVerificationPoint * points; + if (!result) + { + return result; + } + } + + // + if (_verifyPressure && _loopback > 0) + { + // + // Verify Pressure by Candlestick Patterns ... + // We need last 3 Candle ... + + // + for (int i = 0; i < _loopback; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + // Hammer ... + bool isHammer = !checkHammer + ? false + : iBar.IsHammer(); + if (isHammer) + { + // + DrawHammer( + iBar, + ChartID() // + ); + } + + // + // Morning Star ... + bool isMorningStar = !checkMorningStar + ? false + : iBar.IsMorningStar(); + if (isMorningStar) + { + // + DrawMorningStar( + iBar, + ChartID() // + ); + } + + // + // BullishEngulfing ... + bool isBullishEngulfing = !checkBullishEngulfing + ? false + : iBar.IsBullishEngulfing(); + if (isBullishEngulfing) + { + // + DrawBullishEngulfing( + iBar, + ChartID() // + ); + } + + // + result = + // + isHammer + // + || + // + isMorningStar + // + || + // + isBullishEngulfing + // + ; + if (result) + { + break; + } + } + } + + // + return result; +} + +// +bool IsResistanceBreaked( + XOHCL &bar, // Resistance Bar + bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure + bool checkHammer = true, // Check Hammer Pattern for Pressure Verifications + bool checkMorningStar = true, // Check Morning Star Pattern for Pressure Verifications + bool checkBullishEngulfing = true, // Check Bullish Engulfing Pattern for Pressure Verifications + double _threshold = 0, // Upper and Lower threshold of Pivot + double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break + int _loopback = 3 // Verification Loopback +) +{ + // + bool result = false; + + // + if (_breakVerificationPoint < 0) + { + _breakVerificationPoint = 15; + } + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + double points = GetPoints(bar.symbol); + + // + double threshold = 0; + if (_threshold > 0) + { + threshold = _threshold * points; + } + + // + double price = GetBid(bar.symbol); + + // + // Check Price is Below of Support High ... + result = price > bar.low - threshold; + if (!result) + { + return result; + } + + // + // Check Break Verification ... + if (_breakVerificationPoint > 0) + { + // + result = price - (bar.low - threshold) >= _breakVerificationPoint * points; + if (!result) + { + return result; + } + } + + // + if (_verifyPressure && _loopback > 0) + { + // + // Verify Pressure by Candlestick Patterns ... + // We need last 3 Candle ... + + // + for (int i = 0; i < _loopback; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + // Hammer ... + bool isHammer = !checkHammer + ? false + : iBar.IsHammer(); + if (isHammer) + { + // + DrawHammer( + iBar, + ChartID() // + ); + } + + // + // Morning Star ... + bool isMorningStar = !checkMorningStar + ? false + : iBar.IsMorningStar(); + if (isMorningStar) + { + // + DrawMorningStar( + iBar, + ChartID() // + ); + } + + // + // BullishEngulfing ... + bool isBullishEngulfing = !checkBullishEngulfing + ? false + : iBar.IsBullishEngulfing(); + if (isBullishEngulfing) + { + // + DrawBullishEngulfing( + iBar, + ChartID() // + ); + } + + // + result = + // + isHammer + // + || + // + isMorningStar + // + || + // + isBullishEngulfing + // + ; + if (result) + { + break; + } + } + } + + // + return result; +} + +// +bool IsResistanceRejected( + XOHCL &bar, // Resistance Bar + bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure + bool checkShootingStar = true, // Check Shooting Star Pattern for Pressure Verifications + bool checkEveningStar = true, // Check Evening Star Pattern for Pressure Verifications + bool checkBearishEngulfingStar = true, // Check Bearish Engulfing Pattern for Pressure Verifications + double _threshold = 0, // Upper and Lower threshold of Pivot + double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break + int _loopback = 3 // Verification Loopback +) +{ + // + bool result = false; + + // + if (_breakVerificationPoint < 0) + { + _breakVerificationPoint = 15; + } + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + double points = GetPoints(bar.symbol); + + // + double threshold = 0; + if (_threshold > 0) + { + threshold = _threshold * points; + } + + // + double price = GetBid(bar.symbol); + + // + XOHCL cBar; + result = cBar.Init( + bar.symbol, + bar.period, + 0 // + ); + if (!result) + { + return result; + } + + // + double hh2 = cBar.FindHighest( + 2, + MODE_HIGH // + ); + + // + // Check Price is Below of Support High ... + result = + // + price < bar.low - threshold && + ( + // + hh2 > bar.low + // + || + // + hh2 > bar.low - threshold + // + || + // + (threshold > 0 && MathAbs(hh2 - price) > 0 && MathAbs(hh2 - price) <= threshold)) + // + ; + if (!result) + { + return result; + } + + // + // Check Break Verification ... + if (_breakVerificationPoint > 0) + { + // + result = MathAbs((bar.low - threshold) - price) >= _breakVerificationPoint * points; + if (!result) + { + return result; + } + } + + // + if (_verifyPressure && _loopback > 0) + { + // + // Verify Pressure by Candlestick Patterns ... + // We need last 3 Candle ... + + // + for (int i = 0; i < _loopback; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + // Shooting Star ... + bool isShootingStar = !checkShootingStar + ? false + : iBar.IsShootingStar(); + if (isShootingStar) + { + // + DrawShootingStar( + iBar, + ChartID() // + ); + } + + // + // Evening Star ... + bool isEveningStar = !checkEveningStar + ? false + : iBar.IsEveningStar(); + if (isEveningStar) + { + // + DrawEveningStar( + iBar, + ChartID() // + ); + } + + // + // BearishEngulfing ... + bool isBearishEngulfing = !checkBearishEngulfingStar + ? false + : iBar.IsBearishEngulfing(); + if (isBearishEngulfing) + { + // + DrawBearishEngulfing( + iBar, + ChartID() // + ); + } + + // + result = + // + isShootingStar + // + || + // + isEveningStar + // + || + // + isBearishEngulfing + // + ; + if (result) + { + break; + } + } + } + + // + return result; +} + +// +// Drawing Tools ... + +// +// Hammer ... + +// +string GetHammerTag(XOHCL &bar) +{ + return XTLSHammerToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawHammer( + XOHCL &bar, + long chartID, + color clr = clrAqua, + uint width = 1, + uchar arrow = 233 // +) +{ + // + bool result = false; + + // + string name = GetHammerTag(bar); + + // + result = DrawArrow( + chartID, + name, + 0, + bar.time, + bar.low, + arrow, + ANCHOR_TOP, + clr, + STYLE_SOLID, + width // + ); + + // + return result; +} + +// +void RemoveHammer(XOHCL &bar) +{ + RemoveDraws(GetHammerTag(bar)); +} + +// +// Shooting Star ... + +// +string GetShootingStarTag(XOHCL &bar) +{ + return XTLSShootingStarToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawShootingStar( + XOHCL &bar, + long chartID, + color clr = clrMagenta, + uint width = 1, + uchar arrow = 234 // +) +{ + // + bool result = false; + + // + string name = GetShootingStarTag(bar); + + // + result = DrawArrow( + chartID, + name, + 0, + bar.time, + bar.high, + arrow, + ANCHOR_BOTTOM, + clr, + STYLE_SOLID, + width // + ); + + // + return result; +} + +// +void RemoveShootingStar(XOHCL &bar) +{ + RemoveDraws(GetShootingStarTag(bar)); +} + +// +// Bullish Engulfing ... + +// +string GetBullishEngulfingTag(XOHCL &bar) +{ + return XTLSBullishEngulfingToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBullishEngulfing( + XOHCL &bar, + long chartID, + color clr = clrAqua, + bool fill = false, + uint width = 1, + ENUM_LINE_STYLE style = STYLE_SOLID // +) +{ + // + bool result = false; + + // + XOHCL pBar; + result = bar.GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + string name = GetBullishEngulfingTag(bar); + + // + DrawRectangle( + chartID, + name, + 0, + pBar.time, + pBar.low, + bar.time, + bar.high, + clr, + style, + width, + fill // + ); + + // + return result; +} + +// +void RemoveBullishEngulfing(XOHCL &bar) +{ + RemoveDraws(GetBullishEngulfingTag(bar)); +} + +// +// Bearish Engulfing ... + +// +string GetBearishEngulfingTag(XOHCL &bar) +{ + return XTLSBearishEngulfingToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBearishEngulfing( + XOHCL &bar, + long chartID, + color clr = clrMagenta, + bool fill = false, + uint width = 1, + ENUM_LINE_STYLE style = STYLE_SOLID // +) +{ + // + bool result = false; + + // + XOHCL pBar; + result = bar.GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + string name = GetBearishEngulfingTag(bar); + + // + DrawRectangle( + chartID, + name, + 0, + pBar.time, + pBar.low, + bar.time, + bar.high, + clr, + style, + width, + fill // + ); + + // + return result; +} + +// +void RemoveBearishEngulfing(XOHCL &bar) +{ + RemoveDraws(GetBearishEngulfingTag(bar)); +} + +// +// Morning Star ... + +// +string GetMorningStarTag(XOHCL &bar) +{ + return XTLSMorningStarToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawMorningStar( + XOHCL &bar, + long chartID, + color clr = clrAqua, + uint width = 1, + uchar arrow = 233 // +) +{ + // + bool result = false; + + // + string name = GetMorningStarTag(bar); + + // + result = DrawArrow( + chartID, + name, + 0, + bar.time, + bar.low, + arrow, + ANCHOR_TOP, + clr, + STYLE_SOLID, + width // + ); + + // + return result; +} + +// +void RemoveMorningStar(XOHCL &bar) +{ + RemoveDraws(GetMorningStarTag(bar)); +} + +// +// Evening Star ... + +// +string GetEveningStarTag(XOHCL &bar) +{ + return XTLSEveningStarToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawEveningStar( + XOHCL &bar, + long chartID, + color clr = clrMagenta, + uint width = 1, + uchar arrow = 234 // +) +{ + // + bool result = false; + + // + string name = GetEveningStarTag(bar); + + // + result = DrawArrow( + chartID, + name, + 0, + bar.time, + bar.high, + arrow, + ANCHOR_BOTTOM, + clr, + STYLE_SOLID, + width // + ); + + // + return result; +} + +// +void RemoveEveningStar(XOHCL &bar) +{ + RemoveDraws(GetEveningStarTag(bar)); +} + +// +// Swing High ... + +// +string GetSwingHighTag(XOHCL &bar) +{ + return XTLSSwingHighToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawSwingHigh( + XOHCL &bar, + long chartID, + color clr = clrMagenta, + uint width = 1, + uchar arrow = 108 // +) +{ + // + bool result = false; + + // + string name = GetSwingHighTag(bar); + + // + result = DrawArrow( + chartID, + name, + 0, + bar.time, + bar.high, + arrow, + ANCHOR_BOTTOM, + clr, + STYLE_SOLID, + width // + ); + + // + return result; +} + +// +void RemoveSwingHigh(XOHCL &bar) +{ + RemoveDraws(GetSwingHighTag(bar)); +} + +// +// Swing Low ... + +// +string GetSwingLowTag(XOHCL &bar) +{ + return XTLSSwingLowToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawSwingLow( + XOHCL &bar, + long chartID, + color clr = clrAqua, + uint width = 1, + uchar arrow = 108 // +) +{ + // + bool result = false; + + // + string name = GetSwingLowTag(bar); + + // + result = DrawArrow( + chartID, + name, + 0, + bar.time, + bar.low, + arrow, + ANCHOR_TOP, + clr, + STYLE_SOLID, + width // + ); + + // + return result; +} + +// +void RemoveSwingLow(XOHCL &bar) +{ + RemoveDraws(GetSwingLowTag(bar)); +} + +// +// Bullish FVG ... + +// +string GetBullishFVGTag(XOHCL &bar) +{ + return XTLSBullishFVGToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBullishFVG( + XOHCL &bar, + double upper, + double lower, + long chartID, + color clr = clrAqua, + bool fill = false, + uint width = 1, + ENUM_LINE_STYLE style = STYLE_SOLID // +) +{ + // + bool result = false; + + // + XOHCL pBar; + result = bar.GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + string name = GetBullishFVGTag(bar); + + // + DrawRectangle( + chartID, + name, + 0, + ppBar.time, + lower, + bar.time, + upper, + clr, + style, + width, + fill // + ); + + // + return result; +} + +// +void RemoveBullishFVG(XOHCL &bar) +{ + RemoveDraws(GetBullishFVGTag(bar)); +} + +// +// Bearish FVG ... + +// +string GetBearishFVGTag(XOHCL &bar) +{ + return XTLSBearishFVGToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBearishFVG( + XOHCL &bar, + double upper, + double lower, + long chartID, + color clr = clrMagenta, + bool fill = false, + uint width = 1, + ENUM_LINE_STYLE style = STYLE_SOLID // +) +{ + // + bool result = false; + + // + XOHCL pBar; + result = bar.GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + string name = GetBearishFVGTag(bar); + + // + DrawRectangle( + chartID, + name, + 0, + ppBar.time, + upper, + bar.time, + lower, + clr, + style, + width, + fill // + ); + + // + return result; +} + +// +void RemoveBearishFVG(XOHCL &bar) +{ + RemoveDraws(GetBearishFVGTag(bar)); +} + +// +// Bullish Order Block ... + +// +string GetBullishOrderBlockTag(XOHCL &bar) +{ + return XTLSBullishOrderBlockToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBullishOrderBlock( + XOHCL &bar, + long chartID, + bool ray = true, + color clr = clrAqua, + ENUM_LINE_STYLE style = STYLE_DOT, + uint width = 1 // +) +{ + // + bool result = false; + + // + string name = GetBullishOrderBlockTag(bar); + datetime cTime = TimeCurrent(); + + // + // Draw Upper Line ... + result = DrawTrendLine( + chartID, + name + "-Upper", + 0, + bar.time, + bar.high, + cTime, + bar.high, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + // Draw Lower Line ... + result = DrawTrendLine( + chartID, + name + "-Lower", + 0, + bar.time, + bar.low, + cTime, + bar.low, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + return result; +} + +// +void RemoveBullishOrderBlock(XOHCL &bar) +{ + RemoveDraws(GetBullishOrderBlockTag(bar)); +} + +// +// Bearish Order Block ... + +// +string GetBearishOrderBlockTag(XOHCL &bar) +{ + return XTLSBearishOrderBlockToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBearishOrderBlock( + XOHCL &bar, + long chartID, + bool ray = true, + color clr = clrMagenta, + ENUM_LINE_STYLE style = STYLE_DOT, + uint width = 1 // +) +{ + // + bool result = false; + + // + string name = GetBearishOrderBlockTag(bar); + datetime cTime = TimeCurrent(); + + // + // Draw Upper Line ... + result = DrawTrendLine( + chartID, + name + "-Upper", + 0, + bar.time, + bar.high, + cTime, + bar.high, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + // Draw Lower Line ... + result = DrawTrendLine( + chartID, + name + "-Lower", + 0, + bar.time, + bar.low, + cTime, + bar.low, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + return result; +} + +// +void RemoveBearishOrderBlock(XOHCL &bar) +{ + RemoveDraws(GetBearishOrderBlockTag(bar)); +} + +// +// Support ... + +// +string GetSupportTag(XOHCL &bar) +{ + return XTLSSupportToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawSupport( + XOHCL &bar, + long chartID, + double _threshold = 0, + bool ray = true, + color clr = clrGreen, + ENUM_LINE_STYLE style = STYLE_DASH, + uint width = 1, + color thresholdColor = clrAqua // +) +{ + // + bool result = false; + + // + datetime time2 = TimeCurrent(); + + // + string name = GetSupportTag(bar); + + // + result = DrawTrendLine( + chartID, + name, + 0, + bar.time, + bar.high, + time2, + bar.high, + clr, + style, + width, + false, + false, + ray // + ); + + // + if (result && _threshold > 0) + { + // + double threshold = GetPoints(bar.symbol) * _threshold; + + // + string upThresholdName = name + "UP"; + string downThresholdName = name + "DOWN"; + + // + result = DrawTrendLine( + chartID, + upThresholdName, + 0, + bar.time, + bar.high + threshold, + time2, + bar.high + threshold, + thresholdColor, + style, + width, + false, + false, + ray // + ); + + // + if (result) + { + + // + result = DrawTrendLine( + chartID, + downThresholdName, + 0, + bar.time, + bar.high - threshold, + time2, + bar.high - threshold, + thresholdColor, + style, + width, + false, + false, + ray // + ); + } + } + + // + return result; +} + +// +void RemoveSupport(XOHCL &bar) +{ + RemoveDraws(GetSupportTag(bar)); +} + +// +// Support ... + +// +string GetResistanceTag(XOHCL &bar) +{ + return XTLSResistanceToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawResistance( + XOHCL &bar, + long chartID, + double _threshold = 0, + bool ray = true, + color clr = clrRed, + ENUM_LINE_STYLE style = STYLE_DASH, + uint width = 1, + color thresholdColor = clrMagenta // +) +{ + // + bool result = false; + + // + datetime time2 = TimeCurrent(); + + // + string name = GetResistanceTag(bar); + + // + result = DrawTrendLine( + chartID, + name, + 0, + bar.time, + bar.low, + time2, + bar.low, + clr, + style, + width, + false, + false, + ray // + ); + + // + if (result && _threshold > 0) + { + // + double threshold = GetPoints(bar.symbol) * _threshold; + + // + string upThresholdName = name + "UP"; + string downThresholdName = name + "DOWN"; + + // + result = DrawTrendLine( + chartID, + upThresholdName, + 0, + bar.time, + bar.low + threshold, + time2, + bar.low + threshold, + thresholdColor, + style, + width, + false, + false, + ray // + ); + + // + if (result) + { + + // + result = DrawTrendLine( + chartID, + downThresholdName, + 0, + bar.time, + bar.low - threshold, + time2, + bar.low - threshold, + thresholdColor, + style, + width, + false, + false, + ray // + ); + } + } + + // + return result; +} + +// +void RemoveResistance(XOHCL &bar) +{ + RemoveDraws(GetResistanceTag(bar)); +} + +// +// Bullish Trend ... + +// +string GetBullishTrendTag(XOHCL &bar) +{ + return XTLSBullishTrendToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBullishTrend( + XOHCL &bar, + XOHCL &highSwingBars[], + XOHCL &lowSwingBars[], + long chartID, + bool ray = true, + bool drawSwings = true, + color clr = clrAqua, + ENUM_LINE_STYLE style = STYLE_DOT, + uint width = 1, + uchar swingHighArrow = 108, + color swingHighColor = clrAqua, + uchar swingLowArrow = 108, + color swingLowColor = clrMagenta // +) +{ + // + bool result = false; + + // + string name = GetBullishTrendTag(bar); + + // + XOHCL first; + XOHCL last; + + // + // Draw Upper Trend Line ... + first = highSwingBars[ArraySize(highSwingBars) - 1]; + last = highSwingBars[0]; + + // + result = DrawTrendLine( + chartID, + name + "-Upper", + 0, + first.time, + first.high, + last.time, + last.high, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + // Draw Lower Trend Line ... + first = lowSwingBars[ArraySize(lowSwingBars) - 1]; + last = lowSwingBars[0]; + + // + result = DrawTrendLine( + chartID, + name + "-Lower", + 0, + first.time, + first.high, + last.time, + last.high, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + if (result && drawSwings) + { + // + // High Swings ... + for (int i = 0; i < ArraySize(highSwingBars); i++) + { + // + XOHCL iBar = highSwingBars[i]; + + // + result = DrawArrow( + chartID, + name + "-SwingHigh-" + ToString(i), + 0, + iBar.time, + iBar.high, + swingHighArrow, + ANCHOR_BOTTOM, + swingHighColor, + STYLE_SOLID, + width // + ); + if (!result) + { + break; + } + } + + // + // Low Swings ... + for (int i = 0; i < ArraySize(lowSwingBars); i++) + { + // + XOHCL iBar = lowSwingBars[i]; + + // + result = DrawArrow( + chartID, + name + "-SwingLow-" + ToString(i), + 0, + iBar.time, + iBar.low, + swingLowArrow, + ANCHOR_TOP, + swingLowColor, + STYLE_SOLID, + width // + ); + if (!result) + { + break; + } + } + } + + // + return result; +} + +// +void RemoveBullishTrend(XOHCL &bar) +{ + RemoveDraws(GetBullishTrendTag(bar)); +} + +// +// Bearish Trend ... + +// +string GetBearishTrendTag(XOHCL &bar) +{ + return XTLSBearishTrendToken + "-" + GetBarTimeTag(bar); +} + +// +bool DrawBearishTrend( + XOHCL &bar, + XOHCL &highSwingBars[], + XOHCL &lowSwingBars[], + long chartID, + bool ray = true, + bool drawSwings = true, + color clr = clrMagenta, + ENUM_LINE_STYLE style = STYLE_DOT, + uint width = 1, + uchar swingHighArrow = 108, + color swingHighColor = clrMagenta, + uchar swingLowArrow = 108, + color swingLowColor = clrAqua // +) +{ + // + bool result = false; + + // + string name = GetBearishTrendTag(bar); + + // + XOHCL first; + XOHCL last; + + // + // Draw Upper Trend Line ... + first = highSwingBars[ArraySize(highSwingBars) - 1]; + last = highSwingBars[0]; + + // + result = DrawTrendLine( + chartID, + name + "-Upper", + 0, + first.time, + first.high, + last.time, + last.high, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + // Draw Lower Trend Line ... + first = lowSwingBars[ArraySize(lowSwingBars) - 1]; + last = lowSwingBars[0]; + + // + result = DrawTrendLine( + chartID, + name + "-Lower", + 0, + first.time, + first.high, + last.time, + last.high, + clr, + style, + width, + false, + false, + ray // + ); + if (!result) + { + return result; + } + + // + if (result && drawSwings) + { + // + // High Swings ... + for (int i = 0; i < ArraySize(highSwingBars); i++) + { + // + XOHCL iBar = highSwingBars[i]; + + // + result = DrawArrow( + chartID, + name + "-SwingHigh-" + ToString(i), + 0, + iBar.time, + iBar.high, + swingHighArrow, + ANCHOR_BOTTOM, + swingHighColor, + STYLE_SOLID, + width // + ); + if (!result) + { + break; + } + } + + // + // Low Swings ... + for (int i = 0; i < ArraySize(lowSwingBars); i++) + { + // + XOHCL iBar = lowSwingBars[i]; + + // + result = DrawArrow( + chartID, + name + "-SwingLow-" + ToString(i), + 0, + iBar.time, + iBar.low, + swingLowArrow, + ANCHOR_TOP, + swingLowColor, + STYLE_SOLID, + width // + ); + if (!result) + { + break; + } + } + } + + // + return result; +} + +// +void RemoveBearishTrend(XOHCL &bar) +{ + RemoveDraws(GetBearishTrendTag(bar)); +} + +// +void RemoveAllToolsDraws() +{ + // + RemoveDraws(XTLSHammerToken); + RemoveDraws(XTLSSupportToken); + RemoveDraws(XTLSSwingLowToken); + RemoveDraws(XTLSSwingHighToken); + RemoveDraws(XTLSBullishFVGToken); + RemoveDraws(XTLSBearishFVGToken); + RemoveDraws(XTLSResistanceToken); + RemoveDraws(XTLSMorningStarToken); + RemoveDraws(XTLSEveningStarToken); + RemoveDraws(XTLSShootingStarToken); + RemoveDraws(XTLSBullishTrendToken); + RemoveDraws(XTLSBearishTrendToken); + RemoveDraws(XTLSBullishEngulfingToken); + RemoveDraws(XTLSBearishEngulfingToken); + RemoveDraws(XTLSBullishOrderBlockToken); + RemoveDraws(XTLSBearishOrderBlockToken); +} + +// +// +// + +// +string GetBarTimeTag(XOHCL &bar) +{ + // + string result = NULL; + + // + result = + // + ToString((int)bar.time) + // + ; + + // + return result; +} + +// +string GeShootingStarTag(XOHCL &bar) +{ + return "ShootingStar-" + GetBarTimeTag(bar); +} + +// +// string GeShootingStarTag(XOHCL &bar) +// { +// return "ShootingStar-" + GetBarTimeTag(bar); +// } + +// \ No newline at end of file diff --git a/Documents/BKP/14030802-X121/Libraries/x-saherelm.xtrade.lib.mq5 b/Documents/BKP/14030802-X121/Libraries/x-saherelm.xtrade.lib.mq5 new file mode 100644 index 00000000..c0f0128a --- /dev/null +++ b/Documents/BKP/14030802-X121/Libraries/x-saherelm.xtrade.lib.mq5 @@ -0,0 +1,6068 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Seriallize Library +// --------------------------------------- +// Name: XTradeLib +// Description: All models related to Trade ... +// +// +// 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 "../Libraries/x-saherelm.common.lib.mq5" +#include "../Libraries/x-saherelm.draw.lib.mq5" +#include + +// +// Definitions ... + +// +// a List of Used Tokens ... + +// +// Common ... +string XIDToken = "ID"; +string XTicketToken = "TK"; +string XModeToken = "MD"; +string XTypeToken = "TY"; +string XPeriodToken = "PR"; +string XProviderToken = "PRV"; +string XProfitToken = "PF"; + +// +string XTPToken = "TP"; +string XSLToken = "SL"; +string XTimeToken = "TM"; +string XEntryToken = "EN"; +string XVolumeToken = "VL"; +string XSymbolToken = "SMBL"; + +// +string XSupportToken = "SP"; +string XEQMSupportToken = "EQM"; +string XEQPToken = "EQP"; + +// +string XSLTrailToken = "SLT"; + +// +string XActionToken = "A"; + +// +string XDirectionalToken = "D"; +string XINDirectionalToken = "IND"; + +// +string XRecoveryToken = "XRCV"; + +// +// Available Order Modes ... +enum ENUM_X_ORDER_MODES +{ + X_ORDER_MODE_NOTHING, // Nothing + X_ORDER_MODE_MARKET, // Market Order + X_ORDER_MODE_STOP, // Pending Stop Order + X_ORDER_MODE_LIMIT, // Pending Limit Order + X_ORDER_MODE_STOP_LIMIT, // Pending Stop Limit Order +}; + +// +string ToString(ENUM_X_ORDER_MODES value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_ORDER_MODE_MARKET: + result = "Market"; + break; + + // + case X_ORDER_MODE_LIMIT: + result = "Limit"; + break; + + // + case X_ORDER_MODE_STOP: + result = "Stop"; + break; + + // + case X_ORDER_MODE_STOP_LIMIT: + result = "StopLimit"; + break; + } + + // + return result; +} + +// +// Select Positions Type ... +enum ENUM_X_POSITION_SELECT_METHODS +{ + X_POSITION_SELECT_NONE, // None + X_POSITION_SELECT_MAX, // Max + X_POSITION_SELECT_MIN, // Min + X_POSITION_SELECT_BOTH, // Min and Max + X_POSITION_SELECT_ALL, // All +}; + +// +// Signal Execution Result ... +// note that some of them must be handles in +// EA's ... +enum ENUM_X_SIGNAL_EXECUTION_RESULT +{ + // + X_SIGNAL_EXECUTION_UNKNOWN, // Unknown + X_SIGNAL_EXECUTION_SUCCEED, // Succed + X_SIGNAL_EXECUTION_FAILED_SPREAD, // Spread more than Max Allowed + X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED, // Not Allowed Trade Type + X_SIGNAL_EXECUTION_FAILED_NO_EQUITY, // No Equity for Trade + X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR, // Price Error + X_SIGNAL_EXECUTION_FAILED_MAX_REACHED, // Max Allowed Positions Reached + X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED, // Same Positions Delay Not Passed + X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS, // Invalid Params +}; + +// +// Available Guard Action ... +enum ENUM_X_GUARD_ACTIONS +{ + X_GUARD_ACTION_NOTHING, // Nothing + X_GUARD_ACTION_HEDGE, // Hedge + X_GUARD_PARTIAL_CLOSE, // Partial Close + X_GUARD_ACTION_TRAIL_STOP, // Trail StopLoss + X_GUARD_ACTION_FORCE_CLOSE, // Force Close + X_GUARD_ACTION_ADD_SUPPORT_SIGNAL, // Add Support Signal + X_GUARD_ACTION_CANCEL_PENDING_ORDERS, // Cancel Pending Orders +}; + +// +enum ENUM_X_POSITION_TYPES +{ + X_POSITION_TYPE_NONE = 0, + X_POSITION_TYPE_ALL = 1, + X_POSITION_TYPE_LONG = 2, + X_POSITION_TYPE_SHORT = 3, +}; + +// +string ToString(ENUM_X_POSITION_TYPES value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_POSITION_TYPE_ALL: + result = "All"; + break; + + // + case X_POSITION_TYPE_NONE: + result = "NONE"; + break; + + // + case X_POSITION_TYPE_SHORT: + result = "Short"; + break; + + // + case X_POSITION_TYPE_LONG: + result = "Long"; + break; + } + + // + return result; +} + +// +bool IsLong(ENUM_X_POSITION_TYPES value) +{ + return value == X_POSITION_TYPE_LONG; +} + +// +bool ToPositionType( + ENUM_POSITION_TYPE &dest, + ENUM_X_POSITION_TYPES source // +) +{ + // + bool result = false; + + // + result = source == X_POSITION_TYPE_LONG || + source == X_POSITION_TYPE_SHORT; + if (!result) + { + return result; + } + + // + dest = + source == X_POSITION_TYPE_LONG + ? POSITION_TYPE_BUY + : POSITION_TYPE_SELL; + + // + return result; +} + +// +ENUM_X_POSITION_TYPES ToPositionType(ENUM_POSITION_TYPE value) +{ + return IsLong(value) + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; +} + +// +ENUM_X_POSITION_TYPES GetOppositPositionType(ENUM_POSITION_TYPE type) +{ + // + ENUM_X_POSITION_TYPES result = X_POSITION_TYPE_NONE; + + // + bool isLong = IsLong(type); + bool isShort = IsShort(type); + + // + result = + // + isLong + ? X_POSITION_TYPE_SHORT + : isShort + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_NONE + // + ; + + // + return result; +} + +// +// Structs ... + +// +// Model an Open Position ... +struct XPosition +{ + // + // Props ... + + // + // Magic Number ... + ulong magic; + + // + // Ticket ID ... + ulong ticket; + + // + // Tradinng Symbol ... + string symbol; + + // + // Trading Period ... + ENUM_TIMEFRAMES period; + + // + // Position Type ... + ENUM_POSITION_TYPE type; + + // + // Take Profit ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Position Current Profit ... + double profit; + + // + // Position Open Price ... + double entry; + + // + // Current Symbol Price ... + double price; + + // + // Position Swap ... + double swap; + + // + // Position Commission ... + double commission; + + // + // Volume ... + double volume; + + // + // Position Open Time ... + datetime openAt; + + // + // Sifnal Provider ... + string provider; + + // + // Position Comment ... + string comment; + + // + // Constructor ... + XPosition() + { + Clean(); + } + + // + // Initializers ... + + bool ByIndex(int index) + { + // + bool result = false; + + // + static CPositionInfo mPositionInfo; + + // + result = mPositionInfo.SelectByIndex(index); + if (!result) + { + return result; + } + + // + ulong mTicket = mPositionInfo.Ticket(); + + // + result = ByTicket(mTicket); + + // + return result; + } + + bool ByTicket(ulong mTicket) + { + // + bool result = false; + + // + static CPositionInfo mPositionInfo; + + // + result = mPositionInfo.SelectByTicket(mTicket); + if (!result) + { + return result; + } + + // + swap = mPositionInfo.Swap(); + magic = mPositionInfo.Magic(); + openAt = mPositionInfo.Time(); + sl = mPositionInfo.StopLoss(); + ticket = mPositionInfo.Ticket(); + symbol = mPositionInfo.Symbol(); + tp = mPositionInfo.TakeProfit(); + profit = mPositionInfo.Profit(); + volume = mPositionInfo.Volume(); + comment = mPositionInfo.Comment(); + entry = mPositionInfo.PriceOpen(); + type = mPositionInfo.PositionType(); + price = mPositionInfo.PriceCurrent(); + commission = mPositionInfo.Commission(); + + // + period = ExtractPeriod(comment); + provider = ExtractProvider(comment); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + magic = 0; + ticket = 0; + tp = 0; + sl = 0; + swap = 0; + entry = 0; + price = 0; + profit = 0; + volume = 0; + openAt = 0; + commission = 0; + + // + type = NULL; + period = NULL; + + // + symbol = NULL; + comment = NULL; + provider = NULL; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + NotEmpty(ticket) + // + ; + + // + return result; + } + + // + // Retrieve Entry Price ... + double GetEntry() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetEntry( + symbol, + type + // + ); + + // + return result; + } + + // + // Retrieve Exit ... + double GetExit() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetExit( + symbol, + type + // + ); + + // + return result; + } + + // + // Get Spread by Point ... + double GetSpread() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = PriceToPoint(GetSpread(symbol)); + + // + return result; + } + + // + double GetPointsValue() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetPoints(symbol); + + // + return result; + } + + // + double GetProfitInPoint() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE); // Tick size + double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE); // Tick value + double pointSize = SymbolInfoDouble(symbol, SYMBOL_POINT); // Point size + double pointValue = tickValue * pointSize / tickSize; // Point value + + // + result = profit / (volume * tickValue); + + // + return result; + } + + // + // Find Risk ... + double GetRisk() + { + // + double result = 0; + + // + if (!IsValid()) + { + return 0; + } + + // + result = MathAbs(entry - sl); + + // + return result; + } + + // + // Find Reward ... + double GetReward() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = MathAbs(tp - entry); + + // + return result; + } + + // + double GetRewardInPoint() { + // + double result = 0; + + // + result = GetReward() / GetPoints(); + + // + return result; + } + + // + // Find Risk Reward Ratio ... + double GetRiskRewardRatio() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetReward() / GetRisk(); + + // + return result; + } + + // + // Calculate Age ... + int GetAge( + ENUM_TIMEFRAMES mPeriod // Calculate Age based on this period + ) + { + return GetAge(this, mPeriod); + } + + // + // Check this instance is Same os Given instance or not ... + bool IsSameAs( + const XPosition &value // instance for Compare + ) + { + // + bool result = false; + + // + result = + // + type == value.type && + magic == value.magic && + entry == value.entry && + ticket == value.ticket && + volume == value.volume && + symbol == value.symbol && + provider == value.provider + // + ; + + // + return result; + } + + // + // Find index in a Collection ... + int FindIndex( + const XPosition &values[] // Collection to Find + ) + { + // + return FindIndex( + this, + values + // + ); + } + + // + // Check Items Passed Specific Filters or not ... + bool IsFiltersPassed( + string mSymbol = NULL, // Trading Symbol + string mProvider = NULL, // Signal Provider + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe + ENUM_X_POSITION_TYPES mType = NULL, // Long (Buy), Short (Sell) + ulong mMagic = NULL, // Magic Number + bool mFilterByMagic = true // Get Only Self Open Positions + ) + { + // + bool result = false; + + // + result = + // + // Magic Filter ... + IsMagicFilterPassed( + mMagic, + mFilterByMagic, + this + // + ) + // + && + // + // Symbol Filter ... + IsSymbolFilterPassed( + mSymbol, + this + // + ) + // + && + // + // Provider Filter ... + IsProviderFilterPassed( + mProvider, + this + // + ) + // + && + // + // Period Filter ... + IsPeriodFilterPassed( + mPeriod, + this + // + ) + // + && + // + // Type Filter ... + IsTypeFilterPassed( + mType, + this + // + ) + // + ; + + // + return result; + } +}; + +// +// Model a Signal ... +struct XSignal +{ + // + // Props ... + + // + ulong positionId; // if Executed this filled ... + + // + datetime time; // Issue Time ... + + // + double tp; // Take Profit ... + double sl; // Stop Loss ... + double entry; // Exntry or Execution Price ... + double volume; // Position Volume ... + + // + string symbol; // Trading Symbol ... + string comment; // Comment ... + string provider; // Signaller ... + + // + ENUM_TIMEFRAMES period; // Trading TimeFrame ... + ENUM_POSITION_TYPE type; // Long (Buy) or Short (Sell) ... + ENUM_X_ORDER_MODES mode; // Execution Mode ... + + // + XSignal supports[]; // a Collecion of Support Signals ... + + // + int pushers; // Signal Pushers ... + string conditions; // Signal Conditions ... + + // + // Constructor ... + XSignal() + { + Clean(); + } + + // + bool Prepare( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + ENUM_POSITION_TYPE mType, // Long (Buy) or Short (Sell) + ENUM_X_ORDER_MODES mMode, // Execution Mode + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + bool result = false; + + // + result = + // + IsValid(mMode) && + IsValid(mSymbol) && + IsValid(mPeriod) && + NotEmpty(mEntry) && + NotEmpty(mVolume) && + IsValid(mProvider) + // + ; + if (!result) + { + return result; + } + + // + if (mTP < 0) + { + mTP = 0; + } + + // + if (mSL < 0) + { + mSL = 0; + } + + // + type = mType; + mode = mMode; + symbol = mSymbol; + period = mPeriod; + provider = mProvider; + + // + // Normalization Values ... + sl = NormalizePrice(mSL, mSymbol); + tp = NormalizePrice(mTP, mSymbol); + mEntry = NormalizePrice(mEntry, mSymbol); + mVolume = NormalizeVolume(mVolume, mSymbol); + + // + entry = mEntry; + volume = mVolume; + + // + result = Normalize(); + + // + return result; + } + + // + bool PrepareLong( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + ENUM_X_ORDER_MODES mMode, // Execution Mode + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return Prepare( + mSymbol, + mProvider, + mPeriod, + POSITION_TYPE_BUY, + mMode, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + bool PrepareShort( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + ENUM_X_ORDER_MODES mMode, // Execution Mode + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return Prepare( + mSymbol, + mProvider, + mPeriod, + POSITION_TYPE_SELL, + mMode, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + // Market Mode ... + + // + bool PrepareMarketLong( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return PrepareLong( + mSymbol, + mProvider, + mPeriod, + X_ORDER_MODE_MARKET, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + bool PrepareMarketShort( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return PrepareShort( + mSymbol, + mProvider, + mPeriod, + X_ORDER_MODE_MARKET, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + // Stop Mode ... + + // + bool PrepareStopLong( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return PrepareLong( + mSymbol, + mProvider, + mPeriod, + X_ORDER_MODE_STOP, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + bool PrepareStopShort( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return PrepareShort( + mSymbol, + mProvider, + mPeriod, + X_ORDER_MODE_STOP, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + // Limit Mode ... + + // + bool PrepareLimitLong( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return PrepareLong( + mSymbol, + mProvider, + mPeriod, + X_ORDER_MODE_LIMIT, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + bool PrepareLimitShort( + string mSymbol, // Trading Symbol + string mProvider, // Signal Provider + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + double mEntry, // Entry Price + double mVolume, // Volume + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + return PrepareShort( + mSymbol, + mProvider, + mPeriod, + X_ORDER_MODE_LIMIT, + mEntry, + mVolume, + mSL, + mTP + // + ); + } + + // + // Generate Opposit Direction ... + bool GenerateOpposit( + XSignal &mSignal // Oppsoit Signal + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + ENUM_POSITION_TYPE mType = GetOpposit(this.type); + double mEntry = GetExit(this.symbol, mType); + + // + bool isLong = IsLong(mType); + + // + // Calculate Risk Reward Ratio ... + double risk = GetRisk(); + double reward = GetReward(); + + // + double mSL = isLong + ? mEntry - risk + : mEntry + risk; + + // + double mTP = isLong + ? mEntry + reward + : mEntry - reward; + + // + result = mSignal.Prepare( + this.symbol, + this.provider, + this.period, + mType, + this.mode, + mEntry, + this.volume, + mSL, + mTP // + ); + + // + return result; + } + + // + // Prepare Opposit Signal based On a Position ... + bool PrepareOpposit( + XPosition &source // Source Data + ) + { + // + bool result = false; + + // + ENUM_POSITION_TYPE mType = GetOpposit(source.type); + double mEntry = GetEntry(source.symbol, mType); + + // + bool isLong = IsLong(mType); + + // + double risk = source.GetRisk(); + double reward = source.GetReward(); + + // + double mSL = isLong + ? mEntry - risk + : mEntry + risk; + + // + double mTP = isLong + ? mEntry + reward + : mEntry - reward; + + // + return Prepare( + source.symbol, + source.provider, + source.period, + mType, + X_ORDER_MODE_MARKET, + mEntry, + source.volume, + mSL, + mTP // + ); + + // + result = IsValid(); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + entry = 0; + volume = 0; + pushers = 0; + positionId = 0; + + // + time = NULL; + type = NULL; + mode = NULL; + symbol = NULL; + period = NULL; + comment = NULL; + provider = NULL; + conditions = NULL; + + // + Clean(supports); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(period) && + IsValid(symbol) && + NotEmpty(volume) && + NotEmpty(entry) + // + ; + + // + if (!result) + { + return result; + } + + // + return result; + } + + // + // DO All Calculations and Normalizations ... + bool Normalize() + { + // + bool result = false; + + // + // Normalizations ... + symbol = NormalizeSymbol(symbol); + period = NormalizePeriod(period); + + // + time = NormalizeTime(time); + + // + sl = NormalizePrice(sl, symbol); + tp = NormalizePrice(tp, symbol); + entry = NormalizePrice(entry, symbol); + volume = NormalizeVolume(volume, symbol); + + // + result = IsValid(); + + // + return result; + } + + // + // Check Signal Executed or not ... + bool IsExecuted() + { + // + bool result = false; + + // + result = + // + IsValid() && + NotEmpty(positionId) + // + ; + + // + return result; + } + + // + // Generate Comment for Signal ... + string GenerateComment() + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + if (IsValid(provider)) + { + // + // Generate Provider Tag ... + result += GenerateProviderTag(provider); + } + + // + if (IsValid(period)) + { + // + // Generate Period Tag ... + result += GeneratePeriodTag(period); + } + + // + return result; + } + + // + int GetAge() + { + // + return GetAge( + this, + this.period // + ); + } + + // + // Retrieve Entry Price ... + double GetEntry() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetEntry( + symbol, + type + // + ); + + // + return result; + } + + // + // Retrieve Exit ... + double GetExit() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetExit( + symbol, + type + // + ); + + // + return result; + } + + // + // Get Spread by Point ... + double GetSpread() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = PriceToPoint(GetSpread(symbol)); + + // + return result; + } + + // + // Find Risk ... + double GetRisk() + { + // + double result = 0; + + // + if (!IsValid()) + { + return 0; + } + + // + result = MathAbs(entry - sl); + + // + return result; + } + + // + // Find Reward ... + double GetReward() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = MathAbs(tp - entry); + + // + return result; + } + + // + // Find Risk Reward Ratio ... + double GetRiskRewardRatio() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = GetReward() / GetRisk(); + + // + return result; + } + + // + // Draw Signal on Chart ... + bool Draw( + long chartID, + int subWindow = 0, + string prefix = NULL, + color entryColor = clrGold, + color bullishColor = clrSpringGreen, + color bearishColor = clrTomato // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isLong = IsLong(this.type); + + // + prefix = + // + (!IsValid(prefix) ? "" : prefix) + + this.symbol + "_" + + ToString(this.period) + "_" + + this.provider + // + ; + + // + int age = this.GetAge(); + + // + // Retrieve Time ... + datetime time0 = iTime( + this.symbol, + this.period, + age // + ); + + // + // Retrieve 3 Time ... + datetime time3 = iTime( + this.symbol, + this.period, + age + 3 // + ); + + // + color posColor = isLong + ? bullishColor + : bearishColor; + color tpColor = bullishColor; + color slColor = bearishColor; + + // + ENUM_LINE_STYLE vLineStyle = STYLE_DOT; + ENUM_LINE_STYLE tpLineStyle = STYLE_SOLID; + ENUM_LINE_STYLE slLineStyle = STYLE_SOLID; + ENUM_LINE_STYLE entryLineStyle = STYLE_SOLID; + + // + int lineWidth = 2; + + // + // Vertical Line ... + string vlName = prefix + "_" + (string)time; + + // + result = DrawVerticalLine( + chartID, + vlName, + subWindow, + time0, + posColor, + vLineStyle, + lineWidth // + ); + if (!result) + { + return result; + } + + // + // TP ... + double profit = (MathAbs(this.tp - this.entry)) * this.volume; + string tpName = prefix + "_TP_" + (string)profit; + + // + result = DrawTrendLine( + chartID, + tpName, + subWindow, + time3, + this.tp, + time0, + this.tp, + tpColor, + tpLineStyle, + lineWidth // + ); + if (!result) + { + return result; + } + + // + // SL ... + double lost = (MathAbs(this.sl - this.entry)) * this.volume; + string slName = prefix + "_SL_" + (string)lost; + + // + result = DrawTrendLine( + chartID, + slName, + subWindow, + time3, + this.sl, + time0, + this.sl, + slColor, + slLineStyle, + lineWidth // + ); + if (!result) + { + return result; + } + + // + // ENTRY ... + string entryName = prefix + "_ENTRY_" + (string)lost; + + // + result = DrawTrendLine( + chartID, + entryName, + subWindow, + time3, + this.entry, + time, + this.entry, + entryColor, + entryLineStyle, + lineWidth // + ); + + // + return result; + } + + // + // Retrieve String Representation of Signal ... + string ToString() + { + // + string result = NULL; + + // + result = + // + ToString("Symbol", symbol) + + ToString("Period", period) + + ToString("Provider", provider) + + ToString("Type", type) + + ToString("Mode", mode) + + ToString("Volume", volume) + + ToString("Entry", entry) + + ToString("TP", tp) + + ToString("SL", sl) + + ToString("Time", time) + + ToString("Comment", comment) + + // + "" + // + ; + + // + return result; + } +}; + +// +// Model an Order ... +struct XOrder +{ + // + // Time of order placement ... + datetime setupAt; + + // + // Time of order expiration ... + datetime expiredAt; + + // + // Time of order execution or cancellation ... + datetime executedAt; + + // + // Order type ... + ENUM_ORDER_TYPE type; + + // + // Order state ... + ENUM_ORDER_STATE state; + + // + // Type of execution by remainder ... + ENUM_ORDER_TYPE_FILLING filling; + + // + // Order lifetime ... + ENUM_ORDER_TYPE_TIME lifetime; + + // + // Order ticket ... + ulong ticket; + + // + // Magic Number ... + long magic; + + // + // Position id, that is placed on order, + // when it is executed. Each executed order invokes a + // deal, that opens new or changes existing + // position. Id of that position is placed on + // executed order in this moment. + long positionId; + + // + // Initial volume on order placement ... + double initialVolume; + + // + // Unfilled volume ... + double currentVolume; + + // + // Price, specified in the order ... + double openPrice; + + // + // Current price by order symbol ... + double currentPrice; + + // + // Price of placing Limit order when StopLimit order is triggered ... + double stopLimitPrice; + + // + // Take Profit level ... + double tp; + + // + // Stop Loss level ... + double sl; + + // + // Trading Symbol ... + string symbol; + + // + // Signal Provider ... + string provider; + + // + // Order Comment ... + string comment; + + // + ENUM_TIMEFRAMES period; + + // + // Constructor ... + XOrder() + { + Clean(); + } + + // + // Initializers ... + bool ByIndex( + int index // Fill By Index ... + ) + { + // + bool result = false; + + // + int ordersCount = OrdersTotal(); + if (ordersCount <= 0) + { + return result; + } + + // + static COrderInfo mOrderInfo; + + // + result = mOrderInfo.SelectByIndex(index); + if (!result) + { + return result; + } + + // + // Reading Order Info ... + magic = mOrderInfo.Magic(); + sl = mOrderInfo.StopLoss(); + tp = mOrderInfo.TakeProfit(); + ticket = mOrderInfo.Ticket(); + openPrice = mOrderInfo.PriceOpen(); + positionId = mOrderInfo.PositionId(); + currentPrice = mOrderInfo.PriceCurrent(); + initialVolume = mOrderInfo.VolumeInitial(); + currentVolume = mOrderInfo.VolumeCurrent(); + stopLimitPrice = mOrderInfo.PriceStopLimit(); + + // + symbol = mOrderInfo.Symbol(); + comment = mOrderInfo.Comment(); + + // + state = mOrderInfo.State(); + type = mOrderInfo.OrderType(); + lifetime = mOrderInfo.TypeTime(); + filling = mOrderInfo.TypeFilling(); + + // + setupAt = mOrderInfo.TimeSetup(); + executedAt = mOrderInfo.TimeDone(); + expiredAt = mOrderInfo.TimeExpiration(); + + // + period = ExtractPeriod(comment); + provider = ExtractProvider(comment); + + // + result = IsValid(); + + // + return result; + } + + // + // Retrieve Specific History Order ... + bool HistoryByIndex( + int index // Fill By Index ... + ) + { + // + bool result = false; + + // + int ordersCount = HistoryOrdersTotal(); + if (ordersCount <= 0) + { + return result; + } + + // + static CHistoryOrderInfo mOrderInfo; + + // + result = mOrderInfo.SelectByIndex(index); + if (!result) + { + return result; + } + + // + // Reading Order Info ... + magic = mOrderInfo.Magic(); + sl = mOrderInfo.StopLoss(); + tp = mOrderInfo.TakeProfit(); + ticket = mOrderInfo.Ticket(); + openPrice = mOrderInfo.PriceOpen(); + positionId = mOrderInfo.PositionId(); + currentPrice = mOrderInfo.PriceCurrent(); + initialVolume = mOrderInfo.VolumeInitial(); + currentVolume = mOrderInfo.VolumeCurrent(); + stopLimitPrice = mOrderInfo.PriceStopLimit(); + + // + symbol = mOrderInfo.Symbol(); + comment = mOrderInfo.Comment(); + + // + state = mOrderInfo.State(); + type = mOrderInfo.OrderType(); + lifetime = mOrderInfo.TypeTime(); + filling = mOrderInfo.TypeFilling(); + + // + setupAt = mOrderInfo.TimeSetup(); + executedAt = mOrderInfo.TimeDone(); + expiredAt = mOrderInfo.TimeExpiration(); + + // + period = ExtractPeriod(comment); + provider = ExtractProvider(comment); + + // + result = IsValid(); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + tp = 0; + sl = 0; + magic = 0; + ticket = 0; + positionId = 0; + openPrice = 0; + currentPrice = 0; + initialVolume = 0; + currentVolume = 0; + stopLimitPrice = 0; + + // + setupAt = NULL; + expiredAt = NULL; + executedAt = NULL; + + // + symbol = NULL; + comment = NULL; + provider = NULL; + + // + type = NULL; + state = NULL; + period = NULL; + filling = NULL; + lifetime = NULL; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + NotEmpty(ticket) && + NotEmpty(positionId) + // + ; + + // + return result; + } + + // + // Calculate Age ... + int GetAge( + ENUM_TIMEFRAMES mPeriod // Calculate Age based on this period + ) + { + return GetAge(this, mPeriod); + } + + // + // Check this instance is Same os Given instance or not ... + bool IsSameAs( + const XOrder &value // instance for Compare + ) + { + // + bool result = false; + + // + result = + // + type == value.type && + state == value.state && + magic == value.magic && + ticket == value.ticket && + symbol == value.symbol && + provider == value.provider && + positionId == value.positionId + // + ; + + // + return result; + } + + // + // Find index in a Collection ... + int FindIndex( + const XOrder &values[] // Collection to Find + ) + { + // + return FindIndex( + this, + values + // + ); + } + + // + // Check Items Passed Specific Filters or not ... + bool IsFiltersPassed( + string mSymbol = NULL, // Trading Symbol + string mProvider = NULL, // Signal Provider + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe + ENUM_X_POSITION_TYPES mType = NULL, // Long (Buy), Short (Sell) + ENUM_ORDER_STATE mState = NULL, // Order State + ulong mMagic = NULL, // Magic Number + bool mFilterByMagic = true // Get Only Self Open Positions + ) + { + // + bool result = false; + + // + result = + // + // Magic Filter ... + IsMagicFilterPassed( + mMagic, + mFilterByMagic, + this + // + ) + // + && + // + // Symbol Filter ... + IsSymbolFilterPassed( + mSymbol, + this + // + ) + // + && + // + // Provider Filter ... + IsProviderFilterPassed( + mProvider, + this + // + ) + // + && + // + // Period Filter ... + IsPeriodFilterPassed( + mPeriod, + this + // + ) + // + && + // + // Type Filter ... + IsTypeFilterPassed( + mType, + this + // + ) + // + && + // + // State Filter ... + IsStateFilterPassed( + mState, + this + // + ) + // + ; + + // + return result; + } +}; + +// +// Model a Deal ... +struct XDeal +{ + // + // the ID of the Expert Advisor, that executed the deal ... + ulong magic; + + // + // the ID of position, in which the deal was involved ... + ulong positionId; + + // + // Ticket ... + ulong ticket; + + // + // the name of the deal symbol ... + string symbol; + + // + // order by which the deal is executed ... + ulong order; + + // + // the time of deal execution ... + datetime time; + + // + // Deal price ... + double price; + + // + // the financial result of the deal (in deposit currency) ... + double profit; + + // + // the amount of swap when position is closed ... + double swap; + + // + // the amount of commission of the deal ... + double commission; + + // + // the volume of deal ... + double volume; + + // + // the deal comment ... + string comment; + + // + string provider; + + // + ENUM_TIMEFRAMES period; + + // + // the deal type ... + // ------------------------------------------------------------------ + // DEAL_TYPE_BUY => Buy ... + // DEAL_TYPE_SELL => Sell ... + // DEAL_TYPE_BUY_CANCELED => Canceled buy deal ... + // There can be a situation when a previously executed buy deal is canceled. In this case, + // the type of the previously executed deal (DEAL_TYPE_BUY) is changed to DEAL_TYPE_BUY_CANCELED, + // and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation ... + // + // DEAL_TYPE_SELL_CANCELED => Canceled sell deal ... + // There can be a situation when a previously executed sell deal is canceled. In this case, + // the type of the previously executed deal (DEAL_TYPE_SELL) is changed to DEAL_TYPE_SELL_CANCELED, + // and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation + // + // DEAL_TYPE_BALANCE => Balance ... + // DEAL_TYPE_CREDIT => Credit ... + // DEAL_TYPE_CHARGE => Additional charge ... + // DEAL_TYPE_CORRECTION => Correction ... + // DEAL_TAX => Tax charges ... + // DEAL_TYPE_BONUS => Bonus ... + // DEAL_TYPE_INTEREST => Interest rate ... + // DEAL_DIVIDEND => Dividend operations... + // DEAL_DIVIDEND_FRANKED => Franked (non-taxable) dividend operations ... + // DEAL_TYPE_COMMISSION => Additional commission ... + // DEAL_TYPE_COMMISSION_DAILY => Daily commission ... + // DEAL_TYPE_COMMISSION_MONTHLY => Monthly commission ... + // DEAL_TYPE_COMMISSION_AGENT_DAILY => Daily agent commission ... + // DEAL_TYPE_COMMISSION_AGENT_MONTHLY => Monthly agent commission + ENUM_DEAL_TYPE type; + + // + // the deal direction ... + // ---------------------------------- + // DEAL_ENTRY_IN => Entry in ... + // DEAL_ENTRY_OUT => Entry out ... + // DEAL_ENTRY_INOUT => Reverse ... + // DEAL_ENTRY_OUT_BY => Close a position by an opposite one ... + ENUM_DEAL_ENTRY entry; + + // + // deal reson ... + // --------------------- + // DEAL_REASON_SL => The deal was executed as a result of Stop Loss activation ... + // DEAL_REASON_TP => The deal was executed as a result of Take Profit activation ... + // DEAL_REASON_SO => The deal was executed as a result of the Stop Out event ... + // DEAL_REASON_WEB => The deal was executed as a result of activation of an order placed from the web platform ... + // DEAL_REASON_SPLIT => The deal was executed after the split (price reduction) of an instrument, which had an open position during split announcement ... + // DEAL_REASON_CLIENT => The deal was executed as a result of activation of an order placed from a desktop terminal ... + // DEAL_REASON_MOBILE => The deal was executed as a result of activation of an order placed from a mobile application ... + // DEAL_REASON_EXPERT => The deal was executed as a result of activation of an order placed from an MQL5 program, i.e. an Expert Advisor or a script ... + // DEAL_REASON_VMARGIN => The deal was executed after charging the variation margin ... + // DEAL_REASON_ROLLOVER => The deal was executed due to a rollover ... + ENUM_DEAL_REASON reason; + + // + // Constructor ... + XDeal() + { + Clean(); + } + + // + // Initializers ... + bool ByIndex( + int index // Deal Index + ) + { + // + bool result = false; + + // + int dealsCount = HistoryDealsTotal(); + result = dealsCount > 0; + if (!result) + { + return result; + } + + // + static CDealInfo mDealInfo; + + // + result = mDealInfo.SelectByIndex(index); + if (!result) + { + // + return result; + } + + // + // Reading Order Info ... + swap = mDealInfo.Swap(); + magic = mDealInfo.Magic(); + order = mDealInfo.Order(); + ticket = mDealInfo.Ticket(); + time = mDealInfo.Time(); + price = mDealInfo.Price(); + symbol = mDealInfo.Symbol(); + profit = mDealInfo.Profit(); + volume = mDealInfo.Volume(); + comment = mDealInfo.Comment(); + positionId = mDealInfo.PositionId(); + entry = mDealInfo.Entry(); + commission = mDealInfo.Commission(); + type = mDealInfo.DealType(); + reason = (ENUM_DEAL_REASON)HistoryDealGetInteger( + ticket, + DEAL_REASON); + + // + period = ExtractPeriod(comment); + provider = ExtractProvider(comment); + + // + result = IsValid(); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + magic = 0; + positionId = 0; + ticket = 0; + order = 0; + time = 0; + price = 0; + profit = 0; + swap = 0; + commission = 0; + volume = 0; + + // + symbol = NULL; + comment = NULL; + provider = NULL; + + // + type = NULL; + entry = NULL; + period = NULL; + reason = NULL; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + NotEmpty(ticket) && + NotEmpty(positionId) + // + ; + + // + return result; + } + + // + // Calculate Age ... + int GetAge( + ENUM_TIMEFRAMES mPeriod // Calculate Age based on this period + ) + { + return GetAge(this, mPeriod); + } + + // + // Check this instance is Same os Given instance or not ... + bool IsSameAs( + const XDeal &value // instance for Compare + ) + { + // + bool result = false; + + // + result = + // + type == value.type && + magic == value.magic && + entry == value.entry && + reason == value.reason && + ticket == value.ticket && + volume == value.volume && + symbol == value.symbol && + provider == value.provider && + positionId == value.positionId + // + ; + + // + return result; + } + + // + // Find index in a Collection ... + int FindIndex( + const XDeal &values[] // Collection to Find + ) + { + // + return FindIndex( + this, + values + // + ); + } + + // + // Check Items Passed Specific Filters or not ... + bool IsFiltersPassed( + string mSymbol = NULL, // Trading Symbol + string mProvider = NULL, // Signal Provider + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe + ENUM_DEAL_TYPE mType = NULL, // Deal Type + ENUM_DEAL_ENTRY mEntry = NULL, // Deal Entry + ENUM_DEAL_REASON mReason = NULL, // Deal Reason + ulong mMagic = NULL, // Magic Number + bool mFilterByMagic = true // Get Only Self Open Positions + ) + { + // + bool result = false; + + // + result = + // + // Magic Filter ... + IsMagicFilterPassed( + mMagic, + mFilterByMagic, + this + // + ) + // + && + // + // Symbol Filter ... + IsSymbolFilterPassed( + mSymbol, + this + // + ) + // + && + // + // Provider Filter ... + IsProviderFilterPassed( + mProvider, + this + // + ) + // + && + // + // Period Filter ... + IsPeriodFilterPassed( + mPeriod, + this + // + ) + // + && + // + // Type Filter ... + IsTypeFilterPassed( + mType, + this + // + ) + // + && + // + // Entry Filter ... + IsEntryFilterPassed( + mEntry, + this + // + ) + // + && + // + // Reason Filter ... + IsReasonFilterPassed( + mReason, + this + // + ) + // + ; + + // + return result; + } +}; + +// +// Model OnTrade Event Handler Result on XCTrade Class ... +struct XOnTradeHandlerState +{ + // + bool hasNewDeal; + int newDeals; + + // + bool hasNewOrder; + int newOrders; + + // + bool hasNewPosition; + int newPositions; + + // + bool hasNewHistoryOrder; + int newHistoryOrders; + + // + // Constructor ... + XOnTradeHandlerState() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + hasNewDeal = false; + hasNewOrder = false; + hasNewPosition = false; + hasNewHistoryOrder = false; + + // + newDeals = 0; + newOrders = 0; + newPositions = 0; + newHistoryOrders = 0; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + ( + // + hasNewDeal + ? newDeals > 0 + : true + // + ) + // + && + // + ( + // + hasNewOrder + ? newOrders > 0 + : true + // + ) + // + && + // + ( + // + hasNewPosition + ? newPositions > 0 + : true + // + ) + // + && + // + ( + // + hasNewHistoryOrder + ? newHistoryOrders > 0 + : true + // + ) + // + ; + + // + return result; + } +}; + +// +// Model Guard Info ... +struct XGuard +{ + // + string symbol; // Trading Symbol ... + string provider; // Signal Provider ... + ENUM_TIMEFRAMES period; // Trading Timeframe ... + ENUM_X_POSITION_TYPES type; // Position Type ... + ENUM_X_GUARD_ACTIONS action; // Which Action to Do ... + + // + double dblPayLoad; + string strPayload; + + // + // Constructor ... + XGuard() + { + Clean(); + } + + // + // Initialize ... + + // + // Global Initializer ... + bool Init( + string mSymbol, // Trading Symbol ... + ENUM_TIMEFRAMES mPeriod, // Trading Timeframe ... + ENUM_X_GUARD_ACTIONS mAction, // Which Action to Do ... + ENUM_X_POSITION_TYPES mType = NULL, // Position Type ... + string mProvider = NULL, // Signal Provider ... + double mDblPayLoad = NULL, + string mStrPayload = NULL // + ) + { + // + type = mType; + symbol = mSymbol; + period = mPeriod; + action = mAction; + provider = mProvider; + dblPayLoad = mDblPayLoad; + strPayload = mStrPayload; + + // + bool result = IsValid(); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + provider = NULL; + period = NULL; + action = X_GUARD_ACTION_NOTHING; + + // + strPayload = NULL; + dblPayLoad = EMPTY_VALUE; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + action != X_GUARD_ACTION_NOTHING + // + ; + + // + return result; + } +}; + +// +// Model a Position with all of it's Supports ... +struct XPositionPack +{ + // + ulong ticket; // Main Position's Ticket + + // + XPosition position; // Main Position (if Exists) + + // + int supportOrdersCount; // Supported Orders (Untriggered) + int supportPositionsCount; // Supported Positions + + // + XOrder supportOrders[]; // Supported Orders (Untriggered) + XPosition supportPositions[]; // Supported Positions + + // + // Constructor ... + XPositionPack() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + ticket = 0; + + // + position.Clean(); + + // + supportOrdersCount = 0; + supportPositionsCount = 0; + + // + Clean(supportOrders); + Clean(supportPositions); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + NotEmpty(ticket) && + ( + // + supportOrdersCount > 0 + ? ArraySize(supportOrders) == supportOrdersCount + : true + // + ) + // + && + // + ( + // + supportPositionsCount > 0 + ? ArraySize(supportPositions) == supportPositionsCount + : true + // + ) + // + ; + + // + return result; + } +}; + +// +// Check Position SL Trails Structure ... +struct XTrail +{ + // + ulong ticket; // Position Ticket ... + ENUM_POSITION_TYPE type; // Type ... + datetime time; // Trail Time ... + double before; // SL Value Before Trailing ... + double after; // SL Value After Trailing ... + int level; // Number of Trails SL ... + double profit; // Profit in SL Time ... + + // + // Constructor ... + XTrail() + { + Clean(); + } + + // + // Tools ... + + // + bool Init( + ulong mTicket, // Ticket + ENUM_POSITION_TYPE mType, // Type + double mProfit, // Profit + double mBefore, // Before + double mAfter // After + ) + { + // + Clean(); + + // + type = mType; + after = mAfter; + ticket = mTicket; + before = mBefore; + profit = mProfit; + + // + level++; + + // + time = TimeCurrent(); + + // + return IsValid(); + } + + // + bool Update( + double mSl, // new SL ... + double mProfit // Profit + ) + { + // + bool result = false; + + // + time = TimeCurrent(); + + // + double cAfter = after; + after = mSl; + before = cAfter; + profit = mProfit; + + // + level++; + + // + result = IsValid(); + + // + return result; + } + + // + string GenerateTag() + { + // + string result = NULL; + + // + string ticketLevelStr = ToString(ticket) + "," + ToString(level); + + // + result = Surround( + XSLTrailToken, + ticketLevelStr // + ); + + // + return result; + } + + // + // Cleanup ... + void Clean() + { + // + ticket = 0; + time = 0; + before = 0; + after = 0; + level = 0; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + ticket > 0 && + time > 0 && + level > 0 + // + ; + + // + return result; + } +}; + +// +struct XSymbolPositions +{ + // + string symbol; + + // + double profit; + double volume; + + // + double longsProfit; + double longSupportsProfit; + + // + double shortsProfit; + double shortSupportsProfit; + + // + double longsVolume; + double longSupportsVolume; + + // + double shortsVolume; + double shortSupportsVolume; + + // + double requiredProfitForHedge; + + // + XPosition longs[]; + XPosition shorts[]; + XPosition supports[]; + XPosition positions[]; + XPosition longSupports[]; + XPosition shortSupports[]; + + // + bool forceHedge; + + // + XSymbolPositions() + { + Clean(); + } + + // + bool Update( + double mMinProfitPerTrade, + double mMinProfitPerVolumeFactor // + ) + { + // + bool result = false; + + // + bool hasChild = HasChild(); + if (!hasChild) + { + return result; + } + + // + XPosition _supports[]; + XPosition _positions[]; + + // + XPosition _tmp[]; + + // + Copy( + positions, + _tmp // + ); + + // + Clean(positions); + + // + int tmpsCount = ArraySize(_tmp); + for (int i = 0; i < tmpsCount; i++) + { + // + XPosition iPosition = _tmp[i]; + + // + bool isSupport = IsSupport(iPosition.comment); + if (!isSupport) + { + // + AddRef( + iPosition, + _positions // + ); + } + else + { + // + AddRef( + iPosition, + _supports // + ); + } + } + + // + Clean(_tmp); + + // + Copy( + _positions, + positions // + ); + Clean(_positions); + + // + // Extract Types ... + ExtractPositions( + positions, + longs, + shorts // + ); + + // + Copy( + _supports, + supports // + ); + Clean(_supports); + + // + // Extract Types ... + ExtractPositions( + supports, + longSupports, + shortSupports // + ); + + // + int numOfLongs = 0; + int numOfShorts = 0; + CountPositions( + positions, + numOfLongs, + longsProfit, + longsVolume, + numOfShorts, + shortsProfit, + shortsVolume // + ); + + // + numOfLongs = 0; + numOfShorts = 0; + CountPositions( + supports, + numOfLongs, + longSupportsProfit, + longSupportsVolume, + numOfShorts, + shortSupportsProfit, + shortSupportsVolume // + ); + + // + XPosition _allPositions[]; + Copy( + positions, + _allPositions, + false // + ); + Copy( + supports, + _allPositions, + false // + ); + + // + profit = longsProfit + shortsProfit + longSupportsProfit + shortSupportsProfit; + volume = longsVolume + shortsVolume + longSupportsVolume + shortSupportsVolume; + requiredProfitForHedge = SpecifiedCalculateRequiredProfitForHedge( + _allPositions, + mMinProfitPerTrade, + mMinProfitPerVolumeFactor // + ); + + // + Clean(_allPositions); + + // + result = true; + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + forceHedge = false; + + // + profit = 0; + longsProfit = 0; + shortsProfit = 0; + + // + volume = 0; + longsVolume = 0; + shortsVolume = 0; + + // + requiredProfitForHedge = 0; + + // + Clean(longs); + Clean(shorts); + Clean(positions); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = IsValid(symbol); + + // + return result; + } + + // + // Has Child ... + bool HasChild() + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int count = Count(); + result = IsValidSize(count); + + // + return result; + } + + // + // Count ... + int Count() + { + return ArraySize(positions); + } + + // + int CountSupports() + { + return ArraySize(supports); + } + + // + int CountLongs() + { + return ArraySize(longs); + } + + // + int CountShorts() + { + return ArraySize(shorts); + } + + // + int CountLongSupports() + { + return ArraySize(longSupports); + } + + // + int CountShortSupports() + { + return ArraySize(shortSupports); + } + + // + int GetOldest( + XPosition &_oldest, // + ENUM_POSITION_TYPE _type // + ) + { + // + int result = -1; + + // + bool isLong = IsLong(_type); + + // + int count = + isLong + ? CountLongs() + : CountShorts(); + if (!IsValidSize(count)) + { + return result; + } + + // + if (isLong) + { + // + result = GetOldest( + _oldest, + longs // + ); + } + else + { + // + result = GetOldest( + _oldest, + shorts // + ); + } + + // + return result; + } + + // + int GetYoungest( + XPosition &_youngest, // + ENUM_POSITION_TYPE _type // + ) + { + // + int result = -1; + + // + bool isLong = IsLong(_type); + + // + int count = + isLong + ? CountLongs() + : CountShorts(); + if (!IsValidSize(count)) + { + return result; + } + + // + if (isLong) + { + // + result = GetYoungest( + _youngest, + longs // + ); + } + else + { + // + result = GetYoungest( + _youngest, + shorts // + ); + } + + // + return result; + } + + // + int GetMaxInProfit( + XPosition &_position, + ENUM_POSITION_TYPE _type // + ) + { + // + int result = -1; + + // + bool isLong = IsLong(_type); + + // + int count = + isLong + ? CountLongs() + : CountShorts(); + if (!IsValidSize(count)) + { + return result; + } + + // + if (isLong) + { + // + result = FindMaxProfitIndex( + longs // + ); + + // + if (IsValidIndex(result)) + { + _position = longs[result]; + } + } + else + { + // + result = FindMaxProfitIndex( + shorts // + ); + + // + if (IsValidIndex(result)) + { + _position = shorts[result]; + } + } + + // + return result; + } + + // + int GetMinInProfit( + XPosition &_position, + ENUM_POSITION_TYPE _type // + ) + { + // + int result = -1; + + // + bool isLong = IsLong(_type); + + // + int count = + isLong + ? CountLongs() + : CountShorts(); + if (!IsValidSize(count)) + { + return result; + } + + // + if (isLong) + { + // + result = FindMinProfitIndex( + longs // + ); + + // + if (IsValidIndex(result)) + { + _position = longs[result]; + } + } + else + { + // + result = FindMinProfitIndex( + shorts // + ); + + // + if (IsValidIndex(result)) + { + _position = shorts[result]; + } + } + + // + return result; + } + + // + int GetMaxInDrawdown( + XPosition &_position, + ENUM_POSITION_TYPE _type // + ) + { + // + int result = -1; + + // + bool isLong = IsLong(_type); + + // + int count = + isLong + ? CountLongs() + : CountShorts(); + if (!IsValidSize(count)) + { + return result; + } + + // + if (isLong) + { + // + result = FindMaxInDrawdownIndex( + longs // + ); + + // + if (IsValidIndex(result)) + { + _position = longs[result]; + } + } + else + { + // + result = FindMaxInDrawdownIndex( + shorts // + ); + + // + if (IsValidIndex(result)) + { + _position = shorts[result]; + } + } + + // + return result; + } + + // + int GetMinInDrawdown( + XPosition &_position, + ENUM_POSITION_TYPE _type // + ) + { + // + int result = -1; + + // + bool isLong = IsLong(_type); + + // + int count = + isLong + ? CountLongs() + : CountShorts(); + if (!IsValidSize(count)) + { + return result; + } + + // + if (isLong) + { + // + result = FindMinInDrawdownIndex( + longs // + ); + + // + if (IsValidIndex(result)) + { + _position = longs[result]; + } + } + else + { + // + result = FindMinInDrawdownIndex( + shorts // + ); + + // + if (IsValidIndex(result)) + { + _position = shorts[result]; + } + } + + // + return result; + } + + // +}; + +// +// an Structure for Holding Positions Data ... +struct XTradeData +{ + // + datetime time; // Issue Time (Open Position) + string symbol; // Trading Symbol + double entry; // Entry Price + double volume; // Volume + string provider; // Signaller + ENUM_TIMEFRAMES period; // Trading Timeframe + ENUM_X_POSITION_TYPES type; // Position Type + + // + ulong ticket; // Position Ticket + double swap; // Swap + double profit; // Profit on Close + double commission; // Commission + double maxDrawdown; // Max Position Drawdown + string message; // Close Reason + datetime endTime; // End Time + + // + XSignal signal; // Signal Object + int pushers; // Signal Pushers + string conditions; // Signal Conditions + + // + // Constructor ... + void XTradeInfo() + { + Clean(); + } + + // + // Filling Trade Handler ... + bool Fill(XSignal &_signal) + { + // + bool result = false; + + // + Clean(); + + // + // Check Signal Validation ... + result = _signal.IsValid(); + if (!result) + { + return result; + } + + // + signal = _signal; + time = _signal.time; + entry = _signal.entry; + symbol = _signal.symbol; + volume = _signal.volume; + period = _signal.period; + pushers = _signal.pushers; + provider = _signal.provider; + conditions = _signal.conditions; + type = ToPositionType(_signal.type); + + // + if (_signal.IsExecuted()) + { + ticket = _signal.positionId; + } + + // + return result; + } + + // + // Filling Trade Handler ... + bool Fill(XPosition &_position) + { + // + bool result = false; + + // + Clean(); + + // + // Check Signal Validation ... + result = _position.IsValid(); + if (!result) + { + return result; + } + + // + time = _position.openAt; + symbol = _position.symbol; + entry = _position.entry; + volume = _position.volume; + provider = _position.provider; + period = _position.period; + type = ToPositionType(_position.type); + + // + ticket = _position.ticket; + + // + return result; + } + + // + // Update Data ... + bool Update(XPosition &_position) + { + // + bool result = false; + + // + result = _position.IsValid(); + if (!result) + { + return result; + } + + // + profit = _position.profit; + swap = _position.swap; + + // + if (profit < 0 && + (maxDrawdown == 0 || + MathAbs(profit) > MathAbs(maxDrawdown))) + { + maxDrawdown = profit; + } + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + time = NULL; + type = NULL; + symbol = NULL; + period = NULL; + endTime = NULL; + message = NULL; + provider = NULL; + + // + swap = 0; + entry = 0; + ticket = 0; + profit = 0; + volume = 0; + commission = 0; + maxDrawdown = 0; + + // + signal.Clean(); + + // + ResetTrail(); + ResetRecovery(); + } + + // + // Validation ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + ticket > 0 && + IsValid(time) && + IsValid(symbol) && + IsValid(period) + // + ; + + // + return result; + } + + // + // Retrieve Trade Data Age ... + int GetAge() + { + // + int result = -1; + + // + if (!IsValid(symbol) || + !IsValid(time) || + !IsValid(endTime) || + !IsValid(period)) + { + return result; + } + + // + int startIndex = iBarShift( + symbol, + period, + time, + false // + ); + + // + int endIndex = iBarShift( + symbol, + period, + endTime, + false // + ); + + // + result = MathAbs(startIndex - endIndex); + + // + return result; + } + + // + // Check Own of Trade Data ... + // based on Ticket ... + bool IsOwn( + ulong _ticket // + ) + { + // + bool result = false; + + // + result = _ticket == ticket; + + // + return result; + } + + // + // Check Own of Trade Data ... + // based on Symbol/Provider and Period ... + bool IsOwn( + string _symbol, + string _provider, + ENUM_TIMEFRAMES _period, + ENUM_X_POSITION_TYPES _type // + ) + { + // + bool result = false; + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + IsValid(_provider) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE && + // + type == _type && + period == _period && + symbol == _symbol && + provider == _provider + // + ; + + // + return result; + } + + // + // Data Collector ... + + // + // Get Data File Name ... + string GetFileName() + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + result = + // + symbol + "\\" + + ToString(type) + "\\" + + (profit >= 0 ? "Profit" : "Loss") + "\\" + + ToString(ticket) + "_" + + ToString(period) + "_" + + ToFormatString(time) + // + ; + + // + return result; + } + + // + // Get Signal File Name ... + string GetSignalFileName() + { + // + string result = NULL; + + // + result = + // + symbol + "\\" + + ToString(type) + "\\" + + provider + "_" + + ToFormatString(time) + // + ; + + // + return result; + } + + // + // Convert(s) To String Representation(s) ... + string ToString( + bool onlySignals = false // + ) + { + // + string result = NULL; + + // + int age = GetAge(); + + // + result = + // + (onlySignals + ? "" + : ToString("Ticket", ticket)) + + ToString("Symbol", symbol) + + ToString("Period", period) + + ToString("Entry", entry) + + ToString("Provider", provider) + + ToString("Type", ToString(type)) + + ToString("Time", time) + + // + // Attach Trade Info ... + (onlySignals + ? "" + : + // + "-------------" + "\n" + + ToString("Volume", volume) + + ToString("Profit", profit) + + ToString("Commission", commission) + + ToString("Swap", swap) + + ToString("Max Drawdown", maxDrawdown) + + ToString("End Time", endTime) + + ToString("Age", age) + + ToString("Message", message) + + "" + // + ) + + // + // Attach Conditions to Signals ... + (!onlySignals + ? "" + : + // + "-------------" + "\n" + + ToString("Pushers", pushers) + + "Conditions:" + "\n" + + "-------------" + "\n" + + conditions + + "" + // + ) + + // + "" + // + ; + + // + return result; + } + + // + // There are some Controlling Situations for each Trade + // which implemented here ... + + // + // Trailing Stop .... + + // + bool allowTrailStop; // Specified Position Can Trail Stop or not + bool ignoreTPOnTrail; // Ignore TP when SL Trailed + bool trailBasedOnProfit; // Do Trail Based on Profit Points + int trailLevel; // Last Trail Level + double trailStartInPoint; // Trail Starts When Profits Growing in Point + double trailStepInPoint; // Profit Must Grows Point to do Trailling + + // + // Reset all Trailing Configurations .... + void ResetTrail() + { + // + trailLevel = 0; + trailStepInPoint = 0; + trailStartInPoint = 0; + allowTrailStop = false; + ignoreTPOnTrail = false; + trailBasedOnProfit = false; + } + + // + // Recovery ... + + // + bool allowRecover; // Allow Recover Specified Position + double recoveryTPPoint; // Recovery TP Point + double recoverySLPoint; // Recovery SL Point + int maxAllowedRecover; // Max Allowed Recovery + int recoveryLevel; // Number of Recovery Signals + double recoveryVolumeMultiplier; // Recovery Volume Multiplier + double recoveryVolume; // Next Recovery Positioin Volume + ENUM_X_POSITION_TYPES recoveryLookingType; // Looking for Next Recovery Type + + // + void ResetRecovery() + { + // + allowRecover = false; + recoveryLevel = 0; + recoveryVolume = 0; + recoveryTPPoint = 0; + recoverySLPoint = 0; + recoveryVolumeMultiplier = 0; + recoveryLookingType = X_POSITION_TYPE_NONE; + } + + // +}; + +// +// TypeDefs ... + +// +typedef void (*TOnSignal)(XSignal &signal); + +// +typedef void (*TOnDealsChanged)(int count); + +// +typedef void (*TOnOrdersChanged)(int count); + +// +typedef void (*TOnPositionsChanged)(int count); + +// +typedef void (*TOnStopLoss)(const XDeal &deal); +typedef void (*TOnTakeProfit)(const XDeal &deal); + +// +typedef void (*TOnTradeStateChanged)(const XOnTradeHandlerState &state); + +// +typedef void (*TOnForceClose)( + const ulong ticket, + const XPosition &position, + const string comment // +); + +// +typedef void (*TOnPartialClose)( + const ulong ticket, + const double profit, + const string comment // +); + +// +typedef void (*TOnModify)( + const ulong ticket, + const double profit, + const string comment // +); + +// +// Classes ... + +// +// Tools ... + +// +bool IsValid(ENUM_X_ORDER_MODES value) +{ + return value != X_ORDER_MODE_NOTHING; +} + +// +// Ages ... + +// +// Retrieve a Position Age ... +int GetAge( + XSignal &signal, // Selected Signal ... + ENUM_TIMEFRAMES period = NULL // Dest Time Frame ... +) +{ + // + int result = -1; + + // + if (period == NULL) + { + period = _Period; + } + + // + result = iBarShift( + signal.symbol, + period, + signal.time); + + // + return result; +} + +// +// Retrieve a Position Age ... +int GetAge( + XPosition &position, // Selected Position ... + ENUM_TIMEFRAMES period = NULL // Dest Time Frame ... +) +{ + // + int result = -1; + + // + if (period == NULL) + { + period = _Period; + } + + // + result = iBarShift( + position.symbol, + period, + position.openAt); + + // + return result; +} + +// +// Retrieve an Order Age ... +int GetAge( + XOrder &order, // Selected Order ... + ENUM_TIMEFRAMES period = NULL // Dest Time Frame ... +) +{ + // + int result = -1; + + // + if (period == NULL) + { + period = _Period; + } + + // + result = iBarShift( + order.symbol, + period, + order.setupAt); + + // + return result; +} + +// +// Retrieve a Deal Age ... +int GetAge( + XDeal &deal, // Selected Deal ... + ENUM_TIMEFRAMES period = NULL // Dest Time Frame ... +) +{ + // + int result = -1; + + // + if (period == NULL) + { + period = _Period; + } + + // + result = iBarShift( + deal.symbol, + period, + deal.time); + + // + return result; +} + +// +// Get Oldest Deal ... +int GetOldest( + XDeal &item, // Hold Result ... + XDeal &items[] // Source Array ... +) +{ + // + int result = -1; + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + int tmpAge = 0; + XDeal tmpItem; + for (int i = 0; i < itemsCount; i++) + { + // + XDeal iItem = items[i]; + + // + int iAge = GetAge(iItem); + if (iAge > 0 && + (tmpAge == 0 || tmpAge < iAge)) + { + // + tmpAge = iAge; + tmpItem = iItem; + } + } + + // + if (tmpAge > 0) + { + // + result = tmpAge; + item = tmpItem; + } + + // + return result; +} + +// +// Get Youngest Deal ... +int GetYoungest( + XDeal &item, // Hold Result ... + XDeal &items[] // Source Array ... +) +{ + // + int result = -1; + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + int tmpAge = 0; + XDeal tmpItem; + for (int i = 0; i < itemsCount; i++) + { + // + XDeal iItem = items[i]; + + // + int iAge = GetAge(iItem); + if (iAge > 0 && + (tmpAge == 0 || tmpAge > iAge)) + { + // + tmpAge = iAge; + tmpItem = iItem; + } + } + + // + if (tmpAge > 0) + { + // + result = tmpAge; + item = tmpItem; + } + + // + return result; +} + +// +// Get Oldest Order ... +int GetOldest( + XOrder &item, // Hold Result ... + XOrder &items[] // Source Array ... +) +{ + // + int result = -1; + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + int tmpAge = 0; + XOrder tmpItem; + for (int i = 0; i < itemsCount; i++) + { + // + XOrder iItem = items[i]; + + // + int iAge = GetAge(iItem); + if (iAge > 0 && + (tmpAge == 0 || tmpAge < iAge)) + { + // + tmpAge = iAge; + tmpItem = iItem; + } + } + + // + if (tmpAge > 0) + { + // + result = tmpAge; + item = tmpItem; + } + + // + return result; +} + +// +// Get Youngest Order ... +int GetYoungest( + XOrder &item, // Hold Result ... + XOrder &items[] // Source Array ... +) +{ + // + int result = -1; + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + int tmpAge = 0; + XOrder tmpItem; + for (int i = 0; i < itemsCount; i++) + { + // + XOrder iItem = items[i]; + + // + int iAge = GetAge(iItem); + if (iAge > 0 && + (tmpAge == 0 || tmpAge > iAge)) + { + // + tmpAge = iAge; + tmpItem = iItem; + } + } + + // + if (tmpAge > 0) + { + // + result = tmpAge; + item = tmpItem; + } + + // + return result; +} + +// +// Get Oldes Position ... +int GetOldest( + XPosition &item, // Hold Result ... + XPosition &items[] // Source Array ... +) +{ + // + int result = -1; + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + int tmpAge = 0; + XPosition tmpItem; + for (int i = 0; i < itemsCount; i++) + { + // + XPosition iItem = items[i]; + + // + int iAge = GetAge(iItem); + if (iAge > 0 && + (tmpAge == 0 || tmpAge < iAge)) + { + // + tmpAge = iAge; + tmpItem = iItem; + } + } + + // + if (tmpAge > 0) + { + // + result = tmpAge; + item = tmpItem; + } + + // + return result; +} + +// +// Get Youngest Position ... +int GetYoungest( + XPosition &item, // Hold Result ... + XPosition &items[] // Source Array ... +) +{ + // + int result = -1; + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + int tmpAge = 0; + XPosition tmpItem; + for (int i = 0; i < itemsCount; i++) + { + // + XPosition iItem = items[i]; + + // + int iAge = GetAge(iItem); + if (iAge > 0 && + (tmpAge == 0 || tmpAge > iAge)) + { + // + tmpAge = iAge; + tmpItem = iItem; + } + } + + // + if (tmpAge > 0) + { + // + result = tmpAge; + item = tmpItem; + } + + // + return result; +} + +// +int FindMaxProfitIndex( + XPosition &positions[] // Position Collection +) +{ + // + int result = -1; + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + double max = 0; + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + if (iPosition.profit <= 0) + { + continue; + } + + // + if (max == 0 || + max < iPosition.profit) + { + // + result = i; + max = iPosition.profit; + } + } + + // + return result; +} + +// +int FindMinProfitIndex( + XPosition &positions[] // Position Collection +) +{ + // + int result = -1; + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + double min = 0; + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + if (iPosition.profit <= 0) + { + continue; + } + + // + if (min == 0 || + min > iPosition.profit) + { + // + result = i; + min = iPosition.profit; + } + } + + // + return result; +} + +// +int ExtractInProfitPositions( + XPosition &positions[], // Position Collection + XPosition &inProfits[] // Result +) +{ + // + int result = 0; + + // + Clean(inProfits); + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (iPosition.profit > 0) + { + // + AddRef( + iPosition, + inProfits // + ); + } + } + + // + result = ArraySize(inProfits); + + // + return result; +} + +// +int FindMaxInDrawdownIndex( + XPosition &positions[] // Position Collection +) +{ + // + int result = -1; + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + double max = 0; + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + if (iPosition.profit >= 0) + { + continue; + } + + // + if (max == 0 || + MathAbs(max) < MathAbs(iPosition.profit)) + { + // + result = i; + max = iPosition.profit; + } + } + + // + return result; +} + +// +int FindMinInDrawdownIndex( + XPosition &positions[] // Position Collection +) +{ + // + int result = -1; + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + double min = 0; + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + if (iPosition.profit >= 0) + { + continue; + } + + // + if (min == 0 || + min > iPosition.profit) + { + // + result = i; + min = iPosition.profit; + } + } + + // + return result; +} + +// +int ExtractInDrawdownPositions( + XPosition &positions[], // Position Collection + XPosition &inDradowns[] // Result +) +{ + // + int result = 0; + + // + Clean(inDradowns); + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (iPosition.profit < 0) + { + // + AddRef( + iPosition, + inDradowns // + ); + } + } + + // + result = ArraySize(inDradowns); + + // + return result; +} + +// +// Check Filters ... + +// +// Magic Filter ... +template +bool IsMagicFilterPassed( + ulong magic, + bool filterByMagic, + T &item + // +) +{ + // + return !filterByMagic + ? true + : !NotEmpty(magic) + ? false + : magic == item.magic; +} + +// +// Symbol Filter ... +template +bool IsSymbolFilterPassed( + string symbol, + T &item + // +) +{ + // + return !IsValid(symbol) + ? true + : symbol == item.symbol; +} + +// +// Provider Filter ... +template +bool IsProviderFilterPassed( + string provider, + T &item + // +) +{ + // + return !IsValid(provider) + ? true + : provider == item.provider; +} + +// +// Period Filter ... +template +bool IsPeriodFilterPassed( + ENUM_TIMEFRAMES period, + T &item + // +) +{ + // + return !IsValid(period) + ? true + : period == item.period; +} + +// +// Type Filter ... +template +bool IsTypeFilterPassed( + ENUM_POSITION_TYPE type, + T &item + // +) +{ + // + bool result = type == item.type; + + // + return result; +} +template +bool IsTypeFilterPassed( + ENUM_X_POSITION_TYPES type, + T &item + // +) +{ + // + bool result = type == NULL || type == X_POSITION_TYPE_ALL + ? true + : ((type == X_POSITION_TYPE_LONG && ((int)item.type == (int)POSITION_TYPE_BUY || (int)item.type == (int)ORDER_TYPE_BUY)) || + (type == X_POSITION_TYPE_SHORT && ((int)item.type == (int)POSITION_TYPE_SELL || (int)item.type == (int)ORDER_TYPE_SELL))); + + // + return result; +} +template +bool IsTypeFilterPassed( + ENUM_ORDER_TYPE type, + T &item + // +) +{ + // + return type == NULL + ? true + : type == item.type; +} +template +bool IsTypeFilterPassed( + ENUM_DEAL_TYPE type, + T &item + // +) +{ + // + return type == NULL + ? true + : type == item.type; +} + +// +// Mode Filter ... +template +bool IsModeFilterPassed( + ENUM_X_ORDER_MODES mode, + T &item + // +) +{ + // + return mode == NULL + ? true + : mode == item.mode; +} + +// +// Entry Filter ... +template +bool IsEntryFilterPassed( + ENUM_DEAL_ENTRY entry, + T &item + // +) +{ + // + return entry == NULL + ? true + : entry == item.entry; +} + +// +// Reason Filter ... +template +bool IsReasonFilterPassed( + ENUM_DEAL_REASON reason, + T &item + // +) +{ + // + return reason == NULL + ? true + : reason == item.reason; +} + +// +// State Filter ... +template +bool IsStateFilterPassed( + ENUM_ORDER_STATE state, + T &item + // +) +{ + // + return state == NULL + ? true + : state == item.state; +} + +// + +// +// Find Specific Item Index inside a Collection ... +template +int FindIndex( + T &item, // Item to Find + const T &items[] // Items for Search +) +{ + // + int result = -1; + + // + // Check Item Validation ... + if (!item.IsValid()) + { + return result; + } + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + for (int i = 0; i < itemsCount; i++) + { + // + T iItem = items[i]; + + // + // Validate Item ... + if (!iItem.IsValid()) + { + continue; + } + + // + bool isSame = item.IsSameAs(iItem); + if (isSame && result <= -1) + { + // + result = i; + break; + } + } + + // + return result; +} + +// +// +// Calculate Positions Profit Summary ... +double SpecifiedCalculatePositionsProfit( + XPosition &positions[] // Source +) +{ + // + double result = 0; + + // + int positionsCount = ArraySize(positions); + if (positionsCount <= 0) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + result += iPosition.profit; + } + + // + return result; +} + +// +// Calculate Required Profit for Hedging ... +double SpecifiedCalculateRequiredProfitForHedge( + XPosition &positions[], // Source + double mMinProfitPerTrade, + double mMinProfitPerVolumeFactor // +) +{ + // + double result = 0; + + // + int positionsCount = ArraySize(positions); + if (positionsCount <= 0) + { + return result; + } + + // + bool isHedgingEnable = mMinProfitPerTrade > 0 && mMinProfitPerVolumeFactor > 0; + if (!isHedgingEnable) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (mMinProfitPerTrade > 0 && mMinProfitPerVolumeFactor > 0) + { + // + result += + ((iPosition.volume / mMinProfitPerVolumeFactor) * + mMinProfitPerTrade) + + (-1 * iPosition.swap); + } + } + + // + return result; +} + +// +bool SpecifiedIsPositionsReadyForHedge( + XPosition &positions[], // Source + double mMinProfitPerTrade, + double mMinProfitPerVolumeFactor // +) +{ + // + double profit = SpecifiedCalculatePositionsProfit(positions); + double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( + positions, + mMinProfitPerTrade, + mMinProfitPerVolumeFactor // + ); + + // + bool result = requiredProfit > 0 + ? profit >= requiredProfit + : profit > requiredProfit; + + // + return result; +} + +// +int FindCoverageDrawdownPosition( + XPosition &position, // In Drawdown Position + XPosition &inProfits[], // In Profit Positions + XPosition &coverage[], // Coverage Positons + double mMinProfitPerTrade, + double mMinProfitPerVolumeFactor // +) +{ + // + int result = 0; + + // + Clean(coverage); + + // + if (!position.IsValid() || position.profit >= 0) + { + return result; + } + + // + int inProfitsCount = ArraySize(inProfits); + if (!IsValidSize(inProfitsCount)) + { + return result; + } + + // + // Copy in Profits to TMP ... + XPosition tmp[]; + Copy( + inProfits, + tmp // + ); + + // + bool isCoverPassed = false; + while (!isCoverPassed || ArraySize(tmp) > 0) + { + // + XPosition max; + int idx = FindMaxProfitIndex(tmp); + if (idx >= 0) + { + // + if (tmp[idx].profit > 0) + { + AddRef( + tmp[idx], + coverage // + ); + + // + ArrayRemove( + tmp, + idx, + 1 // + ); + } + } + + // + // Check Cover Passed ... + XPosition tmpPositions[]; + Copy( + coverage, + tmpPositions // + ); + AddRef( + position, + tmpPositions // + ); + + // + double profits = SpecifiedCalculatePositionsProfit(tmpPositions); + double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( + tmpPositions, + mMinProfitPerTrade, + mMinProfitPerVolumeFactor // + ); + isCoverPassed = profits >= requiredProfit; + if (isCoverPassed) + { + break; + } + + // + if (!isCoverPassed && ArraySize(tmp) == 0) + { + break; + } + } + + // + result = ArraySize(coverage); + + // + return result; +} + +// +// Extract a Collection of Positions SL ... +int ExtractSLs( + XPosition &positions[], + double &sls[] // +) +{ + // + int result = 0; + + // + Clean(sls); + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (iPosition.sl > 0) + { + // + Add( + iPosition.sl, + sls // + ); + } + } + + // + result = ArraySize(sls); + + // + return result; +} + +// +// Extract a Colletion of Positions TP ... +int ExtractTPs( + XPosition &positions[], + double &tps[] // +) +{ + // + int result = 0; + + // + Clean(tps); + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (iPosition.tp > 0) + { + // + Add( + iPosition.tp, + tps // + ); + } + } + + // + result = ArraySize(tps); + + // + return result; +} + +// +// Retrieve String Representation ... +string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_SIGNAL_EXECUTION_UNKNOWN: + result = "Unknown"; + break; + + // + case X_SIGNAL_EXECUTION_SUCCEED: + result = "Succed"; + break; + + // + case X_SIGNAL_EXECUTION_FAILED_SPREAD: + result = "Spread more than Max Allowed"; + break; + + // + case X_SIGNAL_EXECUTION_FAILED_NO_EQUITY: + result = "No Equity for Trade"; + break; + + // + case X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR: + result = "Price Error"; + break; + + // + case X_SIGNAL_EXECUTION_FAILED_MAX_REACHED: + result = "Max Allowed Positions Reached"; + break; + + // + case X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS: + result = "Invalid Params"; + break; + } + + // + return result; +} + +// +// Converts Position Type to Order Type ... +ENUM_ORDER_TYPE ToOrderType(ENUM_POSITION_TYPE value) +{ + // + bool isLong = IsLong(value); + + // + ENUM_ORDER_TYPE result = + isLong + ? ORDER_TYPE_BUY + : ORDER_TYPE_SELL; + + // + return result; +} +ENUM_ORDER_TYPE ToOrderType(ENUM_X_POSITION_TYPES value) +{ + // + ENUM_POSITION_TYPE mType = + value == X_POSITION_TYPE_SHORT + ? POSITION_TYPE_SELL + : POSITION_TYPE_BUY; + + // + bool isLong = IsLong(mType); + + // + ENUM_ORDER_TYPE result = + isLong + ? ORDER_TYPE_BUY + : ORDER_TYPE_SELL; + + // + return result; +} + +// +// Tagging ... + +// +// Generate Specified Tag for Using in Comments ... +string GeneratePeriodTag(ENUM_TIMEFRAMES period) +{ + // + string strPeriod = ToString(period); + return Surround( + XPeriodToken, + strPeriod + // + ); +} + +// +// Extract Period from a Tagged string ... +ENUM_TIMEFRAMES ExtractPeriod(string value) +{ + // + ENUM_TIMEFRAMES result = NULL; + + // + string pStr = ParseStringSurrounded( + value, + XPeriodToken + // + ); + if (!IsValid(pStr)) + { + return result; + } + + // + result = ToPeriod(pStr); + + // + return result; +} + +// Generate Specified Tag for Using in Comments ... +string GenerateProviderTag(string provider) +{ + // + return Surround( + XProviderToken, + provider + // + ); +} + +// +// Extract Provider from a Tagged string ... +string ExtractProvider(string value) +{ + // + return ParseStringSurrounded( + value, + XProviderToken + // + ); +} + +// +// Generate Support Comment Tag ... +string GenerateSupportTag(ulong ticket) +{ + // + return Surround( + XSupportToken, + ticket + // + ); +} + +// +// Extract Support Positions from a Tagged string ... +ulong ExtractSupportedTicket(string value) +{ + // + return ParseLongSurrounded( + value, + XSupportToken + // + ); +} + +// +// Extract Support ... +template +int ExtractSupports( + T &source[], + T &dest[] // Result ... +) +{ + // + int result = 0; + + // + Clean(dest); + + // + int sourceCount = ArraySize(source); + if (!IsValidSize(sourceCount)) + { + return result; + } + + // + for (int i = 0; i < sourceCount; i++) + { + // + T iSource = source[i]; + + // + ulong isSupport = ExtractSupportedTicket(iSource.comment) > 0; + ulong iEQMSupport = ExtractEQMSupportedTicket(iSource.comment) > 0; + if (isSupport || iEQMSupport) + { + // + AddRef( + iSource, + dest // + ); + } + } + + // + result = ArraySize(dest); + + // + return result; +} + +// +// Generate EQM Support Comment Tag ... +string GenerateEQMSupportTag(ulong ticket) +{ + // + return Surround( + XEQMSupportToken, + ticket + // + ); +} + +// +// Extract EQM Support Positions from a Tagged string ... +ulong ExtractEQMSupportedTicket(string value) +{ + // + return ParseLongSurrounded( + value, + XEQMSupportToken + // + ); +} + +// +bool IsSupport(string value) +{ + // + bool result = false; + + // + bool isSupport = ExtractSupportedTicket(value) > 0; + bool isEQMSupport = ExtractEQMSupportedTicket(value) > 0; + + // + result = + // + isSupport + // + || + // + isEQMSupport + // + ; + + // + return result; +} + +// +ulong ExtractParentTicket(string value) +{ + // + ulong result = 0; + + // + if (!IsSupport(value)) + { + return result; + } + + // + result = ExtractSupportedTicket(value); + if (result > 0) + { + return result; + } + + // + result = ExtractEQMSupportedTicket(value); + + // + return result; +} + +// +// XRecovery ... + +// +string GenerateRecoveryTag(ulong ticket) +{ + // + return Surround( + XRecoveryToken, + ticket // + ); +} + +// +ulong ExtractRecoveredTicket(string value) +{ + // + return ParseLongSurrounded( + value, + XRecoveryToken // + ); +} + +// +// Extract Recoveries ... +template +int ExtractRecoveries( + T &source[], + T &dest[] // Result ... +) +{ + // + int result = 0; + + // + Clean(dest); + + // + int sourceCount = ArraySize(source); + if (!IsValidSize(sourceCount)) + { + return result; + } + + // + for (int i = 0; i < sourceCount; i++) + { + // + T iSource = source[i]; + + // + ulong isRecovery = ExtractRecoveredTicket(iSource.comment) > 0; + if (isRecovery) + { + // + AddRef( + iSource, + dest // + ); + } + } + + // + result = ArraySize(dest); + + // + return result; +} + +// +// Extract Specified Position's Recoveries ... +int ExtractRecoveries( + ulong ticket, + XPosition &source[], + XPosition &dest[] // Result ... +) +{ + // + int result = 0; + + // + Clean(dest); + + // + int sourceCount = ArraySize(source); + if (!IsValidSize(sourceCount)) + { + return result; + } + + // + for (int i = 0; i < sourceCount; i++) + { + // + XPosition iSource = source[i]; + + // + ulong parentTicket = ExtractRecoveredTicket(iSource.comment); + bool isRecovery = parentTicket > 0; + if (isRecovery && parentTicket == ticket) + { + // + AddRef( + iSource, + dest // + ); + } + } + + // + result = ArraySize(dest); + + // + return result; +} + +// +// SL Trails ... + +// +// Extract SL Trail Level ... +int ExtractSLTrailLevel(string comment) +{ + // + int result = 0; + + // + if (!IsValid(comment)) + { + return result; + } + + // + result = ParseIntSurrounded( + comment, + XSLTrailToken + // + ); + + // + return result; +} + +// +// Generate SL Trail Comment Tag ... +string GenerateSLTrailTag(int level) +{ + // + string result = NULL; + + // + if (level <= 0) + { + return result; + } + + // + result = Surround( + XSLTrailToken, + level + // + ); + + // + return result; +} + +// +// Prepare SL Trail Comment ... +string PrepareSLTrailTag( + const string comment // Original Position Comment ... +) +{ + // + string result = NULL; + + // + int level = 0; + result = comment; + + // + // Check Comment Contains SL Trailing or not ... + int lastTrailLevel = ExtractSLTrailLevel(comment); + if (lastTrailLevel <= 0) + { + level++; + } + else + { + // + level = lastTrailLevel + 1; + string lastLevelStr = GenerateSLTrailTag(lastTrailLevel); + StringReplace( + result, + lastLevelStr, + "" + // + ); + } + + // + // Generate level Comment ... + string levelStr = GenerateSLTrailTag(level); + result += levelStr; + + // + return result; +} + +// +// Count Positions from a Collection ... +void CountPositions( + const XPosition &positions[], + int &longs, + double &longProfits, + double &longVolumes, // + // + int &shorts, + double &shortProfits, + double &shortVolumes // +) +{ + // + longs = 0; + longProfits = 0; + longVolumes = 0; + + // + shorts = 0; + shortProfits = 0; + shortVolumes = 0; + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + bool isLong = IsLong(iPosition.type); + if (isLong) + { + // + longs++; + longProfits += iPosition.profit; + longVolumes += iPosition.volume; + } + else + { + // + shorts++; + shortProfits += iPosition.profit; + shortVolumes += iPosition.volume; + } + } +} + +// +// Extract Positions based On Type ... +void ExtractPositions( + XPosition &positions[], + XPosition &longs[], + XPosition &shorts[] // +) +{ + // + int count = ArraySize(positions); + if (!IsValidSize(count)) + { + return; + } + + // + Clean(longs); + Clean(shorts); + + // + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = positions[i]; + + // + bool isLong = IsLong(iPosition.type); + if (isLong) + { + AddRef( + iPosition, + longs // + ); + } + else + { + AddRef( + iPosition, + shorts // + ); + } + } +} + +// +int FindSymbolIndex( + string mSymbol, + XSymbolPositions &mItems[] // +) +{ + // + int result = -1; + + // + if (!IsValid(mSymbol)) + { + return result; + } + + // + int count = ArraySize(mItems); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XSymbolPositions iItem = mItems[i]; + + // + if (iItem.symbol == mSymbol) + { + // + result = i; + break; + } + } + + // + return result; +} + +// +int ExtractSymbolPositions( + XPosition &positions[], + XSymbolPositions &items[], // Holds Result + double mMinProfitPerTrade, + double mMinProfitPerVolumeFactor // +) +{ + // + int result = 0; + + // + int positionsCount = ArraySize(positions); + if (!IsValidSize(positionsCount)) + { + return result; + } + + // + Clean(items); + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + if (!iPosition.IsValid()) + { + continue; + } + + // + int itemIDX = FindSymbolIndex( + iPosition.symbol, + items // + ); + if (!IsValidIndex(itemIDX)) + { + // + // Add New One ... + XSymbolPositions item; + item.symbol = iPosition.symbol; + + // + AddRef( + item, + items // + ); + itemIDX = FindSymbolIndex(iPosition.symbol, items); + } + + // + AddRef( + iPosition, + items[itemIDX].positions // + ); + } + + // + result = ArraySize(items); + if (IsValidSize(result)) + { + // + for (int i = 0; i < result; i++) + { + // + items[i].Update( + mMinProfitPerTrade, + mMinProfitPerVolumeFactor // + ); + } + } + + // + return result; +} + +// +// Custom Drawings ... +bool DrawTrendState( + long chartId, + string _prefix, + XOHCL &_bar, + double &support, + double &resistance, + int shoulders = 10, + int subWindow = 0, + color resistanceColor = clrRed, + color supportColor = clrGreen, + color swingHighColor = clrAqua, + color swingLowColor = clrMagenta // +) +{ + // + bool result = false; + + // + result = + // + IsValid(_prefix) && + _bar.IsValid() + // + ; + if (!result) + { + return result; + } + + // + // Find Low Swings ... + + // + int firstSwingLowIndex = FindSwing( + _bar.symbol, + _bar.period, + X_SWING_LOW, + shoulders, + _bar.Index() + 1 // + ); + XOHCL firstSwingLowBar; + result = firstSwingLowBar.Init( + _bar.symbol, + _bar.period, + firstSwingLowIndex // + ); + if (!result) + { + return result; + } + + // + int secondSwingLowIndex = FindSwing( + _bar.symbol, + _bar.period, + X_SWING_LOW, + shoulders, + firstSwingLowIndex + 1 // + ); + XOHCL secondSwingLowBar; + result = secondSwingLowBar.Init( + _bar.symbol, + _bar.period, + secondSwingLowIndex // + ); + if (!result) + { + return result; + } + + // + support = secondSwingLowBar.low; + + // + string lowSwingTrendLineName = _prefix + "_Low_Swing_Trend"; + + // + result = DrawTrendLine( + chartId, + lowSwingTrendLineName, + subWindow, + secondSwingLowBar.time, + secondSwingLowBar.low, + firstSwingLowBar.time, + firstSwingLowBar.low, + swingLowColor, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + if (!result) + { + return result; + } + + // + string lowSwingSupportLineName = _prefix + "_Low_Swing_Support"; + + // + result = DrawTrendLine( + chartId, + lowSwingSupportLineName, + subWindow, + secondSwingLowBar.time, + secondSwingLowBar.low, + firstSwingLowBar.time, + secondSwingLowBar.low, + supportColor, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + if (!result) + { + return result; + } + + // + // Find High Swings ... + + // + int firstSwingHighIndex = FindSwing( + _bar.symbol, + _bar.period, + X_SWING_HIGH, + shoulders, + _bar.Index() + 1 // + ); + XOHCL firstSwingHighBar; + result = firstSwingHighBar.Init( + _bar.symbol, + _bar.period, + firstSwingHighIndex // + ); + if (!result) + { + return result; + } + + // + int secondSwingHighIndex = FindSwing( + _bar.symbol, + _bar.period, + X_SWING_HIGH, + shoulders, + firstSwingHighIndex + 1 // + ); + XOHCL secondSwingHighBar; + result = secondSwingHighBar.Init( + _bar.symbol, + _bar.period, + secondSwingHighIndex // + ); + if (!result) + { + return result; + } + + // + resistance = secondSwingHighBar.high; + + // + string highSwingTrendLineName = _prefix + "_High_Swing_Trend"; + + // + result = DrawTrendLine( + chartId, + highSwingTrendLineName, + subWindow, + secondSwingHighBar.time, + secondSwingHighBar.high, + firstSwingHighBar.time, + firstSwingHighBar.high, + swingHighColor, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + if (!result) + { + return result; + } + + // + string highSwingResistanceLineName = _prefix + "_High_Swing_Resistance"; + + // + result = DrawTrendLine( + chartId, + highSwingResistanceLineName, + subWindow, + secondSwingHighBar.time, + secondSwingHighBar.high, + firstSwingHighBar.time, + secondSwingHighBar.high, + resistanceColor, + STYLE_SOLID, + 2, + false, + false, + true // Ray Right ... + ); + if (!result) + { + return result; + } + + // + return result; +} + +// \ No newline at end of file diff --git a/Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2018/x-saherelm.x121.amarkets.audusd.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2019/x-saherelm.x121.amarkets.audusd.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2020/x-saherelm.x121.amarkets.audusd.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2021/x-saherelm.x121.amarkets.audusd.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2022/x-saherelm.x121.amarkets.audusd.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2023/x-saherelm.x121.amarkets.audusd.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/2024/x-saherelm.x121.amarkets.audusd.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/Olds/x-saherelm.x121.amarkets.audusd.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.long.parser.mq5 diff --git a/Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/AUDUSD/x-saherelm.x121.amarkets.audusd.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2018/x-saherelm.x121.amarkets.brent.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2019/x-saherelm.x121.amarkets.brent.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2020/x-saherelm.x121.amarkets.brent.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2021/x-saherelm.x121.amarkets.brent.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2022/x-saherelm.x121.amarkets.brent.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2023/x-saherelm.x121.amarkets.brent.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/2024/x-saherelm.x121.amarkets.brent.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/Olds/x-saherelm.x121.amarkets.brent.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.long.parser.mq5 diff --git a/Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/Brent/x-saherelm.x121.amarkets.brent.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2018/x-saherelm.x121.amarkets.us30.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2019/x-saherelm.x121.amarkets.us30.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2020/x-saherelm.x121.amarkets.us30.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2021/x-saherelm.x121.amarkets.us30.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2022/x-saherelm.x121.amarkets.us30.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2023/x-saherelm.x121.amarkets.us30.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/2024/x-saherelm.x121.amarkets.us30.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/Olds/x-saherelm.x121.amarkets.us30.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.long.parser.mq5 diff --git a/Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/DowJones/x-saherelm.x121.amarkets.us30.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2018/x-saherelm.x121.amarkets.euraud.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2019/x-saherelm.x121.amarkets.euraud.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2020/x-saherelm.x121.amarkets.euraud.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2021/x-saherelm.x121.amarkets.euraud.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2022/x-saherelm.x121.amarkets.euraud.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2023/x-saherelm.x121.amarkets.euraud.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/2024/x-saherelm.x121.amarkets.euraud.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/Olds/x-saherelm.x121.amarkets.euraud.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.long.parser.mq5 diff --git a/Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURAUD/x-saherelm.x121.amarkets.euraud.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2018/x-saherelm.x121.amarkets.eurcad.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2019/x-saherelm.x121.amarkets.eurcad.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2020/x-saherelm.x121.amarkets.eurcad.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2021/x-saherelm.x121.amarkets.eurcad.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2022/x-saherelm.x121.amarkets.eurcad.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2023/x-saherelm.x121.amarkets.eurcad.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/2024/x-saherelm.x121.amarkets.eurcad.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/Olds/x-saherelm.x121.amarkets.eurcad.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCAD/x-saherelm.x121.amarkets.eurcad.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2018/x-saherelm.x121.amarkets.eurchf.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2019/x-saherelm.x121.amarkets.eurchf.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2020/x-saherelm.x121.amarkets.eurchf.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2021/x-saherelm.x121.amarkets.eurchf.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2022/x-saherelm.x121.amarkets.eurchf.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2023/x-saherelm.x121.amarkets.eurchf.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/2024/x-saherelm.x121.amarkets.eurchf.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/Olds/x-saherelm.x121.amarkets.eurchf.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.long.parser.mq5 diff --git a/Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURCHF/x-saherelm.x121.amarkets.eurchf.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2018/x-saherelm.x121.amarkets.eurgbp.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2019/x-saherelm.x121.amarkets.eurgbp.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2020/x-saherelm.x121.amarkets.eurgbp.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2021/x-saherelm.x121.amarkets.eurgbp.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2022/x-saherelm.x121.amarkets.eurgbp.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2023/x-saherelm.x121.amarkets.eurgbp.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/2024/x-saherelm.x121.amarkets.eurgbp.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/Olds/x-saherelm.x121.amarkets.eurgbp.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.long.parser.mq5 diff --git a/Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURGBP/x-saherelm.x121.amarkets.eurgbp.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2018/x-saherelm.x121.amarkets.eurjpy.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2019/x-saherelm.x121.amarkets.eurjpy.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2020/x-saherelm.x121.amarkets.eurjpy.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2021/x-saherelm.x121.amarkets.eurjpy.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2022/x-saherelm.x121.amarkets.eurjpy.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2023/x-saherelm.x121.amarkets.eurjpy.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/2024/x-saherelm.x121.amarkets.eurjpy.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/Olds/x-saherelm.x121.amarkets.eurjpy.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.long.parser.mq5 diff --git a/Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURJPY/x-saherelm.x121.amarkets.eurjpy.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2018/x-saherelm.x121.amarkets.eurnzd.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2019/x-saherelm.x121.amarkets.eurnzd.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2020/x-saherelm.x121.amarkets.eurnzd.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2021/x-saherelm.x121.amarkets.eurnzd.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2022/x-saherelm.x121.amarkets.eurnzd.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2023/x-saherelm.x121.amarkets.eurnzd.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/2024/x-saherelm.x121.amarkets.eurnzd.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/Olds/x-saherelm.x121.amarkets.eurnzd.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.long.parser.mq5 diff --git a/Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURNZD/x-saherelm.x121.amarkets.eurnzd.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2018/x-saherelm.x121.amarkets.eurusd.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2019/x-saherelm.x121.amarkets.eurusd.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2020/x-saherelm.x121.amarkets.eurusd.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2021/x-saherelm.x121.amarkets.eurusd.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2022/x-saherelm.x121.amarkets.eurusd.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2023/x-saherelm.x121.amarkets.eurusd.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/2024/x-saherelm.x121.amarkets.eurusd.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/Olds/x-saherelm.x121.amarkets.eurusd.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.long.parser.mq5 diff --git a/Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/EURUSD/x-saherelm.x121.amarkets.eurusd.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2018/x-saherelm.x121.amarkets.gbpusd.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2019/x-saherelm.x121.amarkets.gbpusd.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2020/x-saherelm.x121.amarkets.gbpusd.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2021/x-saherelm.x121.amarkets.gbpusd.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2022/x-saherelm.x121.amarkets.gbpusd.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2023/x-saherelm.x121.amarkets.gbpusd.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/2024/x-saherelm.x121.amarkets.gbpusd.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/Olds/x-saherelm.x121.amarkets.gbpusd.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.long.parser.mq5 diff --git a/Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/GBPUSD/x-saherelm.x121.amarkets.gbpusd.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2018/x-saherelm.x121.amarkets.nzdusd.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2019/x-saherelm.x121.amarkets.nzdusd.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2020/x-saherelm.x121.amarkets.nzdusd.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2021/x-saherelm.x121.amarkets.nzdusd.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2022/x-saherelm.x121.amarkets.nzdusd.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2023/x-saherelm.x121.amarkets.nzdusd.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/2024/x-saherelm.x121.amarkets.nzdusd.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/Olds/x-saherelm.x121.amarkets.nzdusd.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.long.parser.mq5 diff --git a/Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/NZDUSD/x-saherelm.x121.amarkets.nzdusd.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2018/x-saherelm.x121.amarkets.usdcad.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2019/x-saherelm.x121.amarkets.usdcad.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2020/x-saherelm.x121.amarkets.usdcad.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2021/x-saherelm.x121.amarkets.usdcad.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2022/x-saherelm.x121.amarkets.usdcad.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2023/x-saherelm.x121.amarkets.usdcad.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/2024/x-saherelm.x121.amarkets.usdcad.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/Olds/x-saherelm.x121.amarkets.usdcad.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCAD/x-saherelm.x121.amarkets.usdcad.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2018/x-saherelm.x121.amarkets.usdchf.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2019/x-saherelm.x121.amarkets.usdchf.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2020/x-saherelm.x121.amarkets.usdchf.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2021/x-saherelm.x121.amarkets.usdchf.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2022/x-saherelm.x121.amarkets.usdchf.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2023/x-saherelm.x121.amarkets.usdchf.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/2024/x-saherelm.x121.amarkets.usdchf.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/Olds/x-saherelm.x121.amarkets.usdchf.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.long.parser.mq5 diff --git a/Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDCHF/x-saherelm.x121.amarkets.usdchf.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2018/x-saherelm.x121.amarkets.usdjpy.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2019/x-saherelm.x121.amarkets.usdjpy.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2020/x-saherelm.x121.amarkets.usdjpy.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2021/x-saherelm.x121.amarkets.usdjpy.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2022/x-saherelm.x121.amarkets.usdjpy.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2023/x-saherelm.x121.amarkets.usdjpy.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/2024/x-saherelm.x121.amarkets.usdjpy.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/Olds/x-saherelm.x121.amarkets.usdjpy.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.long.parser.mq5 diff --git a/Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/USDJPY/x-saherelm.x121.amarkets.usdjpy.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2018/x-saherelm.x121.amarkets.xagusd.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2019/x-saherelm.x121.amarkets.xagusd.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2020/x-saherelm.x121.amarkets.xagusd.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2021/x-saherelm.x121.amarkets.xagusd.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2022/x-saherelm.x121.amarkets.xagusd.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2023/x-saherelm.x121.amarkets.xagusd.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/2024/x-saherelm.x121.amarkets.xagusd.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/Olds/x-saherelm.x121.amarkets.xagusd.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.long.parser.mq5 diff --git a/Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAGUSD/x-saherelm.x121.amarkets.xagusd.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2018/x-saherelm.x121.amarkets.xauusd.2018.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2019/x-saherelm.x121.amarkets.xauusd.2019.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2020/x-saherelm.x121.amarkets.xauusd.2020.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2021/x-saherelm.x121.amarkets.xauusd.2021.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2022/x-saherelm.x121.amarkets.xauusd.2022.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2023/x-saherelm.x121.amarkets.xauusd.2023.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/2024/x-saherelm.x121.amarkets.xauusd.2024.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.1.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.2.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.2.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.2.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.2.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.3.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.3.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.3.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.3.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.4.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.4.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.4.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.4.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.5.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.5.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.5.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.5.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.6.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.6.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.6.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.6.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.7.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.7.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.7.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.7.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/Olds/x-saherelm.x121.amarkets.xauusd.olds.short.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.long.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.long.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.long.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.long.parser.mq5 diff --git a/Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.short.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.short.parser.mq5 similarity index 100% rename from Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.short.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/XAUUSD/x-saherelm.x121.amarkets.xauusd.short.parser.mq5 diff --git a/Parsers/AMarkets/x-saherelm.x121.amarkets.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/AMarkets/x-saherelm.x121.amarkets.parser.mq5 similarity index 100% rename from Parsers/AMarkets/x-saherelm.x121.amarkets.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/AMarkets/x-saherelm.x121.amarkets.parser.mq5 diff --git a/Parsers/x-saherelm.x121.parser.mq5 b/Documents/BKP/14030802-X121/Parsers/x-saherelm.x121.parser.mq5 similarity index 100% rename from Parsers/x-saherelm.x121.parser.mq5 rename to Documents/BKP/14030802-X121/Parsers/x-saherelm.x121.parser.mq5 diff --git a/Strategies/x-saherelm.x121.strategy.mq5 b/Documents/BKP/14030802-X121/Strategies/x-saherelm.x121.strategy.mq5 similarity index 100% rename from Strategies/x-saherelm.x121.strategy.mq5 rename to Documents/BKP/14030802-X121/Strategies/x-saherelm.x121.strategy.mq5