diff --git a/Classes/x-saherelm.x-app-dialog.class.mq5 b/Classes/x-saherelm.x-app-dialog.class.mq5 index 6bfa4d9c..fc3de5ef 100644 --- a/Classes/x-saherelm.x-app-dialog.class.mq5 +++ b/Classes/x-saherelm.x-app-dialog.class.mq5 @@ -168,6 +168,9 @@ class XCAppDialog : public CAppDialog wndclient.ColorBackground(clr); } + // + // Overrides ... + // protected: // diff --git a/Classes/x-saherelm.x-cobject.class.mq5 b/Classes/x-saherelm.x-cobject.class.mq5 index 2666968f..7645a2a4 100644 --- a/Classes/x-saherelm.x-cobject.class.mq5 +++ b/Classes/x-saherelm.x-cobject.class.mq5 @@ -28,8 +28,8 @@ #include #include #include -#include -#include +#include +#include // // Definitions ... diff --git a/Classes/x-saherelm.x-rm.panel.class.mq5 b/Classes/x-saherelm.x-rm.panel.class.mq5 new file mode 100644 index 00000000..d3808dc5 --- /dev/null +++ b/Classes/x-saherelm.x-rm.panel.class.mq5 @@ -0,0 +1,1162 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XCRMPanel +// Description: provides all based classes for use ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.x-app-dialog.class.mq5" +#include "../Classes/x-saherelm.x-trade.class.mq5" + +// +#include +#include +#include +#include +#include +#include + +// +// Implementation ... + +// +class XCRMPanel : public XCAppDialog +{ + // + public: + // + // Event Binding ... + // EVENT_MAP_BEGIN(XCRMPanel) + // ON_EVENT(ON_CLICK, btnBuy, HandleBtnBuyClicked) + // ON_EVENT(ON_CLICK, btnSell, HandleBtnSellClicked) + // EVENT_MAP_END(XCRMPanel) + + // + // Constructor(s) ... + void XCRMPanel() + { + // + Default(); + } + + // + // Deconstructor ... + void ~XCRMPanel() + { + // + HandleRemoveObjects(); + + // + ZeroMemory(mTrader); + } + + // + // Props ... + + // + int SubWindow() + { + return subWindow; + } + + // + void SubWindow(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + subWindow = value; + } + + // + // BUY ... + + // + string BtnBuyLabel() + { + return buyLabelStr; + } + + // + void BtnBuyLabel(string value) + { + buyLabelStr = value; + } + + // + color BtnBuyBGColor() + { + return btnBuyBGColor; + } + + // + void BtnBuyBGColor(color value) + { + btnBuyBGColor = value; + } + + // + // SELL ... + + // + string BtnSellLabel() + { + return sellLabelStr; + } + + // + void BtnSellLabel(string value) + { + sellLabelStr = value; + } + + // + color BtnSellBGColor() + { + return btnSellBGColor; + } + + // + void BtnSellBGColor(color value) + { + btnSellBGColor = value; + } + + // + double RiskPercent() + { + return riskPercent; + } + + // + void RiskPercent(double value) + { + // + if (value < minAllowedRiskPercent) + { + value = minAllowedRiskPercent; + } + + // + if (value > maxAllowedRiskPercent) + { + value = maxAllowedRiskPercent; + } + + // + riskPercent = value; + + // + tbRisk.Text((string)value); + } + + // + // + // + + bool HasSL() + { + return slLine != NULL; + } + + double ReadSL() + { + // + double result = 0; + + // + if (HasSL()) + { + // + result = slLine.GetDouble(OBJPROP_PRICE); + result = NormalizePrice(result, _Symbol); + } + + // + return result; + } + + bool HasTP() + { + return tpLine != NULL; + } + + double ReadTP() + { + // + double result = 0; + + // + if (HasTP()) + { + // + result = tpLine.GetDouble(OBJPROP_PRICE); + result = NormalizePrice(result, _Symbol); + } + + // + return result; + } + + bool HasEntry() + { + return entryLine != NULL; + } + + double ReadEntry() + { + // + double result = 0; + + // + if (HasEntry()) + { + // + result = entryLine.GetDouble(OBJPROP_PRICE); + result = NormalizePrice(result, _Symbol); + } + + // + return result; + } + + bool GetDirection(ENUM_X_DIRECTION &dir) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + result = HasTP() && + HasSL() && + HasEntry(); + + // + if (!result) + { + return result; + } + + // + double sl = ReadSL(); + double tp = ReadTP(); + double entry = ReadEntry(); + + // + result = sl > 0 && + tp > 0 && + entry > 0; + if (!result) + { + return result; + } + + // + bool isBullish = + tp > entry && + tp > sl && + entry > sl; + bool isBearish = + tp < entry && + tp < sl && + entry < sl; + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + dir = isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; + } + + // + // Tools ... + + // + void Default() + { + // + string prefix = CreateInstanceId(); + + // + defaultR2R = 2; + riskPercent = 1; + defaultRisk = 50; + minAllowedRiskPercent = 0.5; + maxAllowedRiskPercent = 10.0; + + // + disabledBtnColor = clrLightGray; + disabledBtnBGColor = clrGray; + + // + tbRiskID = prefix + "_RiskTB"; + + // + buyLabelStr = "Buy"; + btnBuyBGColor = clrLime; + btnBuyColor = clrDarkBlue; + btnBuyID = prefix + "_" + buyLabelStr; + + // + sellLabelStr = "Sell"; + btnSellBGColor = clrRed; + btnSellColor = clrDarkBlue; + btnSellID = prefix + "_" + sellLabelStr; + + // + slLine = NULL; + slColor = clrMagenta; + slID = prefix + "_SL"; + + // + tpLine = NULL; + tpColor = clrAqua; + tpID = prefix + "_TP"; + + // + entryLine = NULL; + entryColor = clrYellow; + entryID = prefix + "_Entry"; + + // + btnDrawRemoveID = prefix + "_DrawRemove"; + drawLabelStr = "Draw"; + removeLabelStr = "Remove"; + btnDrawColor = clrWhite; + btnDrawBGColor = clrDarkBlue; + btnRemoveColor = clrYellow; + btnRemoveBGColor = clrDarkRed; + + // + slippage = 10; + magicNumber = 1694056; + + // + // Create Trader Instance and Configure it ... + mTrader = new XCTrade( + slippage, + magicNumber // + ); + } + + // + void UpdateState() + { + // + bool canEnable = HasSL() && + HasTP() && + HasEntry(); + + // + if (canEnable) + { + SetRemoveMode(); + } + else + { + SetDrawMode(); + } + + // + double entry = GetBid(_Symbol); + ENUM_X_DIRECTION dir; + if (GetDirection(dir)) + { + entry = GetEntry(_Symbol, dir); + } + + // + if (HasEntry()) + { + double iEntry = ReadEntry(); + if (iEntry != entry) + { + SetEntry(entry); + } + } + } + + // + // Handlers ... + + /** + * Handle Btn Buy Clicked ... + */ + void HandleBtnBuyClicked() + { + // + ENUM_X_DIRECTION dir; + bool has = GetDirection(dir); + bool isBullish = has & + IsBullish(dir); + if (!has || !isBullish) + { + return; + } + + // + double tp = ReadTP(); + double sl = ReadSL(); + double entry = ReadEntry(); + + // + mTrader.Buy( + _Symbol, + _Period, + volume, + entry, + sl, + tp // + ); + } + + /** + * Handle Btn Sell Clicked ... + */ + void HandleBtnSellClicked() + { + // + ENUM_X_DIRECTION dir; + bool has = GetDirection(dir); + bool isBearish = has & + IsBearish(dir); + if (!has || !isBearish) + { + return; + } + + // + double tp = ReadTP(); + double sl = ReadSL(); + double entry = ReadEntry(); + + // + mTrader.Sell( + _Symbol, + _Period, + volume, + entry, + sl, + tp // + ); + } + + /** + * Handle Draw Remove Position ... + */ + void HandleBtnDrawRemoveClicked() + { + // + string btnText = btnDrawRemove.Text(); + if (btnText == drawLabelStr) + { + HandleDrawObjects(); + } + else if (btnText == removeLabelStr) + { + HandleRemoveObjects(); + } + } + + /** + * Handle Risk Percent Changed ... + */ + void HandleOnRiskPercentChanged() + { + // + string tbRiskStr = tbRisk.Text(); + + // + double tbNewRisk = (double)tbRiskStr; + RiskPercent(tbNewRisk); + } + + // + // Virtuals ... + + // + virtual bool OnEvent( + const int id, + const long &lparam, + const double &dparam, + const string &sparam // + ) + { + // + bool result = false; + + // + XCAppDialog::OnEvent(id, lparam, dparam, sparam); + + // + // Check if the event is a button click + if (id == ON_CLICK + CHARTEVENT_CUSTOM) + { + // + // Verify if the clicked object is this button + if (lparam == btnBuy.Id()) + { + // + HandleBtnBuyClicked(); + result = true; + } + else if (lparam == btnSell.Id()) + { + // + HandleBtnSellClicked(); + result = true; + } + else if (lparam == btnDrawRemove.Id()) + { + // + HandleBtnDrawRemoveClicked(); + result = true; + } + } + else if (id == ON_END_EDIT + CHARTEVENT_CUSTOM) + { + // + if (lparam == tbRisk.Id()) + { + // + HandleOnRiskPercentChanged(); + result = true; + } + } + else if (id == CHARTEVENT_OBJECT_DRAG) + { + // + if (sparam == entryLine.Name()) + { + // + CalculateData(); + result = true; + } + else if (sparam == tpLine.Name()) + { + // + CalculateData(); + result = true; + } + else if (sparam == slLine.Name()) + { + // + CalculateData(); + result = true; + } + } + + // + return result; + } + + // + // Overrides ... + + // + bool Create( + const long chart, + const string name, + const int subwin, + const int x1, + const int y1, + const int x2, + const int y2 // + ) + { + // + bool result = false; + + // + // Create App Dialog instance it Self ... + result = XCAppDialog::Create( + chart, + name, + subwin, + x1, + y1, + x2, + y2 // + ); + if (!result) + { + return result; + } + + // + chartId = chart; + subWindow = subwin; + + // + // Configure Dialog ... + BackgroundColor(clrBlack); + + // + int top = Top(); + int left = Left(); + int right = Right(); + int bottom = Bottom(); + + // + int width = Width(); + int height = Height(); + + // + int desiredWidth = width - left; + int desiredHeight = height - top; + + // + int btnWidth = desiredWidth / 2; + int btnHeight = desiredHeight / 3; + + // + // Risk Edit ... + int tbRiskX1 = 0; + int tbRiskY1 = 0; + int tbRiskX2 = tbRiskX1 + (btnWidth * 2); + int tbRiskY2 = tbRiskY1 + btnHeight; + result = tbRisk.Create( + chart, + tbRiskID, + subWindow, + tbRiskX1, + tbRiskY1, + tbRiskX2, + tbRiskY2 // + ); + if (!result) + { + return result; + } + + // + result = tbRisk.Text((string)riskPercent); + result = tbRisk.TextAlign(ALIGN_CENTER); + + // + result = Add(tbRisk); + + // + // Create Draw/Remove Button ... + int btnDrawX1 = 0; + int btnDrawY1 = desiredHeight - (btnHeight * 2); + int btnDrawX2 = btnDrawX1 + (btnWidth * 2); + int btnDrawY2 = btnDrawY1 + btnHeight; + result = btnDrawRemove.Create( + chart, + btnDrawRemoveID, + subWindow, + btnDrawX1, + btnDrawY1, + btnDrawX2, + btnDrawY2 // + ); + if (!result) + { + return result; + } + + // + result = btnDrawRemove.Text(drawLabelStr); + result = btnDrawRemove.Color(btnDrawColor); + result = btnDrawRemove.ColorBackground(btnDrawBGColor); + + // + result = Add(btnDrawRemove); + + // + // Create Buy Button ... + int btnBuyX1 = 0; + int btnBuyY1 = desiredHeight - btnHeight; + int btnBuyX2 = btnBuyX1 + btnWidth; + int btnBuyY2 = btnBuyY1 + btnHeight; + result = btnBuy.Create( + chart, + btnBuyID, + subWindow, + btnBuyX1, + btnBuyY1, + btnBuyX2, + btnBuyY2 // + ); + if (!result) + { + return result; + } + + // + result = btnBuy.Text(buyLabelStr); + result = btnBuy.Color(btnBuyColor); + result = btnBuy.ColorBackground(btnBuyBGColor); + + // + result = Add(btnBuy); + + // + // Create Sell Button ... + int btnSellX1 = btnBuyX2; + int btnSellY1 = btnBuyY1; + int btnSellX2 = btnSellX1 + btnWidth; + int btnSellY2 = btnSellY1 + btnHeight; + result = btnSell.Create( + chart, + btnSellID, + subWindow, + btnSellX1, + btnSellY1, + btnSellX2, + btnSellY2 // + ); + if (!result) + { + return result; + } + + // + result = btnSell.Text(sellLabelStr); + result = btnSell.Color(btnSellColor); + result = btnSell.ColorBackground(btnSellBGColor); + + // + result = Add(btnSell); + + // + if (result) + { + // + UpdateState(); + CalculateData(); + } + + // + return result; + } + + // + protected: + // + XCTrade *mTrader; + int slippage; + long magicNumber; + + // + long chartId; + int subWindow; + + // + string slID; + color slColor; + CChartObjectHLine *slLine; + + // + string tpID; + color tpColor; + CChartObjectHLine *tpLine; + + // + string entryID; + color entryColor; + CChartObjectHLine *entryLine; + + // + double riskPercent; + double minAllowedRiskPercent; + double maxAllowedRiskPercent; + + // + double volume; + + // + double defaultR2R; + double defaultRisk; + + // + color disabledBtnColor; + color disabledBtnBGColor; + + // + // Risk Percent Edit ... + CEdit tbRisk; + string tbRiskID; + + // + // BUY Button ... + CButton btnBuy; + string btnBuyID; + string buyLabelStr; + color btnBuyColor; + color btnBuyBGColor; + + // + // SELL Button ... + CButton btnSell; + string btnSellID; + string sellLabelStr; + color btnSellColor; + color btnSellBGColor; + + // + // DRAW / REMOVE Button ... + CButton btnDrawRemove; + string btnDrawRemoveID; + string drawLabelStr; + string removeLabelStr; + color btnDrawColor; + color btnDrawBGColor; + color btnRemoveColor; + color btnRemoveBGColor; + + // + private: + // + + bool EnableBuy(bool value) + { + // + bool result = false; + + // + btnBuy.Locking(!value); + btnSell.Pressed(value); + if (!value) + { + // + // Disabled ... + btnBuy.Color(disabledBtnColor); + btnBuy.ColorBackground(disabledBtnBGColor); + } + else + { + // + // Enable ... + btnBuy.Color(btnBuyColor); + btnBuy.ColorBackground(btnBuyBGColor); + } + + // + return result; + } + + bool EnableSell(bool value) + { + // + bool result = false; + + // + btnSell.Locking(!value); + btnSell.Pressed(value); + if (!value) + { + // + // Disabled ... + btnSell.Color(disabledBtnColor); + btnSell.ColorBackground(disabledBtnBGColor); + } + else + { + // + // Enable ... + btnSell.Color(btnSellColor); + btnSell.ColorBackground(btnSellBGColor); + } + + // + return result; + } + + bool SetDrawMode() + { + // + bool result = false; + + // + result = btnDrawRemove.Text(drawLabelStr); + result = btnDrawRemove.Color(btnDrawColor); + result = btnDrawRemove.ColorBackground(btnDrawBGColor); + + // + return result; + } + + bool SetRemoveMode() + { + // + bool result = false; + + // + result = btnDrawRemove.Text(removeLabelStr); + result = btnDrawRemove.Color(btnRemoveColor); + result = btnDrawRemove.ColorBackground(btnRemoveBGColor); + + // + return result; + } + + void HandleDrawObjects() + { + // + double entry = GetBid(_Symbol); + double points = GetPoints(_Symbol); + double riskRatio = defaultRisk * points; + double rewardRatio = riskRatio * defaultR2R; + double sl = entry - riskRatio; + double tp = entry + rewardRatio; + + // + datetime rectTime1 = iTime( + _Symbol, + _Period, + 20 // + ); + datetime rectTime2 = iTime( + _Symbol, + _Period, + 19 // + ); + + // + bool has = false; + + // + // Create Entry Line ... + entryLine = new CChartObjectHLine(); + has = entryLine.Create( + chartId, + entryID, + subWindow, + entry // + ); + if (!has) + { + // + HandleRemoveObjects(); + return; + } + entryLine.Selectable(false); + entryLine.Color(entryColor); + + // + // Create SL Line ... + slLine = new CChartObjectHLine(); + has = slLine.Create( + chartId, + slID, + subWindow, + sl // + ); + if (!has) + { + // + HandleRemoveObjects(); + return; + } + slLine.Color(slColor); + slLine.Selectable(true); + + // + // Create TP Line ... + tpLine = new CChartObjectHLine(); + has = tpLine.Create( + chartId, + tpID, + subWindow, + tp // + ); + if (!has) + { + // + HandleRemoveObjects(); + return; + } + tpLine.Color(tpColor); + tpLine.Selectable(true); + + // + CalculateData(); + } + + void HandleRemoveObjects() + { + // + if (HasSL()) + { + // + slLine.Delete(); + slLine.Detach(); + ZeroMemory(slLine); + } + + // + if (HasTP()) + { + // + tpLine.Delete(); + tpLine.Detach(); + ZeroMemory(tpLine); + } + + // + if (HasEntry()) + { + // + entryLine.Delete(); + entryLine.Detach(); + ZeroMemory(entryLine); + } + + // + UpdateState(); + CalculateData(); + } + + void CalculateData() + { + // + EnableBuy(false); + EnableSell(false); + + // + ENUM_X_DIRECTION dir; + bool has = GetDirection(dir); + if (!has) + { + return; + } + + // + bool isBullish = IsBullish(dir); + bool isBearish = IsBearish(dir); + + // + if (isBullish) + { + // + EnableBuy(true); + EnableSell(false); + } + else if (isBearish) + { + // + EnableSell(true); + EnableBuy(false); + } + + // + double sl = ReadSL(); + double tp = ReadTP(); + double entry = ReadEntry(); + double points = GetPoints(_Symbol); + + // + double risk = MathAbs(entry - sl); + int riskPoints = (int)(risk / points); + double riskRewardRatio = MathAbs(tp - entry) / risk; + riskRewardRatio = NormalizeDouble(riskRewardRatio, 2); + + // + double balance = GetBalance(); + + // + double riskAmount = riskPercent * (balance / 100); + riskAmount = NormalizePrice(riskAmount, _Symbol); + + // + double rewardAmount = riskAmount * riskRewardRatio; + rewardAmount = NormalizePrice(rewardAmount, _Symbol); + + // + string currency = mTrader.mAccount.GetCurrency(); + + // + volume = mTrader + .mAccount + .CalculateVolume( + _Symbol, + riskAmount, + riskPoints // + ); + volume = NormalizeVolume(volume, _Symbol); + + // + string slDesc = "SL: " + ToString(sl) + + ", Risk: " + ToString(riskPoints) + " pt (" + ToString(riskPercent) + "%)" + + ", Amount: " + ToString(riskAmount) + currency; + slLine.Tooltip(slDesc); + slLine.Description(slDesc); + + // + string tpDesc = "TP: " + ToString(tp) + " (" + ToString(rewardAmount) + " " + currency + ")" + + ", R2R: 1:" + ToString(riskRewardRatio); + tpLine.Tooltip(tpDesc); + tpLine.Description(tpDesc); + + // + string entryDesc = "Entry: " + ToString(entry) + + ", Volume: " + ToString(volume); + entryLine.Tooltip(entryDesc); + entryLine.Description(entryDesc); + + // + } + + void SetEntry(double value) + { + // + if (value <= 0 || + !HasEntry()) + { + return; + } + + // + bool has = entryLine + .SetDouble(OBJPROP_PRICE, value); + } + + double GetBalance() + { + // + double result = 0; + + // + // TODO: Change This ... + return mTrader.mAccount.GetBalance(); + + // + return result; + } + + // +}; + +// \ No newline at end of file diff --git a/Documents/BKP/workingZone.zone.box.mq5 b/Documents/BKP/workingZone.zone.box.mq5 index 90510180..5cc71c25 100644 --- a/Documents/BKP/workingZone.zone.box.mq5 +++ b/Documents/BKP/workingZone.zone.box.mq5 @@ -2382,6 +2382,602 @@ if (useSenario1) } //////////////////////////////////////////////////////////////////////// + // + bool HasSenario1Conditions( + ENUM_X_CYCLES cycle, + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + X121SMCStrategySignalProviderData &provider, + ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Fil Selected Data ... + XPOIState cState; + X121Conditions cXConditions; + XC121SMCCycleHelper *cHelper; + X121SMCCycleConditions cConditions; + result = provider.SelectCycle( + cycle, + cState, + cXConditions, + cHelper, + cConditions // + ); + if (!result) + { + // + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + + // + return result; + } + Parse(cXConditions); + + // + // Fil Selected Data ... + XPOIState chState; + X121Conditions chXConditions; + XC121SMCCycleHelper *chHelper; + X121SMCCycleConditions chConditions; + if (holderCycle != X_CYCLE_NONE) + { + // + result = provider.SelectCycle( + holderCycle, + chState, + chXConditions, + chHelper, + chConditions // + ); + if (!result) + { + // + chState.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + + // + Parse(chXConditions); + } + + // + // Normalize Args ... + + // + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + int zIDX = barIndex; + int cIDX = zIDX + 1; + int pIDX = cIDX + 1; + + // + bool isBullish = false; + bool isBearish = false; + + // + XOHCL zBar; + XOHCL cBar; + XOHCL pBar; + XOHCL cSMHKBar; + + // + // Initial Bars ... + result = zBar.Init( + cState.symbol, + cState.period, + barIndex // + ); + result = + result && + zBar.GetPreviousBar(cBar); + result = + result && + cBar.GetPreviousBar(pBar); + result = + result && + cHelper + .mX121Helper + .xhkHelper + .GetSMHKAsXOHCL( + cIDX, + cSMHKBar // + ); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + chState.Clean(); + cSMHKBar.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + + // + // + // Detecting Signal Conditions ... + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + cXConditions.isSMHKSwitchedToBullish && + ( + // + // Validate CBar ... + cBar.IsBullish() && + (cBar.open == cSMHKBar.open || + (cBar.low < cSMHKBar.open && + cBar.GetDown() > cSMHKBar.close)) && + // + cXConditions.isSarBullish + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + cXConditions.isSMHKSwitchedToBearish && + ( + // + // Validate CBar ... + cBar.IsBearish() && + (cBar.open == cSMHKBar.open || + (cBar.high > cSMHKBar.open && + cBar.GetUp() < cSMHKBar.close)) && + // + cXConditions.isSarBearish + // + ) + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + box.dir = dir; + box.to = TimeCurrent(); + box.symbol = cXConditions.symbol; + box.period = cXConditions.period; + + // + int fromIDX = -1; + if (isBullish) + { + // + double vale = cXConditions.valesBuffer[cIDX]; + box.lower = vale; + box.upper = cXConditions.valesGoldenBuffer[cIDX]; + + // + int lowerValeIDX = -1; + double lowerVale = cHelper + .mX121Helper + .xpvHelper + .GetLowerVale( + lowerValeIDX, + vale, + cBar.Index() // + ); + + // + int higherValeIDX = -1; + double higherVale = cHelper + .mX121Helper + .xpvHelper + .GetHigherVale( + higherValeIDX, + vale, + cBar.Index() // + ); + + // + if (IsValidIndex(lowerValeIDX) && + IsValidIndex(higherValeIDX)) + { + // + fromIDX = + lowerValeIDX < higherValeIDX + ? lowerValeIDX + : higherValeIDX; + } + else if (IsValidIndex(lowerValeIDX) && + !IsValidIndex(higherValeIDX)) + { + // + fromIDX = lowerValeIDX; + } + else if (!IsValidIndex(lowerValeIDX) && + IsValidIndex(higherValeIDX)) + { + // + fromIDX = higherValeIDX; + } + } + else + { + // + double peak = cXConditions.peaksBuffer[cIDX]; + box.upper = peak; + + // + box.lower = cXConditions.peaksGoldenBuffer[cIDX]; + + // + int lowerPeakIDX = -1; + double lowerPeak = cHelper + .mX121Helper + .xpvHelper + .GetLowerPeak( + lowerPeakIDX, + peak, + cBar.Index() // + ); + + // + int higherPeakIDX = -1; + double higherPeak = cHelper + .mX121Helper + .xpvHelper + .GetHigherPeak( + higherPeakIDX, + peak, + cBar.Index() // + ); + + // + if (IsValidIndex(lowerPeakIDX) && + IsValidIndex(higherPeakIDX)) + { + // + fromIDX = + lowerPeakIDX < higherPeakIDX + ? lowerPeakIDX + : higherPeakIDX; + } + else if (IsValidIndex(lowerPeakIDX) && + !IsValidIndex(higherPeakIDX)) + { + // + fromIDX = lowerPeakIDX; + } + else if (!IsValidIndex(lowerPeakIDX) && + IsValidIndex(higherPeakIDX)) + { + // + fromIDX = higherPeakIDX; + } + } + + // + if (IsValidIndex(fromIDX)) + { + // + box.from = iTime( + zBar.symbol, + zBar.period, + fromIDX // + ); + } + else + { + box.from = pBar.time; + } + + // + // Detect Holder Box ... + XBoxZone tmpBoxes[]; + if (chState.IsValid()) + { + // + if (isBullish) + { + // + // Demand Zones ... + XBoxZone tmp[]; + ToBox( + chState.demandZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bullish Order Blocks ... + ToBox( + chState.bullishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bullish Fair Value Gaps ... + ToBox( + chState.bullishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + } + else + { + // + // Supply Zones ... + XBoxZone tmp[]; + ToBox( + chState.supplyZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bearish Order Blocks ... + ToBox( + chState.bearishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bearish Fair Value Gaps ... + ToBox( + chState.bearishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + } + } + + // + has = HasChild(tmpBoxes); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetOldest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + has = IsBoxInside( + box, + iBox // + ); + if (has) + { + // + holderBox = iBox; + holderBox.to = TimeCurrent(); + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + + // + Clean(tmpBoxes); + + // + // Fix Box Upper and Lower based on Strategy ... + + // + double points = GetPoints(box.symbol); + double minPointsDiff = points * 20; + + // + double prefferSL = 0; + + // + // First Check Based on Prev Bar ... + // double prevDiff = + // isBullish + // ? cBar.low < zBar.open + // ? zBar.open - cBar.low + // : 0 + // : isBearish + // ? cBar.high > zBar.open + // ? cBar.high - zBar.open + // : 0 + // : 0; + // if (prevDiff >= minPointsDiff) + // { + // // + // prefferSL = + // isBullish + // ? cBar.low + // : cBar.high; + // } + + // + // Other SL Conditions ... + if (prefferSL <= 0) + { + // + if (isBullish) + { + // + if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) + { + prefferSL = cXConditions.valesBuffer[cIDX]; + } + else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX]) + { + prefferSL = cXConditions.valesGoldenBuffer[cIDX]; + } + } + else + { + // + if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) + { + prefferSL = cXConditions.peaksBuffer[cIDX]; + } + else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX]) + { + prefferSL = cXConditions.peaksGoldenBuffer[cIDX]; + } + } + } + + // + if (prefferSL > 0) + { + // + prefferSL = + prefferSL <= minPointsDiff + ? minPointsDiff + : prefferSL; + + // + box.upper = + isBullish + ? zBar.open + : prefferSL; + + // + box.lower = + isBullish + ? prefferSL + : zBar.open; + } + + // + // Validate Conditions to Force Has Holder Box ... + // result = + // result && + // holderBox.IsValid(); + result = box.IsValid(); + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + chState.Clean(); + cSMHKBar.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } //////////////////////////////////////////////////////////////////////// diff --git a/Experts/x-saherelm.rr.tools.mq5 b/Experts/x-saherelm.rr.tools.mq5 new file mode 100644 index 00000000..31661054 --- /dev/null +++ b/Experts/x-saherelm.rr.tools.mq5 @@ -0,0 +1,431 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XTest MQL5 Expert Advisor +// ------------------------------------------------- +// Name: XRRToolsEA +// Description: a Template For Exper Advisors +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////x +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XRRToolsEA" +#property strict + +// +#define ShortName "XRRTools" + +// +// Imports ... +#include "../Classes/x-saherelm.x-alert.class.mq5" +#include "../Classes/x-saherelm.x-rm.panel.class.mq5" +#include "../Classes/x-saherelm.x-trade.class.mq5" +#include "../Helpers/x-saherelm.x121.xcc.helper.mq5" +#include "../Helpers/x-saherelm.x121.xct.helper.mq5" + +// +// Inputs ... + +// +// Common ... +input group "Common"; +input long eaMagicNumber = 78692110; // Magic Number +input int eaSlippage = 10; // Slippgae +input string eaLogSuffix = ""; // Log Suffix + +// +// Alert ... +// Here we Provider All Requirements for +// Configuring Alert Provider ... +input group "Alert"; +input bool eAEnableAlerts = true; // Enable Alerts +input bool eALogAlerts = true; // Log Alerts +input bool eAMailAlerts = false; // Mail Alerts +input bool eAPushAlerts = false; // Push Alerts +input bool eATerminalAlerts = false; // Terminal Alerts + +// +// Define Local Variables ... + +// +string eaLogTag; // EA Log Prefix ... +XCAlert *eaAlert; // Alert Provider for Expert Adviser ... +XCTrade *eaTrader; // Trader of Expert Adviser ... +XCRMPanel eaMainWindow; // Main Window ... +XCX121XCTHelper *eaCTHelper; // Bar Timer Indicator Helper class ... +XCX121XCCHelper *eaCCHelper; // Chart Styler Indicator Helper Class ... + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs and Required Parameters + // for EA to Works fine ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Initialize Timer ... + if (!InitTimer()) + { + return INIT_FAILED; + } + + // + // Initialize all Requirements ... + if (!InitEA()) + { + return INIT_FAILED; + } + + // + // Initialize all GUI Objects and Classes ... + if (!InitGUI()) + { + return INIT_FAILED; + } + + // + // Alert Initialization ... + string msg = "Initialized Successfully ..."; + eaAlert.Alert(msg); + + // + // 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 + + // + // Destroy Timer ... + DestroyTimer(); + + // + // Destroy all GUI Requirements ... + DestroyGUI(); + + // + // Alert De Initialization Succeeded ... + string msg = "De Initialized Successfully ..."; + eaAlert.Alert(msg); + + // + // Destroy all EA Requirements ... + DestroyEA(); +} + +// +// On Tick Handler ... +void OnTick() +{ + // + UpdateGUI(); +} + +// +// Handle On Trade Event ... +void OnTrade() +{ + eaTrader.HandleOnTrade(); +} + +// +// On Timer ... +void OnTimer() +{ + // + // TODO: Implement Time Based Functionalities ... +} + +// +// Chart Event Handler ... +void OnChartEvent( + const int id, + const long &lparam, + const double &dparam, + const string &sparam // +) +{ + // + // Apply Chart Event on Main Window ... + eaMainWindow.ChartEvent(id, lparam, dparam, sparam); +} + +// +// Custom Event Handlers ... + +/** + * Handle StopLoss Triggered Positions ... + * + * @param deal: XDeal ... + */ +void OnStopLossTriggered(const XDeal &deal) +{ +} + +/** + * Handle Take Profit Triggered Positions ... + * + * @param deal: XDeal ... + */ +void OnTakeProfitTriggered(const XDeal &deal) +{ +} + +/** + * Handle Force Close a Position ... + * + * @param ticket: Position Ticket ... + * @param position: XPosition ... + * @param comment: Closing Comment ... + */ +void OnPositionForceClosed( + const ulong ticket, + const XPosition &position, + const string comment // +) +{ +} + +// +// Custom Functions ... + +/** + * Validate all Inputs of Expert Adviser ... + * + * @return ( bool ) + */ +bool ValidateInputs() +{ + // + bool result = false; + + // + string errMessage = ""; + + // + bool isCommonValid = ( + // + eaSlippage > 0 && + eaMagicNumber > 0 + // + ); + if (!isCommonValid) + { + // + errMessage += "common configurations error;" + "\n"; + } + + // + result = + // + // Common ... + isCommonValid && + // + // Otere ... + true + // + ; + + // + if (!result) + { + // + // Since here Logger not Initiallized, we Use Raw Print Command ... + Print(ShortName + " Errors: \n", errMessage); + } + + // + return result; +} + +/** + * Initialize Timer ... + * + * @return ( bool ) + */ +bool InitTimer() +{ + // + bool result = false; + + // + // TODO: Initialize Timer if necessary ... + // result = EventSetTimer(1); + // result = EventSetMillisecondTimer(100); + result = true; + + // + return result; +} + +/** + * Destroy Timer ... + */ +void DestroyTimer() +{ + // + // TODO: Use This ... + // EventKillTimer(); +} + +/** + * Initialize all Requirements for Working Fine ... + * + * @return ( bool ) + */ +bool InitEA() +{ + // + bool result = false; + + // + // Locally Apply Changes on Prefix ... + eaLogTag = ShortName + ">" + eaLogSuffix; + + // + // Bar Timer ... + X121XCTInputs ctInputs; + ctInputs.Default(); // Default Configurations ... + eaCTHelper = new XCX121XCTHelper(); + result = eaCTHelper.Init( + _Symbol, + _Period, + ctInputs // + ); + if (!result) + { + return result; + } + + // + // Bar Styles ... + X121XCCInputs ccInputs; + ccInputs.Default(); // Default Configurations ... + eaCCHelper = new XCX121XCCHelper(); + result = eaCCHelper.Init( + _Symbol, + _Period, + ccInputs // + ); + if (!result) + { + return result; + } + + // + // Create Instance of Alert Class and Configure it ... + eaAlert = new XCAlert(); + eaAlert.SetPrefix(eaLogTag); + eaAlert.SetLogAlerts(eALogAlerts); + eaAlert.SetMailAlerts(eAMailAlerts); + eaAlert.SetPushAlerts(eAPushAlerts); + eaAlert.SetEnableAlerts(eAEnableAlerts); + eaAlert.SetTerminalAlerts(eATerminalAlerts); + + // + // Create Trader Instance and Configure it ... + eaTrader = new XCTrade( + eaSlippage, + eaMagicNumber // + ); + eaTrader.AddOnStopLossEventHandler(OnStopLossTriggered); + eaTrader.AddOnTakeProfitEventHandler(OnTakeProfitTriggered); + eaTrader.AddOnForceClosePositionEventHandler(OnPositionForceClosed); + + // + return result; +} + +/** + * Destroy all Initialized EA Requirements ... + */ +void DestroyEA() +{ + // + delete eaCTHelper; + delete eaCCHelper; + + // + delete eaAlert; +} + +/** + * Initialize all GUI Requirements for EA ... + * + * @return ( bool ) + */ +bool InitGUI() +{ + // + bool result = false; + + // + // Initialize Application Main Window ... + result = eaMainWindow.Create( + ChartID(), + ShortName, // Dialog Name ... + 0, // SubWindow ... + 10, // X1 ... + 35, // Y1 ... + 300, // X2 ... + 200 // Y2 ... + ); + + // + // Try To Run Main Window ... + if (result) + { + eaMainWindow.Run(); + } + + // + return result; +} + +/** + * Update GUI based on Each Ticks ... + */ +void UpdateGUI() +{ + // + eaMainWindow.UpdateState(); +} + +/** + * Destroy all Initialized GUi Requirements ... + */ +void DestroyGUI() +{ + // + eaMainWindow.Destroy(); +} + +// diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 423a96b2..5dc4e86d 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -4531,6 +4531,22 @@ int GetDigits( return result; } +// +// Get Digits of Specified Double Value ... +int GetDigits(double num) +{ + // + int d = 0; + double p = 1; + while (MathRound(num * p) / p != num) + { + p = MathPow(10, ++d); + } + + // + return d; +} + // // Retrieve Entry Price ... double GetEntry( diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index 2f0f9dc8..81900a72 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -1441,7 +1441,15 @@ struct X121SMCStrategySignalProviderData } // - if (cycle == X_CYCLE_DECISION) + if (cycle == X_CYCLE_TRIGGER) + { + // + cState = triggerState; + cHelper = triggerCycleHelper; + cConditions = triggerConditions; + cXConditions = triggerXConditions; + } + else if (cycle == X_CYCLE_DECISION) { // cState = decisionState; @@ -1457,6 +1465,14 @@ struct X121SMCStrategySignalProviderData cConditions = analyseConditions; cXConditions = analyseXConditions; } + else if (cycle == X_CYCLE_VERIFICATION) + { + // + cState = verificationState; + cHelper = verificationCycleHelper; + cConditions = verificationConditions; + cXConditions = verificationXConditions; + } else if (cycle == X_CYCLE_CONSOLIDATION) { // @@ -2577,6 +2593,586 @@ struct X121SMCStrategyConditionParser return result; } + // + // + // Detecting Signal Conditions ... + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + cXConditions.isSMHKSwitchedToBullish && + ( + // + // Validate CBar ... + cBar.IsBullish() && + cBar.open >= cSMHKBar.open && + // + cXConditions.isSarBullish + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + cXConditions.isSMHKSwitchedToBearish && + ( + // + // Validate CBar ... + cBar.IsBearish() && + cBar.open <= cSMHKBar.open && + // + cXConditions.isSarBearish + // + ) + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + box.dir = dir; + box.to = TimeCurrent(); + box.symbol = cXConditions.symbol; + box.period = cXConditions.period; + + // + int fromIDX = -1; + if (isBullish) + { + // + double vale = cXConditions.valesBuffer[cIDX]; + box.lower = vale; + box.upper = cXConditions.valesGoldenBuffer[cIDX]; + + // + int lowerValeIDX = -1; + double lowerVale = cHelper + .mX121Helper + .xpvHelper + .GetLowerVale( + lowerValeIDX, + vale, + cBar.Index() // + ); + + // + int higherValeIDX = -1; + double higherVale = cHelper + .mX121Helper + .xpvHelper + .GetHigherVale( + higherValeIDX, + vale, + cBar.Index() // + ); + + // + if (IsValidIndex(lowerValeIDX) && + IsValidIndex(higherValeIDX)) + { + // + fromIDX = + lowerValeIDX < higherValeIDX + ? lowerValeIDX + : higherValeIDX; + } + else if (IsValidIndex(lowerValeIDX) && + !IsValidIndex(higherValeIDX)) + { + // + fromIDX = lowerValeIDX; + } + else if (!IsValidIndex(lowerValeIDX) && + IsValidIndex(higherValeIDX)) + { + // + fromIDX = higherValeIDX; + } + } + else + { + // + double peak = cXConditions.peaksBuffer[cIDX]; + box.upper = peak; + + // + box.lower = cXConditions.peaksGoldenBuffer[cIDX]; + + // + int lowerPeakIDX = -1; + double lowerPeak = cHelper + .mX121Helper + .xpvHelper + .GetLowerPeak( + lowerPeakIDX, + peak, + cBar.Index() // + ); + + // + int higherPeakIDX = -1; + double higherPeak = cHelper + .mX121Helper + .xpvHelper + .GetHigherPeak( + higherPeakIDX, + peak, + cBar.Index() // + ); + + // + if (IsValidIndex(lowerPeakIDX) && + IsValidIndex(higherPeakIDX)) + { + // + fromIDX = + lowerPeakIDX < higherPeakIDX + ? lowerPeakIDX + : higherPeakIDX; + } + else if (IsValidIndex(lowerPeakIDX) && + !IsValidIndex(higherPeakIDX)) + { + // + fromIDX = lowerPeakIDX; + } + else if (!IsValidIndex(lowerPeakIDX) && + IsValidIndex(higherPeakIDX)) + { + // + fromIDX = higherPeakIDX; + } + } + + // + if (IsValidIndex(fromIDX)) + { + // + box.from = iTime( + zBar.symbol, + zBar.period, + fromIDX // + ); + } + else + { + box.from = pBar.time; + } + + // + // Detect Holder Box ... + XBoxZone tmpBoxes[]; + if (chState.IsValid()) + { + // + if (isBullish) + { + // + // Demand Zones ... + XBoxZone tmp[]; + ToBox( + chState.demandZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bullish Order Blocks ... + ToBox( + chState.bullishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bullish Fair Value Gaps ... + ToBox( + chState.bullishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + } + else + { + // + // Supply Zones ... + XBoxZone tmp[]; + ToBox( + chState.supplyZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bearish Order Blocks ... + ToBox( + chState.bearishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bearish Fair Value Gaps ... + ToBox( + chState.bearishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + } + } + + // + has = HasChild(tmpBoxes); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetOldest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + has = IsBoxInside( + box, + iBox // + ); + if (has) + { + // + holderBox = iBox; + holderBox.to = TimeCurrent(); + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + + // + Clean(tmpBoxes); + + // + // Fix Box Upper and Lower based on Strategy ... + + // + double points = GetPoints(box.symbol); + double minPointsDiff = points * 20; + + // // + // double prefferSL = 0; + + // // + // // First Check Based on Prev Bar ... + // // double prevDiff = + // // isBullish + // // ? cBar.low < zBar.open + // // ? zBar.open - cBar.low + // // : 0 + // // : isBearish + // // ? cBar.high > zBar.open + // // ? cBar.high - zBar.open + // // : 0 + // // : 0; + // // if (prevDiff >= minPointsDiff) + // // { + // // // + // // prefferSL = + // // isBullish + // // ? cBar.low + // // : cBar.high; + // // } + + // // + // // Other SL Conditions ... + // if (prefferSL <= 0) + // { + // // + // if (isBullish) + // { + // // + // if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) + // { + // prefferSL = cXConditions.valesBuffer[cIDX]; + // } + // else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX]) + // { + // prefferSL = cXConditions.valesGoldenBuffer[cIDX]; + // } + // } + // else + // { + // // + // if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) + // { + // prefferSL = cXConditions.peaksBuffer[cIDX]; + // } + // else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX]) + // { + // prefferSL = cXConditions.peaksGoldenBuffer[cIDX]; + // } + // } + // } + + // // + // if (prefferSL > 0) + // { + // // + // prefferSL = + // prefferSL <= minPointsDiff + // ? minPointsDiff + // : prefferSL; + + // // + // box.upper = + // isBullish + // ? zBar.open + // : prefferSL; + + // // + // box.lower = + // isBullish + // ? prefferSL + // : zBar.open; + // } + + // + // Validate Conditions to Force Has Holder Box ... + result = + result && + holderBox.IsValid(); + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + chState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + + // + bool HasSenario4Conditions( + ENUM_X_CYCLES cycle, + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + X121SMCStrategySignalProviderData &provider, + ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Fil Selected Data ... + XPOIState cState; + X121Conditions cXConditions; + XC121SMCCycleHelper *cHelper; + X121SMCCycleConditions cConditions; + result = provider.SelectCycle( + cycle, + cState, + cXConditions, + cHelper, + cConditions // + ); + if (!result) + { + // + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + + // + return result; + } + Parse(cXConditions); + + // + // Fil Selected Data ... + XPOIState chState; + X121Conditions chXConditions; + XC121SMCCycleHelper *chHelper; + X121SMCCycleConditions chConditions; + if (holderCycle != X_CYCLE_NONE) + { + // + result = provider.SelectCycle( + holderCycle, + chState, + chXConditions, + chHelper, + chConditions // + ); + if (!result) + { + // + chState.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + + // + Parse(chXConditions); + } + + // + // Normalize Args ... + + // + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + int zIDX = barIndex; + int cIDX = zIDX + 1; + int pIDX = cIDX + 1; + + // + bool isBullish = false; + bool isBearish = false; + + // + XOHCL zBar; + XOHCL cBar; + XOHCL pBar; + + // + // Initial Bars ... + result = zBar.Init( + cState.symbol, + cState.period, + barIndex // + ); + result = + result && + zBar.GetPreviousBar(cBar); + result = + result && + cBar.GetPreviousBar(pBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + chState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + // // Detecting Signal Conditions ... diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index e8972054..227d6bc3 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -457,11 +457,19 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Select and Provide SL Based on ... + double iAtr = 0; if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_MA) { + // + iAtr = provider.decisionXConditions.atrBuffer[1]; + iAtr *= 1.5; } else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_BOX) { + // + iAtr = provider.decisionXConditions.atrBuffer[1]; + iAtr *= 1.5; + // // // if (isBullish) // { @@ -498,12 +506,11 @@ class XCX121SMCXWZSignalDetector : public XCBase } else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_AREA) { + // + iAtr = provider.decisionXConditions.atrBuffer[1]; + iAtr *= 1.5; } - // - double iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; - // // Select Condition SL ... diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 87332620..c4050df0 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -31,10 +31,10 @@ enum ENUM_X121SMC_XWZ_PROVIDERS { X121SMC_XWZ_PROVIDER_NONE, + X121SMC_XWZ_PROVIDER_PVHK, X121SMC_XWZ_PROVIDER_ACTIVATED_MA, X121SMC_XWZ_PROVIDER_ACTIVATED_BOX, X121SMC_XWZ_PROVIDER_ACTIVATED_AREA, - X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, }; // @@ -232,6 +232,88 @@ struct X121SMCStrategyXWZWorkingZone return result; } + /** + * Checking a Box Exists in Collections or not ... + * + * @param box: XBoxZone instance reference ... + * + * @return ( bool ) + */ + bool IsExists(XBoxZone &box) + { + // + bool result = false; + + // + // Check Validation ... + result = box.IsValid() && + (HasWaitingBoxes() || + HasBreakedBoxes() || + HasUnavailableBoxes()); + if (!result) + { + return result; + } + + // + int idx = -1; + bool has = false; + + // + // Check Index in Waiting Boxes ... + has = HasWaitingBoxes(); + if (has) + { + // + idx = FindIndex( + box, + waitingBoxes // + ); + result = IsValidIndex(idx); + if (result) + { + return result; + } + } + + // + // Check Index in Breaked Boxes ... + has = HasBreakedBoxes(); + if (has) + { + // + idx = FindIndex( + box, + breakedBoxes // + ); + result = IsValidIndex(idx); + if (result) + { + return result; + } + } + + // + // Check Index in Unavailable Boxes ... + has = HasUnavailableBoxes(); + if (has) + { + // + idx = FindIndex( + box, + unavailableBoxes // + ); + result = IsValidIndex(idx); + if (result) + { + return result; + } + } + + // + return result; + } + /** * Initialize Working Zone ... * @@ -571,522 +653,6 @@ struct X121SMCStrategyXWZWorkingZone return result; } - /** - * Detect Signal Box Conditions ... - * - * @param box: XBoxZone instance reference, Signalled Box ... - * @param holderBox: XBoxZone instance reference, Signalled Holder Box ... - * @param dir: ENUM_X_DIRECTION member, Specified Signal Direction ... - * @param signalProvider: ENUM_X121SMC_XWZ_PROVIDERS member, Specified Signal Type ... - * @param provider: X121SMCStrategySignalProviderData instance reference ... - * @param barIndex: int ... - * - * @return ( bool ) - */ - bool DetectSignalConditions( - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - ENUM_X121SMC_XWZ_PROVIDERS &signalProvider, - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Normalize Bars ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - signalProvider = X121SMC_XWZ_PROVIDER_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - ENUM_X_DIRECTION trend; - result = IsValid() && - DetectOveralDirection(trend); - if (!result) - { - return result; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - X121SMCStrategyConditionParser cParser; - - // - // Senario 1: - // --------------------------------------------- - // Detect Signal Box Based On Conditions ... - // --------------------------------------------- - bool useSenario1 = false; - bool isSenario1Happend = false; - bool isSenario1Bullish = false; - bool isSenario1Bearish = false; - if (useSenario1) - { - // - isSenario1Happend = cParser.HasSenario1Conditions( - X_CYCLE_ANALYSE, - box, - holderBox, - dir, - provider, - X_CYCLE_CONSOLIDATION, - barIndex // - ); - - // - isSenario1Bullish = - isSenario1Happend && - IsBullish(dir); - - // - isSenario1Bearish = - isSenario1Happend && - IsBearish(dir); - - // - if (isSenario1Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - } - } - - // - // Senario 2: - // --------------------------------------------------- - // Detect Signal Based On Breaked Rejection Boxes ... - // --------------------------------------------------- - bool useSenario2 = true; - bool isSenario2Happend = false; - bool isSenario2Bullish = false; - bool isSenario2Bearish = false; - if (useSenario2) - { - // - // Senario 2 Working Based on - // Breaked Boxes ... - // Since we Works only - // when Has UnAvailable Boxes ... - has = HasUnavailableBoxes(); - if (has) - { - // - isSenario2Happend = cParser.HasSenario2Conditions( - X_CYCLE_DECISION, - trend, - unavailableBoxes, - box, - dir, - provider, - barIndex // - ); - - // - isSenario2Bullish = - isSenario2Happend && - IsBullish(dir); - - // - isSenario2Bearish = - isSenario2Happend && - IsBearish(dir); - - // - if (isSenario2Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - } - } - } - - // - // Senario 3: - // ---------- - bool useSenario3 = false; - bool isSenario3Happend = false; - bool isSenario3Bullish = false; - bool isSenario3Bearish = false; - if (useSenario3) - { - } - - // - // Senario 4: - // ---------- - bool useSenario4 = false; - bool isSenario4Happend = false; - bool isSenario4Bullish = false; - bool isSenario4Bearish = false; - if (useSenario4) - { - } - - // - // Summarize All Senario(s) Conditions ... - - // - isBullish = - // - isSenario1Bullish || - isSenario2Bullish || - isSenario3Bullish || - isSenario3Bullish - // - ; - - // - isBearish = - // - isSenario1Bearish || - isSenario2Bearish || - isSenario3Bearish || - isSenario3Bearish - // - ; - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - if (!result) - { - // - box.Clean(); - holderBox.Clean(); - } - - // - return result; - } - - /** - * Checking a Box Exists in Collections or not ... - * - * @param box: XBoxZone instance reference ... - * - * @return ( bool ) - */ - bool IsExists(XBoxZone &box) - { - // - bool result = false; - - // - // Check Validation ... - result = box.IsValid() && - (HasWaitingBoxes() || - HasBreakedBoxes() || - HasUnavailableBoxes()); - if (!result) - { - return result; - } - - // - int idx = -1; - bool has = false; - - // - // Check Index in Waiting Boxes ... - has = HasWaitingBoxes(); - if (has) - { - // - idx = FindIndex( - box, - waitingBoxes // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - } - - // - // Check Index in Breaked Boxes ... - has = HasBreakedBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedBoxes // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - } - - // - // Check Index in Unavailable Boxes ... - has = HasUnavailableBoxes(); - if (has) - { - // - idx = FindIndex( - box, - unavailableBoxes // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - } - - // - return result; - } - - /** - * Check Working Zone is Destroyed or not ... - * - * @param barIndex: int, bar index ... - * @param forPeriod: ENUM_TIMEFRAMES member ... - * - * @return ( bool ) - */ - bool IsDestroyed( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - period, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - XOHCL cBar; - result = bar.GetPreviousBar(cBar); - if (!result) - { - // - bar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - bool isSupplyZoneBreaked = - // - bar.low > supplyZone.Upper() && - cBar.low > supplyZone.Upper() - // - ; - - // - bool isDemandZoneBreaked = - // - bar.high < demandZone.Lower() && - cBar.high < demandZone.Lower() - // - ; - - // - bar.Clean(); - cBar.Clean(); - - // - result = isSupplyZoneBreaked || - isDemandZoneBreaked; - - // - return result; - } - - /** - * Detect a Signal Priority forDynamic Risk Reward ratio ... - * - * @param priority: ENUM_X121SMC_XWZ_PRIORITY member, holds Specified position Priority ... - * @param forDir: ENUM_X_DIRECTION member, Specified Position Direction for Priority ... - * @param barIndex: int ... - * @param forPeriod: ENUM_TIMEFRAMES member ... - * - * @return ( bool ) - */ - bool DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &priority, - ENUM_X_DIRECTION forDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - priority = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - if (bar.high < supplyZone.Upper() && - bar.low > supplyZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_NONE - : X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - else if (bar.high < supplyZone.Lower() && - bar.low > quarter1) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_WEAK - : X121SMC_XWZ_PRIORITY_HIGH; - } - else if (bar.high < quarter1 && - bar.low > quarter2) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_LOW - : X121SMC_XWZ_PRIORITY_REGULAR; - } - else if (bar.high < quarter2 && - bar.low > quarter3) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_REGULAR - : X121SMC_XWZ_PRIORITY_LOW; - } - else if (bar.high < quarter3 && - bar.low > demandZone.Upper()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_HIGH - : X121SMC_XWZ_PRIORITY_WEAK; - } - else if (bar.high < demandZone.Upper() && - bar.low > demandZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_STRONG_HIGH - : X121SMC_XWZ_PRIORITY_NONE; - } - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE && - priority != X121SMC_XWZ_PRIORITY_WEAK; - - // - bar.Clean(); - - // - return result; - } - /** * Detect Overal Trend of Working Zone ... * @@ -1242,6 +808,482 @@ struct X121SMCStrategyXWZWorkingZone // } + /** + * Check Working Zone is Destroyed or not ... + * + * @param barIndex: int, bar index ... + * @param forPeriod: ENUM_TIMEFRAMES member ... + * + * @return ( bool ) + */ + bool IsDestroyed( + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + XOHCL bar; + result = bar.Init( + symbol, + period, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + XOHCL cBar; + result = bar.GetPreviousBar(cBar); + if (!result) + { + // + bar.Clean(); + cBar.Clean(); + + // + return result; + } + + // + bool isSupplyZoneBreaked = + // + bar.low > supplyZone.Upper() && + cBar.low > supplyZone.Upper() + // + ; + + // + bool isDemandZoneBreaked = + // + bar.high < demandZone.Lower() && + cBar.high < demandZone.Lower() + // + ; + + // + bar.Clean(); + cBar.Clean(); + + // + result = isSupplyZoneBreaked || + isDemandZoneBreaked; + + // + return result; + } + + /** + * Detect Signal Box Conditions ... + * + * @param box: XBoxZone instance reference, Signalled Box ... + * @param holderBox: XBoxZone instance reference, Signalled Holder Box ... + * @param dir: ENUM_X_DIRECTION member, Specified Signal Direction ... + * @param signalProvider: ENUM_X121SMC_XWZ_PROVIDERS member, Specified Signal Type ... + * @param provider: X121SMCStrategySignalProviderData instance reference ... + * @param barIndex: int ... + * + * @return ( bool ) + */ + bool DetectSignalConditions( + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + ENUM_X121SMC_XWZ_PROVIDERS &signalProvider, + X121SMCStrategySignalProviderData &provider, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Normalize Bars ... + + // + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; + signalProvider = X121SMC_XWZ_PROVIDER_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + ENUM_X_DIRECTION trend; + result = IsValid(); + //&& + // DetectOveralDirection(trend); + if (!result) + { + return result; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + int zIDX = barIndex; + int cIDX = zIDX + 1; + int pIDX = cIDX + 1; + + // + bool isBullish = false; + bool isBearish = false; + + // + X121SMCStrategyConditionParser cParser; + + // + // Senario 1: + // --------------------------------------------- + // XPVHK Conditions ... + // --------------------------------------------- + bool useSenario1 = true; + bool isSenario1Happend = false; + bool isSenario1Bullish = false; + bool isSenario1Bearish = false; + if (useSenario1) + { + // + isSenario1Happend = cParser.HasSenario1Conditions( + X_CYCLE_DECISION, + box, + holderBox, + dir, + provider, + X_CYCLE_ANALYSE, + barIndex // + ); + + // + isSenario1Bullish = + isSenario1Happend && + IsBullish(dir); + + // + isSenario1Bearish = + isSenario1Happend && + IsBearish(dir); + + // + if (isSenario1Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_PVHK; + } + } + + // + // Senario 2: + // --------------------------------------------------- + // Detect Signal Based On Breaked Rejection Boxes ... + // --------------------------------------------------- + bool useSenario2 = false; + bool isSenario2Happend = false; + bool isSenario2Bullish = false; + bool isSenario2Bearish = false; + if (useSenario2) + { + // + // Senario 2 Working Based on + // Breaked Boxes ... + // Since we Works only + // when Has UnAvailable Boxes ... + has = HasBreakedBoxes(); + if (has) + { + // + isSenario2Happend = cParser.HasSenario2Conditions( + X_CYCLE_DECISION, + trend, + breakedBoxes, + box, + dir, + provider, + barIndex // + ); + + // + isSenario2Bullish = + isSenario2Happend && + IsBullish(dir); + + // + isSenario2Bearish = + isSenario2Happend && + IsBearish(dir); + + // + if (isSenario2Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; + } + } + } + + // + // Senario 3: + // --------------------------------------------- + // --------------------------------------------- + bool useSenario3 = false; + bool isSenario3Happend = false; + bool isSenario3Bullish = false; + bool isSenario3Bearish = false; + if (useSenario3) + { + } + + // + // Senario 4: + // --------------------------------------------- + // Detect Signal Box Based On Conditions ... + // --------------------------------------------- + bool useSenario4 = false; + bool isSenario4Happend = false; + bool isSenario4Bullish = false; + bool isSenario4Bearish = false; + if (useSenario4) + { + // + isSenario4Happend = cParser.HasSenario4Conditions( + X_CYCLE_ANALYSE, + box, + holderBox, + dir, + provider, + X_CYCLE_CONSOLIDATION, + barIndex // + ); + + // + isSenario4Bullish = + isSenario4Happend && + IsBullish(dir); + + // + isSenario4Bearish = + isSenario4Happend && + IsBearish(dir); + + // + if (isSenario4Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; + } + } + + // + // Senario 5: + // --------------------------------------------- + // --------------------------------------------- + bool useSenario5 = false; + bool isSenario5Happend = false; + bool isSenario5Bullish = false; + bool isSenario5Bearish = false; + if (useSenario5) + { + } + + // + // Summarize All Senario(s) Conditions ... + + // + isBullish = + // + isSenario1Bullish || + isSenario2Bullish || + isSenario3Bullish || + isSenario4Bullish + // + ; + + // + isBearish = + // + isSenario1Bearish || + isSenario2Bearish || + isSenario3Bearish || + isSenario4Bearish + // + ; + + // + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); + + // + if (!result) + { + // + box.Clean(); + holderBox.Clean(); + } + + // + return result; + } + + /** + * Detect a Signal Priority forDynamic Risk Reward ratio ... + * + * @param priority: ENUM_X121SMC_XWZ_PRIORITY member, holds Specified position Priority ... + * @param forDir: ENUM_X_DIRECTION member, Specified Position Direction for Priority ... + * @param barIndex: int ... + * @param forPeriod: ENUM_TIMEFRAMES member ... + * + * @return ( bool ) + */ + bool DetectPriority( + ENUM_X121SMC_XWZ_PRIORITY &priority, + ENUM_X_DIRECTION forDir, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + priority = X121SMC_XWZ_PRIORITY_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid() && + HasDirection(forDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL bar; + result = bar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + if (bar.high < supplyZone.Upper() && + bar.low > supplyZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_NONE + : X121SMC_XWZ_PRIORITY_STRONG_HIGH; + } + else if (bar.high < supplyZone.Lower() && + bar.low > quarter1) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_WEAK + : X121SMC_XWZ_PRIORITY_HIGH; + } + else if (bar.high < quarter1 && + bar.low > quarter2) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_LOW + : X121SMC_XWZ_PRIORITY_REGULAR; + } + else if (bar.high < quarter2 && + bar.low > quarter3) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_REGULAR + : X121SMC_XWZ_PRIORITY_LOW; + } + else if (bar.high < quarter3 && + bar.low > demandZone.Upper()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_HIGH + : X121SMC_XWZ_PRIORITY_WEAK; + } + else if (bar.high < demandZone.Upper() && + bar.low > demandZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_STRONG_HIGH + : X121SMC_XWZ_PRIORITY_NONE; + } + + // + result = priority != X121SMC_XWZ_PRIORITY_NONE && + priority != X121SMC_XWZ_PRIORITY_WEAK; + + // + bar.Clean(); + + // + return result; + } + /** * Draw Working Zne and all of * it's Collections and Conditions ... diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index a2c8cbf5..03b130d6 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -792,22 +792,22 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XPV ... - x121Inputs.xpvInputs.showSar = showAll || false; - x121Inputs.xpvInputs.showPeaks = showAll || false; - x121Inputs.xpvInputs.showVales = showAll || false; - x121Inputs.xpvInputs.showGoldenZones = showAll || false; + x121Inputs.xpvInputs.showSar = showAll || true; + x121Inputs.xpvInputs.showPeaks = showAll || true; + x121Inputs.xpvInputs.showVales = showAll || true; + x121Inputs.xpvInputs.showGoldenZones = showAll || true; // // XHK ... // x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false; - x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || false; + x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || true; // // XATR ... - x121Inputs.xatrInputs.showATRUpper = showAll || true; - x121Inputs.xatrInputs.showATRLower = showAll || true; + x121Inputs.xatrInputs.showATRUpper = showAll || false; + x121Inputs.xatrInputs.showATRLower = showAll || false; // // XSTR ... @@ -850,69 +850,12 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // int requiredPOIS = MaxAllowedRequiredPOIs(); - // - // Decision Cycle ... - mDecisionCycleHelper = new XC121SMCCycleHelper(); - isInited = mDecisionCycleHelper.Init( - symbol, - PERIOD_M1, - x121Inputs, - requiredPOIS // - ); - if (isInited) - { - // - // Configure POI Drawer ... - color bullishColor = clrDodgerBlue; - color bearishColor = clrSienna; - - // - // Bars ... - mDecisionCycleHelper.mPOIDrawer.BarBullishColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.BarBearishColor(bearishColor); - - // - // Swings ... - mDecisionCycleHelper.mPOIDrawer.SwingLowColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.SwingHighColor(bearishColor); - - // - // Momentum ... - mDecisionCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor); - - // - // Rejection ... - mDecisionCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor); - - // - // Support and Resistance ... - mDecisionCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor); - - // - // Demand and Supply ... - mDecisionCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor); - - // - // Order Blocks ... - mDecisionCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor); - - // - // Fair Value Gaps ... - mDecisionCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor); - mDecisionCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor); - } - // // Trigger Cycle ... mTriggerCycleHelper = new XC121SMCCycleHelper(); isInited = mTriggerCycleHelper.Init( symbol, - PERIOD_M5, + PERIOD_M1, x121Inputs, requiredPOIS // ); @@ -964,6 +907,63 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy mTriggerCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor); } + // + // Decision Cycle ... + mDecisionCycleHelper = new XC121SMCCycleHelper(); + isInited = mDecisionCycleHelper.Init( + symbol, + PERIOD_M5, + x121Inputs, + requiredPOIS // + ); + if (isInited) + { + // + // Configure POI Drawer ... + color bullishColor = clrDodgerBlue; + color bearishColor = clrSienna; + + // + // Bars ... + mDecisionCycleHelper.mPOIDrawer.BarBullishColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.BarBearishColor(bearishColor); + + // + // Swings ... + mDecisionCycleHelper.mPOIDrawer.SwingLowColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.SwingHighColor(bearishColor); + + // + // Momentum ... + mDecisionCycleHelper.mPOIDrawer.BullishMomentumBarColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.BearishMomentumBarColor(bearishColor); + + // + // Rejection ... + mDecisionCycleHelper.mPOIDrawer.BullishRejectionBarColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.BearishRejectionBarColor(bearishColor); + + // + // Support and Resistance ... + mDecisionCycleHelper.mPOIDrawer.SupportZoneColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.ResistanceZoneColor(bearishColor); + + // + // Demand and Supply ... + mDecisionCycleHelper.mPOIDrawer.DemandZoneColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.SupplyZoneColor(bearishColor); + + // + // Order Blocks ... + mDecisionCycleHelper.mPOIDrawer.BullishOrderBlockColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.BearishOrderBlockColor(bearishColor); + + // + // Fair Value Gaps ... + mDecisionCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor); + mDecisionCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor); + } + // // Analyse Cycle ... mAnalyseCycleHelper = new XC121SMCCycleHelper();