diff --git a/Documents/BKP/x-poi.bkp.mq5 b/Documents/BKP/x-poi.bkp.mq5 new file mode 100644 index 00000000..696f865c --- /dev/null +++ b/Documents/BKP/x-poi.bkp.mq5 @@ -0,0 +1,1044 @@ + +// +// Represent a Session Working Time ... +struct XSession +{ + // + // Props ... + ENUM_XSESSION session; // Session Identifier + string start; // Start Time + string end; // End Time + + // + bool allowDraw; + color startColor; + ENUM_LINE_STYLE startStyle; + color endColor; + ENUM_LINE_STYLE endStyle; + + /** + * Constructor ... + */ + void XSession() + { + Clean(); + } + + /** + * Clean Structure ... + */ + void Clean() + { + // + start = NULL; + end = NULL; + + // + allowDraw = false; + endColor = clrAqua; + endStyle = STYLE_DOT; + startColor = clrAqua; + endStyle = STYLE_DOT; + } + + /** + * Validate Structure ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = IsValid(start) && + IsValid(end); + + // + return result; + } + + /** + * Initialize Specified Session ... + * + * @param _session: ENUM_XSESSION member ... + * @param _start: String (Session Start Time) ... + * @param _end: String (Session End Time) ... + * + * @return ( bool ) + */ + bool Init( + ENUM_XSESSION _session, + string _start, + string _end // + ) + { + // + bool result = false; + + // + result = IsValid(_start) && + IsValid(_end); + if (!result) + { + return result; + } + + // + end = _end; + start = _start; + session = _session; + + // + result = IsValid(); + + // + return result; + } + + // +}; + +// +struct XTradeDay +{ + // + datetime from; + datetime to; + + // + void XTradeDay() + { + Clean(); + } + + // + void Clean() + { + // + from = NULL; + to = NULL; + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = IsValid(from) && + IsValid(to); + + // + return result; + } + + // + string GetTag() + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + result = ToString(X_POI_TRADING_DAY) + "_" + ToFormatString(from) + "_" + ToFormatString(to); + + // + return result; + } + + // +}; + +// +// Detected Session ... +struct XMarketSession +{ + // + ENUM_XSESSION session; + datetime from; + datetime to; + + // + void XMarketSession() + { + Clean(); + } + + // + void Clean() + { + from = NULL; + to = NULL; + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = IsValid(from) && + IsValid(to); + + // + return result; + } + + // + string GetTag() + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + result = + ToString(X_POI_MARKET_SESSION) + "_" + + ToString(session) + "_" + + ToFormatString(from) + + "_" + + ToFormatString(to) + "_"; + + // + return result; + } +}; + +// +// Zone Struct ... +struct XZone +{ + // + // Props ... + double upper; + double lower; + string prefix; + + // + datetime from; + datetime to; + + // + // Constructor ... + void XZone() + { + Clean(); + } + + // + bool Init( + double _upper, + double _lower, + string _prefix, + datetime _from, + datetime _to // + ) + { + // + bool result = false; + + // + result = + _upper > 0 && + _lower > 0 && + _upper > _lower && + IsValid(_prefix) && + IsValid(_from); + if (!result) + { + return result; + } + + // + NormalizeTime(_to); + + // + upper = _upper; + lower = _lower; + prefix = _prefix; + from = _from; + to = _to; + + // + result = IsValid(); + + // + return result; + } + + // + void Clean() + { + // + upper = 0; + lower = 0; + + // + to = NULL; + from = NULL; + prefix = NULL; + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = upper > 0 && + lower > 0 && + upper > lower && + IsValid(to) && + IsValid(from) && + IsValid(prefix); + + // + return result; + } + + // + double GetRange() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = upper - lower; + + // + return result; + } + + // + double GetMiddle() + { + // + double result = 0; + + // + double range = GetRange(); + if (range <= 0) + { + return result; + } + + // + result = lower + (range / 2); + + // + return result; + } + + // + string GetTag() + { + // + string result = NULL; + + // + result = prefix + "_" + + ToString(upper) + "_" + + ToString(lower); + + // + return result; + } +}; + +// +// XOHCL Event Handler ... +typedef void (*TXOHCLEventHandler)( + ENUM_XPOI_EVENTS event, + XOHCL &bar // +); + +// +// POI Event Handler ... +typedef void (*TXPOIEventHandler)( + ENUM_XPOI_EVENTS event // +); + +// +// Session Event Handler ... +typedef void (*TXSessionEventHandler)( + ENUM_XSESSION session, + ENUM_XPOI_EVENTS event // +); + +// +// Zone Handler ... +typedef void (*TXZoneEventHandler)( + ENUM_XPOI_EVENTS event, + XZone &zone // +); + + +// +// Model Exists Founded POIs ... +struct XPOIState +{ + // + string symbol; + ENUM_TIMEFRAMES period; + datetime reportedAt; + + // + XTradeDay tradingDays[]; + XMarketSession marketSessions[]; + + // + XOHCL momentumBars[]; + XOHCL rejectionBars[]; + + // + XOHCL swingHighs[]; + XOHCL swingLows[]; + + // + XOHCL supportZones[]; + XOHCL resistanceZones[]; + + // + XZone supplyZones[]; + XZone demandZones[]; + + // + XZone bullishOrderBlocks[]; + XZone bearishOrderBlocks[]; + + // + XZone bullishFVGs[]; + XZone bearishFVGs[]; + + // + // Constructor ... + void XPOIState() + { + Clean(); + } + + // + // Actions ... + + /** + * Cleanup all props ... + */ + void Clean() + { + // + symbol = NULL; + period = NULL; + reportedAt = NULL; + + // + Clean(tradingDays); + Clean(marketSessions); + + // + Clean(momentumBars); + Clean(rejectionBars); + + // + Clean(swingHighs); + Clean(swingLows); + + // + Clean(supportZones); + Clean(resistanceZones); + + // + Clean(supplyZones); + Clean(demandZones); + + // + Clean(bullishOrderBlocks); + Clean(bearishOrderBlocks); + + // + Clean(bullishFVGs); + Clean(bearishFVGs); + } + + /** + * Fill Trading Days ... + * + * @param source: XTradeDay instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillTradingDays( + XTradeDay &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(tradingDays); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + tradingDays // + ); + result = ArraySize(tradingDays); + + // + return result; + } + + /** + * Fill Market Sessions ... + * + * @param source: XMarketSession instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillMarketSessions( + XMarketSession &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(marketSessions); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + marketSessions // + ); + result = ArraySize(marketSessions); + + // + return result; + } + + /** + * Fill Momentum Bars ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillMomentumBars( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(momentumBars); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + momentumBars // + ); + result = ArraySize(momentumBars); + + // + return result; + } + + /** + * Fill Retection Bars ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillRejectionBars( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(rejectionBars); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + rejectionBars // + ); + result = ArraySize(rejectionBars); + + // + return result; + } + + /** + * Fill Swing Highs ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSwingHighs( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(swingHighs); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + swingHighs // + ); + result = ArraySize(swingHighs); + + // + return result; + } + + /** + * Fill Swing Lows ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSwingLows( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(swingLows); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + swingLows // + ); + result = ArraySize(swingLows); + + // + return result; + } + + /** + * Fill Support Zones ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSupportZones( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(supportZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + supportZones // + ); + result = ArraySize(supportZones); + + // + return result; + } + + /** + * Fill Resistance Zones ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillResistanceZones( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(resistanceZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + resistanceZones // + ); + result = ArraySize(resistanceZones); + + // + return result; + } + + /** + * Fill Supply Zones ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSupplyZones( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(supplyZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + supplyZones // + ); + result = ArraySize(supplyZones); + + // + return result; + } + + /** + * Fill Demand Zones ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillDemandZones( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(demandZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + demandZones // + ); + result = ArraySize(demandZones); + + // + return result; + } + + /** + * Fill Bullish Order Blockss ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBullishOrderBlocks( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bullishOrderBlocks); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bullishOrderBlocks // + ); + result = ArraySize(bullishOrderBlocks); + + // + return result; + } + + /** + * Fill Bearish Order Blockss ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBearishOrderBlocks( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bearishOrderBlocks); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bearishOrderBlocks // + ); + result = ArraySize(bearishOrderBlocks); + + // + return result; + } + + /** + * Fill Bullish FVGs ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBullishFVGs( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bullishFVGs); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bullishFVGs // + ); + result = ArraySize(bullishFVGs); + + // + return result; + } + + /** + * Fill Bearish FVGs ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBearishFVGs( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bearishFVGs); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bearishFVGs // + ); + result = ArraySize(bearishFVGs); + + // + return result; + } + + // +}; diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index e4305224..3ca2fae4 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -33,7 +33,9 @@ enum ENUM_X_PRICE X_PRICE_HIGH, X_PRICE_OPEN, X_PRICE_CLOSE, - X_PRICE_LOW + X_PRICE_LOW, + X_PRICE_UP, + X_PRICE_DOWN }; // @@ -788,6 +790,14 @@ struct XOHCL case X_PRICE_LOW: result = low; break; + // + case X_PRICE_UP: + result = GetUp(); + break; + // + case X_PRICE_DOWN: + result = GetDown(); + break; } // @@ -5015,7 +5025,7 @@ struct XOHCL // // Other ... - string GetTag(string prefix) + string GetTag(string prefix = "") { // string result = NULL; @@ -5047,6 +5057,7 @@ struct XOHCL } }; +// struct XTrend { // @@ -13234,6 +13245,17 @@ bool IsBullish(ENUM_X_DIRECTION value) // return result; } +bool IsSpecifiedBullish(ENUM_X_DIRECTION value) +{ + // + bool result = false; + + // + result = value == X_DIRECTION_BULLISH; + + // + return result; +} // bool IsBearish(ENUM_X_DIRECTION value) @@ -13247,5 +13269,16 @@ bool IsBearish(ENUM_X_DIRECTION value) // return result; } +bool IsSpecifiedBearish(ENUM_X_DIRECTION value) +{ + // + bool result = false; + + // + result = value == X_DIRECTION_BEARISH; + + // + return result; +} // \ No newline at end of file diff --git a/Libraries/x-saherelm.draw.lib.mq5 b/Libraries/x-saherelm.draw.lib.mq5 deleted file mode 100644 index aeb124ee..00000000 --- a/Libraries/x-saherelm.draw.lib.mq5 +++ /dev/null @@ -1,2620 +0,0 @@ -/////////////////////////////////////////////////////// -// -// 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/Libraries/x-saherelm.tools.lib.mq5 b/Libraries/x-saherelm.tools.lib.mq5 deleted file mode 100644 index f61a5a24..00000000 --- a/Libraries/x-saherelm.tools.lib.mq5 +++ /dev/null @@ -1,2193 +0,0 @@ -/////////////////////////////////////////////////////// -// -// 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/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 07be190c..284bd0dc 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -21,7 +21,7 @@ // // Imports ... -#include "../Libraries/x-saherelm.common.lib.mq5" +#include "../Classes/x-saherelm.base.class.mq5" // // Definitions ... @@ -33,6 +33,8 @@ // All Available POI(s) ... enum ENUM_XPOIS { + // + X_POI_NONE, // // Trading Day ... X_POI_TRADING_DAY, // Trading Day ... @@ -118,102 +120,693 @@ enum ENUM_XSESSION X_FRANKFORT, }; -enum ENUM_X_ZONE_EDGE -{ - X_ZONE_UPPER_EDGE, - X_ZONE_LOWER_EDGE -}; +// +// Implementation ... // -// Represent a Session Working Time ... -struct XSession +// Base POI Model Class ... +class XCBasePOI : public XSCBase { // - // Props ... - ENUM_XSESSION session; // Session Identifier - string start; // Start Time - string end; // End Time + public: + // // - bool allowDraw; - color startColor; - ENUM_LINE_STYLE startStyle; - color endColor; - ENUM_LINE_STYLE endStyle; + // Constructor ... + void XCBasePOI() + { + // + Clean(); - /** - * Constructor ... - */ - void XSession() + // + mSep = "_"; + mLineSep = "\n"; + } + + // + // Deconstructor ... + void ~XCBasePOI() { Clean(); } - /** - * Clean Structure ... - */ - void Clean() - { - // - start = NULL; - end = NULL; + // + // Virtual ... - // - allowDraw = false; - endColor = clrAqua; - endStyle = STYLE_DOT; - startColor = clrAqua; - endStyle = STYLE_DOT; + /** + * Cleanup ... + */ + virtual void Clean() + { + mType = X_POI_NONE; } /** - * Validate Structure ... + * Validate ... + * + * @return ( virtual bool ) + */ + virtual bool IsValid() + { + return false; + } + + /** + * Retrieve POI Type ... + * + * @return ( virtual ENUM_XPOIS member ) + */ + virtual ENUM_XPOIS Type() + { + return mType; + } + + /** + * Retrieve POI Type ... + * + * @return ( virtual string ) + */ + virtual string TypeAsString() + { + return ToString(mType); + } + + /** + * Retrieve POI Tag ... + * + * @return ( virtual string ) + */ + virtual string GetTag() + { + return NULL; + } + + /** + * Retrieve POI Tooltip ... + * + * @return ( virtual string ) + */ + virtual string GetTooltip() + { + return NULL; + } + + // + protected: + // + // Props ... + string mSep; // Separator ... + string mLineSep; // Line Separator ... + ENUM_XPOIS mType; // Type ... + + // + private: + // +}; + +// +// Zone POI Class ... +class XCZone : public XCBasePOI +{ + // + public: + // + + // + // Constructor ... + void XCZone() + { + } + + // + // Deconstructor ... + void ~XCZone() + { + } + + // + // Tools ... + + // + // Getter(s) / Setter(s) ... + + /** + * Get Zone Upper Boundary ... + * + * @return ( double ) + */ + double Upper() + { + return mUpper; + } + + /** + * Get Zone Lower Boundary ... + * + * @return ( double ) + */ + double Lower() + { + return mLower; + } + + // + // Virtuals ... + + /** + * Get Zone Start Date ... + * + * @return ( virtual datetime ) + */ + virtual datetime From() + { + return NULL; + } + + /** + * Get Zone End Date ... + * + * @return ( virtual datetime ) + */ + virtual datetime To() + { + return NULL; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + // + protected: + // + // Props ... + double mUpper; // Zone Upper ... + double mLower; // Zone Lower ... + + /** + * Validate Upper and Lower of Zone ... * * @return ( bool ) */ - bool IsValid() + bool IsValidBoundary() { // bool result = false; // - result = IsValid(start) && - IsValid(end); + result = + // + mUpper > 0 && + mLower > 0 && + mUpper > mLower + // + ; // return result; } /** - * Initialize Specified Session ... - * - * @param _session: ENUM_XSESSION member ... - * @param _start: String (Session Start Time) ... - * @param _end: String (Session End Time) ... + * Check From Date of Zone is Valid ... * * @return ( bool ) */ - bool Init( - ENUM_XSESSION _session, - string _start, - string _end // + bool IsValidFrom() + { + return IsSpecifiedValid(From()); + } + + // + private: + // + // Props ... + + // +}; + +// +// Bar Zone ... +class XCBarZone : public XCZone +{ + // + public: + // + + // + // Constructor ... + void XCBarZone() + { + } + + // + // Deconstructor ... + void ~XCBarZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param type: ENUM_XPOIS member ... + * @param upperPrice: ENUM_X_PRICE member ... + * @param lowerPrice: ENUM_X_PRICE member ... + * + * @return ( bool ) + */ + bool InitBarZone( + XOHCL &bar, + ENUM_XPOIS type, + ENUM_X_PRICE upperPrice, + ENUM_X_PRICE lowerPrice // ) { // bool result = false; // - result = IsValid(_start) && - IsValid(_end); + result = bar.IsValid() && + type != X_POI_NONE && + upperPrice != lowerPrice; if (!result) { return result; } // - end = _end; - start = _start; - session = _session; + mBar = bar; + mType = type; + mUpperPrice = upperPrice; + mLowerPrice = lowerPrice; + mUpper = bar.GetPrice(upperPrice); + mLower = bar.GetPrice(lowerPrice); + + // + result = IsValidBarZone(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + void Clean() override + { + // + mBar.Clean(); + mUpper = 0; + mLower = 0; + mType = X_POI_NONE; + } + + datetime From() override + { + // + datetime result = NULL; + + // + if (!IsValidBarZone()) + { + return result; + } + + // + result = mBar.time; + + // + return result; + } + + datetime To() override + { + // + datetime result = NULL; + + // + if (!IsValidBarZone()) + { + return result; + } + + // + result = TimeCurrent(); + + // + return result; + } + + string GetTag() override + { + // + string result = NULL; + + // + if (!IsValidBarZone()) + { + return result; + } + + // + string hash = ToMD5(mBar.GetTag()); + + // + result = + // + TypeAsString() + mSep + + ToString(mBar.period) + mSep + + hash + // + ; + + // + return result; + } + + string GetTooltip() override + { + // + string result = NULL; + + // + if (!IsValidBarZone()) + { + return result; + } + + // + return result; + } + + // + protected: + // + // Props ... + XOHCL mBar; // Bar ... + ENUM_X_PRICE mUpperPrice; // Upper Price Selection + ENUM_X_PRICE mLowerPrice; // Lower Price Selection + + /** + * Check Bar Zone Validation ... + * + * @return ( bool ) + */ + bool IsValidBarZone() + { + // + bool result = false; + + // + result = mBar.IsValid() && + mType != X_POI_NONE && + IsValidBoundary(); + + // + return result; + } + + // + private: + // + // Props ... + + // +}; +class XCTwoBarZone : public XCZone +{ + // + public: + // + + // + // Constructor ... + void XCTwoBarZone() + { + } + + // + // Deconstructor ... + void ~XCTwoBarZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param type: ENUM_XPOIS member ... + * @param upperPrice: ENUM_X_PRICE member ... + * @param lowerPrice: ENUM_X_PRICE member ... + * + * @return ( bool ) + */ + bool InitTwoBarZone( + XOHCL &startBar, + XOHCL &endBar, + ENUM_XPOIS type, + bool useStartBarForUpper, + ENUM_X_PRICE upperPrice, + ENUM_X_PRICE lowerPrice // + ) + { + // + bool result = false; + + // + result = startBar.IsValid() && + endBar.IsValid() && + startBar.symbol == endBar.symbol && + startBar.period == endBar.period && + startBar.time < endBar.time && + type != X_POI_NONE; + if (!result) + { + return result; + } + + // + mType = type; + mEndBar = endBar; + mStartBar = startBar; + mUpperPrice = upperPrice; + mLowerPrice = lowerPrice; + mUseStartBarForUpper = useStartBarForUpper; + + mUpper = + useStartBarForUpper + ? startBar.GetPrice(upperPrice) + : endBar.GetPrice(upperPrice); + mLower = + useStartBarForUpper + ? endBar.GetPrice(lowerPrice) + : startBar.GetPrice(lowerPrice); + + // + result = IsValidTwoBarZone(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + void Clean() override + { + // + mStartBar.Clean(); + mEndBar.Clean(); + mUpper = 0; + mLower = 0; + mUseStartBarForUpper = false; + mType = X_POI_NONE; + } + + datetime From() override + { + // + datetime result = NULL; + + // + if (!IsValidTwoBarZone()) + { + return result; + } + + // + result = mStartBar.time; + + // + return result; + } + + datetime To() override + { + // + datetime result = NULL; + + // + if (!IsValidTwoBarZone()) + { + return result; + } + + // + result = TimeCurrent(); + + // + return result; + } + + string GetTag() override + { + // + string result = NULL; + + // + if (!IsValidTwoBarZone()) + { + return result; + } + + // + string hash = ToMD5(mStartBar.GetTag() + mSep + mEndBar.GetTag()); + + // + result = + // + TypeAsString() + mSep + + ToString(mStartBar.period) + mSep + + hash + // + ; + + // + return result; + } + + string GetTooltip() override + { + // + string result = NULL; + + // + if (!IsValidTwoBarZone()) + { + return result; + } + + // + return result; + } + + // + protected: + // + // Props ... + XOHCL mStartBar; // Start (Oldest) Bar ... + XOHCL mEndBar; // End (Newest) Bar ... + bool mUseStartBarForUpper; // Use Start Bar for Upper Calculation ... + ENUM_X_PRICE mUpperPrice; // Upper Price Selection + ENUM_X_PRICE mLowerPrice; // Lower Price Selection + + /** + * Check Two Bar Zone Validation ... + * + * @return ( bool ) + */ + bool IsValidTwoBarZone() + { + // + bool result = false; + + // + result = mStartBar.IsValid() && + mEndBar.IsValid() && + mStartBar.symbol == mEndBar.symbol && + mStartBar.period == mEndBar.period && + mStartBar.time < mEndBar.time && + mType != X_POI_NONE && + IsValidBoundary(); + + // + return result; + } + + // + private: + // + // Props ... + + // +}; + +// +// Swing Class ... +class XCSwing : public XCBasePOI +{ + // + public: + // + + // + // Constructor ... + void XCSwing() + { + } + + // + // Deconstructor ... + void ~XCSwing() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param type: ENUM_XPOIS member ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + ENUM_XPOIS type // + ) + { + // + bool result = false; + + // + result = bar.IsValid() && + (type == X_POI_SWING_HIGH || + type == X_POI_SWING_LOW); + if (!result) + { + return result; + } + + // + mBar = bar; + mType = type; // result = IsValid(); @@ -223,180 +816,190 @@ struct XSession } // -}; + // Getter(s) / Setter(s) ... -// -struct XTradeDay -{ - // - datetime from; - datetime to; - - // - void XTradeDay() - { - Clean(); - } - - // - void Clean() - { - // - from = NULL; - to = NULL; - } - - // - bool IsValid() + /** + * Check Swing High or not ... + * + * @return ( bool ) + */ + bool IsSwingHigh() { // bool result = false; // - result = IsValid(from) && - IsValid(to); - - // - return result; - } - - // - string GetTag() - { - // - string result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - result = ToString(X_POI_TRADING_DAY) + "_" + ToFormatString(from) + "_" + ToFormatString(to); - - // - return result; - } - - // -}; - -// -// Detected Session ... -struct XMarketSession -{ - // - ENUM_XSESSION session; - datetime from; - datetime to; - - // - void XMarketSession() - { - Clean(); - } - - // - void Clean() - { - from = NULL; - to = NULL; - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = IsValid(from) && - IsValid(to); - - // - return result; - } - - // - string GetTag() - { - // - string result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - result = - ToString(X_POI_MARKET_SESSION) + "_" + - ToString(session) + "_" + - ToFormatString(from) + - "_" + - ToFormatString(to) + "_"; - - // - return result; - } -}; - -// -// Zone Struct ... -struct XZone -{ - // - // Props ... - double upper; - double lower; - string prefix; - - // - datetime from; - datetime to; - - // - // Constructor ... - void XZone() - { - Clean(); - } - - // - bool Init( - double _upper, - double _lower, - string _prefix, - datetime _from, - datetime _to // - ) - { - // - bool result = false; - - // - result = - _upper > 0 && - _lower > 0 && - _upper > _lower && - IsValid(_prefix) && - IsValid(_from); + result = IsValid(); if (!result) { return result; } // - NormalizeTime(_to); + result = + Type() == X_POI_SWING_HIGH; // - upper = _upper; - lower = _lower; - prefix = _prefix; - from = _from; - to = _to; + return result; + } + + /** + * Check Swing Low or not ... + * + * @return ( bool ) + */ + bool IsSwingLow() + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + Type() == X_POI_SWING_LOW; + + // + return result; + } + + // + // Overrides ... + + void Clean() override + { + // + mBar.Clean(); + mType = X_POI_NONE; + } + + bool IsValid() override + { + // + bool result = false; + + // + result = mBar.IsValid() && + (mType == X_POI_SWING_HIGH || + mType == X_POI_SWING_LOW); + + // + return result; + } + + string GetTag() override + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + string hash = ToMD5(mBar.GetTag()); + + // + result = + // + TypeAsString() + mSep + + ToString(mBar.period) + mSep + + hash + // + ; + + // + return result; + } + + string GetTooltip() override + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + return result; + } + + // + protected: + // + // Props ... + XOHCL mBar; // Swing Bar ... + + // + private: + // +}; + +// +// Supply Zone ... +class XCSupplyZone : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCSupplyZone() + { + } + + // + // Deconstructor ... + void ~XCSupplyZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_SUPPLY_ZONE, + X_PRICE_HIGH, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } // result = IsValid(); @@ -406,767 +1009,905 @@ struct XZone } // - void Clean() - { - // - upper = 0; - lower = 0; - - // - to = NULL; - from = NULL; - prefix = NULL; - } + // Getter(s) / Setter(s) ... // - bool IsValid() + // Overrides ... + + bool IsValid() override { // bool result = false; // - result = upper > 0 && - lower > 0 && - upper > lower && - IsValid(to) && - IsValid(from) && - IsValid(prefix); + result = IsValidBarZone() && + mType == X_POI_SUPPLY_ZONE; // return result; } // - double GetRange() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = upper - lower; - - // - return result; - } + protected: + // // - double GetMiddle() - { - // - double result = 0; - - // - double range = GetRange(); - if (range <= 0) - { - return result; - } - - // - result = lower + (range / 2); - - // - return result; - } + private: + // // - string GetTag() - { - // - string result = NULL; - - // - result = prefix + "_" + - ToString(upper) + "_" + - ToString(lower); - - // - return result; - } }; // -// XOHCL Event Handler ... -typedef void (*TXOHCLEventHandler)( - ENUM_XPOI_EVENTS event, - XOHCL &bar // -); - -// -// POI Event Handler ... -typedef void (*TXPOIEventHandler)( - ENUM_XPOI_EVENTS event // -); - -// -// Session Event Handler ... -typedef void (*TXSessionEventHandler)( - ENUM_XSESSION session, - ENUM_XPOI_EVENTS event // -); - -// -// Zone Handler ... -typedef void (*TXZoneEventHandler)( - ENUM_XPOI_EVENTS event, - XZone &zone // -); - -// -// Model Exists Founded POIs ... -struct XPOIState +// Demand Zone ... +class XCDemandZone : public XCBarZone { // - string symbol; - ENUM_TIMEFRAMES period; - datetime reportedAt; - + public: // - XTradeDay tradingDays[]; - XMarketSession marketSessions[]; - - // - XOHCL momentumBars[]; - XOHCL rejectionBars[]; - - // - XOHCL swingHighs[]; - XOHCL swingLows[]; - - // - XOHCL supportZones[]; - XOHCL resistanceZones[]; - - // - XZone supplyZones[]; - XZone demandZones[]; - - // - XZone bullishOrderBlocks[]; - XZone bearishOrderBlocks[]; - - // - XZone bullishFVGs[]; - XZone bearishFVGs[]; // // Constructor ... - void XPOIState() + void XCDemandZone() { - Clean(); } // - // Actions ... - - /** - * Cleanup all props ... - */ - void Clean() + // Deconstructor ... + void ~XCDemandZone() { - // - symbol = NULL; - period = NULL; - reportedAt = NULL; - - // - Clean(tradingDays); - Clean(marketSessions); - - // - Clean(momentumBars); - Clean(rejectionBars); - - // - Clean(swingHighs); - Clean(swingLows); - - // - Clean(supportZones); - Clean(resistanceZones); - - // - Clean(supplyZones); - Clean(demandZones); - - // - Clean(bullishOrderBlocks); - Clean(bearishOrderBlocks); - - // - Clean(bullishFVGs); - Clean(bearishFVGs); } + // + // Tools ... + /** - * Fill Trading Days ... + * Initialize POI ... * - * @param source: XTradeDay instance Collection ... - * @param forceClean: Boolean ... + * @param bar: XOHCL instance ... * - * @return ( int ) + * @return ( bool ) */ - int FillTradingDays( - XTradeDay &source[], - bool forceClean = true // + bool Init( + XOHCL &bar // ) { // - int result = 0; + bool result = false; // - if (forceClean) - { - Clean(tradingDays); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) + result = bar.IsValid(); + if (!result) { return result; } // - Copy( - source, - tradingDays // + result = InitBarZone( + bar, + X_POI_DEMAND_ZONE, + X_PRICE_HIGH, + X_PRICE_LOW // ); - result = ArraySize(tradingDays); - - // - return result; - } - - /** - * Fill Market Sessions ... - * - * @param source: XMarketSession instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillMarketSessions( - XMarketSession &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(marketSessions); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) + if (!result) { return result; } // - Copy( - source, - marketSessions // - ); - result = ArraySize(marketSessions); + result = IsValid(); // return result; } - /** - * Fill Momentum Bars ... - * - * @param source: XOHCL instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillMomentumBars( - XOHCL &source[], - bool forceClean = true // - ) + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + bool IsValid() override { // - int result = 0; + bool result = false; // - if (forceClean) - { - Clean(momentumBars); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - momentumBars // - ); - result = ArraySize(momentumBars); + result = IsValidBarZone() && + mType == X_POI_DEMAND_ZONE; // return result; } - /** - * Fill Retection Bars ... - * - * @param source: XOHCL instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillRejectionBars( - XOHCL &source[], - bool forceClean = true // - ) - { - // - int result = 0; + // + protected: + // - // - if (forceClean) - { - Clean(rejectionBars); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - rejectionBars // - ); - result = ArraySize(rejectionBars); - - // - return result; - } - - /** - * Fill Swing Highs ... - * - * @param source: XOHCL instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillSwingHighs( - XOHCL &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(swingHighs); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - swingHighs // - ); - result = ArraySize(swingHighs); - - // - return result; - } - - /** - * Fill Swing Lows ... - * - * @param source: XOHCL instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillSwingLows( - XOHCL &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(swingLows); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - swingLows // - ); - result = ArraySize(swingLows); - - // - return result; - } - - /** - * Fill Support Zones ... - * - * @param source: XOHCL instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillSupportZones( - XOHCL &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(supportZones); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - supportZones // - ); - result = ArraySize(supportZones); - - // - return result; - } - - /** - * Fill Resistance Zones ... - * - * @param source: XOHCL instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillResistanceZones( - XOHCL &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(resistanceZones); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - resistanceZones // - ); - result = ArraySize(resistanceZones); - - // - return result; - } - - /** - * Fill Supply Zones ... - * - * @param source: XZone instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillSupplyZones( - XZone &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(supplyZones); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - supplyZones // - ); - result = ArraySize(supplyZones); - - // - return result; - } - - /** - * Fill Demand Zones ... - * - * @param source: XZone instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillDemandZones( - XZone &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(demandZones); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - demandZones // - ); - result = ArraySize(demandZones); - - // - return result; - } - - /** - * Fill Bullish Order Blockss ... - * - * @param source: XZone instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillBullishOrderBlocks( - XZone &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(bullishOrderBlocks); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - bullishOrderBlocks // - ); - result = ArraySize(bullishOrderBlocks); - - // - return result; - } - - /** - * Fill Bearish Order Blockss ... - * - * @param source: XZone instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillBearishOrderBlocks( - XZone &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(bearishOrderBlocks); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - bearishOrderBlocks // - ); - result = ArraySize(bearishOrderBlocks); - - // - return result; - } - - /** - * Fill Bullish FVGs ... - * - * @param source: XZone instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillBullishFVGs( - XZone &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(bullishFVGs); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - bullishFVGs // - ); - result = ArraySize(bullishFVGs); - - // - return result; - } - - /** - * Fill Bearish FVGs ... - * - * @param source: XZone instance Collection ... - * @param forceClean: Boolean ... - * - * @return ( int ) - */ - int FillBearishFVGs( - XZone &source[], - bool forceClean = true // - ) - { - // - int result = 0; - - // - if (forceClean) - { - Clean(bearishFVGs); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - Copy( - source, - bearishFVGs // - ); - result = ArraySize(bearishFVGs); - - // - return result; - } + // + private: + // // }; +// +// Support Zone ... +class XCSupportZone : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCSupportZone() + { + } + + // + // Deconstructor ... + void ~XCSupportZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_SUPPORT_ZONE, + X_PRICE_DOWN, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_SUPPORT_ZONE; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Resistance Zone ... +class XCResistanceZone : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCResistanceZone() + { + } + + // + // Deconstructor ... + void ~XCResistanceZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_RESISTANCE_ZONE, + X_PRICE_HIGH, + X_PRICE_UP // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_RESISTANCE_ZONE; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Order Block ... +class XCOrderBlock : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCOrderBlock() + { + } + + // + // Deconstructor ... + void ~XCOrderBlock() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param dir: ENUM_X_DIRECTION member ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + ENUM_X_DIRECTION dir // + ) + { + // + bool result = false; + + // + result = bar.IsValid() && + (dir == X_DIRECTION_BULLISH || + dir == X_DIRECTION_BEARISH); + if (!result) + { + return result; + } + + // + ENUM_XPOIS mTT = + IsSpecifiedBullish(dir) + ? X_POI_BULLISH_ORDERBLOCK + : X_POI_BEARISH_ORDERBLOCK; + + // + result = InitBarZone( + bar, + mTT, + X_PRICE_HIGH, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BULLISH_ORDERBLOCK; + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BEARISH_ORDERBLOCK; + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + (mType == X_POI_BULLISH_ORDERBLOCK || + mType == X_POI_BEARISH_ORDERBLOCK); + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Rejection Bar ... +class XCRejectionBar : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCRejectionBar() + { + } + + // + // Deconstructor ... + void ~XCRejectionBar() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = + bar.GetLowShadow() > bar.GetHighShadow(); + bool isBearish = + bar.GetHighShadow() > bar.GetLowShadow(); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + ENUM_X_PRICE upPrice = isBullish + ? X_PRICE_HIGH + : X_PRICE_DOWN; + // + ENUM_X_PRICE loPrice = isBullish + ? X_PRICE_UP + : X_PRICE_LOW; + + // + result = InitBarZone( + bar, + X_POI_REJECTION_BAR, + upPrice, + loPrice // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_REJECTION_BAR && + mBar.GetLowShadow() > mBar.GetHighShadow(); + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_REJECTION_BAR && + mBar.GetHighShadow() > mBar.GetLowShadow(); + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_REJECTION_BAR; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Momentum Bar ... +class XMomentumBar : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XMomentumBar() + { + } + + // + // Deconstructor ... + void ~XMomentumBar() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = bar.IsBullish(); + bool isBearish = bar.IsBearish(); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_MOMENTUM_BAR, + X_PRICE_HIGH, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + mBar.IsBullish() && + Type() == X_POI_MOMENTUM_BAR; + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + mBar.IsBearish() && + Type() == X_POI_MOMENTUM_BAR; + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_MOMENTUM_BAR; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Fair Value Gap ... +class XCFVG : public XCTwoBarZone +{ + // + public: + // + + // + // Constructor ... + void XCFVG() + { + } + + // + // Deconstructor ... + void ~XCFVG() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param dir: ENUM_X_DIRECTION member ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &startBar, + XOHCL &endBar, + ENUM_X_DIRECTION dir // + ) + { + // + bool result = false; + + // + result = endBar.IsValid() && + startBar.IsValid() && + (dir == X_DIRECTION_BULLISH || + dir == X_DIRECTION_BEARISH); + if (!result) + { + return result; + } + + // + bool isDirBullish = IsSpecifiedBullish(dir); + ENUM_XPOIS mTT = + isDirBullish + ? X_POI_BULLISH_FVG + : X_POI_BEARISH_FVG; + + // + bool useFistForUpper = isDirBullish + ? false + : true; + ENUM_X_PRICE upPrice = isDirBullish + ? X_PRICE_LOW + : X_PRICE_HIGH; + ENUM_X_PRICE loPrice = isDirBullish + ? X_PRICE_HIGH + : X_PRICE_LOW; + + // + result = InitTwoBarZone( + firstBar, + endBar, + mTT, + useFistForUpper, + upPrice, + loPrice // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BULLISH_ORDERBLOCK; + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BEARISH_ORDERBLOCK; + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + (mType == X_POI_BULLISH_ORDERBLOCK || + mType == X_POI_BEARISH_ORDERBLOCK); + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// + // // Extensions ... @@ -1405,908 +2146,4 @@ string ToString(ENUM_XPOI_EVENTS value) return result; } -// -// XOHCL Extensions ... - -/** - * Check two Bar is Same or not ... - * - * @param source: XOHCL instance ... - * @param dest: XOHCL instance ... - * @param force: Check also it's Dates ... - * - * @return ( bool ) - */ -bool IsSame( - XOHCL &source, - XOHCL &dest // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - dest.IsValid(); - if (!result) - { - return result; - } - - // - result = - source.open == dest.open && - source.close == dest.close && - source.high == dest.high && - source.low == dest.low; - if (!result) - { - return result; - } - - // - return result; -} - -/** - * Find Specific Items Index inside a Collection ... - * - * @param source: XOHCL instance ... - * @param dest: XOHCL instance Collection ... - * - * @return ( int ) - */ -int FindIndex( - XOHCL &source, - XOHCL &dest[] // -) -{ - // - int result = -1; - - // - if (!source.IsValid()) - { - return result; - } - - // - int count = ArraySize(dest); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iBar = dest[i]; - - // - bool isSame = IsSame( - source, - iBar // - ); - if (isSame) - { - // - result = i; - break; - } - } - - // - return result; -} - -/** - * Add Specific Bar to List only if Not Exists ... - * - * @param source: XOHCL instance ... - * @param dest: XOHCL instance Collection ... - * - * @return ( bool ) - */ -bool AddIfNotExists( - XOHCL &source, - XOHCL &dest[] // -) -{ - // - bool result = false; - - // - result = source.IsValid(); - if (!result) - { - return result; - } - - // - int idx = FindIndex(source, dest); - bool isExists = IsValidIndex(idx); - if (!isExists) - { - // - AddRef( - source, - dest // - ); - - // - result = isExists; - } - - // - return result; -} - -// -// XZone Extensions ... - -/** - * Check two Zone is Same or not ... - * - * @param source: XZone instance ... - * @param dest: XZone instance ... - * @param force: Check also it's Dates ... - * - * @return ( bool ) - */ -bool IsSame( - XZone &source, - XZone &dest, - bool force = false // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - dest.IsValid(); - if (!result) - { - return result; - } - - // - result = - source.upper == dest.upper && - source.lower == dest.lower; - if (!result) - { - return result; - } - - // - if (force) - { - // - result = - source.from == dest.from && - source.to == dest.to; - } - - // - return result; -} - -/** - * Find Specific Items Index inside a Collection ... - * - * @param source: XZone instance ... - * @param dest: XZone instance Collection ... - * - * @return ( int ) - */ -int FindIndex( - XZone &source, - XZone &dest[] // -) -{ - // - int result = -1; - - // - if (!source.IsValid()) - { - return result; - } - - // - int count = ArraySize(dest); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iZone = dest[i]; - - // - bool isSame = IsSame( - source, - iZone // - ); - if (isSame) - { - // - result = i; - break; - } - } - - // - return result; -} - -/** - * Add Specific Zone to List only if Not Exists ... - * - * @param source: XZone instance ... - * @param dest: XZone instance Collection ... - * - * @return ( bool ) - */ -bool AddIfNotExists( - XZone &source, - XZone &dest[] // -) -{ - // - bool result = false; - - // - result = source.IsValid(); - if (!result) - { - return result; - } - - // - int idx = FindIndex(source, dest); - bool isExists = IsValidIndex(idx); - if (!isExists) - { - // - AddRef( - source, - dest // - ); - - // - result = isExists; - } - - // - return result; -} - -// - -/** - * Check if a Zone inside another one ... - * - * @param source: XZone instance ... - * @param dest: XZone instance ... - * @param edge: ENUM_X_ZONE_EDGE member, define inside edge of zone ... - * @param forceInside: Boolean, if set true means all edges of source must be inside dest ... - * - * @return ( bool ) - */ -bool IsInside( - XZone &source, - XZone &dest, - ENUM_X_ZONE_EDGE edge, - bool forceInside = true // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - dest.IsValid(); - if (!result) - { - return result; - } - - // - bool isEdgePassed = - // - edge == X_ZONE_UPPER_EDGE - ? source.upper <= dest.upper - : source.lower >= dest.lower - // - ; - - // - bool isForcePassed = - // - forceInside - ? edge == X_ZONE_UPPER_EDGE - ? source.lower >= dest.lower - : source.upper <= dest.upper - : edge == X_ZONE_UPPER_EDGE - ? true - : true - // - ; - - // - result = isEdgePassed && - isForcePassed; - - // - return result; -} -bool IsInside( - XOHCL &source, - XZone &dest, - ENUM_X_ZONE_EDGE edge, - bool forceInside = true // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - dest.IsValid(); - if (!result) - { - return result; - } - - // - XZone iSource; - double upper = - edge == X_ZONE_UPPER_EDGE - ? source.high - : source.GetUp(); - double lower = - edge == X_ZONE_UPPER_EDGE - ? source.GetDown() - : source.low; - - result = iSource.Init( - upper, - lower, - "XOHCL", - source.time, - TimeCurrent() // - ); - if (!result) - { - return result; - } - - // - result = IsInside( - iSource, - dest, - edge, - forceInside // - ); - - // - return result; -} - -/** - * Check a Zone is Between to other Zones ... - * - * @param source: XZone instance ... - * @param upper: XZone instance ... - * @param lower: XZone instance ... - * - * @return ( bool ) - */ -bool IsBetween( - XZone &source, - XZone &upper, - XZone &lower // -) -{ - // - bool result = false; - - // - result = source.IsValid(); - if (!result) - { - return result; - } - - // - bool isUpperValid = upper.IsValid(); - bool isLowerValid = lower.IsValid(); - - // - result = isUpperValid || - isLowerValid; - if (!result) - { - return result; - } - - // - if (isUpperValid) - { - // - result = source.upper < upper.lower; - if (!result) - { - return result; - } - } - - // - if (isLowerValid) - { - // - result = source.lower > lower.upper; - if (!result) - { - return result; - } - } - - // - return result; -} -bool IsBetween( - XOHCL &source, - XZone &upper, - XZone &lower // -) -{ - // - bool result = false; - - // - result = source.IsValid(); - if (!result) - { - return result; - } - - // - bool isUpperValid = upper.IsValid(); - bool isLowerValid = lower.IsValid(); - - // - result = isUpperValid || - isLowerValid; - if (!result) - { - return result; - } - - // - if (isUpperValid) - { - // - result = source.high < upper.lower; - if (!result) - { - return result; - } - } - - // - if (isLowerValid) - { - // - result = source.low > lower.upper; - if (!result) - { - return result; - } - } - - // - return result; -} - -/** - * Check Zone for Refining ... - * - * @param source: XZone instance ... - * @param dest: XZone instance ... - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ -bool CanRefineZone( - XZone &source, - XZone &dest, - XOHCL &bar // -) -{ - // - bool result = false; - - // - result = - // - !dest.IsValid() - ? ( - // - source.lower < bar.low && - source.upper > bar.high - // - ) - : ( - // - dest.lower < bar.low && - dest.upper > bar.high && - source.lower < bar.low && - source.upper > bar.high && - source.GetRange() < dest.GetRange() - // - ) - // - ; - - // - return result; -} - -/** - * Check Source breaked Dest from Upper ... - * - * @param source: XZone instance ... - * @param dest: XZone instance ... - * - * @return ( bool ) - */ -bool IsBreakeUpper( - XZone &source, - XZone &dest // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - dest.IsValid(); - if (!result) - { - return result; - } - - // - result = - // - // Check Boundary ... - source.lower <= dest.upper && - source.lower >= dest.lower && - // - // Check Break ... - source.upper > dest.upper - // - ; - - // - return result; -} - -/** - * Check Source breaked Dest from Lower ... - * - * @param source: XZone instance ... - * @param dest: XZone instance ... - * - * @return ( bool ) - */ -bool IsBreakeLower( - XZone &source, - XZone &dest // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - dest.IsValid(); - if (!result) - { - return result; - } - - // - result = - // - // Check Boundary ... - source.upper <= dest.upper && - source.upper >= dest.lower && - // - // Check Break ... - source.lower < dest.lower - // - ; - - // - return result; -} - -// -// State Extensions ... - -/** - * Normalize and Combine States ... - * - * @param dest: XPOIState instance ...ّ - * @param states: XPOIState instance ...ّ - */ -void CombineStates( - XPOIState &dest, - XPOIState &states[] // -) -{ - // - dest.Clean(); - - // - int count = ArraySize(states); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XPOIState iState = states[i]; - - // - dest.symbol = iState.symbol; - dest.period = - !IsValid(dest.period) || - PeriodSeconds(dest.period) < PeriodSeconds(iState.period) - ? iState.period - : dest.period; - dest.reportedAt = - !IsValid(dest.reportedAt) || - dest.reportedAt > iState.reportedAt - ? iState.reportedAt - : dest.reportedAt; - - // - // Demand ... - int iCount = ArraySize(iState.demandZones); - if (IsValidSize(iCount)) - { - // - Copy( - iState.demandZones, - dest.demandZones, - false // - ); - } - - // - // Supply ... - iCount = ArraySize(iState.supplyZones); - if (IsValidSize(iCount)) - { - // - Copy( - iState.supplyZones, - dest.supplyZones, - false // - ); - } - - // - // Order Blocks ... - - // - iCount = ArraySize(iState.bullishOrderBlocks); - if (IsValidSize(iCount)) - { - // - Copy( - iState.bullishOrderBlocks, - dest.bullishOrderBlocks, - false // - ); - } - - // - iCount = ArraySize(iState.bearishOrderBlocks); - if (IsValidSize(iCount)) - { - // - Copy( - iState.bearishOrderBlocks, - dest.bearishOrderBlocks, - false // - ); - } - - // - // Fair Value Gaps ... - - // - iCount = ArraySize(iState.bullishFVGs); - if (IsValidSize(iCount)) - { - // - Copy( - iState.bullishFVGs, - dest.bullishFVGs, - false // - ); - } - - // - iCount = ArraySize(iState.bearishFVGs); - if (IsValidSize(iCount)) - { - // - Copy( - iState.bearishFVGs, - dest.bearishFVGs, - false // - ); - } - - // - // Supports ... - iCount = ArraySize(iState.supportZones); - if (IsValidSize(iCount)) - { - // - Copy( - iState.supportZones, - dest.supportZones, - false // - ); - } - - // - // Resistances ... - iCount = ArraySize(iState.resistanceZones); - if (IsValidSize(iCount)) - { - // - Copy( - iState.resistanceZones, - dest.resistanceZones, - false // - ); - } - - // - // Swings ... - - // - // Swing Highs ... - iCount = ArraySize(iState.swingHighs); - if (IsValidSize(iCount)) - { - // - Copy( - iState.swingHighs, - dest.swingHighs, - false // - ); - } - - // - // Swing Lows ... - iCount = ArraySize(iState.swingLows); - if (IsValidSize(iCount)) - { - // - Copy( - iState.swingLows, - dest.swingLows, - false // - ); - } - - // - // Momentum Bars ... - iCount = ArraySize(iState.momentumBars); - if (IsValidSize(iCount)) - { - // - Copy( - iState.momentumBars, - dest.momentumBars, - false // - ); - } - - // - // Rejection Bars ... - iCount = ArraySize(iState.rejectionBars); - if (IsValidSize(iCount)) - { - // - Copy( - iState.rejectionBars, - dest.rejectionBars, - false // - ); - } - } -} - -/** - * Check State has Bullish Trend or not ... - * - * @param state: XPOIState instance ... - * - * @return ( bool ) - */ -bool HasBullishTrend(XPOIState &state) -{ - // - bool result = false; - - // - // For Bullish Trends ... - int count = ArraySize(state.swingLows); - result = count >= 2; - if (!result) - { - return result; - } - - // - XOHCL lastSwing = state.swingLows[count - 1]; - XOHCL prevSwing = state.swingLows[count - 2]; - - // - result = lastSwing.low > prevSwing.low; - - // - return result; -} - -/** - * Check State has Bearish Trend or not ... - * - * @param state: XPOIState instance ... - * - * @return ( bool ) - */ -bool HasBearishTrend(XPOIState &state) -{ - // - bool result = false; - - // - // For Bullish Trends ... - int count = ArraySize(state.swingHighs); - result = count >= 2; - if (!result) - { - return result; - } - - // - XOHCL lastSwing = state.swingHighs[count - 1]; - XOHCL prevSwing = state.swingHighs[count - 2]; - - // - result = lastSwing.high < prevSwing.high; - - // - return result; -} - // \ No newline at end of file