From aec54aa45a4ddbfaed7c251d3306412588606000 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 7 Nov 2024 05:23:22 +0330 Subject: [PATCH] last ... --- Documents/BKP/1.mq5 | 317 +++ Documents/BKP/2.mq5 | 127 ++ Documents/BKP/3.mq5 | 433 ++++ .../x-saherelm.x-time.indicator.mq5 | 237 +++ Documents/BKP/Indicators/x-saherelm.xcc.mq5 | 437 ++++ .../BKP/Indicators/x-saherelm.xchche.mq5 | 1190 +++++++++++ .../BKP/Indicators/x-saherelm.xchdon.mq5 | 1603 +++++++++++++++ Documents/BKP/Indicators/x-saherelm.xchhk.mq5 | 1070 ++++++++++ .../BKP/Indicators/x-saherelm.xchich.mq5 | 1826 +++++++++++++++++ Documents/BKP/Indicators/x-saherelm.xchm.mq5 | 1089 ++++++++++ .../BKP/Indicators/x-saherelm.xchstr.mq5 | 1246 +++++++++++ .../BKP/Indicators/x-saherelm.xchswings.mq5 | 993 +++++++++ Documents/BKP/Indicators/x-saherelm.xchtd.mq5 | 900 ++++++++ .../BKP/Indicators/x-saherelm.xchvlm.mq5 | 814 ++++++++ .../BKP/Indicators/x-saherelm.xchvwap.mq5 | 830 ++++++++ Documents/BKP/Indicators/x-saherelm.xct.mq5 | 270 +++ Documents/BKP/Indicators/x-saherelm.xpv.mq5 | 1289 ++++++++++++ .../x-121.smc.test.strategy.class copy 3.mq5 | Bin 0 -> 75924 bytes Experts/x-saherelm.x-121.smc.ea.mq5 | 2 +- Libraries/x-saherelm.x-poi.lib.mq5 | 44 + .../Classes/x-121.smc.base.strategy.class.mq5 | 330 +-- X121SMCEA/Experts/x-121.smc.expert.class.mq5 | 2 - .../x-121.smc.test.strategy.class.mq5 | Bin 64096 -> 140192 bytes 23 files changed, 14777 insertions(+), 272 deletions(-) create mode 100644 Documents/BKP/1.mq5 create mode 100644 Documents/BKP/2.mq5 create mode 100644 Documents/BKP/3.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.x-time.indicator.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xcc.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchche.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchdon.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchhk.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchich.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchm.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchstr.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchswings.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchtd.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchvlm.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xchvwap.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xct.mq5 create mode 100644 Documents/BKP/Indicators/x-saherelm.xpv.mq5 create mode 100644 Documents/BKP/x-121.smc.test.strategy.class copy 3.mq5 diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 new file mode 100644 index 00000000..d757ae4c --- /dev/null +++ b/Documents/BKP/1.mq5 @@ -0,0 +1,317 @@ + // + // Select a Supply Zone which Price is Inside it ... + XZone aSupplyZone; + XZone aSupplyZoneTrigger; + bool hasSupplyZoneArroundCBar = false; + bool hasTriggerSupplyZoneArroundCBar = false; + int aSupplyZonesCount = ArraySize(_15MState.supplyZones); + int aSupplyZonesTriggerCount = ArraySize(_5MState.supplyZones); + if (!hasSupplyZoneArroundCBar || + !hasTriggerSupplyZoneArroundCBar) + { + for (int i = 0; i < aSupplyZonesCount; i++) + { + // + XZone iZone = _15MState.supplyZones[i]; + + // + bool canSetZone = (!hasSupplyZoneArroundCBar && + iZone.lower < cBar.low && + iZone.upper > cBar.high) || + (hasSupplyZoneArroundCBar && + aSupplyZone.lower < cBar.low && + aSupplyZone.upper > cBar.high && + iZone.lower < cBar.low && + iZone.upper > cBar.high && + iZone.GetRange() < aSupplyZone.GetRange()); + if (canSetZone && + !hasTriggerSupplyZoneArroundCBar && + IsValidSize(aSupplyZonesTriggerCount)) + { + // + for (int j = 0; j < aSupplyZonesTriggerCount; j++) + { + // + XZone jZone = _5MState.supplyZones[j]; + + // + bool canSetTriggerZone = (!hasTriggerSupplyZoneArroundCBar && + jZone.lower < cBar.low && + jZone.upper > cBar.high) || + (hasTriggerSupplyZoneArroundCBar && + aSupplyZoneTrigger.lower < cBar.low && + aSupplyZoneTrigger.upper > cBar.high && + jZone.lower < cBar.low && + jZone.upper > cBar.high && + jZone.GetRange() < aSupplyZoneTrigger.GetRange()); + if (canSetTriggerZone) + { + // + iZone.to = cTime; + jZone.to = cTime; + aSupplyZone = iZone; + aSupplyZoneTrigger = jZone; + hasSupplyZoneArroundCBar = true; + hasTriggerSupplyZoneArroundCBar = true; + + // + break; + } + } + } + } + } + + // + // XZone supplyZone; + // int supplyZonesCount = ArraySize(_5MState.supplyZones); + // bool hasSupplyZoneOverCBar = IsValidSize(supplyZonesCount); + // if (hasSupplyZoneOverCBar) + // { + // // + // hasSupplyZoneOverCBar = false; + // for (int i = 0; i < supplyZonesCount; i++) + // { + // // + // XZone iZone = _5MState.supplyZones[i]; + + // // + // if (!hasSupplyZoneOverCBar && + // iZone.lower > cBar.high) + // { + // // + // iZone.to = cTime; + // supplyZone = iZone; + // hasSupplyZoneOverCBar = true; + + // // // + // // break; + // } + // } + // } + + // + XZone demandZone; + int demandZonesCount = ArraySize(_5MState.demandZones); + bool hasDemandZoneUnderCBar = IsValidSize(demandZonesCount); + if (hasDemandZoneUnderCBar) + { + // + hasDemandZoneUnderCBar = false; + for (int i = 0; i < demandZonesCount; i++) + { + // + XZone iZone = _5MState.demandZones[i]; + + // + if (!hasDemandZoneUnderCBar && + iZone.upper < cBar.low) + { + // + iZone.to = cTime; + demandZone = iZone; + hasDemandZoneUnderCBar = true; + + // + break; + } + } + } + + // + XOHCL swingHigh; + int swingHighsCount = ArraySize(_5MState.swingHighs); + bool hasSwingHighOverCBar = IsValidSize(swingHighsCount); + if (hasSwingHighOverCBar) + { + // + hasSwingHighOverCBar = false; + for (int i = 0; i < swingHighsCount; i++) + { + // + XOHCL iBar = _5MState.swingHighs[i]; + + // + if (!hasSwingHighOverCBar && + iBar.high > cBar.high) + { + // + swingHigh = iBar; + hasSwingHighOverCBar = true; + + // + break; + } + } + } + + // + XOHCL swingLow; + int swingLowsCount = ArraySize(_5MState.swingLows); + bool hasSwingLowUnderCBar = IsValidSize(swingLowsCount); + if (hasSwingLowUnderCBar) + { + // + hasSwingLowUnderCBar = false; + for (int i = 0; i < swingLowsCount; i++) + { + // + XOHCL iBar = _5MState.swingLows[i]; + + // + if (!hasSwingLowUnderCBar && + iBar.low < cBar.low) + { + // + swingLow = iBar; + hasSwingLowUnderCBar = true; + + // + break; + } + } + } + + // + XOHCL bullishRejectionBar; + XOHCL bearishRejectionBar; + bool hasBullishRejectionBarUnderCBar = false; + bool hasBearishRejectionBarOverCBar = false; + int rejectionBarsCount = ArraySize(_5MState.rejectionBars); + if (IsValidSize(rejectionBarsCount)) + { + // + for (int i = 0; i < rejectionBarsCount; i++) + { + // + XOHCL iBar = _5MState.rejectionBars[i]; + + // + bool isBullish = iBar.GetLowShadow() > iBar.GetHighShadow(); + bool isBearish = iBar.GetHighShadow() > iBar.GetLowShadow(); + + // + if (isBullish && + !hasBullishRejectionBarUnderCBar && + iBar.high < cBar.low) + { + // + bullishRejectionBar = iBar; + hasBullishRejectionBarUnderCBar = true; + } + + // + if (isBearish && + !hasBearishRejectionBarOverCBar && + iBar.low > cBar.high) + { + // + bearishRejectionBar = iBar; + hasBearishRejectionBarOverCBar = true; + } + } + } + + + + + + + + + + + + + + + + + + + + + // + // XZone bullishOB; + // XZone bearishOB; + // XPOIState state = _15MState; + // int obsCount = ArraySize(state.bullishOrderBlocks); + // // for (int i = 0; i < obsCount; i++) + // { + // // + // XZone iZone = state.bullishOrderBlocks[i]; + // bool canRefine = CanRefineZone( + // iZone, + // bullishOB, + // cBar // + // ); + + // // + // if (canRefine && + // isVWapBullish) + // { + // // + // iZone.to = cTime; + // XCBullishOrderBlockObject *iObj; + // bool isCreated = mPOIDrawer.CreateBullishOrderBlock( + // iZone, + // iObj // + // ); + // if (isCreated) + // { + // mDrawnObjects.Add(iObj); + // } + // } + // } + // obsCount = ArraySize(state.bearishOrderBlocks); + // for (int i = 0; i < obsCount; i++) + // { + // // + // XZone iZone = state.bearishOrderBlocks[i]; + // bool canRefine = CanRefineZone( + // iZone, + // bearishOB, + // cBar // + // ); + + // // + // if (canRefine && + // isVWapBearish) + // { + // // + // iZone.to = cTime; + // XCBearishOrderBlockObject *iObj; + // bool isCreated = mPOIDrawer.CreateBearishOrderBlock( + // iZone, + // iObj // + // ); + // if (isCreated) + // { + // mDrawnObjects.Add(iObj); + // } + // } + // } + + // int m15Count = ArraySize(_15MState.resistanceZones); + + // + // Detect Resistance .... + // if (!mConditions.resistance.IsValid()) + // { + // // + // // XZone h4Resistance; + // // XZone m15Resistance; + // // XZone m5Resistance; + + // // // + // // int h4Count = ArraySize(_4HState.resistanceZones); + // // int m15Count = ArraySize(_15MState.resistanceZones); + // // int m5Count = ArraySize(_5MState.resistanceZones); + + // // // + // // for (int i = 0; i < h4Count; i++) + // // { + // // // + // // XOHCL iBar = _4HState.resistanceZones[i]; + // // } + // } diff --git a/Documents/BKP/2.mq5 b/Documents/BKP/2.mq5 new file mode 100644 index 00000000..cd72555c --- /dev/null +++ b/Documents/BKP/2.mq5 @@ -0,0 +1,127 @@ + // + // Draw supply if Exists ... + // if (hasSupplyZoneOverCBar) + // { + // // + // XCSupplyZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateSupplyZone( + // supplyZone, + // iObj // + // ); + // if (isCreated) + // { + // mDrawnObjects.Add(iObj); + // } + // } + + // + if (hasSupplyZoneArroundCBar) + { + // + XCSupplyZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupplyZone( + aSupplyZone, + iObj // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + // + if (hasTriggerSupplyZoneArroundCBar) + { + // + XCSupplyZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupplyZone( + aSupplyZoneTrigger, + iObj // + ); + + // + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + // + // Draw Demand if Exists ... + if (hasDemandZoneUnderCBar) + { + // + XCDemandZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateDemandZone( + demandZone, + iObj // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + // + // Draw Swing High ... + if (hasSwingHighOverCBar) + { + // + XCSwingHighObject *iObj; + bool isCreated = mPOIDrawer.CreateSwingHigh( + swingHigh, + iObj // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + // + // Draw Swing Low ... + if (hasSwingLowUnderCBar) + { + // + XCSwingLowObject *iObj; + bool isCreated = mPOIDrawer.CreateSwingLow( + swingLow, + iObj // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + // + // Draw Bullish Rejection Bar ... + if (hasBullishRejectionBarUnderCBar) + { + // + XCBullishRejectionBarObject *iObj; + bool isCreated = mPOIDrawer.CreateBullishRejectionBar( + bullishRejectionBar, + iObj // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + // + // Draw Bearish Rejection Bar ... + if (hasBearishRejectionBarOverCBar) + { + // + XCBearishRejectionBarObject *iObj; + bool isCreated = mPOIDrawer.CreateBearishRejectionBar( + bearishRejectionBar, + iObj // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } diff --git a/Documents/BKP/3.mq5 b/Documents/BKP/3.mq5 new file mode 100644 index 00000000..80067ccf --- /dev/null +++ b/Documents/BKP/3.mq5 @@ -0,0 +1,433 @@ + + /** + * Draw Conditions ... + * + * @param conditions: X121SMCStrategyConditions instance ... + */ + void DrawConditions(X121SMCStrategyConditions &conditions) + { + // + XC121SMCConditionsObject *iObj; + iObj = new XC121SMCConditionsObject(mPOIDrawer); + bool isCreated = iObj.CreateByConditions( + ChartIdentification(), + conditions.GetTag(true), + SubWindowIdentification(), + conditions // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + /** + * Draw Market Structure ... + * + * @param structure: X121SMCMarketStructure instance ... + */ + void DrawMarketStructure(X121SMCMarketStructure &structure) + { + // + XC121SMCMarketStructureObject *iObj; + iObj = new XC121SMCMarketStructureObject(mPOIDrawer); + bool isCreated = iObj.CreateByStructure( + ChartIdentification(), + structure.GetTag(), + SubWindowIdentification(), + structure // + ); + if (isCreated) + { + mDrawnObjects.Add(iObj); + } + } + + + + + /** + * Detect Valid Market Conditions ... + * + * @param conditions: X121SMCStrategyConditions instance ... + * + * @return ( virtual bool ) + */ + virtual bool DetecConditions(X121SMCStrategyConditions &conditions) + { + // + bool result = false; + + // + conditions.Clean(); + + // + return result; + } + + /** + * Detect Market Structure based on Conditions ... + * + * @param structure: X121SMCMarketStructure instance ... + * @param conditions: X121SMCStrategyConditions instance ... + */ + virtual void DetectMarketStructure( + X121SMCMarketStructure &structure, + X121SMCStrategyConditions &conditions // + ) + { + } + + /** + * Remove Specific Conditions if Exists ... + * + * @param conditions: X121SMCStrategyConditions instance ... + */ + virtual void RemoveConditionsIfExists(X121SMCStrategyConditions &conditions) + { + } + + /** + * Search Conditions for Find SL Candidates ... + * + * @param candidates: Double Array ... + * @param entry: Double ... + * @param structure: X121SMCStrategyConditions instance ... + * @param type: ENUM_X_POSITION_TYPES member ... + * + * @return ( virtual int ) + */ + virtual int DetectSLCandidates( + double &candidates[], + double entry, + X121SMCStrategyConditions &conditions, + ENUM_X_POSITION_TYPES type // + ) + { + // + int result = 0; + + // + if (type == X_POSITION_TYPE_NONE || + type == X_POSITION_TYPE_ALL) + { + return result; + } + + // + bool useSwings = true; + bool useMomentumBars = true; + bool useRejectionBars = true; + + // + Clean(candidates); + + // + XOHCL candidateBars[]; + if (type == X_POSITION_TYPE_LONG) + { + // + // Search Bullish Momentum, Rejection Bars and Swing Lows ... + + // + // Swing Lows ... + if (useSwings) + { + // + Copy( + conditions.swingLows, + candidateBars, + false // + ); + } + + // + // Bullish Momentum Bars ... + if (useMomentumBars) + { + // + Copy( + conditions.bullishMomentumBars, + candidateBars, + false // + ); + } + + // + // Bullish Rejection Bars ... + if (useRejectionBars) + { + // + Copy( + conditions.bullishRejectionBars, + candidateBars, + false // + ); + } + + // + int count = ArraySize(candidateBars); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XOHCL iBar = candidateBars[i]; + + // + if (iBar.low < entry) + { + // + Add( + iBar.low, + candidates // + ); + } + } + } + } + else if (type == X_POSITION_TYPE_SHORT) + { + // + // Search Bearish Momentum, Rejection Bars and Swing Highs ... + + // + // Swing Highs ... + if (useSwings) + { + // + Copy( + conditions.swingHighs, + candidateBars, + false // + ); + } + + // + // Bearish Momentum Bars ... + if (useMomentumBars) + { + // + Copy( + conditions.bearishMomentumBars, + candidateBars, + false // + ); + } + + // + // Bearish Rejection Bars ... + if (useRejectionBars) + { + // + Copy( + conditions.bearishRejectionBars, + candidateBars, + false // + ); + } + + // + int count = ArraySize(candidateBars); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XOHCL iBar = candidateBars[i]; + + // + if (iBar.high > entry) + { + // + Add( + iBar.low, + candidates // + ); + } + } + } + } + + // + Clean(candidateBars); + result = ArraySize(candidates); + + // + return result; + } + + + + + + + + + + + + + + + + + + + + + // + XZone h4Supply; + XZone m15Supply; + XZone m5Supply; + + // + int h4Count = ArraySize(_15MState.supplyZones); + int m15Count = ArraySize(_5MState.supplyZones); + int m5Count = ArraySize(_1MState.supplyZones); + + // + bool has4HSupplyZone = false; + bool has15mSupplyZone = false; + bool has5mSupplyZone = false; + + // + // for (int i = 0; i < h4Count; i++) + // { + // // + // XZone iZone = _15MState.supplyZones[i]; + + // // + // bool canRefineI = CanRefineZone( + // iZone, + // h4Supply, + // cBar // + // ); + // if (canRefineI) + // { + // // + // h4Supply = iZone; + + // // + // for (int j = 0; j < m15Count; j++) + // { + // // + // XZone jZone = _5MState.supplyZones[j]; + + // // + // bool canRefineJ = CanRefineZone( + // iZone, + // m15Supply, + // cBar // + // ); + // if (canRefineJ) + // { + // // + // m15Supply = jZone; + + // // + // for (int k = 0; k < m5Count; k++) + // { + // // + // XZone kZone = _1MState.supplyZones[k]; + + // // + // bool canRefineK = CanRefineZone( + // kZone, + // m5Supply, + // cBar // + // ); + // if (canRefineK) + // { + // // + // m5Supply = kZone; + // } + // } + // } + // } + // } + // } + + for (int i = 0; i < m15Count; i++) + { + // + XZone iZone = _5MState.supplyZones[i]; + + // + bool canRefineI = CanRefineZone( + iZone, + m15Supply, + cBar // + ); + if (canRefineI) + { + // + m15Supply = iZone; + + // + for (int j = 0; j < m5Count; j++) + { + // + XZone jZone = _1MState.supplyZones[j]; + + // + bool canRefineJ = CanRefineZone( + iZone, + m5Supply, + cBar // + ); + if (canRefineJ) + { + m5Supply = jZone; + } + } + } + } + + // + // has4HSupplyZone = h4Supply.IsValid(); + has15mSupplyZone = m15Supply.IsValid(); + has5mSupplyZone = m5Supply.IsValid(); + + // + bool hasSupply = + // has4HSupplyZone && + has15mSupplyZone && + has5mSupplyZone; + + // + if (hasSupply) + { + // + m15Supply.to = cTime; + m5Supply.to = cTime; + + // + mConditions.supplyZone = m5Supply; + + // + XCSupplyZoneObject *i5Obj; + bool isCreated = mPOIDrawer.CreateSupplyZone( + m5Supply, + i5Obj // + ); + + // + XCSupplyZoneObject *i15Obj; + isCreated = mPOIDrawer.CreateSupplyZone( + m15Supply, + i15Obj // + ); + + // // + // XCSupplyZoneObject *i4Obj; + // isCreated = mPOIDrawer.CreateSupplyZone( + // h4Supply, + // i4Obj // + // ); + + // + Print("Supply Detected ..."); + } diff --git a/Documents/BKP/Indicators/x-saherelm.x-time.indicator.mq5 b/Documents/BKP/Indicators/x-saherelm.x-time.indicator.mq5 new file mode 100644 index 00000000..d2edf38a --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.x-time.indicator.mq5 @@ -0,0 +1,237 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// --------------------------------------------- +// Name: XCTime +// Description: Timing Indicator ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCTime Indicator" +#property strict + +// +// START Constants ... +// + +// +#define ShortName "XCTime" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// END Constants ... +// + +// +// START Inputs ... +// + +// +input color clr = clrYellow; // Text Color +input ENUM_BASE_CORNER corner = CORNER_LEFT_LOWER; // Text Position + +// +input group "Presentation"; +input bool showTime = true; // Show Time + +// +// END Inputs ... +// + +// +// START Buffers ... +// + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + +// +// END Buffers ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// + +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// START Event Handlers ... +// + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (showTime) + { + CreateIndicatorObject(); + } + else + { + ObjectDelete(0, ShortName); + } + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + ulong chID = FindChartID( + _Symbol, + _Period + // + ); + + // + // Delete Object ... + ObjectDelete(chID, ShortName); + + // + Comment(""); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(time, true); + + // + if (!showTime) + { + return rates_total; + } + + // + ulong chID = FindChartID( + _Symbol, + _Period + // + ); + + //s + int offset = TimeGMTOffset(); + string timeString = + "Local: " + string(TimeLocal()) + + ", Server: " + string(TimeTradeServer()); + timeString = timeString; + + // + string objText = timeString; + + // + ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr); + ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText); + ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10); + ObjectSetString(chID, ShortName, OBJPROP_FONT, "Arial"); + + // + return rates_total; +} + +// +// END Event Handlers ... +// + +// +// START Functions ... +// + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +void CreateIndicatorObject() +{ + // + if (!showTime) + { + return; + } + + // + ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0); + ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner); + ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10); + ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2); + + // + ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER; + switch (corner) + { + case CORNER_LEFT_UPPER: + Anchor = ANCHOR_LEFT_UPPER; + break; + case CORNER_RIGHT_UPPER: + Anchor = ANCHOR_RIGHT_UPPER; + break; + case CORNER_LEFT_LOWER: + Anchor = ANCHOR_LEFT_LOWER; + break; + case CORNER_RIGHT_LOWER: + Anchor = ANCHOR_RIGHT_LOWER; + break; + } + + // + ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor); +} + +// +// END Functions ... +// diff --git a/Documents/BKP/Indicators/x-saherelm.xcc.mq5 b/Documents/BKP/Indicators/x-saherelm.xcc.mq5 new file mode 100644 index 00000000..ebc45174 --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xcc.mq5 @@ -0,0 +1,437 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Candle Styles +// --------------------------------------------------- +// Name: XCC +// Description: Candle Styles ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCC Indicator" +#property strict + +// +// START Constants ... +// + +// +// Indicator Short Name ... +#define ShortName "XCC" + +// +// Holds an SnapShot of Charts Configuration ... +struct XChartStyle +{ + // + // chart's ID ... + long chartId; + // + // chart's mode ... + ENUM_CHART_MODE mode; + // + // show bid line ... + bool showBidLine; + // + // show ask line ... + bool showAskLine; + // + // show grids on chart ... + bool showGrid; + // + // show volumes ... + bool showVolumes; + // + // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ... + bool showTradeLevels; + // + // chart autoscroll ... + bool autoScroll; + // + // chart quick navigation state ... + bool quickNavigation; + // + // chart's foreground color ... + color foreGroundColor; + // + // chart's background color ... + color backGroundColor; + // + // Up Color ... + color upColor; + // + // Down Color ... + color downColor; + // + // Bullish color ... + color bullishColor; + // + // Bearish color ... + color bearishColor; + // + // grid color ... + color gridColor; + // + // bid line color ... + color bidLineColor; + // + // ask line color ... + color askLineColor; + // + // line mode and doji candlestick color ... + color lineColor; + // + // Color of stop order levels (Stop Loss and Take Profit) ... + color stopColor; + // + // volumes color ... + color volumesColor; +}; + +// +// END Constants ... +// + +// +// START Inputs ... +// + +// +input group "Chart Style"; +input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode +input color upColor = clrLime; // Up Color +input color downColor = clrRed; // Down Color +input color lineColor = clrLime; // Line mode and Doji candlestick Color +input color bearishColor = clrRed; // Bullish Color +input color bullishColor = clrLime; // Bearish Color +input color volumesColor = clrGreen; // Volumes Color + +// +input group "Presentation"; +input bool showCandles = true; // Show Candles + +// +// END Inputs ... +// + +// +// START Includes and Imports ... +// + +// +// Includes Draw Library ... +#include "../Libraries/x-saherelm.draw.lib.mq5" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// END Includes and Imports ... +// + +// +// START Buffers ... +// + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + +// +// END Buffers ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// + +// +int maxLength; + +// +XChartStyle chartStyle; +XChartStyle clearStyle; + +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// START Event Handlers ... +// + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + drawPrefix = ShortName; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Apply Chart Style ... + ApplyCustomChartStyle(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // this counts Available Bars ... + int limit; + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// END Event Handlers ... +// + +// +// START Functions ... +// + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = true; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index // Selected Bar Index +) +{ +} + +// +// Apply Custom Chart Style ... +void ApplyCustomChartStyle() +{ + // + // Read Current Chart Config and Store it ... + ReadChartStyle(); + + // + // After Reading Current Chart Style ... + // we have to Save Configs and Change Styles ... + clearStyle = chartStyle; + + // + clearStyle.upColor = CLR_NONE; + clearStyle.downColor = CLR_NONE; + clearStyle.lineColor = CLR_NONE; + clearStyle.bullishColor = CLR_NONE; + clearStyle.bearishColor = CLR_NONE; + + // + // Decide to Show or not Candles based on User Input ... + if (showCandles) + { + SetChartStyle(chartStyle); + } + else + { + SetChartStyle(clearStyle); + } +} + +// +// Read Previous Chart Style ... +void ReadChartStyle() +{ + // + // Retrieve Current Chart ID ... + long chartId = ChartID(); + chartStyle.chartId = chartId; + + // + // Retrieve Chart Mode ... + chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE); + + // + chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE); + chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE); + chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID); + chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES); + chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS); + chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL); + chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION); + + // + chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND); + chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND); + chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP); + chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN); + chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL); + chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR); + chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID); + chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID); + chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK); + chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL); + chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE); + chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME); + + // + chartStyle.mode = mode; + chartStyle.upColor = upColor; + chartStyle.downColor = downColor; + chartStyle.lineColor = lineColor; + chartStyle.bearishColor = bearishColor; + chartStyle.bullishColor = bullishColor; + chartStyle.volumesColor = volumesColor; +} + +// +// Set Chart Style ... +void SetChartStyle( + XChartStyle &mChartStyle // Chart Style to Apply +) +{ + // + ApplyChartStyle( + mChartStyle.chartId, + mChartStyle.mode, + mChartStyle.showBidLine, + mChartStyle.showAskLine, + mChartStyle.showGrid, + mChartStyle.showVolumes, + mChartStyle.showTradeLevels, + mChartStyle.autoScroll, + mChartStyle.quickNavigation, + mChartStyle.foreGroundColor, + mChartStyle.backGroundColor, + mChartStyle.upColor, + mChartStyle.downColor, + mChartStyle.bullishColor, + mChartStyle.bearishColor, + mChartStyle.gridColor, + mChartStyle.bidLineColor, + mChartStyle.askLineColor, + mChartStyle.lineColor, + mChartStyle.stopColor, + mChartStyle.volumesColor); +} + +// +// END Functions ... +// diff --git a/Documents/BKP/Indicators/x-saherelm.xchche.mq5 b/Documents/BKP/Indicators/x-saherelm.xchche.mq5 new file mode 100644 index 00000000..9b6b3892 --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchche.mq5 @@ -0,0 +1,1190 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHCHE +// Description: XCHCHE Cycles ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHCHE Indicator" +#property strict + +// +#define ShortName "XCHCHE" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 35; // Length +input int loopback = 26; // Loopback +input double multiplier1 = 3.0; // 1st Multiplier +input double multiplier2 = 3.5; // 2nd Multiplier + +// +input group "Calculation"; +input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to +input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +input bool showLE1 = true; // Show Long Exit 1 +input bool showLE2 = true; // Show Long Exit 2 +input bool showSE1 = true; // Show Short Exit 1 +input bool showSE2 = true; // Show Short Exit 2 + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 20 +#property indicator_plots 20 + +// +// Current ... + +// +// Long Exit 1 ... +#define cLE1BufferIndex 0 +double cLE1Buffer[]; + +// +#property indicator_label1 "XCHCHE C LE 1" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT + +// +// Short Exit 1 ... +#define cSE1BufferIndex 1 +double cSE1Buffer[]; + +// +#property indicator_label2 "XCHCHE C SE 1" +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT +#property indicator_color2 clrRed + +// +// Long Exit 2 ... +#define cLE2BufferIndex 2 +double cLE2Buffer[]; + +// +#property indicator_label3 "XCHCHE C LE 2" +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT +#property indicator_color3 clrAqua + +// +// Short Exit 2 ... +#define cSE2BufferIndex 3 +double cSE2Buffer[]; + +// +#property indicator_label4 "XCHCHE C SE 2" +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_DOT +#property indicator_color4 clrMagenta + +// +// Short ... + +// +// Long Exit 1 ... +#define sLE1BufferIndex 4 +double sLE1Buffer[]; + +// +#property indicator_label5 "XCHCHE S LE 1" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLime +#property indicator_style5 STYLE_DOT + +// +// Short Exit 1 ... +#define sSE1BufferIndex 5 +double sSE1Buffer[]; + +// +#property indicator_label6 "XCHCHE S SE 1" +#property indicator_type6 DRAW_LINE +#property indicator_style6 STYLE_DOT +#property indicator_color6 clrRed + +// +// Long Exit 2 ... +#define sLE2BufferIndex 6 +double sLE2Buffer[]; + +// +#property indicator_label7 "XCHCHE S LE 2" +#property indicator_type7 DRAW_LINE +#property indicator_style7 STYLE_DOT +#property indicator_color7 clrAqua + +// +// Short Exit 2 ... +#define sSE2BufferIndex 7 +double sSE2Buffer[]; + +// +#property indicator_label8 "XCHCHE S SE 2" +#property indicator_type8 DRAW_LINE +#property indicator_style8 STYLE_DOT +#property indicator_color8 clrMagenta + +// +// Medium ... + +// +// Long Exit 1 ... +#define mLE1BufferIndex 8 +double mLE1Buffer[]; + +// +#property indicator_label9 "XCHCHE M LE 1" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLime +#property indicator_style9 STYLE_DOT + +// +// Short Exit 1 ... +#define mSE1BufferIndex 9 +double mSE1Buffer[]; + +// +#property indicator_label10 "XCHCHE M SE 1" +#property indicator_type10 DRAW_LINE +#property indicator_style10 STYLE_DOT +#property indicator_color10 clrRed + +// +// Long Exit 2 ... +#define mLE2BufferIndex 10 +double mLE2Buffer[]; + +// +#property indicator_label11 "XCHCHE M LE 2" +#property indicator_type11 DRAW_LINE +#property indicator_style11 STYLE_DOT +#property indicator_color11 clrAqua + +// +// Short Exit 2 ... +#define mSE2BufferIndex 11 +double mSE2Buffer[]; + +// +#property indicator_label12 "XCHCHE M SE 2" +#property indicator_type12 DRAW_LINE +#property indicator_style12 STYLE_DOT +#property indicator_color12 clrMagenta + +// +// Long ... + +// +// Long Exit 1 ... +#define lLE1BufferIndex 12 +double lLE1Buffer[]; + +// +#property indicator_label13 "XCHCHE L LE 1" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrLime +#property indicator_style13 STYLE_DOT + +// +// Short Exit 1 ... +#define lSE1BufferIndex 13 +double lSE1Buffer[]; + +// +#property indicator_label14 "XCHCHE L SE 1" +#property indicator_type14 DRAW_LINE +#property indicator_style14 STYLE_DOT +#property indicator_color14 clrRed + +// +// Long Exit 2 ... +#define lLE2BufferIndex 14 +double lLE2Buffer[]; + +// +#property indicator_label15 "XCHCHE L LE 2" +#property indicator_type15 DRAW_LINE +#property indicator_style15 STYLE_DOT +#property indicator_color15 clrAqua + +// +// Short Exit 2 ... +#define lSE2BufferIndex 15 +double lSE2Buffer[]; + +// +#property indicator_label16 "XCHCHE L SE 2" +#property indicator_type16 DRAW_LINE +#property indicator_style16 STYLE_DOT +#property indicator_color16 clrMagenta + +// +// Hind ... + +// +// Long Exit 1 ... +#define hLE1BufferIndex 16 +double hLE1Buffer[]; + +// +#property indicator_label17 "XCHCHE H LE 1" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrLime +#property indicator_style17 STYLE_DOT + +// +// Short Exit 1 ... +#define hSE1BufferIndex 17 +double hSE1Buffer[]; + +// +#property indicator_label18 "XCHCHE H SE 1" +#property indicator_type18 DRAW_LINE +#property indicator_style18 STYLE_DOT +#property indicator_color18 clrRed + +// +// Long Exit 2 ... +#define hLE2BufferIndex 18 +double hLE2Buffer[]; + +// +#property indicator_label19 "XCHCHE H LE 2" +#property indicator_type19 DRAW_LINE +#property indicator_style19 STYLE_DOT +#property indicator_color19 clrAqua + +// +// Short Exit 2 ... +#define hSE2BufferIndex 19 +double hSE2Buffer[]; + +// +#property indicator_label20 "XCHCHE H SE 2" +#property indicator_type20 DRAW_LINE +#property indicator_style20 STYLE_DOT +#property indicator_color20 clrMagenta + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +#define hi1Idx 0 +#define lo1Idx 1 +#define hi2Idx 2 +#define lo2Idx 3 +#define trend1Idx 4 +#define trend2Idx 5 + +// +// Current ... +int mCSMLength = length; +double cWork[][6]; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +double sWork[][6]; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +double mWork[][6]; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +double lWork[][6]; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +double hWork[][6]; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + if (Bars(_Symbol, _Period) < rates_total) + { + return (prev_calculated); + } + + // + if (ArrayRange(cWork, 0) != rates_total) + { + // + ArrayResize(cWork, rates_total); + ArrayResize(sWork, rates_total); + ArrayResize(mWork, rates_total); + ArrayResize(lWork, rates_total); + ArrayResize(hWork, rates_total); + } + + // + // this counts Available Bars ... + int limit; + + // + limit = prev_calculated - 1; + if (limit < 0) + { + limit = 0; + } + + // + // Main Loop ... + for (int i = limit; i < rates_total && !IsStopped(); i++) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + low, + close // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + loopback >= 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // Long Exit 1 ... + bool canShowCLE1 = showCurrent && showLE1; + ENUM_DRAW_TYPE cLE1DrawType = canShowCLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLE1BufferIndex, cLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cLE1BufferIndex, PLOT_SHOW_DATA, canShowCLE1); + PlotIndexSetInteger(cLE1BufferIndex, PLOT_DRAW_TYPE, cLE1DrawType); + + // + // Long Exit 2 ... + bool canShowCLE2 = showCurrent && showLE2; + ENUM_DRAW_TYPE cLE2DrawType = canShowCLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLE2BufferIndex, cLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cLE2BufferIndex, PLOT_SHOW_DATA, canShowCLE2); + PlotIndexSetInteger(cLE2BufferIndex, PLOT_DRAW_TYPE, cLE2DrawType); + + // + // Short Exit 1 ... + bool canShowCSE1 = showCurrent && showSE1; + ENUM_DRAW_TYPE cSE1DrawType = canShowCSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cSE1BufferIndex, cSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cSE1BufferIndex, PLOT_SHOW_DATA, canShowCSE1); + PlotIndexSetInteger(cSE1BufferIndex, PLOT_DRAW_TYPE, cSE1DrawType); + + // + // Short Exit 2 ... + bool canShowCSE2 = showCurrent && showSE2; + ENUM_DRAW_TYPE cSE2DrawType = canShowCSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cSE2BufferIndex, cSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(cSE2BufferIndex, PLOT_SHOW_DATA, canShowCSE2); + PlotIndexSetInteger(cSE2BufferIndex, PLOT_DRAW_TYPE, cSE2DrawType); + + // + // Short ... + + // + // Long Exit 1 ... + bool canShowSLE1 = showShort && showLE1; + ENUM_DRAW_TYPE sLE1DrawType = canShowSLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLE1BufferIndex, sLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sLE1BufferIndex, PLOT_SHOW_DATA, canShowSLE1); + PlotIndexSetInteger(sLE1BufferIndex, PLOT_DRAW_TYPE, sLE1DrawType); + + // + // Long Exit 2 ... + bool canShowSLE2 = showShort && showLE2; + ENUM_DRAW_TYPE sLE2DrawType = canShowSLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLE2BufferIndex, sLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sLE2BufferIndex, PLOT_SHOW_DATA, canShowSLE2); + PlotIndexSetInteger(sLE2BufferIndex, PLOT_DRAW_TYPE, sLE2DrawType); + + // + bool canShowSSE1 = showShort && showSE1; + // Short Exit 1 ... + ENUM_DRAW_TYPE sSE1DrawType = canShowSSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sSE1BufferIndex, sSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sSE1BufferIndex, PLOT_SHOW_DATA, canShowSSE1); + PlotIndexSetInteger(sSE1BufferIndex, PLOT_DRAW_TYPE, sSE1DrawType); + + // + // Short Exit 2 ... + bool canShowSSE2 = showShort && showSE2; + ENUM_DRAW_TYPE sSE2DrawType = canShowSSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sSE2BufferIndex, sSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(sSE2BufferIndex, PLOT_SHOW_DATA, canShowSSE2); + PlotIndexSetInteger(sSE2BufferIndex, PLOT_DRAW_TYPE, sSE2DrawType); + + // + // Medium ... + + // + // Long Exit 1 ... + bool canShowMLE1 = showMedium && showLE1; + ENUM_DRAW_TYPE mLE1DrawType = canShowMLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLE1BufferIndex, mLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mLE1BufferIndex, PLOT_SHOW_DATA, canShowMLE1); + PlotIndexSetInteger(mLE1BufferIndex, PLOT_DRAW_TYPE, mLE1DrawType); + + // + // Long Exit 2 ... + bool canShowMLE2 = showMedium && showLE2; + ENUM_DRAW_TYPE mLE2DrawType = canShowMLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLE2BufferIndex, mLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mLE2BufferIndex, PLOT_SHOW_DATA, canShowMLE2); + PlotIndexSetInteger(mLE2BufferIndex, PLOT_DRAW_TYPE, mLE2DrawType); + + // + // Short Exit 1 ... + bool canShowMSE1 = showMedium && showSE1; + ENUM_DRAW_TYPE mSE1DrawType = canShowMSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mSE1BufferIndex, mSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mSE1BufferIndex, PLOT_SHOW_DATA, canShowMSE1); + PlotIndexSetInteger(mSE1BufferIndex, PLOT_DRAW_TYPE, mSE1DrawType); + + // + // Short Exit 2 ... + bool canShowMSE2 = showMedium && showSE2; + ENUM_DRAW_TYPE mSE2DrawType = canShowMSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mSE2BufferIndex, mSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(mSE2BufferIndex, PLOT_SHOW_DATA, canShowMSE2); + PlotIndexSetInteger(mSE2BufferIndex, PLOT_DRAW_TYPE, mSE2DrawType); + + // + // Long ... + + // + // Long Exit 1 ... + bool canShowLLE1 = showLong && showLE1; + ENUM_DRAW_TYPE lLE1DrawType = canShowLLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLE1BufferIndex, lLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lLE1BufferIndex, PLOT_SHOW_DATA, canShowLLE1); + PlotIndexSetInteger(lLE1BufferIndex, PLOT_DRAW_TYPE, lLE1DrawType); + + // + // Long Exit 2 ... + bool canShowLLE2 = showLong && showLE2; + ENUM_DRAW_TYPE lLE2DrawType = canShowLLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLE2BufferIndex, lLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lLE2BufferIndex, PLOT_SHOW_DATA, canShowLLE2); + PlotIndexSetInteger(lLE2BufferIndex, PLOT_DRAW_TYPE, lLE2DrawType); + + // + // Short Exit 1 ... + bool canShowLSE1 = showLong && showSE1; + ENUM_DRAW_TYPE lSE1DrawType = canShowLSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lSE1BufferIndex, lSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lSE1BufferIndex, PLOT_SHOW_DATA, canShowLSE1); + PlotIndexSetInteger(lSE1BufferIndex, PLOT_DRAW_TYPE, lSE1DrawType); + + // + // Short Exit 2 ... + bool canShowLSE2 = showLong && showSE2; + ENUM_DRAW_TYPE lSE2DrawType = canShowLSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lSE2BufferIndex, lSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(lSE2BufferIndex, PLOT_SHOW_DATA, canShowLSE2); + PlotIndexSetInteger(lSE2BufferIndex, PLOT_DRAW_TYPE, lSE2DrawType); + + // + // Hind ... + + // + // Long Exit 1 ... + bool canShowHLE1 = showHind && showLE1; + ENUM_DRAW_TYPE hLE1DrawType = canShowHLE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLE1BufferIndex, hLE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hLE1BufferIndex, PLOT_SHOW_DATA, canShowHLE1); + PlotIndexSetInteger(hLE1BufferIndex, PLOT_DRAW_TYPE, hLE1DrawType); + + // + // Long Exit 2 ... + bool canShowHLE2 = showHind && showLE2; + ENUM_DRAW_TYPE hLE2DrawType = canShowHLE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLE2BufferIndex, hLE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hLE2BufferIndex, PLOT_SHOW_DATA, canShowHLE2); + PlotIndexSetInteger(hLE2BufferIndex, PLOT_DRAW_TYPE, hLE2DrawType); + + // + // Short Exit 1 ... + bool canShowHSE1 = showHind && showSE1; + ENUM_DRAW_TYPE hSE1DrawType = canShowHSE1 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hSE1BufferIndex, hSE1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hSE1BufferIndex, PLOT_SHOW_DATA, canShowHSE1); + PlotIndexSetInteger(hSE1BufferIndex, PLOT_DRAW_TYPE, hSE1DrawType); + + // + // Short Exit 2 ... + bool canShowHSE2 = showHind && showSE2; + ENUM_DRAW_TYPE hSE2DrawType = canShowHSE2 ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hSE2BufferIndex, hSE2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(hSE2BufferIndex, PLOT_SHOW_DATA, canShowHSE2); + PlotIndexSetInteger(hSE2BufferIndex, PLOT_DRAW_TYPE, hSE2DrawType); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mCSMLength, + cWork, + cLE1Buffer, + cLE2Buffer, + cSE1Buffer, + cSE2Buffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mSSMLength, + sWork, + sLE1Buffer, + sLE2Buffer, + sSE1Buffer, + sSE2Buffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mMSMLength, + mWork, + mLE1Buffer, + mLE2Buffer, + mSE1Buffer, + mSE2Buffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mLSMLength, + lWork, + lLE1Buffer, + lLE2Buffer, + lSE1Buffer, + lSE2Buffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + mHSMLength, + hWork, + hLE1Buffer, + hLE2Buffer, + hSE1Buffer, + hSE2Buffer // + ); +} + +// +void CalculateCycle( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + // + int _length, // Calculation Length + double &work[][], // Working Array + // + double &le1[], + double &le2[], + double &se1[], + double &se2[] // +) +{ + // + // Cleanup Buffers ... + le1[bar_index] = se1[bar_index] = EMPTY_VALUE; + le2[bar_index] = se2[bar_index] = EMPTY_VALUE; + + // + int start = MathMax(bar_index - loopback, 0); + + // + // Calculate ATR Value ... + double atrValue = 0; + for (int k = 1; k <= _length && (bar_index - k - 1) >= 0; k++) + { + // + atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) - + MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]); + } + atrValue /= (double)_length; + + // + // Retrieve Highest High and Lowest Lows ... + double loopbackMax = high[ArrayMaximum(high, start, loopback)]; + double loopbackMin = low[ArrayMinimum(low, start, loopback)]; + + // + // Fill Multi Dimesional Working Array ... + work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue; + work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue; + work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue; + work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue; + work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0; + work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0; + + // + if (bar_index > 0) + { + // + // Calculate Trends ... + if (close[bar_index] > work[bar_index - 1][lo1Idx]) + { + work[bar_index][trend1Idx] = 1; + } + + // + if (close[bar_index] < work[bar_index - 1][hi1Idx]) + { + work[bar_index][trend1Idx] = -1; + } + + // + if (close[bar_index] > work[bar_index - 1][lo2Idx]) + { + work[bar_index][trend2Idx] = 1; + } + + // + if (close[bar_index] < work[bar_index - 1][hi2Idx]) + { + work[bar_index][trend2Idx] = -1; + } + + // + // Calculate Exit Values ... + + // + // Exit 1 ... + + // + // Long ... + if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1) + { + // + if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx]) + { + work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx]; + } + + // + le1[bar_index] = work[bar_index][hi1Idx]; + + // // + // if (le1[bar_index - 1] == EMPTY_VALUE) + // { + // longExit1StartBuffer[bar_index] = le1[bar_index]; + // } + } + + // + // Short ... + if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1) + { + // + if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx]) + { + work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx]; + } + + // + se1[bar_index] = work[bar_index][lo1Idx]; + + // // + // if (se1[bar_index - 1] == EMPTY_VALUE) + // { + // shortExit1StartBuffer[bar_index] = se1[bar_index]; + // } + } + + // + // Exit 2 ... + + // + // Long ... + if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1) + { + if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx]) + { + work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx]; + } + + // + le2[bar_index] = work[bar_index][hi2Idx]; + + // // + // if (le2[bar_index - 1] == EMPTY_VALUE) + // { + // longExit2StartBuffer[bar_index] = le2[bar_index]; + // } + } + + // + // Short ... + if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1) + { + // + if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx]) + { + work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx]; + } + + // + se2[bar_index] = work[bar_index][lo2Idx]; + + // // + // if (se2[bar_index - 1] == EMPTY_VALUE) + // { + // shortExit2StartBuffer[bar_index] = se2[bar_index]; + // } + } + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchdon.mq5 b/Documents/BKP/Indicators/x-saherelm.xchdon.mq5 new file mode 100644 index 00000000..64f53ece --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchdon.mq5 @@ -0,0 +1,1603 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XCHDON +// Description: Donchain on Cycles ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHDON Indicator" +#property strict + +// +#define ShortName "XCHDON" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 52; // Market Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Presentation"; + +// +input bool showUpper = true; // Show Upper Band +input bool showLower = true; // Show Lower Band + +// +input bool showOpen = true; // Show Open +input bool showHigh = true; // Show High +input bool showClose = true; // Show Close +input bool showLow = true; // Show Low + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 40 +#property indicator_plots 40 + +// +// Current ... + +// +// Open ... + +// +#define cOpenUpperBufferIndex 0 +double cOpenUpperBuffer[]; + +// +#property indicator_label1 "XCHDON C O U" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrCornflowerBlue +#property indicator_width1 1 + +// +#define cOpenLowerBufferIndex 1 +double cOpenLowerBuffer[]; + +// +#property indicator_label2 "XCHDON C O L" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrCornflowerBlue +#property indicator_width2 1 + +// +// High ... + +// +#define cHighUpperBufferIndex 2 +double cHighUpperBuffer[]; + +// +#property indicator_label3 "XCHDON C H U" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAquamarine +#property indicator_width3 1 + +// +#define cHighLowerBufferIndex 3 +double cHighLowerBuffer[]; + +// +#property indicator_label4 "XCHDON C H L" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrAquamarine +#property indicator_width4 1 + +// +// Low ... + +// +#define cLowUpperBufferIndex 4 +double cLowUpperBuffer[]; + +// +#property indicator_label5 "XCHDON C L U" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrDarkOrchid +#property indicator_width5 1 + +// +#define cLowLowerBufferIndex 5 +double cLowLowerBuffer[]; + +// +#property indicator_label6 "XCHDON C L L" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrDarkOrchid +#property indicator_width6 1 + +// +// Close ... + +// +#define cCloseUpperBufferIndex 6 +double cCloseUpperBuffer[]; + +// +#property indicator_label7 "XCHDON C C U" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrCoral +#property indicator_width7 1 + +// +#define cCloseLowerBufferIndex 7 +double cCloseLowerBuffer[]; + +// +#property indicator_label8 "XCHDON C C L" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrCoral +#property indicator_width8 1 + +// +// Short ... + +// +// Open ... + +// +#define sOpenUpperBufferIndex 8 +double sOpenUpperBuffer[]; + +// +#property indicator_label9 "XCHDON S O U" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrCornflowerBlue +#property indicator_width9 1 + +// +#define sOpenLowerBufferIndex 9 +double sOpenLowerBuffer[]; + +// +#property indicator_label10 "XCHDON S O L" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrCornflowerBlue +#property indicator_width10 1 + +// +// High ... + +// +#define sHighUpperBufferIndex 10 +double sHighUpperBuffer[]; + +// +#property indicator_label11 "XCHDON S H U" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAquamarine +#property indicator_width11 1 + +// +#define sHighLowerBufferIndex 11 +double sHighLowerBuffer[]; + +// +#property indicator_label12 "XCHDON S H L" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrAquamarine +#property indicator_width12 1 + +// +// Low ... + +// +#define sLowUpperBufferIndex 12 +double sLowUpperBuffer[]; + +// +#property indicator_label13 "XCHDON S L U" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkOrchid +#property indicator_width13 1 + +// +#define sLowLowerBufferIndex 13 +double sLowLowerBuffer[]; + +// +#property indicator_label14 "XCHDON S L L" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrDarkOrchid +#property indicator_width14 1 + +// +// Close ... + +// +#define sCloseUpperBufferIndex 14 +double sCloseUpperBuffer[]; + +// +#property indicator_label15 "XCHDON S C U" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrCoral +#property indicator_width15 1 + +// +#define sCloseLowerBufferIndex 15 +double sCloseLowerBuffer[]; + +// +#property indicator_label16 "XCHDON S C L" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrCoral +#property indicator_width16 1 + +// +// Medium ... + +// +// Open ... + +// +#define mOpenUpperBufferIndex 16 +double mOpenUpperBuffer[]; + +// +#property indicator_label17 "XCHDON M O U" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrCornflowerBlue +#property indicator_width17 1 + +// +#define mOpenLowerBufferIndex 17 +double mOpenLowerBuffer[]; + +// +#property indicator_label18 "XCHDON M O L" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrCornflowerBlue +#property indicator_width18 1 + +// +// High ... + +// +#define mHighUpperBufferIndex 18 +double mHighUpperBuffer[]; + +// +#property indicator_label19 "XCHDON M H U" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrAquamarine +#property indicator_width19 1 + +// +#define mHighLowerBufferIndex 19 +double mHighLowerBuffer[]; + +// +#property indicator_label20 "XCHDON M H L" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrAquamarine +#property indicator_width20 1 + +// +// Low ... + +// +#define mLowUpperBufferIndex 20 +double mLowUpperBuffer[]; + +// +#property indicator_label21 "XCHDON M L U" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrDarkOrchid +#property indicator_width21 1 + +// +#define mLowLowerBufferIndex 21 +double mLowLowerBuffer[]; + +// +#property indicator_label22 "XCHDON M L L" +#property indicator_type22 DRAW_LINE +#property indicator_color22 clrDarkOrchid +#property indicator_width22 1 + +// +// Close ... + +// +#define mCloseUpperBufferIndex 22 +double mCloseUpperBuffer[]; + +// +#property indicator_label23 "XCHDON M C U" +#property indicator_type23 DRAW_LINE +#property indicator_color23 clrCoral +#property indicator_width23 1 + +// +#define mCloseLowerBufferIndex 23 +double mCloseLowerBuffer[]; + +// +#property indicator_label24 "XCHDON M C L" +#property indicator_type24 DRAW_LINE +#property indicator_color24 clrCoral +#property indicator_width24 1 + +// +// Long ... + +// +// Open ... + +// +#define lOpenUpperBufferIndex 24 +double lOpenUpperBuffer[]; + +// +#property indicator_label25 "XCHDON L O U" +#property indicator_type25 DRAW_LINE +#property indicator_color25 clrCornflowerBlue +#property indicator_width25 1 + +// +#define lOpenLowerBufferIndex 25 +double lOpenLowerBuffer[]; + +// +#property indicator_label26 "XCHDON L O L" +#property indicator_type26 DRAW_LINE +#property indicator_color26 clrCornflowerBlue +#property indicator_width26 1 + +// +// High ... + +// +#define lHighUpperBufferIndex 26 +double lHighUpperBuffer[]; + +// +#property indicator_label27 "XCHDON L H U" +#property indicator_type27 DRAW_LINE +#property indicator_color27 clrAquamarine +#property indicator_width27 1 + +// +#define lHighLowerBufferIndex 27 +double lHighLowerBuffer[]; + +// +#property indicator_label28 "XCHDON L H L" +#property indicator_type28 DRAW_LINE +#property indicator_color28 clrAquamarine +#property indicator_width28 1 + +// +// Low ... + +// +#define lLowUpperBufferIndex 28 +double lLowUpperBuffer[]; + +// +#property indicator_label29 "XCHDON L L U" +#property indicator_type29 DRAW_LINE +#property indicator_color29 clrDarkOrchid +#property indicator_width29 1 + +// +#define lLowLowerBufferIndex 29 +double lLowLowerBuffer[]; + +// +#property indicator_label30 "XCHDON L L L" +#property indicator_type30 DRAW_LINE +#property indicator_color30 clrDarkOrchid +#property indicator_width30 1 + +// +// Close ... + +// +#define lCloseUpperBufferIndex 30 +double lCloseUpperBuffer[]; + +// +#property indicator_label31 "XCHDON L C U" +#property indicator_type31 DRAW_LINE +#property indicator_color31 clrCoral +#property indicator_width31 1 + +// +#define lCloseLowerBufferIndex 31 +double lCloseLowerBuffer[]; + +// +#property indicator_label32 "XCHDON L C L" +#property indicator_type32 DRAW_LINE +#property indicator_color32 clrCoral +#property indicator_width32 1 + +// +// Hind ... + +// +// Open ... + +// +#define hOpenUpperBufferIndex 32 +double hOpenUpperBuffer[]; + +// +#property indicator_label33 "XCHDON H O U" +#property indicator_type33 DRAW_LINE +#property indicator_color33 clrCornflowerBlue +#property indicator_width33 1 + +// +#define hOpenLowerBufferIndex 33 +double hOpenLowerBuffer[]; + +// +#property indicator_label34 "XCHDON H O L" +#property indicator_type34 DRAW_LINE +#property indicator_color34 clrCornflowerBlue +#property indicator_width34 1 + +// +// High ... + +// +#define hHighUpperBufferIndex 34 +double hHighUpperBuffer[]; + +// +#property indicator_label35 "XCHDON H H U" +#property indicator_type35 DRAW_LINE +#property indicator_color35 clrAquamarine +#property indicator_width35 1 + +// +#define hHighLowerBufferIndex 35 +double hHighLowerBuffer[]; + +// +#property indicator_label36 "XCHDON H H L" +#property indicator_type36 DRAW_LINE +#property indicator_color36 clrAquamarine +#property indicator_width36 1 + +// +// Low ... + +// +#define hLowUpperBufferIndex 36 +double hLowUpperBuffer[]; + +// +#property indicator_label37 "XCHDON H L U" +#property indicator_type37 DRAW_LINE +#property indicator_color37 clrDarkOrchid +#property indicator_width37 1 + +// +#define hLowLowerBufferIndex 37 +double hLowLowerBuffer[]; + +// +#property indicator_label38 "XCHDON H L L" +#property indicator_type38 DRAW_LINE +#property indicator_color38 clrDarkOrchid +#property indicator_width38 1 + +// +// Close ... + +// +#define hCloseUpperBufferIndex 38 +double hCloseUpperBuffer[]; + +// +#property indicator_label39 "XCHDON H C U" +#property indicator_type39 DRAW_LINE +#property indicator_color39 clrCoral +#property indicator_width39 1 + +// +#define hCloseLowerBufferIndex 39 +double hCloseLowerBuffer[]; + +// +#property indicator_label40 "XCHDON H C L" +#property indicator_type40 DRAW_LINE +#property indicator_color40 clrCoral +#property indicator_width40 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + if (rates_total < maxLength - 1) + { + return prev_calculated; + } + + // + int start = prev_calculated == 0 + ? maxLength + : prev_calculated - 1; + + // + // Main Loop ... + for (int i = start; i < rates_total; i++) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume + // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length > 2 + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // CURRENT ... + + // + // Open ... + + // + // UPPER ... + bool canShowCOpenUpper = showUpper && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenUpperBufferIndex, cOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_DRAW_TYPE, cOpenUpperDrawType); + + // + // LOWER ... + bool canShowCOpenLower = showLower && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenLowerBufferIndex, cOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_DRAW_TYPE, cOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowCCloseUpper = showUpper && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseUpperBufferIndex, cCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_DRAW_TYPE, cCloseUpperDrawType); + + // + // LOWER ... + bool canShowCCloseLower = showLower && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseLowerBufferIndex, cCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_DRAW_TYPE, cCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowCHighUpper = showUpper && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighUpperBufferIndex, cHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_DRAW_TYPE, cHighUpperDrawType); + + // + // LOWER ... + bool canShowCHighLower = showLower && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighLowerBufferIndex, cHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_SHOW_DATA, canShowCHighLower); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_DRAW_TYPE, cHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowCLowUpper = showUpper && showLow && showCurrent; + ENUM_DRAW_TYPE cLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowUpperBufferIndex, cLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_DRAW_TYPE, cLowUpperDrawType); + + // + // LOWER ... + bool canShowCLowLower = showLower && showLow && showCurrent; + ENUM_DRAW_TYPE cLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowLowerBufferIndex, cLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_DRAW_TYPE, cLowLowerDrawType); + + // + // SHORT ... + + // + // Open ... + + // + // UPPER ... + bool canShowSOpenUpper = showUpper && showOpen && showShort; + ENUM_DRAW_TYPE sOpenUpperDrawType = canShowSOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenUpperBufferIndex, sOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowSOpenUpper); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_DRAW_TYPE, sOpenUpperDrawType); + + // + // LOWER ... + bool canShowSOpenLower = showLower && showOpen && showShort; + ENUM_DRAW_TYPE sOpenLowerDrawType = canShowSOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenLowerBufferIndex, sOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowSOpenLower); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_DRAW_TYPE, sOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowSCloseUpper = showUpper && showClose && showShort; + ENUM_DRAW_TYPE sCloseUpperDrawType = canShowSCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseUpperBufferIndex, sCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowSCloseUpper); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_DRAW_TYPE, sCloseUpperDrawType); + + // + // LOWER ... + bool canShowSCloseLower = showLower && showClose && showShort; + ENUM_DRAW_TYPE sCloseLowerDrawType = canShowSCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseLowerBufferIndex, sCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowSCloseLower); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_DRAW_TYPE, sCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowSHighUpper = showUpper && showHigh && showShort; + ENUM_DRAW_TYPE sHighUpperDrawType = canShowSHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighUpperBufferIndex, sHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_SHOW_DATA, canShowSHighUpper); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_DRAW_TYPE, sHighUpperDrawType); + + // + // LOWER ... + bool canShowSHighLower = showLower && showHigh && showShort; + ENUM_DRAW_TYPE sHighLowerDrawType = canShowSHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighLowerBufferIndex, sHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_SHOW_DATA, canShowSHighLower); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_DRAW_TYPE, sHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowSLowUpper = showUpper && showLow && showShort; + ENUM_DRAW_TYPE sLowUpperDrawType = canShowSLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowUpperBufferIndex, sLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_SHOW_DATA, canShowSLowUpper); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_DRAW_TYPE, sLowUpperDrawType); + + // + // LOWER ... + bool canShowSLowLower = showLower && showLow && showShort; + ENUM_DRAW_TYPE sLowLowerDrawType = canShowSLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowLowerBufferIndex, sLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_SHOW_DATA, canShowSLowLower); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_DRAW_TYPE, sLowLowerDrawType); + + // + // MEDIUM ... + + // + // Open ... + + // + // UPPER ... + bool canShowMOpenUpper = showUpper && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenUpperDrawType = canShowMOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenUpperBufferIndex, mOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowMOpenUpper); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_DRAW_TYPE, mOpenUpperDrawType); + + // + // LOWER ... + bool canShowMOpenLower = showLower && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenLowerDrawType = canShowMOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenLowerBufferIndex, mOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowMOpenLower); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_DRAW_TYPE, mOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowMCloseUpper = showUpper && showClose && showMedium; + ENUM_DRAW_TYPE mCloseUpperDrawType = canShowMCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseUpperBufferIndex, mCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowMCloseUpper); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_DRAW_TYPE, mCloseUpperDrawType); + + // + // LOWER ... + bool canShowMCloseLower = showLower && showClose && showMedium; + ENUM_DRAW_TYPE mCloseLowerDrawType = canShowMCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseLowerBufferIndex, mCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowMCloseLower); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_DRAW_TYPE, mCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowMHighUpper = showUpper && showHigh && showMedium; + ENUM_DRAW_TYPE mHighUpperDrawType = canShowMHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighUpperBufferIndex, mHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_SHOW_DATA, canShowMHighUpper); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_DRAW_TYPE, mHighUpperDrawType); + + // + // LOWER ... + bool canShowMHighLower = showLower && showHigh && showMedium; + ENUM_DRAW_TYPE mHighLowerDrawType = canShowMHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighLowerBufferIndex, mHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_SHOW_DATA, canShowMHighLower); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_DRAW_TYPE, mHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowMLowUpper = showUpper && showLow && showMedium; + ENUM_DRAW_TYPE mLowUpperDrawType = canShowMLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowUpperBufferIndex, mLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_SHOW_DATA, canShowMLowUpper); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_DRAW_TYPE, mLowUpperDrawType); + + // + // LOWER ... + bool canShowMLowLower = showLower && showLow && showMedium; + ENUM_DRAW_TYPE mLowLowerDrawType = canShowMLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowLowerBufferIndex, mLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_SHOW_DATA, canShowMLowLower); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_DRAW_TYPE, mLowLowerDrawType); + + // + // LONG ... + + // + // Open ... + + // + // UPPER ... + bool canShowLOpenUpper = showUpper && showOpen && showLong; + ENUM_DRAW_TYPE lOpenUpperDrawType = canShowLOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenUpperBufferIndex, lOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowLOpenUpper); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_DRAW_TYPE, lOpenUpperDrawType); + + // + // LOWER ... + bool canShowLOpenLower = showLower && showOpen && showLong; + ENUM_DRAW_TYPE lOpenLowerDrawType = canShowLOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenLowerBufferIndex, lOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowLOpenLower); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_DRAW_TYPE, lOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowLCloseUpper = showUpper && showClose && showLong; + ENUM_DRAW_TYPE lCloseUpperDrawType = canShowLCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseUpperBufferIndex, lCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowLCloseUpper); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_DRAW_TYPE, lCloseUpperDrawType); + + // + // LOWER ... + bool canShowLCloseLower = showLower && showClose && showLong; + ENUM_DRAW_TYPE lCloseLowerDrawType = canShowLCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseLowerBufferIndex, lCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowLCloseLower); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_DRAW_TYPE, lCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowLHighUpper = showUpper && showHigh && showLong; + ENUM_DRAW_TYPE lHighUpperDrawType = canShowLHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighUpperBufferIndex, lHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_SHOW_DATA, canShowLHighUpper); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_DRAW_TYPE, lHighUpperDrawType); + + // + // LOWER ... + bool canShowLHighLower = showLower && showHigh && showLong; + ENUM_DRAW_TYPE lHighLowerDrawType = canShowLHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighLowerBufferIndex, lHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_SHOW_DATA, canShowLHighLower); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_DRAW_TYPE, lHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowLLowUpper = showUpper && showLow && showLong; + ENUM_DRAW_TYPE lLowUpperDrawType = canShowLLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowUpperBufferIndex, lLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_SHOW_DATA, canShowLLowUpper); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_DRAW_TYPE, lLowUpperDrawType); + + // + // LOWER ... + bool canShowLLowLower = showLower && showLow && showLong; + ENUM_DRAW_TYPE lLowLowerDrawType = canShowLLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowLowerBufferIndex, lLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_SHOW_DATA, canShowLLowLower); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_DRAW_TYPE, lLowLowerDrawType); + + // + // HIND ... + + // + // Open ... + + // + // UPPER ... + bool canShowHOpenUpper = showUpper && showOpen && showHind; + ENUM_DRAW_TYPE hOpenUpperDrawType = canShowHOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenUpperBufferIndex, hOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowHOpenUpper); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_DRAW_TYPE, hOpenUpperDrawType); + + // + // LOWER ... + bool canShowHOpenLower = showLower && showOpen && showHind; + ENUM_DRAW_TYPE hOpenLowerDrawType = canShowHOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenLowerBufferIndex, hOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowHOpenLower); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_DRAW_TYPE, hOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowHCloseUpper = showUpper && showClose && showHind; + ENUM_DRAW_TYPE hCloseUpperDrawType = canShowHCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseUpperBufferIndex, hCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowHCloseUpper); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_DRAW_TYPE, hCloseUpperDrawType); + + // + // LOWER ... + bool canShowHCloseLower = showLower && showClose && showHind; + ENUM_DRAW_TYPE hCloseLowerDrawType = canShowHCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseLowerBufferIndex, hCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowHCloseLower); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_DRAW_TYPE, hCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowHHighUpper = showUpper && showHigh && showHind; + ENUM_DRAW_TYPE hHighUpperDrawType = canShowHHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighUpperBufferIndex, hHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_SHOW_DATA, canShowHHighUpper); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_DRAW_TYPE, hHighUpperDrawType); + + // + // LOWER ... + bool canShowHHighLower = showLower && showHigh && showHind; + ENUM_DRAW_TYPE hHighLowerDrawType = canShowHHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighLowerBufferIndex, hHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_SHOW_DATA, canShowHHighLower); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_DRAW_TYPE, hHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowHLowUpper = showUpper && showLow && showHind; + ENUM_DRAW_TYPE hLowUpperDrawType = canShowHLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowUpperBufferIndex, hLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_SHOW_DATA, canShowHLowUpper); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_DRAW_TYPE, hLowUpperDrawType); + + // + // LOWER ... + bool canShowHLowLower = showLower && showLow && showHind; + ENUM_DRAW_TYPE hLowLowerDrawType = canShowHLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowLowerBufferIndex, hLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_SHOW_DATA, canShowHLowLower); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_DRAW_TYPE, hLowLowerDrawType); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // CURRENT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + // + cOpenUpperBuffer, + cOpenLowerBuffer, + cHighUpperBuffer, + cHighLowerBuffer, + cLowUpperBuffer, + cLowLowerBuffer, + cCloseUpperBuffer, + cCloseLowerBuffer // + ); + + // + // SHORT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + // + sOpenUpperBuffer, + sOpenLowerBuffer, + sHighUpperBuffer, + sHighLowerBuffer, + sLowUpperBuffer, + sLowLowerBuffer, + sCloseUpperBuffer, + sCloseLowerBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + // + mOpenUpperBuffer, + mOpenLowerBuffer, + mHighUpperBuffer, + mHighLowerBuffer, + mLowUpperBuffer, + mLowLowerBuffer, + mCloseUpperBuffer, + mCloseLowerBuffer // + ); + + // + // LONG ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + // + lOpenUpperBuffer, + lOpenLowerBuffer, + lHighUpperBuffer, + lHighLowerBuffer, + lLowUpperBuffer, + lLowLowerBuffer, + lCloseUpperBuffer, + lCloseLowerBuffer // + ); + + // + // HIND ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + // + hOpenUpperBuffer, + hOpenLowerBuffer, + hHighUpperBuffer, + hHighLowerBuffer, + hLowUpperBuffer, + hLowLowerBuffer, + hCloseUpperBuffer, + hCloseLowerBuffer // + ); +} + +// +void CalculateCycle( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, + // + double &_ouBuffer[], + double &_olBuffer[], + double &_huBuffer[], + double &_hlBuffer[], + double &_luBuffer[], + double &_llBuffer[], + double &_cuBuffer[], + double &_clBuffer[] // +) +{ + // + double iUpper = 0; + double iLower = 0; + + // + // OPEN ... + + // + iUpper = open[ArrayMaximum(open, bar_index - _length + 1, _length)]; + iLower = open[ArrayMinimum(open, bar_index - _length + 1, _length)]; + + // + _ouBuffer[bar_index] = iUpper; + _olBuffer[bar_index] = iLower; + + // + // HIGH ... + + // + iUpper = high[ArrayMaximum(high, bar_index - _length + 1, _length)]; + iLower = high[ArrayMinimum(high, bar_index - _length + 1, _length)]; + + // + _huBuffer[bar_index] = iUpper; + _hlBuffer[bar_index] = iLower; + + // + // LOW ... + + // + iUpper = low[ArrayMaximum(low, bar_index - _length + 1, _length)]; + iLower = low[ArrayMinimum(low, bar_index - _length + 1, _length)]; + + // + _luBuffer[bar_index] = iUpper; + _llBuffer[bar_index] = iLower; + + // + // CLOSE ... + + // + iUpper = close[ArrayMaximum(close, bar_index - _length + 1, _length)]; + iLower = close[ArrayMinimum(close, bar_index - _length + 1, _length)]; + + // + _cuBuffer[bar_index] = iUpper; + _clBuffer[bar_index] = iLower; +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchhk.mq5 b/Documents/BKP/Indicators/x-saherelm.xchhk.mq5 new file mode 100644 index 00000000..ff6fae86 --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchhk.mq5 @@ -0,0 +1,1070 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHHK +// Description: Smoothed HikenAshi Cycles ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHHK Indicator" +#property strict + +// +#define ShortName "XCHHK" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; + +// +input int cSmoothingLength = 14; // Smoothing Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +input bool ignoreShadows = false; // Ignore Bar Shadows + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 29 +#property indicator_plots 25 + +// +// Current ... + +// +#define cOpenBufferIndex 0 +double cOpenBuffer[]; + +// +#define cHighBufferIndex 1 +double cHighBuffer[]; + +// +#define cLowBufferIndex 2 +double cLowBuffer[]; + +// +#define cCloseBufferIndex 3 +double cCloseBuffer[]; + +// +#define cColorBufferIndex 4 +double cColorBuffer[]; + +// +#define cBufferIndex 0 +#property indicator_label1 "C Open;C High;C Low;C Close" +#property indicator_type1 DRAW_COLOR_CANDLES +#property indicator_color1 CLR_NONE, clrAqua, clrMagenta + +// +// Short ... + +// +#define sOpenBufferIndex 5 +double sOpenBuffer[]; + +// +#define sHighBufferIndex 6 +double sHighBuffer[]; + +// +#define sLowBufferIndex 7 +double sLowBuffer[]; + +// +#define sCloseBufferIndex 8 +double sCloseBuffer[]; + +// +#define sColorBufferIndex 9 +double sColorBuffer[]; + +// +#define sBufferIndex 1 +#property indicator_label2 "S Open;S High;S Low;S Close" +#property indicator_type2 DRAW_COLOR_CANDLES +#property indicator_color2 CLR_NONE, clrAqua, clrMagenta + +// +// Medium ... + +// +#define mOpenBufferIndex 10 +double mOpenBuffer[]; + +// +#define mHighBufferIndex 11 +double mHighBuffer[]; + +// +#define mLowBufferIndex 12 +double mLowBuffer[]; + +// +#define mCloseBufferIndex 13 +double mCloseBuffer[]; + +// +#define mColorBufferIndex 14 +double mColorBuffer[]; + +// +#define mBufferIndex 2 +#property indicator_label3 "M Open;M High;M Low;M Close" +#property indicator_type3 DRAW_COLOR_CANDLES +#property indicator_color3 CLR_NONE, clrAqua, clrMagenta + +// +// Long ... + +// +#define lOpenBufferIndex 15 +double lOpenBuffer[]; + +// +#define lHighBufferIndex 16 +double lHighBuffer[]; + +// +#define lLowBufferIndex 17 +double lLowBuffer[]; + +// +#define lCloseBufferIndex 18 +double lCloseBuffer[]; + +// +#define lColorBufferIndex 19 +double lColorBuffer[]; + +// +#define lBufferIndex 3 +#property indicator_label4 "L Open;L High;L Low;L Close" +#property indicator_type4 DRAW_COLOR_CANDLES +#property indicator_color4 CLR_NONE, clrAqua, clrMagenta + +// +// Hind ... + +// +#define hOpenBufferIndex 20 +double hOpenBuffer[]; + +// +#define hHighBufferIndex 21 +double hHighBuffer[]; + +// +#define hLowBufferIndex 22 +double hLowBuffer[]; + +// +#define hCloseBufferIndex 23 +double hCloseBuffer[]; + +// +#define hColorBufferIndex 24 +double hColorBuffer[]; + +// +#define hBufferIndex 4 +#property indicator_label5 "H Open;H High;H Low;H Close" +#property indicator_type5 DRAW_COLOR_CANDLES +#property indicator_color5 CLR_NONE, clrAqua, clrMagenta + +// +// Data Buffers ... + +// +#define openBufferIndex 25 +double openBuffer[]; + +// +#define highBufferIndex 26 +double highBuffer[]; + +// +#define lowBufferIndex 27 +double lowBuffer[]; + +// +#define closeBufferIndex 28 +double closeBuffer[]; + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCSMLength = cSmoothingLength; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // this counts Available Bars ... + int limit; + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + CalculateHK(i, prev_calculated, rates_total, open, high, close, low); + } + + // + CalculateCycles(rates_total, prev_calculated); + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + cSmoothingLength > 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Data Buffers ... + + // + // Open ... + ArraySetAsSeries(openBuffer, true); + SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_CALCULATIONS); + + // + // High ... + ArraySetAsSeries(highBuffer, true); + SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_CALCULATIONS); + + // + // Low ... + ArraySetAsSeries(lowBuffer, true); + SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_CALCULATIONS); + + // + // Close ... + ArraySetAsSeries(closeBuffer, true); + SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_CALCULATIONS); + + // + // Current ... + + // + // Color ... + ArraySetAsSeries(cColorBuffer, true); + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(cBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(cBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(cColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(cOpenBuffer, true); + PlotIndexSetInteger(cOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cOpenBufferIndex, cOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(cHighBuffer, true); + PlotIndexSetInteger(cHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cHighBufferIndex, cHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(cCloseBuffer, true); + PlotIndexSetInteger(cCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cCloseBufferIndex, cCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(cLowBuffer, true); + PlotIndexSetInteger(cLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(cLowBufferIndex, cLowBuffer, INDICATOR_DATA); + + // + // Short ... + + // + // Color ... + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(sBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(sBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(sColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(sOpenBuffer, true); + PlotIndexSetInteger(sOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sOpenBufferIndex, sOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(sHighBuffer, true); + PlotIndexSetInteger(sHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sHighBufferIndex, sHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(sCloseBuffer, true); + PlotIndexSetInteger(sCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sCloseBufferIndex, sCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(sLowBuffer, true); + PlotIndexSetInteger(sLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(sLowBufferIndex, sLowBuffer, INDICATOR_DATA); + + // + // Medium ... + + // + // Color ... + ArraySetAsSeries(mColorBuffer, true); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(mBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(mBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(mColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(mOpenBuffer, true); + PlotIndexSetInteger(mOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mOpenBufferIndex, mOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(mHighBuffer, true); + PlotIndexSetInteger(mHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mHighBufferIndex, mHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(mCloseBuffer, true); + PlotIndexSetInteger(mCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mCloseBufferIndex, mCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(mLowBuffer, true); + PlotIndexSetInteger(mLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(mLowBufferIndex, mLowBuffer, INDICATOR_DATA); + + // + // Long ... + + // + // Color ... + ArraySetAsSeries(lColorBuffer, true); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(lBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(lBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(lColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(lOpenBuffer, true); + PlotIndexSetInteger(lOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lOpenBufferIndex, lOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(lHighBuffer, true); + PlotIndexSetInteger(lHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lHighBufferIndex, lHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(lCloseBuffer, true); + PlotIndexSetInteger(lCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lCloseBufferIndex, lCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(lLowBuffer, true); + PlotIndexSetInteger(lLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(lLowBufferIndex, lLowBuffer, INDICATOR_DATA); + + // + // Hind ... + + // + // Color ... + ArraySetAsSeries(hColorBuffer, true); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(hBufferIndex, PLOT_EMPTY_VALUE, 0.0); + + // + PlotIndexSetInteger(hBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(hColorBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(hOpenBuffer, true); + PlotIndexSetInteger(hOpenBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hOpenBufferIndex, hOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(hHighBuffer, true); + PlotIndexSetInteger(hHighBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hHighBufferIndex, hHighBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(hCloseBuffer, true); + PlotIndexSetInteger(hCloseBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hCloseBufferIndex, hCloseBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(hLowBuffer, true); + PlotIndexSetInteger(hLowBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(hLowBufferIndex, hLowBuffer, INDICATOR_DATA); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Hiken Ashi ... +void CalculateHK( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + double mPrevHKOpenValue; + double mPrevHKCloseValue; + + // + if (ArraySize(open) <= bar_index + 1) + { + // + mPrevHKOpenValue = 0; + mPrevHKCloseValue = 0; + } + else + { + // + mPrevHKOpenValue = openBuffer[bar_index + 1]; + mPrevHKCloseValue = closeBuffer[bar_index + 1]; + } + + // + double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2; + double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4; + double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue)); + double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue)); + + // + openBuffer[bar_index] = mHKOpenValue; + highBuffer[bar_index] = mHKHighValue; + lowBuffer[bar_index] = mHKLowValue; + closeBuffer[bar_index] = mHKCloseValue; +} + +// +void CalculateCycles( + int ratesTotal, // Total Bars + int prevCalculated // Calculated Bars +) +{ + // + // Current ... + CalculateCycle( + cOpenBuffer, + cHighBuffer, + cLowBuffer, + cCloseBuffer, + cColorBuffer, + mCSMLength, + showCurrent, + ratesTotal, + prevCalculated // + ); + + // + // Short ... + CalculateCycle( + sOpenBuffer, + sHighBuffer, + sLowBuffer, + sCloseBuffer, + sColorBuffer, + mSSMLength, + showShort, + ratesTotal, + prevCalculated // + ); + + // + // Medium ... + CalculateCycle( + mOpenBuffer, + mHighBuffer, + mLowBuffer, + mCloseBuffer, + mColorBuffer, + mMSMLength, + showMedium, + ratesTotal, + prevCalculated // + ); + + // + // Long ... + CalculateCycle( + lOpenBuffer, + lHighBuffer, + lLowBuffer, + lCloseBuffer, + lColorBuffer, + mLSMLength, + showLong, + ratesTotal, + prevCalculated // + ); + + // + // Hind ... + CalculateCycle( + hOpenBuffer, + hHighBuffer, + hLowBuffer, + hCloseBuffer, + hColorBuffer, + mHSMLength, + showHind, + ratesTotal, + prevCalculated // + ); +} + +// +void CalculateCycle( + double &open[], + double &high[], + double &low[], + double &close[], + double &clr[], // Color Index Buffer + int length, // Calculation Length + bool show, // Show or not + int ratesTotal, // Total Bars + int prevCalculated // Calculated Bars +) +{ + // + // Open ... + int calculatedSMOpens = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + openBuffer, + open // + ); + + // + // Close ... + int calculatedSMCloses = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + closeBuffer, + close // + ); + + // + int calculatedSMLows = 0; + int calculatedSMHighs = 0; + if (!ignoreShadows) + { + // + // High ... + calculatedSMHighs = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + highBuffer, + high // + ); + + // + // Low ... + calculatedSMLows = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + lowBuffer, + low // + ); + } + else + { + // + // High ... + calculatedSMHighs = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + openBuffer, + high // + ); + + // + // Low ... + calculatedSMLows = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + length, + closeBuffer, + low // + ); + } + + // + // Find Calculated Items for Colors Calculations ... + int mNumberOfItems = MathMin(calculatedSMOpens, calculatedSMHighs); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMLows); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMCloses); + + // + // Create a Loop for Color of Candles ... + for (int i = 0; i < mNumberOfItems; i++) + { + // + bool isBearish = + // + open[i] > close[i] + // + ; + + // + if (show) + { + // + clr[i] = isBearish + ? bearishColorIDX + : bullishColorIDX; + } + else + { + // + clr[i] = hideColorIDX; + } + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchich.mq5 b/Documents/BKP/Indicators/x-saherelm.xchich.mq5 new file mode 100644 index 00000000..f468e31d --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchich.mq5 @@ -0,0 +1,1826 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XCHICH +// Description: Ichimoku Kinko Hyo on Cycles ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHICH Indicator" +#property strict + +// +#define ShortName "XCHICH" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Ichimoku Lines Calculator Mode ... +enum ENUM_X_ICHIMOKU_CALCULATION_MODE +{ + // + X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low + X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close +}; + +// +// Inputs ... + +// +input group "Market"; + +// +// TENKANSEN ... +input group "Tenkan Sen"; +input int tenkanSenLength = 9; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// KIJUNSEN ... +input group "Kijun Sen"; +input int kijunSenLength = 26; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// SENKOUSPANB ... +input group "Senkou Span B"; +input int senkouSpanBLength = 52; // Length +input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode + +// +// CHIKOUSPAN ... +input group "Chikou Span"; +input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Presentation"; + +// +input bool showTenkanSen = true; // Show Tenkan Sen +input bool showKijunSen = true; // Show Kijun Sen +input bool showChikouSpan = true; // Show Chikou Span +input bool showSenkouSpanA = true; // Show Senkou Span A +input bool showSenkouSpanB = true; // Show Senkou Span B +input bool showKumo = true; // Show Kumo +input bool shiftKumo = true; // Shift Kumo to Future + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 40 +#property indicator_plots 30 + +// +// CURRENT ... + +// +#define cTenBufferIndex 0 +double cTenBuffer[]; + +// +#property indicator_label1 "XICH C TK" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrBrown +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +#define cKijBufferIndex 1 +double cKijBuffer[]; + +// +#property indicator_label2 "XICH C KJ" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrDodgerBlue +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +#define cChikBufferIndex 2 +double cChikBuffer[]; + +// +#property indicator_label3 "XICH C CS" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrDarkGreen +#property indicator_style3 STYLE_SOLID +#property indicator_width3 1 + +// +#define cSSABufferIndex 3 +double cSSABuffer[]; + +// +#property indicator_label4 "XICH C SSA" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrLightGray +#property indicator_style4 STYLE_DASHDOTDOT +#property indicator_width4 1 + +// +#define cSSBBufferIndex 4 +double cSSBBuffer[]; + +// +#property indicator_label5 "XICH C SSB" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLightGray +#property indicator_style5 STYLE_DASHDOTDOT +#property indicator_width5 1 + +// +// SHORT ... + +// +#define sTenBufferIndex 5 +double sTenBuffer[]; + +// +#property indicator_label6 "XICH S TK" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrBrown +#property indicator_style6 STYLE_SOLID +#property indicator_width6 1 + +// +#define sKijBufferIndex 6 +double sKijBuffer[]; + +// +#property indicator_label7 "XICH S KJ" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrDodgerBlue +#property indicator_style7 STYLE_SOLID +#property indicator_width7 1 + +// +#define sChikBufferIndex 7 +double sChikBuffer[]; + +// +#property indicator_label8 "XICH S CS" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrDarkGreen +#property indicator_style8 STYLE_SOLID +#property indicator_width8 1 + +// +#define sSSABufferIndex 8 +double sSSABuffer[]; + +// +#property indicator_label9 "XICH S SSA" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLightGray +#property indicator_style9 STYLE_DASHDOTDOT +#property indicator_width9 1 + +// +#define sSSBBufferIndex 9 +double sSSBBuffer[]; + +// +#property indicator_label10 "XICH S SSB" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrLightGray +#property indicator_style10 STYLE_DASHDOTDOT +#property indicator_width10 1 + +// +// MEDIUM ... + +// +#define mTenBufferIndex 10 +double mTenBuffer[]; + +// +#property indicator_label11 "XICH M TK" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrBrown +#property indicator_style11 STYLE_SOLID +#property indicator_width11 1 + +// +#define mKijBufferIndex 11 +double mKijBuffer[]; + +// +#property indicator_label12 "XICH M KJ" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrDodgerBlue +#property indicator_style12 STYLE_SOLID +#property indicator_width12 1 + +// +#define mChikBufferIndex 12 +double mChikBuffer[]; + +// +#property indicator_label13 "XICH M CS" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkGreen +#property indicator_style13 STYLE_SOLID +#property indicator_width13 1 + +// +#define mSSABufferIndex 13 +double mSSABuffer[]; + +// +#property indicator_label14 "XICH M SSA" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrLightGray +#property indicator_style14 STYLE_DASHDOTDOT +#property indicator_width14 1 + +// +#define mSSBBufferIndex 14 +double mSSBBuffer[]; + +// +#property indicator_label15 "XICH M SSB" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrLightGray +#property indicator_style15 STYLE_DASHDOTDOT +#property indicator_width15 1 + +// +// LONG ... + +// +#define lTenBufferIndex 15 +double lTenBuffer[]; + +// +#property indicator_label16 "XICH L TK" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrBrown +#property indicator_style16 STYLE_SOLID +#property indicator_width16 1 + +// +#define lKijBufferIndex 16 +double lKijBuffer[]; + +// +#property indicator_label17 "XICH L KJ" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrDodgerBlue +#property indicator_style17 STYLE_SOLID +#property indicator_width17 1 + +// +#define lChikBufferIndex 17 +double lChikBuffer[]; + +// +#property indicator_label18 "XICH L CS" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrDarkGreen +#property indicator_style18 STYLE_SOLID +#property indicator_width18 1 + +// +#define lSSABufferIndex 18 +double lSSABuffer[]; + +// +#property indicator_label19 "XICH L SSA" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrLightGray +#property indicator_style19 STYLE_DASHDOTDOT +#property indicator_width19 1 + +// +#define lSSBBufferIndex 19 +double lSSBBuffer[]; + +// +#property indicator_label20 "XICH L SSB" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrLightGray +#property indicator_style20 STYLE_DASHDOTDOT +#property indicator_width20 1 + +// +// HIND ... + +// +#define hTenBufferIndex 20 +double hTenBuffer[]; + +// +#property indicator_label21 "XICH H TK" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrBrown +#property indicator_style21 STYLE_SOLID +#property indicator_width21 1 + +// +#define hKijBufferIndex 21 +double hKijBuffer[]; + +// +#property indicator_label22 "XICH H KJ" +#property indicator_type22 DRAW_LINE +#property indicator_color22 clrDodgerBlue +#property indicator_style22 STYLE_SOLID +#property indicator_width22 1 + +// +#define hChikBufferIndex 22 +double hChikBuffer[]; + +// +#property indicator_label23 "XICH H CS" +#property indicator_type23 DRAW_LINE +#property indicator_color23 clrDarkGreen +#property indicator_style23 STYLE_SOLID +#property indicator_width23 1 + +// +#define hSSABufferIndex 23 +double hSSABuffer[]; + +// +#property indicator_label24 "XICH H SSA" +#property indicator_type24 DRAW_LINE +#property indicator_color24 clrLightGray +#property indicator_style24 STYLE_DASHDOTDOT +#property indicator_width24 1 + +// +#define hSSBBufferIndex 24 +double hSSBBuffer[]; + +// +#property indicator_label25 "XICH H SSB" +#property indicator_type25 DRAW_LINE +#property indicator_color25 clrLightGray +#property indicator_style25 STYLE_DASHDOTDOT +#property indicator_width25 1 + +// +// +// + +// +// CURRENT ... + +// +#define cSSAKCBufferIndex 25 +double cSSAKCBuffer[]; + +// +#define cSSBKCBufferIndex 26 +double cSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define cKCBufferIndex 25 + +// +#property indicator_label26 "XICH C Kumo" +#property indicator_type26 DRAW_FILLING +#property indicator_color26 clrAqua, clrMagenta +#property indicator_style26 STYLE_SOLID +#property indicator_width26 1 + +// +// SHORT ... + +// +#define sSSAKCBufferIndex 27 +double sSSAKCBuffer[]; + +// +#define sSSBKCBufferIndex 28 +double sSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define sKCBufferIndex 26 + +// +#property indicator_label27 "XICH S Kumo" +#property indicator_type27 DRAW_FILLING +#property indicator_color27 clrAqua, clrMagenta +#property indicator_style27 STYLE_SOLID +#property indicator_width27 1 + +// +// MEDIUM ... + +// +#define mSSAKCBufferIndex 29 +double mSSAKCBuffer[]; + +// +#define mSSBKCBufferIndex 30 +double mSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define mKCBufferIndex 27 + +// +#property indicator_label28 "XICH M Kumo" +#property indicator_type28 DRAW_FILLING +#property indicator_color28 clrAqua, clrMagenta +#property indicator_style28 STYLE_SOLID +#property indicator_width28 1 + +// +// LONG ... + +// +#define lSSAKCBufferIndex 31 +double lSSAKCBuffer[]; + +// +#define lSSBKCBufferIndex 32 +double lSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define lKCBufferIndex 28 + +// +#property indicator_label29 "XICH L Kumo" +#property indicator_type29 DRAW_FILLING +#property indicator_color29 clrAqua, clrMagenta +#property indicator_style29 STYLE_SOLID +#property indicator_width29 1 + +// +// HIND ... + +// +#define hSSAKCBufferIndex 33 +double hSSAKCBuffer[]; + +// +#define hSSBKCBufferIndex 34 +double hSSBKCBuffer[]; + +// +// CLOUD ... + +// +#define hKCBufferIndex 29 + +// +#property indicator_label30 "XICH H Kumo" +#property indicator_type30 DRAW_FILLING +#property indicator_color30 clrAqua, clrMagenta +#property indicator_style30 STYLE_SOLID +#property indicator_width30 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCTenkanSenLength = tenkanSenLength; +int mCKijunSenLength = kijunSenLength; +int mCSenkouSpanBLength = senkouSpanBLength; + +// +// Short ... +int mSCycleLength = 0; +int mSTenkanSenLength = 0; +int mSKijunSenLength = 0; +int mSSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMTenkanSenLength = 0; +int mMKijunSenLength = 0; +int mMSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLTenkanSenLength = 0; +int mLKijunSenLength = 0; +int mLSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHTenkanSenLength = 0; +int mHKijunSenLength = 0; +int mHSenkouSpanBLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +ENUM_SERIESMODE mTenkanSenTopMode = NULL; +ENUM_SERIESMODE mTenkanSenBottomMode = NULL; + +// +ENUM_SERIESMODE mKijunSenTopMode = NULL; +ENUM_SERIESMODE mKijunSenBottomMode = NULL; + +// +ENUM_SERIESMODE mSenkouSpanBTopMode = NULL; +ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // this counts Available Bars ... + int limit; + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume + // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + (tenkanSenLength > 2 && + kijunSenLength > tenkanSenLength && + senkouSpanBLength > kijunSenLength) + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSTenkanSenLength = mSCycleLength * mCTenkanSenLength; + mSKijunSenLength = mSCycleLength * mCKijunSenLength; + mSSenkouSpanBLength = mSCycleLength * mCSenkouSpanBLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMTenkanSenLength = mMCycleLength * mCTenkanSenLength; + mMKijunSenLength = mMCycleLength * mCKijunSenLength; + mMSenkouSpanBLength = mMCycleLength * mCSenkouSpanBLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLTenkanSenLength = mLCycleLength * mCTenkanSenLength; + mLKijunSenLength = mLCycleLength * mCKijunSenLength; + mLSenkouSpanBLength = mLCycleLength * mCSenkouSpanBLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHTenkanSenLength = mHCycleLength * mCTenkanSenLength; + mHKijunSenLength = mHCycleLength * mCKijunSenLength; + mHSenkouSpanBLength = mHCycleLength * mCSenkouSpanBLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(mCTenkanSenLength, mCKijunSenLength); + result = MathMax(result, mCSenkouSpanBLength); + + // + // Short ... + result = MathMax(mSTenkanSenLength, mSKijunSenLength); + result = MathMax(result, mSSenkouSpanBLength); + + // + // Medium ... + result = MathMax(mMTenkanSenLength, mMKijunSenLength); + result = MathMax(result, mMSenkouSpanBLength); + + // + // Long ... + result = MathMax(mLTenkanSenLength, mLKijunSenLength); + result = MathMax(result, mLSenkouSpanBLength); + + // + // Hind ... + result = MathMax(mHTenkanSenLength, mHKijunSenLength); + result = MathMax(result, mHSenkouSpanBLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // TENKANSEN ... + + // + bool canCShowTenkanSen = showTenkanSen && showCurrent; + ENUM_DRAW_TYPE cTenkanSenDrawType = canCShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cTenBuffer, true); + SetIndexBuffer(cTenBufferIndex, cTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cTenBufferIndex, PLOT_SHOW_DATA, canCShowTenkanSen); + PlotIndexSetInteger(cTenBufferIndex, PLOT_DRAW_TYPE, cTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canCShowKijunSen = showKijunSen && showCurrent; + ENUM_DRAW_TYPE cKijunSenDrawType = canCShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cKijBuffer, true); + SetIndexBuffer(cKijBufferIndex, cKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cKijBufferIndex, PLOT_SHOW_DATA, canCShowKijunSen); + PlotIndexSetInteger(cKijBufferIndex, PLOT_DRAW_TYPE, cKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canCShowChikouSpan = showChikouSpan && showCurrent; + ENUM_DRAW_TYPE cChikouSpanDrawType = canCShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cChikBuffer, true); + SetIndexBuffer(cChikBufferIndex, cChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cChikBufferIndex, PLOT_SHIFT, -mCKijunSenLength); + PlotIndexSetInteger(cChikBufferIndex, PLOT_SHOW_DATA, canCShowChikouSpan); + PlotIndexSetInteger(cChikBufferIndex, PLOT_DRAW_TYPE, cChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int cShiftSize = shiftKumo ? mCKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canCShowSenkouSpanA = showSenkouSpanA && showCurrent; + ENUM_DRAW_TYPE cSenkouSpanADrawType = canCShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cSSABuffer, true); + SetIndexBuffer(cSSABufferIndex, cSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSABufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cSSABufferIndex, PLOT_SHOW_DATA, canCShowSenkouSpanA); + PlotIndexSetInteger(cSSABufferIndex, PLOT_DRAW_TYPE, cSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canCShowSenkouSpanB = showSenkouSpanB && showCurrent; + ENUM_DRAW_TYPE cSenkouSpanBDrawType = canCShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cSSBBuffer, true); + SetIndexBuffer(cSSBBufferIndex, cSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_SHOW_DATA, canCShowSenkouSpanB); + PlotIndexSetInteger(cSSBBufferIndex, PLOT_DRAW_TYPE, cSenkouSpanBDrawType); + + // + // Short ... + + // + // TENKANSEN ... + + // + bool canSShowTenkanSen = showTenkanSen && showShort; + ENUM_DRAW_TYPE sTenkanSenDrawType = canSShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sTenBuffer, true); + SetIndexBuffer(sTenBufferIndex, sTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sTenBufferIndex, PLOT_SHOW_DATA, canSShowTenkanSen); + PlotIndexSetInteger(sTenBufferIndex, PLOT_DRAW_TYPE, sTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canSShowKijunSen = showKijunSen && showShort; + ENUM_DRAW_TYPE sKijunSenDrawType = canSShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sKijBuffer, true); + SetIndexBuffer(sKijBufferIndex, sKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sKijBufferIndex, PLOT_SHOW_DATA, canSShowKijunSen); + PlotIndexSetInteger(sKijBufferIndex, PLOT_DRAW_TYPE, sKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canSShowChikouSpan = showChikouSpan && showShort; + ENUM_DRAW_TYPE sChikouSpanDrawType = canSShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sChikBuffer, true); + SetIndexBuffer(sChikBufferIndex, sChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sChikBufferIndex, PLOT_SHIFT, -mSKijunSenLength); + PlotIndexSetInteger(sChikBufferIndex, PLOT_SHOW_DATA, canSShowChikouSpan); + PlotIndexSetInteger(sChikBufferIndex, PLOT_DRAW_TYPE, sChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int sShiftSize = shiftKumo ? mSKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canSShowSenkouSpanA = showSenkouSpanA && showShort; + ENUM_DRAW_TYPE sSenkouSpanADrawType = canSShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sSSABuffer, true); + SetIndexBuffer(sSSABufferIndex, sSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSABufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sSSABufferIndex, PLOT_SHOW_DATA, canSShowSenkouSpanA); + PlotIndexSetInteger(sSSABufferIndex, PLOT_DRAW_TYPE, sSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canSShowSenkouSpanB = showSenkouSpanB && showShort; + ENUM_DRAW_TYPE sSenkouSpanBDrawType = canSShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sSSBBuffer, true); + SetIndexBuffer(sSSBBufferIndex, sSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_SHOW_DATA, canSShowSenkouSpanB); + PlotIndexSetInteger(sSSBBufferIndex, PLOT_DRAW_TYPE, sSenkouSpanBDrawType); + + // + // Medium ... + + // + // TENKANSEN ... + + // + bool canMShowTenkanSen = showTenkanSen && showMedium; + ENUM_DRAW_TYPE mTenkanSenDrawType = canMShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mTenBuffer, true); + SetIndexBuffer(mTenBufferIndex, mTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mTenBufferIndex, PLOT_SHOW_DATA, canMShowTenkanSen); + PlotIndexSetInteger(mTenBufferIndex, PLOT_DRAW_TYPE, mTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canMShowKijunSen = showKijunSen && showMedium; + ENUM_DRAW_TYPE mKijunSenDrawType = canMShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mKijBuffer, true); + SetIndexBuffer(mKijBufferIndex, mKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mKijBufferIndex, PLOT_SHOW_DATA, canMShowKijunSen); + PlotIndexSetInteger(mKijBufferIndex, PLOT_DRAW_TYPE, mKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canMShowChikouSpan = showChikouSpan && showMedium; + ENUM_DRAW_TYPE mChikouSpanDrawType = canMShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mChikBuffer, true); + SetIndexBuffer(mChikBufferIndex, mChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mChikBufferIndex, PLOT_SHIFT, -mMKijunSenLength); + PlotIndexSetInteger(mChikBufferIndex, PLOT_SHOW_DATA, canMShowChikouSpan); + PlotIndexSetInteger(mChikBufferIndex, PLOT_DRAW_TYPE, mChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int mShiftSize = shiftKumo ? mMKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canMShowSenkouSpanA = showSenkouSpanA && showMedium; + ENUM_DRAW_TYPE mSenkouSpanADrawType = canMShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mSSABuffer, true); + SetIndexBuffer(mSSABufferIndex, mSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSABufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mSSABufferIndex, PLOT_SHOW_DATA, canMShowSenkouSpanA); + PlotIndexSetInteger(mSSABufferIndex, PLOT_DRAW_TYPE, mSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canMShowSenkouSpanB = showSenkouSpanB && showMedium; + ENUM_DRAW_TYPE mSenkouSpanBDrawType = canMShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mSSBBuffer, true); + SetIndexBuffer(mSSBBufferIndex, mSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_SHOW_DATA, canMShowSenkouSpanB); + PlotIndexSetInteger(mSSBBufferIndex, PLOT_DRAW_TYPE, mSenkouSpanBDrawType); + + // + // Long ... + + // + // TENKANSEN ... + + // + bool canLShowTenkanSen = showTenkanSen && showLong; + ENUM_DRAW_TYPE lTenkanSenDrawType = canLShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lTenBuffer, true); + SetIndexBuffer(lTenBufferIndex, lTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lTenBufferIndex, PLOT_SHOW_DATA, canLShowTenkanSen); + PlotIndexSetInteger(lTenBufferIndex, PLOT_DRAW_TYPE, lTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canLShowKijunSen = showKijunSen && showLong; + ENUM_DRAW_TYPE lKijunSenDrawType = canLShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lKijBuffer, true); + SetIndexBuffer(lKijBufferIndex, lKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lKijBufferIndex, PLOT_SHOW_DATA, canLShowKijunSen); + PlotIndexSetInteger(lKijBufferIndex, PLOT_DRAW_TYPE, lKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canLShowChikouSpan = showChikouSpan && showLong; + ENUM_DRAW_TYPE lChikouSpanDrawType = canLShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lChikBuffer, true); + SetIndexBuffer(lChikBufferIndex, lChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lChikBufferIndex, PLOT_SHIFT, -mLKijunSenLength); + PlotIndexSetInteger(lChikBufferIndex, PLOT_SHOW_DATA, canLShowChikouSpan); + PlotIndexSetInteger(lChikBufferIndex, PLOT_DRAW_TYPE, lChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int lShiftSize = shiftKumo ? mLKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canLShowSenkouSpanA = showSenkouSpanA && showLong; + ENUM_DRAW_TYPE lSenkouSpanADrawType = canLShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lSSABuffer, true); + SetIndexBuffer(lSSABufferIndex, lSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSABufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lSSABufferIndex, PLOT_SHOW_DATA, canLShowSenkouSpanA); + PlotIndexSetInteger(lSSABufferIndex, PLOT_DRAW_TYPE, lSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canLShowSenkouSpanB = showSenkouSpanB && showLong; + ENUM_DRAW_TYPE lSenkouSpanBDrawType = canLShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lSSBBuffer, true); + SetIndexBuffer(lSSBBufferIndex, lSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_SHOW_DATA, canLShowSenkouSpanB); + PlotIndexSetInteger(lSSBBufferIndex, PLOT_DRAW_TYPE, lSenkouSpanBDrawType); + + // + // Hind ... + + // + // TENKANSEN ... + + // + bool canHShowTenkanSen = showTenkanSen && showHind; + ENUM_DRAW_TYPE hTenkanSenDrawType = canHShowTenkanSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hTenBuffer, true); + SetIndexBuffer(hTenBufferIndex, hTenBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hTenBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hTenBufferIndex, PLOT_SHOW_DATA, canHShowTenkanSen); + PlotIndexSetInteger(hTenBufferIndex, PLOT_DRAW_TYPE, hTenkanSenDrawType); + + // + // KIJUNSEN ... + + // + bool canHShowKijunSen = showKijunSen && showHind; + ENUM_DRAW_TYPE hKijunSenDrawType = canHShowKijunSen ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hKijBuffer, true); + SetIndexBuffer(hKijBufferIndex, hKijBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hKijBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hKijBufferIndex, PLOT_SHOW_DATA, canHShowKijunSen); + PlotIndexSetInteger(hKijBufferIndex, PLOT_DRAW_TYPE, hKijunSenDrawType); + + // + // CHIKOUSPAN ... + + // + bool canHShowChikouSpan = showChikouSpan && showHind; + ENUM_DRAW_TYPE hChikouSpanDrawType = canHShowChikouSpan ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hChikBuffer, true); + SetIndexBuffer(hChikBufferIndex, hChikBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hChikBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hChikBufferIndex, PLOT_SHIFT, -mHKijunSenLength); + PlotIndexSetInteger(hChikBufferIndex, PLOT_SHOW_DATA, canHShowChikouSpan); + PlotIndexSetInteger(hChikBufferIndex, PLOT_DRAW_TYPE, hChikouSpanDrawType); + + // + // SENKOUSPAN A and B ... + int hShiftSize = shiftKumo ? mHKijunSenLength : 0; + + // + // SENKOUSPANA ... + bool canHShowSenkouSpanA = showSenkouSpanA && showHind; + ENUM_DRAW_TYPE hSenkouSpanADrawType = canHShowSenkouSpanA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hSSABuffer, true); + SetIndexBuffer(hSSABufferIndex, hSSABuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSABufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hSSABufferIndex, PLOT_SHOW_DATA, canHShowSenkouSpanA); + PlotIndexSetInteger(hSSABufferIndex, PLOT_DRAW_TYPE, hSenkouSpanADrawType); + + // + // SENKOUSPANB ... + bool canHShowSenkouSpanB = showSenkouSpanB && showHind; + ENUM_DRAW_TYPE hSenkouSpanBDrawType = canHShowSenkouSpanB ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hSSBBuffer, true); + SetIndexBuffer(hSSBBufferIndex, hSSBBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_SHOW_DATA, canHShowSenkouSpanB); + PlotIndexSetInteger(hSSBBufferIndex, PLOT_DRAW_TYPE, hSenkouSpanBDrawType); + + // + // Here we Create KUMO CLOUD Buffers ... + + // + // int lastBufferIndex = hSSBBufferIndex; + + // + // Current ... + bool cCanShowKumo = showKumo && showCurrent; + ENUM_DRAW_TYPE cKumoDrawType = cCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(cSSAKCBuffer, true); + SetIndexBuffer(cSSAKCBufferIndex, cSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(cSSBKCBuffer, true); + SetIndexBuffer(cSSBKCBufferIndex, cSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(cSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(cKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(cKCBufferIndex, PLOT_SHIFT, cShiftSize); + PlotIndexSetInteger(cKCBufferIndex, PLOT_DRAW_TYPE, cKumoDrawType); + + // + // Short ... + bool sCanShowKumo = showKumo && showShort; + ENUM_DRAW_TYPE sKumoDrawType = sCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(sSSAKCBuffer, true); + SetIndexBuffer(sSSAKCBufferIndex, sSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(sSSBKCBuffer, true); + SetIndexBuffer(sSSBKCBufferIndex, sSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(sKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(sKCBufferIndex, PLOT_SHIFT, sShiftSize); + PlotIndexSetInteger(sKCBufferIndex, PLOT_DRAW_TYPE, sKumoDrawType); + + // + // Medium ... + bool mCanShowKumo = showKumo && showMedium; + ENUM_DRAW_TYPE mKumoDrawType = mCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(mSSAKCBuffer, true); + SetIndexBuffer(mSSAKCBufferIndex, mSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(mSSBKCBuffer, true); + SetIndexBuffer(mSSBKCBufferIndex, mSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(mSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(mKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(mKCBufferIndex, PLOT_SHIFT, mShiftSize); + PlotIndexSetInteger(mKCBufferIndex, PLOT_DRAW_TYPE, mKumoDrawType); + + // + // Long ... + bool lCanShowKumo = showKumo && showLong; + ENUM_DRAW_TYPE lKumoDrawType = lCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(lSSAKCBuffer, true); + SetIndexBuffer(lSSAKCBufferIndex, lSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(lSSBKCBuffer, true); + SetIndexBuffer(lSSBKCBufferIndex, lSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(lKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(lKCBufferIndex, PLOT_SHIFT, lShiftSize); + PlotIndexSetInteger(lKCBufferIndex, PLOT_DRAW_TYPE, lKumoDrawType); + + // + // Hind ... + bool hCanShowKumo = showKumo && showHind; + ENUM_DRAW_TYPE hKumoDrawType = hCanShowKumo ? DRAW_FILLING : DRAW_NONE; + + // + // SENKOUSPANA ... + ArraySetAsSeries(hSSAKCBuffer, true); + SetIndexBuffer(hSSAKCBufferIndex, hSSAKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSAKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // SENKOUSPANB ... + ArraySetAsSeries(hSSBKCBuffer, true); + SetIndexBuffer(hSSBKCBufferIndex, hSSBKCBuffer, INDICATOR_DATA); + PlotIndexSetInteger(hSSBKCBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + PlotIndexSetInteger(hKCBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(hKCBufferIndex, PLOT_SHIFT, hShiftSize); + PlotIndexSetInteger(hKCBufferIndex, PLOT_DRAW_TYPE, hKumoDrawType); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // CURRENT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mCTenkanSenLength, + mCKijunSenLength, + mCSenkouSpanBLength, + // + cTenBuffer, + cKijBuffer, + cChikBuffer, + cSSABuffer, + cSSBBuffer, + cSSAKCBuffer, + cSSBKCBuffer + // + ); + + // + // SHORT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mSTenkanSenLength, + mSKijunSenLength, + mSSenkouSpanBLength, + // + sTenBuffer, + sKijBuffer, + sChikBuffer, + sSSABuffer, + sSSBBuffer, + sSSAKCBuffer, + sSSBKCBuffer + // + ); + + // + // MEDIUM ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mMTenkanSenLength, + mMKijunSenLength, + mMSenkouSpanBLength, + // + mTenBuffer, + mKijBuffer, + mChikBuffer, + mSSABuffer, + mSSBBuffer, + mSSAKCBuffer, + mSSBKCBuffer + // + ); + + // + // LONG ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mLTenkanSenLength, + mLKijunSenLength, + mLSenkouSpanBLength, + // + lTenBuffer, + lKijBuffer, + lChikBuffer, + lSSABuffer, + lSSBBuffer, + lSSAKCBuffer, + lSSBKCBuffer + // + ); + + // + // HIND ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mHTenkanSenLength, + mHKijunSenLength, + mHSenkouSpanBLength, + // + hTenBuffer, + hKijBuffer, + hChikBuffer, + hSSABuffer, + hSSBBuffer, + hSSAKCBuffer, + hSSBKCBuffer + // + ); +} + +// +void CalculateCycle( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _tenkanSenLength, + int _kijunSenLength, + int _senkouSpanBLength, + // + double &_tenkanSenBuffer[], + double &_kijunSenBuffer[], + double &_chikouSpanBuffer[], + double &_senkouABuffer[], + double &_senkouBBuffer[], + double &_cloudSenkouSpanABuffer[], + double &_cloudSenkouSpanBBuffer[] + // +) +{ + // + double topValue; + double bottomValue; + + // + // TENKANSEN ... + + // + // Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ... + if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL) + { + // + switch (tenkanSenMode) + { + // + case X_XICH_HH_LL_MODE: + // + mTenkanSenTopMode = MODE_HIGH; + mTenkanSenBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mTenkanSenTopMode = MODE_OPEN; + mTenkanSenBottomMode = MODE_CLOSE; + break; + } + } + + // + XOHCL bar; + bar.Init( + _Symbol, + _Period, + bar_index + // + ); + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _tenkanSenLength, + mTenkanSenTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _tenkanSenLength, + mTenkanSenBottomMode + // + ); + + // + double tenkanSenValue = (topValue + bottomValue) / 2; + _tenkanSenBuffer[bar_index] = tenkanSenValue; + + // + // KIJUNSEN ... + + // + // Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ... + if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL) + { + // + switch (kijunSenMode) + { + // + case X_XICH_HH_LL_MODE: + // + mKijunSenTopMode = MODE_HIGH; + mKijunSenBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mKijunSenTopMode = MODE_OPEN; + mKijunSenBottomMode = MODE_CLOSE; + break; + } + } + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _kijunSenLength, + mKijunSenTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _kijunSenLength, + mKijunSenBottomMode + // + ); + + // + double kijunSenValue = (topValue + bottomValue) / 2; + _kijunSenBuffer[bar_index] = kijunSenValue; + + // + // CHIKOUSPAN ... + double chikouSpanValue = bar + .GetPrice(chikuoSpanAppliedTo); + + // + _chikouSpanBuffer[bar_index] = chikouSpanValue; + + // + // KUMO ... + + // + // SENKOUSPANA ... + double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2; + _senkouABuffer[bar_index] = senkouSpanAValue; + _cloudSenkouSpanABuffer[bar_index] = senkouSpanAValue; + + // + // SENKOUSPANB ... + + // + // Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ... + if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL) + { + // + switch (senkouSpanBMode) + { + // + case X_XICH_HH_LL_MODE: + // + mSenkouSpanBTopMode = MODE_HIGH; + mSenkouSpanBBottomMode = MODE_LOW; + break; + + // + case X_XICH_HO_LC_MODE: + // + mSenkouSpanBTopMode = MODE_OPEN; + mSenkouSpanBBottomMode = MODE_CLOSE; + break; + } + } + + // + // Calculate Top ... + topValue = bar + .FindHighest( + _senkouSpanBLength, + mSenkouSpanBTopMode + // + ); + + // + // Calculate Bottom ... + bottomValue = bar + .FindLowest( + _senkouSpanBLength, + mSenkouSpanBBottomMode + // + ); + + // + double senkouSpanBValue = (topValue + bottomValue) / 2; + _senkouBBuffer[bar_index] = senkouSpanBValue; + _cloudSenkouSpanBBuffer[bar_index] = senkouSpanBValue; + + // +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchm.mq5 b/Documents/BKP/Indicators/x-saherelm.xchm.mq5 new file mode 100644 index 00000000..cb3572d2 --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchm.mq5 @@ -0,0 +1,1089 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHM +// Description: XCHMrend Detector ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHM Indicator" +#property strict + +// +#define ShortName "XCHM" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input int fastLength = 9; // Fast Length +input int slowLength = 18; // Slow Length +input ENUM_MA_METHOD method = MODE_SMA; // Mode +input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// Parts ... +input bool showFast = true; // Show Fast +input bool showSlow = true; // Show Slow + +// +// AVG ... +input bool showAVG = true; // Show Average + +// +// Cycles ... +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 12 +#property indicator_plots 12 + +// +// AVG ... + +// +// Fast ... +#define avgFastBufferIndex 0 +double avgFastBuffer[]; + +// +#property indicator_label1 "XCHM AF" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Slow ... +#define avgSlowBufferIndex 1 +double avgSlowBuffer[]; + +// +#property indicator_label2 "XCHM AS" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// Current ... + +// +// Fast ... +#define cFastBufferIndex 2 +double cFastBuffer[]; + +// +#property indicator_label3 "XCHM CF" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Slow ... +#define cSlowBufferIndex 3 +double cSlowBuffer[]; + +// +#property indicator_label4 "XCHM CS" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrMagenta +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Short ... + +// +// Fast ... +#define sFastBufferIndex 4 +double sFastBuffer[]; + +// +#property indicator_label5 "XCHM SF" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrAqua +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Slow ... +#define sSlowBufferIndex 5 +double sSlowBuffer[]; + +// +#property indicator_label6 "XCHM SS" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrMagenta +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Medium ... + +// +// Fast ... +#define mFastBufferIndex 6 +double mFastBuffer[]; + +// +#property indicator_label7 "XCHM MF" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrAqua +#property indicator_style7 STYLE_DOT +#property indicator_width7 1 + +// +// Slow ... +#define mSlowBufferIndex 7 +double mSlowBuffer[]; + +// +#property indicator_label8 "XCHM MS" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrMagenta +#property indicator_style8 STYLE_DOT +#property indicator_width8 1 + +// +// Long ... + +// +// Fast ... +#define lFastBufferIndex 8 +double lFastBuffer[]; + +// +#property indicator_label9 "XCHM LF" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrAqua +#property indicator_style9 STYLE_DOT +#property indicator_width9 1 + +// +// Slow ... +#define lSlowBufferIndex 9 +double lSlowBuffer[]; + +// +#property indicator_label10 "XCHM LS" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrMagenta +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +// +// Hind ... + +// +// Fast ... +#define hFastBufferIndex 10 +double hFastBuffer[]; + +// +#property indicator_label11 "XCHM HF" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAqua +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +// Slow ... +#define hSlowBufferIndex 11 +double hSlowBuffer[]; + +// +#property indicator_label12 "XCHM HS" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrMagenta +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +// Variables ... + +// +int maxLength; + +// +// Current ... +int cFastHandler = INVALID_HANDLE; +int cSlowHandler = INVALID_HANDLE; + +// +// Short ... +int mSCLength = 0; +int mSCFastLength = 0; +int mSCSlowLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +int sFastHandler = INVALID_HANDLE; +int sSlowHandler = INVALID_HANDLE; + +// +// Medium ... +int mMCLength = 0; +int mMCFastLength = 0; +int mMCSlowLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +int mFastHandler = INVALID_HANDLE; +int mSlowHandler = INVALID_HANDLE; + +// +// Long ... +int mLCLength = 0; +int mLCFastLength = 0; +int mLCSlowLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +int lFastHandler = INVALID_HANDLE; +int lSlowHandler = INVALID_HANDLE; + +// +// Hind ... +int mHCLength = 0; +int mHCFastLength = 0; +int mHCSlowLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +int hFastHandler = INVALID_HANDLE; +int hSlowHandler = INVALID_HANDLE; + +// +// EVENT Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + // Current ... + IndicatorRelease(cFastHandler); + IndicatorRelease(cSlowHandler); + + // + // Short ... + IndicatorRelease(sFastHandler); + IndicatorRelease(sSlowHandler); + + // + // Medium ... + IndicatorRelease(mFastHandler); + IndicatorRelease(mSlowHandler); + + // + // Long ... + IndicatorRelease(lFastHandler); + IndicatorRelease(lSlowHandler); + + // + // Hind ... + IndicatorRelease(hFastHandler); + IndicatorRelease(hSlowHandler); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(low, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(close, true); + + // + // this counts Available Bars ... + int limit; + + // + // Validate Calculated Bars ... + bool isPassedRequiredCalculatedBars = + // + // Current ... + BarsCalculated(cFastHandler) >= maxLength && + BarsCalculated(cSlowHandler) >= maxLength && + // + // Short ... + BarsCalculated(sFastHandler) >= maxLength && + BarsCalculated(sSlowHandler) >= maxLength && + // + // Medium ... + BarsCalculated(mFastHandler) >= maxLength && + BarsCalculated(mSlowHandler) >= maxLength && + // + // Long ... + BarsCalculated(lFastHandler) >= maxLength && + BarsCalculated(lSlowHandler) >= maxLength && + // + // Hind ... + BarsCalculated(hFastHandler) >= maxLength && + BarsCalculated(hSlowHandler) >= maxLength + // + ; + if (!isPassedRequiredCalculatedBars) + { + return prev_calculated; + } + + // + limit = + (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Buffers Copy ... + + // + // Current ... + int copiedCFasts = CopyBuffer(cFastHandler, 0, 0, limit, cFastBuffer); + int copiedCSlows = CopyBuffer(cSlowHandler, 0, 0, limit, cSlowBuffer); + + // + // Short ... + int copiedSFasts = CopyBuffer(sFastHandler, 0, 0, limit, sFastBuffer); + int copiedSSlows = CopyBuffer(sSlowHandler, 0, 0, limit, sSlowBuffer); + + // + // Medium ... + int copiedMFasts = CopyBuffer(mFastHandler, 0, 0, limit, mFastBuffer); + int copiedMSlows = CopyBuffer(mSlowHandler, 0, 0, limit, mSlowBuffer); + + // + // Long ... + int copiedLFasts = CopyBuffer(lFastHandler, 0, 0, limit, lFastBuffer); + int copiedLSlows = CopyBuffer(lSlowHandler, 0, 0, limit, lSlowBuffer); + + // + // Hind ... + int copiedHFasts = CopyBuffer(hFastHandler, 0, 0, limit, hFastBuffer); + int copiedHSlows = CopyBuffer(hSlowHandler, 0, 0, limit, hSlowBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // + // Current ... + copiedCFasts > 0 && + copiedCSlows > 0 && + // + // Short ... + copiedSFasts > 0 && + copiedSSlows > 0 && + // + // Medium ... + copiedMFasts > 0 && + copiedMSlows > 0 && + // + // Long ... + copiedLFasts > 0 && + copiedLSlows > 0 && + // + // Hind ... + copiedHFasts > 0 && + copiedHSlows > 0 + // + ; + if (!isPassedRequiredCopiedItems) + { + return prev_calculated; + } + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// CUSTOM Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + fastLength > 2 && + slowLength > fastLength && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(fastLength, slowLength); + + // + // Short ... + result = MathMax(result, mSCFastLength); + result = MathMax(result, mSCSlowLength); + + // + // Medium ... + result = MathMax(result, mMCFastLength); + result = MathMax(result, mMCSlowLength); + + // + // Long ... + result = MathMax(result, mLCFastLength); + result = MathMax(result, mLCSlowLength); + + // + // Hind ... + result = MathMax(result, mHCFastLength); + result = MathMax(result, mHCSlowLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // AVG ... + + // + // Fast ... + bool canShowAVGFast = showAVG && showFast; + ENUM_DRAW_TYPE avgFastDrawType = canShowAVGFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgFastBuffer, true); + SetIndexBuffer(avgFastBufferIndex, avgFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_SHOW_DATA, canShowAVGFast); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_TYPE, avgFastDrawType); + + // + // Slow ... + bool canShowAVGSlow = showAVG && showSlow; + ENUM_DRAW_TYPE avgSlowDrawType = canShowAVGSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgSlowBuffer, true); + SetIndexBuffer(avgSlowBufferIndex, avgSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_SHOW_DATA, canShowAVGSlow); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_TYPE, avgSlowDrawType); + + // + // Current ... + + // + // Fast ... + bool canShowCFast = showCurrent && showFast; + ENUM_DRAW_TYPE cFastDrawType = canShowCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cFastBuffer, true); + SetIndexBuffer(cFastBufferIndex, cFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cFastBufferIndex, PLOT_SHOW_DATA, canShowCFast); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_TYPE, cFastDrawType); + + // + // Slow ... + bool canShowCSlow = showCurrent && showSlow; + ENUM_DRAW_TYPE cSlowDrawType = canShowCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cSlowBuffer, true); + SetIndexBuffer(cSlowBufferIndex, cSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_SHOW_DATA, canShowCSlow); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_TYPE, cSlowDrawType); + + // + // Short ... + + // + // Fast ... + bool canShowSFast = showShort && showFast; + ENUM_DRAW_TYPE sFastDrawType = canShowSFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sFastBuffer, true); + SetIndexBuffer(sFastBufferIndex, sFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sFastBufferIndex, PLOT_SHOW_DATA, canShowSFast); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_TYPE, sFastDrawType); + + // + // Slow ... + bool canShowSSlow = showShort && showSlow; + ENUM_DRAW_TYPE sSlowDrawType = canShowSSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sSlowBuffer, true); + SetIndexBuffer(sSlowBufferIndex, sSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_SHOW_DATA, canShowSSlow); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_TYPE, sSlowDrawType); + + // + // Medium ... + + // + // Fast ... + bool canShowMFast = showMedium && showFast; + ENUM_DRAW_TYPE mFastDrawType = canShowMFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mFastBuffer, true); + SetIndexBuffer(mFastBufferIndex, mFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mFastBufferIndex, PLOT_SHOW_DATA, canShowMFast); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_TYPE, mFastDrawType); + + // + // Slow ... + bool canShowMSlow = showMedium && showSlow; + ENUM_DRAW_TYPE mSlowDrawType = canShowMSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mSlowBuffer, true); + SetIndexBuffer(mSlowBufferIndex, mSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_SHOW_DATA, canShowMSlow); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_TYPE, mSlowDrawType); + + // + // Long ... + + // + // Fast ... + bool canShowLFast = showLong && showFast; + ENUM_DRAW_TYPE lFastDrawType = canShowLFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lFastBuffer, true); + SetIndexBuffer(lFastBufferIndex, lFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lFastBufferIndex, PLOT_SHOW_DATA, canShowLFast); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_TYPE, lFastDrawType); + + // + // Slow ... + bool canShowLSlow = showLong && showSlow; + ENUM_DRAW_TYPE lSlowDrawType = canShowLSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lSlowBuffer, true); + SetIndexBuffer(lSlowBufferIndex, lSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_SHOW_DATA, canShowLSlow); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_TYPE, lSlowDrawType); + + // + // Hind ... + + // + // Fast ... + bool canShowHFast = showHind && showFast; + ENUM_DRAW_TYPE hFastDrawType = canShowHFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hFastBuffer, true); + SetIndexBuffer(hFastBufferIndex, hFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hFastBufferIndex, PLOT_SHOW_DATA, canShowHFast); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_TYPE, hFastDrawType); + + // + // Slow ... + bool canShowHSlow = showHind && showSlow; + ENUM_DRAW_TYPE hSlowDrawType = canShowHSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hSlowBuffer, true); + SetIndexBuffer(hSlowBufferIndex, hSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_SHOW_DATA, canShowHSlow); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_TYPE, hSlowDrawType); +} + +// +// Initial Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Initialize Handlers ... + cFastHandler = iMA( + _Symbol, + _Period, + fastLength, + 0, + method, + appliedTo // + ); + cSlowHandler = iMA( + _Symbol, + _Period, + slowLength, + 0, + method, + appliedTo // + ); + result = + // + cFastHandler != INVALID_HANDLE && + cSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSCFastLength = fastLength * mSCLength; + mSCSlowLength = slowLength * mSCLength; + + // + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + sFastHandler = iMA( + _Symbol, + _Period, + mSCFastLength, + 0, + method, + appliedTo // + ); + sSlowHandler = iMA( + _Symbol, + _Period, + mSCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + sFastHandler != INVALID_HANDLE && + sSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMCFastLength = fastLength * mMCLength; + mMCSlowLength = slowLength * mMCLength; + + // + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + mFastHandler = iMA( + _Symbol, + _Period, + mMCFastLength, + 0, + method, + appliedTo // + ); + mSlowHandler = iMA( + _Symbol, + _Period, + mMCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + mFastHandler != INVALID_HANDLE && + mSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLCFastLength = fastLength * mLCLength; + mLCSlowLength = slowLength * mLCLength; + + // + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + lFastHandler = iMA( + _Symbol, + _Period, + mLCFastLength, + 0, + method, + appliedTo // + ); + lSlowHandler = iMA( + _Symbol, + _Period, + mLCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + lFastHandler != INVALID_HANDLE && + lSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHCFastLength = fastLength * mHCLength; + mHCSlowLength = slowLength * mHCLength; + + // + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + hFastHandler = iMA( + _Symbol, + _Period, + mHCFastLength, + 0, + method, + appliedTo // + ); + hSlowHandler = iMA( + _Symbol, + _Period, + mHCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + hFastHandler != INVALID_HANDLE && + hSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Do all Custom Calculations ... +void CalculateBuffers(int barIndex) +{ + // + double cFast = cFastBuffer[barIndex]; + double sFast = sFastBuffer[barIndex]; + double mFast = mFastBuffer[barIndex]; + double lFast = lFastBuffer[barIndex]; + double hFast = hFastBuffer[barIndex]; + + // + double fast = + cFast + + sFast + + mFast + + lFast + + hFast; + avgFastBuffer[barIndex] = fast / 5; + + // + double cSlow = cSlowBuffer[barIndex]; + double sSlow = sSlowBuffer[barIndex]; + double mSlow = mSlowBuffer[barIndex]; + double lSlow = lSlowBuffer[barIndex]; + double hSlow = hSlowBuffer[barIndex]; + + // + double slow = + cSlow + + sSlow + + mSlow + + lSlow + + hSlow; + avgSlowBuffer[barIndex] = slow / 5; +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchstr.mq5 b/Documents/BKP/Indicators/x-saherelm.xchstr.mq5 new file mode 100644 index 00000000..b67b000c --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchstr.mq5 @@ -0,0 +1,1246 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHSTR +// Description: Smoothed HikenAshi Cycles ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHSTR Indicator" +#property strict + +// +#define ShortName "XCHSTR" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; + +// +input int atrLength = 14; // Length +input double atrMultiplier = 3.0; // Multiplier +input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 35 +#property indicator_plots 10 + +// +// Current ... + +// +#define cBufferIndex 0 +#define cPlotBufferIndex 0 +double cBuffer[]; + +// +#define cColorBufferIndex 1 +double cColorBuffer[]; + +// +#property indicator_label1 "C XSTR" +#property indicator_type1 DRAW_COLOR_LINE +#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style1 STYLE_DOT + +// +// Short ... + +// +#define sBufferIndex 2 +#define sPlotBufferIndex 1 +double sBuffer[]; + +// +#define sColorBufferIndex 3 +double sColorBuffer[]; + +// +#property indicator_label2 "S XSTR" +#property indicator_type2 DRAW_COLOR_LINE +#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style2 STYLE_DOT + +// +// Medium ... + +// +#define mBufferIndex 4 +#define mPlotBufferIndex 2 +double mBuffer[]; + +// +#define mColorBufferIndex 5 +double mColorBuffer[]; + +// +#property indicator_label3 "M XSTR" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style3 STYLE_DOT + +// +// Long ... + +// +#define lBufferIndex 6 +#define lPlotBufferIndex 3 +double lBuffer[]; + +// +#define lColorBufferIndex 7 +double lColorBuffer[]; + +// +#property indicator_label4 "L XSTR" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style4 STYLE_DOT + +// +// Hind ... + +// +#define hBufferIndex 8 +#define hPlotBufferIndex 4 +double hBuffer[]; + +// +#define hColorBufferIndex 9 +double hColorBuffer[]; + +// +#property indicator_label5 "H XSTR" +#property indicator_type5 DRAW_COLOR_LINE +#property indicator_color5 CLR_NONE, clrGreen, clrDarkRed +#property indicator_style5 STYLE_DOT + +// +// Data Buffers ... + +// +// Current ... + +// +#define cAtrBufferIndex 10 +double cAtrBuffer[]; + +// +#define cTrendBufferIndex 11 +double cTrendBuffer[]; + +// +#define cUpBufferIndex 12 +double cUpBuffer[]; + +// +#define cDownBufferIndex 13 +double cDownBuffer[]; + +// +#define cPriceBufferIndex 14 +double cPriceBuffer[]; + +// +// Short ... + +// +#define sAtrBufferIndex 15 +double sAtrBuffer[]; + +// +#define sTrendBufferIndex 16 +double sTrendBuffer[]; + +// +#define sUpBufferIndex 17 +double sUpBuffer[]; + +// +#define sDownBufferIndex 18 +double sDownBuffer[]; + +// +#define sPriceBufferIndex 19 +double sPriceBuffer[]; + +// +// Medium ... + +// +#define mAtrBufferIndex 20 +double mAtrBuffer[]; + +// +#define mTrendBufferIndex 21 +double mTrendBuffer[]; + +// +#define mUpBufferIndex 22 +double mUpBuffer[]; + +// +#define mDownBufferIndex 23 +double mDownBuffer[]; + +// +#define mPriceBufferIndex 24 +double mPriceBuffer[]; + +// +// Long ... + +// +#define lAtrBufferIndex 25 +double lAtrBuffer[]; + +// +#define lTrendBufferIndex 26 +double lTrendBuffer[]; + +// +#define lUpBufferIndex 27 +double lUpBuffer[]; + +// +#define lDownBufferIndex 28 +double lDownBuffer[]; + +// +#define lPriceBufferIndex 29 +double lPriceBuffer[]; + +// +// Hind ... + +// +#define hAtrBufferIndex 30 +double hAtrBuffer[]; + +// +#define hTrendBufferIndex 31 +double hTrendBuffer[]; + +// +#define hUpBufferIndex 32 +double hUpBuffer[]; + +// +#define hDownBufferIndex 33 +double hDownBuffer[]; + +// +#define hPriceBufferIndex 34 +double hPriceBuffer[]; + +// +// Variables, Properties and etc ... + +// +int changeOfTrend; +int startBearishTrend; +int startBullishTrend; + +// +int maxLength; + +// +// Current ... +int mCSMLength = atrLength; +int mCAtrHandler = INVALID_HANDLE; + +// +// Short ... +int mSCLength = 0; +int mSSMLength = 0; +int mSAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCLength = 0; +int mMSMLength = 0; +int mMAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCLength = 0; +int mLSMLength = 0; +int mLAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCLength = 0; +int mHSMLength = 0; +int mHAtrHandler = INVALID_HANDLE; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + int numOfRequiredAtrs; + if (prev_calculated > rates_total || prev_calculated < 0) + { + numOfRequiredAtrs = rates_total; + } + else + { + // + numOfRequiredAtrs = rates_total - prev_calculated; + if (prev_calculated > 0) + { + numOfRequiredAtrs++; + } + } + + // + // Checking for stop ... + if (IsStopped()) + { + return 0; + } + + // + // Check Number of items Copy or not ... + int copiedCATRs = CopyBuffer(mCAtrHandler, 0, 0, numOfRequiredAtrs, cAtrBuffer); + int copiedSATRs = CopyBuffer(mSAtrHandler, 0, 0, numOfRequiredAtrs, sAtrBuffer); + int copiedMATRs = CopyBuffer(mMAtrHandler, 0, 0, numOfRequiredAtrs, mAtrBuffer); + int copiedLATRs = CopyBuffer(mLAtrHandler, 0, 0, numOfRequiredAtrs, lAtrBuffer); + int copiedHATRs = CopyBuffer(mHAtrHandler, 0, 0, numOfRequiredAtrs, hAtrBuffer); + if (copiedCATRs <= 0 || + copiedSATRs <= 0 || + copiedMATRs <= 0 || + copiedLATRs <= 0 || + copiedHATRs <= 0) + { + return 0; + } + + // + int limit; + + // + // checking for the limit start of calculation of an indicator ... + if (prev_calculated > rates_total || prev_calculated <= 0) + { + // + // starting index for calculation of all bars ... + limit = maxLength; + } + else + { + // + // starting number for calculation of new bars + limit = prev_calculated - 1; + } + + // + // Main Loop ... + for (int i = limit; i < rates_total && !IsStopped(); i++) + { + // + CalculateBuffers( + open, + high, + low, + close, + i // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + atrLength >= 2 && + atrMultiplier > 0 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + mCAtrHandler = iATR( + _Symbol, + _Period, + mCSMLength // + ); + result = mCAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSSMLength = mSCLength * mCSMLength; + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + mSAtrHandler = iATR( + _Symbol, + _Period, + mSSMLength // + ); + result = mSAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMSMLength = mMCLength * mCSMLength; + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + mMAtrHandler = iATR( + _Symbol, + _Period, + mMSMLength // + ); + result = mMAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLSMLength = mLCLength * mCSMLength; + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + mLAtrHandler = iATR( + _Symbol, + _Period, + mLSMLength // + ); + result = mLAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHSMLength = mHCLength * mCSMLength; + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + mHAtrHandler = iATR( + _Symbol, + _Period, + mHSMLength // + ); + result = mHAtrHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCSMLength, mSSMLength); + result = MathMax(result, mMSMLength); + result = MathMax(result, mLSMLength); + result = MathMax(result, mHSMLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // CURRENT Cycle ... + + // + // STR ... + SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(cPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(cAtrBufferIndex, cAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(cPriceBufferIndex, cPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(cTrendBufferIndex, cTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(cUpBufferIndex, cUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(cDownBufferIndex, cDownBuffer, INDICATOR_CALCULATIONS); + + // + // SHORT Cycle ... + + // + // STR ... + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(sPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(sAtrBufferIndex, sAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(sPriceBufferIndex, sPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(sTrendBufferIndex, sTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(sUpBufferIndex, sUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(sDownBufferIndex, sDownBuffer, INDICATOR_CALCULATIONS); + + // + // MEDIUM Cycle ... + + // + // STR ... + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(mPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(mAtrBufferIndex, mAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(mPriceBufferIndex, mPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(mTrendBufferIndex, mTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(mUpBufferIndex, mUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(mDownBufferIndex, mDownBuffer, INDICATOR_CALCULATIONS); + + // + // LONG Cycle ... + + // + // STR ... + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(lPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(lAtrBufferIndex, lAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(lPriceBufferIndex, lPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(lTrendBufferIndex, lTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(lUpBufferIndex, lUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(lDownBufferIndex, lDownBuffer, INDICATOR_CALCULATIONS); + + // + // HIND Cycle ... + + // + // STR ... + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA); + + // + // Color ... + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Bar Buffer ... + PlotIndexSetDouble(hPlotBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind); + + // + // Data Buffers ... + + // + // ATR ... + SetIndexBuffer(hAtrBufferIndex, hAtrBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + SetIndexBuffer(hPriceBufferIndex, hPriceBuffer, INDICATOR_CALCULATIONS); + + // + // Trend ... + SetIndexBuffer(hTrendBufferIndex, hTrendBuffer, INDICATOR_CALCULATIONS); + + // + // Up ... + SetIndexBuffer(hUpBufferIndex, hUpBuffer, INDICATOR_CALCULATIONS); + + // + // Down ... + SetIndexBuffer(hDownBufferIndex, hDownBuffer, INDICATOR_CALCULATIONS); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Hiken Ashi ... +void CalculateBuffers( + const double &open[], + const double &high[], + const double &low[], + const double &close[], + int barIndex // +) +{ + // + // Current ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + cAtrBuffer, + cPriceBuffer, + cUpBuffer, + cDownBuffer, + cTrendBuffer, + cBuffer, + cColorBuffer, + showCurrent // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + sAtrBuffer, + sPriceBuffer, + sUpBuffer, + sDownBuffer, + sTrendBuffer, + sBuffer, + sColorBuffer, + showShort // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + mAtrBuffer, + mPriceBuffer, + mUpBuffer, + mDownBuffer, + mTrendBuffer, + mBuffer, + mColorBuffer, + showMedium // + ); + + // + // Short ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + lAtrBuffer, + lPriceBuffer, + lUpBuffer, + lDownBuffer, + lTrendBuffer, + lBuffer, + lColorBuffer, + showLong // + ); + + // + // Hind ... + CalculateCycle( + open, + high, + low, + close, + barIndex, + hAtrBuffer, + hPriceBuffer, + hUpBuffer, + hDownBuffer, + hTrendBuffer, + hBuffer, + hColorBuffer, + showHind // + ); +} + +// +void CalculateCycle( + const double &open[], + const double &high[], + const double &low[], + const double &close[], + int barIndex, + double &atr[], + double &price[], + double &up[], + double &down[], + double &trend[], + double &main[], + double &clr[], // Color Index Buffer + bool show // +) +{ + // + // Calculated Price ... + double _price = getPrice( + atrAppliedTo, + open, + high, + low, + close, + barIndex // + ); + price[barIndex] = _price; + + // + double _atr = atr[barIndex]; + + // + // Up ... + up[barIndex] = _price + (atrMultiplier * _atr); + + // + // Down ... + down[barIndex] = _price - (atrMultiplier * _atr); + + // + if (close[barIndex] > up[barIndex - 1]) + { + // + trend[barIndex] = 1; + if (trend[barIndex - 1] == -1) + { + changeOfTrend = 1; + } + } + else if (close[barIndex] < down[barIndex - 1]) + { + // + trend[barIndex] = -1; + if (trend[barIndex - 1] == 1) + { + changeOfTrend = 1; + } + } + else if (trend[barIndex - 1] == 1) + { + // + trend[barIndex] = 1; + changeOfTrend = 0; + } + else if (trend[barIndex - 1] == -1) + { + // + trend[barIndex] = -1; + changeOfTrend = 0; + } + + // + // Down Trend Starting ... + if (trend[barIndex] < 0 && trend[barIndex - 1] > 0) + { + startBearishTrend = 1; + } + else + { + startBearishTrend = 0; + } + + // + // Up Trend Starting ... + if (trend[barIndex] > 0 && trend[barIndex - 1] < 0) + { + startBullishTrend = 1; + } + else + { + startBullishTrend = 0; + } + + // + if (trend[barIndex] > 0 && down[barIndex] < down[barIndex - 1]) + { + down[barIndex] = down[barIndex - 1]; + } + + // + if (trend[barIndex] < 0 && up[barIndex] > up[barIndex - 1]) + { + up[barIndex] = up[barIndex - 1]; + } + + // + if (startBearishTrend == 1) + { + up[barIndex] = price[barIndex] + (atrMultiplier * _atr); + } + + // + if (startBullishTrend == 1) + { + down[barIndex] = price[barIndex] - (atrMultiplier * _atr); + } + + // + double colorIDX = hideColorIDX; + clr[barIndex] = colorIDX; + + // + if (trend[barIndex] == 1) + { + // + main[barIndex] = down[barIndex]; + if (changeOfTrend == 1) + { + // + main[barIndex - 1] = main[barIndex - 2]; + changeOfTrend = 0; + } + + // + colorIDX = bullishColorIDX; + } + else if (trend[barIndex] == -1) + { + // + main[barIndex] = up[barIndex]; + if (changeOfTrend == 1) + { + // + main[barIndex - 1] = main[barIndex - 2]; + changeOfTrend = 0; + } + + // + colorIDX = bearishColorIDX; + } + + // + if (show) + { + clr[barIndex] = colorIDX; + } + + // +} + +// +// TEMPLATE Function ... + +template +double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i) +{ + switch (tprice) + { + case PRICE_CLOSE: + return (close[i]); + case PRICE_OPEN: + return (open[i]); + case PRICE_HIGH: + return (high[i]); + case PRICE_LOW: + return (low[i]); + case PRICE_MEDIAN: + return ((high[i] + low[i]) / 2.0); + case PRICE_TYPICAL: + return ((high[i] + low[i] + close[i]) / 3.0); + case PRICE_WEIGHTED: + return ((high[i] + low[i] + close[i] + close[i]) / 4.0); + } + return (0); +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchswings.mq5 b/Documents/BKP/Indicators/x-saherelm.xchswings.mq5 new file mode 100644 index 00000000..15c5c4ff --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchswings.mq5 @@ -0,0 +1,993 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHSwings +// Description: XCHSwings Detector ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHVWAP Indicator" +#property strict + +// +#define ShortName "XCHVWAP" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input int length = 12; // Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; +// +input bool showSwingHighs = true; // Show Swing Highs +input bool showSwingLows = true; // Show Swing Lows +// +input bool showCurrent = true; // Show Cycle Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +#property indicator_chart_window + +// +#property indicator_buffers 10 +#property indicator_plots 10 + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +// Current ... + +// +#define cSHBufferIndex 0 +double cSHBuffer[]; + +// +#property indicator_label1 "XCHVSwings CH" +#property indicator_type1 DRAW_ARROW +#property indicator_color1 clrMagenta +#property indicator_style1 STYLE_SOLID +#property indicator_width1 2 + +// +#define cSLBufferIndex 1 +double cSLBuffer[]; + +// +#property indicator_label2 "XCHVSwings CL" +#property indicator_type2 DRAW_ARROW +#property indicator_color2 clrAqua +#property indicator_style2 STYLE_SOLID +#property indicator_width2 2 + +// +// Short ... + +// +#define sSHBufferIndex 2 +double sSHBuffer[]; + +// +#property indicator_label3 "XCHVSwings SH" +#property indicator_type3 DRAW_ARROW +#property indicator_color3 clrMagenta +#property indicator_style3 STYLE_SOLID +#property indicator_width3 2 + +// +#define sSLBufferIndex 3 +double sSLBuffer[]; + +// +#property indicator_label4 "XCHVSwings SL" +#property indicator_type4 DRAW_ARROW +#property indicator_color4 clrAqua +#property indicator_style4 STYLE_SOLID +#property indicator_width4 2 + +// +// Medium ... + +// +#define mSHBufferIndex 4 +double mSHBuffer[]; + +// +#property indicator_label5 "XCHVSwings MH" +#property indicator_type5 DRAW_ARROW +#property indicator_color5 clrMagenta +#property indicator_style5 STYLE_SOLID +#property indicator_width5 2 + +// +#define mSLBufferIndex 5 +double mSLBuffer[]; + +// +#property indicator_label6 "XCHVSwings ML" +#property indicator_type6 DRAW_ARROW +#property indicator_color6 clrAqua +#property indicator_style6 STYLE_SOLID +#property indicator_width6 2 + +// +// Long ... + +// +#define lSHBufferIndex 6 +double lSHBuffer[]; + +// +#property indicator_label7 "XCHVSwings LH" +#property indicator_type7 DRAW_ARROW +#property indicator_color7 clrMagenta +#property indicator_style7 STYLE_SOLID +#property indicator_width7 2 + +// +#define lSLBufferIndex 7 +double lSLBuffer[]; + +// +#property indicator_label8 "XCHVSwings LL" +#property indicator_type8 DRAW_ARROW +#property indicator_color8 clrAqua +#property indicator_style8 STYLE_SOLID +#property indicator_width8 2 + +// +// Hind ... + +// +#define hSHBufferIndex 8 +double hSHBuffer[]; + +// +#property indicator_label9 "XCHVSwings HH" +#property indicator_type9 DRAW_ARROW +#property indicator_color9 clrMagenta +#property indicator_style9 STYLE_SOLID +#property indicator_width9 2 + +// +#define hSLBufferIndex 9 +double hSLBuffer[]; + +// +#property indicator_label10 "XCHVSwings HL" +#property indicator_type10 DRAW_ARROW +#property indicator_color10 clrAqua +#property indicator_style10 STYLE_SOLID +#property indicator_width10 2 + +// +// Variables ... + +// +int maxLength; + +// +// Cuurent ... +int mCMarketLength = length; + +// +double cH1 = 0; +double cL1 = 0; +datetime cH1Time = 0; +datetime cL1Time = 0; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +double sH1 = 0; +double sL1 = 0; +datetime sH1Time = 0; +datetime sL1Time = 0; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +double mH1 = 0; +double mL1 = 0; +datetime mH1Time = 0; +datetime mL1Time = 0; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +double lH1 = 0; +double lL1 = 0; +datetime lH1Time = 0; +datetime lL1Time = 0; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +double hH1 = 0; +double hL1 = 0; +datetime hH1Time = 0; +datetime hL1Time = 0; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + int start; + + // + if (prev_calculated == 0) + { + start = maxLength; + } + else + { + start = prev_calculated - 1; + } + + // + for (int i = start; i < rates_total - maxLength && !IsStopped(); i++) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + time, + open, + high, + close, + low, + tick_volume // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + + // Setting Indicator Digits + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + ENUM_DRAW_TYPE cSHDrawType = + showCurrent && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(cSHBufferIndex, cSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(cSHBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingHighs); + PlotIndexSetInteger(cSHBufferIndex, PLOT_DRAW_TYPE, cSHDrawType); + + // + ENUM_DRAW_TYPE cSLDrawType = + showCurrent && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(cSLBufferIndex, cSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(cSLBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingLows); + PlotIndexSetInteger(cSLBufferIndex, PLOT_DRAW_TYPE, cSLDrawType); + + // + // Short ... + + // + ENUM_DRAW_TYPE sSHDrawType = + showShort && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(sSHBufferIndex, sSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(sSHBufferIndex, PLOT_SHOW_DATA, showShort && showSwingHighs); + PlotIndexSetInteger(sSHBufferIndex, PLOT_DRAW_TYPE, sSHDrawType); + + // + ENUM_DRAW_TYPE sSLDrawType = + showShort && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(sSLBufferIndex, sSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(sSLBufferIndex, PLOT_SHOW_DATA, showShort && showSwingLows); + PlotIndexSetInteger(sSLBufferIndex, PLOT_DRAW_TYPE, sSLDrawType); + + // + // Medium ... + + // + ENUM_DRAW_TYPE mSHDrawType = + showMedium && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(mSHBufferIndex, mSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(mSHBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingHighs); + PlotIndexSetInteger(mSHBufferIndex, PLOT_DRAW_TYPE, mSHDrawType); + + // + ENUM_DRAW_TYPE mSLDrawType = + showMedium && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(mSLBufferIndex, mSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(mSLBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingLows); + PlotIndexSetInteger(mSLBufferIndex, PLOT_DRAW_TYPE, mSLDrawType); + + // + // Long ... + + // + ENUM_DRAW_TYPE lSHDrawType = + showLong && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(lSHBufferIndex, lSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(lSHBufferIndex, PLOT_SHOW_DATA, showLong && showSwingHighs); + PlotIndexSetInteger(lSHBufferIndex, PLOT_DRAW_TYPE, lSHDrawType); + + // + ENUM_DRAW_TYPE lSLDrawType = + showLong && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(lSLBufferIndex, lSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(lSLBufferIndex, PLOT_SHOW_DATA, showLong && showSwingLows); + PlotIndexSetInteger(lSLBufferIndex, PLOT_DRAW_TYPE, lSLDrawType); + + // + // Hind ... + + // + ENUM_DRAW_TYPE hSHDrawType = + showHind && showSwingHighs + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(hSHBufferIndex, hSHBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSHBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSHBufferIndex, PLOT_ARROW, 234); + PlotIndexSetInteger(hSHBufferIndex, PLOT_SHOW_DATA, showHind && showSwingHighs); + PlotIndexSetInteger(hSHBufferIndex, PLOT_DRAW_TYPE, hSHDrawType); + + // + ENUM_DRAW_TYPE hSLDrawType = + showHind && showSwingLows + ? DRAW_ARROW + : DRAW_NONE; + + // + SetIndexBuffer(hSLBufferIndex, hSLBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSLBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSLBufferIndex, PLOT_ARROW, 233); + PlotIndexSetInteger(hSLBufferIndex, PLOT_SHOW_DATA, showHind && showSwingLows); + PlotIndexSetInteger(hSLBufferIndex, PLOT_DRAW_TYPE, hSLDrawType); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const datetime &time[], + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + CalculateCycles( + // + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const datetime &time[], + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cSHBuffer, + cSLBuffer, + cH1, + cH1Time, + cL1, + cL1Time // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sSHBuffer, + sSLBuffer, + sH1, + sH1Time, + sL1, + sL1Time // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mSHBuffer, + mSLBuffer, + mH1, + mH1Time, + mL1, + mL1Time // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lSHBuffer, + lSLBuffer, + lH1, + lH1Time, + lL1, + lL1Time // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + // + time, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hSHBuffer, + hSLBuffer, + hH1, + hH1Time, + hL1, + hL1Time // + ); +} + +// +void CalculateCycle( + // + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + // + const datetime &time[], + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, // Calculation Length + bool _show, + double &_hBuffer[], + double &_lBuffer[], + double &_h1, + datetime &_h1Time, + double &_l1, + datetime &_l1Time // +) +{ + // + bool isSwingHigh = true; + bool isSwingLow = true; + + // + _hBuffer[bar_index] = 0; + _lBuffer[bar_index] = 0; + + // + // Check for Swing High + for (int j = 1; j <= _length; j++) + { + // + if (high[bar_index] <= high[bar_index + j] || high[bar_index] <= high[bar_index - j]) + { + // + isSwingHigh = false; + break; + } + } + + // + // Check for Swing Low + for (int j = 1; j <= _length; j++) + { + // + if (low[bar_index] >= low[bar_index + j] || low[bar_index] >= low[bar_index - j]) + { + // + isSwingLow = false; + break; + } + } + + // + if (isSwingHigh) + { + // + _hBuffer[bar_index] = high[bar_index]; + if (high[bar_index] > _h1 || _h1 == 0) + { + // + _h1 = high[bar_index]; + _h1Time = time[bar_index]; + } + } + + // + if (isSwingLow) + { + // + _lBuffer[bar_index] = low[bar_index]; + if (low[bar_index] < _l1 || _l1 == 0) + { + // + _l1 = low[bar_index]; + _l1Time = time[bar_index]; + } + } +} \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchtd.mq5 b/Documents/BKP/Indicators/x-saherelm.xchtd.mq5 new file mode 100644 index 00000000..86ec2b54 --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchtd.mq5 @@ -0,0 +1,900 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHTD +// Description: XCHTD Cycles ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHTD Indicator" +#property strict + +// +#define ShortName "XCHTD" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +enum ENUM_XCHTD_MODE +{ + XCHTD_POWER_MODE = 0, // Using Power + XCHTD_PRESSURE_MODE = 1, // Using Pressure + XCHTD_TYPE_MODE = 2, // Using Type + XCHTD_STRONG_MODE = 3, // Using Power and Pressures +}; + +// +// Inputs ... + +// +input group "Market"; +input int length = 14; // Length +input ENUM_XCHTD_MODE mode = XCHTD_POWER_MODE; // Mode + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// Current ... +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 10 +#property indicator_plots 0 + +// +// Current ... + +// +#define cBullBufferIndex 0 +double cBullBuffer[]; + +// +#property indicator_label1 "XCHTD C Bull" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID + +// +#define cBearBufferIndex 1 +double cBearBuffer[]; + +// +#property indicator_label2 "XCHTD C Bear" +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_SOLID +#property indicator_color2 clrRed + +// +// Short ... + +// +#define sBullBufferIndex 2 +double sBullBuffer[]; + +// +#property indicator_label3 "XCHTD S Bull" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrLime +#property indicator_style3 STYLE_SOLID + +// +#define sBearBufferIndex 3 +double sBearBuffer[]; + +// +#property indicator_label4 "XCHTD S Bear" +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_SOLID +#property indicator_color4 clrRed + +// +// Medium ... + +// +#define mBullBufferIndex 4 +double mBullBuffer[]; + +// +#property indicator_label5 "XCHTD M Bull" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrLime +#property indicator_style5 STYLE_SOLID + +// +#define mBearBufferIndex 5 +double mBearBuffer[]; + +// +#property indicator_label6 "XCHTD M Bear" +#property indicator_type6 DRAW_LINE +#property indicator_style6 STYLE_SOLID +#property indicator_color6 clrRed + +// +// Long ... + +// +#define lBullBufferIndex 6 +double lBullBuffer[]; + +// +#property indicator_label7 "XCHTD L Bull" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrLime +#property indicator_style7 STYLE_SOLID + +// +#define lBearBufferIndex 7 +double lBearBuffer[]; + +// +#property indicator_label8 "XCHTD L Bear" +#property indicator_type8 DRAW_LINE +#property indicator_style8 STYLE_SOLID +#property indicator_color8 clrRed + +// +// Hind ... + +// +#define hBullBufferIndex 8 +double hBullBuffer[]; + +// +#property indicator_label9 "XCHTD H Bull" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrLime +#property indicator_style9 STYLE_SOLID + +// +#define hBearBufferIndex 9 +double hBearBuffer[]; + +// +#property indicator_label10 "XCHTD H Bear" +#property indicator_type10 DRAW_LINE +#property indicator_style10 STYLE_SOLID +#property indicator_color10 clrRed + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + + // + limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated; + + // + // Main Loop ... + for (int i = limit; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + open, + high, + close, + low, + tick_volume // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(cBullBuffer, true); + SetIndexBuffer(cBullBufferIndex, cBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(cBullBufferIndex, PLOT_DRAW_TYPE, cDrawType); + // PlotIndexSetInteger(cBullBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + ArraySetAsSeries(cBearBuffer, true); + SetIndexBuffer(cBearBufferIndex, cBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(cBearBufferIndex, PLOT_DRAW_TYPE, cDrawType); + // PlotIndexSetInteger(cBearBufferIndex, PLOT_SHOW_DATA, showCurrent); + + // + // Short ... + + // + // ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(sBullBuffer, true); + SetIndexBuffer(sBullBufferIndex, sBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(sBullBufferIndex, PLOT_DRAW_TYPE, sDrawType); + // PlotIndexSetInteger(sBullBufferIndex, PLOT_SHOW_DATA, showShort); + + // + ArraySetAsSeries(sBearBuffer, true); + SetIndexBuffer(sBearBufferIndex, sBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(sBearBufferIndex, PLOT_DRAW_TYPE, sDrawType); + // PlotIndexSetInteger(sBearBufferIndex, PLOT_SHOW_DATA, showShort); + + // + // Medium ... + + // + // ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(mBullBuffer, true); + SetIndexBuffer(mBullBufferIndex, mBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(mBullBufferIndex, PLOT_DRAW_TYPE, mDrawType); + // PlotIndexSetInteger(mBullBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + ArraySetAsSeries(mBearBuffer, true); + SetIndexBuffer(mBearBufferIndex, mBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(mBearBufferIndex, PLOT_DRAW_TYPE, mDrawType); + // PlotIndexSetInteger(mBearBufferIndex, PLOT_SHOW_DATA, showMedium); + + // + // Long ... + + // + // ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(lBullBuffer, true); + SetIndexBuffer(lBullBufferIndex, lBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(lBullBufferIndex, PLOT_DRAW_TYPE, lDrawType); + // PlotIndexSetInteger(lBullBufferIndex, PLOT_SHOW_DATA, showLong); + + // + ArraySetAsSeries(lBearBuffer, true); + SetIndexBuffer(lBearBufferIndex, lBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(lBearBufferIndex, PLOT_DRAW_TYPE, lDrawType); + // PlotIndexSetInteger(lBearBufferIndex, PLOT_SHOW_DATA, showLong); + + // + // Hind ... + + // + // ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(hBullBuffer, true); + SetIndexBuffer(hBullBufferIndex, hBullBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(hBullBufferIndex, PLOT_DRAW_TYPE, hDrawType); + // PlotIndexSetInteger(hBullBufferIndex, PLOT_SHOW_DATA, showHind); + + // + ArraySetAsSeries(hBearBuffer, true); + SetIndexBuffer(hBearBufferIndex, hBearBuffer, INDICATOR_CALCULATIONS); + // PlotIndexSetInteger(hBearBufferIndex, PLOT_DRAW_TYPE, hDrawType); + // PlotIndexSetInteger(hBearBufferIndex, PLOT_SHOW_DATA, showHind); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cBullBuffer, + cBearBuffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sBullBuffer, + sBearBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mBullBuffer, + mBearBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lBullBuffer, + lBearBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hBullBuffer, + hBearBuffer // + ); +} + +// +void CalculateCycle( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, // Calculation Length + bool _show, + double &_bull[], + double &_bear[] // +) +{ + // + double bullPower = 0; + double bearPower = 0; + + // + double lowShadow = 0; + double highShadow = 0; + + // + double bullPressure = 0; + double bearPressure = 0; + + // + double bullRange = 0; + double bearRange = 0; + + // + for (int i = bar_index; i < bar_index + _length; i++) + { + // + bool isBullish = + // + close[i] > open[i] + // + ; + + // + bool isBearish = + // + close[i] < open[i] + // + ; + + // + double iUpper = MathMax(open[i], close[i]); + double iLower = MathMin(open[i], close[i]); + + // + double iBody = iUpper - iLower; + double iRange = high[i] - low[i]; + + // + double iHighShadow = high[i] - iUpper; + double iLowShadow = iLower - low[i]; + + // + if (isBullish) + { + // + bullPower += iBody; + bullRange += iRange; + bearPressure += iHighShadow; + } + else if (isBearish) + { + // + bearPower += iBody; + bearRange += iRange; + bullPressure += iLowShadow; + } + + // + lowShadow += iLowShadow; + highShadow += iHighShadow; + } + + // + if (mode == XCHTD_POWER_MODE) + { + // + _bull[bar_index] = bullPower; + _bear[bar_index] = bearPower; + } + else if (mode == XCHTD_PRESSURE_MODE) + { + // + _bull[bar_index] = bullPressure; + _bear[bar_index] = bearPressure; + } + else if (mode == XCHTD_TYPE_MODE) + { + // + _bull[bar_index] = bullRange; + _bear[bar_index] = bearRange; + } + else if (mode == XCHTD_STRONG_MODE) + { + // + _bull[bar_index] = bullPower + bullPressure; + _bear[bar_index] = bearPower + bearPressure; + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchvlm.mq5 b/Documents/BKP/Indicators/x-saherelm.xchvlm.mq5 new file mode 100644 index 00000000..dd1105e9 --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchvlm.mq5 @@ -0,0 +1,814 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHVLM +// Description: XCHVLM Cycles ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHVLM Indicator" +#property strict + +// +#define ShortName "XCHVLM" + +// +// Includes Common Library ... +#include +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 14; // Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 + +// +#property indicator_chart_window + +// +#property indicator_buffers 10 +#property indicator_plots 0 + +// +// Current ... + +// +#define cBufferIndex 0 +double cBuffer[]; + +// +#define cColorBufferIndex 1 +double cColorBuffer[]; + +// +#define cPlotBufferIndex 0 +#property indicator_label1 "XCHVLM C" +#property indicator_style1 STYLE_SOLID +#property indicator_type1 DRAW_COLOR_HISTOGRAM +#property indicator_color1 CLR_NONE, clrLime, clrRed + +// +// Short ... + +// +#define sBufferIndex 2 +double sBuffer[]; + +// +#define sColorBufferIndex 3 +double sColorBuffer[]; + +// +#define sPlotBufferIndex 1 +#property indicator_label2 "XCHVLM S" +#property indicator_style2 STYLE_SOLID +#property indicator_type2 DRAW_COLOR_HISTOGRAM +#property indicator_color2 CLR_NONE, clrLime, clrRed + +// +// Medium ... + +// +#define mBufferIndex 4 +double mBuffer[]; + +// +#define mColorBufferIndex 5 +double mColorBuffer[]; + +// +#define mPlotBufferIndex 2 +#property indicator_label3 "XCHVLM M" +#property indicator_style3 STYLE_SOLID +#property indicator_type3 DRAW_COLOR_HISTOGRAM +#property indicator_color3 CLR_NONE, clrLime, clrRed + +// +// Long ... + +// +#define lBufferIndex 6 +double lBuffer[]; + +// +#define lColorBufferIndex 7 +double lColorBuffer[]; + +// +#define lPlotBufferIndex 3 +#property indicator_label4 "XCHVLM L" +#property indicator_style4 STYLE_SOLID +#property indicator_type4 DRAW_COLOR_HISTOGRAM +#property indicator_color4 CLR_NONE, clrLime, clrRed + +// +// Hind ... + +// +#define hBufferIndex 8 +double hBuffer[]; + +// +#define hColorBufferIndex 9 +double hColorBuffer[]; + +// +#define hPlotBufferIndex 4 +#property indicator_label5 "XCHVLM H" +#property indicator_style5 STYLE_SOLID +#property indicator_type5 DRAW_COLOR_HISTOGRAM +#property indicator_color5 CLR_NONE, clrLime, clrRed + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; +double cVolumes[]; +double cDistances[]; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +double sVolumes[]; +double sDistances[]; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +double mVolumes[]; +double mDistances[]; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +double lVolumes[]; +double lDistances[]; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +double hVolumes[]; +double hDistances[]; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Current ... + ArrayResize(cVolumes, maxLength, 0); + ArrayResize(cDistances, maxLength, 0); + + // + // Short ... + ArrayResize(sVolumes, maxLength, 0); + ArrayResize(sDistances, maxLength, 0); + + // + // Medium ... + ArrayResize(mVolumes, maxLength, 0); + ArrayResize(mDistances, maxLength, 0); + + // + // Long ... + ArrayResize(lVolumes, maxLength, 0); + ArrayResize(lDistances, maxLength, 0); + + // + // Hind ... + ArrayResize(hVolumes, maxLength, 0); + ArrayResize(hDistances, maxLength, 0); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + Clean(cVolumes); + Clean(cDistances); + + // + Clean(sVolumes); + Clean(sDistances); + + // + Clean(mVolumes); + Clean(mDistances); + + // + Clean(lVolumes); + Clean(lDistances); + + // + Clean(hVolumes); + Clean(hDistances); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + static int i = maxLength * 2; + for (i; i < rates_total; i++) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume // + ); + } + + // + i = rates_total - 1; + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length >= 2 && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Current ... + + // + // ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(cPlotBufferIndex, PLOT_DRAW_TYPE, cDrawType); + // PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent); + // SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_CALCULATIONS); + + // + // Short ... + + // + // ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(sPlotBufferIndex, PLOT_DRAW_TYPE, sDrawType); + // PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort); + // SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_CALCULATIONS); + + // + // Medium ... + + // + // ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(mPlotBufferIndex, PLOT_DRAW_TYPE, mDrawType); + // PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium); + // SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_CALCULATIONS); + + // + // Long ... + + // + // ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(lPlotBufferIndex, PLOT_DRAW_TYPE, lDrawType); + // PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong); + // SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_CALCULATIONS); + + // + // Hind ... + + // + // ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_COLOR_HISTOGRAM : DRAW_NONE; + // PlotIndexSetInteger(hPlotBufferIndex, PLOT_DRAW_TYPE, hDrawType); + // PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind); + // SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_CALCULATIONS); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // CURRENT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + showCurrent, + cVolumes, + cDistances, + cBuffer, + cColorBuffer // + ); + + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + showShort, + sVolumes, + sDistances, + sBuffer, + sColorBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + showMedium, + mVolumes, + mDistances, + mBuffer, + mColorBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + showLong, + lVolumes, + lDistances, + lBuffer, + lColorBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + showHind, + hVolumes, + hDistances, + hBuffer, + hColorBuffer // + ); +} + +// +void CalculateCycle( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, // Calculation Length + bool _show, + double &_volumes[], + double &_distances[], + double &_buffer[], + double &_colorBuffer[] // +) +{ + // + for (int x = 0; x < _length; x++) + { + // + _volumes[x] = (double)tickVolume[bar_index - x]; + _distances[x] = + (close[bar_index - x] > open[bar_index - x]) + ? high[bar_index - x] - low[bar_index - x] + : low[bar_index - x] - high[bar_index - x]; + } + + // + double iValue = MathMean(_volumes) * MathMean(_distances); + + // + _buffer[bar_index] = iValue; + _colorBuffer[bar_index] = iValue > 0 + ? _show + ? bullishColorIDX + : hideColorIDX + : _show + ? bearishColorIDX + : hideColorIDX; +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xchvwap.mq5 b/Documents/BKP/Indicators/x-saherelm.xchvwap.mq5 new file mode 100644 index 00000000..b98fafcf --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xchvwap.mq5 @@ -0,0 +1,830 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHVWAP +// Description: XCHVWAP Trend Detector ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHVWAP Indicator" +#property strict + +// +#define ShortName "XCHVWAP" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 14 +#property indicator_plots 8 + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 +#define neuturalColorIDX 3 + +// +// Short ... + +// +#define sBufferIndex 0 +double sBuffer[]; + +// +#define sColorBufferIndex 1 +double sColorBuffer[]; + +// +#define sPlotBufferIndex 0 +#property indicator_label1 "XCHVWAP S" +#property indicator_type1 DRAW_COLOR_LINE +#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Medium ... + +// +#define mBufferIndex 2 +double mBuffer[]; + +// +#define mColorBufferIndex 3 +double mColorBuffer[]; + +// +#define mPlotBufferIndex 1 +#property indicator_label2 "XCHVWAP M" +#property indicator_type2 DRAW_COLOR_LINE +#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Long ... + +// +#define lBufferIndex 4 +double lBuffer[]; + +// +#define lColorBufferIndex 5 +double lColorBuffer[]; + +// +#define lPlotBufferIndex 2 +#property indicator_label3 "XCHVWAP L" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Hind ... + +// +#define hBufferIndex 6 +double hBuffer[]; + +// +#define hColorBufferIndex 7 +double hColorBuffer[]; + +// +#define hPlotBufferIndex 3 +#property indicator_label4 "XCHVWAP H" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrGreen, clrRed, clrGray +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Data Buffers ... + +// +// Volumes ... +#define volumeBufferIndex 8 +double volumeBuffer[]; + +// +// Price ... +#define priceBufferIndex 9 +double priceBuffer[]; + +// +// SHORT ... +#define sStateBufferIndex 10 +double sStateBuffer[]; + +// +// MEDIUM ... +#define mStateBufferIndex 11 +double mStateBuffer[]; + +// +// LONG ... +#define lStateBufferIndex 12 +double lStateBuffer[]; + +// +// HIND ... +#define hStateBufferIndex 13 +double hStateBuffer[]; + +// +// Variables ... + +// +int maxLength; + +// +// Short ... +int mSCycleLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// EVENT Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(low, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + + // + // this counts Available Bars ... + int limit; + + // + limit = + (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume // + ); + } + + // + return rates_total; +} + +// +// CUSTOM Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // Short ... + + // + ArraySetAsSeries(sBuffer, true); + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Medium ... + + // + ArraySetAsSeries(mBuffer, true); + ArraySetAsSeries(mColorBuffer, true); + SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA); + SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Long ... + + // + ArraySetAsSeries(lBuffer, true); + ArraySetAsSeries(lColorBuffer, true); + SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA); + SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Hind ... + + // + ArraySetAsSeries(hBuffer, true); + ArraySetAsSeries(hColorBuffer, true); + SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA); + SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Data Buffers ... + + // + // Volumes ... + ArraySetAsSeries(volumeBuffer, true); + SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS); + + // + // Price ... + ArraySetAsSeries(priceBuffer, true); + SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS); + + // + // Short State ... + ArraySetAsSeries(sStateBuffer, true); + SetIndexBuffer(sStateBufferIndex, sStateBuffer, INDICATOR_CALCULATIONS); + + // + // Medium State ... + ArraySetAsSeries(mStateBuffer, true); + SetIndexBuffer(mStateBufferIndex, mStateBuffer, INDICATOR_CALCULATIONS); + + // + // Long State ... + ArraySetAsSeries(lStateBuffer, true); + SetIndexBuffer(lStateBufferIndex, lStateBuffer, INDICATOR_CALCULATIONS); + + // + // Hind State ... + ArraySetAsSeries(hStateBuffer, true); + SetIndexBuffer(hStateBufferIndex, hStateBuffer, INDICATOR_CALCULATIONS); +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mSCycleLength, mMCycleLength); + result = MathMax(result, mLCycleLength); + result = MathMax(result, mHCycleLength); + + // + return result; +} + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // Calculate Volumes and Price ... + + // + if (ratesTotal - bar_index <= maxLength) + { + // + CalculateDataBuffers( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + return; + } + + // + CalculateDataBuffers( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateDataBuffers( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + double price = GetAppliedPrice( + appliedTo, + open, + high, + low, + close, + bar_index // + ); + priceBuffer[bar_index] = price; + volumeBuffer[bar_index] = (double)tickVolume[bar_index]; +} + +// +void CalculateCycles( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // SHORT ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mSCycleLength, + showShort, + sBuffer, + sColorBuffer, + sStateBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mMCycleLength, + showMedium, + mBuffer, + mColorBuffer, + mStateBuffer // + ); + + // + // LONG ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mLCycleLength, + showLong, + lBuffer, + lColorBuffer, + lStateBuffer // + ); + + // + // HIND ... + CalculateCycle( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume, + // + mHCycleLength, + showHind, + hBuffer, + hColorBuffer, + hStateBuffer // + ); +} + +// +void CalculateCycle( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[], + // + int _length, // Calculation Length + bool _show, + double &_buffer[], + double &_colorBuffer[], + double &_stateBuffer[] // +) +{ + // + double vSum = 0; + double pSum = 0; + double mSum = 0; + for (int x = 0; x < _length; x++) + { + // + pSum += priceBuffer[x + bar_index]; + vSum += volumeBuffer[x + bar_index]; + mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index]; + } + + // + double iValue = mSum / vSum; + iValue = NormalizeDouble(iValue, _Digits); + + // + _buffer[bar_index] = iValue; + + // + bool isBullish = low[bar_index] > iValue; + bool isBearish = high[bar_index] < iValue; + + // + double iColor = + isBullish + ? bullishColorIDX + : isBearish + ? bearishColorIDX + : neuturalColorIDX; + + // + _colorBuffer[bar_index] = hideColorIDX; + _stateBuffer[bar_index] = iColor; + if (_show) + { + _colorBuffer[bar_index] = iColor; + } +} + +// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.xct.mq5 b/Documents/BKP/Indicators/x-saherelm.xct.mq5 new file mode 100644 index 00000000..92fbb28b --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xct.mq5 @@ -0,0 +1,270 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// --------------------------------------------- +// Name: XCT +// Description: Trend Magic Indicator ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCT Indicator" +#property strict + +// +// START Constants ... +// + +// +#define ShortName "XCT" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// END Constants ... +// + +// +// START Inputs ... +// + +// +input color clr = clrYellow; // Text Color +input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position + +// +input group "Presentation"; +input bool showCandleTime = true; // Show Candle Time + +// +// END Inputs ... +// + +// +// START Buffers ... +// + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + +// +// END Buffers ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// + +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// START Event Handlers ... +// + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (showCandleTime) + { + CreateIndicatorObject(); + } + else + { + ObjectDelete(0, ShortName); + } + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + ulong chID = FindChartID( + _Symbol, + _Period + // + ); + + // + // Delete Object ... + ObjectDelete(chID, ShortName); + + // + Comment(""); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(time, true); + + // + if (!showCandleTime) + { + return rates_total; + } + + // + ulong chID = FindChartID( + _Symbol, + _Period + // + ); + + // + XBarRemainsTime barRemains; + barRemains.Init( + _Symbol, + _Period + // + ); + + // + string msg = barRemains + .ToString( + "", + "", + "", + "", + "", + ":", + true + // + ); + + // + long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD); + + // + string _sp = ""; + if (mSpread < 10) + _sp = ".."; + else if (mSpread < 100) + _sp = "."; + + // + // int offset = TimeGMTOffset(); + // string timeString = + // ", Time: " + string(TimeCurrent()) + "\n" + + // ", ServerTime: " + string(TimeTradeServer()) + "\n" + + // ", GMT Offset: " + (string)offset; + // timeString = timeString; + // Comment(timeString); + + // + string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg; + + // + ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr); + ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText); + ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10); + ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier"); + + // + return rates_total; +} + +// +// END Event Handlers ... +// + +// +// START Functions ... +// + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +void CreateIndicatorObject() +{ + // + if (!showCandleTime) + { + return; + } + + // + ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0); + ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner); + ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10); + ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2); + + // + ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER; + switch (corner) + { + case CORNER_LEFT_UPPER: + Anchor = ANCHOR_LEFT_UPPER; + break; + case CORNER_RIGHT_UPPER: + Anchor = ANCHOR_RIGHT_UPPER; + break; + case CORNER_LEFT_LOWER: + Anchor = ANCHOR_LEFT_LOWER; + break; + case CORNER_RIGHT_LOWER: + Anchor = ANCHOR_RIGHT_LOWER; + break; + } + + // + ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor); +} + +// +// END Functions ... +// diff --git a/Documents/BKP/Indicators/x-saherelm.xpv.mq5 b/Documents/BKP/Indicators/x-saherelm.xpv.mq5 new file mode 100644 index 00000000..e15924df --- /dev/null +++ b/Documents/BKP/Indicators/x-saherelm.xpv.mq5 @@ -0,0 +1,1289 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XPV +// Description: Peaks and Vales ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XPV Indicator" +#property strict + +// +// Definitions ... + +// +#define ShortName "XPV" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Makret Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Fibonacci"; +input double fiboLevel1 = 0.236; // Fibio 1st Level +input double fiboLevel2 = 0.382; // Fibio 2st Level +input double fiboLevel3 = 0.5; // Fibio 3rd Level +input double fiboLevel4 = 0.618; // Fibio 4th Level +input double fiboLevel5 = 0.764; // Fibio 5th Level + +// +input group "Boundary Detection Modes"; +input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method +input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method + +// +input group "Presentation"; +input bool showPeaksAndVales = true; // Show Peaks and Vales +input bool showLevels = false; // Show Levels +input bool showConsolidations = false; // Show Consolidations +input bool showFibo1Levels = false; // Show Fibo 1st Level +input bool showFibo2Levels = false; // Show Fibo 2nd Level +input bool showFibo3Levels = false; // Show Fibo 3rd Level +input bool showFibo4Levels = false; // Show Fibo 4th Level +input bool showFibo5Levels = false; // Show Fibo 5th Level + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 32 +#property indicator_plots 32 + +// +// PEAKS ... + +// +#define peaksBufferIndex 0 +double peaksBuffer[]; + +// +#property indicator_label1 "XPV PEAKS" +#property indicator_type1 DRAW_ARROW +#property indicator_color1 clrAqua +#property indicator_width1 1 + +// +// VALES ... + +// +#define valesBufferIndex 1 +double valesBuffer[]; + +// +#property indicator_label2 "XPV VALES" +#property indicator_type2 DRAW_ARROW +#property indicator_color2 clrMagenta +#property indicator_width2 1 + +// +#define rBufferIndex 2 +double rBuffer[]; + +// +#define rColorBufferIndex 3 +double rColorBuffer[]; + +// +#property indicator_label3 "XPV R" +#property indicator_type3 DRAW_COLOR_LINE +#property indicator_color3 CLR_NONE, clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +#define sBufferIndex 4 +#define sBufferPlotIndex 3 +double sBuffer[]; + +// +#define sColorBufferIndex 5 +double sColorBuffer[]; + +// +#property indicator_label4 "XPV S" +#property indicator_type4 DRAW_COLOR_LINE +#property indicator_color4 CLR_NONE, clrMagenta +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// FIBBO Level 1 ... + +// +#define fl1BufferIndex 6 +#define fl1BufferPlotIndex 4 +double fl1Buffer[]; + +// +#define fl1ColorBufferIndex 7 +double fl1ColorBuffer[]; + +// +#property indicator_label5 "XPV FL1" +#property indicator_type5 DRAW_COLOR_LINE +#property indicator_color5 CLR_NONE, clrGold +#property indicator_style5 STYLE_DASHDOTDOT +#property indicator_width5 1 + +// +// FIBBO Level 2 ... + +// +#define fl2BufferIndex 8 +#define fl2BufferPlotIndex 5 +double fl2Buffer[]; + +// +#define fl2ColorBufferIndex 9 +double fl2ColorBuffer[]; + +// +#property indicator_label6 "XPV FL2" +#property indicator_type6 DRAW_COLOR_LINE +#property indicator_color6 CLR_NONE, clrGold +#property indicator_style6 STYLE_DASHDOTDOT +#property indicator_width6 1 + +// +// FIBBO Level 3 ... + +// +#define fl3BufferIndex 10 +#define fl3BufferPlotIndex 6 +double fl3Buffer[]; + +// +#define fl3ColorBufferIndex 11 +double fl3ColorBuffer[]; + +// +#property indicator_label7 "XPV FL3" +#property indicator_type7 DRAW_COLOR_LINE +#property indicator_color7 CLR_NONE, clrGold +#property indicator_style7 STYLE_DASHDOTDOT +#property indicator_width7 1 + +// +// FIBBO Level 4 ... + +// +#define fl4BufferIndex 12 +#define fl4BufferPlotIndex 7 +double fl4Buffer[]; + +// +#define fl4ColorBufferIndex 13 +double fl4ColorBuffer[]; + +// +#property indicator_label8 "XPV FL4" +#property indicator_type8 DRAW_COLOR_LINE +#property indicator_color8 CLR_NONE, clrGold +#property indicator_style8 STYLE_DASHDOTDOT +#property indicator_width8 1 + +// +// FIBBO Level 5 ... + +// +#define fl5BufferIndex 14 +#define fl5BufferPlotIndex 8 +double fl5Buffer[]; + +// +#define fl5ColorBufferIndex 15 +double fl5ColorBuffer[]; + +// +#property indicator_label9 "XPV FL5" +#property indicator_type9 DRAW_COLOR_LINE +#property indicator_color9 CLR_NONE, clrGold +#property indicator_style9 STYLE_DASHDOTDOT +#property indicator_width9 1 + +// +// LEVELS ... + +// +#define scHHBufferIndex 16 +#define scHHBufferPlotIndex 9 +double scHHBuffer[]; + +// +#define scHHColorBufferIndex 17 +double scHHColorBuffer[]; + +// +#property indicator_label10 "XPV SHH" +#property indicator_type10 DRAW_COLOR_LINE +#property indicator_color10 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +#define scLLBufferIndex 18 +#define scLLBufferPlotIndex 10 +double scLLBuffer[]; + +// +#define scLLColorBufferIndex 19 +double scLLColorBuffer[]; + +// +#property indicator_label11 "XPV SLL" +#property indicator_type11 DRAW_COLOR_LINE +#property indicator_color11 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +#define mcHHBufferIndex 20 +#define mcHHBufferPlotIndex 11 +double mcHHBuffer[]; + +// +#define mcHHColorBufferIndex 21 +double mcHHColorBuffer[]; + +// +#property indicator_label12 "XPV MHH" +#property indicator_type12 DRAW_COLOR_LINE +#property indicator_color12 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +#define mcLLBufferIndex 22 +#define mcLLBufferPlotIndex 12 +double mcLLBuffer[]; + +// +#define mcLLColorBufferIndex 23 +double mcLLColorBuffer[]; + +// +#property indicator_label13 "XPV MLL" +#property indicator_type13 DRAW_COLOR_LINE +#property indicator_color13 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style13 STYLE_DOT +#property indicator_width13 1 + +// +#define lcHHBufferIndex 24 +#define lcHHBufferPlotIndex 13 +double lcHHBuffer[]; + +// +#define lcHHColorBufferIndex 25 +double lcHHColorBuffer[]; + +// +#property indicator_label14 "XPV LHH" +#property indicator_type14 DRAW_COLOR_LINE +#property indicator_color14 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style14 STYLE_DOT +#property indicator_width14 1 + +// +#define lcLLBufferIndex 26 +#define lcLLBufferPlotIndex 14 +double lcLLBuffer[]; + +// +#define lcLLColorBufferIndex 27 +double lcLLColorBuffer[]; + +// +#property indicator_label15 "XPV LLL" +#property indicator_type15 DRAW_COLOR_LINE +#property indicator_color15 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style15 STYLE_DOT +#property indicator_width15 1 + +// +#define hcHHBufferIndex 28 +#define hcHHBufferPlotIndex 15 +double hcHHBuffer[]; + +// +#define hcHHColorBufferIndex 29 +double hcHHColorBuffer[]; + +// +#property indicator_label16 "XPV HHH" +#property indicator_type16 DRAW_COLOR_LINE +#property indicator_color16 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style16 STYLE_DOT +#property indicator_width16 1 + +// +#define hcLLBufferIndex 30 +#define hcLLBufferPlotIndex 16 +double hcLLBuffer[]; + +// +#define hcLLColorBufferIndex 31 +double hcLLColorBuffer[]; + +// +#property indicator_label17 "XPV HLL" +#property indicator_type17 DRAW_COLOR_LINE +#property indicator_color17 CLR_NONE, clrLightGray, clrAqua, clrMagenta +#property indicator_style17 STYLE_DOT +#property indicator_width17 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +double mHideColorIDX = 0; + +// +// XMarketCycle sc; +int mSCLength = 0; +double mLastSCHH = 0; +double mLastSCLL = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// XMarketCycle mc; +int mMCLength = 0; +double mLastMCHH = 0; +double mLastMCLL = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// XMarketCycle lc; +int mLCLength = 0; +double mLastLCHH = 0; +double mLastLCLL = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// XMarketCycle hc; +int mHCLength = 0; +double mLastHCHH = 0; +double mLastHCLL = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +double lastPeak = 0; +double lastVale = 0; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... + // +) +{ + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // this counts Available Bars ... + int limit; + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mSCLength, mMCLength); + result = MathMax(result, mLCLength); + result = MathMax(result, mHCLength); + + // + return result; +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // PEAKS and VALES ... + ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; + + // + // PEAKS ... + ArraySetAsSeries(peaksBuffer, true); + SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA); + PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225); + PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); + PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + // VALES ... + ArraySetAsSeries(valesBuffer, true); + SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA); + PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225); + PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); + PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + // SUPPORT and RESISTANCE ... + // + + // + // RESISTANCE ... + ArraySetAsSeries(rBuffer, true); + SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA); + PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength); + + // + // RESISTANCE Color ... + ArraySetAsSeries(rColorBuffer, true); + SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX); + + // + // SUPPORT ... + ArraySetAsSeries(sBuffer, true); + SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA); + PlotIndexSetInteger(sBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false); + + // + // SUPPORT Color ... + ArraySetAsSeries(sColorBuffer, true); + SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX); + + // + // FIBBO Levels ... + + // + // LEVEL 1 ... + + // + // Buffer ... + ArraySetAsSeries(fl1Buffer, true); + SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl1BufferPlotIndex, PLOT_SHOW_DATA, showFibo1Levels); + + // + // Color ... + ArraySetAsSeries(fl1ColorBuffer, true); + SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 2 ... + + // + // Buffer ... + ArraySetAsSeries(fl2Buffer, true); + SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl2BufferPlotIndex, PLOT_SHOW_DATA, showFibo2Levels); + + // + // Color ... + ArraySetAsSeries(fl2ColorBuffer, true); + SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 3 ... + + // + // Buffer ... + ArraySetAsSeries(fl3Buffer, true); + SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl3BufferPlotIndex, PLOT_SHOW_DATA, showFibo3Levels); + + // + // Color ... + ArraySetAsSeries(fl3ColorBuffer, true); + SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 4 ... + + // + // Buffer ... + ArraySetAsSeries(fl4Buffer, true); + SetIndexBuffer(fl4BufferIndex, fl4Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl4BufferPlotIndex, PLOT_SHOW_DATA, showFibo4Levels); + + // + // Color ... + ArraySetAsSeries(fl4ColorBuffer, true); + SetIndexBuffer(fl4ColorBufferIndex, fl4ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LEVEL 5 ... + + // + // Buffer ... + ArraySetAsSeries(fl5Buffer, true); + SetIndexBuffer(fl5BufferIndex, fl5Buffer, INDICATOR_DATA); + PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(fl5BufferPlotIndex, PLOT_SHOW_DATA, showFibo5Levels); + + // + // Color ... + ArraySetAsSeries(fl5ColorBuffer, true); + SetIndexBuffer(fl5ColorBufferIndex, fl5ColorBuffer, INDICATOR_COLOR_INDEX); + + // + // SHORT Buffers ... + + // + // HIGH ... + ArraySetAsSeries(scHHBuffer, true); + SetIndexBuffer(scHHBufferIndex, scHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(scHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(scHHColorBuffer, true); + SetIndexBuffer(scHHColorBufferIndex, scHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(scLLBuffer, true); + SetIndexBuffer(scLLBufferIndex, scLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(scLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(scLLColorBuffer, true); + SetIndexBuffer(scLLColorBufferIndex, scLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // MEDIUM Buffer ... + + // + // HIGH ... + ArraySetAsSeries(mcHHBuffer, true); + SetIndexBuffer(mcHHBufferIndex, mcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(mcHHColorBuffer, true); + SetIndexBuffer(mcHHColorBufferIndex, mcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(mcLLBuffer, true); + SetIndexBuffer(mcLLBufferIndex, mcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(mcLLColorBuffer, true); + SetIndexBuffer(mcLLColorBufferIndex, mcLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LONG Buffer ... + + // + // HIGH ... + ArraySetAsSeries(lcHHBuffer, true); + SetIndexBuffer(lcHHBufferIndex, lcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(lcHHColorBuffer, true); + SetIndexBuffer(lcHHColorBufferIndex, lcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(lcLLBuffer, true); + SetIndexBuffer(lcLLBufferIndex, lcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(lcLLColorBuffer, true); + SetIndexBuffer(lcLLColorBufferIndex, lcLLColorBuffer, INDICATOR_COLOR_INDEX); + + // + // HIND Buffer ... + + // + // HIGH ... + ArraySetAsSeries(hcHHBuffer, true); + SetIndexBuffer(hcHHBufferIndex, hcHHBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hcHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(hcHHColorBuffer, true); + SetIndexBuffer(hcHHColorBufferIndex, hcHHColorBuffer, INDICATOR_COLOR_INDEX); + + // + // LOW ... + ArraySetAsSeries(hcLLBuffer, true); + SetIndexBuffer(hcLLBufferIndex, hcLLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hcLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels); + + // + ArraySetAsSeries(hcLLColorBuffer, true); + SetIndexBuffer(hcLLColorBufferIndex, hcLLColorBuffer, INDICATOR_COLOR_INDEX); +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Calculate Buffers ... +void CalculateBuffers( + int bar_index // Selected Bar Index +) +{ + // + // Calculate Cycles ... + CalculateCycles(bar_index); + + // + // Calculate Peaks and Vales ... + CalculatePeaksAndVales(bar_index); + + // + // Calculate Fibonnaci ... + CalculateFibonacci(bar_index); +} + +// +// Custom ... + +// +// Initial Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + if (IsValid(mSCPeriod)) + { + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + if (IsValid(mMCPeriod)) + { + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + if (IsValid(mLCPeriod)) + { + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + if (IsValid(mHCPeriod)) + { + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + } + + // + result = mSCLength > 0 && + mMCLength > mSCLength && + mLCLength > mMCLength && + mHCLength > mLCLength; + + // + return result; +} + +// +// Calculate Specified Cycles HH and LL ... +void CalculateCycle( + int barIndex, + ENUM_X_MARKET_CYCLES cycle, + double &lastHH, + double &hhBuffer[], + double &hhColorBuffer[], + double &lastLL, + double &llBuffer[], + double &llColorBuffer[] // +) +{ + // + XOHCL bar; + bar.Init( + _Symbol, + _Period, + barIndex + // + ); + + // + int mLength = 0; + switch (cycle) + { + // + case X_MARKET_CYCLE_SHORT: + mLength = mSCLength; + break; + + // + case X_MARKET_CYCLE_MEDIUM: + mLength = mMCLength; + break; + + // + case X_MARKET_CYCLE_LONG: + mLength = mLCLength; + break; + + // + case X_MARKET_CYCLE_HIND: + mLength = mHCLength; + break; + } + + // + if (mLength <= 0) + { + return; + } + + // + double hhValue = bar.FindHighest( + mLength, + hhMode + // + ); + hhBuffer[barIndex] = hhValue; + + // + double hhColorIDX = + !showLevels + ? mHideColorIDX + : (hhValue == lastHH) + ? !showConsolidations + ? mHideColorIDX + : 1 + : hhValue > lastHH + ? 2 + : hhValue < lastHH + ? 3 + : mHideColorIDX; + hhColorBuffer[barIndex] = hhColorIDX; + + // + lastHH = hhValue; + + // + double llValue = bar.FindLowest( + mLength, + llMode + // + ); + llBuffer[barIndex] = llValue; + + // + double llColorIDX = + !showLevels + ? mHideColorIDX + : (llValue == lastLL) + ? !showConsolidations + ? mHideColorIDX + : 1 + : llValue > lastLL + ? 2 + : llValue < lastLL + ? 3 + : mHideColorIDX; + llColorBuffer[barIndex] = llColorIDX; + + // + lastLL = llValue; +} + +// +// Calculate Cycles Up and Down Boundaries ... +void CalculateCycles( + int barIndex // Bar Index +) +{ + // + // Short ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_SHORT, + // + mLastSCHH, + scHHBuffer, + scHHColorBuffer, + // + mLastSCLL, + scLLBuffer, + scLLColorBuffer + // + ); + + // + // Medium ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_MEDIUM, + // + mLastMCHH, + mcHHBuffer, + mcHHColorBuffer, + // + mLastMCLL, + mcLLBuffer, + mcLLColorBuffer + // + ); + + // + // Long ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_LONG, + // + mLastLCHH, + lcHHBuffer, + lcHHColorBuffer, + // + mLastLCLL, + lcLLBuffer, + lcLLColorBuffer + // + ); + + // + // Hind ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_HIND, + // + mLastHCHH, + hcHHBuffer, + hcHHColorBuffer, + // + mLastHCLL, + hcLLBuffer, + hcLLColorBuffer + // + ); +} + +// +// Calculate Peaks and Values ... +void CalculatePeaksAndVales( + int barIndex // Bar Index +) +{ + // + // Retrieve Requirements ... + + // + // Short ... + double scHHValue = scHHBuffer[barIndex]; + double scLLValue = scLLBuffer[barIndex]; + + // + // Medium ... + double mcHHValue = mcHHBuffer[barIndex]; + double mcLLValue = mcLLBuffer[barIndex]; + + // + // Long ... + double lcHHValue = lcHHBuffer[barIndex]; + double lcLLValue = lcLLBuffer[barIndex]; + + // + // Hind ... + double hcHHValue = hcHHBuffer[barIndex]; + double hcLLValue = hcLLBuffer[barIndex]; + + // + double rColorIDX = mHideColorIDX; + double sColorIDX = mHideColorIDX; + + // + // RESISTANCE ... + double rValue = (scHHValue + mcHHValue + lcHHValue + hcHHValue) / 4; + + // + // PEAKS ... + bool isPeak = rValue == hcHHValue && + hcHHValue == lcHHValue && + lcHHValue == mcHHValue && + mcHHValue == scHHValue; + + // + if (isPeak && lastPeak != rValue) + { + // + rColorIDX = 1; + lastPeak = rValue; + } + + // + // SUPPORT ... + double sValue = (scLLValue + mcLLValue + lcLLValue + hcLLValue) / 4; + + // + // VALES ... + bool isVale = sValue == hcLLValue && + hcLLValue == lcLLValue && + lcLLValue == mcLLValue && + mcLLValue == scLLValue; + + // + if (isVale && lastVale != sValue) + { + // + sColorIDX = 1; + + // + lastVale = sValue; + } + + // + rBuffer[barIndex] = rValue; + sBuffer[barIndex] = sValue; + peaksBuffer[barIndex] = lastPeak; + valesBuffer[barIndex] = lastVale; + + // + if (showPeaksAndVales) + { + // + rColorBuffer[barIndex] = rColorIDX; + sColorBuffer[barIndex] = sColorIDX; + } + else + { + // + rColorBuffer[barIndex] = mHideColorIDX; + sColorBuffer[barIndex] = mHideColorIDX; + } +} + +// +// Calculate Fibonacci Level 1 ... +void CalculateFibonacci( + int barIndex // Bar Index +) +{ + // + // Select Requirements ... + double upPrice = peaksBuffer[barIndex]; + double downPrice = valesBuffer[barIndex]; + + // + // Level 1 ... + double fibLevel1Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel1, + 1); + // + // Level 2 ... + double fibLevel2Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel2, + 1); + + // + // Level 3 ... + double fibLevel3Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel3, + 1); + + // + // Level 4 ... + double fibLevel4Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel4, + 1); + + // + // Level 5 ... + double fibLevel5Value = GetFibonacciLevel( + upPrice, + downPrice, + fiboLevel5, + 1); + + // + fl1Buffer[barIndex] = fibLevel1Value; + fl2Buffer[barIndex] = fibLevel2Value; + fl3Buffer[barIndex] = fibLevel3Value; + fl4Buffer[barIndex] = fibLevel4Value; + fl5Buffer[barIndex] = fibLevel5Value; + + // + double fl1ColorIdx = showFibo1Levels ? 1 : mHideColorIDX; + double fl2ColorIdx = showFibo2Levels ? 1 : mHideColorIDX; + double fl3ColorIdx = showFibo3Levels ? 1 : mHideColorIDX; + double fl4ColorIdx = showFibo4Levels ? 1 : mHideColorIDX; + double fl5ColorIdx = showFibo5Levels ? 1 : mHideColorIDX; + + // + fl1ColorBuffer[barIndex] = fl1ColorIdx; + fl2ColorBuffer[barIndex] = fl2ColorIdx; + fl3ColorBuffer[barIndex] = fl3ColorIdx; + fl4ColorBuffer[barIndex] = fl4ColorIdx; + fl5ColorBuffer[barIndex] = fl5ColorIdx; +} + +// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.test.strategy.class copy 3.mq5 b/Documents/BKP/x-121.smc.test.strategy.class copy 3.mq5 new file mode 100644 index 0000000000000000000000000000000000000000..c0a6969581a64850a25d4067abd792be7d1a69d9 GIT binary patch literal 75924 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 literal 0 HcmV?d00001 diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index ad448168..9e887987 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -248,7 +248,7 @@ void OnStopLossTriggered(const XDeal &deal) */ void OnTakeProfitTriggered(const XDeal &deal) { - eaExpert.HandleOnTakeProfitTriggered(deal); + eaExpert.HandleOnTakeProfitTriggered(deal); } /** diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index a42109f0..07be190c 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -1915,6 +1915,50 @@ bool IsBetween( return result; } +/** + * Check Zone for Refining ... + * + * @param source: XZone instance ... + * @param dest: XZone instance ... + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ +bool CanRefineZone( + XZone &source, + XZone &dest, + XOHCL &bar // +) +{ + // + bool result = false; + + // + result = + // + !dest.IsValid() + ? ( + // + source.lower < bar.low && + source.upper > bar.high + // + ) + : ( + // + dest.lower < bar.low && + dest.upper > bar.high && + source.lower < bar.low && + source.upper > bar.high && + source.GetRange() < dest.GetRange() + // + ) + // + ; + + // + return result; +} + /** * Check Source breaked Dest from Upper ... * diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index ae8c2818..de857359 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -367,6 +367,14 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert ENUM_XPOI_EVENTS _4HStates[]; m4HPOI.Update(_4HStates); + // + ENUM_XPOI_EVENTS _2HStates[]; + m2HPOI.Update(_2HStates); + + // + ENUM_XPOI_EVENTS _1HStates[]; + m1HPOI.Update(_1HStates); + // ENUM_XPOI_EVENTS _15MStates[]; m15MPOI.Update(_15MStates); @@ -383,6 +391,8 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert // Read all POI States ... m1DPOI.GetState(_1DState); m4HPOI.GetState(_4HState); + m2HPOI.GetState(_2HState); + m1HPOI.GetState(_1HState); m15MPOI.GetState(_15MState); m5MPOI.GetState(_5MState); m1MPOI.GetState(_1MState); @@ -398,6 +408,14 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert _4HState, _States // ); + AddRef( + _2HState, + _States // + ); + AddRef( + _1HState, + _States // + ); AddRef( _15MState, _States // @@ -467,219 +485,6 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert return result; } - /** - * Detect Valid Market Conditions ... - * - * @param conditions: X121SMCStrategyConditions instance ... - * - * @return ( virtual bool ) - */ - virtual bool DetecConditions(X121SMCStrategyConditions &conditions) - { - // - bool result = false; - - // - conditions.Clean(); - - // - return result; - } - - /** - * Detect Market Structure based on Conditions ... - * - * @param structure: X121SMCMarketStructure instance ... - * @param conditions: X121SMCStrategyConditions instance ... - */ - virtual void DetectMarketStructure( - X121SMCMarketStructure &structure, - X121SMCStrategyConditions &conditions // - ) - { - } - - /** - * Remove Specific Conditions if Exists ... - * - * @param conditions: X121SMCStrategyConditions instance ... - */ - virtual void RemoveConditionsIfExists(X121SMCStrategyConditions &conditions) - { - } - - /** - * Search Conditions for Find SL Candidates ... - * - * @param candidates: Double Array ... - * @param entry: Double ... - * @param structure: X121SMCStrategyConditions instance ... - * @param type: ENUM_X_POSITION_TYPES member ... - * - * @return ( virtual int ) - */ - virtual int DetectSLCandidates( - double &candidates[], - double entry, - X121SMCStrategyConditions &conditions, - ENUM_X_POSITION_TYPES type // - ) - { - // - int result = 0; - - // - if (type == X_POSITION_TYPE_NONE || - type == X_POSITION_TYPE_ALL) - { - return result; - } - - // - bool useSwings = true; - bool useMomentumBars = true; - bool useRejectionBars = true; - - // - Clean(candidates); - - // - XOHCL candidateBars[]; - if (type == X_POSITION_TYPE_LONG) - { - // - // Search Bullish Momentum, Rejection Bars and Swing Lows ... - - // - // Swing Lows ... - if (useSwings) - { - // - Copy( - conditions.swingLows, - candidateBars, - false // - ); - } - - // - // Bullish Momentum Bars ... - if (useMomentumBars) - { - // - Copy( - conditions.bullishMomentumBars, - candidateBars, - false // - ); - } - - // - // Bullish Rejection Bars ... - if (useRejectionBars) - { - // - Copy( - conditions.bullishRejectionBars, - candidateBars, - false // - ); - } - - // - int count = ArraySize(candidateBars); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XOHCL iBar = candidateBars[i]; - - // - if (iBar.low < entry) - { - // - Add( - iBar.low, - candidates // - ); - } - } - } - } - else if (type == X_POSITION_TYPE_SHORT) - { - // - // Search Bearish Momentum, Rejection Bars and Swing Highs ... - - // - // Swing Highs ... - if (useSwings) - { - // - Copy( - conditions.swingHighs, - candidateBars, - false // - ); - } - - // - // Bearish Momentum Bars ... - if (useMomentumBars) - { - // - Copy( - conditions.bearishMomentumBars, - candidateBars, - false // - ); - } - - // - // Bearish Rejection Bars ... - if (useRejectionBars) - { - // - Copy( - conditions.bearishRejectionBars, - candidateBars, - false // - ); - } - - // - int count = ArraySize(candidateBars); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XOHCL iBar = candidateBars[i]; - - // - if (iBar.high > entry) - { - // - Add( - iBar.low, - candidates // - ); - } - } - } - } - - // - Clean(candidateBars); - result = ArraySize(candidates); - - // - return result; - } - /** * Customize Strategy Identifier ... * @@ -702,6 +507,8 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert // Point Of Interests ... XCPOI *m1DPOI; XCPOI *m4HPOI; + XCPOI *m2HPOI; + XCPOI *m1HPOI; XCPOI *m15MPOI; XCPOI *m5MPOI; XCPOI *m1MPOI; @@ -709,6 +516,8 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert // XPOIState _1DState; XPOIState _4HState; + XPOIState _2HState; + XPOIState _1HState; XPOIState _15MState; XPOIState _5MState; XPOIState _1MState; @@ -723,10 +532,8 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert MqlTick mLastTick; // Last Issued Tick ... // - X121SMCStrategyConditions mConditions[]; - - // - XBarTracker mBarTracker; // Strategy Time Tracker ... + XBarTracker mBarTracker; // Strategy Time Tracker ... + X121SMCStrategyConditions mConditions; // Market Conditions ... // // Actions ... @@ -985,15 +792,8 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert return result; } - /** - * Clear All Conditions ... - */ - void ClearConditions() - { - Clean(mConditions); - } - // + /** * Notified Signal Event Handler(s) ... * @@ -1146,50 +946,6 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert mDrawnObjects.Add(iObj); } - /** - * Draw Conditions ... - * - * @param conditions: X121SMCStrategyConditions instance ... - */ - void DrawConditions(X121SMCStrategyConditions &conditions) - { - // - XC121SMCConditionsObject *iObj; - iObj = new XC121SMCConditionsObject(mPOIDrawer); - bool isCreated = iObj.CreateByConditions( - ChartIdentification(), - conditions.GetTag(true), - SubWindowIdentification(), - conditions // - ); - if (isCreated) - { - mDrawnObjects.Add(iObj); - } - } - - /** - * Draw Market Structure ... - * - * @param structure: X121SMCMarketStructure instance ... - */ - void DrawMarketStructure(X121SMCMarketStructure &structure) - { - // - XC121SMCMarketStructureObject *iObj; - iObj = new XC121SMCMarketStructureObject(mPOIDrawer); - bool isCreated = iObj.CreateByStructure( - ChartIdentification(), - structure.GetTag(), - SubWindowIdentification(), - structure // - ); - if (isCreated) - { - mDrawnObjects.Add(iObj); - } - } - // // Private ... private: @@ -1299,6 +1055,42 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert // m4HPOI.Init(); + // + // 2H Period ... + // POI Detector ... + m2HPOI = new XCPOI( + symbol, + PERIOD_H2 // + ); + + // + m2HPOI.DisableDrawPOIs(); + m2HPOI.SupplyZonePeriod(PERIOD_H12); + m2HPOI.DemandZonePeriod(PERIOD_H12); + m2HPOI.SubWindowIdentification(0); + m2HPOI.ChartIdentification(ChartID()); + + // + m2HPOI.Init(); + + // + // 1H Period ... + // POI Detector ... + m1HPOI = new XCPOI( + symbol, + PERIOD_H1 // + ); + + // + m1HPOI.DisableDrawPOIs(); + m1HPOI.SupplyZonePeriod(PERIOD_H6); + m1HPOI.DemandZonePeriod(PERIOD_H6); + m1HPOI.SubWindowIdentification(0); + m1HPOI.ChartIdentification(ChartID()); + + // + m1HPOI.Init(); + // // 15M Period ... // POI Detector ... diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index af6e9d61..d6fb2027 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -23,8 +23,6 @@ // Imports ... #include "../../Classes/x-saherelm.xexpert.class.mq5" #include "../Classes/x-121.smc.xtradehandler.class.mq5" -#include "../Strategy/x-121.smc.ob.strategy.class.mq5" -#include "../Strategy/x-121.smc.supdem.strategy.class.mq5" #include "../Strategy/x-121.smc.test.strategy.class.mq5" // diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index ba6cdc4bd11de42ed3aacebd7b2b62158b595380..73a14df3761ac63da533db624d137f5c0bdce97e 100644 GIT binary patch literal 140192 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 p%u2I1%PFlkVY0OCHGgHaPF* delta 4978 zcmbVPdrVu`89yHh_<^A}j%{!-a0v-GBseAu2_qCyLsFWOlm^mP)#?NSNlbawI3#Hr z#}>iC>Jn+1N*h*#9R;Kl}EPE_RO31+c_k zj352Yi05W4_})GnZKwkibkKiJfR%QA8|2L6q=O8J-`2;NJUS^)*T|%WFKk6s=I5sP3vgb z3@zw38`BG#@s{G~g2T|uj5^7UM)=xJJ&(c zg#zln3>L9@bZZv={R=m;Z$l@8p_{??BF=nTN!QpNH4xekRB{wm}e;1%-*Ot_HJ) zbHBLd7F5d^154gPLDH0TgDwiyU`@$57z68?q_Y~L9%A(NiJNJrYqFq_hccZq zgC&kD?KurD0c__PFk7D@2>}_8VsR`bs2yiu?IVlMX&_Cx90xRN4qan_H`Q3C9jBp~ ze)TdO)~QjGQi=klnGOzs9>ZVC0!0|2eQ!b@-C|*W#Y2}1FvP5UIPh9%)ha09;H`}# z+9JYeh{UoYN76*ShKwv)V}*4b)AF|11t{A!_opP-IKTxdL~D~~xkw*mS&1C_74MDT zLn_abF2$<2H$MuUo1!k`gylxV%1<@<>vpy%sFwBHCezR5->jBo%)-#6j( znOu5dkVUr|3u*jGfI0l7k;*0}npZUr4~5OtD8Y_sCF3#{XOqoiAJ$@IWCyy>nrM$( zqw#hC%99{U&^Hy))A~GSHrL1Tr$sqX7gffOC&nIAWyATo!wiD&pj5t}eadk1bvOH% zu(P~1HvY6cH?vvP&6ji;)<@w;GM32#r(6b41 zy+&;I%3|N*wR&$wiutyrxtqO}=<$|``KS&o`oKsd8z2jR>RrEBN#deLi*}(!RTH0V z?kL0BLyE0j&xOrJN@sSj2H&mV)N*qSXjp>PnY^<;g1>ZrO9Uckp9+EevZhR1RTbbXFdzc3t#x$cvO3|*XG~-drqG?6McPzvCmwd1_dkL4) z<{}kJewqId-!FO7^PR70m>7$ZOWtI@Kh}|&@At|W-}ODI`5s%;Xc5$oE+q0@Oupay zkbED&UpcGN@_odY%=g!PiF`lYlbY`_>vO#i&v$It$dZpz=t8zFUf^#iI+YLlVwoi> zrBCi9r&&hyk)!PYZgPr^cnZ6HrJTL=w6C+o_awd22?JEV3hlJj3r%$TDtN@RZrvv? z8h#SC;ox80G8 z)65f;4cFTp82nsXB93FutsZ{`_A3sKoC726J;S<*8?S)tCwnt$XymutO_pNPx=Q`J z3=7`<`38>VN-JqxI~~o*Xo;z>r|pJ}9V^lLg%P&X-a__%j{BLqwNZ4{&$1?JZYSi^ z`G13W8PUima6p+F{SRyTn3vH`kbd3+%i`?!B^!_`yF}H04M(|`2k3l&*`O*Ez0Q)_ z4&#GLr)W6*m3uh1@okrcf2ed}xOf}73(cV(*Mt>+xZ97Bw{k<;U}Sbgf)i>(J8c(L1q7duadE*#MVwjLYDp0+J&pK7Av zYB1vba28&Fp*}$rPZSkBT$Jc&P1xF}$a^s8!3TY(Lf`Z=dDDJHo)YXHluuf)VbnP` zT*P6(hT%FEel~QU(xZIVhyiAgd&ta=S+Mo2j8iAr_c1dzeb*L0vJPuT)(a#ji=EVE Uhnmpr_ukrtvM!4TOEaYZ0R_e>ssI20