Let's address the issues one by one.
Issue 1: Possible Loss of Data Due to Type Conversion
This warning typically occurs when you are assigning a value of one type to a variable of another type, which might result in data loss. In the context of MQL4, this often happens when dealing with integer and double types.
To resolve this, ensure that you are using the correct data types and performing explicit type casting where necessary.
Issue 2: 'OBJPROP_TRANSPARENCY' - Undeclared Identifier
The OBJPROP_TRANSPARENCY property is used to set the transparency level of graphical objects. This property is available in MQL4, but you need to ensure that you are using it correctly and that your MQL4 version supports it.
Revised Code
Here’s the revised code with corrections for both issues:
//+------------------------------------------------------------------+
//| SDZones.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
// Buffers to hold the supply and demand zone levels
double SupplyZoneBuffer[];
double DemandZoneBuffer[];
// Input parameters
input int ZoneLength = 20; // Length to look back for zones
input double VolumeThreshold = 1000000.0; // Volume threshold to consider a swing significant
input double PriceDeviation = 30.0; // Price deviation in points to consider a swing significant
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Indicator buffers mapping
SetIndexBuffer(0, SupplyZoneBuffer);
SetIndexBuffer(1, DemandZoneBuffer);
SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1, Blue);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1, Red);
SetIndexArrow(0, 233); // Up arrow for supply
SetIndexArrow(1, 234); // Down arrow for demand
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(limit < 0) return(0);
// Loop through the bars to find supply and demand zones
for(int i = limit - 1; i >= ZoneLength; i--)
{
double highest_high = 0;
double lowest_low = 0;
long total_volume = 0;
// Find the highest high and lowest low in the lookback period
for(int j = i; j > i - ZoneLength; j--)
{
if(high[j] > highest_high) highest_high = high[j];
if(low[j] < lowest_low || lowest_low == 0) lowest_low = low[j];
total_volume += volume[j];
}
// Check if the volume is significant and the price deviation is enough
if(total_volume >= VolumeThreshold && MathAbs(highest_high - lowest_low) >= PriceDeviation)
{
// Check for supply zone (significant high)
if(close[i] < highest_high)
{
SupplyZoneBuffer[i] = highest_high;
DemandZoneBuffer[i] = 0;
}
// Check for demand zone (significant low)
else if(close[i] > lowest_low)
{
SupplyZoneBuffer[i] = 0;
DemandZoneBuffer[i] = lowest_low;
}
}
else
{
SupplyZoneBuffer[i] = 0;
DemandZoneBuffer[i] = 0;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+