73 lines
4.2 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| VZ_Features.mq5 |
| |||
//| VizionAI — the EA's 12 NN features + derived states, per bar. |
| |||
//| No drawing: 15 DRAW_NONE buffers readable via iCustom by the EA, |
| |||
//| the export service, and backtests. Single source of truth. |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "VIZION"
| |||
#property version "1.00"
| |||
#property strict
| |||
#property indicator_chart_window
| |||
#property indicator_buffers 15
| |||
#property indicator_plots 15
| |||
#include "VZ_Core.mqh"
| |||
| |||
// buffer index map (keep in sync with the export service and the EA reader)
| |||
// 0 f0 MA7-MA14 spread (pts) 6 f6 stoch K 12 MA stack (+1/-1/0)
| |||
// 1 f1 MA14-MA21 7 f7 stoch D 13 mode (0 trend,1 range,2 chop)
| |||
// 2 f2 MA21-MA50 8 f8 ADX 14 bias (+1/-1/0)
| |||
// 3 f3 MA50-MA140 9 f9 ATR/close*1e4
| |||
// 4 f4 MA7 slope (EA conv.) 10 f10 close-MFIB382 (pts)
| |||
// 5 f5 MA14 slope (EA conv.) 11 f11 close-MFIB618 (pts)
| |||
| |||
input int Fib_Lookback_Bars = 350; // same as the EA
| |||
input bool EA_Compat_Slopes = true; // negate f4/f5 to match the EA's current (inverted) convention
| |||
| |||
double B0[], B1[], B2[], B3[], B4[], B5[], B6[], B7[], B8[], B9[], B10[], B11[], BStack[], BMode[], BBias[];
| |||
VZ_Handles g_h;
| |||
| |||
int OnInit()
| |||
{
| |||
SetIndexBuffer(0, B0, INDICATOR_DATA); SetIndexBuffer(1, B1, INDICATOR_DATA);
| |||
SetIndexBuffer(2, B2, INDICATOR_DATA); SetIndexBuffer(3, B3, INDICATOR_DATA);
| |||
SetIndexBuffer(4, B4, INDICATOR_DATA); SetIndexBuffer(5, B5, INDICATOR_DATA);
| |||
SetIndexBuffer(6, B6, INDICATOR_DATA); SetIndexBuffer(7, B7, INDICATOR_DATA);
| |||
SetIndexBuffer(8, B8, INDICATOR_DATA); SetIndexBuffer(9, B9, INDICATOR_DATA);
| |||
SetIndexBuffer(10, B10, INDICATOR_DATA); SetIndexBuffer(11, B11, INDICATOR_DATA);
| |||
SetIndexBuffer(12, BStack, INDICATOR_DATA); SetIndexBuffer(13, BMode, INDICATOR_DATA); SetIndexBuffer(14, BBias, INDICATOR_DATA);
| |||
string names[15] = {"f0 MA7-14","f1 MA14-21","f2 MA21-50","f3 MA50-140","f4 MA7 slope","f5 MA14 slope",
| |||
"f6 StochK","f7 StochD","f8 ADX","f9 ATRn","f10 dMFIB382","f11 dMFIB618","MA stack","Mode","Bias"};
| |||
for(int i = 0; i < 15; ++i) { PlotIndexSetInteger(i, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetString(i, PLOT_LABEL, names[i]); }
| |||
ArraySetAsSeries(B0, true); ArraySetAsSeries(B1, true); ArraySetAsSeries(B2, true); ArraySetAsSeries(B3, true);
| |||
ArraySetAsSeries(B4, true); ArraySetAsSeries(B5, true); ArraySetAsSeries(B6, true); ArraySetAsSeries(B7, true);
| |||
ArraySetAsSeries(B8, true); ArraySetAsSeries(B9, true); ArraySetAsSeries(B10, true); ArraySetAsSeries(B11, true);
| |||
ArraySetAsSeries(BStack, true); ArraySetAsSeries(BMode, true); ArraySetAsSeries(BBias, true);
| |||
IndicatorSetString(INDICATOR_SHORTNAME, "VZ_Features");
| |||
IndicatorSetInteger(INDICATOR_DIGITS, 3);
| |||
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;
| |||
// recompute the last two bars every tick; everything older only once
| |||
int limit = (prev_calculated <= 0) ? rates_total - need : MathMin(rates_total - prev_calculated + 1, rates_total - need);
| |||
double point = _Point, f[];
| |||
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; // indicators still loading — retry next tick
| |||
VZ_Features(b, point, EA_Compat_Slopes, f);
| |||
B0[i]=f[0]; B1[i]=f[1]; B2[i]=f[2]; B3[i]=f[3]; B4[i]=f[4]; B5[i]=f[5];
| |||
B6[i]=f[6]; B7[i]=f[7]; B8[i]=f[8]; B9[i]=f[9]; B10[i]=f[10]; B11[i]=f[11];
| |||
BStack[i] = b.stack_bull ? 1.0 : (b.stack_bear ? -1.0 : 0.0);
| |||
BMode[i] = (double)b.mode;
| |||
BBias[i] = (double)b.bias;
| |||
}
| |||
return rates_total;
| |||
}
|