2026-02-15 05:13:55 +00:00 | | | #ifndef REENTRY_MQH
|
| | | #define REENTRY_MQH
|
| | |
|
| | | bool OpenBuy(const string reason, double lot_multiplier = 1.0);
|
| | | bool OpenSell(const string reason, double lot_multiplier = 1.0);
|
| | |
|
| | | struct ReEntryCandidate
|
| | | {
|
| | | bool active;
|
| | | bool is_buy;
|
| | | datetime closed_time;
|
| | | int attempts;
|
| | | string reason;
|
| | | };
|
| | |
|
| | | ReEntryCandidate g_reentry[16];
|
| | |
|
| | | void InitReEntry()
|
| | | {
|
| | | for(int i = 0; i < ArraySize(g_reentry); ++i)
|
| | | {
|
| | | g_reentry[i].active = false;
|
| | | g_reentry[i].is_buy = false;
|
| | | g_reentry[i].closed_time = 0;
|
| | | g_reentry[i].attempts = 0;
|
| | | g_reentry[i].reason = "";
|
| | | }
|
| | | }
|
| | |
|
| | | void QueueReEntryCandidate(const bool is_buy, const string reason)
|
| | | {
|
| | | if(!Enable_ReEntry)
|
| | | return;
|
| | |
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | // one live candidate per direction: several closes in the same second must not queue a burst
|
| | | if(ReEntry_One_Per_Direction)
|
| | | for(int k = 0; k < ArraySize(g_reentry); ++k)
|
| | | if(g_reentry[k].active && g_reentry[k].is_buy == is_buy)
|
| | | return;
|
| | |
|
2026-02-15 05:13:55 +00:00 | | | for(int i = 0; i < ArraySize(g_reentry); ++i)
|
| | | {
|
| | | if(!g_reentry[i].active)
|
| | | {
|
| | | g_reentry[i].active = true;
|
| | | g_reentry[i].is_buy = is_buy;
|
| | | g_reentry[i].closed_time = TimeCurrent();
|
| | | g_reentry[i].attempts = 0;
|
| | | g_reentry[i].reason = reason;
|
| | | return;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | // Is (setup, direction) armed for a re-entry right now? (Require_Setup mode)
|
| | | bool ReEntryArmedFor(const string setup, const bool is_buy, int &idx)
|
| | | {
|
| | | idx = -1;
|
| | | if(!Enable_ReEntry || !ReEntry_Require_Setup) return false;
|
| | | for(int i = 0; i < ArraySize(g_reentry); ++i)
|
| | | {
|
| | | if(!g_reentry[i].active || g_reentry[i].is_buy != is_buy) continue;
|
| | | if(g_reentry[i].reason != setup) continue;
|
| | | if(TimeCurrent() - g_reentry[i].closed_time < ReEntry_Cooldown) return false;
|
| | | if(g_reentry[i].attempts >= ReEntry_Max_Attempts) { g_reentry[i].active = false; return false; }
|
| | | idx = i;
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | // Book the result of an armed re-entry attempt made by the setup engine.
|
| | | void ReEntryConsume(const int idx, const bool opened)
|
| | | {
|
| | | if(idx < 0 || idx >= ArraySize(g_reentry)) return;
|
| | | if(!opened) return; // the refusing gate journaled why; stay armed
|
| | | g_reentry[idx].attempts++;
|
| | | if(g_reentry[idx].attempts >= ReEntry_Max_Attempts)
|
| | | g_reentry[idx].active = false;
|
| | | else
|
| | | g_reentry[idx].closed_time = TimeCurrent();
|
| | | }
|
| | |
|
2026-02-15 05:13:55 +00:00 | | | bool CanReEnter(const int direction)
|
| | | {
|
| | | if(direction > 0)
|
| | | return (Active_Praise_Signals >= Active_Warnings);
|
| | | if(direction < 0)
|
| | | return (Active_Warnings >= Active_Praise_Signals);
|
| | | return false;
|
| | | }
|
| | |
|
| | | void ExecuteReEntries()
|
| | | {
|
| | | if(!Enable_ReEntry)
|
| | | return;
|
| | |
|
| | | for(int i = 0; i < ArraySize(g_reentry); ++i)
|
| | | {
|
| | | if(!g_reentry[i].active)
|
| | | continue;
|
| | |
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | // Setup-validated mode: expiry is handled here, opening happens in FireSetup when the
|
| | | // armed setup fires again.
|
| | | if(ReEntry_Require_Setup)
|
| | | {
|
| | | if(ReEntry_Max_Age_Sec > 0 && TimeCurrent() - g_reentry[i].closed_time > ReEntry_Max_Age_Sec)
|
| | | {
|
| | | Print("ReEntry: armed ", g_reentry[i].reason, " ", g_reentry[i].is_buy ? "BUY" : "SELL", " expired - setup did not return within ", ReEntry_Max_Age_Sec, "s");
|
| | | g_reentry[i].active = false;
|
| | | }
|
| | | continue;
|
| | | }
|
| | |
|
2026-02-15 05:13:55 +00:00 | | | if(TimeCurrent() - g_reentry[i].closed_time < ReEntry_Cooldown)
|
| | | continue;
|
| | |
|
| | | if(g_reentry[i].attempts >= ReEntry_Max_Attempts)
|
| | | {
|
| | | g_reentry[i].active = false;
|
| | | continue;
|
| | | }
|
| | |
|
| | | int confirms = 0;
|
| | | if(g_reentry[i].is_buy)
|
| | | {
|
| | | if(IsBullBias()) confirms++;
|
| | | if(Trend_Resumption || Bull_MA50_Reclaimed()) confirms++;
|
| | | if(StochCrossUp() || Stoch_K_Current > Stoch_Mid) confirms++;
|
| | | if(Coordinator_Bias_Direction >= 0 && Coordinator_AllowTrade) confirms++;
|
| | | }
|
| | | else
|
| | | {
|
| | | if(IsBearBias()) confirms++;
|
| | | if(Trend_Resumption || Bear_MA50_Reclaimed()) confirms++;
|
| | | if(StochCrossDown() || Stoch_K_Current < Stoch_Mid) confirms++;
|
| | | if(Coordinator_Bias_Direction <= 0 && Coordinator_AllowTrade) confirms++;
|
| | | }
|
| | |
|
| | | if(Require_Stronger_Signal && confirms < 3)
|
| | | continue;
|
| | |
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | // Age out instead of dying on the first refusal (cooldown, policy, AI gate, guards) — the
|
| | | // old code cancelled the candidate the moment OpenBuy/OpenSell returned false, which the
|
| | | // 300 s trade cooldown guaranteed 30 s after every close.
|
| | | if(ReEntry_Max_Age_Sec > 0 && TimeCurrent() - g_reentry[i].closed_time > ReEntry_Max_Age_Sec)
|
| | | {
|
| | | Print("ReEntry: candidate expired (", g_reentry[i].is_buy ? "BUY" : "SELL", ", ", g_reentry[i].reason, ") after ", ReEntry_Max_Age_Sec, "s");
|
| | | g_reentry[i].active = false;
|
| | | continue;
|
| | | }
|
| | |
|
| | | // Same direction discipline as setups: with the trend in CONTINUATION, against it in a
|
| | | // pullback/reversal when Pullback_Trade_Direction is COUNTER (helpers in TradingSetups.mqh).
|
| | | // Re-entries follow State the same way setups do, both ways: in CONTINUATION only with-trend
|
| | | // re-entries fire; in PULLBACK / REVERSAL only counter-trend ones. A candidate whose direction
|
| | | // does not match the current state waits (until it matches or the candidate ages out).
|
| | | if(ReEntry_Follow_State && Current_Mode == MODE_TRENDING && Current_Bias_Direction != 0)
|
| | | {
|
| | | bool with_trend = (g_reentry[i].is_buy == (Current_Bias_Direction > 0));
|
| | | bool cont = (Current_State == STATE_CONTINUATION);
|
| | | bool allowed = cont ? with_trend
|
| | | : (Pullback_Trade_Direction == PB_COUNTER_TREND ? !with_trend
|
| | | : Pullback_Trade_Direction == PB_WITH_TREND ? with_trend : true);
|
| | | if(!allowed)
|
| | | {
|
| | | static datetime last_dir_note = 0;
|
| | | if(TimeCurrent() - last_dir_note >= 60)
|
| | | {
|
| | | Print("ReEntry: ", g_reentry[i].is_buy ? "BUY" : "SELL", " candidate waiting - ",
|
| | | with_trend ? "with-trend" : "counter-trend", " re-entry needs State ",
|
| | | with_trend ? "CONTINUATION" : "PULLBACK/REVERSAL", " (now ",
|
| | | cont ? "CONTINUATION" : (Current_State == STATE_REVERSAL ? "REVERSAL" : "PULLBACK"),
|
| | | ", ", Current_Bias_Direction > 0 ? "BULL" : "BEAR", " bias)");
|
| | | last_dir_note = TimeCurrent();
|
| | | }
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
2026-02-15 05:13:55 +00:00 | | | string label = "RE-ENTRY " + IntegerToString(g_reentry[i].attempts + 1) + " | " + g_reentry[i].reason;
|
| | |
|
| | | bool ok = false;
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | g_reentry_attempt = true; // lets IsInCooldown() step aside for re-entries
|
2026-02-15 05:13:55 +00:00 | | | if(g_reentry[i].is_buy)
|
| | | ok = OpenBuy(label, 1.0);
|
| | | else
|
| | | ok = OpenSell(label, 1.0);
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | g_reentry_attempt = false;
|
2026-02-15 05:13:55 +00:00 | | |
|
| | | if(ok)
|
| | | {
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | Print("ReEntry: ", label, " opened (attempt ", g_reentry[i].attempts + 1, "/", ReEntry_Max_Attempts, ")");
|
2026-02-15 05:13:55 +00:00 | | | g_reentry[i].attempts++;
|
| | | if(g_reentry[i].attempts >= ReEntry_Max_Attempts)
|
| | | g_reentry[i].active = false;
|
| | | else
|
| | | g_reentry[i].closed_time = TimeCurrent();
|
| | | }
|
| | | else
|
| | | {
|
EA: sync live build (Jul-Nov 2026) — trade report direction/setup fix, VZ indicators, risk modules
- AIGateway/profitgtx: report_trade takes direction and setup from the position's
opening deal ("dir_src":"entry"); the closing deal inverted every direction and
restarts lost the setup (99% "auto")
- add MATheory, RiskGuards, RiskSizing, TradePolicy (setup blocklist, strict AI gate)
- add VZ_Core + VZ_Features/MFIB/Regime/Setups/Sessions indicators, VZ_FeaturesExport
service, VZ_DumpMA, VZ_TogglePause
- margin-aware sizing, news, labels and session updates since 2026-07-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:48:22 -06:00 | | | // keep the candidate and retry on later ticks; the refusing gate journals its own reason
|
| | | static datetime last_note = 0;
|
| | | if(TimeCurrent() - last_note >= 60)
|
| | | {
|
| | | Print("ReEntry: ", label, " refused this tick - will retry until it expires");
|
| | | last_note = TimeCurrent();
|
| | | }
|
2026-02-15 05:13:55 +00:00 | | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endif
|