Vizion-Trading-EA/VZ_MFIB.mq5
SahrJohn SahrJohn 526860b9cd 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
113 lines
5.3 KiB
MQL5
//+------------------------------------------------------------------+
//| VZ_MFIB.mq5 |
//| VizionAI — the EA's fib ladder (lookback ATH/ATL) and the MFIB |
//| levels anchored at 0.32 in the bias direction, as chart lines |
//| with buffers. Same math as FibLevels.mqh via VZ_Core.mqh. |
//+------------------------------------------------------------------+
#property copyright "VIZION"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 13
#property indicator_plots 13
#include "VZ_Core.mqh"
// ladder 0..6: low, .236, .382, .5, .618, .786, high
#property indicator_label1 "Fib 0"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDimGray
#property indicator_style1 STYLE_DOT
#property indicator_label2 "Fib 0.236"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDimGray
#property indicator_style2 STYLE_DOT
#property indicator_label3 "Fib 0.382"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrSlateGray
#property indicator_style3 STYLE_DOT
#property indicator_label4 "Fib 0.5"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrSlateGray
#property indicator_style4 STYLE_DOT
#property indicator_label5 "Fib 0.618"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrSlateGray
#property indicator_style5 STYLE_DOT
#property indicator_label6 "Fib 0.786"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrDimGray
#property indicator_style6 STYLE_DOT
#property indicator_label7 "Fib 1"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrDimGray
#property indicator_style7 STYLE_DOT
// MFIB anchored levels 7..11
#property indicator_label8 "MFIB 0.236"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrGoldenrod
#property indicator_style8 STYLE_DASH
#property indicator_label9 "MFIB 0.382"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrGold
#property indicator_width9 2
#property indicator_label10 "MFIB 0.5"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrGoldenrod
#property indicator_style10 STYLE_DASH
#property indicator_label11 "MFIB 0.618"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrGold
#property indicator_width11 2
#property indicator_label12 "MFIB 0.786"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrGoldenrod
#property indicator_style12 STYLE_DASH
// 12: bias (+1/-1/0), no drawing
#property indicator_label13 "Bias"
#property indicator_type13 DRAW_NONE
input int Fib_Lookback_Bars = 350; // same as the EA
input bool Show_Ladder = true; // plain lookback ladder (grey)
input bool Show_MFIB = true; // anchored MFIB levels (gold) — the ones the EA trades off
double L0[], L1[], L2[], L3[], L4[], L5[], L6[], M236[], M382[], M500[], M618[], M786[], BBias[];
VZ_Handles g_h;
int OnInit()
{
SetIndexBuffer(0, L0, INDICATOR_DATA); SetIndexBuffer(1, L1, INDICATOR_DATA); SetIndexBuffer(2, L2, INDICATOR_DATA);
SetIndexBuffer(3, L3, INDICATOR_DATA); SetIndexBuffer(4, L4, INDICATOR_DATA); SetIndexBuffer(5, L5, INDICATOR_DATA);
SetIndexBuffer(6, L6, INDICATOR_DATA); SetIndexBuffer(7, M236, INDICATOR_DATA); SetIndexBuffer(8, M382, INDICATOR_DATA);
SetIndexBuffer(9, M500, INDICATOR_DATA); SetIndexBuffer(10, M618, INDICATOR_DATA); SetIndexBuffer(11, M786, INDICATOR_DATA);
SetIndexBuffer(12, BBias, INDICATOR_DATA);
ArraySetAsSeries(L0, true); ArraySetAsSeries(L1, true); ArraySetAsSeries(L2, true); ArraySetAsSeries(L3, true);
ArraySetAsSeries(L4, true); ArraySetAsSeries(L5, true); ArraySetAsSeries(L6, true); ArraySetAsSeries(M236, true);
ArraySetAsSeries(M382, true); ArraySetAsSeries(M500, true); ArraySetAsSeries(M618, true); ArraySetAsSeries(M786, true);
ArraySetAsSeries(BBias, true);
for(int i = 0; i < 13; ++i) PlotIndexSetDouble(i, PLOT_EMPTY_VALUE, EMPTY_VALUE);
if(!Show_Ladder) for(int i = 0; i < 7; ++i) PlotIndexSetInteger(i, PLOT_DRAW_TYPE, DRAW_NONE);
if(!Show_MFIB) for(int i = 7; i < 12; ++i) PlotIndexSetInteger(i, PLOT_DRAW_TYPE, DRAW_NONE);
IndicatorSetString(INDICATOR_SHORTNAME, "VZ_MFIB");
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
return VZ_Init(g_h, _Symbol, _Period) ? INIT_SUCCEEDED : INIT_FAILED;
}
void OnDeinit(const int reason) { VZ_Release(g_h); }
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) + 2;
if(rates_total < need) return 0;
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)
{
if(!VZ_Fill(g_h, _Symbol, _Period, i, Fib_Lookback_Bars, b)) return prev_calculated;
L0[i]=b.level[0]; L1[i]=b.level[1]; L2[i]=b.level[2]; L3[i]=b.level[3]; L4[i]=b.level[4]; L5[i]=b.level[5]; L6[i]=b.level[6];
M236[i]=b.mfib_236; M382[i]=b.mfib_382; M500[i]=b.mfib_500; M618[i]=b.mfib_618; M786[i]=b.mfib_786;
BBias[i] = (double)b.bias;
}
return rates_total;
}