deepseek_mql4_20250519_bd21c1
deepseek_mql4_20250519_bd21c1
//| VolumeDelta.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, hapharmonic"
#property link "https://www.metaquotes.net/"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 clrDodgerBlue // Buy volume
#property indicator_color2 clrOrangeRed // Sell volume
#property indicator_color3 clrDodgerBlue // Total volume (buy)
#property indicator_color4 clrOrangeRed // Total volume (sell)
#property indicator_color5 clrDodgerBlue // EMA Fast
#property indicator_color6 clrOrangeRed // EMA Slow
// Input parameters
input bool UseCandleColors = true; // Volume on Candles
input color BuyColor = clrDodgerBlue; // Volume Buy
input color SellColor = clrOrangeRed; // Volume Sell
input bool ShowLabels = false; // Show Labels
input bool ShowHistory = true; // Show History
input bool ShowEMA = true; // Show EMA
input bool UseVolumeConfirmation = true; // Use Volume Confirmation
input int FastEMALength = 12; // Fast EMA Length
input int SlowEMALength = 26; // Slow EMA Length
input int VolumeConfirmationLength = 6; // Volume Confirmation Length
// Buffers
double BuyVolumeBuffer[];
double SellVolumeBuffer[];
double TotalVolumeBuffer[];
double HigherVolumeBuffer[];
double LowerVolumeBuffer[];
double EMABufferFast[];
double EMABufferSlow[];
// Global variables
int lastAlertBar = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Set indicator properties
IndicatorShortName("Volume Delta");
IndicatorDigits(Digits);
// Set up buffers
SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, 1, BuyColor);
SetIndexBuffer(0, BuyVolumeBuffer);
SetIndexLabel(0, "Buy Volume");
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[])
{
int limit = rates_total - prev_calculated;
if(prev_calculated > 0) limit++;
// Calculate EMAs
EMABufferFast[i] = iMA(NULL, 0, FastEMALength, 0, MODE_EMA, PRICE_CLOSE, i);
EMABufferSlow[i] = iMA(NULL, 0, SlowEMALength, 0, MODE_EMA, PRICE_CLOSE, i);
if(UseVolumeConfirmation)
{
double volumeMA = iMA(NULL, 0, VolumeConfirmationLength, 0, MODE_SMA,
VOLUME_TICK, i);
bool volumeConfirmed = volume[i] > volumeMA;
if(isBuyGreater)
{
// Color the candle based on buy volume percentage
// MT4 doesn't have gradient candles, so we'd need to implement this
differently
// Possibly using object creation or custom drawing
}
else
{
// Color the candle based on sell volume percentage
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Function to create text labels (similar to Pine's label.new) |
//+------------------------------------------------------------------+
void CreateLabel(string name, int bar, double price, string text, color clr, int
fontSize=10)
{
if(!ShowLabels) return;
//+------------------------------------------------------------------+
//| Function to check volume confirmation |
//+------------------------------------------------------------------+
bool IsVolumeConfirmed(int index, int length)
{
double volumeMA = iMA(NULL, 0, length, 0, MODE_SMA, VOLUME_TICK, index);
return Volume[index] > volumeMA;
}