diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index 5800ec25..83029a50 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -1537,14 +1537,14 @@ class XCX121Helper : public XCBase // // Helpers ... - XCX121XPVHelper *xpvHelper; - XCX121XHKHelper *xhkHelper; - XCX121XATRHelper *xatrHelper; - XCX121XSTRHelper *xstrHelper; - XCX121XCHEHelper *xcheHelper; - XCX121XDONHelper *xdonHelper; - XCX121XVWAPHelper *xvwapHelper; - XCX121XTRENDHelper *xtrendHelper; + // XCX121XPVHelper *xpvHelper; + // XCX121XHKHelper *xhkHelper; + // XCX121XATRHelper *xatrHelper; + // XCX121XSTRHelper *xstrHelper; + // XCX121XCHEHelper *xcheHelper; + // XCX121XDONHelper *xdonHelper; + // XCX121XVWAPHelper *xvwapHelper; + // XCX121XTRENDHelper *xtrendHelper; // // Constructors ... @@ -1556,25 +1556,25 @@ class XCX121Helper : public XCBase // Deconstructor ... ~XCX121Helper() { - // - delete xpvHelper; - delete xhkHelper; - delete xatrHelper; - delete xstrHelper; - delete xcheHelper; - delete xdonHelper; - delete xvwapHelper; - delete xtrendHelper; + // // + // delete xpvHelper; + // delete xhkHelper; + // delete xatrHelper; + // delete xstrHelper; + // delete xcheHelper; + // delete xdonHelper; + // delete xvwapHelper; + // delete xtrendHelper; - // - ZeroMemory(xpvHelper); - ZeroMemory(xhkHelper); - ZeroMemory(xatrHelper); - ZeroMemory(xstrHelper); - ZeroMemory(xcheHelper); - ZeroMemory(xdonHelper); - ZeroMemory(xvwapHelper); - ZeroMemory(xtrendHelper); + // // + // ZeroMemory(xpvHelper); + // ZeroMemory(xhkHelper); + // ZeroMemory(xatrHelper); + // ZeroMemory(xstrHelper); + // ZeroMemory(xcheHelper); + // ZeroMemory(xdonHelper); + // ZeroMemory(xvwapHelper); + // ZeroMemory(xtrendHelper); } // @@ -1627,142 +1627,142 @@ class XCX121Helper : public XCBase // // Setting Inputs ... - // - mInputs = inputs; - xpvInputs = inputs.xpvInputs; - xhkInputs = inputs.xhkInputs; - xatrInputs = inputs.xatrInputs; - xstrInputs = inputs.xstrInputs; - xcheInputs = inputs.xcheInputs; - xdonInputs = inputs.xdonInputs; - xvwapInputs = inputs.xvwapInputs; - xtrendInputs = inputs.xtrendInputs; + // // + // mInputs = inputs; + // xpvInputs = inputs.xpvInputs; + // xhkInputs = inputs.xhkInputs; + // xatrInputs = inputs.xatrInputs; + // xstrInputs = inputs.xstrInputs; + // xcheInputs = inputs.xcheInputs; + // xdonInputs = inputs.xdonInputs; + // xvwapInputs = inputs.xvwapInputs; + // xtrendInputs = inputs.xtrendInputs; - // - // Initial Helpers ... + // // + // // Initial Helpers ... - // - // XPV ... - xpvHelper = new XCX121XPVHelper(); - result = xpvHelper.Init( - symbol, - period, - xpvInputs // - ); - if (!result) - { - return result; - } + // // + // // XPV ... + // xpvHelper = new XCX121XPVHelper(); + // result = xpvHelper.Init( + // symbol, + // period, + // xpvInputs // + // ); + // if (!result) + // { + // return result; + // } - // - // XHK ... - xhkHelper = new XCX121XHKHelper(); - result = xhkHelper.Init( - symbol, - period, - xhkInputs // - ); - if (!result) - { - return result; - } + // // + // // XHK ... + // xhkHelper = new XCX121XHKHelper(); + // result = xhkHelper.Init( + // symbol, + // period, + // xhkInputs // + // ); + // if (!result) + // { + // return result; + // } - // - // XATR ... - xatrHelper = new XCX121XATRHelper(); - result = xatrHelper.Init( - symbol, - period, - xatrInputs // - ); - if (!result) - { - return result; - } + // // + // // XATR ... + // xatrHelper = new XCX121XATRHelper(); + // result = xatrHelper.Init( + // symbol, + // period, + // xatrInputs // + // ); + // if (!result) + // { + // return result; + // } - // - // XSTR ... - xstrHelper = new XCX121XSTRHelper(); - result = xstrHelper.Init( - symbol, - period, - xstrInputs // - ); - if (!result) - { - return result; - } + // // + // // XSTR ... + // xstrHelper = new XCX121XSTRHelper(); + // result = xstrHelper.Init( + // symbol, + // period, + // xstrInputs // + // ); + // if (!result) + // { + // return result; + // } - // - // XCHE ... - xcheHelper = new XCX121XCHEHelper(); - result = xcheHelper.Init( - symbol, - period, - xcheInputs // - ); - if (!result) - { - return result; - } + // // + // // XCHE ... + // xcheHelper = new XCX121XCHEHelper(); + // result = xcheHelper.Init( + // symbol, + // period, + // xcheInputs // + // ); + // if (!result) + // { + // return result; + // } - // - // XDON ... - xdonHelper = new XCX121XDONHelper(); - result = xdonHelper.Init( - symbol, - period, - xdonInputs // - ); - if (!result) - { - return result; - } + // // + // // XDON ... + // xdonHelper = new XCX121XDONHelper(); + // result = xdonHelper.Init( + // symbol, + // period, + // xdonInputs // + // ); + // if (!result) + // { + // return result; + // } - // - // XVWAP ... - xvwapHelper = new XCX121XVWAPHelper(); - result = xvwapHelper.Init( - symbol, - period, - xvwapInputs // - ); - if (!result) - { - return result; - } + // // + // // XVWAP ... + // xvwapHelper = new XCX121XVWAPHelper(); + // result = xvwapHelper.Init( + // symbol, + // period, + // xvwapInputs // + // ); + // if (!result) + // { + // return result; + // } - // - // XTREND ... - xtrendHelper = new XCX121XTRENDHelper(); - result = xtrendHelper.Init( - symbol, - period, - xtrendInputs // - ); - if (!result) - { - return result; - } + // // + // // XTREND ... + // xtrendHelper = new XCX121XTRENDHelper(); + // result = xtrendHelper.Init( + // symbol, + // period, + // xtrendInputs // + // ); + // if (!result) + // { + // return result; + // } - // - if (inputs.showRSI) - { - // - mRSIHandler = iRSI( - symbol, - period, - xatrInputs.rsiLength, - xatrInputs.rsiAppliedTo // - ); + // // + // if (inputs.showRSI) + // { + // // + // mRSIHandler = iRSI( + // symbol, + // period, + // xatrInputs.rsiLength, + // xatrInputs.rsiAppliedTo // + // ); - // - result = mRSIHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - } + // // + // result = mRSIHandler != INVALID_HANDLE; + // if (!result) + // { + // return result; + // } + // } // return result; @@ -1771,195 +1771,195 @@ class XCX121Helper : public XCBase // // Conditions Readers ... - // - // XPV ... - bool GetPVConditions( - X121XPVConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XPV ... + // bool GetPVConditions( + // X121XPVConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xpvHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xpvHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - // XHK ... - bool GetHKConditions( - X121XHKConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XHK ... + // bool GetHKConditions( + // X121XHKConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xhkHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xhkHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - // XATR ... - bool GetATRConditions( - X121XATRConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XATR ... + // bool GetATRConditions( + // X121XATRConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xatrHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xatrHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - // XSTR ... - bool GetSTRConditions( - X121XSTRConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XSTR ... + // bool GetSTRConditions( + // X121XSTRConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xstrHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xstrHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - // XCHE ... - bool GetCHEConditions( - X121XCHEConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XCHE ... + // bool GetCHEConditions( + // X121XCHEConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xcheHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xcheHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - // XDON ... - bool GetDONConditions( - X121XDONConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XDON ... + // bool GetDONConditions( + // X121XDONConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xdonHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xdonHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - // XVWAP ... - bool GetVWAPConditions( - X121XVWAPConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XVWAP ... + // bool GetVWAPConditions( + // X121XVWAPConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xvwapHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xvwapHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - // XTREND ... - bool GetTrendConditions( - X121XTRENDConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; + // // + // // XTREND ... + // bool GetTrendConditions( + // X121XTRENDConditions &conditions, // + // int barIndex = 0, // + // int loopback = 5 // + // ) + // { + // // + // bool result = false; - // - result = xtrendHelper.GetConditions( - conditions, - barIndex, - loopback // - ); + // // + // result = xtrendHelper.GetConditions( + // conditions, + // barIndex, + // loopback // + // ); - // - return result; - } + // // + // return result; + // } - // - void Free() - { - // - xpvHelper.Free(); - xhkHelper.Free(); - xatrHelper.Free(); - xstrHelper.Free(); - xcheHelper.Free(); - xdonHelper.Free(); - xvwapHelper.Free(); - xtrendHelper.Free(); - } + // // + // void Free() + // { + // // + // xpvHelper.Free(); + // xhkHelper.Free(); + // xatrHelper.Free(); + // xstrHelper.Free(); + // xcheHelper.Free(); + // xdonHelper.Free(); + // xvwapHelper.Free(); + // xtrendHelper.Free(); + // } // bool GetConditions( @@ -1971,1379 +1971,1379 @@ class XCX121Helper : public XCBase // bool result = true; - // - if (loopback < 5) - { - loopback = 5; - } - - // - conditions.Clean(); - - // - conditions.symbol = mSymbol; - conditions.period = mPeriod; - conditions.time = TimeCurrent(); - - // - int zIndex = barIndex; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - XOHCL zBar; - result = zBar.Init( - mSymbol, - mPeriod, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - mSymbol, - mPeriod, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - mSymbol, - mPeriod, - pIndex // - ); - if (!result) - { - return result; - } - - // - // XPV ... - X121XPVConditions xpvConditions; - result = GetPVConditions( - xpvConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XHK ... - X121XHKConditions xhkConditions; - result = GetHKConditions( - xhkConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XATR ... - X121XATRConditions xatrConditions; - result = GetATRConditions( - xatrConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XSTR ... - X121XSTRConditions xstrConditions; - result = GetSTRConditions( - xstrConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XCHE ... - X121XCHEConditions xcheConditions; - result = GetCHEConditions( - xcheConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XDON ... - X121XDONConditions xdonConditions; - result = GetDONConditions( - xdonConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XVWAP ... - X121XVWAPConditions xvwapConditions; - result = GetVWAPConditions( - xvwapConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XTREND ... - X121XTRENDConditions xtrendConditions; - result = GetTrendConditions( - xtrendConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Fill Volume Buffer ... - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - // Reading Bar Valuem ... - long iVol = iVolume( - mSymbol, - mPeriod, - i // - ); - - // - Add( - iVol, - conditions.volumeBuffer // - ); - } - - // - // Fill X121 Conditions Reference by Using - // Retrieved Conditions ... - - // - int cIDX = 1; - int pIDX = cIDX + 1; - - // - // XPV ... - - // - // Buffers ... - - // - Copy( - xpvConditions.peaksBuffer, - conditions.peaksBuffer // - ); - - // - Copy( - xpvConditions.valesBuffer, - conditions.valesBuffer // - ); - - // - Copy( - xpvConditions.sarBuffer, - conditions.sarBuffer // - ); - - // - Copy( - xpvConditions.cHHBuffer, - conditions.cHHBuffer // - ); - - // - Copy( - xpvConditions.cLLBuffer, - conditions.cLLBuffer // - ); - - // - Copy( - xpvConditions.sHHBuffer, - conditions.sHHBuffer // - ); - - // - Copy( - xpvConditions.sLLBuffer, - conditions.sLLBuffer // - ); - - // - Copy( - xpvConditions.mHHBuffer, - conditions.mHHBuffer // - ); - - // - Copy( - xpvConditions.mLLBuffer, - conditions.mLLBuffer // - ); - - // - Copy( - xpvConditions.lHHBuffer, - conditions.lHHBuffer // - ); - - // - Copy( - xpvConditions.lLLBuffer, - conditions.lLLBuffer // - ); - - // - Copy( - xpvConditions.hHHBuffer, - conditions.hHHBuffer // - ); - - // - Copy( - xpvConditions.hLLBuffer, - conditions.hLLBuffer // - ); - - // - // Conditions ... - - // - conditions.isNewPeak = xpvConditions.isNewPeak; - conditions.isNewVale = xpvConditions.isNewVale; - conditions.isSarBullish = xpvConditions.isSarBullish; - conditions.isSarBearish = xpvConditions.isSarBearish; - conditions.isNewPeakOverLast = xpvConditions.isNewPeakOverLast; - conditions.isNewValeOverLast = xpvConditions.isNewValeOverLast; - conditions.isNewPeakUnderLast = xpvConditions.isNewPeakUnderLast; - conditions.isNewValeUnderLast = xpvConditions.isNewValeUnderLast; - conditions.isRejectedPrevVale = xpvConditions.isRejectedPrevVale; - conditions.isRejectedPrevPeak = xpvConditions.isRejectedPrevPeak; - conditions.isBreakedUpPrevPeak = xpvConditions.isBreakedUpPrevPeak; - conditions.isBreakedDownPrevVale = xpvConditions.isBreakedDownPrevVale; - conditions.isSarSwitchedToBullish = xpvConditions.isSarSwitchedToBullish; - conditions.isSarSwitchedToBearish = xpvConditions.isSarSwitchedToBearish; - - // - // XHK ... - - // - // Buffers ... - - // - Copy( - xhkConditions.xhkRawOpenBuffer, - conditions.xhkRawOpenBuffer // - ); - - // - Copy( - xhkConditions.xhkRawHighBuffer, - conditions.xhkRawHighBuffer // - ); - - // - Copy( - xhkConditions.xhkRawLowBuffer, - conditions.xhkRawLowBuffer // - ); - - // - Copy( - xhkConditions.xhkRawCloseBuffer, - conditions.xhkRawCloseBuffer // - ); - - // - Copy( - xhkConditions.xhkSMOpenBuffer, - conditions.xhkSMOpenBuffer // - ); - - // - Copy( - xhkConditions.xhkSMHighBuffer, - conditions.xhkSMHighBuffer // - ); - - // - Copy( - xhkConditions.xhkSMLowBuffer, - conditions.xhkSMLowBuffer // - ); - - // - Copy( - xhkConditions.xhkSMCloseBuffer, - conditions.xhkSMCloseBuffer // - ); - - // - // Conditions ... - conditions.isSMHKBullish = xhkConditions.isSMHKBullish; - conditions.isRawHKBullish = xhkConditions.isRawHKBullish; - conditions.isSMHKBearish = xhkConditions.isSMHKBearish; - conditions.isRawHKBearish = xhkConditions.isRawHKBearish; - conditions.isBreakedUpSMHK = xhkConditions.isBreakedUpSMHK; - conditions.isBreakedUpRawHK = xhkConditions.isBreakedUpRawHK; - conditions.isRejectedUpSMHK = xhkConditions.isRejectedUpSMHK; - conditions.isClosedOverSMHK = xhkConditions.isClosedOverSMHK; - conditions.isRejectedUpRawHK = xhkConditions.isRejectedUpRawHK; - conditions.isBreakedDownSMHK = xhkConditions.isBreakedDownSMHK; - conditions.isClosedUnderSMHK = xhkConditions.isClosedUnderSMHK; - conditions.isClosedOverRawHK = xhkConditions.isClosedOverRawHK; - conditions.isClosedUnderRawHK = xhkConditions.isClosedUnderRawHK; - conditions.isBreakedDownRawHK = xhkConditions.isBreakedDownRawHK; - conditions.isRejectedDownSMHK = xhkConditions.isRejectedDownSMHK; - conditions.isRejectedDownRawHK = xhkConditions.isRejectedDownRawHK; - conditions.isRawHKBreakedUpSMHK = xhkConditions.isRawHKBreakedUpSMHK; - conditions.isRawHKClosedOverSMHK = xhkConditions.isRawHKClosedOverSMHK; - conditions.isSMHKSwitchedToBearish = xhkConditions.isSMHKSwitchedToBearish; - conditions.isRawHKSwitchedToBearish = xhkConditions.isRawHKSwitchedToBearish; - conditions.isRawHKClosedUnderSMHK = xhkConditions.isRawHKClosedUnderSMHK; - conditions.isRawHKBreakedDownSMHK = xhkConditions.isRawHKBreakedDownSMHK; - conditions.isSMHKSwitchedToBullish = xhkConditions.isSMHKSwitchedToBullish; - conditions.isRawHKSwitchedToBullish = xhkConditions.isRawHKSwitchedToBullish; - - // - // XTREND ... - - // - // Buffers ... - - // - Copy( - xtrendConditions.upTrendBuffer, - conditions.upTrendBuffer // - ); - - // - Copy( - xtrendConditions.downTrendBuffer, - conditions.downTrendBuffer // - ); - - // - Copy( - xtrendConditions.maBuffer, - conditions.maBuffer // - ); - - // - Copy( - xtrendConditions.adxBuffer, - conditions.adxBuffer // - ); - - // - Copy( - xtrendConditions.adxPBuffer, - conditions.adxPBuffer // - ); - - // - Copy( - xtrendConditions.adxMBuffer, - conditions.adxMBuffer // - ); - - // - Copy( - xtrendConditions.upTBuffer, - conditions.upTBuffer // - ); - - // - Copy( - xtrendConditions.downTBuffer, - conditions.downTBuffer // - ); - - // - conditions.isTrendBullish = xtrendConditions.isTrendBullish; - conditions.isTrendBearish = xtrendConditions.isTrendBearish; - conditions.isTrendSwitchedToBullish = xtrendConditions.isTrendSwitchedToBullish; - conditions.isTrendSwitchedToBearish = xtrendConditions.isTrendSwitchedToBearish; - - // - // XATR ... - - // - // Buffers ... - - // - Copy( - xatrConditions.atrUpperBuffer, - conditions.atrUpperBuffer // - ); - - // - Copy( - xatrConditions.atrLowerBuffer, - conditions.atrLowerBuffer // - ); - - // - Copy( - xatrConditions.atrUpperRawBuffer, - conditions.atrUpperRawBuffer // - ); - - // - Copy( - xatrConditions.atrLowerRawBuffer, - conditions.atrLowerRawBuffer // - ); - - // - Copy( - xatrConditions.atrBuffer, - conditions.atrBuffer // - ); - - // - Copy( - xatrConditions.rsiBuffer, - conditions.rsiBuffer // - ); - - // - // Conditions ... - - // - conditions.isRsiOverSold = xatrConditions.isRsiOverSold; - conditions.isRsiOverBought = xatrConditions.isRsiOverBought; - conditions.isBreakedUpAtrUpper = xatrConditions.isBreakedUpAtrUpper; - conditions.isBreakedUpAtrLower = xatrConditions.isBreakedUpAtrLower; - conditions.isClosedOverAtrUpper = xatrConditions.isClosedOverAtrUpper; - conditions.isRejectedUpAtrUpper = xatrConditions.isRejectedUpAtrUpper; - conditions.isRejectedUpAtrLower = xatrConditions.isRejectedUpAtrLower; - conditions.isClosedOverAtrLower = xatrConditions.isClosedOverAtrLower; - conditions.isBreakedDownAtrUpper = xatrConditions.isBreakedDownAtrUpper; - conditions.isBreakedDownAtrLower = xatrConditions.isBreakedDownAtrLower; - conditions.isClosedUnderAtrUpper = xatrConditions.isClosedUnderAtrUpper; - conditions.isClosedUnderAtrLower = xatrConditions.isClosedUnderAtrLower; - conditions.isRejectedDownAtrUpper = xatrConditions.isRejectedDownAtrUpper; - conditions.isRejectedDownAtrLower = xatrConditions.isRejectedDownAtrLower; - conditions.isRsiCrossedOverOverSold = xatrConditions.isRsiCrossedOverOverSold; - conditions.isRsiCrossedUnderOverSold = xatrConditions.isRsiCrossedUnderOverSold; - conditions.isRsiCrossedOverOverBought = xatrConditions.isRsiCrossedOverOverBought; - conditions.isRsiCrossedUnderOverBought = xatrConditions.isRsiCrossedUnderOverBought; - - // - // XSTR ... - - // - // Buffers ... - - // - Copy( - xstrConditions.strBuffer, - conditions.strBuffer // - ); - - // - Copy( - xstrConditions.strPriceBuffer, - conditions.strPriceBuffer // - ); - - // - Copy( - xstrConditions.strUpBuffer, - conditions.strUpBuffer // - ); - - // - Copy( - xstrConditions.strDownBuffer, - conditions.strDownBuffer // - ); - - // - Copy( - xstrConditions.strStateBuffer, - conditions.strStateBuffer // - ); - - // - // Conditions ... - - // - conditions.isStrBullish = xstrConditions.isStrBullish; - conditions.isStrBearish = xstrConditions.isStrBearish; - conditions.isStrSwitchedToBullish = xstrConditions.isStrSwitchedToBullish; - conditions.isStrSwitchedToBearish = xstrConditions.isStrSwitchedToBearish; - - // - // XCHE ... - - // - // Buffers ... - - // - Copy( - xcheConditions.le1Buffer, - conditions.le1Buffer // - ); - - // - Copy( - xcheConditions.se1Buffer, - conditions.se1Buffer // - ); - - // - Copy( - xcheConditions.le2Buffer, - conditions.le2Buffer // - ); - - // - Copy( - xcheConditions.se2Buffer, - conditions.se2Buffer // - ); - - // - Copy( - xcheConditions.le1StartBuffer, - conditions.le1StartBuffer // - ); - - // - Copy( - xcheConditions.se1StartBuffer, - conditions.se1StartBuffer // - ); - - // - Copy( - xcheConditions.le2StartBuffer, - conditions.le2StartBuffer // - ); - - // - Copy( - xcheConditions.se2StartBuffer, - conditions.se2StartBuffer // - ); - - // - // Conditions ... - - conditions.isCheBullish = xcheConditions.isCheBullish; - conditions.isCheBearish = xcheConditions.isCheBearish; - conditions.isChe1Bullish = xcheConditions.isChe1Bullish; - conditions.isChe1Bearish = xcheConditions.isChe1Bearish; - conditions.isChe2Bullish = xcheConditions.isChe2Bullish; - conditions.isChe2Bearish = xcheConditions.isChe2Bearish; - conditions.isClosedOverCheMin = xcheConditions.isClosedOverCheMin; - conditions.isClosedOverCheMax = xcheConditions.isClosedOverCheMax; - conditions.isClosedUnderCheMin = xcheConditions.isClosedUnderCheMin; - conditions.isClosedUnderCheMax = xcheConditions.isClosedUnderCheMax; - conditions.isCheSwitchedToBullish = xcheConditions.isCheSwitchedToBullish; - conditions.isCheSwitchedToBearish = xcheConditions.isCheSwitchedToBearish; - conditions.isChe1SwitchedToBullish = xcheConditions.isChe1SwitchedToBullish; - conditions.isChe1SwitchedToBearish = xcheConditions.isChe1SwitchedToBearish; - conditions.isChe2SwitchedToBullish = xcheConditions.isChe2SwitchedToBullish; - conditions.isChe2SwitchedToBearish = xcheConditions.isChe2SwitchedToBearish; - - // - // XDON ... - - // - // Buffers ... - - // - Copy( - xdonConditions.donOpenUpperBuffer, - conditions.donOpenUpperBuffer // - ); - - // - Copy( - xdonConditions.donOpenLowerBuffer, - conditions.donOpenLowerBuffer // - ); - - // - Copy( - xdonConditions.donHighUpperBuffer, - conditions.donHighUpperBuffer // - ); - - // - Copy( - xdonConditions.donHighLowerBuffer, - conditions.donHighLowerBuffer // - ); - - // - Copy( - xdonConditions.donLowUpperBuffer, - conditions.donLowUpperBuffer // - ); - - // - Copy( - xdonConditions.donLowLowerBuffer, - conditions.donLowLowerBuffer // - ); - - // - Copy( - xdonConditions.donCloseUpperBuffer, - conditions.donCloseUpperBuffer // - ); - - // - Copy( - xdonConditions.donCloseLowerBuffer, - conditions.donCloseLowerBuffer // - ); - - // - // Conditions ... - - // - conditions.isBreakedDonLowUpper = xdonConditions.isBreakedDonLowUpper; - conditions.isBreakedDonLowLower = xdonConditions.isBreakedDonLowLower; - conditions.isRejectedDonLowUpper = xdonConditions.isRejectedDonLowUpper; - conditions.isRejectedDonLowLower = xdonConditions.isRejectedDonLowLower; - conditions.isBreakedDonOpenUpper = xdonConditions.isBreakedDonOpenUpper; - conditions.isBreakedDonHighUpper = xdonConditions.isBreakedDonHighUpper; - conditions.isBreakedDonOpenLower = xdonConditions.isBreakedDonOpenLower; - conditions.isBreakedDonHighLower = xdonConditions.isBreakedDonHighLower; - conditions.isRejectedDonOpenUpper = xdonConditions.isRejectedDonOpenUpper; - conditions.isRejectedDonHighUpper = xdonConditions.isRejectedDonHighUpper; - conditions.isRejectedDonOpenLower = xdonConditions.isRejectedDonOpenLower; - conditions.isRejectedDonHighLower = xdonConditions.isRejectedDonHighLower; - conditions.isBreakedDonCloseUpper = xdonConditions.isBreakedDonCloseUpper; - conditions.isBreakedDonCloseLower = xdonConditions.isBreakedDonCloseLower; - conditions.isRejectedDonCloseUpper = xdonConditions.isRejectedDonCloseUpper; - conditions.isRejectedDonCloseLower = xdonConditions.isRejectedDonCloseLower; - - // - // XVWAP ... - - // - // Buffers ... - - // - Copy( - xvwapConditions.vwapFastBuffer, - conditions.vwapFastBuffer // - ); - - // - Copy( - xvwapConditions.vwapMidBuffer, - conditions.vwapMidBuffer // - ); - - // - Copy( - xvwapConditions.vwapSlowBuffer, - conditions.vwapSlowBuffer // - ); - - // - Copy( - xvwapConditions.vwapVolumeBuffer, - conditions.vwapVolumeBuffer // - ); - - // - Copy( - xvwapConditions.vwapPriceBuffer, - conditions.vwapPriceBuffer // - ); - - // - Copy( - xvwapConditions.vwapFastStateBuffer, - conditions.vwapFastStateBuffer // - ); - - // - Copy( - xvwapConditions.vwapMidStateBuffer, - conditions.vwapMidStateBuffer // - ); - - // - Copy( - xvwapConditions.vwapSlowStateBuffer, - conditions.vwapSlowStateBuffer // - ); - - // - // Conditions ... - - // - conditions.isVWapMidBullish = xvwapConditions.isVWapMidBullish; - conditions.isVWapMidBearish = xvwapConditions.isVWapMidBearish; - conditions.isVWapFastBullish = xvwapConditions.isVWapFastBullish; - conditions.isVWapFastBearish = xvwapConditions.isVWapFastBearish; - conditions.isVWapMidNeutural = xvwapConditions.isVWapMidNeutural; - conditions.isVWapSlowBullish = xvwapConditions.isVWapSlowBullish; - conditions.isVWapSlowBearish = xvwapConditions.isVWapSlowBearish; - conditions.isVWapFastOverMid = xvwapConditions.isVWapFastOverMid; - conditions.isVWapMidOverSlow = xvwapConditions.isVWapMidOverSlow; - conditions.isVWapFastNeutural = xvwapConditions.isVWapFastNeutural; - conditions.isVWapSlowNeutural = xvwapConditions.isVWapSlowNeutural; - conditions.isVWapFastUnderMid = xvwapConditions.isVWapFastUnderMid; - conditions.isVWapMidUnderSlow = xvwapConditions.isVWapMidUnderSlow; - conditions.isVWapBullishState = xvwapConditions.isVWapBullishState; - conditions.isVWapBearishState = xvwapConditions.isVWapBearishState; - conditions.isVWapNeuturalState = xvwapConditions.isVWapNeuturalState; - conditions.isVWapBullishOrdered = xvwapConditions.isVWapBullishOrdered; - conditions.isVWapBearishOrdered = xvwapConditions.isVWapBearishOrdered; - conditions.isVWapSwitchedToBullishState = xvwapConditions.isVWapSwitchedToBullishState; - conditions.isVWapSwitchedToBearishState = xvwapConditions.isVWapSwitchedToBearishState; - conditions.isVWapSwitchedToNeuturalState = xvwapConditions.isVWapSwitchedToNeuturalState; - conditions.isVWapSwitchedToBullishOrdered = xvwapConditions.isVWapSwitchedToBullishOrdered; - conditions.isVWapSwitchedToBearishOrdered = xvwapConditions.isVWapSwitchedToBearishOrdered; - - // - // Slopes ... - - // - double rsiSlope = GetSlope(conditions.rsiBuffer, pIDX, cIDX); - double strSlope = GetSlope(conditions.strBuffer, pIDX, cIDX); - double atrUpperSlope = GetSlope(conditions.atrUpperBuffer, pIDX, cIDX); - double atrLowerSlope = GetSlope(conditions.atrLowerBuffer, pIDX, cIDX); - double vwapFastSlope = GetSlope(conditions.vwapFastBuffer, pIDX, cIDX); - double vwapMidSlope = GetSlope(conditions.vwapMidBuffer, pIDX, cIDX); - double vwapSlowSlope = GetSlope(conditions.vwapSlowBuffer, pIDX, cIDX); - - // - bool isRsiSlopeBullish = rsiSlope > 0; - bool isStrSlopeBullish = strSlope > 0; - bool isAtrUpperSlopeBullish = atrUpperSlope > 0; - bool isAtrLowerSlopeBullish = atrLowerSlope > 0; - bool isVwapFastSlopeBullish = vwapFastSlope > 0; - bool isVwapMidSlopeBullish = vwapMidSlope > 0; - bool isVwapSlowSlopeBullish = vwapSlowSlope > 0; - - // - bool isRsiSlopeBearish = rsiSlope < 0; - bool isStrSlopeBearish = strSlope < 0; - bool isAtrUpperSlopeBearish = atrUpperSlope < 0; - bool isAtrLowerSlopeBearish = atrLowerSlope < 0; - bool isVwapFastSlopeBearish = vwapFastSlope < 0; - bool isVwapMidSlopeBearish = vwapMidSlope < 0; - bool isVwapSlowSlopeBearish = vwapSlowSlope < 0; - - // - conditions.rsiSlope = rsiSlope; - conditions.strSlope = strSlope; - conditions.vwapMidSlope = vwapMidSlope; - conditions.vwapSlowSlope = vwapSlowSlope; - conditions.atrUpperSlope = atrUpperSlope; - conditions.atrLowerSlope = atrLowerSlope; - conditions.vwapFastSlope = vwapFastSlope; - conditions.isRsiSlopeBearish = isRsiSlopeBearish; - conditions.isStrSlopeBearish = isStrSlopeBearish; - conditions.isRsiSlopeBullish = isRsiSlopeBullish; - conditions.isStrSlopeBullish = isStrSlopeBullish; - conditions.isVwapMidSlopeBearish = isVwapMidSlopeBearish; - conditions.isVwapMidSlopeBullish = isVwapMidSlopeBullish; - conditions.isAtrUpperSlopeBearish = isAtrUpperSlopeBearish; - conditions.isAtrLowerSlopeBearish = isAtrLowerSlopeBearish; - conditions.isVwapFastSlopeBearish = isVwapFastSlopeBearish; - conditions.isVwapSlowSlopeBearish = isVwapSlowSlopeBearish; - conditions.isAtrUpperSlopeBullish = isAtrUpperSlopeBullish; - conditions.isAtrLowerSlopeBullish = isAtrLowerSlopeBullish; - conditions.isVwapFastSlopeBullish = isVwapFastSlopeBullish; - conditions.isVwapSlowSlopeBullish = isVwapSlowSlopeBullish; - - // - // Complex Conditions ... - - // - double vwapFast = conditions.vwapFastBuffer[cIDX]; - double vwapMid = conditions.vwapMidBuffer[cIDX]; - double vwapSlow = conditions.vwapSlowBuffer[cIDX]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow // - }; - - // - double vwapMin = GetMin(vwaps); - double vwapMax = GetMax(vwaps); - - // - bool isVWapMinBreakedUp = IsBarBreak( - vwapMin, - X_DIRECTION_BULLISH, - cBar // - ); - bool isVWapMinBreakedDown = IsBarBreak( - vwapMin, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isVWapMaxBreakedUp = IsBarBreak( - vwapMax, - X_DIRECTION_BULLISH, - cBar // - ); - bool isVWapMaxBreakedDown = IsBarBreak( - vwapMax, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isVWapFatsOverMid = conditions.vwapFastBuffer[cIDX] > conditions.vwapMidBuffer[cIDX]; - bool isVWapFatsOverMidPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapFatsUnderMid = conditions.vwapFastBuffer[cIDX] < conditions.vwapMidBuffer[cIDX]; - bool isVWapFatsUnderMidPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapFatsOverSlow = conditions.vwapFastBuffer[cIDX] > conditions.vwapSlowBuffer[cIDX]; - bool isVWapFatsOverSlowPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapFatsUnderSlow = conditions.vwapFastBuffer[cIDX] < conditions.vwapSlowBuffer[cIDX]; - bool isVWapFatsUnderSlowPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapFastCrossedOverMid = isVWapFatsOverMid && - !isVWapFatsOverMidPrev; - bool isVWapFastCrossedUnderMid = isVWapFatsUnderMid && - !isVWapFatsUnderMidPrev; - - // - bool isVWapFastCrossedOverSlow = isVWapFatsOverSlow && - !isVWapFatsOverSlowPrev; - bool isVWapFastCrossedUnderSlow = isVWapFatsUnderSlow && - !isVWapFatsUnderSlowPrev; - - // - bool isClosedOverVWapMin = cBar.close > vwapMin; - bool isClosedUnderVWapMin = cBar.close < vwapMin; - - // - bool isClosedOverVWapMax = cBar.close > vwapMax; - bool isClosedUnderVWapMax = cBar.close < vwapMax; - - // - bool isSarEqualsToPeak = - conditions.sarBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - bool isSarEqualsToVale = - conditions.sarBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isSarIncreased = conditions.sarBuffer[cIDX] > conditions.sarBuffer[pIDX]; - bool isSarDecreased = conditions.sarBuffer[cIDX] < conditions.sarBuffer[pIDX]; - - // - double prevSar = conditions.sarBuffer[pIDX]; - double prevStr = conditions.strBuffer[pIDX]; - double prevCheLE1 = conditions.le1Buffer[pIDX]; - double prevCheLE2 = conditions.le2Buffer[pIDX]; - double prevCheSE1 = conditions.se1Buffer[pIDX]; - double prevCheSE2 = conditions.se2Buffer[pIDX]; - double prevAtrUpper = conditions.atrUpperBuffer[pIDX]; - double prevAtrLower = conditions.atrLowerBuffer[pIDX]; - - // - double ches[]; - if (prevCheLE1 != EMPTY_VALUE) - { - // - Add( - prevCheLE1, - ches // - ); - } - if (prevCheLE2 != EMPTY_VALUE) - { - // - Add( - prevCheLE2, - ches // - ); - } - if (prevCheSE1 != EMPTY_VALUE) - { - // - Add( - prevCheSE1, - ches // - ); - } - if (prevCheSE2 != EMPTY_VALUE) - { - // - Add( - prevCheSE2, - ches // - ); - } - - // - double cheMin = GetMin(ches); - double cheMax = GetMax(ches); - - // - bool isBreakedUpPrevSar = IsBarBreak( - prevSar, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevSar = IsBarBreak( - prevSar, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevStr = IsBarBreak( - prevStr, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevStr = IsBarBreak( - prevStr, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isRejectedUpPrevAtrUpper = IsBarReject( - prevAtrUpper, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isRejectedDownPrevAtrUpper = IsBarReject( - prevAtrUpper, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isRejectedUpPrevAtrLower = IsBarReject( - prevAtrLower, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isRejectedDownPrevAtrLower = IsBarReject( - prevAtrLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevAtrUpper = IsBarBreak( - prevAtrUpper, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevAtrUpper = IsBarBreak( - prevAtrUpper, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevAtrLower = IsBarBreak( - prevAtrLower, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevAtrLower = IsBarBreak( - prevAtrLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevCheLE1 = IsBarBreak( - prevCheLE1, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedUpPrevCheLE2 = IsBarBreak( - prevCheLE2, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedUpPrevCheSE1 = IsBarBreak( - prevCheSE1, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedUpPrevCheSE2 = IsBarBreak( - prevCheSE2, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isBreakedDownPrevCheLE1 = IsBarBreak( - prevCheLE1, - X_DIRECTION_BEARISH, - cBar // - ); - bool isBreakedDownPrevCheLE2 = IsBarBreak( - prevCheLE2, - X_DIRECTION_BEARISH, - cBar // - ); - bool isBreakedDownPrevCheSE1 = IsBarBreak( - prevCheSE1, - X_DIRECTION_BEARISH, - cBar // - ); - bool isBreakedDownPrevCheSE2 = IsBarBreak( - prevCheSE2, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevCheMin = IsBarBreak( - cheMin, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevCheMin = IsBarBreak( - cheMin, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevCheMax = IsBarBreak( - cheMax, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevCheMax = IsBarBreak( - cheMax, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isSarCrossedUnderPeak = - conditions.sarBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - !(conditions.sarBuffer[pIDX] < conditions.peaksBuffer[pIDX]); - bool isSarCrossedOverVale = - conditions.sarBuffer[cIDX] > conditions.valesBuffer[cIDX] && - !(conditions.sarBuffer[pIDX] > conditions.valesBuffer[pIDX]); - - // - bool isStrEqualsToPeak = - conditions.strBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - bool isStrEqualsToVale = - conditions.strBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isStrCrossedUnderPeak = - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - !(conditions.strBuffer[pIDX] < conditions.peaksBuffer[pIDX]); - bool isStrCrossedOverVale = - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX] && - !(conditions.strBuffer[pIDX] > conditions.valesBuffer[pIDX]); - - // - bool isPeakOverAtrUpper = - conditions.peaksBuffer[cIDX] > conditions.atrUpperBuffer[cIDX]; - bool isValeUnderAtrLower = - conditions.valesBuffer[cIDX] > conditions.atrLowerBuffer[cIDX]; - - // - bool isNewPeakOverAtrUpper = - isPeakOverAtrUpper && - conditions.isNewPeak; - bool isNewValeUnderAtrLower = - isValeUnderAtrLower && - conditions.isNewVale; - - // - bool isStrUpperOverPeak = - conditions.strBuffer[cIDX] > conditions.peaksBuffer[cIDX]; - bool isStrUpperOverPeakPrev = - conditions.strBuffer[pIDX] > conditions.peaksBuffer[pIDX]; - - // - bool isStrUpperUnderPeak = - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX]; - bool isStrUpperUnderPeakPrev = - conditions.strBuffer[pIDX] < conditions.peaksBuffer[pIDX]; - - // - bool isStrUpperCrossedOverPeak = isStrUpperOverPeak && - !isStrUpperOverPeakPrev; - bool isStrUpperCrossedUnderPeak = isStrUpperUnderPeak && - !isStrUpperUnderPeakPrev; - - // - bool isStrLowerOverVale = - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX]; - bool isStrLowerOverValePrev = - conditions.strBuffer[pIDX] > conditions.valesBuffer[pIDX]; - - // - bool isStrLowerUnderVale = - conditions.strBuffer[cIDX] < conditions.valesBuffer[cIDX]; - bool isStrLowerUnderValePrev = - conditions.strBuffer[pIDX] < conditions.valesBuffer[pIDX]; - - // - bool isStrLowerCrossedOverVale = isStrLowerOverVale && - !isStrLowerOverValePrev; - bool isStrLowerCrossedUnderVale = isStrLowerUnderVale && - !isStrLowerUnderValePrev; - - // - bool isDonHighUpperEqualsToPeak = - conditions.donHighUpperBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - bool isDonLowLowerEqualsToVale = - conditions.donLowLowerBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isStrUpperOverAtrUpper = - conditions.strUpBuffer[cIDX] > conditions.atrUpperBuffer[cIDX]; - bool isStrUpperOverAtrUpperPrev = - conditions.strUpBuffer[pIDX] > conditions.atrUpperBuffer[pIDX]; - bool isStrUpperCrossedOverAtrUpper = isStrUpperOverAtrUpper && - !isStrUpperOverAtrUpperPrev; - - // - bool isStrUpperUnderAtrUpper = - conditions.strUpBuffer[cIDX] < conditions.atrUpperBuffer[cIDX]; - bool isStrUpperUnderAtrUpperPrev = - conditions.strUpBuffer[pIDX] < conditions.atrUpperBuffer[pIDX]; - bool isStrUpperCrossedUnderAtrUpper = isStrUpperUnderAtrUpper && - !isStrUpperUnderAtrUpperPrev; - - // - bool isStrLowerOverAtrLower = - conditions.strDownBuffer[cIDX] > conditions.atrLowerBuffer[cIDX]; - bool isStrLowerOverAtrLowerPrev = - conditions.strDownBuffer[pIDX] > conditions.atrLowerBuffer[pIDX]; - bool isStrLowerCrossedOverAtrLower = isStrLowerOverAtrLower && - !isStrLowerOverAtrLowerPrev; - - // - bool isStrLowerUnderAtrLower = - conditions.strDownBuffer[cIDX] < conditions.atrLowerBuffer[cIDX]; - bool isStrLowerUnderAtrLowerPrev = - conditions.strDownBuffer[pIDX] < conditions.atrLowerBuffer[pIDX]; - bool isStrLowerCrossedUnderAtrLower = isStrLowerUnderAtrLower && - !isStrLowerUnderAtrLowerPrev; - - // - bool isStrUpperOverDonHighUpper = - conditions.strUpBuffer[cIDX] > conditions.donHighUpperBuffer[cIDX]; - bool isStrUpperOverDonHighUpperPrev = - conditions.strUpBuffer[pIDX] > conditions.donHighUpperBuffer[pIDX]; - bool isStrUpperCrossedOverDonHighUpper = isStrUpperOverDonHighUpper && - !isStrUpperOverDonHighUpperPrev; - - // - bool isStrUpperUnderDonHighUpper = - conditions.strUpBuffer[cIDX] < conditions.donHighUpperBuffer[cIDX]; - bool isStrUpperUnderDonHighUpperPrev = - conditions.strUpBuffer[pIDX] < conditions.donHighUpperBuffer[pIDX]; - bool isStrUpperCrossedUnderDonHighUpper = isStrUpperUnderDonHighUpper && - !isStrUpperUnderDonHighUpperPrev; - - // - bool isStrLowerOverDonLowLower = - conditions.strDownBuffer[cIDX] > conditions.donLowLowerBuffer[cIDX]; - bool isStrLowerOverDonLowLowerPrev = - conditions.strDownBuffer[pIDX] > conditions.donLowLowerBuffer[pIDX]; - bool isStrLowerCrossedOverDonLowLower = isStrLowerOverDonLowLower && - !isStrLowerOverDonLowLowerPrev; - - // - bool isStrLowerUnderDonLowLower = - conditions.strDownBuffer[cIDX] < conditions.donLowLowerBuffer[cIDX]; - bool isStrLowerUnderDonLowLowerPrev = - conditions.strDownBuffer[pIDX] < conditions.donLowLowerBuffer[pIDX]; - bool isStrLowerCrossedUnderDonLowLower = isStrLowerUnderDonLowLower && - !isStrLowerUnderDonLowLowerPrev; - - // - bool isAtrUpperOverPeak = conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX]; - bool isAtrUpperEqualsToPeak = conditions.atrUpperBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - - // - bool isAtrUpperCrossedUpPeak = conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX]); - bool isAtrUpperCrossedDownPeak = conditions.atrUpperBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] < conditions.peaksBuffer[cIDX]); - - // - bool isAtrLowerUnderVale = conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX]; - bool isAtrLowerEqualsToVale = conditions.atrUpperBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isAtrLowerCrossedUpVale = conditions.atrUpperBuffer[cIDX] > conditions.valesBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] > conditions.valesBuffer[cIDX]); - bool isAtrLowerCrossedDownVale = conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX]); - - // - conditions.cheMin = cheMin; - conditions.cheMax = cheMax; - conditions.vwapMin = vwapMin; - conditions.vwapMax = vwapMax; - - // - conditions.isSarIncreased = isSarIncreased; - conditions.isSarDecreased = isSarDecreased; - conditions.isSarEqualsToPeak = isSarEqualsToPeak; - conditions.isSarEqualsToVale = isSarEqualsToVale; - conditions.isStrEqualsToPeak = isStrEqualsToPeak; - conditions.isStrEqualsToVale = isStrEqualsToVale; - conditions.isStrUpperOverPeak = isStrUpperOverPeak; - conditions.isPeakOverAtrUpper = isPeakOverAtrUpper; - conditions.isStrLowerOverVale = isStrLowerOverVale; - conditions.isVWapMinBreakedUp = isVWapMinBreakedUp; - conditions.isVWapMaxBreakedUp = isVWapMaxBreakedUp; - conditions.isBreakedUpPrevSar = isBreakedUpPrevSar; - conditions.isBreakedUpPrevStr = isBreakedUpPrevStr; - conditions.isAtrUpperOverPeak = isAtrUpperOverPeak; - conditions.isAtrLowerUnderVale = isAtrLowerUnderVale; - conditions.isStrLowerUnderVale = isStrLowerUnderVale; - conditions.isStrUpperUnderPeak = isStrUpperUnderPeak; - conditions.isValeUnderAtrLower = isValeUnderAtrLower; - conditions.isClosedOverVWapMin = isClosedOverVWapMin; - conditions.isClosedOverVWapMax = isClosedOverVWapMax; - conditions.isClosedUnderVWapMin = isClosedUnderVWapMin; - conditions.isClosedUnderVWapMax = isClosedUnderVWapMax; - conditions.isVWapMinBreakedDown = isVWapMinBreakedDown; - conditions.isVWapMaxBreakedDown = isVWapMaxBreakedDown; - conditions.isSarCrossedOverVale = isSarCrossedOverVale; - conditions.isStrCrossedOverVale = isStrCrossedOverVale; - conditions.isBreakedDownPrevStr = isBreakedDownPrevStr; - conditions.isBreakedDownPrevSar = isBreakedDownPrevSar; - conditions.isSarCrossedUnderPeak = isSarCrossedUnderPeak; - conditions.isStrCrossedUnderPeak = isStrCrossedUnderPeak; - conditions.isNewPeakOverAtrUpper = isNewPeakOverAtrUpper; - conditions.isBreakedUpPrevCheLE1 = isBreakedUpPrevCheLE1; - conditions.isBreakedUpPrevCheLE2 = isBreakedUpPrevCheLE2; - conditions.isBreakedUpPrevCheSE1 = isBreakedUpPrevCheSE1; - conditions.isBreakedUpPrevCheSE2 = isBreakedUpPrevCheSE2; - conditions.isBreakedUpPrevCheMin = isBreakedUpPrevCheMin; - conditions.isBreakedUpPrevCheMax = isBreakedUpPrevCheMax; - conditions.isAtrUpperEqualsToPeak = isAtrUpperEqualsToPeak; - conditions.isAtrLowerEqualsToVale = isAtrLowerEqualsToVale; - conditions.isNewValeUnderAtrLower = isNewValeUnderAtrLower; - conditions.isStrUpperOverAtrUpper = isStrUpperOverAtrUpper; - conditions.isStrLowerOverAtrLower = isStrLowerOverAtrLower; - conditions.isBreakedDownPrevCheMin = isBreakedDownPrevCheMin; - conditions.isBreakedDownPrevCheMax = isBreakedDownPrevCheMax; - conditions.isBreakedDownPrevCheLE1 = isBreakedDownPrevCheLE1; - conditions.isBreakedDownPrevCheLE2 = isBreakedDownPrevCheLE2; - conditions.isBreakedDownPrevCheSE1 = isBreakedDownPrevCheSE1; - conditions.isBreakedDownPrevCheSE2 = isBreakedDownPrevCheSE2; - conditions.isStrUpperUnderAtrUpper = isStrUpperUnderAtrUpper; - conditions.isStrLowerUnderAtrLower = isStrLowerUnderAtrLower; - conditions.isBreakedUpPrevAtrUpper = isBreakedUpPrevAtrUpper; - conditions.isBreakedUpPrevAtrLower = isBreakedUpPrevAtrLower; - conditions.isAtrUpperCrossedUpPeak = isAtrUpperCrossedUpPeak; - conditions.isAtrLowerCrossedUpVale = isAtrLowerCrossedUpVale; - conditions.isVWapFastCrossedOverMid = isVWapFastCrossedOverMid; - conditions.isRejectedUpPrevAtrUpper = isRejectedUpPrevAtrUpper; - conditions.isRejectedUpPrevAtrLower = isRejectedUpPrevAtrLower; - conditions.isAtrUpperCrossedDownPeak = isAtrUpperCrossedDownPeak; - conditions.isAtrLowerCrossedDownVale = isAtrLowerCrossedDownVale; - conditions.isBreakedDownPrevAtrUpper = isBreakedDownPrevAtrUpper; - conditions.isBreakedDownPrevAtrLower = isBreakedDownPrevAtrLower; - conditions.isVWapFastCrossedUnderMid = isVWapFastCrossedUnderMid; - conditions.isDonLowLowerEqualsToVale = isDonLowLowerEqualsToVale; - conditions.isStrUpperCrossedOverPeak = isStrUpperCrossedOverPeak; - conditions.isStrLowerCrossedOverVale = isStrLowerCrossedOverVale; - conditions.isStrLowerOverDonLowLower = isStrLowerOverDonLowLower; - conditions.isVWapFastCrossedOverSlow = isVWapFastCrossedOverSlow; - conditions.isRejectedDownPrevAtrUpper = isRejectedDownPrevAtrUpper; - conditions.isRejectedDownPrevAtrLower = isRejectedDownPrevAtrLower; - conditions.isVWapFastCrossedUnderSlow = isVWapFastCrossedUnderSlow; - conditions.isStrUpperOverDonHighUpper = isStrUpperOverDonHighUpper; - conditions.isStrLowerUnderDonLowLower = isStrLowerUnderDonLowLower; - conditions.isDonHighUpperEqualsToPeak = isDonHighUpperEqualsToPeak; - conditions.isStrUpperCrossedUnderPeak = isStrUpperCrossedUnderPeak; - conditions.isStrLowerCrossedUnderVale = isStrLowerCrossedUnderVale; - conditions.isStrUpperUnderDonHighUpper = isStrUpperUnderDonHighUpper; - conditions.isStrLowerCrossedOverAtrLower = isStrLowerCrossedOverAtrLower; - conditions.isStrUpperCrossedOverAtrUpper = isStrUpperCrossedOverAtrUpper; - conditions.isStrUpperCrossedUnderAtrUpper = isStrUpperCrossedUnderAtrUpper; - conditions.isStrLowerCrossedUnderAtrLower = isStrLowerCrossedUnderAtrLower; - conditions.isStrLowerCrossedOverDonLowLower = isStrLowerCrossedOverDonLowLower; - conditions.isStrUpperCrossedOverDonHighUpper = isStrUpperCrossedOverDonHighUpper; - conditions.isStrLowerCrossedUnderDonLowLower = isStrLowerCrossedUnderDonLowLower; - conditions.isStrUpperCrossedUnderDonHighUpper = isStrUpperCrossedUnderDonHighUpper; - - // - xpvConditions.Clean(); - xhkConditions.Clean(); - xatrConditions.Clean(); - xstrConditions.Clean(); - xcheConditions.Clean(); - xdonConditions.Clean(); - xvwapConditions.Clean(); - xtrendConditions.Clean(); - - // - Free(); + // // + // if (loopback < 5) + // { + // loopback = 5; + // } + + // // + // conditions.Clean(); + + // // + // conditions.symbol = mSymbol; + // conditions.period = mPeriod; + // conditions.time = TimeCurrent(); + + // // + // int zIndex = barIndex; + // int cIndex = zIndex + 1; + // int pIndex = cIndex + 1; + // int ppIndex = pIndex + 1; + + // // + // XOHCL zBar; + // result = zBar.Init( + // mSymbol, + // mPeriod, + // zIndex // + // ); + // if (!result) + // { + // return result; + // } + + // // + // XOHCL cBar; + // result = cBar.Init( + // mSymbol, + // mPeriod, + // cIndex // + // ); + // if (!result) + // { + // return result; + // } + + // // + // XOHCL pBar; + // result = pBar.Init( + // mSymbol, + // mPeriod, + // pIndex // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XPV ... + // X121XPVConditions xpvConditions; + // result = GetPVConditions( + // xpvConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XHK ... + // X121XHKConditions xhkConditions; + // result = GetHKConditions( + // xhkConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XATR ... + // X121XATRConditions xatrConditions; + // result = GetATRConditions( + // xatrConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XSTR ... + // X121XSTRConditions xstrConditions; + // result = GetSTRConditions( + // xstrConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XCHE ... + // X121XCHEConditions xcheConditions; + // result = GetCHEConditions( + // xcheConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XDON ... + // X121XDONConditions xdonConditions; + // result = GetDONConditions( + // xdonConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XVWAP ... + // X121XVWAPConditions xvwapConditions; + // result = GetVWAPConditions( + // xvwapConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XTREND ... + // X121XTRENDConditions xtrendConditions; + // result = GetTrendConditions( + // xtrendConditions, + // barIndex, + // loopback // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // Fill Volume Buffer ... + // for (int i = barIndex; i < barIndex + loopback; i++) + // { + // // + // // Reading Bar Valuem ... + // long iVol = iVolume( + // mSymbol, + // mPeriod, + // i // + // ); + + // // + // Add( + // iVol, + // conditions.volumeBuffer // + // ); + // } + + // // + // // Fill X121 Conditions Reference by Using + // // Retrieved Conditions ... + + // // + // int cIDX = 1; + // int pIDX = cIDX + 1; + + // // + // // XPV ... + + // // + // // Buffers ... + + // // + // Copy( + // xpvConditions.peaksBuffer, + // conditions.peaksBuffer // + // ); + + // // + // Copy( + // xpvConditions.valesBuffer, + // conditions.valesBuffer // + // ); + + // // + // Copy( + // xpvConditions.sarBuffer, + // conditions.sarBuffer // + // ); + + // // + // Copy( + // xpvConditions.cHHBuffer, + // conditions.cHHBuffer // + // ); + + // // + // Copy( + // xpvConditions.cLLBuffer, + // conditions.cLLBuffer // + // ); + + // // + // Copy( + // xpvConditions.sHHBuffer, + // conditions.sHHBuffer // + // ); + + // // + // Copy( + // xpvConditions.sLLBuffer, + // conditions.sLLBuffer // + // ); + + // // + // Copy( + // xpvConditions.mHHBuffer, + // conditions.mHHBuffer // + // ); + + // // + // Copy( + // xpvConditions.mLLBuffer, + // conditions.mLLBuffer // + // ); + + // // + // Copy( + // xpvConditions.lHHBuffer, + // conditions.lHHBuffer // + // ); + + // // + // Copy( + // xpvConditions.lLLBuffer, + // conditions.lLLBuffer // + // ); + + // // + // Copy( + // xpvConditions.hHHBuffer, + // conditions.hHHBuffer // + // ); + + // // + // Copy( + // xpvConditions.hLLBuffer, + // conditions.hLLBuffer // + // ); + + // // + // // Conditions ... + + // // + // conditions.isNewPeak = xpvConditions.isNewPeak; + // conditions.isNewVale = xpvConditions.isNewVale; + // conditions.isSarBullish = xpvConditions.isSarBullish; + // conditions.isSarBearish = xpvConditions.isSarBearish; + // conditions.isNewPeakOverLast = xpvConditions.isNewPeakOverLast; + // conditions.isNewValeOverLast = xpvConditions.isNewValeOverLast; + // conditions.isNewPeakUnderLast = xpvConditions.isNewPeakUnderLast; + // conditions.isNewValeUnderLast = xpvConditions.isNewValeUnderLast; + // conditions.isRejectedPrevVale = xpvConditions.isRejectedPrevVale; + // conditions.isRejectedPrevPeak = xpvConditions.isRejectedPrevPeak; + // conditions.isBreakedUpPrevPeak = xpvConditions.isBreakedUpPrevPeak; + // conditions.isBreakedDownPrevVale = xpvConditions.isBreakedDownPrevVale; + // conditions.isSarSwitchedToBullish = xpvConditions.isSarSwitchedToBullish; + // conditions.isSarSwitchedToBearish = xpvConditions.isSarSwitchedToBearish; + + // // + // // XHK ... + + // // + // // Buffers ... + + // // + // Copy( + // xhkConditions.xhkRawOpenBuffer, + // conditions.xhkRawOpenBuffer // + // ); + + // // + // Copy( + // xhkConditions.xhkRawHighBuffer, + // conditions.xhkRawHighBuffer // + // ); + + // // + // Copy( + // xhkConditions.xhkRawLowBuffer, + // conditions.xhkRawLowBuffer // + // ); + + // // + // Copy( + // xhkConditions.xhkRawCloseBuffer, + // conditions.xhkRawCloseBuffer // + // ); + + // // + // Copy( + // xhkConditions.xhkSMOpenBuffer, + // conditions.xhkSMOpenBuffer // + // ); + + // // + // Copy( + // xhkConditions.xhkSMHighBuffer, + // conditions.xhkSMHighBuffer // + // ); + + // // + // Copy( + // xhkConditions.xhkSMLowBuffer, + // conditions.xhkSMLowBuffer // + // ); + + // // + // Copy( + // xhkConditions.xhkSMCloseBuffer, + // conditions.xhkSMCloseBuffer // + // ); + + // // + // // Conditions ... + // conditions.isSMHKBullish = xhkConditions.isSMHKBullish; + // conditions.isRawHKBullish = xhkConditions.isRawHKBullish; + // conditions.isSMHKBearish = xhkConditions.isSMHKBearish; + // conditions.isRawHKBearish = xhkConditions.isRawHKBearish; + // conditions.isBreakedUpSMHK = xhkConditions.isBreakedUpSMHK; + // conditions.isBreakedUpRawHK = xhkConditions.isBreakedUpRawHK; + // conditions.isRejectedUpSMHK = xhkConditions.isRejectedUpSMHK; + // conditions.isClosedOverSMHK = xhkConditions.isClosedOverSMHK; + // conditions.isRejectedUpRawHK = xhkConditions.isRejectedUpRawHK; + // conditions.isBreakedDownSMHK = xhkConditions.isBreakedDownSMHK; + // conditions.isClosedUnderSMHK = xhkConditions.isClosedUnderSMHK; + // conditions.isClosedOverRawHK = xhkConditions.isClosedOverRawHK; + // conditions.isClosedUnderRawHK = xhkConditions.isClosedUnderRawHK; + // conditions.isBreakedDownRawHK = xhkConditions.isBreakedDownRawHK; + // conditions.isRejectedDownSMHK = xhkConditions.isRejectedDownSMHK; + // conditions.isRejectedDownRawHK = xhkConditions.isRejectedDownRawHK; + // conditions.isRawHKBreakedUpSMHK = xhkConditions.isRawHKBreakedUpSMHK; + // conditions.isRawHKClosedOverSMHK = xhkConditions.isRawHKClosedOverSMHK; + // conditions.isSMHKSwitchedToBearish = xhkConditions.isSMHKSwitchedToBearish; + // conditions.isRawHKSwitchedToBearish = xhkConditions.isRawHKSwitchedToBearish; + // conditions.isRawHKClosedUnderSMHK = xhkConditions.isRawHKClosedUnderSMHK; + // conditions.isRawHKBreakedDownSMHK = xhkConditions.isRawHKBreakedDownSMHK; + // conditions.isSMHKSwitchedToBullish = xhkConditions.isSMHKSwitchedToBullish; + // conditions.isRawHKSwitchedToBullish = xhkConditions.isRawHKSwitchedToBullish; + + // // + // // XTREND ... + + // // + // // Buffers ... + + // // + // Copy( + // xtrendConditions.upTrendBuffer, + // conditions.upTrendBuffer // + // ); + + // // + // Copy( + // xtrendConditions.downTrendBuffer, + // conditions.downTrendBuffer // + // ); + + // // + // Copy( + // xtrendConditions.maBuffer, + // conditions.maBuffer // + // ); + + // // + // Copy( + // xtrendConditions.adxBuffer, + // conditions.adxBuffer // + // ); + + // // + // Copy( + // xtrendConditions.adxPBuffer, + // conditions.adxPBuffer // + // ); + + // // + // Copy( + // xtrendConditions.adxMBuffer, + // conditions.adxMBuffer // + // ); + + // // + // Copy( + // xtrendConditions.upTBuffer, + // conditions.upTBuffer // + // ); + + // // + // Copy( + // xtrendConditions.downTBuffer, + // conditions.downTBuffer // + // ); + + // // + // conditions.isTrendBullish = xtrendConditions.isTrendBullish; + // conditions.isTrendBearish = xtrendConditions.isTrendBearish; + // conditions.isTrendSwitchedToBullish = xtrendConditions.isTrendSwitchedToBullish; + // conditions.isTrendSwitchedToBearish = xtrendConditions.isTrendSwitchedToBearish; + + // // + // // XATR ... + + // // + // // Buffers ... + + // // + // Copy( + // xatrConditions.atrUpperBuffer, + // conditions.atrUpperBuffer // + // ); + + // // + // Copy( + // xatrConditions.atrLowerBuffer, + // conditions.atrLowerBuffer // + // ); + + // // + // Copy( + // xatrConditions.atrUpperRawBuffer, + // conditions.atrUpperRawBuffer // + // ); + + // // + // Copy( + // xatrConditions.atrLowerRawBuffer, + // conditions.atrLowerRawBuffer // + // ); + + // // + // Copy( + // xatrConditions.atrBuffer, + // conditions.atrBuffer // + // ); + + // // + // Copy( + // xatrConditions.rsiBuffer, + // conditions.rsiBuffer // + // ); + + // // + // // Conditions ... + + // // + // conditions.isRsiOverSold = xatrConditions.isRsiOverSold; + // conditions.isRsiOverBought = xatrConditions.isRsiOverBought; + // conditions.isBreakedUpAtrUpper = xatrConditions.isBreakedUpAtrUpper; + // conditions.isBreakedUpAtrLower = xatrConditions.isBreakedUpAtrLower; + // conditions.isClosedOverAtrUpper = xatrConditions.isClosedOverAtrUpper; + // conditions.isRejectedUpAtrUpper = xatrConditions.isRejectedUpAtrUpper; + // conditions.isRejectedUpAtrLower = xatrConditions.isRejectedUpAtrLower; + // conditions.isClosedOverAtrLower = xatrConditions.isClosedOverAtrLower; + // conditions.isBreakedDownAtrUpper = xatrConditions.isBreakedDownAtrUpper; + // conditions.isBreakedDownAtrLower = xatrConditions.isBreakedDownAtrLower; + // conditions.isClosedUnderAtrUpper = xatrConditions.isClosedUnderAtrUpper; + // conditions.isClosedUnderAtrLower = xatrConditions.isClosedUnderAtrLower; + // conditions.isRejectedDownAtrUpper = xatrConditions.isRejectedDownAtrUpper; + // conditions.isRejectedDownAtrLower = xatrConditions.isRejectedDownAtrLower; + // conditions.isRsiCrossedOverOverSold = xatrConditions.isRsiCrossedOverOverSold; + // conditions.isRsiCrossedUnderOverSold = xatrConditions.isRsiCrossedUnderOverSold; + // conditions.isRsiCrossedOverOverBought = xatrConditions.isRsiCrossedOverOverBought; + // conditions.isRsiCrossedUnderOverBought = xatrConditions.isRsiCrossedUnderOverBought; + + // // + // // XSTR ... + + // // + // // Buffers ... + + // // + // Copy( + // xstrConditions.strBuffer, + // conditions.strBuffer // + // ); + + // // + // Copy( + // xstrConditions.strPriceBuffer, + // conditions.strPriceBuffer // + // ); + + // // + // Copy( + // xstrConditions.strUpBuffer, + // conditions.strUpBuffer // + // ); + + // // + // Copy( + // xstrConditions.strDownBuffer, + // conditions.strDownBuffer // + // ); + + // // + // Copy( + // xstrConditions.strStateBuffer, + // conditions.strStateBuffer // + // ); + + // // + // // Conditions ... + + // // + // conditions.isStrBullish = xstrConditions.isStrBullish; + // conditions.isStrBearish = xstrConditions.isStrBearish; + // conditions.isStrSwitchedToBullish = xstrConditions.isStrSwitchedToBullish; + // conditions.isStrSwitchedToBearish = xstrConditions.isStrSwitchedToBearish; + + // // + // // XCHE ... + + // // + // // Buffers ... + + // // + // Copy( + // xcheConditions.le1Buffer, + // conditions.le1Buffer // + // ); + + // // + // Copy( + // xcheConditions.se1Buffer, + // conditions.se1Buffer // + // ); + + // // + // Copy( + // xcheConditions.le2Buffer, + // conditions.le2Buffer // + // ); + + // // + // Copy( + // xcheConditions.se2Buffer, + // conditions.se2Buffer // + // ); + + // // + // Copy( + // xcheConditions.le1StartBuffer, + // conditions.le1StartBuffer // + // ); + + // // + // Copy( + // xcheConditions.se1StartBuffer, + // conditions.se1StartBuffer // + // ); + + // // + // Copy( + // xcheConditions.le2StartBuffer, + // conditions.le2StartBuffer // + // ); + + // // + // Copy( + // xcheConditions.se2StartBuffer, + // conditions.se2StartBuffer // + // ); + + // // + // // Conditions ... + + // conditions.isCheBullish = xcheConditions.isCheBullish; + // conditions.isCheBearish = xcheConditions.isCheBearish; + // conditions.isChe1Bullish = xcheConditions.isChe1Bullish; + // conditions.isChe1Bearish = xcheConditions.isChe1Bearish; + // conditions.isChe2Bullish = xcheConditions.isChe2Bullish; + // conditions.isChe2Bearish = xcheConditions.isChe2Bearish; + // conditions.isClosedOverCheMin = xcheConditions.isClosedOverCheMin; + // conditions.isClosedOverCheMax = xcheConditions.isClosedOverCheMax; + // conditions.isClosedUnderCheMin = xcheConditions.isClosedUnderCheMin; + // conditions.isClosedUnderCheMax = xcheConditions.isClosedUnderCheMax; + // conditions.isCheSwitchedToBullish = xcheConditions.isCheSwitchedToBullish; + // conditions.isCheSwitchedToBearish = xcheConditions.isCheSwitchedToBearish; + // conditions.isChe1SwitchedToBullish = xcheConditions.isChe1SwitchedToBullish; + // conditions.isChe1SwitchedToBearish = xcheConditions.isChe1SwitchedToBearish; + // conditions.isChe2SwitchedToBullish = xcheConditions.isChe2SwitchedToBullish; + // conditions.isChe2SwitchedToBearish = xcheConditions.isChe2SwitchedToBearish; + + // // + // // XDON ... + + // // + // // Buffers ... + + // // + // Copy( + // xdonConditions.donOpenUpperBuffer, + // conditions.donOpenUpperBuffer // + // ); + + // // + // Copy( + // xdonConditions.donOpenLowerBuffer, + // conditions.donOpenLowerBuffer // + // ); + + // // + // Copy( + // xdonConditions.donHighUpperBuffer, + // conditions.donHighUpperBuffer // + // ); + + // // + // Copy( + // xdonConditions.donHighLowerBuffer, + // conditions.donHighLowerBuffer // + // ); + + // // + // Copy( + // xdonConditions.donLowUpperBuffer, + // conditions.donLowUpperBuffer // + // ); + + // // + // Copy( + // xdonConditions.donLowLowerBuffer, + // conditions.donLowLowerBuffer // + // ); + + // // + // Copy( + // xdonConditions.donCloseUpperBuffer, + // conditions.donCloseUpperBuffer // + // ); + + // // + // Copy( + // xdonConditions.donCloseLowerBuffer, + // conditions.donCloseLowerBuffer // + // ); + + // // + // // Conditions ... + + // // + // conditions.isBreakedDonLowUpper = xdonConditions.isBreakedDonLowUpper; + // conditions.isBreakedDonLowLower = xdonConditions.isBreakedDonLowLower; + // conditions.isRejectedDonLowUpper = xdonConditions.isRejectedDonLowUpper; + // conditions.isRejectedDonLowLower = xdonConditions.isRejectedDonLowLower; + // conditions.isBreakedDonOpenUpper = xdonConditions.isBreakedDonOpenUpper; + // conditions.isBreakedDonHighUpper = xdonConditions.isBreakedDonHighUpper; + // conditions.isBreakedDonOpenLower = xdonConditions.isBreakedDonOpenLower; + // conditions.isBreakedDonHighLower = xdonConditions.isBreakedDonHighLower; + // conditions.isRejectedDonOpenUpper = xdonConditions.isRejectedDonOpenUpper; + // conditions.isRejectedDonHighUpper = xdonConditions.isRejectedDonHighUpper; + // conditions.isRejectedDonOpenLower = xdonConditions.isRejectedDonOpenLower; + // conditions.isRejectedDonHighLower = xdonConditions.isRejectedDonHighLower; + // conditions.isBreakedDonCloseUpper = xdonConditions.isBreakedDonCloseUpper; + // conditions.isBreakedDonCloseLower = xdonConditions.isBreakedDonCloseLower; + // conditions.isRejectedDonCloseUpper = xdonConditions.isRejectedDonCloseUpper; + // conditions.isRejectedDonCloseLower = xdonConditions.isRejectedDonCloseLower; + + // // + // // XVWAP ... + + // // + // // Buffers ... + + // // + // Copy( + // xvwapConditions.vwapFastBuffer, + // conditions.vwapFastBuffer // + // ); + + // // + // Copy( + // xvwapConditions.vwapMidBuffer, + // conditions.vwapMidBuffer // + // ); + + // // + // Copy( + // xvwapConditions.vwapSlowBuffer, + // conditions.vwapSlowBuffer // + // ); + + // // + // Copy( + // xvwapConditions.vwapVolumeBuffer, + // conditions.vwapVolumeBuffer // + // ); + + // // + // Copy( + // xvwapConditions.vwapPriceBuffer, + // conditions.vwapPriceBuffer // + // ); + + // // + // Copy( + // xvwapConditions.vwapFastStateBuffer, + // conditions.vwapFastStateBuffer // + // ); + + // // + // Copy( + // xvwapConditions.vwapMidStateBuffer, + // conditions.vwapMidStateBuffer // + // ); + + // // + // Copy( + // xvwapConditions.vwapSlowStateBuffer, + // conditions.vwapSlowStateBuffer // + // ); + + // // + // // Conditions ... + + // // + // conditions.isVWapMidBullish = xvwapConditions.isVWapMidBullish; + // conditions.isVWapMidBearish = xvwapConditions.isVWapMidBearish; + // conditions.isVWapFastBullish = xvwapConditions.isVWapFastBullish; + // conditions.isVWapFastBearish = xvwapConditions.isVWapFastBearish; + // conditions.isVWapMidNeutural = xvwapConditions.isVWapMidNeutural; + // conditions.isVWapSlowBullish = xvwapConditions.isVWapSlowBullish; + // conditions.isVWapSlowBearish = xvwapConditions.isVWapSlowBearish; + // conditions.isVWapFastOverMid = xvwapConditions.isVWapFastOverMid; + // conditions.isVWapMidOverSlow = xvwapConditions.isVWapMidOverSlow; + // conditions.isVWapFastNeutural = xvwapConditions.isVWapFastNeutural; + // conditions.isVWapSlowNeutural = xvwapConditions.isVWapSlowNeutural; + // conditions.isVWapFastUnderMid = xvwapConditions.isVWapFastUnderMid; + // conditions.isVWapMidUnderSlow = xvwapConditions.isVWapMidUnderSlow; + // conditions.isVWapBullishState = xvwapConditions.isVWapBullishState; + // conditions.isVWapBearishState = xvwapConditions.isVWapBearishState; + // conditions.isVWapNeuturalState = xvwapConditions.isVWapNeuturalState; + // conditions.isVWapBullishOrdered = xvwapConditions.isVWapBullishOrdered; + // conditions.isVWapBearishOrdered = xvwapConditions.isVWapBearishOrdered; + // conditions.isVWapSwitchedToBullishState = xvwapConditions.isVWapSwitchedToBullishState; + // conditions.isVWapSwitchedToBearishState = xvwapConditions.isVWapSwitchedToBearishState; + // conditions.isVWapSwitchedToNeuturalState = xvwapConditions.isVWapSwitchedToNeuturalState; + // conditions.isVWapSwitchedToBullishOrdered = xvwapConditions.isVWapSwitchedToBullishOrdered; + // conditions.isVWapSwitchedToBearishOrdered = xvwapConditions.isVWapSwitchedToBearishOrdered; + + // // + // // Slopes ... + + // // + // double rsiSlope = GetSlope(conditions.rsiBuffer, pIDX, cIDX); + // double strSlope = GetSlope(conditions.strBuffer, pIDX, cIDX); + // double atrUpperSlope = GetSlope(conditions.atrUpperBuffer, pIDX, cIDX); + // double atrLowerSlope = GetSlope(conditions.atrLowerBuffer, pIDX, cIDX); + // double vwapFastSlope = GetSlope(conditions.vwapFastBuffer, pIDX, cIDX); + // double vwapMidSlope = GetSlope(conditions.vwapMidBuffer, pIDX, cIDX); + // double vwapSlowSlope = GetSlope(conditions.vwapSlowBuffer, pIDX, cIDX); + + // // + // bool isRsiSlopeBullish = rsiSlope > 0; + // bool isStrSlopeBullish = strSlope > 0; + // bool isAtrUpperSlopeBullish = atrUpperSlope > 0; + // bool isAtrLowerSlopeBullish = atrLowerSlope > 0; + // bool isVwapFastSlopeBullish = vwapFastSlope > 0; + // bool isVwapMidSlopeBullish = vwapMidSlope > 0; + // bool isVwapSlowSlopeBullish = vwapSlowSlope > 0; + + // // + // bool isRsiSlopeBearish = rsiSlope < 0; + // bool isStrSlopeBearish = strSlope < 0; + // bool isAtrUpperSlopeBearish = atrUpperSlope < 0; + // bool isAtrLowerSlopeBearish = atrLowerSlope < 0; + // bool isVwapFastSlopeBearish = vwapFastSlope < 0; + // bool isVwapMidSlopeBearish = vwapMidSlope < 0; + // bool isVwapSlowSlopeBearish = vwapSlowSlope < 0; + + // // + // conditions.rsiSlope = rsiSlope; + // conditions.strSlope = strSlope; + // conditions.vwapMidSlope = vwapMidSlope; + // conditions.vwapSlowSlope = vwapSlowSlope; + // conditions.atrUpperSlope = atrUpperSlope; + // conditions.atrLowerSlope = atrLowerSlope; + // conditions.vwapFastSlope = vwapFastSlope; + // conditions.isRsiSlopeBearish = isRsiSlopeBearish; + // conditions.isStrSlopeBearish = isStrSlopeBearish; + // conditions.isRsiSlopeBullish = isRsiSlopeBullish; + // conditions.isStrSlopeBullish = isStrSlopeBullish; + // conditions.isVwapMidSlopeBearish = isVwapMidSlopeBearish; + // conditions.isVwapMidSlopeBullish = isVwapMidSlopeBullish; + // conditions.isAtrUpperSlopeBearish = isAtrUpperSlopeBearish; + // conditions.isAtrLowerSlopeBearish = isAtrLowerSlopeBearish; + // conditions.isVwapFastSlopeBearish = isVwapFastSlopeBearish; + // conditions.isVwapSlowSlopeBearish = isVwapSlowSlopeBearish; + // conditions.isAtrUpperSlopeBullish = isAtrUpperSlopeBullish; + // conditions.isAtrLowerSlopeBullish = isAtrLowerSlopeBullish; + // conditions.isVwapFastSlopeBullish = isVwapFastSlopeBullish; + // conditions.isVwapSlowSlopeBullish = isVwapSlowSlopeBullish; + + // // + // // Complex Conditions ... + + // // + // double vwapFast = conditions.vwapFastBuffer[cIDX]; + // double vwapMid = conditions.vwapMidBuffer[cIDX]; + // double vwapSlow = conditions.vwapSlowBuffer[cIDX]; + + // // + // double vwaps[3] = { + // vwapFast, + // vwapMid, + // vwapSlow // + // }; + + // // + // double vwapMin = GetMin(vwaps); + // double vwapMax = GetMax(vwaps); + + // // + // bool isVWapMinBreakedUp = IsBarBreak( + // vwapMin, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isVWapMinBreakedDown = IsBarBreak( + // vwapMin, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isVWapMaxBreakedUp = IsBarBreak( + // vwapMax, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isVWapMaxBreakedDown = IsBarBreak( + // vwapMax, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isVWapFatsOverMid = conditions.vwapFastBuffer[cIDX] > conditions.vwapMidBuffer[cIDX]; + // bool isVWapFatsOverMidPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapMidBuffer[pIDX]; + + // // + // bool isVWapFatsUnderMid = conditions.vwapFastBuffer[cIDX] < conditions.vwapMidBuffer[cIDX]; + // bool isVWapFatsUnderMidPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapMidBuffer[pIDX]; + + // // + // bool isVWapFatsOverSlow = conditions.vwapFastBuffer[cIDX] > conditions.vwapSlowBuffer[cIDX]; + // bool isVWapFatsOverSlowPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapSlowBuffer[pIDX]; + + // // + // bool isVWapFatsUnderSlow = conditions.vwapFastBuffer[cIDX] < conditions.vwapSlowBuffer[cIDX]; + // bool isVWapFatsUnderSlowPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapSlowBuffer[pIDX]; + + // // + // bool isVWapFastCrossedOverMid = isVWapFatsOverMid && + // !isVWapFatsOverMidPrev; + // bool isVWapFastCrossedUnderMid = isVWapFatsUnderMid && + // !isVWapFatsUnderMidPrev; + + // // + // bool isVWapFastCrossedOverSlow = isVWapFatsOverSlow && + // !isVWapFatsOverSlowPrev; + // bool isVWapFastCrossedUnderSlow = isVWapFatsUnderSlow && + // !isVWapFatsUnderSlowPrev; + + // // + // bool isClosedOverVWapMin = cBar.close > vwapMin; + // bool isClosedUnderVWapMin = cBar.close < vwapMin; + + // // + // bool isClosedOverVWapMax = cBar.close > vwapMax; + // bool isClosedUnderVWapMax = cBar.close < vwapMax; + + // // + // bool isSarEqualsToPeak = + // conditions.sarBuffer[cIDX] == conditions.peaksBuffer[cIDX]; + // bool isSarEqualsToVale = + // conditions.sarBuffer[cIDX] == conditions.valesBuffer[cIDX]; + + // // + // bool isSarIncreased = conditions.sarBuffer[cIDX] > conditions.sarBuffer[pIDX]; + // bool isSarDecreased = conditions.sarBuffer[cIDX] < conditions.sarBuffer[pIDX]; + + // // + // double prevSar = conditions.sarBuffer[pIDX]; + // double prevStr = conditions.strBuffer[pIDX]; + // double prevCheLE1 = conditions.le1Buffer[pIDX]; + // double prevCheLE2 = conditions.le2Buffer[pIDX]; + // double prevCheSE1 = conditions.se1Buffer[pIDX]; + // double prevCheSE2 = conditions.se2Buffer[pIDX]; + // double prevAtrUpper = conditions.atrUpperBuffer[pIDX]; + // double prevAtrLower = conditions.atrLowerBuffer[pIDX]; + + // // + // double ches[]; + // if (prevCheLE1 != EMPTY_VALUE) + // { + // // + // Add( + // prevCheLE1, + // ches // + // ); + // } + // if (prevCheLE2 != EMPTY_VALUE) + // { + // // + // Add( + // prevCheLE2, + // ches // + // ); + // } + // if (prevCheSE1 != EMPTY_VALUE) + // { + // // + // Add( + // prevCheSE1, + // ches // + // ); + // } + // if (prevCheSE2 != EMPTY_VALUE) + // { + // // + // Add( + // prevCheSE2, + // ches // + // ); + // } + + // // + // double cheMin = GetMin(ches); + // double cheMax = GetMax(ches); + + // // + // bool isBreakedUpPrevSar = IsBarBreak( + // prevSar, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedDownPrevSar = IsBarBreak( + // prevSar, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isBreakedUpPrevStr = IsBarBreak( + // prevStr, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedDownPrevStr = IsBarBreak( + // prevStr, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isRejectedUpPrevAtrUpper = IsBarReject( + // prevAtrUpper, + // X_DIRECTION_BULLISH, + // cBar // + // ); + + // // + // bool isRejectedDownPrevAtrUpper = IsBarReject( + // prevAtrUpper, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isRejectedUpPrevAtrLower = IsBarReject( + // prevAtrLower, + // X_DIRECTION_BULLISH, + // cBar // + // ); + + // // + // bool isRejectedDownPrevAtrLower = IsBarReject( + // prevAtrLower, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isBreakedUpPrevAtrUpper = IsBarBreak( + // prevAtrUpper, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedDownPrevAtrUpper = IsBarBreak( + // prevAtrUpper, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isBreakedUpPrevAtrLower = IsBarBreak( + // prevAtrLower, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedDownPrevAtrLower = IsBarBreak( + // prevAtrLower, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isBreakedUpPrevCheLE1 = IsBarBreak( + // prevCheLE1, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedUpPrevCheLE2 = IsBarBreak( + // prevCheLE2, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedUpPrevCheSE1 = IsBarBreak( + // prevCheSE1, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedUpPrevCheSE2 = IsBarBreak( + // prevCheSE2, + // X_DIRECTION_BULLISH, + // cBar // + // ); + + // // + // bool isBreakedDownPrevCheLE1 = IsBarBreak( + // prevCheLE1, + // X_DIRECTION_BEARISH, + // cBar // + // ); + // bool isBreakedDownPrevCheLE2 = IsBarBreak( + // prevCheLE2, + // X_DIRECTION_BEARISH, + // cBar // + // ); + // bool isBreakedDownPrevCheSE1 = IsBarBreak( + // prevCheSE1, + // X_DIRECTION_BEARISH, + // cBar // + // ); + // bool isBreakedDownPrevCheSE2 = IsBarBreak( + // prevCheSE2, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isBreakedUpPrevCheMin = IsBarBreak( + // cheMin, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedDownPrevCheMin = IsBarBreak( + // cheMin, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isBreakedUpPrevCheMax = IsBarBreak( + // cheMax, + // X_DIRECTION_BULLISH, + // cBar // + // ); + // bool isBreakedDownPrevCheMax = IsBarBreak( + // cheMax, + // X_DIRECTION_BEARISH, + // cBar // + // ); + + // // + // bool isSarCrossedUnderPeak = + // conditions.sarBuffer[cIDX] < conditions.peaksBuffer[cIDX] && + // !(conditions.sarBuffer[pIDX] < conditions.peaksBuffer[pIDX]); + // bool isSarCrossedOverVale = + // conditions.sarBuffer[cIDX] > conditions.valesBuffer[cIDX] && + // !(conditions.sarBuffer[pIDX] > conditions.valesBuffer[pIDX]); + + // // + // bool isStrEqualsToPeak = + // conditions.strBuffer[cIDX] == conditions.peaksBuffer[cIDX]; + // bool isStrEqualsToVale = + // conditions.strBuffer[cIDX] == conditions.valesBuffer[cIDX]; + + // // + // bool isStrCrossedUnderPeak = + // conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX] && + // !(conditions.strBuffer[pIDX] < conditions.peaksBuffer[pIDX]); + // bool isStrCrossedOverVale = + // conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX] && + // !(conditions.strBuffer[pIDX] > conditions.valesBuffer[pIDX]); + + // // + // bool isPeakOverAtrUpper = + // conditions.peaksBuffer[cIDX] > conditions.atrUpperBuffer[cIDX]; + // bool isValeUnderAtrLower = + // conditions.valesBuffer[cIDX] > conditions.atrLowerBuffer[cIDX]; + + // // + // bool isNewPeakOverAtrUpper = + // isPeakOverAtrUpper && + // conditions.isNewPeak; + // bool isNewValeUnderAtrLower = + // isValeUnderAtrLower && + // conditions.isNewVale; + + // // + // bool isStrUpperOverPeak = + // conditions.strBuffer[cIDX] > conditions.peaksBuffer[cIDX]; + // bool isStrUpperOverPeakPrev = + // conditions.strBuffer[pIDX] > conditions.peaksBuffer[pIDX]; + + // // + // bool isStrUpperUnderPeak = + // conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX]; + // bool isStrUpperUnderPeakPrev = + // conditions.strBuffer[pIDX] < conditions.peaksBuffer[pIDX]; + + // // + // bool isStrUpperCrossedOverPeak = isStrUpperOverPeak && + // !isStrUpperOverPeakPrev; + // bool isStrUpperCrossedUnderPeak = isStrUpperUnderPeak && + // !isStrUpperUnderPeakPrev; + + // // + // bool isStrLowerOverVale = + // conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX]; + // bool isStrLowerOverValePrev = + // conditions.strBuffer[pIDX] > conditions.valesBuffer[pIDX]; + + // // + // bool isStrLowerUnderVale = + // conditions.strBuffer[cIDX] < conditions.valesBuffer[cIDX]; + // bool isStrLowerUnderValePrev = + // conditions.strBuffer[pIDX] < conditions.valesBuffer[pIDX]; + + // // + // bool isStrLowerCrossedOverVale = isStrLowerOverVale && + // !isStrLowerOverValePrev; + // bool isStrLowerCrossedUnderVale = isStrLowerUnderVale && + // !isStrLowerUnderValePrev; + + // // + // bool isDonHighUpperEqualsToPeak = + // conditions.donHighUpperBuffer[cIDX] == conditions.peaksBuffer[cIDX]; + // bool isDonLowLowerEqualsToVale = + // conditions.donLowLowerBuffer[cIDX] == conditions.valesBuffer[cIDX]; + + // // + // bool isStrUpperOverAtrUpper = + // conditions.strUpBuffer[cIDX] > conditions.atrUpperBuffer[cIDX]; + // bool isStrUpperOverAtrUpperPrev = + // conditions.strUpBuffer[pIDX] > conditions.atrUpperBuffer[pIDX]; + // bool isStrUpperCrossedOverAtrUpper = isStrUpperOverAtrUpper && + // !isStrUpperOverAtrUpperPrev; + + // // + // bool isStrUpperUnderAtrUpper = + // conditions.strUpBuffer[cIDX] < conditions.atrUpperBuffer[cIDX]; + // bool isStrUpperUnderAtrUpperPrev = + // conditions.strUpBuffer[pIDX] < conditions.atrUpperBuffer[pIDX]; + // bool isStrUpperCrossedUnderAtrUpper = isStrUpperUnderAtrUpper && + // !isStrUpperUnderAtrUpperPrev; + + // // + // bool isStrLowerOverAtrLower = + // conditions.strDownBuffer[cIDX] > conditions.atrLowerBuffer[cIDX]; + // bool isStrLowerOverAtrLowerPrev = + // conditions.strDownBuffer[pIDX] > conditions.atrLowerBuffer[pIDX]; + // bool isStrLowerCrossedOverAtrLower = isStrLowerOverAtrLower && + // !isStrLowerOverAtrLowerPrev; + + // // + // bool isStrLowerUnderAtrLower = + // conditions.strDownBuffer[cIDX] < conditions.atrLowerBuffer[cIDX]; + // bool isStrLowerUnderAtrLowerPrev = + // conditions.strDownBuffer[pIDX] < conditions.atrLowerBuffer[pIDX]; + // bool isStrLowerCrossedUnderAtrLower = isStrLowerUnderAtrLower && + // !isStrLowerUnderAtrLowerPrev; + + // // + // bool isStrUpperOverDonHighUpper = + // conditions.strUpBuffer[cIDX] > conditions.donHighUpperBuffer[cIDX]; + // bool isStrUpperOverDonHighUpperPrev = + // conditions.strUpBuffer[pIDX] > conditions.donHighUpperBuffer[pIDX]; + // bool isStrUpperCrossedOverDonHighUpper = isStrUpperOverDonHighUpper && + // !isStrUpperOverDonHighUpperPrev; + + // // + // bool isStrUpperUnderDonHighUpper = + // conditions.strUpBuffer[cIDX] < conditions.donHighUpperBuffer[cIDX]; + // bool isStrUpperUnderDonHighUpperPrev = + // conditions.strUpBuffer[pIDX] < conditions.donHighUpperBuffer[pIDX]; + // bool isStrUpperCrossedUnderDonHighUpper = isStrUpperUnderDonHighUpper && + // !isStrUpperUnderDonHighUpperPrev; + + // // + // bool isStrLowerOverDonLowLower = + // conditions.strDownBuffer[cIDX] > conditions.donLowLowerBuffer[cIDX]; + // bool isStrLowerOverDonLowLowerPrev = + // conditions.strDownBuffer[pIDX] > conditions.donLowLowerBuffer[pIDX]; + // bool isStrLowerCrossedOverDonLowLower = isStrLowerOverDonLowLower && + // !isStrLowerOverDonLowLowerPrev; + + // // + // bool isStrLowerUnderDonLowLower = + // conditions.strDownBuffer[cIDX] < conditions.donLowLowerBuffer[cIDX]; + // bool isStrLowerUnderDonLowLowerPrev = + // conditions.strDownBuffer[pIDX] < conditions.donLowLowerBuffer[pIDX]; + // bool isStrLowerCrossedUnderDonLowLower = isStrLowerUnderDonLowLower && + // !isStrLowerUnderDonLowLowerPrev; + + // // + // bool isAtrUpperOverPeak = conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX]; + // bool isAtrUpperEqualsToPeak = conditions.atrUpperBuffer[cIDX] == conditions.peaksBuffer[cIDX]; + + // // + // bool isAtrUpperCrossedUpPeak = conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX] && + // !(conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX]); + // bool isAtrUpperCrossedDownPeak = conditions.atrUpperBuffer[cIDX] < conditions.peaksBuffer[cIDX] && + // !(conditions.atrUpperBuffer[cIDX] < conditions.peaksBuffer[cIDX]); + + // // + // bool isAtrLowerUnderVale = conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX]; + // bool isAtrLowerEqualsToVale = conditions.atrUpperBuffer[cIDX] == conditions.valesBuffer[cIDX]; + + // // + // bool isAtrLowerCrossedUpVale = conditions.atrUpperBuffer[cIDX] > conditions.valesBuffer[cIDX] && + // !(conditions.atrUpperBuffer[cIDX] > conditions.valesBuffer[cIDX]); + // bool isAtrLowerCrossedDownVale = conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX] && + // !(conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX]); + + // // + // conditions.cheMin = cheMin; + // conditions.cheMax = cheMax; + // conditions.vwapMin = vwapMin; + // conditions.vwapMax = vwapMax; + + // // + // conditions.isSarIncreased = isSarIncreased; + // conditions.isSarDecreased = isSarDecreased; + // conditions.isSarEqualsToPeak = isSarEqualsToPeak; + // conditions.isSarEqualsToVale = isSarEqualsToVale; + // conditions.isStrEqualsToPeak = isStrEqualsToPeak; + // conditions.isStrEqualsToVale = isStrEqualsToVale; + // conditions.isStrUpperOverPeak = isStrUpperOverPeak; + // conditions.isPeakOverAtrUpper = isPeakOverAtrUpper; + // conditions.isStrLowerOverVale = isStrLowerOverVale; + // conditions.isVWapMinBreakedUp = isVWapMinBreakedUp; + // conditions.isVWapMaxBreakedUp = isVWapMaxBreakedUp; + // conditions.isBreakedUpPrevSar = isBreakedUpPrevSar; + // conditions.isBreakedUpPrevStr = isBreakedUpPrevStr; + // conditions.isAtrUpperOverPeak = isAtrUpperOverPeak; + // conditions.isAtrLowerUnderVale = isAtrLowerUnderVale; + // conditions.isStrLowerUnderVale = isStrLowerUnderVale; + // conditions.isStrUpperUnderPeak = isStrUpperUnderPeak; + // conditions.isValeUnderAtrLower = isValeUnderAtrLower; + // conditions.isClosedOverVWapMin = isClosedOverVWapMin; + // conditions.isClosedOverVWapMax = isClosedOverVWapMax; + // conditions.isClosedUnderVWapMin = isClosedUnderVWapMin; + // conditions.isClosedUnderVWapMax = isClosedUnderVWapMax; + // conditions.isVWapMinBreakedDown = isVWapMinBreakedDown; + // conditions.isVWapMaxBreakedDown = isVWapMaxBreakedDown; + // conditions.isSarCrossedOverVale = isSarCrossedOverVale; + // conditions.isStrCrossedOverVale = isStrCrossedOverVale; + // conditions.isBreakedDownPrevStr = isBreakedDownPrevStr; + // conditions.isBreakedDownPrevSar = isBreakedDownPrevSar; + // conditions.isSarCrossedUnderPeak = isSarCrossedUnderPeak; + // conditions.isStrCrossedUnderPeak = isStrCrossedUnderPeak; + // conditions.isNewPeakOverAtrUpper = isNewPeakOverAtrUpper; + // conditions.isBreakedUpPrevCheLE1 = isBreakedUpPrevCheLE1; + // conditions.isBreakedUpPrevCheLE2 = isBreakedUpPrevCheLE2; + // conditions.isBreakedUpPrevCheSE1 = isBreakedUpPrevCheSE1; + // conditions.isBreakedUpPrevCheSE2 = isBreakedUpPrevCheSE2; + // conditions.isBreakedUpPrevCheMin = isBreakedUpPrevCheMin; + // conditions.isBreakedUpPrevCheMax = isBreakedUpPrevCheMax; + // conditions.isAtrUpperEqualsToPeak = isAtrUpperEqualsToPeak; + // conditions.isAtrLowerEqualsToVale = isAtrLowerEqualsToVale; + // conditions.isNewValeUnderAtrLower = isNewValeUnderAtrLower; + // conditions.isStrUpperOverAtrUpper = isStrUpperOverAtrUpper; + // conditions.isStrLowerOverAtrLower = isStrLowerOverAtrLower; + // conditions.isBreakedDownPrevCheMin = isBreakedDownPrevCheMin; + // conditions.isBreakedDownPrevCheMax = isBreakedDownPrevCheMax; + // conditions.isBreakedDownPrevCheLE1 = isBreakedDownPrevCheLE1; + // conditions.isBreakedDownPrevCheLE2 = isBreakedDownPrevCheLE2; + // conditions.isBreakedDownPrevCheSE1 = isBreakedDownPrevCheSE1; + // conditions.isBreakedDownPrevCheSE2 = isBreakedDownPrevCheSE2; + // conditions.isStrUpperUnderAtrUpper = isStrUpperUnderAtrUpper; + // conditions.isStrLowerUnderAtrLower = isStrLowerUnderAtrLower; + // conditions.isBreakedUpPrevAtrUpper = isBreakedUpPrevAtrUpper; + // conditions.isBreakedUpPrevAtrLower = isBreakedUpPrevAtrLower; + // conditions.isAtrUpperCrossedUpPeak = isAtrUpperCrossedUpPeak; + // conditions.isAtrLowerCrossedUpVale = isAtrLowerCrossedUpVale; + // conditions.isVWapFastCrossedOverMid = isVWapFastCrossedOverMid; + // conditions.isRejectedUpPrevAtrUpper = isRejectedUpPrevAtrUpper; + // conditions.isRejectedUpPrevAtrLower = isRejectedUpPrevAtrLower; + // conditions.isAtrUpperCrossedDownPeak = isAtrUpperCrossedDownPeak; + // conditions.isAtrLowerCrossedDownVale = isAtrLowerCrossedDownVale; + // conditions.isBreakedDownPrevAtrUpper = isBreakedDownPrevAtrUpper; + // conditions.isBreakedDownPrevAtrLower = isBreakedDownPrevAtrLower; + // conditions.isVWapFastCrossedUnderMid = isVWapFastCrossedUnderMid; + // conditions.isDonLowLowerEqualsToVale = isDonLowLowerEqualsToVale; + // conditions.isStrUpperCrossedOverPeak = isStrUpperCrossedOverPeak; + // conditions.isStrLowerCrossedOverVale = isStrLowerCrossedOverVale; + // conditions.isStrLowerOverDonLowLower = isStrLowerOverDonLowLower; + // conditions.isVWapFastCrossedOverSlow = isVWapFastCrossedOverSlow; + // conditions.isRejectedDownPrevAtrUpper = isRejectedDownPrevAtrUpper; + // conditions.isRejectedDownPrevAtrLower = isRejectedDownPrevAtrLower; + // conditions.isVWapFastCrossedUnderSlow = isVWapFastCrossedUnderSlow; + // conditions.isStrUpperOverDonHighUpper = isStrUpperOverDonHighUpper; + // conditions.isStrLowerUnderDonLowLower = isStrLowerUnderDonLowLower; + // conditions.isDonHighUpperEqualsToPeak = isDonHighUpperEqualsToPeak; + // conditions.isStrUpperCrossedUnderPeak = isStrUpperCrossedUnderPeak; + // conditions.isStrLowerCrossedUnderVale = isStrLowerCrossedUnderVale; + // conditions.isStrUpperUnderDonHighUpper = isStrUpperUnderDonHighUpper; + // conditions.isStrLowerCrossedOverAtrLower = isStrLowerCrossedOverAtrLower; + // conditions.isStrUpperCrossedOverAtrUpper = isStrUpperCrossedOverAtrUpper; + // conditions.isStrUpperCrossedUnderAtrUpper = isStrUpperCrossedUnderAtrUpper; + // conditions.isStrLowerCrossedUnderAtrLower = isStrLowerCrossedUnderAtrLower; + // conditions.isStrLowerCrossedOverDonLowLower = isStrLowerCrossedOverDonLowLower; + // conditions.isStrUpperCrossedOverDonHighUpper = isStrUpperCrossedOverDonHighUpper; + // conditions.isStrLowerCrossedUnderDonLowLower = isStrLowerCrossedUnderDonLowLower; + // conditions.isStrUpperCrossedUnderDonHighUpper = isStrUpperCrossedUnderDonHighUpper; + + // // + // xpvConditions.Clean(); + // xhkConditions.Clean(); + // xatrConditions.Clean(); + // xstrConditions.Clean(); + // xcheConditions.Clean(); + // xdonConditions.Clean(); + // xvwapConditions.Clean(); + // xtrendConditions.Clean(); + + // // + // Free(); // return result; @@ -3363,15 +3363,15 @@ class XCX121Helper : public XCBase // // Inputs ... - X121Inputs mInputs; - X121XPVInputs xpvInputs; - X121XHKInputs xhkInputs; - X121XATRInputs xatrInputs; - X121XDONInputs xdonInputs; - X121XSTRInputs xstrInputs; - X121XCHEInputs xcheInputs; - X121XVWAPInputs xvwapInputs; - X121XTRENDInputs xtrendInputs; + // X121Inputs mInputs; + // X121XPVInputs xpvInputs; + // X121XHKInputs xhkInputs; + // X121XATRInputs xatrInputs; + // X121XDONInputs xdonInputs; + // X121XSTRInputs xstrInputs; + // X121XCHEInputs xcheInputs; + // X121XVWAPInputs xvwapInputs; + // X121XTRENDInputs xtrendInputs; // int mRSIHandler; diff --git a/Libraries/x-saherelm.common.lib_@!!@.mq5 b/Libraries/x-saherelm.common.lib_@!!@.mq5 deleted file mode 100644 index 8c26e79f..00000000 --- a/Libraries/x-saherelm.common.lib_@!!@.mq5 +++ /dev/null @@ -1,10597 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Common Library -// -------------------------------------- -// Name: XCommonLib -// Description: provide all commonly used functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.x-md5.class.mq5" - -// -#include - -// -// Models ... - -// -// Specified Price Type ... -enum ENUM_X_PRICE -{ - X_PRICE_HIGH, - X_PRICE_OPEN, - X_PRICE_CLOSE, - X_PRICE_LOW, - X_PRICE_UP, - X_PRICE_DOWN -}; - -// -enum ENUM_X_DIRECTION -{ - X_DIRECTION_ALL, // All - X_DIRECTION_NONE, // None - X_DIRECTION_BULLISH, // Bullish - X_DIRECTION_BEARISH, // Bearish -}; - -// -enum ENUM_X_FIBO_LEVELS -{ - X_FIBO_LEVEL_236, - X_FIBO_LEVEL_382, - X_FIBO_LEVEL_500, - X_FIBO_LEVEL_618, - X_FIBO_LEVEL_764, -}; - -// -double GetFiboLevelValue(ENUM_X_FIBO_LEVELS value) -{ - // - double result = 0; - - // - switch (value) - { - // - case X_FIBO_LEVEL_236: - result = 0.236; - break; - - // - case X_FIBO_LEVEL_382: - result = 0.382; - break; - - // - case X_FIBO_LEVEL_500: - result = 0.500; - break; - - // - case X_FIBO_LEVEL_618: - result = 0.618; - break; - - // - case X_FIBO_LEVEL_764: - result = 0.764; - break; - } - - // - return result; -} - -// -string ToString(ENUM_X_DIRECTION value) -{ - // - string result = NULL; - - // - switch (value) - { - case X_DIRECTION_ALL: - result = "ALL"; - break; - case X_DIRECTION_NONE: - result = "NONE"; - break; - case X_DIRECTION_BULLISH: - result = "BULLISH"; - break; - case X_DIRECTION_BEARISH: - result = "BEARISH"; - break; - } - - // - return result; -} - -// -// Swing Types Enum ... -enum ENUM_X_SWING_TYPE -{ - X_NO_SWING = 0, - X_SWING_HIGH = 1, - X_SWING_LOW = -1, -}; - -// -string ToString(ENUM_X_SWING_TYPE value) -{ - // - string result = NULL; - - // - switch (value) - { - // - case X_NO_SWING: - result = "NO_SWING"; - break; - - // - case X_SWING_LOW: - result = "SWING_LOW"; - break; - - // - case X_SWING_HIGH: - result = "SWING_HIGH"; - break; - } - - // - return result; -} - -// -ENUM_SERIESMODE ToSeriesMode(ENUM_X_SWING_TYPE value) -{ - // - ENUM_SERIESMODE result = MODE_HIGH; - - // - switch (value) - { - // - case X_SWING_HIGH: - result = MODE_HIGH; - break; - - // - case X_SWING_LOW: - result = MODE_LOW; - break; - } - - // - return result; -} - -// -// Find Swing Points ... -int FindSwing( - string mSymbol, // Trading Symbol ... - ENUM_TIMEFRAMES mPeriod, // Trading Period ... - ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ... - int mLength, // Loopback ... - int bar_index // BarIndex ... -) -{ - // - int result = -1; - - // - if (StringLen(mSymbol) == 0 || (mMode != X_SWING_HIGH && mMode != X_SWING_LOW)) - { - return result; - } - - // - int current = bar_index; - int founded = FindNextSwing( - mSymbol, - mPeriod, - mMode, - (mLength * 2) + 1, - current - mLength); - - // - while (founded != current) - { - // - current = FindNextSwing( - mSymbol, - mPeriod, - mMode, - mLength, - current + 1); - - // - founded = FindNextSwing( - mSymbol, - mPeriod, - mMode, - (mLength * 2) + 1, - current - mLength); - } - - // - result = current; - - // - return result; -} - -// -// Find Next Swing ... -int FindNextSwing( - string mSymbol, // Trading Symbol ... - ENUM_TIMEFRAMES mPeriod, // Trading Period ... - ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ... - int mLength, // Loopback ... - int bar_index // BarIndex ... -) -{ - // - int result = -1; - - // - if (bar_index < 0) - { - mLength += bar_index; - bar_index = 0; - } - - // - ENUM_SERIESMODE mSeriesMode = ToSeriesMode(mMode); - - // - result = mMode == X_SWING_HIGH - ? iHighest( - mSymbol, - mPeriod, - mSeriesMode, - mLength, - bar_index) - : iLowest( - mSymbol, - mPeriod, - mSeriesMode, - mLength, - bar_index); - - // - return result; -} - -// -// XPERIOD Calculation Method ... -enum ENUM_X_PERIOD_METHOD -{ - // - X_PERIOD_NOTHING, // Nothing - X_PERIOD_AUTO, // Auto Select - X_PERIOD_MANUALLY // Manually -}; - -// -// Available Market Cycles ... -enum ENUM_X_MARKET_CYCLES -{ - // - X_MARKET_CYCLE_UNKNOWN, // Unknown Cycle - X_MARKET_CYCLE_SHORT, // Short Cycle - X_MARKET_CYCLE_MEDIUM, // Medium Cycle - X_MARKET_CYCLE_LONG, // Long Cycle - X_MARKET_CYCLE_HIND, // Hind Cycle -}; - -// -// Structs ... - -// -// Model Specified Ticks Info ... -struct XTick -{ - // - string symbol; // Symbol ... - datetime time; // Time ... - double bid; // Bid ... - double ask; // Ask ... - double spread; // Spread ... - long volume; // Volume ... - - // - // Constructor ... - void XTick() - { - Clean(); - } - - // - // Tools Functions ... - - /** - * Initial ... - * - * @param _symbol: Symbol ... - * @param _time: Time ... - * @param _bid: Bid Price ... - * @param _ask: Ask Price ... - * @param _volume: Tick Volume ... - */ - bool Init( - string _symbol, - datetime _time, - double _bid, - double _ask, - double _spread, - long _volume // - ) - { - // - bool result = false; - - // - result = IsValid(_symbol) && - IsValid(_time) && - _bid > 0 && - _ask > 0; - if (!result) - { - return result; - } - - // - bid = _bid; - ask = _ask; - time = _time; - symbol = _symbol; - spread = _spread; - - // - result = IsValid(); - - // - return result; - } - - /** - * Init Tick by Symbol ... - * - * @param _symbol: String ... - * - * @return ( bool ) - */ - bool Init( - string _symbol, - ENUM_TIMEFRAMES _volumePeriod = NULL // - ) - { - // - bool result = false; - - // - result = IsValid(_symbol); - if (!result) - { - return result; - } - - // - datetime _time = TimeCurrent(); - double _bid = GetBid(_symbol); - double _ask = GetAsk(_symbol); - double _spread = GetSpread(_symbol); - - // - long _volume = 0; - if (IsValid(_volumePeriod)) - { - _volume = iTickVolume(_symbol, _volumePeriod, 0); - } - - // - result = Init( - _symbol, - _time, - _bid, - _ask, - _spread, - _volume // - ); - - // - return result; - } - - /** - * Cleanup ... - */ - void Clean() - { - // - bid = 0; - ask = 0; - volume = 0; - time = NULL; - symbol = NULL; - - // - ZeroMemory(this); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = IsValid(symbol) && - IsValid(time) && - bid > 0 && - ask > 0 && - volume >= 0; - - // - return result; - } - - // -}; - -// -// Model a Bar Remains Time ... -struct XBarRemainsTime -{ - // - int days; - int hours; - int minutes; - int seconds; - - // - // Constructor ... - XBarRemainsTime() - { - Clean(); - } - - // - // Always Calculate Current 0 Bar Timing ... - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL // Trading Period - ) - { - // - bool result = false; - - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - int minuteSecoonds = 60; - int hourSeconds = minuteSecoonds * 60; - int daySeconds = 24 * hourSeconds; - - // - int periodSeconds = PeriodSeconds( - mPeriod); - datetime startTime = GetBarTime( - mSymbol, - mPeriod, - 0 - // - ); - - // - int secondsDiff = (int)startTime + periodSeconds - (int)TimeCurrent(); - - // - int mWorkingSecondsDiff = secondsDiff; - if (mWorkingSecondsDiff > daySeconds) - { - // - days = mWorkingSecondsDiff / daySeconds; - mWorkingSecondsDiff -= days * daySeconds; - } - if (mWorkingSecondsDiff > hourSeconds) - { - // - hours = mWorkingSecondsDiff / hourSeconds; - mWorkingSecondsDiff -= hours * hourSeconds; - } - if (mWorkingSecondsDiff > minuteSecoonds) - { - // - minutes = mWorkingSecondsDiff / minuteSecoonds; - mWorkingSecondsDiff -= minutes * minuteSecoonds; - } - seconds = mWorkingSecondsDiff; - - // - result = true; - - // - return result; - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - days = 0; - hours = 0; - minutes = 0; - seconds = 0; - - // - ZeroMemory(this); - } - - // - // To String Representation ... - string ToString( - string dayId = "d", - string hourId = "h", - string minuteId = "m", - string secondId = "s", - string idSeparator = ": ", - string separator = ", ", - bool ignoreZeroValues = true - // - ) - { - // - string result = ""; - - // - // Days ... - if (!ignoreZeroValues || days > 0) - { - result += dayId + idSeparator + (string)days + separator; - } - - // - // Hours ... - if (!ignoreZeroValues || hours > 0) - { - // - string strHour = ToString(hours); - if (StringLen(strHour) == 1) - { - strHour = "0" + strHour; - } - - // - result += hourId + idSeparator + strHour + separator; - } - - // - // Minutes ... - if (!ignoreZeroValues || minutes > 0) - { - // - string strMinute = ToString(minutes); - if (StringLen(strMinute) == 1) - { - strMinute = "0" + strMinute; - } - - // - result += minuteId + idSeparator + strMinute + separator; - } - - // - // Seconds ... - if (!ignoreZeroValues || seconds > 0) - { - // - string strSec = ToString(seconds); - if (StringLen(strSec) == 1) - { - strSec = "0" + strSec; - } - - // - result += secondId + idSeparator + strSec; - } - - // - return result; - } -}; - -// -// Describe an Specific Candle ... -struct XOHCL -{ - // - // Props ... - - // - double high; - double open; - double close; - double low; - - // - string symbol; - datetime time; - ENUM_TIMEFRAMES period; - - // - // Constructor ... - XOHCL() - { - Clean(); - } - - // - // Init a Bar ... - // Using Bar Index ... - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - int barIndex = 0 // Bar Index - ) - { - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - symbol = mSymbol; - period = mPeriod; - - // - time = iTime( - mSymbol, - mPeriod, - barIndex // - ); - - // - open = iOpen( - mSymbol, - mPeriod, - barIndex // - ); - open = NormalizePrice(open, mSymbol); - - // - close = iClose( - mSymbol, - mPeriod, - barIndex // - ); - close = NormalizePrice(close, mSymbol); - - // - high = iHigh( - mSymbol, - mPeriod, - barIndex // - ); - high = NormalizePrice(high, mSymbol); - - // - low = iLow( - mSymbol, - mPeriod, - barIndex // - ); - low = NormalizePrice(low, mSymbol); - - // - bool result = IsValid(); - - // - return result; - } - - // - // Init a Bar ... - // Using Bar Time ... - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - datetime mTime = NULL // Bar Time - ) - { - // - mTime = NormalizeTime(mTime); - - // - int barIndex = iBarShift( - mSymbol, - mPeriod, - mTime, - false // - ); - - // - bool result = Init( - mSymbol, - mPeriod, - barIndex - // - ); - - // - return result; - } - - // - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - double mOpen = 0, // Open - double mHigh = 0, // High - double mClose = 0, // Close - double mLow = 0, // Low - int barIndex = 0 // Bar Index - ) - { - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - symbol = mSymbol; - period = mPeriod; - - // - time = iTime( - mSymbol, - mPeriod, - barIndex - // - ); - - // - open = mOpen; - high = mHigh; - close = mClose; - low = mLow; - - // - return IsValid(); - } - - // - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - double mOpen = 0, // Open - double mHigh = 0, // High - double mClose = 0, // Close - double mLow = 0, // Low - datetime mTime = NULL // Bar Time - ) - { - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - symbol = mSymbol; - period = mPeriod; - - // - int barIndex = iBarShift( - symbol, - period, - mTime); - - // - time = iTime( - mSymbol, - mPeriod, - barIndex - // - ); - - // - open = mOpen; - high = mHigh; - close = mClose; - low = mLow; - - // - return IsValid(); - } - - // - // Tools ... - - // - void Clean() - { - // - high = 0; - open = 0; - close = 0; - low = 0; - - // - time = NULL; - symbol = NULL; - period = NULL; - - // - ZeroMemory(this); - } - - // - // Validate Bar ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - high > 0 && - open > 0 && - close > 0 && - low > 0 - // - ; - - // - return result; - } - - // - int TotalBars() - { - // - int result = 0; - - // - result = iBars( - symbol, - period // - ); - - // - return result; - } - - // - // Calculate X_PRICE Specified Type ... - double GetPrice(ENUM_X_PRICE mPType) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - switch (mPType) - { - // - case X_PRICE_OPEN: - result = open; - break; - // - case X_PRICE_HIGH: - result = high; - break; - // - case X_PRICE_CLOSE: - result = close; - break; - // - case X_PRICE_LOW: - result = low; - break; - // - case X_PRICE_UP: - result = GetUp(); - break; - // - case X_PRICE_DOWN: - result = GetDown(); - break; - } - - // - return result; - } - - // - // Retrieve Price base On Series Mode ... - double GetPrice(ENUM_SERIESMODE mMode) - { - // - ENUM_X_PRICE mXMode = ToPrice(mMode); - - // - return GetPrice(mXMode); - } - - // - // Calculate Applied Price ... - double GetPrice( - ENUM_APPLIED_PRICE mAppliedTo // Select Application Method - ) - { - // - double result = 0; - - // - // Calculate Applied Price ... - switch (mAppliedTo) - { - // - case PRICE_CLOSE: - result = close; - break; - - // - case PRICE_OPEN: - result = open; - break; - - // - case PRICE_HIGH: - result = high; - break; - - // - case PRICE_LOW: - result = low; - break; - - // - case PRICE_MEDIAN: - result = (high + low) / 2; - break; - - // - case PRICE_TYPICAL: - result = (high + low + close) / 3; - break; - - // - case PRICE_WEIGHTED: - result = (high + low + close + close) / 4; - break; - } - - // - return result; - } - - // - // Find Specific Price ... - bool FindHigherPriceBar( - XOHCL &bar, - double price, - ENUM_X_PRICE _type = X_PRICE_HIGH // - ) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = TotalBars(); - result = IsValidSize(totalBars); - if (!result) - { - return result; - } - - // - int start = Index(); - int maxAllowedLoopback = totalBars / 5; - for (int i = start; i < maxAllowedLoopback; i++) - { - // - result = bar.Init( - symbol, - period, - i // - ); - - // - if (!result) - { - break; - } - - // - double iPrice = bar.GetPrice(_type); - - // - result = - // - iPrice > 0 && - iPrice > price - // - ; - if (result) - { - break; - } - } - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - // Find Specific Price ... - bool FindLowerPriceBar( - XOHCL &bar, - double price, - ENUM_X_PRICE _type = X_PRICE_HIGH // - ) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = TotalBars(); - result = IsValidSize(totalBars); - if (!result) - { - return result; - } - - // - int start = Index(); - int maxAllowedLoopback = totalBars / 5; - for (int i = start; i < maxAllowedLoopback; i++) - { - // - result = bar.Init( - symbol, - period, - i // - ); - - // - if (!result) - { - break; - } - - // - double iPrice = bar.GetPrice(_type); - - // - result = - // - iPrice > 0 && - iPrice < price - // - ; - if (result) - { - break; - } - } - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - // Calculate Bar Mid Line ... - double GetMid() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = (high + low) / 2; - - // - return result; - } - - // - // Calculate up Price ... - double GetUp() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = MathMax(open, close); - - // - return result; - } - - // - // Calculate Down Price ... - double GetDown() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = MathMin(open, close); - - // - return result; - } - - // - // Retrieve Required Price for Zone Checking ... - // For Bullish Zones => low; - // For Bearish Zones => high; - double GetZoneCheckValue(ENUM_X_DIRECTION forDir) - { - // - double result = 0; - - // - if (!IsValid() || - !HasDirection(forDir)) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - result = - isBullish - ? low - : high; - - return result; - } - - // - // Calculate Bar Body ... - double GetBody() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = GetUp() - GetDown(); - - // - return result; - } - - // - // Calculate Bar Range ... - double GetRange() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = high - low; - - // - return result; - } - - // - // Calculate Bar Shadows ... - double GetShadows() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = GetRange() - GetBody(); - - // - return result; - } - - // - // Calculate Bar High Shadow ... - double GetHighShadow() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = - // - high - GetUp() - // - ; - - // - return result; - } - - // - // Calculate Bar Low Shadow ... - double GetLowShadow() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = - // - GetDown() - low; - // - ; - - // - return result; - } - - // - // Check Bar is Bullish ... - bool IsBullish() - { - // - bool result = false; - - // - if (!IsValid()) - { - return result; - } - - // - result = open < close; - - // - return result; - } - - // - // Check Bar is Bearish ... - bool IsBearish() - { - // - bool result = false; - - // - if (!IsValid()) - { - return result; - } - - // - result = open > close; - - // - return result; - } - - // - // Get Direction of Bar ... - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool isBullish = IsBullish(); - bool isBearish = IsBearish(); - - // - result = - isBullish && isBearish - ? X_DIRECTION_ALL - : !isBullish && !isBearish - ? X_DIRECTION_NONE - : isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - // Find Next Bar Time ... - datetime NextAt() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int prSeconds = PeriodSeconds(period); - - // - result = time + prSeconds; - - // - return result; - } - - // - // Find Prev Bar Time ... - datetime BeforeOn() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int prSeconds = PeriodSeconds(period); - - // - result = time - prSeconds; - - // - return result; - } - - // - // Calculate Last Bar Open Time in Smaller Period ... - datetime GetLastBarTimeOfPeriod( - ENUM_TIMEFRAMES smallerPeriod // - ) - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int sourceSeconds = PeriodSeconds(period); - int destSeconds = PeriodSeconds(smallerPeriod); - if (destSeconds >= sourceSeconds) - { - // - result = time; - return result; - } - - // - result = (datetime)((((int)time) + sourceSeconds) - destSeconds); - - // - return result; - } - - // - // Calculate Close Time ... - datetime GetCloseTime() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int seconds = PeriodSeconds(period); - - // - result = (datetime)(((int)time) + seconds); - - // - return result; - } - - // - bool BarAt( - int index, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - if (index < 0) - { - index = 0; - } - - // - result = bar.Init( - symbol, - period, - index // - ); - - // - return result; - } - - // - bool BarIn( - ENUM_TIMEFRAMES _period, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - result = IsValid() && - IsSpecifiedValid(_period); - if (!result) - { - return result; - } - - // - int index = Index(_period); - result = bar.Init( - symbol, - _period, - index // - ); - - // - return result; - } - - // - // Find Current Bar Index on Chart ... - int Index() - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - result = iBarShift( - symbol, - period, - time - // - ); - - // - return result; - } - - // - int Index(datetime value) - { - // - int result = -1; - - // - value = NormalizeTime(value); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = iBarShift( - symbol, - period, - value // - ); - - // - return result; - } - - // - int Index(ENUM_TIMEFRAMES value) - { - // - int result = -1; - - // - result = IsValid() && - IsSpecifiedValid(value); - if (!result) - { - return result; - } - - // - result = iBarShift( - symbol, - value, - time // - ); - - // - return result; - } - - // - bool GetNextBar(XOHCL &bar) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int idx = Index(); - result = idx > 0; - if (!result) - { - return result; - } - - // - result = bar.Init( - this.symbol, - this.period, - idx - 1 // - ); - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - bool GetPreviousBar(XOHCL &bar) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int idx = Index(); - - // - result = bar.Init( - this.symbol, - this.period, - idx + 1 // - ); - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - // Find Highest Bar Index ... - int FindHighestIndex( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (mLength < 2) - { - mLength = 2; - } - - // - result = iHighest( - symbol, - period, - mMode, - mLength, - Index()); - - // - return result; - } - - // - // Find Highest ... - double FindHighest( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - int idx = FindHighestIndex( - mLength, - mMode); - if (idx <= -1) - { - return result; - } - - // - XOHCL iH; - result = iH.Init( - symbol, - period, - idx - // - ); - if (!result) - { - return result; - } - - // - result = iH.GetPrice(mMode); - - // - return result; - } - - // - // Find Highest ... - double FindHighestUp( - int mLength // Loopback ... - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = FindHighest(mLength, MODE_OPEN); - result = MathMax(mLength, FindHighest(mLength, MODE_CLOSE)); - - // - return result; - } - - // - // Find Lowest Bar Index ... - int FindLowestIndex( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (mLength < 2) - { - mLength = 2; - } - - // - result = iLowest( - symbol, - period, - mMode, - mLength, - Index()); - - // - return result; - } - - // - // Find Lowest ... - double FindLowest( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - int idx = FindLowestIndex( - mLength, - mMode); - if (idx <= -1) - { - return result; - } - - // - XOHCL iL; - result = iL.Init( - symbol, - period, - idx - // - ); - if (!result) - { - return result; - } - - // - result = iL.GetPrice(mMode); - - // - return result; - } - - // - // Find Lowest ... - double FindLowesttDown( - int mLength // Loopback ... - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = FindLowest(mLength, MODE_OPEN); - result = MathMax(mLength, FindLowest(mLength, MODE_CLOSE)); - - // - return result; - } - - // - // Other ... - string GetTag(string prefix = "") - { - // - string result = NULL; - - // - result = - (IsValid(prefix) - ? prefix + "_" - : "") + - "XOHCL_" + symbol + "_" + ToString(period) + "_" + ToFormatString(time); - - // - return result; - } - - // - // Convert to String Representation ... - string ToString() - { - // - string result = ""; - - // - result = GetTypeName(this) + - "(O(" + ToString(open) + "),H(" + ToString(high) + "),C(" + ToString(close) + "),L(" + ToString(low) + "))"; - - // - return result; - } -}; - -// -// Tracking Times ... -struct XTimeTracker -{ - // - // Props ... - int xMonth; - int xDayOfWeek; - int xForWeekDay; - int xDay; - int xHour; - int xMinute; - - // - // Constructor ... - XTimeTracker() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - xDay = -1; - xHour = -1; - xMonth = -1; - xMinute = -1; - xDayOfWeek = -1; - xForWeekDay = -1; - - // - ZeroMemory(this); - } - - // - // Detecting New Minute ... - bool IsNewMinute() - { - // - bool result = false; - - // - // Retrieve Current Time as Struct ... - MqlDateTime timeStruct = GetCurrentTime(); - - // - // Check Houre ... - result = timeStruct.min != xMinute; - if (result) - { - xMinute = timeStruct.min; - } - - // - return result; - } - - // - // Detecting New Houre ... - bool IsNewHour() - { - // - bool result = false; - - // - // Retrieve Current Time as Struct ... - MqlDateTime timeStruct = GetCurrentTime(); - - // - // Check Houre ... - result = timeStruct.hour != xHour; - if (result) - { - xHour = timeStruct.hour; - } - - // - return result; - } - - // - // Detecting New Day ... - bool IsNewDay() - { - // - bool result = false; - - // - // Retrieve Current Time as Struct ... - MqlDateTime timeStruct = GetCurrentTime(); - - // - // Check Houre ... - result = timeStruct.day_of_year != xDay; - if (result) - { - xDay = timeStruct.day_of_year; - } - - // - return result; - } - - // - // Detecting New Week ... - bool IsNewWeek() - { - // - bool result = false; - - // - // Retrieve Current Time as Struct ... - MqlDateTime timeStruct = GetCurrentTime(); - - // - // Check Week ... - // Since Week Starts From Monday in Forex World ... - // we Calculate Start of Week by 1-Monday ... - result = - xDayOfWeek == -1 && - xForWeekDay == -1 - ? true - : timeStruct.day_of_week == 1 && - timeStruct.day_of_year > xForWeekDay; - - // - xForWeekDay = timeStruct.day_of_year; - xDayOfWeek = timeStruct.day_of_week; - - // - return result; - } - - // - // Detecting End Of Week ... - bool IsWeekEnd() - { - // - bool result = false; - - // - // Retrieve Current Time as Struct ... - MqlDateTime timeStruct = GetCurrentTime(); - - // - // Check WeekEnd ... - // Since Week Starts From Monday in Forex World ... - // we Calculate End of Week by 5-Friday ... - result = - xDayOfWeek != -1 && - timeStruct.day_of_week == 5 && - timeStruct.hour == 23 && - timeStruct.min == 59 && - timeStruct.sec == 59; - - // - return result; - } - - // - // Detecting New Month ... - bool IsNewMonth() - { - // - bool result = false; - - // - // Retrieve Current Time as Struct ... - MqlDateTime timeStruct = GetCurrentTime(); - - // - // Check Houre ... - result = timeStruct.mon != xMonth; - if (result) - { - xMonth = timeStruct.mon; - } - - // - return result; - } -}; - -// -// Tracking Bars on Specified Environment ... -struct XBarTracker -{ - // - string symbol; // Tracking Symbol - ENUM_TIMEFRAMES period; // Tracking Time Frame - - // - int lastTrackedBar; // Last Tracked Bar ... - - // - bool waitsUntilNext; // Waits Until Next Bar ... - - // - // Constructor ... - XBarTracker() - { - Clean(); - } - - // - // Initializer ... - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL // Trading Period - ) - { - // - bool result = false; - - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - this.symbol = mSymbol; - this.period = mPeriod; - - // - this.lastTrackedBar = 0; - - // - result = true; - - // - return result; - } - - // - // Retrieve all Bars ... - int CountBars() - { - // - return iBars( - symbol, - period - // - ); - } - - // - // Check if it's New Bar ... - bool IsNewBar() - { - // - bool result = false; - - // - int currentBars = CountBars(); - - // - result = currentBars > lastTrackedBar; - if (result) - { - lastTrackedBar = currentBars; - } - - // - return result; - } - - // - bool CanProcessBar() - { - // - bool _isInTestMode = IsRunningOnTestMode(); - - // - bool isNewBar = IsNewBar(); - - // - bool result = - _isInTestMode - ? isNewBar - : !waitsUntilNext - ? true - : isNewBar; - if (result && waitsUntilNext) - { - waitsUntilNext = false; - } - - // - return result; - } - - // - void Waits() - { - this.waitsUntilNext = true; - } - - // - // Tools ... - void Clean() - { - // - symbol = NormalizeSymbol(NULL); - period = NormalizePeriod(NULL); - - // - ZeroMemory(this); - } - - // - bool GetBar( - XOHCL &bar, - int index = 0 // - ) - { - // - bool result = false; - - // - result = bar.Init( - symbol, - period, - index // - ); - - // - return result; - } - - // - bool GetBar( - XOHCL &bar, - datetime time = NULL // - ) - { - // - bool result = false; - - // - NormalizeTime(time); - - // - int barIndex = iBarShift( - symbol, - period, - time, - false // - ); - - // - result = barIndex >= 0; - if (!result) - { - return result; - } - - // - result = bar.Init( - symbol, - period, - barIndex // - ); - - // - return result; - } - - // - int Index(datetime time = NULL) - { - // - int result = 0; - - // - NormalizeTime(time); - - // - result = iBarShift( - symbol, - period, - time, - false // - ); - - // - return result; - } -}; - -// -// Model a Market Cycle ... -struct XMarketCycle -{ - // - // Props ... - - // - string prefix; // Prefix Trag ... - - // - string symbol; // Market Symbol ... - - // - ENUM_TIMEFRAMES period; // Period of Cycle ... - ENUM_X_PERIOD_METHOD method; // Period Selection Method ... - ENUM_X_MARKET_CYCLES cycle; // Cycles of MArket ... - - // - int length; // Number Of Candles per Current Time Frame ... - ENUM_TIMEFRAMES hostPeriod; // Current Time Frame ... - - // - datetime lastStart; // Last Candle Bar Time ... - - // - XBarTracker barTracker; // Bar Tracker ... - XBarRemainsTime remains; // Current Bar Remains Model ... - - // - // Constructor ... - XMarketCycle() - { - Clean(); - } - - // - // Init Cycle ... - bool Init( - string mSymbol, // Trading Symbol - ENUM_TIMEFRAMES mHostPeriod, // Host Period - ENUM_X_MARKET_CYCLES mCycle, // Init Cycle - string mPrefix = "" // Prefix - ) - { - // - bool result = false; - - // - mSymbol = NormalizeSymbol(mSymbol); - mHostPeriod = NormalizePeriod(mHostPeriod); - - // - result = IsValid(mCycle); - if (!result) - { - return result; - } - - // - this.cycle = mCycle; - - // - // Set Automatically Prefix ... - if (StringLen(mPrefix) == 0) - { - this.prefix = ToString(cycle); - } - - // - result = IsValid( - method, - period // - ); - if (!result) - { - return result; - } - - // - this.symbol = mSymbol; - this.hostPeriod = mHostPeriod; - - // - // Find Cycle Period ... - if (method == X_PERIOD_AUTO) - { - // - // Select Period ... - this.period = GetCyclePeriod( - this.cycle, - this.hostPeriod); - } - - // - // Set Prefix if Provided ... - if (StringLen(mPrefix) > 0) - { - this.prefix = mPrefix; - } - - // - // Calculate Required Info ... - - // - // Length ... - this.length = PeriodSeconds(this.period) / PeriodSeconds(this.hostPeriod); - - // - // Update Additional Data ... - result = this.Update(0); - - // - return result; - } - - // - bool Init( - string mSymbol, // Trading Symbol - ENUM_TIMEFRAMES mHostPeriod, // Host Period - ENUM_X_MARKET_CYCLES mCycle, // Init Cycle - ENUM_X_PERIOD_METHOD mMethod, // Period Selection Method - ENUM_TIMEFRAMES mPeriod, // Provided Period - string mPrefix = "" // Prefix - ) - { - // - this.period = mPeriod; - this.method = mMethod; - - // - return Init( - mSymbol, - mHostPeriod, - mCycle, - mPrefix - // - ); - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - length = 0; - lastStart = 0; - - // - cycle = NULL; - prefix = NULL; - symbol = NULL; - period = NULL; - method = NULL; - hostPeriod = NULL; - - // - remains.Clean(); - barTracker.Clean(); - - // - ZeroMemory(this); - } - - // - // Check Structure Valid ... - bool IsValid() - { - // - bool result = false; - - // - result = IsValid( - method, - period); - if (!result) - { - return result; - } - - // - result = - // - length > 0 && - symbol != NULL && - period != NULL && - method != NULL && - hostPeriod != NULL && - method != X_PERIOD_NOTHING - // - ; - - // - return result; - } - - // - // Update Market Cycle Additional Info ... - bool Update(int hostBarIndex) - { - // - bool result = false; - - // - result = this.IsValid(); - if (!result) - { - return result; - } - - // - // Init Remains ... - result = remains.Init( - this.symbol, - this.period); - if (!result) - { - return result; - } - - // - // Init Bar Tracker ... - result = barTracker.Init( - this.symbol, - this.period); - if (!result) - { - return result; - } - - // - return result; - } - - // - // Count Bars ... - int CountBars() - { - // - int result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = barTracker.CountBars(); - - // - return result; - } - - // - // Check New Bar ... - bool IsNewBar() - { - // - bool result = false; - - // - if (!IsValid()) - { - return result; - } - - // - result = barTracker.IsNewBar(); - - // - return result; - } - - // - // Retrieve Current Bar Index based on Host Period bar Index ... - int GetBarIndex(int barIndex) - { - // - int result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - if (barIndex < 0) - { - return result; - } - - // - int totalBars = CountBars(); - if (barIndex >= totalBars) - { - // - result = totalBars - 1; - return result; - } - - // - datetime hostBarTime = iTime( - this.symbol, - this.hostPeriod, - barIndex - // - ); - - // - result = iBarShift( - this.symbol, - this.period, - hostBarTime - // - ); - - // - return result; - } - - // - // Retrieve Current Cycles Specific Bar ... - XOHCL GetBar(int barIndex) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int totalBars = CountBars(); - if (barIndex >= totalBars) - { - barIndex = totalBars - 1; - } - - // - XOHCL result; - result.Init( - this.symbol, - this.period, - barIndex - // - ); - - // - return result; - } - - // - // Extract Specific Range of Bars ... - // using Start Bar Index ... - int GetBars( - XOHCL &result[], // Hold Result - int from = 0, // Start Bar Index - int count = 1, // Number of Bars - bool forceClean = true // Clean Result Array - ) - { - // - int mResult = 0; - - // - if (from < 0) - { - from = 0; - } - - // - int total = Bars( - symbol, - period); - if (from > total - 2) - { - from = total - 2; - } - - // - if (count < 0) - { - count = 1; - } - - // - int start = from; - int end = start + count; - if (end > total - 1) - { - end = total - 1; - } - - // - if (forceClean) - { - Clean(result); - } - - // - int beforeSize = ArraySize(result); - - // - for (int i = start; i < end; i++) - { - // - XOHCL iBar; - bool isValid = iBar.Init( - symbol, - period, - i - // - ); - - // - if (isValid) - { - // - AddRef( - iBar, - result - // - ); - } - } - - // - int afterSize = ArraySize(result); - - // - mResult = afterSize - beforeSize; - - // - return mResult; - } - - // - // Extract Specific Range of Bars ... - // using Start Bar Time ... - int GetBars( - XOHCL &result[], // Hold Result - datetime from = NULL, // Start Bar Time - int count = 1, // Number of Bars - bool forceClean = true // Clean Result Array - ) - { - // - from = NormalizeTime(from); - - // - int barIndex = iBarShift( - symbol, - period, - from, - false - // - ); - - // - return GetBars( - result, - symbol, - period, - barIndex, - count, - forceClean - // - ); - } - - // - // Retrieve Bar Time ... - datetime GetBarTime(int barIndex) - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int totalBars = CountBars(); - if (barIndex >= totalBars) - { - barIndex = totalBars - 1; - } - - // - result = iTime( - this.symbol, - this.period, - barIndex - // - ); - - // - return result; - } - - // - // Find Chart ID ... - ulong GetChartID() - { - // - ulong result = 0; - - // - long firstChart = ChartFirst(); - result = firstChart; - - // - while (result >= 0) - { - // - string chSymbol = ChartSymbol(result); - ENUM_TIMEFRAMES chPeriod = ChartPeriod(result); - - // - bool isOwnChart = - // - symbol == chSymbol && - period == chPeriod - // - ; - if (isOwnChart) - { - break; - } - - // - result = ChartNext(result); - if (result < 0) - { - break; - } - } - - // - return result; - } - - // - // Create and String Representation for Unique Taging ... - string ToString() - { - // - string result = ""; - - // - if (!IsValid()) - { - return result; - } - - // - result = - GetTypeName(this) + "(" + - "PRFX(" + this.prefix + ")" + - "SMBL(" + this.symbol + ")" + - "CYC(" + ToString(this.cycle) + ")" + - "PRD(" + ToString(this.period) + ")" + - "PRDHST(" + ToString(this.hostPeriod) + ")" + - "MTH(" + EnumToString(this.method) + ")" + - ")"; - - // - return result; - } - - // - // Here we Produce a Summary brief of - // state of Cycle ... - string GenerateSummary() - { - // - string result = ""; - - // - bool hasPrefix = - StringLen(this.prefix) > 0 && - this.prefix != ToString(this.cycle); - result += (hasPrefix ? this.prefix + "[" : "") + - ToString(this.cycle) + - (hasPrefix ? "]" : "") + "\n"; - - // - result += " - PR: " + ToString(this.period) + "\n"; - - // - XOHCL cBar = GetBar(0); - - // - result += " - State: " + (cBar.IsBullish() ? "Bullish" : cBar.IsBearish() ? "Bearish" - : "Neutural"); - - // - return result; - } -}; - -// -// Linear Regression ... - -// -struct XLinearRegressionWorkStruct -{ - // - struct sDataStruct - { - // - double value; - double sumY; - double sumXY; - }; - - // - sDataStruct data[]; - - // - int dataSize; - int period; - double sumX; - double sumXX; - double divisor; - - // - // Constructor ... - XLinearRegressionWorkStruct() - : dataSize(-1), period(-1) - { - } -}; - -// -struct XLinearRegression -{ - // - XLinearRegressionWorkStruct m_work; - - // - // Calculate Linear Regression ... - double Calculate( - double value, - int period, - double &_slope, - double &_intercept, - int r, - int bars // - ) - { - // - if (m_work.dataSize <= bars) - { - m_work.dataSize = ArrayResize(m_work.data, bars + 500, 2000); - } - - // - if (period < 1) - { - period = 1; - } - - // - if (m_work.period != (int)period) - { - // - m_work.period = (int)period; - m_work.sumX = m_work.period * (m_work.period - 1.0) / 2.0; - m_work.sumXX = m_work.period * (m_work.period - 1.0) * (2.0 * m_work.period - 1.0) / 6.0; - m_work.divisor = m_work.sumX * m_work.sumX - m_work.period * m_work.sumXX; - - // - if (m_work.divisor) - { - m_work.divisor = 1.0 / m_work.divisor; - } - } - - // - m_work.data[r].value = value; - - // - if (r >= m_work.period) - { - // - m_work.data[r].sumY = m_work.data[r - 1].sumY + value - m_work.data[r - m_work.period].value; - m_work.data[r].sumXY = m_work.data[r - 1].sumXY + m_work.data[r].sumY - m_work.data[r - m_work.period].value * (m_work.period - 1.0) - value; - } - else - { - // - m_work.data[r].sumY = value; - m_work.data[r].sumXY = 0; - - // - for (int _k = 1; _k < m_work.period && r >= _k; _k++) - { - // - m_work.data[r].sumY += m_work.data[r - _k].value; - m_work.data[r].sumXY += _k * m_work.data[r - _k].value; - } - } - - // - _slope = (m_work.period * m_work.data[r].sumXY - m_work.sumX * m_work.data[r].sumY) * m_work.divisor; - _intercept = (m_work.data[r].sumY - _slope * m_work.sumX) / (double)m_work.period; - - // - double result = (_intercept + _slope * (m_work.period - 1.0)); - - // - return result; - } - - // -}; - -// -// Use To Parse Symbols for -// Ignore Brokers Additional Suffixes ... -struct XSymbolParser -{ - // - string version; // Temp ... - - // - // Symbol Parsing ... - - // - // Forext ... - - // - bool IsEURUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsUSDJPY(string symbol) - { - // - string symbolIdentifiers[] = { - "USD", - "JPY" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURJPY(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "JPY" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsUSDCHF(string symbol) - { - // - string symbolIdentifiers[] = { - "USD", - "CHF" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURCHF(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "CHF" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsGBPUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "GBP", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURGBP(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "GBP" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsAUDUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "AUD", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURAUD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "AUD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsUSDCAD(string symbol) - { - // - string symbolIdentifiers[] = { - "USD", - "CAD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURCAD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "CAD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsNZDUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "NZD", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURNZD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "NZD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - // Metals ... - - // - bool IsXAUUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "XAU", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsXAGUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "XAG", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - // Indexes ... - - // - bool IsDowJones(string symbol) - { - // - bool result = Contains( - "DowJones30", - symbol // - ); - - // - return result; - } - - // - // Oil ... - - // - bool IsBrent(string symbol) - { - // - bool result = Contains( - "BRENT", - symbol // - ); - - // - return result; - } - - // - // Symbol Finder ... - string GetEURUSDSymbol() - { - // - string result = NULL; - - // - string symbols[]; - int symbolsCount = GetAllSymbols( - symbols // - ); - if (!IsValidSize(symbolsCount)) - { - return result; - } - - // - for (int i = 0; i < symbolsCount; i++) - { - // - string iSymbol = symbols[i]; - if (IsEURUSD(iSymbol)) - { - // - result = iSymbol; - break; - } - } - - // - return result; - } -}; - -// -struct XSymbolSessionParser -{ - // - string version; // Temp ... - - // - // Check Market Is Open for Specific Symbol - // in Current Time ... - bool CanTrade( - string symbol // Trading Symbol - ) - { - // - bool result = false; - - // - result = IsValid(symbol); - if (!result) - { - return result; - } - - // - MqlDateTime timeStruct; - result = TimeCurrent(timeStruct); - if (!result) - { - return result; - } - - // - ENUM_DAY_OF_WEEK dayOfWeek = (ENUM_DAY_OF_WEEK)timeStruct.day_of_week; - - // - datetime cTime = TimeCurrent(); - - // - datetime from; - datetime to; - result = SymbolInfoSessionTrade( - symbol, - dayOfWeek, - 0, // Session Index ... - from, - to // - ); - if (!result) - { - return result; - } - - // - result = cTime > from && cTime < to; - - // - return result; - } -}; - -// -// Parsing Market Names ... -struct XMarketParser -{ - // - string _version; // Temp ... - - // - bool IsIngot(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // - bool IsErrante(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // - bool IsAMarkets(string market) - { - // - bool result = false; - - // - result = IsValid(market) && - market == "AMarkets LLC"; - - // - return result; - } - - // - bool IsIFCMarkets(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // - bool IsOtetMarkets(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // -}; - -// -// Specified Swing Point ... -struct XSwingPoint -{ - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - - // - double swing; - datetime time; - ENUM_X_SWING_TYPE type; - - // - // Constructor ... - XSwingPoint() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleanup Model ... - */ - void Clean() - { - // - swing = 0; - time = NULL; - - // - symbol = NULL; - period = NULL; - - // - type = X_NO_SWING; - } - - /** - * Validate Model ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - swing > 0 && - IsValid(time) && - IsValid(symbol) && - IsValid(period) && - type != X_NO_SWING; - - // - return result; - } - - /** - * Check Swing is Low or not ... - * - * @return ( bool ) - */ - bool IsSwingLow() - { - return type == X_SWING_LOW; - } - - /** - * Check Swing is High or not ... - * - * @return ( bool ) - */ - bool IsSwingHigh() - { - return type == X_SWING_HIGH; - } -}; - -/** - * Extract values of swings from specified Collection ... - * - * @param swings: XSwingPoint instance Collection ... - * @param values: double Collection ... - * - * @return ( int ) - */ -int ExtractSwings( - XSwingPoint &swings[], - double &values[] // -) -{ - // - int result = 0; - - // - Clean(values); - - // - int count = ArraySize(swings); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - Add( - swings[i].swing, - values // - ); - } - - // - result = ArraySize(values); - - // - return result; -} - -// -// Functions ... - -// -// Validators ... - -// -// Validate an String has length and not NULL ... -bool IsValid(string value) -{ - // - bool result = false; - - // - result = - // - value != NULL && - StringLen(value) > 0 - // - ; - - // - return result; -} -bool IsSpecifiedValid(string value) -{ - return IsValid(value); -} - -// -// Validate a Date ... -bool IsValid(datetime value) -{ - // - bool result = false; - - // - result = NotEmpty(value) && value != NULL; - - // - return result; -} -bool IsSpecifiedValid(datetime value) -{ - return IsValid(value); -} - -// -// Validate a Period Param ... -bool IsValid(ENUM_TIMEFRAMES value) -{ - // - bool result = false; - - // - result = - // - value != NULL - // - ; - - // - return result; -} -bool IsSpecifiedValid(ENUM_TIMEFRAMES value) -{ - // - return IsValid(value); -} - -// -// Validate Specified Cycle ... -bool IsValid(ENUM_X_MARKET_CYCLES value) -{ - // - bool result = false; - - // - result = - // - value != NULL && - value != X_MARKET_CYCLE_UNKNOWN - // - ; - - // - return result; -} - -// -// Validate Specific Period Mode ... -bool IsValid( - ENUM_X_PERIOD_METHOD mMethod, // Period Select Method - ENUM_TIMEFRAMES mPeriod // Selected Period -) -{ - // - bool result = false; - - // - result = - // - mMethod == X_PERIOD_NOTHING - ? false - : mMethod == X_PERIOD_MANUALLY - ? mPeriod != NULL - : mMethod == X_PERIOD_AUTO - ? true - : false - // - ; - - // - return result; -} - -// -bool IsSpecifiedValid( - ENUM_X_PERIOD_METHOD mMethod, // Period Select Method - ENUM_TIMEFRAMES mPeriod // Selected Period -) -{ - return IsValid(mMethod, - mPeriod // - ); -} - -// -// Validate Swing Mode ... -bool IsValid(ENUM_X_SWING_TYPE value) -{ - // - bool result = false; - - // - result = - // - value == X_SWING_HIGH || - value == X_SWING_LOW - // - ; - - // - return result; -} - -// -// As IS ... - -// -// Determine a Position type is Long or not ... -bool IsLong(ENUM_POSITION_TYPE type) -{ - // - bool result = type == POSITION_TYPE_BUY; - - // - return result; -} -bool IsLong(ENUM_ORDER_TYPE type) -{ - // - bool result = type == ORDER_TYPE_BUY; - - // - return result; -} - -// -// Determine a Position type is Short or not ... -bool IsShort(ENUM_POSITION_TYPE type) -{ - // - bool result = type == POSITION_TYPE_SELL; - - // - return result; -} -bool IsShort(ENUM_ORDER_TYPE type) -{ - // - bool result = type == ORDER_TYPE_SELL; - - // - return result; -} - -// -// Retrieve Opposit Direction Type ... -ENUM_POSITION_TYPE GetOpposit(ENUM_POSITION_TYPE type) -{ - // - ENUM_POSITION_TYPE result = NULL; - - // - bool isLong = IsLong(type); - result = isLong - ? POSITION_TYPE_SELL - : POSITION_TYPE_BUY; - - // - return result; -} -ENUM_ORDER_TYPE GetOpposit(ENUM_ORDER_TYPE type) -{ - // - ENUM_ORDER_TYPE result = NULL; - - // - bool isLong = IsLong(type); - result = isLong - ? ORDER_TYPE_SELL - : ORDER_TYPE_BUY; - - // - return result; -} - -// -string ToString(ENUM_POSITION_TYPE value) -{ - // - string result = NULL; - - // - result = - // - IsLong(value) - ? "Long" - : "Short" - // - ; - - // - return result; -} -string ToString(ENUM_ORDER_TYPE value) -{ - // - string result = NULL; - - // - result = - // - IsLong(value) - ? "Long" - : "Short" - // - ; - - // - return result; -} - -// -// Check Expert Running in Testing Mode or not ... -bool IsRunningOnTestMode() -{ - // - bool result = false; - - // - // check programm mode ... - result = MQL5InfoInteger(MQL5_TESTING); - - // - return result; -} - -// -// Find Chart ID ... -long FindChartID( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL // Trading Period -) -{ - // - long result = ChartFirst(); - long first = result; - - // - while (result > 0) - { - // - string chSymbol = ChartSymbol(result); - ENUM_TIMEFRAMES chPeriod = ChartPeriod(result); - - // - bool isOwn = - // - chSymbol == mSymbol && - chPeriod == mPeriod - // - ; - if (isOwn) - { - break; - } - - // - result = ChartNext(result); - } - - // - return result; -} - -// -// Normalizers ... - -// -// Check a Symbol provided or not ... -// if not use Default ... -string NormalizeSymbol(string value) -{ - // - string result = value; - - // - if (!IsValid(result)) - { - result = _Symbol; - } - - // - return result; -} - -// -// Check a Datetime provided or not ... -// if not use Current ... -datetime NormalizeTime(datetime value) -{ - // - datetime result = value; - - // - if (!IsValid(result)) - { - result = TimeCurrent(); - } - - // - return result; -} - -// -// Check a Period provided or not ... -// if not use Default ... -ENUM_TIMEFRAMES NormalizePeriod(ENUM_TIMEFRAMES value) -{ - // - ENUM_TIMEFRAMES result = value; - - // - if (!IsValid(value)) - { - result = _Period; - } - - // - return result; -} - -// -// Normalize Cycle ... -ENUM_X_MARKET_CYCLES NormalizeCycle(ENUM_X_MARKET_CYCLES value) -{ - // - ENUM_X_MARKET_CYCLES result = value; - - // - if (!IsValid(result)) - { - result = X_MARKET_CYCLE_SHORT; - } - - // - return value; -} - -// -// Validate a Buffer Size for Looping or etc ... -bool IsValidSize(int size) -{ - // - bool result = size > 0; - - // - return result; -} - -template -bool IsValidSize(T &buffer[]) -{ - // - bool result = false; - - // - result = - // - IsValidSize(ArraySize(buffer)) - // - ; - - // - return result; -} - -// -// Check a Given Index is Valid or not ... -bool IsValidIndex(int index) -{ - return index >= 0; -} - -// -// Normalize Index Based On Specified Buffer ... -template -void NormalizeIndex( - int &index, - T &buffer[] // -) -{ - // - int bufferSize = ArraySize(buffer); - - // - if (bufferSize <= 0) - { - index = 0; - } - - // - if (index <= 0) - { - index = 0; - } - - // - if (index > bufferSize - 1) - { - index = bufferSize - 1; - } -} - -// -// Normalize Start and Count based on Specified Buffer ... -template -void NormalizeCount( - int &start, - int &count, - T &buffer[] // -) -{ - // - // Validate Buffer Size ... - int bufferSize = ArraySize(buffer); - if (!IsValidSize(bufferSize)) - { - return; - } - - // - // Normalization Start ... - NormalizeIndex( - start, - buffer // - ); - - // - if (count < start) - { - count = (start - count); - } - - // - // Normalization Count ... - - // - if (count < 0) - { - count = start; - } - - // - if (count > bufferSize) - { - count = bufferSize; - } -} - -// -// Normalize a give Volume ... -double NormalizeVolume( - double mVolume, // desired volume to normalize - string mSymbol = NULL, // Trading Symbol - int mLength = 2 // Length of Digits -) -{ - // - double result = mVolume; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - // Normalize Digits ... - int digits = GetDigits(mSymbol); - - // - mLength = - mLength == 0 || mLength > digits - ? digits - : MathMin(mLength, digits); - - // - // Normalize Volume ... - result = NormalizeDouble(result, mLength); - - // - double maxAvailableVolume = SymbolInfoDouble(mSymbol, SYMBOL_VOLUME_MAX); - double minAvailableVolume = SymbolInfoDouble(mSymbol, SYMBOL_VOLUME_MIN); - - // - // Validate Result ... - if (result > maxAvailableVolume) - { - result = maxAvailableVolume; - } - else if (result < minAvailableVolume) - { - result = minAvailableVolume; - } - - // - return result; -} - -// -// Normallize Price ... -double NormalizePrice( - double mPrice, // desired Price for normalization - string mSymbol = NULL // Trading Symbol -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - double tickSize = 0; - result = SymbolInfoDouble(mSymbol, SYMBOL_TRADE_TICK_SIZE, tickSize); - - // - int digits = GetDigits(mSymbol); - result = NormalizeDouble(MathRound(mPrice / tickSize) * tickSize, digits); - - // - return result; -} - -// -// Prices ... - -// -// Retrieve Ask Price ... -double GetAsk( - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - - // - double result = SymbolInfoDouble(mSymbol, SYMBOL_ASK); - - // - return result; -} - -// -// Retrieve Bid Price ... -double GetBid( - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - - // - double result = SymbolInfoDouble(mSymbol, SYMBOL_BID); - - // - return result; -} - -// -// Retrieve Spread Price ... -double GetSpread( - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - - // - double ask = GetAsk(mSymbol); - double bid = GetBid(mSymbol); - - // - double result = MathAbs(ask - bid); - - // - return result; -} - -// -// Retrieve Point Value ... -double GetPoints( - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - - // - double result = SymbolInfoDouble(mSymbol, SYMBOL_POINT); - - // - return result; -} - -// -// Retrieve Point Digits ... -int GetDigits( - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - - // - int result = (int)SymbolInfoInteger(mSymbol, SYMBOL_DIGITS); - - // - return result; -} - -// -// Retrieve Entry Price ... -double GetEntry( - string mSymbol = NULL, // Trading Symbol - ENUM_POSITION_TYPE type = POSITION_TYPE_BUY // Get entry price for Which direction trade ... -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsLong(type) - ? GetAsk(mSymbol) - : GetBid(mSymbol); - result = NormalizePrice(result, mSymbol); - - // - return result; -} -double GetEntry( - string mSymbol = NULL, // Trading Symbol - ENUM_X_DIRECTION type = X_DIRECTION_BULLISH // Get entry price for Which direction trade ... -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsBullish(type) - ? GetAsk(mSymbol) - : GetBid(mSymbol); - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -// -// Retrieve Exit Price ... -double GetExit( - string mSymbol = NULL, // Trading Symbol - ENUM_POSITION_TYPE type = POSITION_TYPE_BUY // Get entry price for Which direction trade ... -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsLong(type) - ? GetBid(mSymbol) - : GetAsk(mSymbol); - result = NormalizePrice(result, mSymbol); - - // - return result; -} -double GetExit( - string mSymbol = NULL, // Trading Symbol - ENUM_X_DIRECTION type = X_DIRECTION_BULLISH // Get entry price for Which direction trade ... -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsBullish(type) - ? GetBid(mSymbol) - : GetAsk(mSymbol); - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -// -// Get 1 Pip in Price Value ... -double GetPipPrice( - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - - // - double symbolPoint = GetPoints(mSymbol); - int symbolDigits = GetDigits(mSymbol); - - // - double result = symbolPoint; - if (symbolDigits == 3 || symbolDigits == 5) - { - result *= 10; - } - - // - return result; -} - -// -// Converts Pips To Price ... -double PipsToPrice( - double mPips, // pips amount - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - - // - int digits = GetDigits(mSymbol); - double pipValue = GetPipPrice(mSymbol); - double result = mPips * pipValue; - - // - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -// -// Converts Price to Pips ... -double PriceToPips( - double mPrice, // the price amount which required to calculate - string mSymbol = NULL // Trading Symbol -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - mPrice = NormalizePrice(mPrice, mSymbol); - - // - int digits = GetDigits(mSymbol); - double pipPrice = GetPipPrice(mSymbol); - - // - double result = mPrice / pipPrice; - - // - result = NormalizeDouble(result, digits); - - // - return result; -} - -// -// Convert Price to Point ... -double PriceToPoint( - double price, // the price amount which required to calculate - string mSymbol = NULL // Trading Symbol -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - price = NormalizePrice(price, mSymbol); - - // - double point = GetPoints(mSymbol); - result = price / point; - - // - return result; -} - -// -// Converts Point to Price ... -double PointToPrice( - double points, // Points Amount - string mSymbol = NULL // Trading Symbol -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - double point = GetPoints(mSymbol); - result = points * point; - - // - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -// -// Converts Series Mode to XPRICE ... -ENUM_X_PRICE ToPrice( - ENUM_SERIESMODE mMode // Specified Series Mode ... -) -{ - // - ENUM_X_PRICE result = X_PRICE_CLOSE; - - // - switch (mMode) - { - // - // High ... - case MODE_HIGH: - result = X_PRICE_HIGH; - break; - - // - // Open ... - case MODE_OPEN: - result = X_PRICE_OPEN; - break; - - // - // Low ... - case MODE_LOW: - result = X_PRICE_LOW; - break; - - // - // Close ... - // Default ... - case MODE_CLOSE: - default: - result = X_PRICE_CLOSE; - break; - } - - // - return result; -} - -// -// Retrieve Applied Price ... -template -double GetAppliedPrice( - ENUM_APPLIED_PRICE tprice, // Type of Price Selection - T &open[], // Open Prices - T &high[], // High Preices - T &low[], // Low Prices - T &close[], // Close Prices - int i // Bar Index -) -{ - switch (tprice) - { - case PRICE_CLOSE: - return (close[i]); - case PRICE_OPEN: - return (open[i]); - case PRICE_HIGH: - return (high[i]); - case PRICE_LOW: - return (low[i]); - case PRICE_MEDIAN: - return ((high[i] + low[i]) / 2.0); - case PRICE_TYPICAL: - return ((high[i] + low[i] + close[i]) / 3.0); - case PRICE_WEIGHTED: - return ((high[i] + low[i] + close[i] + close[i]) / 4.0); - } - return (0); -} - -// -double iGetPrice( - int tprice, - double open, - double high, - const double low, - const double close // -) -{ - // - switch (tprice) - { - case PRICE_CLOSE: - return (close); - case PRICE_OPEN: - return (open); - case PRICE_HIGH: - return (high); - case PRICE_LOW: - return (low); - case PRICE_MEDIAN: - return ((high + low) / 2.0); - case PRICE_TYPICAL: - return ((high + low + close) / 3.0); - case PRICE_WEIGHTED: - return ((high + low + close + close) / 4.0); - } - - // - return (0); -} - -/** - * Calculates Price Change Percentage based on - * Several Params ... - * - * @param _symbol: Symbol ... - * @param _period: Time Frame ... - * @param _from: start Bar Index ... - * @param _length: Length of Bars ... - * - * @return ( double ) - */ -double GetPriceChanged( - string _symbol = NULL, - ENUM_TIMEFRAMES _period = NULL, - int _from = 0, - int _length = 3 // -) -{ - // - double result = 0; - - // - NormalizeSymbol(_symbol); - NormalizePeriod(_period); - - // - if (_from < 0) - { - _from = 0; - } - - // - if (_length < 2) - { - _length = 2; - } - - // - double closes[]; - int copiedCloses = CopyClose( - _symbol, - _period, - _from, - _length, - closes // - ); - if (copiedCloses < _length) - { - return result; - } - ArrayReverse(closes); - - // - double change = (closes[0] - closes[_length - 1]) / closes[_length - 1] * 100; - result = change; - - // - return result; -} - -// -// Calculate TP/SL for Specified Type of Positions ... -void CalculateTPSL( - double &mSL, // Hold SL - double &mTP, // Hold TP - ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) - double mEntry, // Entry Price - double mR2R = 1, // Provided Risk To Reward Ratio - double slPrice = 0, // Provided SL Price - double tpPrice = 0, // Provided TP Price - double priceToRisk = 0, // If Entry equal to Provided SL Price Risk Point - double priceToReward = 0 // If Entry equal to Provided TP Price Reward Point -) -{ - // - // if Both TP and SL Provided, ignore R2R and Calculate direct ... - // if SL provided, Calculate TP based on Provided R2R ... - // if TP provided, Calculate SL based on Provided R2R ... - // default R2R is set to 1 ... - - // - mSL = 0; - mTP = 0; - - // - bool isLong = IsLong(mType); - - // - // Set Default R2R ... - if (mR2R < 1) - { - mR2R = 1; - } - - // - if (mEntry <= 0 || - (tpPrice <= 0 && slPrice <= 0)) - { - return; - } - - // - double risk = 0; - double reward = 0; - - // - bool canCalculateBasedOnSL = slPrice > 0 && - (isLong - ? slPrice <= mEntry - : slPrice >= mEntry); - - // - bool canCalculateBasedOnTP = tpPrice > 0 && - (isLong - ? tpPrice >= mEntry - : tpPrice <= mEntry); - - // - if (canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - risk = MathAbs(mEntry - slPrice); - if (risk == 0) - { - risk = priceToRisk; - } - reward = risk * mR2R; - } - else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = MathAbs(mEntry - tpPrice); - if (reward == 0) - { - reward = priceToReward; - } - risk = reward / mR2R; - } - else if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - bool canSetTPPrice = isLong - ? tpPrice > mEntry - : tpPrice < mEntry; - if (canSetTPPrice) - { - mTP = tpPrice; - } - - // - bool canSetSLPrice = isLong - ? slPrice < mEntry - : slPrice > mEntry; - if (canSetSLPrice) - { - mSL = slPrice; - } - - // - return; - } - else if (canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - bool canSetTPPrice = isLong - ? tpPrice > mEntry - : tpPrice < mEntry; - if (canSetTPPrice) - { - mTP = tpPrice; - } - - // - bool canSetSLPrice = isLong - ? slPrice < mEntry - : slPrice > mEntry; - if (canSetSLPrice) - { - mSL = slPrice; - } - - // - return; - } - - // - mTP = isLong - ? mEntry + reward - : mEntry - reward; - - // - mSL = isLong - ? mEntry - risk - : mEntry + risk; -} - -// -bool CalculateTPSLByPoint( - double &mSL, // Hold SL - double &mTP, // Hold TP - ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) - double mEntry, // Entry Price - double mPointValue, // Point Value - double mR2R = 1, // Provided Risk To Reward Ratio - double slPoint = 0, // Provided SL Point - double tpPoint = 0 // Provided TP Point -) -{ - // - bool result = false; - - // - mSL = 0; - mTP = 0; - - // - bool isLong = IsLong(mType); - - // - // Set Default R2R ... - if (mR2R < 1) - { - mR2R = 1; - } - - // - if (mEntry <= 0 || - mPointValue <= 0 || - (slPoint <= 0 && tpPoint <= 0)) - { - return result; - } - - // - double risk = 0; - double reward = 0; - - // - bool canCalculateBasedOnSL = slPoint > 0; - - // - bool canCalculateBasedOnTP = tpPoint > 0; - - // - if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - return result; - } - - // - if (canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = tpPoint * mPointValue; - risk = slPoint * mPointValue; - } - else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = tpPoint * mPointValue; - risk = reward / mR2R; - } - else if (canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - risk = slPoint * mPointValue; - reward = risk * mR2R; - } - - // - result = risk > 0 && reward > 0; - if (!result) - { - return result; - } - - // - mTP = isLong - ? mEntry + reward - : mEntry - reward; - - // - mSL = isLong - ? mEntry - risk - : mEntry + risk; - - // - return result; -} - -// -bool CalculateTPSLByPrice( - double &mSL, // Hold SL - double &mTP, // Hold TP - ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) - double mEntry, // Entry Price - double mR2R = 1 // Provided Risk To Reward Ratio -) -{ - // - bool result = false; - - // - bool isLong = IsLong(mType); - - // - // Set Default R2R ... - if (mR2R < 1) - { - mR2R = 1; - } - - // - if (mEntry <= 0 || - (mSL <= 0 && mTP <= 0)) - { - return result; - } - - // - double risk = 0; - double reward = 0; - - // - bool canCalculateBasedOnSL = mSL > 0; - bool canCalculateBasedOnTP = mTP > 0; - - // - if ( - !canCalculateBasedOnSL && - !canCalculateBasedOnTP) - { - return result; - } - - // - if (!canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = MathAbs(mTP - mEntry); - risk = reward / mR2R; - } - else if (canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - risk = MathAbs(mEntry - mSL); - reward = risk * mR2R; - } - - // - result = risk > 0 && reward > 0; - if (!result) - { - return result; - } - - // - mTP = isLong - ? mEntry + reward - : mEntry - reward; - - // - mSL = isLong - ? mEntry - risk - : mEntry + risk; - - // - return result; -} - -/** - * Retrieve Current Tick ... - */ -bool GetTick( - string mSymbol, - MqlTick &tick // -) -{ - return SymbolInfoTick(mSymbol, tick); -} - -/** - * Retrieve Tick Entry ... - */ -double GetTickEntry( - MqlTick &mTick, - ENUM_POSITION_TYPE type, - string mSymbol = NULL // -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsLong(type) - ? mTick.ask - : mTick.bid; - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -/** - * Retrieve Tick Exit ... - */ -double GetTickExit( - MqlTick &mTick, - ENUM_POSITION_TYPE type, - string mSymbol = NULL // -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsLong(type) - ? mTick.bid - : mTick.ask; - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -/** - * Calculate Momentum Changes based on Given Price - */ -double CalculateMomentum( - double currentPrice, - double previousPrice // -) -{ - // - double result = 0; - - // - return result; -} - -/** - * Detect Possible Momentum Changes - * Using MqlTick ... - */ -bool DetectMomentumChange( - ENUM_POSITION_TYPE type, - string mSymbol = NULL, - int mLength = 14 // -) -{ - // - bool result = false; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - MqlTick ticks[]; - int copied = CopyTicks( - mSymbol, - ticks, - COPY_TICKS_ALL, - 0, - mLength + 1 // - ); - - // - result = copied > mLength; - if (!result) - { - return result; - } - - // - double previousPrice = GetTickExit( - ticks[mLength], - type, - mSymbol // - ); - for (int i = mLength - 1; i >= 0; i--) - { - // - double currentPrice = GetTickExit( - ticks[i], - type, - mSymbol // - ); - - // - double momentum = CalculateMomentum( - currentPrice, - previousPrice // - ); - - // - if (fabs(momentum) > 1.0) - { - // - result = true; - break; - } - } - - // - return result; -} - -// -// Fill Specified Applied Prices ... -int FillPrice( - double &buffer[], - ENUM_APPLIED_PRICE _mAppliedTo = PRICE_CLOSE, - string _mSymbol = NULL, - ENUM_TIMEFRAMES _mPeriod = NULL, - int _mStart = 0, - int _mLoopback = 10 // -) -{ - // - int result = 0; - - // - if (_mStart < 0) - { - _mStart = 0; - } - - // - if (_mLoopback < 7) - { - _mLoopback = 7; - } - - // - _mSymbol = NormalizeSymbol(_mSymbol); - _mPeriod = NormalizePeriod(_mPeriod); - - // - Clean(buffer); - ArraySetAsSeries(buffer, true); - - // - double open[]; - result = CopyOpen( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - open // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - double high[]; - result = CopyHigh( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - high // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - double low[]; - result = CopyLow( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - low // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - double close[]; - result = CopyClose( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - close // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - for (int i = 0; i < result; i++) - { - // - double iPrice = GetAppliedPrice( - _mAppliedTo, - open, - high, - low, - close, - i // - ); - - // - Add( - iPrice, - buffer // - ); - } - - // - result = ArraySize(buffer); - - // - return result; -} - -// -// Symbols ... - -// -// Retrieve Available Symbols ... -int GetAllSymbols( - string &symbols[], // Hold Result - bool onlyInWatchList = false, // Specified Retrieve only Symbols which in Watch List - bool forceClean = true // Force To Clean Result Array -) -{ - // - int result = 0; - - // - if (forceClean) - { - Clean(symbols); - } - - // - int beforeSize = ArraySize(symbols); - - // - int symbolsCount = SymbolsTotal(onlyInWatchList); - if (symbolsCount <= 0) - { - return result; - } - - // - for (int i = 0; i < symbolsCount; i++) - { - // - string iSymbol = SymbolName( - i, - onlyInWatchList - // - ); - if (!IsValid(iSymbol)) - { - continue; - } - - // - Add( - iSymbol, - symbols - // - ); - } - - // - int afterSize = ArraySize(symbols); - - // - result = afterSize - beforeSize; - - // - return result; -} - -// -// This is a Global Way to Filter Symbols -// you can pass Specific string as Query or a List String for Filtering ... -int FilterSymbols( - string query, // Which Query to Search Symbol - string &symbols[], // Hold Result - bool onlyInWatchList = false, // Specified Retrieve only Symbols which in Watch List - bool forceClean = true, // Force To Clean Result Array - bool ignoreCase = true, // Ignore Case - string querySeparator = "," // If Provided means query is a COllection of Queries and need to be Splitted -) -{ - // - int result = 0; - - // - if (forceClean) - { - Clean(symbols); - } - - // - if (!IsValid(query)) - { - return result; - } - - // - // Check Query is an String array or not ... - string mQueries[]; - int queriesCount = 0; - if (IsValid(querySeparator) && Contains(querySeparator, query, true)) - { - // - queriesCount = SplitContent( - mQueries, - query, - querySeparator - // - ); - } - - // - int beforeSize = ArraySize(symbols); - - // - string allSymbols[]; - int allSymbolsCount = GetAllSymbols( - allSymbols, - onlyInWatchList, - forceClean); - if (allSymbolsCount <= 0) - { - return result; - } - - // - // Loop Through all Symbols ... - for (int i = 0; i < allSymbolsCount; i++) - { - // - string iSymbol = allSymbols[i]; - - // - bool isFilterPassed = false; - if (queriesCount == 0) - { - // - isFilterPassed = Contains( - query, - iSymbol, - ignoreCase - // - ); - } - else if (queriesCount > 0) - { - // - isFilterPassed = Contains( - mQueries, - iSymbol, - ignoreCase - // - ); - } - - // - if (isFilterPassed) - { - // - Add( - iSymbol, - symbols - // - ); - } - } - - // - int afterSize = ArraySize(symbols); - - // - result = afterSize - beforeSize; - - // - return result; -} - -// -int FilterUSDSymbols( - string &symbols[], // Hold Result - bool onlyInWatchList = false, // Specified Retrieve only Symbols which in Watch List - bool forceClean = true, // Force To Clean Result Array - bool ignoreCase = true, // Ignore Case - string querySeparator = "," // If Provided means query is a COllection of Queries and need to be Splitted -) -{ - // - return FilterSymbols( - "USD", - symbols, - onlyInWatchList, - forceClean, - ignoreCase, - querySeparator - // - ); -} - -// -// Time / Date ... - -// -// 0 => Sunday -// 1 => Monday -// 2 => Tuesday -// 3 => Wednesday -// 4 => Thursday -// 5 => Friday -// 6 => Saturday -enum ENUM_X_WEEK_DAYS -{ - X_WEEK_DAY_NONE = -1, - X_WEEK_DAY_SUNDAY = 0, - X_WEEK_DAY_MONDAY = 1, - X_WEEK_DAY_TUESDAY = 2, - X_WEEK_DAY_WEDNESDAY = 3, - X_WEEK_DAY_THURSDAY = 4, - X_WEEK_DAY_FRIDAY = 5, - X_WEEK_DAY_SATURDAY = 6, -}; - -// -// Retrieve Day of Week ... -ENUM_X_WEEK_DAYS GetDayOfWeek( - datetime time = NULL // -) -{ - // - ENUM_X_WEEK_DAYS result = X_WEEK_DAY_NONE; - - // - time = NormalizeTime(time); - MqlDateTime timeStruct; - bool hasDate = TimeToStruct( - time, - timeStruct // - ); - if (!hasDate) - { - return result; - } - - // - result = (ENUM_X_WEEK_DAYS)timeStruct.day_of_week; - - // - return result; -} - -// -// Representation of Time Struct ... -// struct MqlDateTime -// { -// int year; // Year -// int mon; // Month -// int day; // Day -// int hour; // Hour -// int min; // Minutes -// int sec; // Seconds -// int day_of_week; // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) -// int day_of_year; // Day number of the year (January 1st is assigned the number value of zero) -// }; - -// -// Converts Time to Seconds ... -ulong TimeToSeconds( - datetime time // Specify time to Convert ... -) -{ - // - ulong result = (ulong)time; - - // - return result; -} -ulong TimeToSeconds( - MqlDateTime &time // Specify time to Convert ... -) -{ - // - datetime dTime = StructToTime(time); - - // - ulong result = TimeToSeconds(dTime); - - // - return result; -} - -// -// Converts Seconds To Time ... -datetime SecondsToTime( - ulong seconds // Specify Seconds to Convert ... -) -{ - // - datetime result = (datetime)seconds; - - // - return result; -} -MqlDateTime SecondsToStruct( - ulong seconds // Specify Seconds to Convert ... -) -{ - // - datetime dTime = SecondsToTime(seconds); - - // - MqlDateTime result = {}; - TimeToStruct( - dTime, - result); - - // - return result; -} - -// -// Converts Time to MilliSeconds ... -ulong TimeToMilliSeconds( - datetime time // Specify time to Convert ... -) -{ - // - ulong result = TimeToSeconds(time) * 1000; - - // - return result; -} -ulong TimeToMilliSeconds( - MqlDateTime &time // Specify time to Convert ... -) -{ - // - datetime dTime = StructToTime(time); - - // - ulong result = TimeToMilliSeconds(dTime); - - // - return result; -} - -// -// Converts MillisSeconds to Time ... -datetime MilliSecondsToTiem( - ulong milliSeconds // Specify MilliSeconds to Convert ... -) -{ - // - ulong seconds = milliSeconds / 1000; - - // - datetime result = SecondsToTime(seconds); - - // - return result; -} -MqlDateTime MilliSecondsToStruct( - ulong milliSeconds // Specify MilliSeconds to Convert ... -) -{ - // - datetime dTime = MilliSecondsToTiem(milliSeconds); - - // - MqlDateTime result = {}; - TimeToStruct( - dTime, - result); - - // - return result; -} - -// -// Converts Hours to Seconds ... -int HoursToSeconds(int value) -{ - // - int result = 0; - - // - if (value < 0) - { - value = 0; - } - - // - if (value == 0) - { - return result; - } - - // - result = value * 60 * 60; - - // - return result; -} - -// -// Retrieve DateTime Structure ... -MqlDateTime GetCurrentTime() -{ - // - MqlDateTime result = {}; - - // - datetime cTime = TimeCurrent(); - TimeToStruct(cTime, result); - - // - return result; -} - -// -// Retrieve Current Time as Seconds ... -ulong GetCurrentTimeAsSeconds() -{ - // - datetime time = TimeCurrent(); - - // - ulong result = TimeToSeconds(time); - - // - return result; -} - -// -// Retrieve Current Time as MilliSeconds ... -ulong GetCurrentTimeAsMilliSeconds() -{ - // - datetime time = TimeCurrent(); - - // - ulong result = TimeToMilliSeconds(time); - - // - return result; -} - -// -int GetLocalOffset() -{ - // - MqlDateTime cTimeStruct; - datetime cTime = TimeCurrent(cTimeStruct); - - // - MqlDateTime cLTimeStruct; - datetime cLTime = TimeLocal(cLTimeStruct); - - // - cTimeStruct.sec = 0; - cTime = StructToTime(cTimeStruct); - - // - cLTimeStruct.sec = 0; - cLTime = StructToTime(cLTimeStruct); - - // - int result = ((int)cLTime - (int)cTime); - - // - return result; -} - -// -int GetUTCRequiredTimeOffset() -{ - // - int utcOffset = TimeGMTOffset(); - int localOffset = GetLocalOffset(); - - // - int result = utcOffset + localOffset; - - // - return result; -} - -// -datetime GetUTCTime( - datetime time = NULL, - bool applyTradeServerTime = false // -) -{ - // - datetime result = NULL; - - // - NormalizeTime(time); - - // - datetime cTime = TimeCurrent(); - datetime cTimeLocal = TimeLocal(); - - // - int cLocalOffset = ((int)cTimeLocal - (int)cTime); - int gmtOffset = TimeGMTOffset(); - int offsetDelte = gmtOffset + cLocalOffset; - int requiredUTCOffset = GetUTCRequiredTimeOffset(); - if (requiredUTCOffset > 0) - { - requiredUTCOffset = -1 * requiredUTCOffset; - } - - // - int timeSeconds = (int)time; - int resultSeconds = timeSeconds + requiredUTCOffset; - - // - result = (datetime)(resultSeconds); - - // - return result; -} - -// -// Retrieve only Hour and Minute as String ... -string GetTimeString( - datetime time = NULL // -) -{ - // - NormalizeTime(time); - - // - string result = NULL; - - // - MqlDateTime tStruct; - bool isStructed = TimeToStruct(time, tStruct); - if (!isStructed) - { - return result; - } - - // - string hour = ToString(tStruct.hour); - hour = - StringLen(hour) == 1 - ? "0" + hour - : hour; - - // - string minute = ToString(tStruct.min); - minute = - StringLen(minute) == 1 - ? "0" + minute - : minute; - - // - result = hour + ":" + minute; - - // - return result; -} - -// -// Converts a Date time to File Format ... -string ToFormatString( - datetime mTime, - string separator = "_" // -) -{ - // - string result = NULL; - - // - if (!IsValid(mTime)) - { - return result; - } - - // - MqlDateTime timeStruct; - bool isConverts = TimeToStruct( - mTime, - timeStruct // - ); - if (!isConverts) - { - return result; - } - - // - string year = ToString(timeStruct.year); - string month = ToString(timeStruct.mon); - string day = ToString(timeStruct.day); - string hour = ToString(timeStruct.hour); - string minute = ToString(timeStruct.min); - string second = ToString(timeStruct.sec); - - // - result = - // - // Year ... - year + separator + - // - // Month ... - (StringLen(month) == 1 - ? "0" + month - : month) + - separator + - // - // Day ... - (StringLen(day) == 1 - ? "0" + day - : day) + - separator + - // - // Hour ... - (StringLen(hour) == 1 - ? "0" + hour - : hour) + - separator + - // - // Minute ... - (StringLen(minute) == 1 - ? "0" + minute - : minute) + - separator + - // - // Seconds ... - (StringLen(second) == 1 - ? "0" + second - : second) + - separator + - // - "" - // - ; - - // - return result; -} - -/** - * Converts an String Represetation of Time (00:00) to Date Time .. - * - * @param value: String ... - * - * @return ( datetime ) - */ -datetime ParseDateTimeFromTimeString(string value) -{ - // - datetime result = NULL; - - // - if (!IsValid(value)) - { - return result; - } - - // - // Check Signalling Time ... - MqlDateTime cTime; - bool isTimeRecieved = TimeCurrent(cTime); - if (!isTimeRecieved) - { - return result; - } - - // - // Split ... - string parts[]; - int partsCount = SplitContent( - parts, - value, - ":" - // - ); - if (!IsValidSize(partsCount)) - { - return result; - } - - // - int hour = 0; - int minute = 0; - if (partsCount >= 1) - { - hour = (int)(parts[0]); - } - if (partsCount >= 2) - { - minute = (int)(parts[1]); - } - - // - cTime.day_of_week = 0; - cTime.day_of_year = 0; - - // - cTime.hour = hour; - cTime.min = minute; - - // - result = StructToTime(cTime); - - // - return result; -} - -// -// Check Specific Time in Range of another Time ... -bool IsTimeInRange( - datetime currentTime = NULL, - datetime startTime = NULL, - datetime stopTime = NULL // -) -{ - // - bool result = false; - - // - // Normallize Current Time ... - currentTime = NormalizeTime(currentTime); - - // - result = !IsValid(startTime) && - !IsValid(stopTime); - if (result) - { - return result; - } - - // - result = IsValid(startTime) && - IsValid(stopTime); - if (!result) - { - // - result = IsValid(startTime) && - currentTime >= startTime; - - // - return result; - } - - // - result = currentTime >= startTime && - currentTime < stopTime; - - // - return result; -} -bool IsTimeInRange( - datetime currentTime, - string startTime, - string endTime // -) -{ - // - bool result = false; - - // - result = IsValid(startTime) && - IsValid(endTime); - if (!result) - { - // - // Here Since there isnot provide any - // data source we pass result as true ... - result = true; - return result; - } - - // - // Converts String Representation to Time ... - datetime st = ParseDateTimeFromTimeString(startTime); - datetime et = ParseDateTimeFromTimeString(endTime); - - // - result = IsTimeInRange( - currentTime, - st, - et // - ); - - // - return result; -} - -// -// Bar Times ... - -// -// Retrieve Specified Bar Time ... -datetime GetBarTime( - string mSymbol = "", // Specify Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame - int barIndex = 0 // Specify Bar Index -) -{ - // - // Validate and Normalize Args ... - - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - // Retrieve Bar Time ... - datetime result = iTime( - mSymbol, - mPeriod, - barIndex); - - // - return result; -} - -// -// Retrieve Specified Bar Time ... -ulong GetBarTimeAsSeconds( - string mSymbol = "", // Specify Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame - int barIndex = 0 // Specify Bar Index -) -{ - // - // Retrieve Bar Time ... - datetime time = GetBarTime( - mSymbol, - mPeriod, - barIndex); - - // - ulong result = TimeToSeconds(time); - - // - return result; -} - -// -// Retrieve Specified Bar Time ... -ulong GetBarTimeAsMilliSeconds( - string mSymbol = "", // Specify Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame - int barIndex = 0 // Specify Bar Index -) -{ - // - // Retrieve Bar Time ... - datetime time = GetBarTime( - mSymbol, - mPeriod, - barIndex); - - // - ulong result = TimeToMilliSeconds(time); - - // - return result; -} - -// -// Retrieve a Bar Time Structure ... -MqlDateTime GetBarTimeStruct( - string mSymbol = "", // Specify Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame - int barIndex = 0 // Specify Bar Index -) -{ - // - MqlDateTime result = {}; - - // - // Retrieve Bar Time ... - datetime barTime = GetBarTime( - mSymbol, - mPeriod, - barIndex); - - // - // Convert to Structure ... - TimeToStruct(barTime, result); - - // - return result; -} - -// -// Retrieve Last Available Bar Time of -// Dest Period inside Source Period ... -datetime GetLastBarTime( - ENUM_TIMEFRAMES sourcePeriod, - ENUM_TIMEFRAMES destPeriod // -) -{ - // - datetime result = NULL; - - // - if (!IsValid(sourcePeriod) || - !IsValid(destPeriod)) - { - return result; - } - - // - int sourceSeconds = PeriodSeconds(sourcePeriod); - int destSeconds = PeriodSeconds(destPeriod); - if (sourceSeconds < destSeconds) - { - return result; - } - - // - XOHCL sourceBar; - bool isInited = sourceBar.Init( - _Symbol, - sourcePeriod, - 0 // - ); - if (!isInited) - { - return result; - } - - // - result = (datetime)((((int)sourceBar.time) + sourceSeconds) - destSeconds); - - // - return result; -} - -// -// Other Tools ... - -// -template -bool IsSame( - T &buffer[], // Search Buffer - int count = 5, // Number of Searchs - int start = 0 // Start ... -) -{ - // - bool result = false; - - // - int bufferSize = ArraySize(buffer); - result = bufferSize > 0; - if (!result) - { - return result; - } - - // - // Validate Count ... - result = start + count < bufferSize; - if (!result) - { - return result; - } - - // - T iTem = buffer[start]; - for (int i = start; i < start + count; i++) - { - // - if (iTem != buffer[i]) - { - result = false; - break; - } - - // - if (!result) - { - result = true; - } - } - - // - return result; -} - -// -// Check first Cross Over second at index ... -bool IsCrossedOver( - const double &first[], // the buffer which check crossing over second buffer - const double &second[], // first buffer checks based on this buffer - const int index = 0 // check crosses in specific index -) -{ - // - bool result = false; - - // - // Validate Args ... - if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) - { - return result; - } - - // - result = first[index] > second[index] && - !(first[index + 1] > second[index + 1]); - - // - return result; -} - -// -// Check first is Over second at index ... -bool IsOver( - const double &first[], // the buffer which check over second buffer - const double &second[], // first buffer checks based on this buffer - const int index = 0 // check crosses in specific index -) -{ - // - bool result = false; - - // - // Validate Args ... - if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) - { - return result; - } - - // - result = first[index] > second[index] && - first[index + 1] > second[index + 1]; - - // - return result; -} - -// -// Check first Cross Under second at index ... -bool IsCrossedUnder( - const double &first[], // the buffer which check crossing under second buffer - const double &second[], // first buffer checks based on this buffer - const int index = 0 // check crosses in specific index -) -{ - // - bool result = false; - - // - // Validate Args ... - if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) - { - return result; - } - - // - result = first[index] < second[index] && - !(first[index + 1] < second[index + 1]); - - // - return result; -} - -// -// Check first is Under second at index ... -bool IsUnder( - const double &first[], // the buffer which check under second buffer - const double &second[], // first buffer checks based on this buffer - const int index = 0 // check crosses in specific index -) -{ - // - bool result = false; - - // - // Validate Args ... - if (ArraySize(first) < index + 1 || ArraySize(second) < index + 1) - { - return result; - } - - // - result = first[index] < second[index] && - first[index + 1] < second[index + 1]; - - // - return result; -} - -// -// Check if a Value Increasing in Loopback ... -bool IsIncreasing( - const double &buffer[], // the Buffer which required to search - int from = -1, // Last Time Index - int to = -1 // Fisrs Tima Index -) -{ - // - bool result = false; - - // - if (from == -1) - { - from = ArraySize(buffer) - 1; - } - - // - if (to == -1) - { - to = 0; - } - - // - // Validate Args ... - if ( - from <= to || - ArraySize(buffer) < from + 1) - { - return result; - } - - // - // Loop through Items ... - double toValue = buffer[to]; - double fromValue = buffer[from]; - result = toValue >= fromValue; - for (int i = to + 1; i <= from - 1; i++) - { - // - double iValue = buffer[i]; - bool isPassed = toValue >= iValue; - - // - bool isIIncreasing = IsIncreasing( - buffer, - from, - i // - ); - - // - // Check Result ... - result = result && isPassed && isIIncreasing; - if (!result) - { - break; - } - } - - // - return result; -} - -// -// Check if a Value Decreasing in Loopback ... -bool IsDecreasing( - const double &buffer[], // the Buffer which required to search - int from = -1, // Last Time Index - int to = -1 // Fisrs Tima Index -) -{ - // - bool result = false; - - // - if (from == -1) - { - from = ArraySize(buffer) - 1; - } - - // - if (to == -1) - { - to = 0; - } - - // - // Validate Args ... - if ( - from <= to || - ArraySize(buffer) < from + 1) - { - return result; - } - - // - // Loop through Items ... - double toValue = buffer[to]; - double fromValue = buffer[from]; - result = toValue <= fromValue; - for (int i = to + 1; i <= from - 1; i++) - { - // - double iValue = buffer[i]; - bool isPassed = toValue <= iValue; - - // - bool isIDecreasing = IsDecreasing( - buffer, - from, - i // - ); - - // - // Check Result ... - result = result && isPassed && isIDecreasing; - if (!result) - { - break; - } - } - - // - return result; -} - -// -bool IsTrendingUp( - const double &buffer1[], // First Buffer - const double &buffer2[] // Seccend Buffer -) -{ - // - bool result = false; - - // - int buffer1Count = ArraySize(buffer1); - int buffer2Count = ArraySize(buffer2); - if (buffer1Count <= 0 || buffer2Count <= 0) - { - return result; - } - - // - int count = MathMin(buffer1Count, buffer2Count); - if (count <= 1) - { - return result; - } - - // - int upCounts = 0; - int downCounts = 0; - double value = MathAbs(buffer1[0] - buffer2[0]); - for (int i = 1; i < count; i++) - { - // - double iValue = MathAbs(buffer1[i] - buffer2[i]); - - // - if (value > iValue) - { - upCounts++; - } - - // - if (value < iValue) - { - downCounts++; - } - } - - // - result = upCounts > 1 && upCounts > downCounts; - - // - return result; -} - -// -bool IsTrendingDown( - const double &buffer1[], // First Buffer - const double &buffer2[] // Seccend Buffer -) -{ - // - bool result = false; - - // - int buffer1Count = ArraySize(buffer1); - int buffer2Count = ArraySize(buffer2); - if (buffer1Count <= 0 || buffer2Count <= 0) - { - return result; - } - - // - int count = MathMin(buffer1Count, buffer2Count); - if (count <= 1) - { - return result; - } - - // - int upCounts = 0; - int downCounts = 0; - double value = MathAbs(buffer1[0] - buffer2[0]); - for (int i = 1; i < count; i++) - { - // - double iValue = MathAbs(buffer1[i] - buffer2[i]); - - // - if (value > iValue) - { - upCounts++; - } - - // - if (value < iValue) - { - downCounts++; - } - } - - // - result = downCounts > 1 && downCounts > upCounts; - - // - return result; -} - -// -// Calculate Slope of Specified Buffer at Specified Index ... -double GetSlope( - const double &buffer[], // Buffer - int from, // In Past Index ... - int to // In Past Index ... -) -{ - // - double result = 0; - - // - if (from > ArraySize(buffer) || to > ArraySize(buffer)) - { - return result; - } - - // - double toValue = buffer[to]; - double fromValue = buffer[from]; - double deltaValue = toValue - fromValue; - double deltaTime = from - to; - - // - result = deltaValue / deltaTime; - - // - return result; -} - -// -// Check Bar Reject Specified Value ... -bool IsBarReject( - double value, - ENUM_X_DIRECTION dir, - XOHCL &bar // -) -{ - // - bool result = false; - - // - result = value > 0 && - bar.IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - bool isUp = IsBullish(dir); - bool isDown = IsBearish(dir); - - // - result = - // - isUp - ? bar.IsBullish() && - bar.low < value && - bar.GetDown() > value - : isDown - ? bar.IsBearish() && - bar.high > value && - bar.GetUp() < value - : false - // - ; - - // - return result; -} - -// -// Check Bar Break Specified Value ... -bool IsBarBreak( - double value, - ENUM_X_DIRECTION dir, - XOHCL &bar // -) -{ - // - bool result = false; - - // - result = value > 0 && - bar.IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - bool isUp = IsBullish(dir); - bool isDown = IsBearish(dir); - - // - result = - isUp - ? bar.IsBullish() && - ((bar.GetDown() < value && - bar.GetUp() > value) || - (bar.close > value && - pBar.close < value)) - : isDown - ? bar.IsBearish() && - ((bar.GetUp() > value && - bar.GetDown() < value) || - (bar.close < value && - pBar.close > value)) - : false; - - // - return result; -} - -// -// Calculate Fib Level ... -double GetFibonacciLevel( - double upPrice, // Upper Bound - double downPrice, // Downer Bound - double level, // Level Multiplier Factor - int direction // From Down to Up < 0, other wise Vice Versa - // -) -{ - // - double ling = upPrice - downPrice; - double pLevel = (ling / 100) * (level * 100); - - // - double result = direction > 0 ? upPrice - pLevel : downPrice + pLevel; - - // - return result; -} - -// -// Method 1 -// Normalize between 1 and 0 ... -template -double GetNormalizedValueMethod1( - T &buffer[], // Array which required to Normalize - int mLength, // Length of Normalization - int mStart = 0, // start index - int digits = 5 // Normalization Digits -) -{ - // - double result = 0; - - // - if (digits <= 5) - { - digits = 5; - } - - // - int bufferSize = ArraySize(buffer); - if (!IsValidSize(bufferSize)) - { - return result; - } - - // - // Normalize Count ... - NormalizeCount( - mStart, - mLength, - buffer // - ); - - // - T max = 0; - T min = 0; - - // - if (bufferSize != mLength) - { - // - T tmp[]; - Copy( - mStart, - mLength, - buffer, - tmp // - ); - - // - max = GetMax(tmp); - min = GetMin(tmp); - } - - // - if (bufferSize == mLength) - { - // - max = GetMax(buffer); - min = GetMin(buffer); - } - - // - T iValue = buffer[mStart]; - - // - double minMaxDiff = (max - min); - if (minMaxDiff <= 0) - { - return result; - } - - // - result = (iValue - min) / minMaxDiff; - - // - result = NormalizeDouble(result, digits); - - // - return result; -} - -// -// Method 2 -// Normalize Between Specified Upper and Lower ... -template -double GetNormalizedValueMethod2( - T &buffer[], // Array which required to Normalize - int mLength, // Length of Normalization - int mUpper, // Specified Upper Value - int mLower, // Specified Lower Value - int mStart = 0, // start index - int digits = 5 // Normalization Digits -) -{ - // - double result = 0; - - // - if (digits <= 5) - { - digits = 5; - } - - // - int bufferSize = ArraySize(buffer); - if (!IsValidSize(bufferSize)) - { - return result; - } - - // - // Normalize Count ... - NormalizeCount( - mStart, - mLength, - buffer // - ); - - // - T max = 0; - T min = 0; - - // - if (bufferSize != mLength) - { - // - T tmp[]; - Copy( - mStart, - mLength, - buffer, - tmp // - ); - - // - max = GetMax(tmp); - min = GetMin(tmp); - } - - // - if (bufferSize == mLength) - { - // - max = GetMax(buffer); - min = GetMin(buffer); - } - - // - T iValue = buffer[mStart]; - - // - double minMaxDiff = (max - min); - double boundaryDiff = (mUpper - mLower); - if (minMaxDiff <= 0 || boundaryDiff <= 0) - { - return result; - } - - // - result = boundaryDiff / (minMaxDiff * (iValue - max) + max); - - // - result = NormalizeDouble(result, digits); - - // - return result; -} - -// -void NormalizeBuffer( - double &source[], // Source Buffer - double &dest[], // Result Buffer - double upper = 100, // Upper Value to Normalize - double lower = -100, // Lower Value to Normalize - int size = -1, // Size Of Normalization - int digits = 5 // Digits for Result -) -{ - // - if (size <= 0) - { - size = ArraySize(source); - } - - // - bool asSeriesFlag = ArrayGetAsSeries(source); - - // - ArraySetAsSeries(source, false); - ArraySetAsSeries(dest, false); - - // - double min = ArrayMinimum(source, 0, size); - double max = ArrayMaximum(source, 0, size); - - // - for (int i = 0; i < size; i++) - { - // - double iNormal = lower + ((source[i] - min) / (max - min)) * (upper - lower); - - // - if (digits > 0) - { - iNormal = NormalizeDouble(iNormal, digits); - } - - // - dest[i] = iNormal; - } - - // - ArraySetAsSeries(source, asSeriesFlag); - ArraySetAsSeries(dest, asSeriesFlag); -} - -// -// Templates ... - -// -// Retrieve Specific Object Types Name ... -template -string GetTypeName(const T &t) -{ - return typename(T); -} - -// -template -string GetToken(T &item) -{ - // - string mType = GetTypeName(item); - - // - string result = mType; - - // - string parts[]; - int partsCount = SplitContent( - parts, - result, - " " - // - ); - if (partsCount <= 0) - { - // - result = mType; - return result; - } - - // - bool hasLastPart = GetLastItem( - result, - parts - // - ); - if (!hasLastPart) - { - // - result = mType; - return result; - } - - // - return result; -} - -// -// Same as Get Token for Use in Classes ... -template -string GetSpecificToken(T &item) -{ - // - string mType = GetTypeName(item); - - // - string result = mType; - - // - string parts[]; - int partsCount = SplitContent( - parts, - result, - " " - // - ); - if (partsCount <= 0) - { - // - result = mType; - return result; - } - - // - bool hasLastPart = GetLastItem( - result, - parts - // - ); - if (!hasLastPart) - { - // - result = mType; - return result; - } - - // - return result; -} - -// -// Generate Unique Tags ... -template -string GenerateTag(T &model) -{ - // - string result = ""; - - // - string tag = model.ToString(); - if (StringLen(tag) == 0) - { - return result; - } - - // - static XSCMD5 md5; - - // - result = md5.Hash(tag); - - // - return result; -} - -// -// Hash Specified Content ... -template -string ToMD5(T content) -{ - // - string result = ""; - - // - string strContent = ToString(content); - if (StringLen(strContent) == 0) - { - return result; - } - - // - static XCMD5 md5; - - // - result = md5.Hash(strContent); - - // - return result; -} - -// -// Check a Value Not Empty ... -template -bool NotEmpty(T value) -{ - return value != EMPTY_VALUE; -} - -// -// Check a Value Not Empty and Zero ... -template -bool NotEmptyZero(T value) -{ - return value != EMPTY_VALUE && value != 0; -} - -// -// Add Specified Item to Array ... -template -int Add( - T item, // item want to add - T &buffer[] // Destination buffer -) -{ - // - int result = 0; - - // - ArrayResize( - buffer, - ArraySize(buffer) + 1); - - // - buffer[ArraySize(buffer) - 1] = item; - - // - result = ArraySize(buffer); - - // - return result; -} -template -int AddSpecific( - T item, // item want to add - T &buffer[] // Destination buffer -) -{ - // - return Add( - item, - buffer // - ); -} -template -int AddRef( - T &item, // item want to add - T &buffer[] // Destination buffer -) -{ - // - int result = 0; - - // - ArrayResize( - buffer, - ArraySize(buffer) + 1); - - // - buffer[ArraySize(buffer) - 1] = item; - - // - result = ArraySize(buffer); - - // - return result; -} - -// -// Check Specified Array Has Childs or not ... -template -bool HasChild(T &buffer[]) -{ - return IsValidSize(ArraySize(buffer)); -} -template -bool SpecificHasChild(T &buffer[]) -{ - return HasChild(buffer); -} - -// -// Remove Specified Item from an Array ... -template -bool Remove( - T item, - T &buffer[]) -{ - // - bool result = false; - - // - int itemIndex = FindIndex( - item, - buffer); - if (itemIndex < 0) - { - return result; - } - - // - result = ArrayRemove( - buffer, - itemIndex, - 1); - - // - return result; -} - -// -// Clean Specified Array ... -template -void Clean(T &buffer[]) -{ - // - ArrayResize(buffer, 0); - ArrayFree(buffer); - ZeroMemory(buffer); -} -template -void SpecificClean(T &buffer[]) -{ - Clean(buffer); -} - -// -// Copy Whole Content of Source to Dest array ... -template -void Copy( - T &source[], // Source Buffer ... - T &dest[], // Dest Buffer ... - bool cleanDest = true // Force Clen Dest Buffer ... -) -{ - // - if (cleanDest) - { - Clean(dest); - } - - // - int sourceCount = ArraySize(source); - if (sourceCount <= 0) - { - return; - } - - // - for (int i = 0; i < sourceCount; i++) - { - // - T iSource = source[i]; - - // - AddRef( - iSource, - dest); - } -} - -// -// Copy Items from a Buffer ... -template -int Copy( - int start, // Start - int count, // Number of Items for read - T &source[], // Source Buffer - T &dest[], // Dest Buffer - bool forceClean = true, // Force To Clean buffer - bool forceStart = true // Force To Clean buffer -) -{ - // - int result = 0; - - // - if (forceClean) - { - Clean(dest); - } - - // - if (start < 0 && forceStart) - { - start = 0; - } - - // - if (start >= ArraySize(source)) - { - start = ArraySize(source) - 1; - } - - // - if (count == 0) - { - count = ArraySize(source) - 1 - start; - } - - // - if (start + count > ArraySize(source)) - { - return result; - } - - // - int beforeSize = ArraySize(dest); - - // - bool asSeriesDest = ArrayGetAsSeries(dest); - bool asSeriesSource = ArrayGetAsSeries(source); - - // - ArraySetAsSeries(dest, true); - ArraySetAsSeries(source, true); - - // - ArrayCopy( - dest, - source, - 0, - start, - count - // - ); - - // - int afterSize = ArraySize(dest); - - // - result = afterSize - beforeSize; - - // - ArraySetAsSeries(dest, asSeriesDest); - ArraySetAsSeries(source, asSeriesSource); - - // - return result; -} - -// -// Copy Items from a Buffer ... -template -int CopyRef( - int start, // Start - int count, // Number of Items for read - T &source[], // Source Buffer - T &dest[], // Dest Buffer - bool forceClean = true // Force To Clean buffer -) -{ - // - int result = 0; - - // - if (forceClean) - { - Clean(dest); - } - - // - if (start < 0) - { - start = 0; - } - - // - if (start >= ArraySize(source)) - { - start = ArraySize(source) - 1; - } - - // - int beforeSize = ArraySize(dest); - - // - bool asSeriesDest = ArrayGetAsSeries(dest); - bool asSeriesSource = ArrayGetAsSeries(source); - - // - ArraySetAsSeries(dest, true); - ArraySetAsSeries(source, true); - - // - for (int i = start; i < start + count; i++) - { - // - AddRef( - source[i], - dest - // - ); - } - - // - int afterSize = ArraySize(dest); - - // - result = afterSize - beforeSize; - - // - ArraySetAsSeries(dest, asSeriesDest); - ArraySetAsSeries(source, asSeriesSource); - - // - return result; -} - -// -// Retrive Last Item of Specified Buffer ... -template -bool GetLastItem( - T &item, // Holds Result - T &buffer[] // Specified Buffer -) -{ - // - bool result = false; - - // - int bufferSize = ArraySize(buffer); - if (bufferSize <= 0) - { - return result; - } - - // - item = buffer[bufferSize - 1]; - - // - result = true; - return result; -} - -// -// Remove Last Item of Specified Buffer ... -template -bool RemoveLastItem( - T &buffer[] // Specified Buffer -) -{ - // - bool result = false; - - // - int count = ArraySize(buffer); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - ArrayRemove( - buffer, - count - 1, - 1 // - ); - - // - return result; -} - -template -void CleanupArray( - T &buffer[], // Buffer to Cleanup ... - int maxAllowed = 0 // Max Allowed Number of items ... -) -{ - // - if (maxAllowed <= 0) - { - return; - } - - // - int count = ArraySize(buffer); - if (!IsValidSize(count) || - count <= maxAllowed) - { - return; - } - - // - int mustRemove = count - maxAllowed; - if (!IsValidSize(mustRemove)) - { - return; - } - - // - ArrayRemove( - buffer, - 0, - mustRemove // - ); -} - -// -// Search Array For Specific Item ... -template -int FindIndex( - T item, // What is Search ... - T &buffer[] // Search in ... -) -{ - // - int result = -1; - - // - int count = ArraySize(buffer); - if (count <= 0) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - T iT = buffer[i]; - - // - if (iT == item) - { - // - result = i; - break; - } - } - - // - return result; -} - -// -// Check an Array Contains Specified Value ... -template -bool Contains( - T item, // What is Search ... - T &buffer[] // Search in ... -) -{ - // - bool result = false; - - // - int idx = FindIndex( - item, - buffer); - result = idx > -1; - - // - return result; -} - -// -// Calculate a Buffer's Sum ... -template -double GetSum( - T &buffer[], // the Buffer which required to search - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - // - double result = 0; - - // - T tmp[]; - int tmpCount = Copy( - start, - count, - buffer, - tmp - // - ); - if (tmpCount <= 0) - { - return result; - } - - // - // Calculate Summary ... - for (int i = 0; i < tmpCount; i++) - { - result += buffer[i]; - } - - // - return result; -} - -// -// Calculate a Buffer's Average ... -template -double GetAverage( - T &buffer[], // the Buffer which required to search - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - // - double result = 0; - - // - T tmp[]; - int tmpCount = Copy( - start, - count, - buffer, - tmp - // - ); - if (tmpCount <= 0) - { - return result; - } - - // - // Calculate Summary ... - for (int i = 0; i < tmpCount; i++) - { - result += buffer[i]; - } - - // - // Calculate Average ... - result = result / tmpCount; - - // - return result; -} - -// -// Get Max of Specific Loopback of a Buffer ... -template -T GetMax( - T &buffer[], // the Buffer which required to search - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - // - T result = 0; - - // - if (count <= 0) - { - count = ArraySize(buffer); - } - - // - T tmp[]; - int tmpCount = Copy( - start, - count, - buffer, - tmp - // - ); - if (tmpCount <= 0) - { - return result; - } - - // - // Loop Through LoopBack ... - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - result = - // - result == 0 || result < iValue - // - ? iValue - // - : result - // - ; - } - - // - return result; -} -template -T GetMax( - T &buffer[], // the Buffer which required to search - int &index, // Item Index ... - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - // - T result = 0; - index = -1; - - // - if (count <= 0) - { - count = ArraySize(buffer); - } - - // - T tmp[]; - int tmpCount = Copy( - start, - count, - buffer, - tmp - // - ); - if (tmpCount <= 0) - { - return result; - } - - // - // Loop Through LoopBack ... - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - bool isNew = result == 0; - bool canSet = isNew || - (!isNew && - result < iValue); - if (canSet) - { - // - index = i; - result = iValue; - } - } - - // - return result; -} -template -T GetSpecifiedMax( - T &buffer[], // the Buffer which required to search - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - return GetMax( - buffer, - start, - count // - ); -} -template -T GetSpecifiedMax( - T &buffer[], // the Buffer which required to search - int &index, // Item Index ... - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - return GetMax( - buffer, - index, - start, - count // - ); -} - -// -// Get Min of Specific Loopback of a Buffer ... -template -T GetMin( - T &buffer[], // the Buffer which required to search - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - // - T result = 0; - - // - if (count <= 0) - { - count = ArraySize(buffer); - } - - // - T tmp[]; - int tmpCount = Copy( - start, - count, - buffer, - tmp - // - ); - if (tmpCount <= 0) - { - return result; - } - - // - // Loop Through LoopBack ... - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - result = - // - result == 0 || result > iValue - // - ? iValue - // - : result - // - ; - } - - // - return result; -} -template -T GetMin( - T &buffer[], // the Buffer which required to search - int &index, // Item Index ... - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - // - T result = 0; - index = -1; - - // - if (count <= 0) - { - count = ArraySize(buffer); - } - - // - T tmp[]; - int tmpCount = Copy( - start, - count, - buffer, - tmp - // - ); - if (tmpCount <= 0) - { - return result; - } - - // - // Loop Through LoopBack ... - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - bool isNew = result == 0; - bool canSet = isNew || - (!isNew && - result > iValue); - if (canSet) - { - // - index = i; - result = iValue; - } - } - - // - return result; -} -template -T GetSpecifiedMin( - T &buffer[], // the Buffer which required to search - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - return GetMin( - buffer, - start, - count // - ); -} -template -T GetSpecifiedMin( - T &buffer[], // the Buffer which required to search - int &index, // Item Index ... - int start = 0, // Start Index - int count = 0 // Count for Search -) -{ - return GetMin( - buffer, - index, - start, - count // - ); -} - -// -// Find a Value less than Specified ... -template -T FindLesserThan( - T value, // Specified Value ... - const T &source[], // Source ... - bool isDescend = false // Find Biggest Lesser Value ... -) -{ - // - T result = -1; - - // - int itemsCount = ArraySize(source); - if (itemsCount <= 0) - { - return result; - } - - // - // Make a Copy of source ... - T tmp[]; - - // - ArrayResize( - tmp, - ArraySize(source) // - ); - - // - ArrayCopy( - tmp, - source // - ); - - // - // Sort Temp Buffer ... - ArraySort(tmp); - if (isDescend) - { - ArrayReverse(tmp); - } - - // - int tmpCount = ArraySize(tmp); - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - if (iValue < value) - { - // - result = iValue; - break; - } - } - - // - return result; -} -template -T FindLesserThan( - T value, // Specified Value ... - int &index, // Item Index ... - const T &source[], // Source ... - bool isDescend = false // Find Biggest Lesser Value ... -) -{ - // - T result = -1; - index = -1; - - // - int itemsCount = ArraySize(source); - if (itemsCount <= 0) - { - return result; - } - - // - // Make a Copy of source ... - T tmp[]; - - // - ArrayResize( - tmp, - ArraySize(source) // - ); - - // - ArrayCopy( - tmp, - source // - ); - - // - // Sort Temp Buffer ... - ArraySort(tmp); - if (isDescend) - { - ArrayReverse(tmp); - } - - // - int tmpCount = ArraySize(tmp); - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - if (iValue < value) - { - // - index = i; - result = iValue; - break; - } - } - - // - return result; -} - -// -// Find a Value less than Specified ... -template -T FindBiggerThan( - T value, // Specified Value ... - const T &source[], // Source ... - bool isDescend = false // Find Smallest Bigger Value ... -) -{ - // - T result = -1; - - // - int itemsCount = ArraySize(source); - if (itemsCount <= 0) - { - return result; - } - - // - // Make a Copy of source ... - T tmp[]; - - // - ArrayResize( - tmp, - ArraySize(source) // - ); - - // - ArrayCopy( - tmp, - source // - ); - - // - // Sort Temp Buffer ... - ArraySort(tmp); - if (!isDescend) - { - ArrayReverse(tmp); - } - - // - int tmpCount = ArraySize(tmp); - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - if (iValue > value) - { - // - result = iValue; - break; - } - } - - // - return result; -} -template -T FindBiggerThan( - T value, // Specified Value ... - int &index, // Item Index ... - const T &source[], // Source ... - bool isDescend = false // Find Smallest Bigger Value ... -) -{ - // - T result = -1; - index = -1; - - // - int itemsCount = ArraySize(source); - if (itemsCount <= 0) - { - return result; - } - - // - // Make a Copy of source ... - T tmp[]; - - // - ArrayResize( - tmp, - ArraySize(source) // - ); - - // - ArrayCopy( - tmp, - source // - ); - - // - // Sort Temp Buffer ... - ArraySort(tmp); - if (!isDescend) - { - ArrayReverse(tmp); - } - - // - int tmpCount = ArraySize(tmp); - for (int i = 0; i < tmpCount; i++) - { - // - T iValue = tmp[i]; - - // - if (iValue > value) - { - // - index = i; - result = iValue; - break; - } - } - - // - return result; -} - -// -// Find Same Values in Array ... -template -void FindSames( - T &result[], // Holds Result ... - T &source[], // Source ... - int verifications = 3 // Number of Consequence Repeat ... -) -{ - // - Clean(result); - - // - // TenkanSen Flats ... - int sourceCount = ArraySize(source); - if (sourceCount > verifications) - { - // - T mLast = 0; - int mVerified = 0; - for (int i = 0; i < sourceCount; i++) - { - // - T iVal = source[i]; - if (mLast == 0) - { - mLast = iVal; - } - else if (mLast == iVal) - { - mVerified++; - } - else - { - mLast = iVal; - mVerified = 0; - } - - // - if (iVal == mLast && mVerified >= verifications) - { - // - Add( - iVal, - result); - - // - mLast = 0; - mVerified = 0; - } - } - } -} - -// -// Add an Item to a Buffer if not Exists ... -void AddIfNotExists( - double value, - double &values[], - double smoothingPoint = 3 // -) -{ - // - double smoothingValue = smoothingPoint * GetPoints(_Symbol); - - // - int valuesCount = ArraySize(values); - if (valuesCount <= 0) - { - // - Add(value, - values); - } - else - { - // - bool isExists = false; - for (int i = 0; i < valuesCount; i++) - { - // - double iVal = values[i]; - - // - double diff = MathAbs(iVal - value); - - // - if (iVal == value || diff < smoothingValue) - { - // - isExists = true; - break; - } - } - - // - if (!isExists) - { - // - Add(value, - values); - } - } -} - -// -// Add a Buffers Child to another Buffer -// if it's not Contains them ... -void AddsIfNotExists( - double &source[], - double &dest[], - double smoothingPoint = 3) -{ - // - double smoothingValue = smoothingPoint * GetPoints(_Symbol); - - // - int sourceCount = ArraySize(source); - if (sourceCount <= 0) - { - return; - } - - // - for (int i = 0; i < sourceCount; i++) - { - // - double iSource = source[i]; - - // - AddIfNotExists( - iSource, - dest, - smoothingPoint); - } -} - -// -// Bar XOHCL ... - -// -// Extract Specific Range of Bars ... -// using Start Bar Index ... -int GetBars( - XOHCL &result[], // Hold Result - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Time Frame - int from = 0, // Start Bar Index - int count = 1, // Number of Bars - bool forceClean = true // Clean Result Array -) -{ - // - int mResult = 0; - - // - if (from < 0) - { - from = 0; - } - - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - int total = Bars( - mSymbol, - mPeriod); - if (from > total - 2) - { - from = total - 2; - } - - // - if (count < 0) - { - count = 1; - } - - // - int start = from; - int end = start + count; - if (end > total - 1) - { - end = total - 1; - } - - // - if (forceClean) - { - Clean(result); - } - - // - int beforeSize = ArraySize(result); - - // - for (int i = start; i < end; i++) - { - // - XOHCL iBar; - bool isValid = iBar.Init( - mSymbol, - mPeriod, - i - // - ); - - // - if (isValid) - { - // - AddRef( - iBar, - result - // - ); - } - } - - // - int afterSize = ArraySize(result); - - // - mResult = afterSize - beforeSize; - - // - return mResult; -} - -// -// Extract Specific Range of Bars ... -// using Start Bar Time ... -int GetBars( - XOHCL &result[], // Hold Result - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Time Frame - datetime from = NULL, // Start Bar Time - int count = 1, // Number of Bars - bool forceClean = true // Clean Result Array -) -{ - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - from = NormalizeTime(from); - - // - int barIndex = iBarShift( - mSymbol, - mPeriod, - from, - false - // - ); - - // - return GetBars( - result, - mSymbol, - mPeriod, - barIndex, - count, - forceClean - // - ); -} - -// -// String ... - -// -// Search a Content Contains Specific String or not ... -bool Contains( - string mQuery, // Search String - string mContent, // Search Content - bool ignoreCase = true // Ignore Case -) -{ - // - bool result = false; - - // - // Validate Query ... - result = IsValid(mQuery); - if (!result) - { - return result; - } - - // - // Validate Content ... - result = IsValid(mContent); - if (!result) - { - return result; - } - - // - // Normalize Inputs ... - string query = mQuery; - string content = mContent; - if (ignoreCase) - { - // - StringToLower(query); - StringToLower(content); - } - - // - int queryIdx = StringFind( - content, - query); - - // - result = queryIdx >= 0; - - // - return result; -} - -// -bool Contains( - string &mQueries[], // Search Strings - string mContent, // Search Content - bool ignoreCase = true // Ignore Case -) -{ - // - bool result = false; - - // - // Validate Queries ... - int queriesCount = ArraySize(mQueries); - result = queriesCount > 0; - if (!result) - { - return result; - } - - // - // Validate Content ... - result = IsValid(mContent); - if (!result) - { - return result; - } - - // - int containsCount = 0; - for (int i = 0; i < queriesCount; i++) - { - // - bool isContains = Contains( - mQueries[i], - mContent, - ignoreCase); - - // - if (!isContains) - { - // - result = false; - break; - } - - // - containsCount++; - } - - // - result = containsCount == queriesCount; - - // - return result; -} - -// -int FindIndexes( - string mQuery, // Search String - string mContent, // Search Content - int &result[], // Holding Results - bool ignoreCase = false // Ignore Case -) -{ - // - int mResult = 0; - - // - Clean(result); - - // - // Validate Inputs ... - if (!IsValid(mQuery) || - !IsValid(mContent)) - { - return mResult; - } - - // - // Apply Ignore Case if Provided ... - if (ignoreCase) - { - // - bool isConverted = StringToLower(mQuery); - if (!isConverted) - { - return mResult; - } - - // - isConverted = StringToLower(mContent); - if (!isConverted) - { - return mResult; - } - } - - // - // Search First Index ... - int lastPos = 0; - int idx = StringFind( - mContent, - mQuery, - lastPos // - ); - while (idx >= 0) - { - // - // Add Position to Result ... - Add( - idx, - result // - ); - - // - lastPos = idx + StringLen(mQuery); - idx = StringFind( - mContent, - mQuery, - lastPos // - ); - } - - // - mResult = ArraySize(result); - - // - return mResult; -} - -// -// Convert From String ... -template -T FromString(string value) -{ - // - T result = NULL; - - // - if (!IsValid(value)) - { - return result; - } - - // - result = (T)value; - - // - return result; -} - -// -// Converts an item to String ... -template -string ToString(T value) -{ - return (string)value; -} - -// -// Used In Report or Summary Generators ... -string ToString( - string prefix, // Title - bool value, // Value - bool ignoreFalseConditions = true, // Ignore False Conditions - string lineSeparator = "\n", // Line Separator - string prefixSeparator = ":" // Title Separator -) -{ - // - string result = NULL; - - // - result = (value || !ignoreFalseConditions) - ? prefix + - prefixSeparator + " " + - ToString(value) + - lineSeparator - : ""; - - // - return result; -} - -// -template -string ToString( - string prefix, // Title - T value, // Value - string lineSeparator = "\n", // Line Separator - string prefixSeparator = ":" // Title Separator -) -{ - // - string result = NULL; - - // - result = prefix + - prefixSeparator + " " + - ToString(value) + - lineSeparator; - - // - return result; -} - -// -string SetLabel( - string mLabel, // Provided Label ... - string value, // Source Value ... - string separator = "\n", // Line Separator - bool addTopEmptyLine = true // Add Empty Line On top -) -{ - // - string result = value; - - // - if (StringLen(mLabel) <= 0) - { - return result; - } - - // - result = (StringLen(value) > 0) - ? (addTopEmptyLine ? separator : "") + - mLabel + - separator + - "-----------------------------" + - separator + - value - : value; - - // - return result; -} - -// -// Converts a Buffer to String Representation ... -template -string ToString( - const T &buffer[], // Specified Buffer - string separator = ",", // Specified Separator - bool addIndex = false, // Specified Add Items Indexes or Not - string indexLabel = "i:", // Specified Index Label - string indexSeparator = ">" // Specified Index Separator -) -{ - // - string result = ""; - - // - int bufferSize = ArraySize(buffer); - if (bufferSize <= 0) - { - return result; - } - - // - for (int i = 0; i < bufferSize; i++) - { - // - if (addIndex) - { - // - if (StringLen(indexLabel) > 0) - { - result += indexLabel + " "; - } - - // - result += (string)i + " "; - - // - if (StringLen(indexSeparator) > 0) - { - result += indexSeparator + " "; - } - } - - // - string iItemString = (string)buffer[i]; - - // - result += iItemString; - - // - if (i < bufferSize - 1) - { - result += separator; - } - } - - // - return result; -} - -// -// Converts String to boolean ... -bool ToBoolean(string value) -{ - // - bool result = false; - - // - if (StringLen(value) <= 0) - { - return result; - } - - // - StringToLower(value); - result = value == "true"; - - // - return result; -} - -// -// Split an String Representation of an Array ... -int SplitContent( - string &result[], // Hold Result ... - string content, // Source ... - string separator = ",", // Separator ... - bool forceCleanResult = true // Clean Result ... -) -{ - // - int mResult = 0; - - // - if (forceCleanResult) - { - Clean(result); - } - - // - int before = ArraySize(result); - - // - if (separator == NULL || StringLen(separator) == 0) - { - separator = ","; - } - - // - if (StringLen(content) == 0) - { - return mResult; - } - - // - StringSplit( - content, - StringGetCharacter( - separator, - 0), - result); - - // - int after = ArraySize(result); - - // - mResult = after - before; - - // - return mResult; -} - -// -// Extract Data from String ... -string ExtractString( - const string source, // Source String used for Extracting - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - string result = ""; - - // - // Validate String ... - if ( - StringLen(source) == 0 || - StringLen(endString) == 0 || - StringLen(startString) == 0) - { - return result; - } - - // - // Find Start String Position ... - int sPos = StringFind( - source, - startString); - if (sPos < 0) - { - return result; - } - - // - // Find End String Position after Start String ... - int searchEndFromPos = sPos + StringLen(startString); - int ePos = StringFind( - source, - endString, - searchEndFromPos); - if (ePos < 0) - { - return result; - } - - // - // Extract Data from Source ... - int dLength = ePos - searchEndFromPos; - result = StringSubstr( - source, - searchEndFromPos, - dLength); - - // - return result; -} - -// -// Extract an Array of Contents ... -int ExtractStrings( - string &result[], // Hold Result - const string source, // Source String used for Extracting - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - int mResult = 0; - - // - Clean(result); - - // - // Validate Args ... - int sourceLength = StringLen(source); - int startLength = StringLen(startString); - int endLength = StringLen(endString); - - // - int minRequiredLength = startLength + endLength; - - // - if ( - endLength <= 0 || - startLength <= 0 || - sourceLength <= 0 || - sourceLength < minRequiredLength) - { - return mResult; - } - - // - // Make a Copy of Source for Manipulating ... - string workStr = source; - - // - // Define a Loop ... - while (StringLen(workStr) > minRequiredLength) - { - // - // Find Item ... - string item = ExtractString( - workStr, - startString, - endString); - - // - // Breakout when couldn't find anymore item ... - int itemLength = StringLen(item); - if (itemLength <= 0) - { - break; - } - - // - // Prepare Item Source String for Replacing in Work String ... - string itemSource = startString + item + endString; - - // - // Add Item to Result Array ... - Add( - item, - result); - - // - // Replace Item Soure in Work String ... - StringReplace( - workStr, - itemSource, - ""); - } - - // - // Calculate Size of Array ... - mResult = ArraySize(result); - - // - return mResult; -} - -// -string ExtractSurrounded( - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - return ExtractString( - surrounded, - mToken + startString, - endString - // - ); -} - -// -int ParseIntSurrounded( - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - int result = NULL; - - // - string strContent = ExtractSurrounded( - surrounded, - mToken, - startString, - endString - // - ); - if (!IsValid(strContent)) - { - return result; - } - - // - result = (int)strContent; - - // - return result; -} -long ParseLongSurrounded( - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - long result = NULL; - - // - string strContent = ExtractSurrounded( - surrounded, - mToken, - startString, - endString - // - ); - if (!IsValid(strContent)) - { - return result; - } - - // - result = (long)strContent; - - // - return result; -} -string ParseStringSurrounded( - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - string result = NULL; - - // - string strContent = ExtractSurrounded( - surrounded, - mToken, - startString, - endString - // - ); - if (!IsValid(strContent)) - { - return result; - } - - // - result = (string)strContent; - - // - return result; -} -double ParseDoubleSurrounded( - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - double result = NULL; - - // - string strContent = ExtractSurrounded( - surrounded, - mToken, - startString, - endString - // - ); - if (!IsValid(strContent)) - { - return result; - } - - // - result = (double)strContent; - - // - return result; -} -datetime ParseTimeSurrounded( - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - const string startString = "(", // Expression Start String must be Unique - const string endString = ")" // Where to End Extraction, usually a Sign -) -{ - // - datetime result = NULL; - - // - string strContent = ExtractSurrounded( - surrounded, - mToken, - startString, - endString - // - ); - if (!IsValid(strContent)) - { - return result; - } - - // - result = (datetime)strContent; - - // - return result; -} - -// -int ParseIntArraySurrounded( - int &result[], // Holds Result - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - string separator = ",", // Separator ... - const string startString = "(", // Expression Start String must be Unique - const string endString = ")", // Where to End Extraction, usually a Sign - bool forceClean = true // Clean Result ... -) -{ - // - int count = 0; - - // - if (forceClean) - { - Clean(result); - } - - // - int before = ArraySize(result); - - // - string contentStr = ParseStringSurrounded(surrounded, mToken); - if (!IsValid(contentStr)) - { - return count; - } - - // - string tmps[]; - int tmpsCount = SplitContent( - tmps, - contentStr - // - ); - if (tmpsCount <= 0) - { - return count; - } - - // - for (int i = 0; i < tmpsCount; i++) - { - // - string iTMP = tmps[i]; - if (!IsValid(iTMP)) - { - continue; - } - - // - int iValue = (int)iTMP; - - // - Add( - iValue, - result - // - ); - } - - // - int after = ArraySize(result); - - // - count = after - before; - - // - return count; -} -int ParseLongArraySurrounded( - long &result[], // Holds Result - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - string separator = ",", // Separator ... - const string startString = "(", // Expression Start String must be Unique - const string endString = ")", // Where to End Extraction, usually a Sign - bool forceClean = true // Clean Result ... -) -{ - // - int count = 0; - - // - if (forceClean) - { - Clean(result); - } - - // - int before = ArraySize(result); - - // - string contentStr = ParseStringSurrounded(surrounded, mToken); - if (!IsValid(contentStr)) - { - return count; - } - - // - string tmps[]; - int tmpsCount = SplitContent( - tmps, - contentStr - // - ); - if (tmpsCount <= 0) - { - return count; - } - - // - for (int i = 0; i < tmpsCount; i++) - { - // - string iTMP = tmps[i]; - if (!IsValid(iTMP)) - { - continue; - } - - // - long iValue = (long)iTMP; - - // - Add( - iValue, - result - // - ); - } - - // - int after = ArraySize(result); - - // - count = after - before; - - // - return count; -} -int ParseDoubleArraySurrounded( - double &result[], // Holds Result - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - string separator = ",", // Separator ... - const string startString = "(", // Expression Start String must be Unique - const string endString = ")", // Where to End Extraction, usually a Sign - bool forceClean = true // Clean Result ... -) -{ - // - int count = 0; - - // - if (forceClean) - { - Clean(result); - } - - // - int before = ArraySize(result); - - // - string contentStr = ParseStringSurrounded(surrounded, mToken); - if (!IsValid(contentStr)) - { - return count; - } - - // - string tmps[]; - int tmpsCount = SplitContent( - tmps, - contentStr - // - ); - if (tmpsCount <= 0) - { - return count; - } - - // - for (int i = 0; i < tmpsCount; i++) - { - // - string iTMP = tmps[i]; - if (!IsValid(iTMP)) - { - continue; - } - - // - double iValue = (double)iTMP; - - // - Add( - iValue, - result - // - ); - } - - // - int after = ArraySize(result); - - // - count = after - before; - - // - return count; -} -int ParseTimeArraySurrounded( - datetime &result[], // Holds Result - const string surrounded, // Surrounded Content - const string mToken, // Specified Token - string separator = ",", // Separator ... - const string startString = "(", // Expression Start String must be Unique - const string endString = ")", // Where to End Extraction, usually a Sign - bool forceClean = true // Clean Result ... -) -{ - // - int count = 0; - - // - if (forceClean) - { - Clean(result); - } - - // - int before = ArraySize(result); - - // - string contentStr = ParseStringSurrounded(surrounded, mToken); - if (!IsValid(contentStr)) - { - return count; - } - - // - string tmps[]; - int tmpsCount = SplitContent( - tmps, - contentStr - // - ); - if (tmpsCount <= 0) - { - return count; - } - - // - for (int i = 0; i < tmpsCount; i++) - { - // - string iTMP = tmps[i]; - if (!IsValid(iTMP)) - { - continue; - } - - // - datetime iValue = (datetime)iTMP; - - // - Add( - iValue, - result - // - ); - } - - // - int after = ArraySize(result); - - // - count = after - before; - - // - return count; -} - -// -// Surround an String by Specific Token ... -template -string Surround( - string mToken, // an String which used to Tokenize - T &value, // a Value for Tokenize it - string startString = "(", // Token Start Content - string endString = ")" // Token End Content -) -{ - // - string result = NULL; - - // - string strValue = ToString(value); - if (!IsValid(strValue)) - { - return result; - } - - // - result = - // - (IsValid(mToken) - ? mToken - : "") + - // - startString + - strValue + - endString - // - ; - - // - return result; -} - -// -template -string SurroundArray( - string mToken, - T &value[], - string startString = "(", // Token Start Content - string endString = ")" // Token End Content -) -{ - // - string result = NULL; - - // - string valueStr = ToString(value); - if (!IsValid(valueStr)) - { - return result; - } - - // - result = Surround( - mToken, - valueStr, - startString, - endString - // - ); - - // - return result; -} - -// -// Periods / Cycles ... - -// -// Converts an String to TimeFrame ... -ENUM_TIMEFRAMES ToPeriod(string value) -{ - // - if (StringLen(value) == 0) - { - return _Period; - } - - // - StringTrimLeft(value); - StringTrimRight(value); - - // - ENUM_TIMEFRAMES result = _Period; - - // - if (value == "M1") - { - result = PERIOD_M1; - } - else if (value == "M2") - { - result = PERIOD_M2; - } - else if (value == "M3") - { - result = PERIOD_M3; - } - else if (value == "M4") - { - result = PERIOD_M4; - } - else if (value == "M5") - { - result = PERIOD_M5; - } - else if (value == "M6") - { - result = PERIOD_M6; - } - else if (value == "M10") - { - result = PERIOD_M10; - } - else if (value == "M12") - { - result = PERIOD_M12; - } - else if (value == "M15") - { - result = PERIOD_M15; - } - else if (value == "M20") - { - result = PERIOD_M20; - } - else if (value == "M30") - { - result = PERIOD_M30; - } - else if (value == "H1") - { - result = PERIOD_H1; - } - else if (value == "H2") - { - result = PERIOD_H2; - } - else if (value == "H3") - { - result = PERIOD_H3; - } - else if (value == "H4") - { - result = PERIOD_H4; - } - else if (value == "H6") - { - result = PERIOD_H6; - } - else if (value == "H8") - { - result = PERIOD_H8; - } - else if (value == "H12") - { - result = PERIOD_H12; - } - else if (value == "D1") - { - result = PERIOD_D1; - } - else if (value == "W1") - { - result = PERIOD_W1; - } - else if (value == "MN1") - { - result = PERIOD_MN1; - } - - // - return result; -} - -// -// Converts Period to String ... -string ToString(ENUM_TIMEFRAMES mPeriod) -{ - // - string result = ""; - - // - string mPStr = EnumToString(mPeriod); - - string mPStrParts[]; - int partsCount = StringSplit( - mPStr, - StringGetCharacter("_", 0), - mPStrParts); - if (partsCount <= 0) - { - return result; - } - - // - result = mPStrParts[1]; - - // - return result; -} - -// -// Retrieve All Available Period as an Array ...s -int GetAllAvailablePeriods( - ENUM_TIMEFRAMES &result[] // Holds Result ... -) -{ - // - Clean(result); - - // - Add( - PERIOD_M1, - result - // - ); - - // - Add( - PERIOD_M2, - result - // - ); - - // - Add( - PERIOD_M3, - result - // - ); - - // - Add( - PERIOD_M4, - result - // - ); - - // - Add( - PERIOD_M5, - result - // - ); - - // - Add( - PERIOD_M6, - result - // - ); - - // - Add( - PERIOD_M10, - result - // - ); - - // - Add( - PERIOD_M12, - result - // - ); - - // - Add( - PERIOD_M15, - result - // - ); - - // - Add( - PERIOD_M20, - result - // - ); - - // - Add( - PERIOD_M30, - result - // - ); - - // - Add( - PERIOD_H1, - result - // - ); - - // - Add( - PERIOD_H2, - result - // - ); - - // - Add( - PERIOD_H3, - result - // - ); - - // - Add( - PERIOD_H4, - result - // - ); - - // - Add( - PERIOD_H6, - result - // - ); - - // - Add( - PERIOD_H8, - result - // - ); - - // - Add( - PERIOD_H12, - result - // - ); - - // - Add( - PERIOD_D1, - result - // - ); - - // - Add( - PERIOD_W1, - result - // - ); - - // - Add( - PERIOD_MN1, - result - // - ); - - // - int mResult = ArraySize(result); - - // - return mResult; -} - -// -// Get Specific Time Frame Start Candle Time ... -datetime GetPeriodStartTime( - string mSymbol = NULL, // Specified Symbol ... - ENUM_TIMEFRAMES mPeriod = NULL, // Specified Period ... - datetime mTime = NULL // Specified Bar Time of Host Period ... -) -{ - // - // Normalize Arg ... - mTime = NormalizeTime(mTime); - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - int barIndex = iBarShift( - mSymbol, - mPeriod, - mTime, - false - // - ); - - // - datetime result = GetBarTime( - mSymbol, - mPeriod, - barIndex - // - ); - - // - return result; -} - -// -// Converts an String to it's related Market Cycle ... -ENUM_X_MARKET_CYCLES ToCycle(string value) -{ - // - ENUM_X_MARKET_CYCLES result = X_MARKET_CYCLE_UNKNOWN; - - // - ENUM_X_MARKET_CYCLES cycles[]; - int count = GetAllMarketCycles(cycles); - for (int i = 0; i < count; i++) - { - // - ENUM_X_MARKET_CYCLES iCycle = cycles[i]; - string iStr = ToString(iCycle); - - // - if (value == iStr) - { - // - result = iCycle; - break; - } - } - - // - return result; -} - -// -// Converts a Cycle to it's String Representation ... -string ToString(ENUM_X_MARKET_CYCLES cycle) -{ - // - string result = ""; - - // - string mPStr = EnumToString(cycle); - - string mPStrParts[]; - int partsCount = StringSplit( - mPStr, - StringGetCharacter("_", 0), - mPStrParts); - if (partsCount <= 0) - { - return result; - } - - // - result = mPStrParts[3]; - - // - return result; -} - -// -// Retrieve all Available Cycles ... -int GetAllMarketCycles(ENUM_X_MARKET_CYCLES &result[]) -{ - // - int mResult = 0; - - // - Clean(result); - - // - ENUM_X_MARKET_CYCLES tmp[] = { - X_MARKET_CYCLE_UNKNOWN, - X_MARKET_CYCLE_SHORT, - X_MARKET_CYCLE_MEDIUM, - X_MARKET_CYCLE_LONG, - X_MARKET_CYCLE_HIND}; - - // - Copy( - tmp, - result // - ); - - // - Clean(tmp); - - // - mResult = ArraySize(result); - - // - return mResult; -} - -// -// Retrieve Nearest Period base on Given Period ... -ENUM_TIMEFRAMES GetNearestPeriod(ENUM_TIMEFRAMES mPeriod) -{ - // - ENUM_TIMEFRAMES result = _Period; - - // - mPeriod = NormalizePeriod(mPeriod); - - // - switch (mPeriod) - { - // - case PERIOD_M1: - case PERIOD_M2: - case PERIOD_M3: - result = PERIOD_M5; - break; - - // - case PERIOD_M4: - case PERIOD_M5: - case PERIOD_M6: - result = PERIOD_M10; - break; - - // - case PERIOD_M10: - case PERIOD_M12: - case PERIOD_M15: - result = PERIOD_M20; - break; - - // - case PERIOD_M20: - case PERIOD_M30: - result = PERIOD_H1; - break; - - // - case PERIOD_H1: - case PERIOD_H2: - result = PERIOD_H3; - break; - - // - case PERIOD_H3: - result = PERIOD_H4; - break; - - // - case PERIOD_H4: - result = PERIOD_H6; - break; - - // - case PERIOD_H6: - result = PERIOD_H8; - break; - - // - case PERIOD_H8: - result = PERIOD_H12; - break; - - // - default: - result = mPeriod; - break; - } - - // - return result; -} - -// -// Retrieve Mediest Period base on Given Period ... -ENUM_TIMEFRAMES GetMediestPeriod(ENUM_TIMEFRAMES mPeriod) -{ - // - ENUM_TIMEFRAMES result = _Period; - - // - mPeriod = NormalizePeriod(mPeriod); - - // - switch (mPeriod) - { - // - case PERIOD_M1: - case PERIOD_M2: - case PERIOD_M3: - result = PERIOD_M10; - break; - - // - case PERIOD_M4: - case PERIOD_M5: - case PERIOD_M6: - result = PERIOD_M15; - break; - - // - case PERIOD_M10: - case PERIOD_M12: - case PERIOD_M15: - result = PERIOD_M30; - break; - - // - case PERIOD_M20: - case PERIOD_M30: - result = PERIOD_H2; - break; - - // - case PERIOD_H1: - case PERIOD_H2: - result = PERIOD_H4; - break; - - // - case PERIOD_H3: - result = PERIOD_H6; - break; - - // - case PERIOD_H4: - result = PERIOD_H8; - break; - - // - case PERIOD_H6: - result = PERIOD_H12; - break; - - // - case PERIOD_H8: - result = PERIOD_D1; - break; - - // - default: - result = mPeriod; - break; - } - - // - return result; -} - -// -// Retrieve Longest Period base on Given Period ... -ENUM_TIMEFRAMES GetLongestPeriod(ENUM_TIMEFRAMES mPeriod) -{ - // - ENUM_TIMEFRAMES result = _Period; - - // - mPeriod = NormalizePeriod(mPeriod); - - // - switch (mPeriod) - { - // - case PERIOD_M1: - case PERIOD_M2: - case PERIOD_M3: - result = PERIOD_M30; - break; - - // - case PERIOD_M4: - case PERIOD_M5: - case PERIOD_M6: - result = PERIOD_H1; - break; - - // - case PERIOD_M10: - case PERIOD_M12: - case PERIOD_M15: - result = PERIOD_H2; - break; - - // - case PERIOD_M20: - case PERIOD_M30: - result = PERIOD_H4; - break; - - // - case PERIOD_H1: - case PERIOD_H2: - result = PERIOD_H6; - break; - - // - case PERIOD_H3: - result = PERIOD_H8; - break; - - // - case PERIOD_H4: - result = PERIOD_H12; - break; - - // - case PERIOD_H6: - result = PERIOD_D1; - break; - - // - case PERIOD_H8: - result = PERIOD_W1; - break; - - // - default: - result = mPeriod; - break; - } - - // - return result; -} - -// -// Retrieve Hindmost Period base on Given Period ... -ENUM_TIMEFRAMES GetHindMostPeriod(ENUM_TIMEFRAMES mPeriod) -{ - // - ENUM_TIMEFRAMES result = _Period; - - // - mPeriod = NormalizePeriod(mPeriod); - - // - switch (mPeriod) - { - // - case PERIOD_M1: - case PERIOD_M2: - case PERIOD_M3: - result = PERIOD_H1; - break; - - // - case PERIOD_M4: - case PERIOD_M5: - case PERIOD_M6: - result = PERIOD_H2; - break; - - // - case PERIOD_M10: - case PERIOD_M12: - case PERIOD_M15: - result = PERIOD_H4; - break; - - // - case PERIOD_M20: - case PERIOD_M30: - result = PERIOD_H6; - break; - - // - case PERIOD_H1: - case PERIOD_H2: - result = PERIOD_H8; - break; - - // - case PERIOD_H3: - result = PERIOD_H12; - break; - - // - case PERIOD_H4: - result = PERIOD_D1; - break; - - // - case PERIOD_H6: - result = PERIOD_W1; - break; - - // - case PERIOD_H8: - result = PERIOD_MN1; - break; - - // - default: - result = mPeriod; - break; - } - - // - return result; -} - -// -// Retrieve Specified Cycles Period related to Host Period ... -ENUM_TIMEFRAMES GetCyclePeriod( - ENUM_X_MARKET_CYCLES mCycle = NULL, // Specified Cycle - ENUM_TIMEFRAMES mPeriod = NULL // Host Period -) -{ - // - ENUM_TIMEFRAMES result = NULL; - - // - mPeriod = NormalizePeriod(mPeriod); - mCycle = NormalizeCycle(mCycle); - - // - switch (mCycle) - { - // - // Short ... - case X_MARKET_CYCLE_SHORT: - result = GetNearestPeriod(mPeriod); - break; - - // - // Medium ... - case X_MARKET_CYCLE_MEDIUM: - result = GetMediestPeriod(mPeriod); - break; - - // - // Long ... - case X_MARKET_CYCLE_LONG: - result = GetLongestPeriod(mPeriod); - break; - - // - // Hind ... - case X_MARKET_CYCLE_HIND: - result = GetHindMostPeriod(mPeriod); - break; - } - - // - return result; -} - -// -// Calculate a Cycle Length based on Host Period ... -int GetCycleLengthOn( - ENUM_TIMEFRAMES _hostPeriod, - ENUM_X_MARKET_CYCLES _cycle, - ENUM_X_PERIOD_METHOD _method, - ENUM_TIMEFRAMES _period // -) -{ - // - int result = 0; - - // - // Validate ... - bool isValid = - // - IsValid(_hostPeriod) && - IsValid(_method, _Period) - // - ; - if (!isValid) - { - return result; - } - - // - // Calculate Period ... - isValid = - _method != X_PERIOD_NOTHING && - _cycle != X_MARKET_CYCLE_UNKNOWN; - if (!isValid) - { - return result; - } - - // - if (_method == X_PERIOD_AUTO) - { - // - _period = GetCyclePeriod( - _cycle, - _hostPeriod // - ); - } - isValid = IsValid(_period); - if (!isValid) - { - return result; - } - - // - int _hostPeriodSeconds = PeriodSeconds(_hostPeriod); - int _periodSeconds = PeriodSeconds(_period); - - // - isValid = _periodSeconds >= _hostPeriodSeconds; - if (!isValid) - { - return result; - } - - // - result = _periodSeconds / _hostPeriodSeconds; - - // - return result; -} - -// -// Direction ... - -// -bool HasDirection(ENUM_X_DIRECTION value) -{ - // - bool result = false; - - // - result = value != X_DIRECTION_NONE && - value != X_DIRECTION_ALL; - - // - return result; -} - -// -bool IsBullish(ENUM_X_DIRECTION value) -{ - // - bool result = false; - - // - result = value == X_DIRECTION_BULLISH; - - // - return result; -} -bool IsSpecifiedBullish(ENUM_X_DIRECTION value) -{ - // - bool result = false; - - // - result = value == X_DIRECTION_BULLISH; - - // - return result; -} - -// -bool IsBearish(ENUM_X_DIRECTION value) -{ - // - bool result = false; - - // - result = value == X_DIRECTION_BEARISH; - - // - return result; -} -bool IsSpecifiedBearish(ENUM_X_DIRECTION value) -{ - // - bool result = false; - - // - result = value == X_DIRECTION_BEARISH; - - // - return result; -} - -// -ENUM_X_DIRECTION Opposit(ENUM_X_DIRECTION value) -{ - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - if (!HasDirection(value)) - { - return result; - } - - // - result = - IsBullish(value) - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH; - - // - return result; -} - -// -// Moving Average ... - -enum ENUM_X_MA_METHOD -{ - X_MA_MODE_NONE, // None - X_MA_MODE_SMA, // SMA - X_MA_MODE_EMA, // EMA - X_MA_MODE_LWMA, // LWMA - X_MA_MODE_SMMA, // SMMA -}; - -/** - * Calculate Sspecified Buffer's Moving Averages ... - * - * @param rates_total: Integer, number of items ... - * @param prev_calculated: Integer, Previous Calculate Items ... - * @param begin: Integer, Bar Index ... - * @param period: Integer, Moving Average Length ... - * @param source: Double Array, Specified Array for Calculating Moving Averages ... - * @param buffer: Double Array, Specified Array to Apply Calculated Moving Average on it ... - * @param method: ENUM_MA_METHOD member Specified Moving Average Calculation Method ... - * - * @return ( int ) - */ -int iMAOnBuffer( - const int _rates_total, - const int _prev_calculated, - const int _begin, - const int _period, - const double &_source[], - double &_buffer[], - ENUM_X_MA_METHOD _method = X_MA_MODE_SMA // -) -{ - // - int result = 0; - - // - if ( - _period < 0 || - _rates_total <= 0 || - _prev_calculated < 0 || - _method == X_MA_MODE_NONE || - _prev_calculated > _rates_total) - { - return result; - } - - // - switch (_method) - { - // - case X_MA_MODE_SMA: - result = SimpleMAOnBuffer( - _rates_total, - _prev_calculated, - _begin, - _period, - _source, - _buffer // - ); - break; - - // - case X_MA_MODE_EMA: - result = ExponentialMAOnBuffer( - _rates_total, - _prev_calculated, - _begin, - _period, - _source, - _buffer // - ); - break; - - // - case X_MA_MODE_LWMA: - result = LinearWeightedMAOnBuffer( - _rates_total, - _prev_calculated, - _begin, - _period, - _source, - _buffer // - ); - break; - - // - case X_MA_MODE_SMMA: - result = SmoothedMAOnBuffer( - _rates_total, - _prev_calculated, - _begin, - _period, - _source, - _buffer // - ); - break; - } - - // - return result; -} - -// \ No newline at end of file diff --git a/X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.class.mq5 index 30fab3f0..d5bf90e3 100644 --- a/X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.class.mq5 @@ -2161,8 +2161,9 @@ class XCX121SMCXSupDemOBSSignalDetector : public XCBase } // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 2; + double iAtr = 5 * points; + // decisionXConditions.atrBuffer[1]; + // iAtr *= 2; // double slsMin = GetMin(sls);