Vizion-Trading-EA/VZ_DumpMA.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
85 lines
3.8 KiB
MQL5
//+------------------------------------------------------------------+
//| VZ_DumpMA.mq5 — dump OHLC + EMA 7/14/21/50/140/230/500/1400 |
//| for the study symbols on several timeframes to CSV. |
//| Output: MQL5\Files\vizion\ma_<symbol>_<tf>.csv (oldest first) |
//| Run once from any chart (Navigator -> Scripts -> VZ_DumpMA). |
//+------------------------------------------------------------------+
#property copyright "VizionAI"
#property version "1.00"
#property script_show_inputs
input string Symbols = "XAUUSD,US Tech 100,Wall Street 30";
input string TFs = "M1,M5,M15,H1";
input int BarCount = 3000;
ENUM_TIMEFRAMES TFFromString(const string s)
{
if(s == "M1") return PERIOD_M1;
if(s == "M5") return PERIOD_M5;
if(s == "M15") return PERIOD_M15;
if(s == "M30") return PERIOD_M30;
if(s == "H1") return PERIOD_H1;
if(s == "H4") return PERIOD_H4;
return PERIOD_D1;
}
void OnStart()
{
int periods[8] = {7, 14, 21, 50, 140, 230, 500, 1400};
string syms[], tfs[];
int ns = StringSplit(Symbols, ',', syms);
int nt = StringSplit(TFs, ',', tfs);
int files = 0;
for(int si = 0; si < ns; ++si)
{
string sym = syms[si]; StringTrimLeft(sym); StringTrimRight(sym);
if(!SymbolSelect(sym, true)) { Print("VZ_DumpMA: unknown symbol ", sym); continue; }
for(int ti = 0; ti < nt; ++ti)
{
string tfs_s = tfs[ti]; StringTrimLeft(tfs_s); StringTrimRight(tfs_s);
ENUM_TIMEFRAMES tf = TFFromString(tfs_s);
int h[8];
bool ok = true;
for(int i = 0; i < 8; ++i)
{
h[i] = iMA(sym, tf, periods[i], 0, MODE_EMA, PRICE_CLOSE);
if(h[i] == INVALID_HANDLE) ok = false;
}
int hatr = iATR(sym, tf, 14);
if(!ok || hatr == INVALID_HANDLE) { Print("VZ_DumpMA: handle failed ", sym, " ", tfs_s); continue; }
// let the terminal calculate
double tmp[];
int tries = 0;
while(tries < 50 && (CopyBuffer(h[7], 0, 0, BarCount, tmp) < BarCount || CopyBuffer(hatr, 0, 0, BarCount, tmp) < BarCount)) { Sleep(200); tries++; }
MqlRates r[];
int got = CopyRates(sym, tf, 0, BarCount, r);
if(got <= 0) { Print("VZ_DumpMA: no rates ", sym, " ", tfs_s); continue; }
double m0[], m1[], m2[], m3[], m4[], m5[], m6[], m7[], atr[];
CopyBuffer(h[0], 0, 0, got, m0); CopyBuffer(h[1], 0, 0, got, m1); CopyBuffer(h[2], 0, 0, got, m2); CopyBuffer(h[3], 0, 0, got, m3);
CopyBuffer(h[4], 0, 0, got, m4); CopyBuffer(h[5], 0, 0, got, m5); CopyBuffer(h[6], 0, 0, got, m6); CopyBuffer(h[7], 0, 0, got, m7);
CopyBuffer(hatr, 0, 0, got, atr);
string fsym = sym; StringReplace(fsym, " ", "_");
string fname = "vizion\\ma_" + fsym + "_" + tfs_s + ".csv";
int fh = FileOpen(fname, FILE_WRITE | FILE_CSV | FILE_ANSI, ',');
if(fh == INVALID_HANDLE) { Print("VZ_DumpMA: cannot open ", fname, " err ", GetLastError()); continue; }
FileWrite(fh, "time", "open", "high", "low", "close", "ema7", "ema14", "ema21", "ema50", "ema140", "ema230", "ema500", "ema1400", "atr");
int n = MathMin(got, ArraySize(m7));
for(int i = 0; i < n; ++i) // CopyRates / CopyBuffer without series flag: oldest first
FileWrite(fh, TimeToString(r[i].time, TIME_DATE | TIME_MINUTES), r[i].open, r[i].high, r[i].low, r[i].close,
m0[i], m1[i], m2[i], m3[i], m4[i], m5[i], m6[i], m7[i], atr[i]);
FileClose(fh);
files++;
Print("VZ_DumpMA: wrote ", fname, " (", n, " bars)");
for(int i = 0; i < 8; ++i) IndicatorRelease(h[i]);
IndicatorRelease(hatr);
}
}
Alert("VZ_DumpMA: ", files, " files written to MQL5\\Files\\vizion");
}
//+------------------------------------------------------------------+