mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-07-27 20:47:44 +00:00
refactor(indicators): new calculator
This commit is contained in:
@@ -1,95 +1,57 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| RVOL_Pro.mq5 |
|
//| RVOL_Pro.mq5 |
|
||||||
//| Relative Volume (RVOL) Professional Indicator |
|
//| Copyright 2026, xxxxxxxx|
|
||||||
//| Copyright 2026, xxxxxxxx |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2026, xxxxxxxx"
|
#property copyright "Copyright 2026, xxxxxxxx"
|
||||||
#property version "1.12" // Adopted standard Real Volume check
|
#property version "1.00"
|
||||||
#property description "Displays volume as a ratio of its moving average."
|
#property description "Relative Volume Indicator."
|
||||||
|
#property description "Highlights institutional activity spikes > 2.0."
|
||||||
|
|
||||||
#property indicator_separate_window
|
#property indicator_separate_window
|
||||||
#property indicator_buffers 2
|
#property indicator_buffers 2
|
||||||
#property indicator_plots 1
|
#property indicator_plots 1
|
||||||
|
|
||||||
//--- Plot Settings
|
|
||||||
#property indicator_label1 "RVOL"
|
|
||||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 2
|
|
||||||
|
|
||||||
//--- Color definitions for the histogram
|
|
||||||
#property indicator_color1 clrSilver, clrDodgerBlue, clrGold
|
|
||||||
|
|
||||||
//--- Levels
|
//--- Levels
|
||||||
#property indicator_level1 1.5
|
#property indicator_level1 1.0
|
||||||
#property indicator_level2 2.5
|
#property indicator_level2 2.0
|
||||||
|
#property indicator_levelcolor clrSilver
|
||||||
#property indicator_levelstyle STYLE_DOT
|
#property indicator_levelstyle STYLE_DOT
|
||||||
|
|
||||||
//--- Include Engine
|
//--- Plot: RVOL Histogram (Colored)
|
||||||
#include <MyIncludes\RVOL_Calculator.mqh>
|
#property indicator_label1 "RVOL"
|
||||||
|
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color1 clrGray, clrDodgerBlue, clrOrangeRed // Low, Normal, High
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
#property indicator_width1 3
|
||||||
|
|
||||||
|
#include <MyIncludes\RelativeVolume_Calculator.mqh>
|
||||||
|
|
||||||
//--- Input Parameters
|
//--- Input Parameters
|
||||||
input group "Calculation Settings"
|
input int InpPeriod = 20; // Average Volume Period
|
||||||
input int InpPeriod = 20; // Lookback period for average volume
|
input double InpThreshold = 2.0; // High Activity Threshold
|
||||||
input ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; // Volume Type (Tick or Real)
|
|
||||||
|
|
||||||
input group "Visual Settings"
|
|
||||||
input double InpLevelHigh = 1.5; // Level for 'High' volume
|
|
||||||
input double InpLevelExtreme= 2.5; // Level for 'Extreme' volume
|
|
||||||
input color InpColorNormal = clrSilver;
|
|
||||||
input color InpColorHigh = clrDodgerBlue;
|
|
||||||
input color InpColorExtreme= clrGold;
|
|
||||||
|
|
||||||
//--- Buffers
|
//--- Buffers
|
||||||
double ExtRvolBuffer[];
|
double BufferRVOL[];
|
||||||
double ExtColorBuffer[];
|
double BufferColors[]; // 0=Low, 1=Normal, 2=High
|
||||||
|
|
||||||
//--- Global Calculator
|
//--- Global Object
|
||||||
CRVOLCalculator *g_calculator;
|
CRelativeVolumeCalculator *g_calculator;
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| OnInit |
|
//| OnInit |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
// --- ADOPTED: Real Volume Availability Check (from PVI/NVI Pro) ---
|
SetIndexBuffer(0, BufferRVOL, INDICATOR_DATA);
|
||||||
if(InpVolumeType == VOLUME_REAL && SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_LIMIT) == 0)
|
SetIndexBuffer(1, BufferColors, INDICATOR_COLOR_INDEX);
|
||||||
{
|
|
||||||
Print("RVOL_Pro Error: Real Volume is not available for '", _Symbol, "'. The indicator will not be drawn. Please switch to Tick Volume.");
|
|
||||||
return(INIT_FAILED);
|
|
||||||
}
|
|
||||||
// --- End of Check ---
|
|
||||||
|
|
||||||
//--- Bind buffers
|
string name = StringFormat("RVOL(%d)", InpPeriod);
|
||||||
SetIndexBuffer(0, ExtRvolBuffer, INDICATOR_DATA);
|
IndicatorSetString(INDICATOR_SHORTNAME, name);
|
||||||
SetIndexBuffer(1, ExtColorBuffer, INDICATOR_COLOR_INDEX);
|
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||||
|
|
||||||
//--- Use standard chronological array order
|
g_calculator = new CRelativeVolumeCalculator();
|
||||||
ArraySetAsSeries(ExtRvolBuffer, false);
|
|
||||||
ArraySetAsSeries(ExtColorBuffer, false);
|
|
||||||
|
|
||||||
//--- Set Plot Properties
|
|
||||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriod);
|
|
||||||
|
|
||||||
//--- Dynamically set colors and levels from inputs
|
|
||||||
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
|
|
||||||
PlotIndexSetString(0, PLOT_LABEL, StringFormat("RVOL(%d)", InpPeriod));
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("RVOL(%d)", InpPeriod));
|
|
||||||
|
|
||||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, InpLevelHigh);
|
|
||||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, InpLevelExtreme);
|
|
||||||
|
|
||||||
PlotIndexSetInteger(0, PLOT_LINE_COLOR, 0, InpColorNormal);
|
|
||||||
PlotIndexSetInteger(0, PLOT_LINE_COLOR, 1, InpColorHigh);
|
|
||||||
PlotIndexSetInteger(0, PLOT_LINE_COLOR, 2, InpColorExtreme);
|
|
||||||
|
|
||||||
//--- Initialize the calculator engine
|
|
||||||
g_calculator = new CRVOLCalculator();
|
|
||||||
if(!g_calculator.Init(InpPeriod))
|
if(!g_calculator.Init(InpPeriod))
|
||||||
{
|
return INIT_FAILED;
|
||||||
Print("RVOL_Pro Error: Failed to initialize calculator engine.");
|
|
||||||
return(INIT_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(INIT_SUCCEEDED);
|
return(INIT_SUCCEEDED);
|
||||||
}
|
}
|
||||||
@@ -117,34 +79,30 @@ int OnCalculate(const int rates_total,
|
|||||||
const long &volume[],
|
const long &volume[],
|
||||||
const int &spread[])
|
const int &spread[])
|
||||||
{
|
{
|
||||||
if(InpVolumeType == VOLUME_TICK)
|
if(rates_total < InpPeriod)
|
||||||
{
|
return 0;
|
||||||
g_calculator.Calculate(rates_total, prev_calculated, tick_volume, ExtRvolBuffer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_calculator.Calculate(rates_total, prev_calculated, volume, ExtRvolBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
int limit = (prev_calculated == 0) ? InpPeriod : prev_calculated - 1;
|
// 1. Calculate
|
||||||
|
// Note: RVOL uses Volume (Tick or Real). Usually Tick Volume in Forex.
|
||||||
|
g_calculator.Calculate(rates_total, prev_calculated, tick_volume, BufferRVOL);
|
||||||
|
|
||||||
for(int i = limit; i < rates_total; i++)
|
// 2. Color Logic
|
||||||
|
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
||||||
|
|
||||||
|
for(int i = start_index; i < rates_total; i++)
|
||||||
{
|
{
|
||||||
if(ExtRvolBuffer[i] >= InpLevelExtreme)
|
double val = BufferRVOL[i];
|
||||||
{
|
|
||||||
ExtColorBuffer[i] = 2; // Index for Extreme color
|
if(val > InpThreshold)
|
||||||
}
|
BufferColors[i] = 2.0; // High (Instituional)
|
||||||
else
|
else
|
||||||
if(ExtRvolBuffer[i] >= InpLevelHigh)
|
if(val > 1.0)
|
||||||
{
|
BufferColors[i] = 1.0; // Normal
|
||||||
ExtColorBuffer[i] = 1; // Index for High color
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
BufferColors[i] = 0.0; // Low
|
||||||
ExtColorBuffer[i] = 0; // Index for Normal color
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user