last works ... add new Ocillators ...

This commit is contained in:
2025-03-28 07:24:05 +03:30
parent c00704b83b
commit b2c585bc93
11 changed files with 3380 additions and 43 deletions
+135
View File
@@ -0,0 +1,135 @@
//+------------------------------------------------------------------+
//| CumulativeDelta.mq5 |
//| Copyright © 2023, YourName |
//| |
//+------------------------------------------------------------------+
#property copyright "YourName"
#property link "https://www.yourwebsite.com"
#property version "1.00"
//
#include "../Libraries/x-saherelm.common.lib.mq5"
//
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 3
//
//--- Plot settings for Line
#property indicator_label1 "Cumulative Delta"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
//
//--- Plot settings for Histogram
#property indicator_label2 "Delta"
#property indicator_type2 DRAW_HISTOGRAM
#property indicator_color2 clrGray
//
//--- Plot settings for Moving Average line
#property indicator_label3 "Signal"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrOrchid
//
//--- Input parameters
input int MAPeriod = 14; // Period for the moving average
//
//--- Indicator buffers
double MABuffer[];
double DeltaBuffer[];
double CumulativeDeltaBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//
// Attach buffer to the indicator
SetIndexBuffer(2, MABuffer, INDICATOR_DATA);
SetIndexBuffer(1, DeltaBuffer, INDICATOR_DATA);
SetIndexBuffer(0, CumulativeDeltaBuffer, INDICATOR_DATA);
IndicatorSetString(INDICATOR_SHORTNAME, "Cumulative Delta");
//
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[] //
)
{
//
// Start from the first uncalculated bar
int start = MathMax(prev_calculated - 1, 0);
//
// Loop through bars
for (int i = start; i < rates_total; i++)
{
//
// Calculate Delta based on bar-level data
double delta = 0.0;
if (close[i] > open[i])
{
delta = (double)tick_volume[i]; // Buying pressure (bullish bar)
}
else if (close[i] < open[i])
{
delta = -(double)tick_volume[i]; // Selling pressure (bearish bar)
}
//
// Accumulate cumulative delta
if (i == 0)
{
//
DeltaBuffer[i] = delta;
CumulativeDeltaBuffer[i] = delta; // First bar starts with delta
}
else
{
//
DeltaBuffer[i] = DeltaBuffer[i - 1] + delta;
CumulativeDeltaBuffer[i] = CumulativeDeltaBuffer[i - 1] + delta;
}
//
// Calculate Moving Average of Cumulative Delta
if (i >= MAPeriod - 1)
{
//
double sum = 0.0;
for (int j = 0; j < MAPeriod; j++)
{
sum += CumulativeDeltaBuffer[i - j];
}
//
MABuffer[i] = sum / MAPeriod; // Simple Moving Average
}
else
{
MABuffer[i] = EMPTY_VALUE; // Not enough data for MA
}
}
//
return (rates_total);
}
//+------------------------------------------------------------------+
+210
View File
@@ -0,0 +1,210 @@
//+------------------------------------------------------------------+
//| BuySellVolumes.mq5 |
//| Copyright © 2023, YourName |
//| |
//+------------------------------------------------------------------+
#property copyright "YourName"
#property link "https://www.yourwebsite.com"
#property version "1.00"
//
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 4
//--- Plot settings for Buy Volume
#property indicator_label1 "Buy Volume"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrLime
//--- Plot settings for Sell Volume
#property indicator_label2 "Sell Volume"
#property indicator_type2 DRAW_HISTOGRAM
#property indicator_color2 clrRed
//--- Plot settings for Buy Volume MA
#property indicator_label3 "Buy Volume MA"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrGreen
//--- Plot settings for Sell Volume MA
#property indicator_label4 "Sell Volume MA"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrRed
//--- Input parameters
input int MAPeriod = 14; // Period for the moving average
//--- Indicator buffers
double BuyVolumeBuffer[]; // Buffer for Buy Volume
double SellVolumeBuffer[]; // Buffer for Sell Volume
double BuyVolumeMABuffer[]; // Buffer for Buy Volume Moving Average
double SellVolumeMABuffer[]; // Buffer for Sell Volume Moving Average
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//
// Attach buffers to the indicator
SetIndexBuffer(0, BuyVolumeBuffer, INDICATOR_DATA);
SetIndexBuffer(1, SellVolumeBuffer, INDICATOR_DATA);
SetIndexBuffer(2, BuyVolumeMABuffer, INDICATOR_DATA);
SetIndexBuffer(3, SellVolumeMABuffer, INDICATOR_DATA);
//
// Set short name for the indicator
IndicatorSetString(INDICATOR_SHORTNAME, "Buy and Sell Volumes");
//
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[] //
)
{
//
// Start from the first uncalculated bar
int start = MathMax(prev_calculated - 1, 0);
//
// Loop through bars
for (int i = start; i < rates_total; i++)
{
//
// Calculate Buy and Sell Volumes based on bar-level data
double buyVolume = 0.0;
double sellVolume = 0.0;
//
if (close[i] > open[i])
{
//
buyVolume = (double)tick_volume[i]; // Buying pressure (bullish bar)
sellVolume = 0.0;
}
else if (close[i] < open[i])
{
//
sellVolume = (double)tick_volume[i]; // Selling pressure (bearish bar)
buyVolume = 0.0;
}
else
{
//
// Neutral bar: split volume equally between buy and sell
buyVolume = tick_volume[i] / 2.0;
sellVolume = tick_volume[i] / 2.0;
}
//
// Store Buy and Sell Volumes in their respective buffers
BuyVolumeBuffer[i] = buyVolume;
SellVolumeBuffer[i] = sellVolume;
//
// Calculate Moving Averages for Buy and Sell Volumes
if (i >= MAPeriod - 1)
{
//
// Calculate Simple Moving Average for Buy Volume
double buySum = 0.0;
for (int j = 0; j < MAPeriod; j++)
buySum += BuyVolumeBuffer[i - j];
BuyVolumeMABuffer[i] = buySum / MAPeriod;
//
// Calculate Simple Moving Average for Sell Volume
double sellSum = 0.0;
for (int j = 0; j < MAPeriod; j++)
sellSum += SellVolumeBuffer[i - j];
SellVolumeMABuffer[i] = sellSum / MAPeriod;
}
else
{
//
// Not enough data for MA
BuyVolumeMABuffer[i] = EMPTY_VALUE;
SellVolumeMABuffer[i] = EMPTY_VALUE;
}
}
//
// Normalize all values between 0 and 100
// NormalizeValues(rates_total);
//
return (rates_total);
}
//+------------------------------------------------------------------+
//| Normalize all values between 0 and 100 |
//+------------------------------------------------------------------+
void NormalizeValues(int rates_total)
{
//
// Find the maximum and minimum values across all buffers
double maxValue = 0.0;
double minValue = DBL_MAX;
//
for (int i = 0; i < rates_total; i++)
{
//
if (BuyVolumeBuffer[i] != EMPTY_VALUE && BuyVolumeBuffer[i] > maxValue)
maxValue = BuyVolumeBuffer[i];
if (SellVolumeBuffer[i] != EMPTY_VALUE && SellVolumeBuffer[i] > maxValue)
maxValue = SellVolumeBuffer[i];
if (BuyVolumeMABuffer[i] != EMPTY_VALUE && BuyVolumeMABuffer[i] > maxValue)
maxValue = BuyVolumeMABuffer[i];
if (SellVolumeMABuffer[i] != EMPTY_VALUE && SellVolumeMABuffer[i] > maxValue)
maxValue = SellVolumeMABuffer[i];
//
if (BuyVolumeBuffer[i] != EMPTY_VALUE && BuyVolumeBuffer[i] < minValue)
minValue = BuyVolumeBuffer[i];
if (SellVolumeBuffer[i] != EMPTY_VALUE && SellVolumeBuffer[i] < minValue)
minValue = SellVolumeBuffer[i];
if (BuyVolumeMABuffer[i] != EMPTY_VALUE && BuyVolumeMABuffer[i] < minValue)
minValue = BuyVolumeMABuffer[i];
if (SellVolumeMABuffer[i] != EMPTY_VALUE && SellVolumeMABuffer[i] < minValue)
minValue = SellVolumeMABuffer[i];
}
//
// Avoid division by zero
if (maxValue == minValue)
return;
//
// Normalize all values
for (int i = 0; i < rates_total; i++)
{
//
if (BuyVolumeBuffer[i] != EMPTY_VALUE)
BuyVolumeBuffer[i] = ((BuyVolumeBuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
if (SellVolumeBuffer[i] != EMPTY_VALUE)
SellVolumeBuffer[i] = ((SellVolumeBuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
if (BuyVolumeMABuffer[i] != EMPTY_VALUE)
BuyVolumeMABuffer[i] = ((BuyVolumeMABuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
if (SellVolumeMABuffer[i] != EMPTY_VALUE)
SellVolumeMABuffer[i] = ((SellVolumeMABuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
}
}
//+------------------------------------------------------------------+
@@ -825,7 +825,7 @@ class XC121SMCCycleHelper : public XCBase
}
//
datetime GetNearestCloseOverX3MAFast(
datetime DetectNearestCloseOverX3MAFast(
XOHCL &bar,
int maxAllowedBars = 20 //
)
@@ -891,7 +891,7 @@ class XC121SMCCycleHelper : public XCBase
}
//
datetime GetNearestCloseUnderX3MAFast(
datetime DetectNearestCloseUnderX3MAFast(
XOHCL &bar,
int maxAllowedBars = 20 //
)