89 行
3.8 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| VZ_Regime.mq5 |
| |||
//| VizionAI — separate window: ADX with the entry-guard line, |
| |||
//| ATR-normalised, Stoch K/D, and the EA's market mode as a colour |
| |||
//| band (trending / ranging / chop). Same rules as MarketState.mqh. |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "VIZION"
| |||
#property version "1.00"
| |||
#property strict
| |||
#property indicator_separate_window
| |||
#property indicator_minimum 0
| |||
#property indicator_maximum 100
| |||
#property indicator_buffers 7
| |||
#property indicator_plots 6
| |||
#property indicator_level1 20
| |||
#property indicator_level2 80
| |||
#property indicator_levelcolor clrDimGray
| |||
#property indicator_levelstyle STYLE_DOT
| |||
| |||
#property indicator_label1 "Mode"
| |||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
| |||
#property indicator_color1 clrSeaGreen, clrSteelBlue, clrIndianRed // 0 trending, 1 ranging, 2 chop
| |||
#property indicator_width1 2
| |||
#property indicator_label2 "ADX"
| |||
#property indicator_type2 DRAW_LINE
| |||
#property indicator_color2 clrWhite
| |||
#property indicator_width2 2
| |||
#property indicator_label3 "ADX guard"
| |||
#property indicator_type3 DRAW_LINE
| |||
#property indicator_color3 clrOrangeRed
| |||
#property indicator_style3 STYLE_DASH
| |||
#property indicator_label4 "ATR norm x4"
| |||
#property indicator_type4 DRAW_LINE
| |||
#property indicator_color4 clrGoldenrod
| |||
#property indicator_label5 "Stoch K"
| |||
#property indicator_type5 DRAW_LINE
| |||
#property indicator_color5 clrDeepSkyBlue
| |||
#property indicator_label6 "Stoch D"
| |||
#property indicator_type6 DRAW_LINE
| |||
#property indicator_color6 clrLightSteelBlue
| |||
#property indicator_style6 STYLE_DOT
| |||
#include "VZ_Core.mqh"
| |||
| |||
input int Fib_Lookback_Bars = 350; // same as the EA (mode does not use it, kept for parity)
| |||
input double ADX_Guard = 33.0; // Max_ADX_To_Trade in the EA: no entries above this
| |||
input double Mode_Band_Height = 6.0; // height of the mode colour band at the bottom of the window
| |||
| |||
double BMode[], BModeColor[], BADX[], BGuard[], BATR[], BK[], BD[];
| |||
VZ_Handles g_h;
| |||
| |||
int OnInit()
| |||
{
| |||
SetIndexBuffer(0, BMode, INDICATOR_DATA);
| |||
SetIndexBuffer(1, BModeColor, INDICATOR_COLOR_INDEX);
| |||
SetIndexBuffer(2, BADX, INDICATOR_DATA);
| |||
SetIndexBuffer(3, BGuard, INDICATOR_DATA);
| |||
SetIndexBuffer(4, BATR, INDICATOR_DATA);
| |||
SetIndexBuffer(5, BK, INDICATOR_DATA);
| |||
SetIndexBuffer(6, BD, INDICATOR_DATA);
| |||
ArraySetAsSeries(BMode, true); ArraySetAsSeries(BModeColor, true); ArraySetAsSeries(BADX, true);
| |||
ArraySetAsSeries(BGuard, true); ArraySetAsSeries(BATR, true); ArraySetAsSeries(BK, true); ArraySetAsSeries(BD, true);
| |||
IndicatorSetString(INDICATOR_SHORTNAME, "VZ_Regime (ADX guard " + DoubleToString(ADX_Guard, 0) + ")");
| |||
IndicatorSetInteger(INDICATOR_DIGITS, 1);
| |||
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;
| |||
BMode[i] = Mode_Band_Height;
| |||
BModeColor[i] = (double)b.mode;
| |||
BADX[i] = b.adx;
| |||
BGuard[i] = ADX_Guard;
| |||
BATR[i] = MathMin(100.0, (b.atr > 0.0 ? (b.atr / b.close) * 10000.0 : 0.0) * 4.0);
| |||
BK[i] = b.stoch_k;
| |||
BD[i] = b.stoch_d;
| |||
}
| |||
return rates_total;
| |||
}
|