mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-05 16:47:44 +00:00
refactor: Upgraded with dynamic 5-Zone hybrid R2-based thermal color matrix (Standard aligned)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//| Copyright 2026, xxxxxxxx|
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2026, xxxxxxxx"
|
||||
#property version "1.01" // Increased decimal digits precision to show micro-pip fluctuations in MTF Data Window
|
||||
#property version "1.10" // Upgraded with dynamic 5-Zone hybrid R2-based thermal color matrix (Standard aligned)
|
||||
#property description "Multi-Timeframe (MTF) Linear Regression Slope."
|
||||
#property description "Displays HTF Linear Regression Slope on current chart cleanly without live-bar warping."
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
|
||||
//--- Levels (Zero line gravity pivot)
|
||||
#property indicator_level1 0.0
|
||||
#property indicator_levelcolor clrSilver
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//--- Plot 1: Slope Histogram (Swapped Bull/Bear Thermal Palette)
|
||||
#property indicator_label1 "Slope MTF"
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
// Colors: 0 = Neutral (Gray), 1 = Bullish (MediumSeaGreen), 2 = Bearish (Tomato)
|
||||
#property indicator_color1 clrGray, clrMediumSeaGreen, clrTomato
|
||||
// Colors:
|
||||
// 0 = Chop/Noise (Gray)
|
||||
// 1 = Bull Climax / Strong (MediumSeaGreen)
|
||||
// 2 = Bull Flow / Weak (PaleGreen)
|
||||
// 3 = Bear Climax / Strong (Crimson)
|
||||
// 4 = Bear Flow / Weak (LightCoral)
|
||||
#property indicator_color1 clrGray, clrMediumSeaGreen, clrPaleGreen, clrCrimson, clrLightCoral
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
@@ -39,7 +39,8 @@ input ENUM_TIMEFRAMES InpTimeframe = PERIOD_H1; // Target
|
||||
input group "Slope Settings"
|
||||
input int InpPeriod = 20; // Observation Period (N)
|
||||
input ENUM_CANDLE_SOURCE InpSource = SOURCE_STANDARD; // Candle Source
|
||||
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // Applied Price (Standard Mode)
|
||||
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // Applied Price (Standard)
|
||||
input double InpTrendLevel = 0.7; // Strong Trend Level (R2 Threshold)
|
||||
|
||||
//--- Buffers
|
||||
double BufferSlope_MTF[];
|
||||
@@ -57,7 +58,7 @@ CLinearRegressionCalculator *g_calculator;
|
||||
bool g_is_mtf_mode = false;
|
||||
ENUM_TIMEFRAMES g_calc_timeframe;
|
||||
bool g_data_ready = false;
|
||||
bool g_data_synced = false;
|
||||
bool g_data_synced = false;
|
||||
int g_htf_count = 0;
|
||||
datetime g_last_htf_time = 0;
|
||||
|
||||
@@ -132,7 +133,7 @@ int OnInit()
|
||||
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin);
|
||||
|
||||
//--- FIXED: Set dynamic decimal digits to match symbol precision + 2 (EURUSD = 7 digits) to show micro-pip details
|
||||
//--- Set dynamic decimal digits to match symbol precision + 2 (EURUSD = 7 digits) to show micro-pip details
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 2);
|
||||
|
||||
//--- Initialize 1-second timer for weekend/async chart refreshes (Only if MTF mode is active)
|
||||
@@ -198,15 +199,29 @@ int OnCalculate(const int rates_total,
|
||||
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : InpPeriod;
|
||||
for(int i = start_index; i < rates_total; i++)
|
||||
{
|
||||
double r = r2[i];
|
||||
double sl = s[i];
|
||||
BufferSlope_MTF[i] = sl;
|
||||
if(sl > 0.0)
|
||||
BufferColors_MTF[i] = 1.0;
|
||||
|
||||
if(r <= 0.3)
|
||||
{
|
||||
BufferColors_MTF[i] = 0.0; // Gray
|
||||
}
|
||||
else
|
||||
if(sl < 0.0)
|
||||
BufferColors_MTF[i] = 2.0;
|
||||
else
|
||||
BufferColors_MTF[i] = 0.0;
|
||||
if(sl >= 0.0)
|
||||
{
|
||||
if(r >= InpTrendLevel)
|
||||
BufferColors_MTF[i] = 1.0; // Strong Bullish
|
||||
else
|
||||
BufferColors_MTF[i] = 2.0; // Weak Bullish
|
||||
}
|
||||
else // sl < 0.0
|
||||
{
|
||||
if(r >= InpTrendLevel)
|
||||
BufferColors_MTF[i] = 3.0; // Strong Bearish
|
||||
else
|
||||
BufferColors_MTF[i] = 4.0; // Weak Bearish
|
||||
}
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
@@ -302,7 +317,6 @@ int OnCalculate(const int rates_total,
|
||||
}
|
||||
|
||||
//--- 3. FIXED: Dynamically adjust 'start' to the beginning of the current forming HTF bar
|
||||
//--- This forces the entire forming LTF step block to remain perfectly flat, updating on every tick!
|
||||
int start = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
||||
|
||||
int first_bar_of_forming_htf = rates_total - 1;
|
||||
@@ -327,17 +341,30 @@ int OnCalculate(const int rates_total,
|
||||
int idx_htf = g_htf_count - 1 - shift_htf;
|
||||
if(idx_htf >= 0 && idx_htf < g_htf_count)
|
||||
{
|
||||
double r2 = h_res_r2[idx_htf];
|
||||
double sl = h_res_slope[idx_htf];
|
||||
BufferSlope_MTF[i] = sl;
|
||||
|
||||
// Color Logic
|
||||
if(sl > 0.0)
|
||||
BufferColors_MTF[i] = 1.0; // Index 1: Green (Bullish)
|
||||
// Color Logic based on HTF direction and HTF R2 strength
|
||||
if(r2 <= 0.3)
|
||||
{
|
||||
BufferColors_MTF[i] = 0.0; // Index 0: Gray (Chop)
|
||||
}
|
||||
else
|
||||
if(sl < 0.0)
|
||||
BufferColors_MTF[i] = 2.0; // Index 2: Red (Bearish)
|
||||
if(sl >= 0.0)
|
||||
{
|
||||
if(r2 >= InpTrendLevel)
|
||||
BufferColors_MTF[i] = 1.0; // Index 1: MediumSeaGreen (Strong Bull)
|
||||
else
|
||||
BufferColors_MTF[i] = 2.0; // Index 2: PaleGreen (Weak Bull)
|
||||
}
|
||||
else
|
||||
BufferColors_MTF[i] = 0.0; // Index 0: Gray (Neutral)
|
||||
{
|
||||
if(r2 >= InpTrendLevel)
|
||||
BufferColors_MTF[i] = 3.0; // Index 3: Crimson (Strong Bear)
|
||||
else
|
||||
BufferColors_MTF[i] = 4.0; // Index 4: LightCoral (Weak Bear)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user