| //+------------------------------------------------------------------+
|
| //| VZ_Setups.mq5 |
|
| //| VizionAI — marks bars where the EA's price-based setup triggers |
|
| //| fire (TradingSetups.mqh), split into allowed vs blocked by the |
|
| //| Setup_Blocklist policy, so the policy can be eyeballed on chart. |
|
| //| |
|
| //| Replicable from price alone: MAGNET-WALK, FIB-BREAK/RECLAIM, |
|
| //| MFIB-LADDER, RANGE-EDGE, RANGE-MFIB, CHOP-SNAP, CHOP-REV. |
|
| //| Not replicable (depend on open trades / warnings / re-entries): |
|
| //| FORCE-*, RE-ENTRY, EMA-RETEST/REJECT cooldowns. Marks are |
|
| //| approximations of the EA's state-dependent gates. |
|
| //+------------------------------------------------------------------+
|
| #property copyright "VIZION"
|
| #property version "1.00"
|
| #property strict
|
| #property indicator_chart_window
|
| #property indicator_buffers 5
|
| #property indicator_plots 5
|
| #property indicator_label1 "Buy setup (allowed)"
|
| #property indicator_type1 DRAW_ARROW
|
| #property indicator_color1 clrLimeGreen
|
| #property indicator_width1 2
|
| #property indicator_label2 "Sell setup (allowed)"
|
| #property indicator_type2 DRAW_ARROW
|
| #property indicator_color2 clrTomato
|
| #property indicator_width2 2
|
| #property indicator_label3 "Buy setup (blocked by policy)"
|
| #property indicator_type3 DRAW_ARROW
|
| #property indicator_color3 clrGray
|
| #property indicator_label4 "Sell setup (blocked by policy)"
|
| #property indicator_type4 DRAW_ARROW
|
| #property indicator_color4 clrGray
|
| #property indicator_label5 "Setup code"
|
| #property indicator_type5 DRAW_NONE
|
| #include "VZ_Core.mqh"
|
|
|
| input int Fib_Lookback_Bars = 350; // same as the EA
|
| input int MA_Touch_Buffer = 75; // points, same as the EA
|
| input double Stoch_Oversold = 20.0;
|
| input double Stoch_Weak_Low = 35.0;
|
| input double Stoch_Mid = 50.0;
|
| input double Stoch_Weak_High = 65.0;
|
| input double Stoch_Overbought = 80.0;
|
| input string Setup_Blocklist = "FORCE-URGENT,FORCE-STANDARD,CHOP-SNAP"; // same as the EA policy
|
| input int Arrow_Offset_Pts = 120; // vertical offset of the arrows from the bar
|
|
|
| // setup codes written to buffer 4 (positive = buy, negative = sell)
|
| // 1 MAGNET-WALK 2 FIB-BREAK 3 FIB-RECLAIM 4 MFIB-LADDER 5 RANGE-EDGE 6 RANGE-MFIB 7 CHOP-SNAP 8 CHOP-REV
|
| double BuyOK[], SellOK[], BuyBlk[], SellBlk[], Code[];
|
| VZ_Handles g_h;
|
|
|
| bool Blocked(const string name)
|
| {
|
| if(StringLen(Setup_Blocklist) == 0) return false;
|
| string parts[]; int n = StringSplit(Setup_Blocklist, ',', parts);
|
| string up = name; StringToUpper(up);
|
| for(int i = 0; i < n; ++i)
|
| {
|
| string p = parts[i]; StringTrimLeft(p); StringTrimRight(p); StringToUpper(p);
|
| if(StringLen(p) > 0 && StringFind(up, p) == 0) return true;
|
| }
|
| return false;
|
| }
|
|
|
| bool Near(const double price, const double level) { return MathAbs(price - level) <= MA_Touch_Buffer * _Point; }
|
|
|
| int OnInit()
|
| {
|
| SetIndexBuffer(0, BuyOK, INDICATOR_DATA); SetIndexBuffer(1, SellOK, INDICATOR_DATA);
|
| SetIndexBuffer(2, BuyBlk, INDICATOR_DATA); SetIndexBuffer(3, SellBlk, INDICATOR_DATA);
|
| SetIndexBuffer(4, Code, INDICATOR_DATA);
|
| ArraySetAsSeries(BuyOK, true); ArraySetAsSeries(SellOK, true); ArraySetAsSeries(BuyBlk, true);
|
| ArraySetAsSeries(SellBlk, true); ArraySetAsSeries(Code, true);
|
| PlotIndexSetInteger(0, PLOT_ARROW, 233); PlotIndexSetInteger(1, PLOT_ARROW, 234);
|
| PlotIndexSetInteger(2, PLOT_ARROW, 233); PlotIndexSetInteger(3, PLOT_ARROW, 234);
|
| for(int i = 0; i < 5; ++i) PlotIndexSetDouble(i, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
| IndicatorSetString(INDICATOR_SHORTNAME, "VZ_Setups");
|
| IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
| return VZ_Init(g_h, _Symbol, _Period) ? INIT_SUCCEEDED : INIT_FAILED;
|
| }
|
|
|
| void OnDeinit(const int reason) { VZ_Release(g_h); }
|
|
|
| void Mark(const int i, const bool buy, const string name, const int code, const double low, const double high)
|
| {
|
| double off = Arrow_Offset_Pts * _Point;
|
| bool blk = Blocked(name);
|
| if(buy) { if(blk) BuyBlk[i] = low - off; else BuyOK[i] = low - off; }
|
| else { if(blk) SellBlk[i] = high + off; else SellOK[i] = high + off; }
|
| Code[i] = buy ? code : -code;
|
| }
|
|
|
| int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[],
|
| const double &open[], const double &high[], const double &low[], const double &close[],
|
| const long &tick_volume[], const long &volume[], const int &spread[])
|
| {
|
| int need = MathMax(Fib_Lookback_Bars, 120) + 3;
|
| if(rates_total < need) return 0;
|
| ArraySetAsSeries(close, true); ArraySetAsSeries(high, true); ArraySetAsSeries(low, true);
|
| int limit = (prev_calculated <= 0) ? rates_total - need : MathMin(rates_total - prev_calculated + 1, rates_total - need);
|
| VZ_Bar b;
|
| for(int i = limit; i >= 0; --i)
|
| {
|
| BuyOK[i] = SellOK[i] = BuyBlk[i] = SellBlk[i] = EMPTY_VALUE; Code[i] = 0.0;
|
| if(!VZ_Fill(g_h, _Symbol, _Period, i, Fib_Lookback_Bars, b)) return prev_calculated;
|
| double c0 = close[i], c1 = close[i + 1];
|
| int dir = b.bias;
|
|
|
| if(b.mode == VZ_MODE_TRENDING)
|
| {
|
| // FIB-BREAK / FIB-RECLAIM across ladder levels 1..5 (continuation)
|
| for(int k = 1; k <= 5; ++k)
|
| {
|
| if(c1 <= b.level[k] && c0 > b.level[k]) { Mark(i, true, "FIB-BREAK-UP", 2, low[i], high[i]); break; }
|
| if(c1 >= b.level[k] && c0 < b.level[k]) { Mark(i, false, "FIB-BREAK-DN", 2, low[i], high[i]); break; }
|
| }
|
| // MAGNET-WALK: price hugging EMA21 within 0.7 ATR, in bias direction
|
| bool hugging = (b.atr > 0.0 && MathAbs(c0 - b.ma[2]) / b.atr < 0.7);
|
| if(hugging && dir >= 0) Mark(i, true, "MAGNET-WALK-UP", 1, low[i], high[i]);
|
| if(hugging && dir <= 0) Mark(i, false, "MAGNET-WALK-DN", 1, low[i], high[i]);
|
| // MFIB-LADDER: at the anchored 0.382 / 0.618
|
| if(Near(c0, b.mfib_382) || Near(c0, b.mfib_618))
|
| {
|
| if(dir >= 0) Mark(i, true, "MFIB-LADDER-UP", 4, low[i], high[i]);
|
| if(dir <= 0) Mark(i, false, "MFIB-LADDER-DN", 4, low[i], high[i]);
|
| }
|
| }
|
| else if(b.mode == VZ_MODE_RANGING)
|
| {
|
| if(Near(c0, b.level[1]) && b.stoch_k < Stoch_Weak_Low) Mark(i, true, "RANGE-EDGE-BUY", 5, low[i], high[i]);
|
| if(Near(c0, b.level[5]) && b.stoch_k > Stoch_Weak_High) Mark(i, false, "RANGE-EDGE-SELL", 5, low[i], high[i]);
|
| if(Near(c0, b.mfib_382) && b.stoch_k < Stoch_Mid) Mark(i, true, "RANGE-MFIB-BUY", 6, low[i], high[i]);
|
| if(Near(c0, b.mfib_618) && b.stoch_k > Stoch_Mid) Mark(i, false, "RANGE-MFIB-SELL", 6, low[i], high[i]);
|
| }
|
| else // chop
|
| {
|
| if(b.stoch_k <= Stoch_Oversold) Mark(i, true, "CHOP-REV-BUY", 8, low[i], high[i]);
|
| if(b.stoch_k >= Stoch_Overbought) Mark(i, false, "CHOP-REV-SELL", 8, low[i], high[i]);
|
| if(Near(c0, b.ma[0]))
|
| {
|
| if(c0 < b.ma[0]) Mark(i, true, "CHOP-SNAP-BUY", 7, low[i], high[i]);
|
| if(c0 > b.ma[0]) Mark(i, false, "CHOP-SNAP-SELL", 7, low[i], high[i]);
|
| }
|
| }
|
| }
|
| return rates_total;
|
| }
|