0% found this document useful (0 votes)
17 views4 pages

deepseek_mql4_20250519_bd21c1

The document is a script for a custom MetaTrader 4 indicator called 'Volume Delta' that analyzes buy and sell volumes, calculates exponential moving averages (EMAs), and provides alerts for crossovers. It includes customizable input parameters for visual features and volume confirmation settings. The script is structured with initialization and calculation functions to manage the indicator's behavior and display on the trading chart.

Uploaded by

Amit Badge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

deepseek_mql4_20250519_bd21c1

The document is a script for a custom MetaTrader 4 indicator called 'Volume Delta' that analyzes buy and sell volumes, calculates exponential moving averages (EMAs), and provides alerts for crossovers. It includes customizable input parameters for visual features and volume confirmation settings. The script is structured with initialization and calculation functions to manage the indicator's behavior and display on the trading chart.

Uploaded by

Amit Badge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

//+------------------------------------------------------------------+

//| 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");

SetIndexStyle(1, DRAW_HISTOGRAM, EMPTY, 1, SellColor);


SetIndexBuffer(1, SellVolumeBuffer);
SetIndexLabel(1, "Sell Volume");
SetIndexStyle(2, DRAW_LINE, EMPTY, 2, BuyColor);
SetIndexBuffer(2, TotalVolumeBuffer);
SetIndexLabel(2, "Total Volume");

SetIndexStyle(3, DRAW_HISTOGRAM, EMPTY, 1, BuyColor);


SetIndexBuffer(3, HigherVolumeBuffer);
SetIndexLabel(3, "Higher Volume");

SetIndexStyle(4, DRAW_HISTOGRAM, EMPTY, 1, SellColor);


SetIndexBuffer(4, LowerVolumeBuffer);
SetIndexLabel(4, "Lower Volume");

SetIndexStyle(5, DRAW_LINE, EMPTY, 2, BuyColor);


SetIndexBuffer(5, EMABufferFast);
SetIndexLabel(5, "Fast EMA");

SetIndexStyle(6, DRAW_LINE, EMPTY, 2, SellColor);


SetIndexBuffer(6, EMABufferSlow);
SetIndexLabel(6, "Slow EMA");

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++;

for(int i = limit-1; i >= 0; i--)


{
// Calculate buy and sell volume
double range = high[i] - low[i];
double buyVol = range > 0 ? volume[i] * (close[i] - low[i]) / range : 0;
double sellVol = volume[i] - buyVol;

// Store values in buffers


BuyVolumeBuffer[i] = buyVol;
SellVolumeBuffer[i] = sellVol;
TotalVolumeBuffer[i] = volume[i];

// Determine higher/lower volume


bool isBuyGreater = buyVol > sellVol;
HigherVolumeBuffer[i] = isBuyGreater ? buyVol : sellVol;
LowerVolumeBuffer[i] = isBuyGreater ? sellVol : buyVol;

// 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);

// Check for crossovers (for alerts)


if(i == 0 && ShowEMA && Bars > MathMax(FastEMALength, SlowEMALength))
{
bool crossover = EMABufferFast[1] <= EMABufferSlow[1] && EMABufferFast[0]
> EMABufferSlow[0];
bool crossunder = EMABufferFast[1] >= EMABufferSlow[1] && EMABufferFast[0]
< EMABufferSlow[0];

if(UseVolumeConfirmation)
{
double volumeMA = iMA(NULL, 0, VolumeConfirmationLength, 0, MODE_SMA,
VOLUME_TICK, i);
bool volumeConfirmed = volume[i] > volumeMA;

if(crossover && volumeConfirmed && lastAlertBar != Bars)


{
Alert("Bullish EMA Crossover on ", Symbol(), " ", Period());
lastAlertBar = Bars;
}
else if(crossunder && volumeConfirmed && lastAlertBar != Bars)
{
Alert("Bearish EMA Crossunder on ", Symbol(), " ", Period());
lastAlertBar = Bars;
}
}
else
{
if(crossover && lastAlertBar != Bars)
{
Alert("Bullish EMA Crossover on ", Symbol(), " ", Period());
lastAlertBar = Bars;
}
else if(crossunder && lastAlertBar != Bars)
{
Alert("Bearish EMA Crossunder on ", Symbol(), " ", Period());
lastAlertBar = Bars;
}
}
}

// Apply candle coloring if enabled


if(UseCandleColors)
{
double percentBuy = buyVol / volume[i] * 100;
double percentSell = 100 - percentBuy;

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;

string labelName = "VolDeltaLabel_" + name + "_" + IntegerToString(bar);

if(ObjectFind(0, labelName) < 0)


{
ObjectCreate(0, labelName, OBJ_TEXT, 0, Time[bar], price);
}

ObjectSetString(0, labelName, OBJPROP_TEXT, text);


ObjectSetInteger(0, labelName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, labelName, OBJPROP_FONTSIZE, fontSize);
}

//+------------------------------------------------------------------+
//| 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;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy