From f0d3ededea89b584baeb70619b78184095a235ac Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 28 Oct 2024 13:56:20 +0330 Subject: [PATCH] last works ... --- Classes/x-saherelm.x-chart-objects.class.mq5 | 266 ++++++++ Documents/BKP/121.smc.strategy.tmp.mq5 | 228 +++++++ Libraries/x-saherelm.common.lib.mq5 | 54 +- Libraries/x-saherelm.xtrade.lib.mq5 | 22 +- X121SMCEA/Libraries/x-121.smc.lib.mq5 | 31 +- .../Strategy/x-121.smc.strategy.class.mq5 | 589 +++++++++++------- 6 files changed, 952 insertions(+), 238 deletions(-) create mode 100644 Documents/BKP/121.smc.strategy.tmp.mq5 diff --git a/Classes/x-saherelm.x-chart-objects.class.mq5 b/Classes/x-saherelm.x-chart-objects.class.mq5 index 3564d8d1..841d157b 100644 --- a/Classes/x-saherelm.x-chart-objects.class.mq5 +++ b/Classes/x-saherelm.x-chart-objects.class.mq5 @@ -21,6 +21,7 @@ // #include "../Libraries/x-saherelm.x-poi.lib.mq5" +#include "../Libraries/x-saherelm.xtrade.lib.mq5" // #include @@ -56,6 +57,9 @@ enum ENUM_X_CHART_IDS X_FROM, X_UPPER, X_LOWER, + X_ENTRY, + X_SL, + X_TP }; // @@ -95,6 +99,21 @@ string ToString(ENUM_X_CHART_IDS value) case X_LOWER: result = "XLOWER"; break; + + // + case X_TP: + result = "XTP"; + break; + + // + case X_SL: + result = "XSL"; + break; + + // + case X_ENTRY: + result = "XENTRY"; + break; } // @@ -574,6 +593,253 @@ class XCZoneObject : public XCBaseObject // // Structured Chart Object ... +// +// Signal ... +class XCSignalObject : public XCBaseObject +{ + // + public: + // + + // + // Constructor ... + void XCSignalObject() + { + } + + // + // Deconstructor ... + void ~XCSignalObject() + { + } + + /** + * Create a Signal Object on Chart ... + * + * @param chart_id: Long ... + * @param name: String ... + * @param window: Integer ... + * @param signal: XSignal instance ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + const string name, + const int window, + XSignal &signal // + ) + { + // + bool result = false; + + // + result = IsValid(name) && + signal + .IsValid(); + if (!result) + { + return result; + } + + // + int delay = (PeriodSeconds(signal.period) * 2); + datetime time1 = (datetime)((int)signal.time - delay); + datetime time2 = (datetime)((int)signal.time + delay); + + // + // TP ... + string tpName = ToString(X_TP) + "_" + name; + result = mTPTrend.Create( + chart_id, + tpName, + window, + time1, + signal.tp, + time2, + signal.tp // + ); + if (!result) + { + return result; + } + + // + // SL ... + string slName = ToString(X_TP) + "_" + name; + result = mSLTrend.Create( + chart_id, + slName, + window, + time1, + signal.sl, + time2, + signal.sl // + ); + if (!result) + { + // + mTPTrend.Delete(); + return result; + } + + // + // ENTRY ... + string entrName = ToString(X_ENTRY) + "_" + name; + result = mEntryTrend.Create( + chart_id, + entrName, + window, + time1, + signal.entry, + time2, + signal.entry // + ); + if (!result) + { + // + mTPTrend.Delete(); + mSLTrend.Delete(); + return result; + } + + // + return result; + } + + // + // Setter(s) ... + + // + // TP ... + + /** + * Set TP Width ... + * + * @param value: Integer ... + */ + void TPWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mTPTrend.Width(value); + } + + /** + * Set TP Color ... + * + * @param value: Color ... + */ + void TPColor(color value) + { + mTPTrend.Color(value); + } + + /** + * Set TP Style ... + * + * @param value: ENUM_LINE_STYLE ... + */ + void TPStyle(ENUM_LINE_STYLE value) + { + mTPTrend.Style(value); + } + + // + // SL ... + + /** + * Set SL Width ... + * + * @param value: Integer ... + */ + void SLWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mSLTrend.Width(value); + } + + /** + * Set SL Color ... + * + * @param value: Color ... + */ + void SLColor(color value) + { + mSLTrend.Color(value); + } + + /** + * Set SL Style ... + * + * @param value: ENUM_LINE_STYLE ... + */ + void SLStyle(ENUM_LINE_STYLE value) + { + mSLTrend.Style(value); + } + + // + // ENTRY ... + + /** + * Set Entry Width ... + * + * @param value: Integer ... + */ + void EntryWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mEntryTrend.Width(value); + } + + /** + * Set Entry Color ... + * + * @param value: Color ... + */ + void EntryColor(color value) + { + mEntryTrend.Color(value); + } + + /** + * Set Entry Style ... + * + * @param value: ENUM_LINE_STYLE ... + */ + void EntryStyle(ENUM_LINE_STYLE value) + { + mEntryTrend.Style(value); + } + + // + private: + // + + // + CChartObjectTrend mTPTrend; + CChartObjectTrend mSLTrend; + CChartObjectTrend mEntryTrend; +}; + // // XTradeDay Object ... class XCTardeDayObject : public XCFromToObject diff --git a/Documents/BKP/121.smc.strategy.tmp.mq5 b/Documents/BKP/121.smc.strategy.tmp.mq5 new file mode 100644 index 00000000..531ec2c3 --- /dev/null +++ b/Documents/BKP/121.smc.strategy.tmp.mq5 @@ -0,0 +1,228 @@ + // + // LONG ... + + // + bool isSoImportantLong = + iConditions.demandZone.IsValid() && + iConditions.bullishFVG.IsValid() && + iConditions.bullishOrderBlock.IsValid(); + + // + bool isImportantLong = + iConditions.demandZone.IsValid() && + (iConditions.bullishFVG.IsValid() || + iConditions.bullishOrderBlock.IsValid()); + + // + bool isRiskyLong = + iConditions.demandZone.IsValid() && + (iConditions.bullishFVG.IsValid() || + iConditions.bullishOrderBlock.IsValid()); + + // + bool hasLongConditions = isSoImportantLong || + isImportantLong || + isRiskyLong; + + // + if (hasLongConditions) + { + // + // Find Trigger for Input Positions ... + // - [] Breakout; + // - [] Engulf; + // - [] Rejection Bar; + // - [] Momentum Bar; + + // + type = POSITION_TYPE_BUY; + entry = GetEntry(mSymbol, type); + sl = iConditions.demandZone.lower - (10 * points); + risk = entry - sl; + reward = risk * r2r; + tp = entry + reward; + + // + bool isSpreadOK = IsSpreadPass(); + + // + // Price Must Breakout the Upper of Demand ... + bool isBreakout = + // + cBar.IsBullish() && + zBar.low > conditions.demandZone.upper && + cBar.high > conditions.demandZone.upper && + cBar.close > conditions.demandZone.upper && + (cBar.open < conditions.demandZone.upper || + cBar.low < conditions.demandZone.upper) + // + ; + + // + // Price Must have Bullish Trend and Momentum on Ticks ... + bool isTicksBullishMomentum = + IsTicksBullish() && + IsTicksHasMomentum(); + + // + // Detect momentum / Swing Low / Rejection Bars ... + bool hasMomentumBars = false; + int swingLowsCount = ArraySize(_5MState.swingLows); + int momentumBarsCount = ArraySize(_5MState.momentumBars); + int rejectionBarsCount = ArraySize(_5MState.rejectionBars); + if (IsValidSize(swingLowsCount) || + IsValidSize(momentumBarsCount) || + IsValidSize(rejectionBarsCount)) + { + // + int foundedPOIs = 0; + + // + // Check Swing Lows ... + if (IsValidSize(swingLowsCount)) + { + // + for (int i = 0; i < swingLowsCount; i++) + { + // + XOHCL iBar = _5MState.swingLows[i]; + + // + if (iBar.time > iConditions.demandZone.from) + { + // + if (iBar.low < entry) + { + // + foundedPOIs++; + DrawSwingBar(iBar, true); + } + } + } + } + + // + // Check Momentum Bars ... + if (IsValidSize(momentumBarsCount)) + { + // + for (int i = 0; i < momentumBarsCount; i++) + { + // + XOHCL iBar = _5MState.momentumBars[i]; + + // + if (iBar.time > iConditions.demandZone.from) + { + // + if (iBar.IsBullish() && iBar.low < entry) + { + // + foundedPOIs++; + DrawMomentumBar(iBar); + } + } + } + } + + // + // Check Rejection Bars ... + if (IsValidSize(rejectionBarsCount)) + { + // + for (int i = 0; i < rejectionBarsCount; i++) + { + // + XOHCL iBar = _5MState.rejectionBars[i]; + + // + if (iBar.time > iConditions.demandZone.from) + { + // + if (iBar.low < entry && + iBar.GetLowShadow() > iBar.GetHighShadow()) + { + // + foundedPOIs++; + DrawRejectionBar(iBar); + } + } + } + } + + // + pushers = foundedPOIs; + hasMomentumBars = foundedPOIs > 0; + } + + // + hasLongConditions = + hasLongConditions && + // + isSpreadOK && + // + isBreakout && + isTicksBullishMomentum && + // + hasMomentumBars + // + ; + + // + if (hasLongConditions) + { + // + removeIDX = i; + conditions = iConditions; + result = hasLongConditions; + + // + break; + } + } + + // + // SHORT ... + + // + bool isSoImportantShort = + iConditions.supplyZone.IsValid() && + iConditions.bearishFVG.IsValid() && + iConditions.bearishOrderBlock.IsValid(); + + // + bool isImportantShort = + iConditions.supplyZone.IsValid() && + (iConditions.bearishFVG.IsValid() || + iConditions.bearishOrderBlock.IsValid()); + + // + bool isRiskyShort = + iConditions.supplyZone.IsValid() && + (!iConditions.bearishFVG.IsValid() && + !iConditions.bearishOrderBlock.IsValid()); + + // + bool hasShortConditions = isSoImportantShort || + isImportantShort || + isRiskyShort; + + // + if (hasShortConditions) + { + // + // Find Trigger for Input Positions ... + // - [] Breakout; + // - [] Engulf; + // - [] Rejection Bar; + // - [] Momentum Bar; + + // + + // + // removeIDX = i; + // conditions = iConditions; + // // DrawConditions(iConditions); + // Print("hasShortConditions"); + break; + } diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 00c7e3de..c713b91c 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -200,6 +200,7 @@ struct XTick datetime time; // Time ... double bid; // Bid ... double ask; // Ask ... + double spread; // Spread ... // // Constructor ... @@ -223,7 +224,8 @@ struct XTick string _symbol, datetime _time, double _bid, - double _ask // + double _ask, + double _spread // ) { // @@ -234,19 +236,59 @@ struct XTick IsValid(_time) && _bid > 0 && _ask > 0; - if (!result) { + if (!result) + { return result; } - + // - symbol = _symbol; - time = _time; bid = _bid; ask = _ask; + time = _time; + symbol = _symbol; + spread = _spread; // result = IsValid(); - + + // + return result; + } + + /** + * Init Tick by Symbol ... + * + * @param _symbol: String ... + * + * @return ( bool ) + */ + bool Init(string _symbol) + { + // + bool result = false; + + // + result = IsValid(_symbol); + if (!result) + { + return result; + } + + // + datetime _time = TimeCurrent(); + double _bid = GetBid(_symbol); + double _ask = GetAsk(_symbol); + double _spread = GetSpread(_symbol); + + // + result = Init( + _symbol, + _time, + _bid, + _ask, + _spread // + ); + // return result; } diff --git a/Libraries/x-saherelm.xtrade.lib.mq5 b/Libraries/x-saherelm.xtrade.lib.mq5 index c0f0128a..19ff8804 100644 --- a/Libraries/x-saherelm.xtrade.lib.mq5 +++ b/Libraries/x-saherelm.xtrade.lib.mq5 @@ -612,7 +612,8 @@ struct XPosition } // - double GetRewardInPoint() { + double GetRewardInPoint() + { // double result = 0; @@ -1618,6 +1619,25 @@ struct XSignal return result; } + // + string GetTag() + { + // + string result = NULL; + + // + result = "XSignal_" + + symbol + "_" + + ToString(period) + "_" + + ToString(type) + "_" + + ToString(sl) + "_" + + ToString(tp) + "_" + + ToString(entry); + + // + return result; + } + // // Retrieve String Representation of Signal ... string ToString() diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index da4868de..90248ee6 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -53,12 +53,22 @@ struct X121SMCStrategyConditions XZone supplyZone; XZone bearishOrderBlock; XZone bearishFVG; - + + // + XOHCL swingHighs[]; + XOHCL bearishMomentumBars[]; + XOHCL bearishRejectionBars[]; + // XZone demandZone; XZone bullishOrderBlock; XZone bullishFVG; + // + XOHCL swingLows[]; + XOHCL bullishMomentumBars[]; + XOHCL bullishRejectionBars[]; + // // Constructor ... void XStrategyConditions() @@ -79,7 +89,24 @@ struct X121SMCStrategyConditions time = NULL; // - // Clean Helpers Conditions ... + supplyZone.Clean(); + bearishOrderBlock.Clean(); + bearishFVG.Clean(); + + // + demandZone.Clean(); + bullishOrderBlock.Clean(); + bullishFVG.Clean(); + + // + Clean(swingHighs); + Clean(bearishMomentumBars); + Clean(bearishRejectionBars); + + // + Clean(swingLows); + Clean(bullishMomentumBars); + Clean(bullishRejectionBars); } // diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 2135cee0..edc06d61 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -314,6 +314,14 @@ class XCX121SMCStrategy : public XSCBaseAlert signal, conditions // ); + + // + DrawSignal( + signal, + conditions); + + // + // ClearDraws(); } // @@ -330,6 +338,9 @@ class XCX121SMCStrategy : public XSCBaseAlert signal.Clean(); conditions.Clean(); + // + int pushers = 0; + // double sl = 0; double tp = 0; @@ -472,138 +483,24 @@ class XCX121SMCStrategy : public XSCBaseAlert for (int i = 0; i < conditionsCount; i++) { // + result = false; X121SMCStrategyConditions iConditions = mConditions[i]; // - // LONG ... - - // - bool isSoImportantLong = - iConditions.demandZone.IsValid() && - iConditions.bullishFVG.IsValid() && - iConditions.bullishOrderBlock.IsValid(); - - // - bool isImportantLong = - iConditions.demandZone.IsValid() && - (iConditions.bullishFVG.IsValid() || - iConditions.bullishOrderBlock.IsValid()); - - // - bool isRiskyLong = - iConditions.demandZone.IsValid() && - (iConditions.bullishFVG.IsValid() || - iConditions.bullishOrderBlock.IsValid()); - - // - bool hasLongConditions = isSoImportantLong || - isImportantLong || - isRiskyLong; - - // - if (hasLongConditions) + // Longs ... + bool isAllowLong = AllowLong(); + if (isAllowLong) { // - // Find Trigger for Input Positions ... - // - [] Breakout; - // - [] Engulf; - // - [] Rejection Bar; - // - [] Momentum Bar; - - // - // Price Must Breakout the Upper of Demand ... - bool isBreakout = - // - cBar.IsBullish() && - zBar.low > conditions.demandZone.upper && - cBar.high > conditions.demandZone.upper && - cBar.close > conditions.demandZone.upper && - (cBar.open < conditions.demandZone.upper || - cBar.low < conditions.demandZone.upper) - // - ; - - // - // Price Must have Bullish Trend and Momentum on Ticks ... - bool isTicksBullishMomentum = - IsTicksBullish() && - IsTicksHasMomentum(); - - // - bool hasMpmentumBar = - // - cBar. - // - ; - - // - hasLongConditions = - hasLongConditions && - // - isBreakout && - isTicksBullishMomentum - // - ; - - // - if (hasLongConditions) - { - // - removeIDX = i; - conditions = iConditions; - DrawConditions(iConditions); - Print("hasLongConditions"); - break; - } } // - // SHORT ... - - // - bool isSoImportantShort = - iConditions.supplyZone.IsValid() && - iConditions.bearishFVG.IsValid() && - iConditions.bearishOrderBlock.IsValid(); - - // - bool isImportantShort = - iConditions.supplyZone.IsValid() && - (iConditions.bearishFVG.IsValid() || - iConditions.bearishOrderBlock.IsValid()); - - // - bool isRiskyShort = - iConditions.supplyZone.IsValid() && - (!iConditions.bearishFVG.IsValid() && - !iConditions.bearishOrderBlock.IsValid()); - - // - bool hasShortConditions = isSoImportantShort || - isImportantShort || - isRiskyShort; - - // - if (hasShortConditions) + // Shorts ... + bool isAllowShort = AllowShort(); + if (isAllowShort) { // - // Find Trigger for Input Positions ... - // - [] Breakout; - // - [] Engulf; - // - [] Rejection Bar; - // - [] Momentum Bar; - - // - - // - removeIDX = i; - conditions = iConditions; - DrawConditions(iConditions); - Print("hasShortConditions"); - break; } - - // } // @@ -617,6 +514,22 @@ class XCX121SMCStrategy : public XSCBaseAlert removeIDX, 1 // ); + + // + signal.sl = sl; + signal.tp = tp; + signal.type = type; + signal.mode = mode; + signal.entry = entry; + signal.volume = volume; + signal.symbol = mSymbol; + signal.pushers = pushers; + signal.provider = GetTag(); + signal.time = TimeCurrent(); + signal.period = _5MState.period; + + // + result = PrepareSignal(signal); } // @@ -694,19 +607,9 @@ class XCX121SMCStrategy : public XSCBaseAlert */ void SaveTickData() { - // - datetime time = TimeCurrent(); - double ask = GetAsk(mSymbol); - double bid = GetBid(mSymbol); - // XTick tick; - bool isInited = tick.Init( - mSymbol, - time, - bid, - ask // - ); + bool isInited = tick.Init(mSymbol); if (!isInited) { return; @@ -719,6 +622,57 @@ class XCX121SMCStrategy : public XSCBaseAlert ); } + /** + * Check Spread Passed for Positions... + * + * @return ( bool ) + */ + bool IsSpreadPass() + { + // + bool result = false; + + // + int length = 5; + + // + int ticksCount = ArraySize(mTicks); + if (ticksCount <= length) + { + return result; + } + + // + int start = -1; + int end = -1; + CalculateTicksParams( + start, + end, + length + 1 // + ); + result = IsValidIndex(start) && + IsValidIndex(end); + if (!result) + { + return result; + } + + // + end -= 1; + double spread = 0; + for (int i = start; i < end; i++) + { + spread += mTicks[i].spread; + } + spread /= length; + + // + result = mTicks[ticksCount - 1].spread <= spread; + + // + return result; + } + /** * Calculate Ticks Param for Looping through Last n items ... * @@ -907,6 +861,14 @@ class XCX121SMCStrategy : public XSCBaseAlert // Collect all Drawn Objects ... CArrayObj mDrawnObjects; + /** + * Clear all Drawn Objects ... + */ + void ClearDraws() + { + mDrawnObjects.Clear(); + } + /** * Remove Specified Drawn Object ... * @@ -933,7 +895,11 @@ class XCX121SMCStrategy : public XSCBaseAlert { // string iName = ((CChartObject *)mDrawnObjects.At(i)).Name(); - string iObjName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName(); + string iObjName = NULL; + if (!IsValid(iName)) + { + iObjName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName(); + } // if ((IsValid(iName) && @@ -989,6 +955,10 @@ class XCX121SMCStrategy : public XSCBaseAlert // mForceDisabled = false; + // + R2R(2); + Volume(0.01); + // string symbol = Symbol(); ENUM_TIMEFRAMES period = Period(); @@ -1092,6 +1062,9 @@ class XCX121SMCStrategy : public XSCBaseAlert delete m5MPOI; delete m15MPOI; // delete m4HSupDemPOI; + + // + ClearDraws(); } /** @@ -1729,26 +1702,10 @@ class XCX121SMCStrategy : public XSCBaseAlert // string name = zone.GetTag(); RemoveObject(name); - // int idx = FindIndex(zone, mSupplyZones); - // if (IsValidIndex(idx)) - // { - // // // - // // ArrayRemove( - // // mSupplyZones, - // // idx, - // // 1 // - // // ); - - // // - // } // zone.to = TimeCurrent(); name = zone.GetTag(); - // AddRef( - // zone, - // mSupplyZones // - // ); // XCSupplyZoneObject *iObj; @@ -1791,26 +1748,10 @@ class XCX121SMCStrategy : public XSCBaseAlert // string name = zone.GetTag(); RemoveObject(name); - // int idx = FindIndex(zone, mDemandZones); - // if (IsValidIndex(idx)) - // { - // // // - // // ArrayRemove( - // // mDemandZones, - // // idx, - // // 1 // - // // ); - - // // - // } // zone.to = TimeCurrent(); name = zone.GetTag(); - // AddRef( - // zone, - // mDemandZones // - // ); // XCDemandZoneObject *iObj; @@ -1853,26 +1794,10 @@ class XCX121SMCStrategy : public XSCBaseAlert // string name = zone.GetTag(); RemoveObject(name); - // int idx = FindIndex(zone, mBearishOrderBlocks); - // if (IsValidIndex(idx)) - // { - // // // - // // ArrayRemove( - // // mBearishOrderBlocks, - // // idx, - // // 1 // - // // ); - - // // - // } // zone.to = TimeCurrent(); name = zone.GetTag(); - // AddRef( - // zone, - // mBearishOrderBlocks // - // ); // XCBearishOrderBlockObject *iObj; @@ -1915,26 +1840,10 @@ class XCX121SMCStrategy : public XSCBaseAlert // string name = zone.GetTag(); RemoveObject(name); - // int idx = FindIndex(zone, mBullishOrderBlocks); - // if (IsValidIndex(idx)) - // { - // // // - // // ArrayRemove( - // // mBullishOrderBlocks, - // // idx, - // // 1 // - // // ); - - // // - // } // zone.to = TimeCurrent(); name = zone.GetTag(); - // AddRef( - // zone, - // mBullishOrderBlocks // - // ); // XCBullishOrderBlockObject *iObj; @@ -1977,26 +1886,10 @@ class XCX121SMCStrategy : public XSCBaseAlert // string name = zone.GetTag(); RemoveObject(name); - // int idx = FindIndex(zone, mBearishFVGs); - // if (IsValidIndex(idx)) - // { - // // - // // ArrayRemove( - // // mBearishFVGs, - // // idx, - // // 1 // - // // ); - - // // - // } // zone.to = TimeCurrent(); name = zone.GetTag(); - // AddRef( - // zone, - // mBearishFVGs // - // ); // XCBearishFVGObject *iObj; @@ -2039,26 +1932,10 @@ class XCX121SMCStrategy : public XSCBaseAlert // string name = zone.GetTag(); RemoveObject(name); - // int idx = FindIndex(zone, mBullishFVGs); - // if (IsValidIndex(idx)) - // { - // // // - // // ArrayRemove( - // // mBullishFVGs, - // // idx, - // // 1 // - // // ); - - // // - // } // zone.to = TimeCurrent(); name = zone.GetTag(); - // AddRef( - // zone, - // mBullishFVGs // - // ); // XCBullishFVGObject *iObj; @@ -2085,6 +1962,199 @@ class XCX121SMCStrategy : public XSCBaseAlert mDrawnObjects.Add(iObj); } + /** + * Draw Specified Swing Bars ... + * + * @param bar: XOHLC instance ... + * @param isLow: Boolean ... + */ + void DrawSwingBar( + XOHCL &bar, + bool isLow // + ) + { + // + if (!bar.IsValid()) + { + return; + } + + // + string tagPref = + isLow + ? ToString(X_POI_SWING_LOW) + : ToString(X_POI_SWING_HIGH); + string name = bar.GetTag(tagPref); + RemoveObject(name); + + // + double price = + isLow + ? bar.low + : bar.high; + char arrowCode = + isLow + ? (char)188 + : (char)108; + color clr = + isLow + ? clrAqua + : clrMagenta; + ENUM_ARROW_ANCHOR anchor = + isLow + ? ANCHOR_TOP + : ANCHOR_BOTTOM; + + // + CChartObjectArrow *iObj; + iObj = new CChartObjectArrow(); + bool isCreated = iObj.Create( + ChartID(), + name, + 0, + bar.time, + price, + arrowCode // + ); + if (!isCreated) + { + return; + } + + // + // Configure Object ... + iObj.Width(1); + iObj.Color(clr); + iObj.Anchor(anchor); + + // + mDrawnObjects.Add(iObj); + } + + /** + * Draw Momentum Bar ... + * + * @param bar: XOHCL instance ... + */ + void DrawMomentumBar(XOHCL &bar) + { + // + if (!bar.IsValid()) + { + return; + } + + // + bool isBullish = bar.IsBullish(); + string name = bar.GetTag(ToString(X_POI_MOMENTUM_BAR)); + RemoveObject(name); + + // + double price = + isBullish + ? bar.low + : bar.high; + char arrowCode = + isBullish + ? (char)225 + : (char)226; + color clr = + isBullish + ? clrAqua + : clrMagenta; + ENUM_ARROW_ANCHOR anchor = + isBullish + ? ANCHOR_TOP + : ANCHOR_BOTTOM; + + // + CChartObjectArrow *iObj; + iObj = new CChartObjectArrow(); + bool isCreated = iObj.Create( + ChartID(), + name, + 0, + bar.time, + price, + arrowCode // + ); + if (!isCreated) + { + return; + } + + // + // Configure Object ... + iObj.Width(1); + iObj.Color(clr); + iObj.Anchor(anchor); + + // + mDrawnObjects.Add(iObj); + } + + /** + * Draw Bullish Rejection Bar ... + * + * @param bar: XOHCL instance ... + */ + void DrawRejectionBar(XOHCL &bar) + { + // + if (!bar.IsValid()) + { + return; + } + + // + bool isBullish = bar.GetLowShadow() > bar.GetHighShadow(); + string name = bar.GetTag(ToString(X_POI_REJECTION_BAR)); + RemoveObject(name); + + // + double price = + isBullish + ? bar.low + : bar.high; + char arrowCode = + isBullish + ? (char)217 + : (char)218; + color clr = + isBullish + ? clrAqua + : clrMagenta; + ENUM_ARROW_ANCHOR anchor = + isBullish + ? ANCHOR_TOP + : ANCHOR_BOTTOM; + + // + CChartObjectArrow *iObj; + iObj = new CChartObjectArrow(); + bool isCreated = iObj.Create( + ChartID(), + name, + 0, + bar.time, + price, + arrowCode // + ); + if (!isCreated) + { + return; + } + + // + // Configure Object ... + iObj.Width(1); + iObj.Color(clr); + iObj.Anchor(anchor); + + // + mDrawnObjects.Add(iObj); + } + /** * Draw Specific Condition ... * @@ -2129,6 +2199,67 @@ class XCX121SMCStrategy : public XSCBaseAlert } } + /** + * Draw Specified Signal ... + * + * @param signal: XSignal instance ... + * @param conditions: X121SMCStrategyConditions instance ... + */ + void DrawSignal( + XSignal &signal, + X121SMCStrategyConditions &conditions // + ) + { + // + if (!signal.IsValid() || + !conditions.IsValid()) + { + // + return; + } + + // + // DrawConditions(conditions); + + // + string name = signal.GetTag(); + RemoveObject(name); + + // + XCSignalObject *iObj; + iObj = new XCSignalObject(); + + // + bool isCreated = iObj.Create( + ChartID(), + name, + 0, + signal // + ); + if (!isCreated) + { + return; + } + + // + iObj.TPWidth(1); + iObj.TPColor(clrGreen); + iObj.TPWidth(STYLE_DOT); + + // + iObj.SLWidth(1); + iObj.SLColor(clrRed); + iObj.SLWidth(STYLE_DOT); + + // + iObj.EntryWidth(1); + iObj.EntryColor(clrYellow); + iObj.EntryWidth(STYLE_DOT); + + // + mDrawnObjects.Add(iObj); + } + // };