refactor(indicators): Refactored with Dynamic Input Levels

This commit is contained in:
Toh4iem9
2026-03-17 13:57:49 +01:00
parent 53d1f70a8e
commit 5e80d01748
@@ -3,7 +3,7 @@
//| Copyright 2026, xxxxxxxx|
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, xxxxxxxx"
#property version "2.00" // Upgraded with Double Buffering (Session Gaps)
#property version "2.10" // Refactored with Dynamic Input Levels
#property description "V-Score Projected Bands on Main Chart."
#property description "Rolling standard deviation (Bollinger style) around VWAP."
@@ -24,8 +24,8 @@
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- Plot 3 & 4: Upper 1.5 Band (Odd / Even)
#property indicator_label3 "Bull Flow (+1.5)"
//--- Plot 3 & 4: Upper Flow Band (Odd / Even)
#property indicator_label3 "Bull Flow" // Dynamically updated in OnInit
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrCoral
#property indicator_style3 STYLE_SOLID
@@ -37,8 +37,8 @@
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- Plot 5 & 6: Lower 1.5 Band (Odd / Even)
#property indicator_label5 "Bear Flow (-1.5)"
//--- Plot 5 & 6: Lower Flow Band (Odd / Even)
#property indicator_label5 "Bear Flow" // Dynamically updated in OnInit
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrLightSkyBlue
#property indicator_style5 STYLE_SOLID
@@ -50,8 +50,8 @@
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//--- Plot 7 & 8: Upper 2.0 Band (Odd / Even)
#property indicator_label7 "Bull Extreme (+2.0)"
//--- Plot 7 & 8: Upper Extreme Band (Odd / Even)
#property indicator_label7 "Bull Extreme" // Dynamically updated in OnInit
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrCoral
#property indicator_style7 STYLE_SOLID
@@ -63,8 +63,8 @@
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//--- Plot 9 & 10: Lower 2.0 Band (Odd / Even)
#property indicator_label9 "Bear Extreme (-2.0)"
//--- Plot 9 & 10: Lower Extreme Band (Odd / Even)
#property indicator_label9 "Bear Extreme" // Dynamically updated in OnInit
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrLightSkyBlue
#property indicator_style9 STYLE_SOLID
@@ -76,8 +76,8 @@
#property indicator_style10 STYLE_SOLID
#property indicator_width10 1
//--- Plot 11 & 12: Upper 2.5 Band (Odd / Even)
#property indicator_label11 "Bull Wall (+2.5)"
//--- Plot 11 & 12: Upper Wall Band (Odd / Even)
#property indicator_label11 "Bull Wall" // Dynamically updated in OnInit
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrOrangeRed
#property indicator_style11 STYLE_SOLID
@@ -89,8 +89,8 @@
#property indicator_style12 STYLE_SOLID
#property indicator_width12 1
//--- Plot 13 & 14: Lower 2.5 Band (Odd / Even)
#property indicator_label13 "Bear Wall (-2.5)"
//--- Plot 13 & 14: Lower Wall Band (Odd / Even)
#property indicator_label13 "Bear Wall" // Dynamically updated in OnInit
#property indicator_type13 DRAW_LINE
#property indicator_color13 clrDeepSkyBlue
#property indicator_style13 STYLE_SOLID
@@ -105,19 +105,27 @@
#include <MyIncludes\VWAP_Calculator.mqh>
//--- Input Parameters
input group "V-Score Logic Settings"
input int InpPeriod = 20; // Volatility Lookback
input ENUM_VWAP_PERIOD InpVWAPReset = PERIOD_SESSION; // VWAP Anchor
input ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; // Volume Type
input group "V-Score Core Settings"
input int InpPeriod = 20; // Volatility Lookback
input ENUM_VWAP_PERIOD InpVWAPReset = PERIOD_SESSION; // VWAP Anchor
input ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; // Volume Type
//--- Double Buffers
double BufVWAP_Odd[], BufVWAP_Even[];
double BufUp15_Odd[], BufUp15_Even[];
double BufDn15_Odd[], BufDn15_Even[];
double BufUp20_Odd[], BufUp20_Even[];
double BufDn20_Odd[], BufDn20_Even[];
double BufUp25_Odd[], BufUp25_Even[];
double BufDn25_Odd[], BufDn25_Even[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
input group "V-Score Z-Levels (Standard Deviations)"
input double InpLevelFlow = 1.5; // Flow Level (Point of No Return)
input double InpLevelExtreme = 2.0; // Extreme Level (Warning)
input double InpLevelWall = 2.5; // Wall Level (Climax Exhaustion)
//--- Double Buffers (Semantically Named)
double BufVWAP_Odd[], BufVWAP_Even[];
double BufUpFlow_Odd[], BufUpFlow_Even[];
double BufDnFlow_Odd[], BufDnFlow_Even[];
double BufUpExtr_Odd[], BufUpExtr_Even[];
double BufDnExtr_Odd[], BufDnExtr_Even[];
double BufUpWall_Odd[], BufUpWall_Even[];
double BufDnWall_Odd[], BufDnWall_Even[];
// Internal Arrays
double m_vwap_odd[];
@@ -132,27 +140,35 @@ CVWAPCalculator *g_vwap;
//+------------------------------------------------------------------+
int OnInit()
{
// VWAP
// VWAP Base
SetIndexBuffer(0, BufVWAP_Odd, INDICATOR_DATA);
SetIndexBuffer(1, BufVWAP_Even, INDICATOR_DATA);
// +1.5
SetIndexBuffer(2, BufUp15_Odd, INDICATOR_DATA);
SetIndexBuffer(3, BufUp15_Even, INDICATOR_DATA);
// -1.5
SetIndexBuffer(4, BufDn15_Odd, INDICATOR_DATA);
SetIndexBuffer(5, BufDn15_Even, INDICATOR_DATA);
// +2.0
SetIndexBuffer(6, BufUp20_Odd, INDICATOR_DATA);
SetIndexBuffer(7, BufUp20_Even, INDICATOR_DATA);
// -2.0
SetIndexBuffer(8, BufDn20_Odd, INDICATOR_DATA);
SetIndexBuffer(9, BufDn20_Even, INDICATOR_DATA);
// +2.5
SetIndexBuffer(10, BufUp25_Odd, INDICATOR_DATA);
SetIndexBuffer(11, BufUp25_Even, INDICATOR_DATA);
// -2.5
SetIndexBuffer(12, BufDn25_Odd, INDICATOR_DATA);
SetIndexBuffer(13, BufDn25_Even, INDICATOR_DATA);
// Flow Level Bands
SetIndexBuffer(2, BufUpFlow_Odd, INDICATOR_DATA);
SetIndexBuffer(3, BufUpFlow_Even, INDICATOR_DATA);
SetIndexBuffer(4, BufDnFlow_Odd, INDICATOR_DATA);
SetIndexBuffer(5, BufDnFlow_Even, INDICATOR_DATA);
// Extreme Level Bands
SetIndexBuffer(6, BufUpExtr_Odd, INDICATOR_DATA);
SetIndexBuffer(7, BufUpExtr_Even, INDICATOR_DATA);
SetIndexBuffer(8, BufDnExtr_Odd, INDICATOR_DATA);
SetIndexBuffer(9, BufDnExtr_Even, INDICATOR_DATA);
// Wall Level Bands
SetIndexBuffer(10, BufUpWall_Odd, INDICATOR_DATA);
SetIndexBuffer(11, BufUpWall_Even, INDICATOR_DATA);
SetIndexBuffer(12, BufDnWall_Odd, INDICATOR_DATA);
SetIndexBuffer(13, BufDnWall_Even, INDICATOR_DATA);
// Dynamically set plot labels to reflect custom input levels in the Data Window
PlotIndexSetString(2, PLOT_LABEL, StringFormat("Bull Flow (+%.2f)", InpLevelFlow));
PlotIndexSetString(4, PLOT_LABEL, StringFormat("Bear Flow (-%.2f)", InpLevelFlow));
PlotIndexSetString(6, PLOT_LABEL, StringFormat("Bull Extr (+%.2f)", InpLevelExtreme));
PlotIndexSetString(8, PLOT_LABEL, StringFormat("Bear Extr (-%.2f)", InpLevelExtreme));
PlotIndexSetString(10, PLOT_LABEL, StringFormat("Bull Wall (+%.2f)", InpLevelWall));
PlotIndexSetString(12, PLOT_LABEL, StringFormat("Bear Wall (-%.2f)", InpLevelWall));
// Prevent drawing lines to 0 when values are empty
for(int i=0; i<14; i++)
@@ -222,18 +238,18 @@ int OnCalculate(const int rates_total,
// Reset all outputs for current bar first
BufVWAP_Odd[i] = EMPTY_VALUE;
BufVWAP_Even[i] = EMPTY_VALUE;
BufUp15_Odd[i] = EMPTY_VALUE;
BufUp15_Even[i] = EMPTY_VALUE;
BufDn15_Odd[i] = EMPTY_VALUE;
BufDn15_Even[i] = EMPTY_VALUE;
BufUp20_Odd[i] = EMPTY_VALUE;
BufUp20_Even[i] = EMPTY_VALUE;
BufDn20_Odd[i] = EMPTY_VALUE;
BufDn20_Even[i] = EMPTY_VALUE;
BufUp25_Odd[i] = EMPTY_VALUE;
BufUp25_Even[i] = EMPTY_VALUE;
BufDn25_Odd[i] = EMPTY_VALUE;
BufDn25_Even[i] = EMPTY_VALUE;
BufUpFlow_Odd[i] = EMPTY_VALUE;
BufUpFlow_Even[i] = EMPTY_VALUE;
BufDnFlow_Odd[i] = EMPTY_VALUE;
BufDnFlow_Even[i] = EMPTY_VALUE;
BufUpExtr_Odd[i] = EMPTY_VALUE;
BufUpExtr_Even[i] = EMPTY_VALUE;
BufDnExtr_Odd[i] = EMPTY_VALUE;
BufDnExtr_Even[i] = EMPTY_VALUE;
BufUpWall_Odd[i] = EMPTY_VALUE;
BufUpWall_Even[i] = EMPTY_VALUE;
BufDnWall_Odd[i] = EMPTY_VALUE;
BufDnWall_Even[i] = EMPTY_VALUE;
// If VWAP is missing or just reset, continue
if(current_vwap == 0 || current_vwap == EMPTY_VALUE)
@@ -263,22 +279,22 @@ int OnCalculate(const int rates_total,
BufVWAP_Odd[i] = current_vwap;
if(std_dev > 1.0e-9)
{
BufUp15_Odd[i] = current_vwap + (1.5 * std_dev);
BufDn15_Odd[i] = current_vwap - (1.5 * std_dev);
BufUp20_Odd[i] = current_vwap + (2.0 * std_dev);
BufDn20_Odd[i] = current_vwap - (2.0 * std_dev);
BufUp25_Odd[i] = current_vwap + (2.5 * std_dev);
BufDn25_Odd[i] = current_vwap - (2.5 * std_dev);
BufUpFlow_Odd[i] = current_vwap + (InpLevelFlow * std_dev);
BufDnFlow_Odd[i] = current_vwap - (InpLevelFlow * std_dev);
BufUpExtr_Odd[i] = current_vwap + (InpLevelExtreme * std_dev);
BufDnExtr_Odd[i] = current_vwap - (InpLevelExtreme * std_dev);
BufUpWall_Odd[i] = current_vwap + (InpLevelWall * std_dev);
BufDnWall_Odd[i] = current_vwap - (InpLevelWall * std_dev);
}
else
{
// Collapse bands to VWAP if zero volatility
BufUp15_Odd[i] = current_vwap;
BufDn15_Odd[i] = current_vwap;
BufUp20_Odd[i] = current_vwap;
BufDn20_Odd[i] = current_vwap;
BufUp25_Odd[i] = current_vwap;
BufDn25_Odd[i] = current_vwap;
BufUpFlow_Odd[i] = current_vwap;
BufDnFlow_Odd[i] = current_vwap;
BufUpExtr_Odd[i] = current_vwap;
BufDnExtr_Odd[i] = current_vwap;
BufUpWall_Odd[i] = current_vwap;
BufDnWall_Odd[i] = current_vwap;
}
}
else
@@ -286,21 +302,22 @@ int OnCalculate(const int rates_total,
BufVWAP_Even[i] = current_vwap;
if(std_dev > 1.0e-9)
{
BufUp15_Even[i] = current_vwap + (1.5 * std_dev);
BufDn15_Even[i] = current_vwap - (1.5 * std_dev);
BufUp20_Even[i] = current_vwap + (2.0 * std_dev);
BufDn20_Even[i] = current_vwap - (2.0 * std_dev);
BufUp25_Even[i] = current_vwap + (2.5 * std_dev);
BufDn25_Even[i] = current_vwap - (2.5 * std_dev);
BufUpFlow_Even[i] = current_vwap + (InpLevelFlow * std_dev);
BufDnFlow_Even[i] = current_vwap - (InpLevelFlow * std_dev);
BufUpExtr_Even[i] = current_vwap + (InpLevelExtreme * std_dev);
BufDnExtr_Even[i] = current_vwap - (InpLevelExtreme * std_dev);
BufUpWall_Even[i] = current_vwap + (InpLevelWall * std_dev);
BufDnWall_Even[i] = current_vwap - (InpLevelWall * std_dev);
}
else
{
BufUp15_Even[i] = current_vwap;
BufDn15_Even[i] = current_vwap;
BufUp20_Even[i] = current_vwap;
BufDn20_Even[i] = current_vwap;
BufUp25_Even[i] = current_vwap;
BufDn25_Even[i] = current_vwap;
// Collapse bands to VWAP if zero volatility
BufUpFlow_Even[i] = current_vwap;
BufDnFlow_Even[i] = current_vwap;
BufUpExtr_Even[i] = current_vwap;
BufDnExtr_Even[i] = current_vwap;
BufUpWall_Even[i] = current_vwap;
BufDnWall_Even[i] = current_vwap;
}
}
}