diff --git a/Experts/x-test.ea.mq5 b/Experts/x-test.ea.mq5 index 9ab6490b..16e07b2d 100644 --- a/Experts/x-test.ea.mq5 +++ b/Experts/x-test.ea.mq5 @@ -25,6 +25,7 @@ // // Imports ... #include "../Test/x-saherelm.test.xea.mq5" +#include "../Libraries/x-saherelm.tools.mq5" #include "../Helpers/x-saherelm.xct.helper.mq5" #include "../Helpers/x-saherelm.xcc.helper.mq5" @@ -48,6 +49,16 @@ XSCXTestSetup *iSetup; XSCXCTHelper *mCTHelper; XSCXCCHelper *mCCHelper; +// +// For Pivot Checking ... +XPivot lastSupportPivot; +XPivot lastResistancePivot; + +// +// For Zone Checking ... +XZone lastSupportZone; +XZone lastResistanceZone; + // // Event Handlers ... @@ -119,138 +130,12 @@ void OnTick() } // - XTestConditions conditions; - bool hasConditions = iSetup.GetConditions( - conditions, - 0, - 5 // - ); - if (hasConditions) - { - // - bool isCHMAOverUnder1 = - // - (conditions.chmaConditions.isFastOverMin && - conditions.chmaConditions.isFastUnderMin) - // - ; - // - bool isCHMAOverUnder2 = - // - (conditions.chmaConditions.isSlowOverMin && - conditions.chmaConditions.isSlowUnderMin) - // - ; - // - bool isCHMAOverUnder3 = - // - (conditions.chmaConditions.isFastOverMax && - conditions.chmaConditions.isFastUnderMax) - // - ; - // - bool isCHMAOverUnder4 = - // - (conditions.chmaConditions.isSlowOverMax && - conditions.chmaConditions.isSlowUnderMax) - // - ; - // - if (isCHMAOverUnder1 || isCHMAOverUnder2 || isCHMAOverUnder3 || isCHMAOverUnder4) - { - Print("isCHMAOverUnder"); - } - } + // Check Pivots ... + // HandleCheckPivots(); - // // - // XOHCL cBar; - // bool isInit = cBar.Init( - // _Symbol, - // _Period, - // 1 // - // ); - // if (!isInit) - // { - // return; - // } - - // // - // datetime time1 = iTime( - // _Symbol, - // _Period, - // 2 // - // ); - - // // - // double fib382 = 0; - - // // - // bool isHammer = cBar.IsHammer(); - // if (isHammer) - // { - // // - // fib382 = GetFibonacciLevel( - // cBar.high, - // cBar.low, - // 0.382, - // -1 // - // ); - // DrawTrendLine( - // ChartID(), - // "HMR_TR", - // 0, - // time1, - // fib382, - // cBar.time, - // fib382, - // clrYellow // - // ); - // Print("Hammer ..."); - // eaBarTracker.Waits(); - // } - - // // - // bool isShootingStar = cBar.IsShootingStar(); - // if (isShootingStar) - // { - // // - // fib382 = GetFibonacciLevel( - // cBar.high, - // cBar.low, - // 0.382, - // 1 // - // ); - // DrawTrendLine( - // ChartID(), - // "HMR_TR", - // 0, - // time1, - // fib382, - // cBar.time, - // fib382, - // clrYellow // - // ); - // Print("ShootingStar ..."); - // eaBarTracker.Waits(); - // } - - // // - // bool isBullishEngulf = cBar.IsBullishEngulf(); - // if (isBullishEngulf) - // { - // // - // Print("Bullish Engulf ..."); - // eaBarTracker.Waits(); - // } - - // // - // bool isBearishEngulf = cBar.IsBearishEngulf(); - // if (isBearishEngulf) - // { - // // - // Print("Bearish Engulf ..."); - // eaBarTracker.Waits(); - // } + // + // Check Zones ... + HandleCheckZones(); } // @@ -457,18 +342,293 @@ void PreConfigureStyles(XTestInputs &inputs) // // XCHMA ... - inputs.chmaInputs.showFast = true; - inputs.chmaInputs.showSlow = true; - inputs.chmaInputs.showCCFast = true; - inputs.chmaInputs.showCCSlow = true; - inputs.chmaInputs.showSCFast = true; - inputs.chmaInputs.showSCSlow = true; - inputs.chmaInputs.showMCFast = true; - inputs.chmaInputs.showMCSlow = true; - inputs.chmaInputs.showLCFast = true; - inputs.chmaInputs.showLCSlow = true; - inputs.chmaInputs.showHCFast = true; - inputs.chmaInputs.showHCSlow = true; + inputs.chmaInputs.showFast = false; + inputs.chmaInputs.showSlow = false; + inputs.chmaInputs.showCCFast = false; + inputs.chmaInputs.showCCSlow = false; + inputs.chmaInputs.showSCFast = false; + inputs.chmaInputs.showSCSlow = false; + inputs.chmaInputs.showMCFast = false; + inputs.chmaInputs.showMCSlow = false; + inputs.chmaInputs.showLCFast = false; + inputs.chmaInputs.showLCSlow = false; + inputs.chmaInputs.showHCFast = false; + inputs.chmaInputs.showHCSlow = false; +} + +// +// Custom Testing Functions ... + +// +void HandleCheckPivots() +{ + // + XOHCL cBar; + bool isInited = cBar.Init( + _Symbol, + _Period, + 1 // + ); + if (!isInited) + { + return; + } + + // + // Check Resistance ... + if (!lastResistancePivot.isResistance) + { + // + isInited = lastResistancePivot.FindLastResistance( + _Symbol, + _Period // + ); + if (!isInited) + { + // + lastResistancePivot.Clean(); + return; + } + + // + bool isDrawn = lastResistancePivot.Draw(ChartID()); + if (isDrawn) + { + Print("Valid Resistance ..."); + } + } + + // + // Check Support ... + if (!lastSupportPivot.isSupport) + { + // + isInited = lastSupportPivot.FindLastSupport( + _Symbol, + _Period // + ); + if (!isInited) + { + // + lastSupportPivot.Clean(); + return; + } + + // + bool isDrawn = lastSupportPivot.Draw(ChartID()); + if (isDrawn) + { + Print("Valid Support ..."); + } + } + else + { + // + bool isBreaked = lastSupportPivot.IsBreaked(); + bool isRejected = lastSupportPivot.IsRejected(); + + // + if (isBreaked) + { + // + lastSupportPivot.Clean(); + Print("Support Breaked ..."); + } + + // + if (isRejected) + { + // + lastSupportPivot.Clean(); + Print("Support Rejected ..."); + } + } +} + +// +void HandleCheckZones() { + // + bool result = false; + + // + // Find Last Support Zone ... + if (!lastSupportZone.IsValid()) { + // + result = lastSupportZone.FindLastSupportZone( + _Symbol, + _Period // + ); + if (!result) { + return; + } + + // + result = lastSupportZone.Draw(ChartID()); + if (result) { + Print("Valid Support Zone ..."); + } + } else { + + } + + // + // Find Last Resistance Zone ... + if (!lastResistanceZone.IsValid()) { + // + result = lastResistanceZone.FindLastResistanceZone( + _Symbol, + _Period // + ); + if (!result) { + return; + } + + // + result = lastResistanceZone.Draw(ChartID()); + if (result) { + Print("Valid Resistance Zone ..."); + } + } else { + + } +} + +// +void OldTests() +{ + // // + // XTestConditions conditions; + // bool hasConditions = iSetup.GetConditions( + // conditions, + // 0, + // 5 // + // ); + // if (hasConditions) + // { + // // + // bool isCHMAOverUnder1 = + // // + // (conditions.chmaConditions.isFastOverMin && + // conditions.chmaConditions.isFastUnderMin) + // // + // ; + // // + // bool isCHMAOverUnder2 = + // // + // (conditions.chmaConditions.isSlowOverMin && + // conditions.chmaConditions.isSlowUnderMin) + // // + // ; + // // + // bool isCHMAOverUnder3 = + // // + // (conditions.chmaConditions.isFastOverMax && + // conditions.chmaConditions.isFastUnderMax) + // // + // ; + // // + // bool isCHMAOverUnder4 = + // // + // (conditions.chmaConditions.isSlowOverMax && + // conditions.chmaConditions.isSlowUnderMax) + // // + // ; + // // + // if (isCHMAOverUnder1 || isCHMAOverUnder2 || isCHMAOverUnder3 || isCHMAOverUnder4) + // { + // Print("isCHMAOverUnder"); + // } + // } + + // // + // XOHCL cBar; + // bool isInit = cBar.Init( + // _Symbol, + // _Period, + // 1 // + // ); + // if (!isInit) + // { + // return; + // } + + // // + // datetime time1 = iTime( + // _Symbol, + // _Period, + // 2 // + // ); + + // // + // double fib382 = 0; + + // // + // bool isHammer = cBar.IsHammer(); + // if (isHammer) + // { + // // + // fib382 = GetFibonacciLevel( + // cBar.high, + // cBar.low, + // 0.382, + // -1 // + // ); + // DrawTrendLine( + // ChartID(), + // "HMR_TR", + // 0, + // time1, + // fib382, + // cBar.time, + // fib382, + // clrYellow // + // ); + // Print("Hammer ..."); + // eaBarTracker.Waits(); + // } + + // // + // bool isShootingStar = cBar.IsShootingStar(); + // if (isShootingStar) + // { + // // + // fib382 = GetFibonacciLevel( + // cBar.high, + // cBar.low, + // 0.382, + // 1 // + // ); + // DrawTrendLine( + // ChartID(), + // "HMR_TR", + // 0, + // time1, + // fib382, + // cBar.time, + // fib382, + // clrYellow // + // ); + // Print("ShootingStar ..."); + // eaBarTracker.Waits(); + // } + + // // + // bool isBullishEngulf = cBar.IsBullishEngulf(); + // if (isBullishEngulf) + // { + // // + // Print("Bullish Engulf ..."); + // eaBarTracker.Waits(); + // } + + // // + // bool isBearishEngulf = cBar.IsBearishEngulf(); + // if (isBearishEngulf) + // { + // // + // Print("Bearish Engulf ..."); + // eaBarTracker.Waits(); + // } } // \ No newline at end of file diff --git a/Libraries/x-saherelm.draw.lib.mq5 b/Libraries/x-saherelm.draw.lib.mq5 index cf58a7ac..b71f62a6 100644 --- a/Libraries/x-saherelm.draw.lib.mq5 +++ b/Libraries/x-saherelm.draw.lib.mq5 @@ -498,16 +498,19 @@ string FindObjectName( // int objectsCount = ObjectsTotal(chartId, subWindow); - if (objectsCount <= 0) { + if (objectsCount <= 0) + { return result; } // - for (int i = objectsCount - 1; i >= 0; i--) { + for (int i = objectsCount - 1; i >= 0; i--) + { // string iObjectName = ObjectName(chartId, i, subWindow); bool isExists = StringFind(iObjectName, suggest) >= 0; - if (isExists) { + if (isExists) + { // result = iObjectName; break; @@ -1000,7 +1003,16 @@ bool DrawRectangle( // // Create a rectangle by the given coordinates ... - result = ObjectCreate(chartID, name, OBJ_RECTANGLE, subWindow, time1, price1, time2, price2); + result = ObjectCreate( + chartID, + name, + OBJ_RECTANGLE, + subWindow, + time1, + price1, + time2, + price2 // + ); if (!result) { return result; diff --git a/Libraries/x-saherelm.tools.mq5 b/Libraries/x-saherelm.tools.mq5 index f6b69922..0a91ec9a 100644 --- a/Libraries/x-saherelm.tools.mq5 +++ b/Libraries/x-saherelm.tools.mq5 @@ -49,7 +49,11 @@ struct XPivot // bool isSupport; + datetime supportTime; + + // bool isResistance; + datetime resistanceTime; // int _lastCalculatedBar; @@ -68,19 +72,32 @@ struct XPivot string _symbol, ENUM_TIMEFRAMES _period, double _price, - int _supResVerifications = 21 // + int barIndex = 0, + int _supResVerificationsStep = 21 // ) { // bool result = false; + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (_supResVerificationsStep < 0) + { + _supResVerificationsStep = 21; + } + // result = // _price > 0 && IsValid(_symbol) && IsValid(_period) && - IsValidSize(_supResVerifications) + IsValidSize(_supResVerificationsStep) // ; @@ -95,10 +112,12 @@ struct XPivot price = _price; // - _loopbackForSupportAndResistance = _supResVerifications; + _loopbackForSupportAndResistance = _supResVerificationsStep; // - Calculate(); + Calculate( + barIndex // + ); // result = IsValid(); @@ -107,6 +126,350 @@ struct XPivot return result; } + // + // Find Last Support for Market and + // Initialize Pivot Based On it ... + bool FindLastSupport( + string _symbol, + ENUM_TIMEFRAMES _period, + int barIndex = 0, + int _supResVerificationsStep = 21 // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (_supResVerificationsStep < 0) + { + _supResVerificationsStep = 21; + } + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + IsValidSize(_supResVerificationsStep) + // + ; + + if (!result) + { + return result; + } + + // + // Find Resistance ... + + // + // Retrieve Current Bar ... + XOHCL cBar; + result = cBar.Init( + _symbol, + _period, + barIndex // + ); + if (!result) + { + return result; + } + + // + // Calculate Available Bars ... + + // + int bars = iBars( + _symbol, + _period // + ); + int maxAllowedBars = bars - 500; + int currentLength = _supResVerificationsStep; + + // + // Find Highest High ... + for (int i = barIndex; i < maxAllowedBars; i++) + { + // + // Validate and Regenrate Current Length ... + if (i > 1) + { + // + currentLength = _supResVerificationsStep * i; + + // + if (currentLength > maxAllowedBars) + { + currentLength = maxAllowedBars; + } + } + + // + // Clean ... + Clean(); + + // + int llIndex = cBar.FindLowestIndex( + currentLength, + MODE_LOW // + ); + XOHCL llBar; + result = llBar.Init( + _Symbol, + _Period, + llIndex // + ); + if (!result) + { + continue; + } + + // + result = Init( + _symbol, + _period, + llBar.low, + barIndex // + ); + if (!result) + { + // + Clean(); + continue; + } + + // + result = isSupport; + if (result) + { + // + supportTime = llBar.time; + break; + } + } + + // + result = IsValid() && isSupport; + + // + return result; + } + + // + // Find Last Resistance for Market and + // Initialized Pivot Based On it ... + bool FindLastResistance( + string _symbol, + ENUM_TIMEFRAMES _period, + int barIndex = 0, + int _supResVerificationsStep = 21 // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (_supResVerificationsStep < 0) + { + _supResVerificationsStep = 21; + } + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + IsValidSize(_supResVerificationsStep) + // + ; + + if (!result) + { + return result; + } + + // + // Find Resistance ... + + // + // Retrieve Current Bar ... + XOHCL cBar; + result = cBar.Init( + _symbol, + _period, + barIndex // + ); + if (!result) + { + return result; + } + + // + // Calculate Available Bars ... + + // + int bars = iBars( + _symbol, + _period // + ); + int maxAllowedBars = bars - 500; + int currentLength = _supResVerificationsStep; + + // + // Find Highest High ... + for (int i = barIndex; i < maxAllowedBars; i++) + { + // + // Validate and Regenrate Current Length ... + if (i > 1) + { + // + currentLength = _supResVerificationsStep * i; + + // + if (currentLength > maxAllowedBars) + { + currentLength = maxAllowedBars; + } + } + + // + // Clean ... + Clean(); + + // + int hhIndex = cBar.FindHighestIndex( + currentLength, + MODE_HIGH // + ); + XOHCL hhBar; + result = hhBar.Init( + _Symbol, + _Period, + hhIndex // + ); + if (!result) + { + continue; + } + + // + result = Init( + _symbol, + _period, + hhBar.high, + barIndex // + ); + if (!result) + { + // + Clean(); + continue; + } + + // + result = isResistance; + if (result) + { + // + resistanceTime = hhBar.time; + break; + } + } + + // + result = IsValid() && isResistance; + + // + return result; + } + + // + // Check Rejection Based On Pivot Type ... + bool IsRejected() + { + // + bool result = false; + + // + result = + // + IsValid() && + ( + // + isSupport || + isResistance + // + ) + // + ; + if (!result) + { + return result; + } + + // + result = + // + isSupport + ? IsSupportRejected() + : IsResistanceRejected() + // + ; + + // + return result; + } + + // + // Check Breake Based On Pivot Type ... + bool IsBreaked() + { + // + bool result = false; + + // + result = + // + IsValid() && + ( + // + isSupport || + isResistance + // + ) + // + ; + if (!result) + { + return result; + } + + // + result = + // + isSupport + ? IsSupportBreaked() + : IsResistanceBreaked() + // + ; + + // + return result; + } + // // Tools ... @@ -373,9 +736,11 @@ struct XPivot void Clean() { // + time = NULL; symbol = NULL; period = NULL; - time = NULL; + supportTime = NULL; + resistanceTime = NULL; // price = 0; @@ -392,6 +757,9 @@ struct XPivot // isSupport = false; isResistance = false; + + // + _objName = NULL; } // @@ -416,7 +784,10 @@ struct XPivot // // Calculate Required Data ... - void Calculate(int loopback = 288) + void Calculate( + int barIndex, + int loopback = 288 // + ) { // if (isSupport || isResistance) @@ -430,6 +801,9 @@ struct XPivot period // ); + // + loopback += barIndex; + // // Normalizing Loopback ... if (loopback > bars) @@ -454,7 +828,7 @@ struct XPivot bool isInited = pBar.Init( symbol, period, - 1 // + barIndex + 1 // ); if (!isInited) { @@ -648,9 +1022,94 @@ struct XPivot } // - string GetTag() { + string GetTag() + { return "XPivot"; } + + // + // Draw Functions ... + + // + // Last Draw Object Name ... + string _objName; + + // + // Draw ... + bool Draw( + long _chartId, + string _prefix = "", + color _color = clrYellow, + ENUM_LINE_STYLE _style = STYLE_DOT, + bool _ray = true, + int _width = 1, + int _subWindow = 0, + bool forcePrefix = false // + ) + { + // + bool result = false; + + // + if (!isSupport && !isResistance) + { + return result; + } + + // + _objName = (IsValid(_prefix) && forcePrefix) + ? _prefix + : GetTag() + "_" + (IsValid(_prefix) ? _prefix + "_" : "") + ToString(NormalizeDouble(price, 2)); + + // + int timeBarIndex = iBarShift( + symbol, + period, + time, + false // + ); + datetime time1 = + // + isSupport + ? supportTime + : resistanceTime + // + ; + + // + result = DrawTrendLine( + _chartId, + _objName, + _subWindow, + time1, + price, + time, + price, + _color, + _style, + _width, + false, + false, + _ray // + ); + + // + return result; + } + + // + // Remove Draw ... + void Remove() + { + // + if (!IsValid(_objName)) + { + return; + } + + // + RemoveDraws(_objName); + } }; // @@ -692,7 +1151,9 @@ struct XZone string _symbol, ENUM_TIMEFRAMES _period, double _upPrice, - double _downPrice // + double _downPrice, + int barIndex = 0, + int pivotVerificationStep = 21 // ) { // @@ -721,7 +1182,9 @@ struct XZone result = up.Init( symbol, period, - _upPrice // + _upPrice, + barIndex, + pivotVerificationStep // ); if (!result) { @@ -732,7 +1195,9 @@ struct XZone result = down.Init( symbol, period, - _downPrice // + _downPrice, + barIndex, + pivotVerificationStep // ); if (!result) { @@ -752,6 +1217,152 @@ struct XZone return result; } + // + // Find Last Support Zone ... + bool FindLastSupportZone( + string _symbol, + ENUM_TIMEFRAMES _period, + int barIndex = 0, + int pivotVerificationStep = 21 // + ) + { + // + bool result = false; + + // + // Since Support Pivots Used Target Bar's Low price + // Last Resistance Set in Down Line of Zone ... + result = down.FindLastSupport( + _symbol, + _Period, + barIndex, + pivotVerificationStep // + ); + if (!result) + { + return result; + } + + // + // Since Support Pivots Used Target Bar's Low price + // we can Set it's High as Up Zone ... + XOHCL tBar; + result = tBar.Init( + _symbol, + _period, + down.supportTime // + ); + if (!result) + { + return result; + } + + // + // Now we Have Target Bar ... + // Set it's High as Up Line of Zone ... + result = up.Init( + _symbol, + _period, + tBar.high, + barIndex, + pivotVerificationStep // + ); + if (!result) + { + return result; + } + + // + up.supportTime = down.supportTime; + + // + if (result) + { + // + symbol = _symbol; + period = _period; + + // + time = TimeCurrent(); + } + + // + return result; + } + + // + // Find Last Resistance Zone ... + bool FindLastResistanceZone( + string _symbol, + ENUM_TIMEFRAMES _period, + int barIndex = 0, + int pivotVerificationStep = 21 // + ) + { + // + bool result = false; + + // + // Since Resistance Pivots Used Target Bar's High price + // Last Resistance Set in Up Line of Zone ... + result = up.FindLastResistance( + _symbol, + _Period, + barIndex, + pivotVerificationStep // + ); + if (!result) + { + return result; + } + + // + // Since Resistance Pivots Used Target Bar's High price + // we can Set it's Low as Down Zone ... + XOHCL tBar; + result = tBar.Init( + _symbol, + _period, + up.resistanceTime // + ); + if (!result) + { + return result; + } + + // + // Now we Have Target Bar ... + // Set it's Low as Down Line of Zone ... + result = down.Init( + _symbol, + _period, + tBar.low, + barIndex, + pivotVerificationStep // + ); + if (!result) + { + return result; + } + + // + down.resistanceTime = up.resistanceTime; + + // + if (result) + { + // + symbol = _symbol; + period = _period; + + // + time = TimeCurrent(); + } + + // + return result; + } + // // Tools ... @@ -766,10 +1377,6 @@ struct XZone return result; } - // - up.Calculate(); - down.Calculate(); - // if (up.isSupport && down.isSupport) { @@ -806,6 +1413,9 @@ struct XZone // up.Clean(); down.Clean(); + + // + _objName = NULL; } // @@ -828,202 +1438,302 @@ struct XZone // return result; } -}; - -// -// a Range Box Model ... -struct XRBox -{ - // - string symbol; - ENUM_TIMEFRAMES period; // - datetime time; - datetime expiration; - - // - XZone up; // Up Zone ... - XZone down; // Down Zone ... - - // - // Constructor ... - XRBox() + string GetTag() { - Clean(); + return "XZone"; } // - // Initialization ... - bool Init( - string _symbol, - ENUM_TIMEFRAMES _period, - double _upZoneUpperPrice, - double _upZoneLowerPrice, - double _downZoneUpperPrice, - double _downZoneLowerPrice, - datetime _expiration = NULL // + // Draw Functions ... + + // + // Last Draw Object Name ... + string _objName; + + // + // Draw ... + bool Draw( + long _chartId, + string _prefix = "", + color _color = clrYellow, + ENUM_LINE_STYLE _style = STYLE_DOT, + bool _ray = true, + int _width = 1, + int _subWindow = 0 // ) { // bool result = false; + // + ENUM_XZONE_STATE state = GetState(); + // result = // - IsValid(_symbol) && - IsValid(_period) && - _upZoneUpperPrice > 0 && - _upZoneLowerPrice > 0 && - _upZoneLowerPrice < _upZoneUpperPrice && - _downZoneUpperPrice > 0 && - _downZoneLowerPrice > 0 && - _downZoneLowerPrice < _downZoneUpperPrice + IsValid() && + state != XZONE_STATE_INVALID // ; - // if (!result) { return result; } // - result = IsValid(); + _objName = GetTag() + "_" + (IsValid(_prefix) ? _prefix + "_" : "") + ToString(NormalizeDouble(up.price, 2)) + "," + ToString(NormalizeDouble(down.price, 2)); // - if (result) - { + datetime time1 = // - time = TimeCurrent(); - } - - // - return result; - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - time = NULL; - symbol = NULL; - period = NULL; - expiration = NULL; - - // - up.Clean(); - down.Clean(); - } - - // - // Validation ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - IsValid(symbol) && - IsValid(period) && - up.IsValid() && - down.IsValid() + down.isSupport + ? down.supportTime + : down.resistanceTime // ; + // + result = down.Draw( + _chartId, + _objName + "_DOWN", + _color, + _style, + _ray, + _width, + _subWindow, + true // Force PRefix ... + ); + if (!result) { + return result; + } + + // + result = up.Draw( + _chartId, + _objName + "_UP", + _color, + _style, + _ray, + _width, + _subWindow, + true // Force PRefix ... + ); + // return result; } + + // + // Remove Draw ... + void Remove() + { + // + if (!IsValid(_objName)) + { + return; + } + + // + RemoveDraws(_objName); + } }; // -// Detect Trends ... -struct XTrendDetector -{ - // - string symbol; - ENUM_TIMEFRAMES period; +// a Range Box Model ... +// struct XRBox +// { +// // +// string symbol; +// ENUM_TIMEFRAMES period; - // - double higherHighs[]; - datetime higherHighTimes[]; +// // +// datetime time; +// datetime expiration; - // - double higherLows[]; - datetime higherLowTimes[]; +// // +// XZone up; // Up Zone ... +// XZone down; // Down Zone ... - // - double lowerHighs[]; - datetime lowerHighTimes[]; +// // +// // Constructor ... +// XRBox() +// { +// Clean(); +// } - // - double lowerLows[]; - datetime lowerLowTimes[]; +// // +// // Initialization ... +// bool Init( +// string _symbol, +// ENUM_TIMEFRAMES _period, +// double _upZoneUpperPrice, +// double _upZoneLowerPrice, +// double _downZoneUpperPrice, +// double _downZoneLowerPrice, +// datetime _expiration = NULL // +// ) +// { +// // +// bool result = false; - // - int _numberOfPivots; - int _pivotShoulders; +// // +// result = +// // +// IsValid(_symbol) && +// IsValid(_period) && +// _upZoneUpperPrice > 0 && +// _upZoneLowerPrice > 0 && +// _upZoneLowerPrice < _upZoneUpperPrice && +// _downZoneUpperPrice > 0 && +// _downZoneLowerPrice > 0 && +// _downZoneLowerPrice < _downZoneUpperPrice +// // +// ; +// // +// if (!result) +// { +// return result; +// } - // - // Constructor ... - XTrendDetector() - { - Clean(); - } +// // +// result = IsValid(); - // - // Tools ... +// // +// if (result) +// { +// // +// time = TimeCurrent(); +// } - // - // Cleanup ... - void Clean() - { - // - symbol = NULL; - period = NULL; +// // +// return result; +// } - // - _numberOfPivots = 0; - _pivotShoulders = 0; +// // +// // Tools ... - // - Clean(higherHighs); - Clean(higherHighTimes); +// // +// // Cleanup ... +// void Clean() +// { +// // +// time = NULL; +// symbol = NULL; +// period = NULL; +// expiration = NULL; - // - Clean(higherLows); - Clean(higherLowTimes); +// // +// up.Clean(); +// down.Clean(); +// } - // - Clean(lowerHighs); - Clean(lowerHighTimes); +// // +// // Validation ... +// bool IsValid() +// { +// // +// bool result = false; - // - Clean(lowerLows); - Clean(lowerLowTimes); - } +// // +// result = +// // +// IsValid(symbol) && +// IsValid(period) && +// up.IsValid() && +// down.IsValid() +// // +// ; - // - // Validate ... - bool IsValid() - { - // - bool result = false; +// // +// return result; +// } +// }; - // - result = - // - IsValid(symbol) && - IsValid(period) - // - ; +// // +// // Detect Trends ... +// struct XTrendDetector +// { +// // +// string symbol; +// ENUM_TIMEFRAMES period; - // - return result; - } -}; +// // +// double higherHighs[]; +// datetime higherHighTimes[]; + +// // +// double higherLows[]; +// datetime higherLowTimes[]; + +// // +// double lowerHighs[]; +// datetime lowerHighTimes[]; + +// // +// double lowerLows[]; +// datetime lowerLowTimes[]; + +// // +// int _numberOfPivots; +// int _pivotShoulders; + +// // +// // Constructor ... +// XTrendDetector() +// { +// Clean(); +// } + +// // +// // Tools ... + +// // +// // Cleanup ... +// void Clean() +// { +// // +// symbol = NULL; +// period = NULL; + +// // +// _numberOfPivots = 0; +// _pivotShoulders = 0; + +// // +// Clean(higherHighs); +// Clean(higherHighTimes); + +// // +// Clean(higherLows); +// Clean(higherLowTimes); + +// // +// Clean(lowerHighs); +// Clean(lowerHighTimes); + +// // +// Clean(lowerLows); +// Clean(lowerLowTimes); +// } + +// // +// // Validate ... +// bool IsValid() +// { +// // +// bool result = false; + +// // +// result = +// // +// IsValid(symbol) && +// IsValid(period) +// // +// ; + +// // +// return result; +// } +// };