You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Define indicator buffers
double BearPressureBuffer[];
double BullPressureBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Set indicator buffers
SetIndexBuffer(0, BearPressureBuffer);
SetIndexBuffer(1, BullPressureBuffer);
// Set indicator label
IndicatorShortName("Sophisticated Buy/Sell Pressure");
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[])
{
for (int i = prev_calculated; i < rates_total; i++)
{
double bear_pressure = 0.0;
double bull_pressure = 0.0;
double candle_range = high[i] - low[i];
double candle_body = MathAbs(close[i] - open[i]);
double upper_wick = high[i] - MathMax(open[i], close[i]);
double lower_wick = MathMin(open[i], close[i]) - low[i];
// Calculate volume distribution within the candle
double total_volume = volume[i];
double buy_volume = tick_volume[i] * (upper_wick / candle_range);
double sell_volume = tick_volume[i] * (lower_wick / candle_range);
// Calculate relative buy and sell pressure
if (candle_body > 0) // To avoid division by zero
{
bear_pressure = sell_volume / candle_body;
bull_pressure = buy_volume / candle_body;
}
BearPressureBuffer[i] = bear_pressure;
BullPressureBuffer[i] = bull_pressure;
}
return(rates_total);
}
In this version, the code considers various aspects of the candle's characteristics, such as its range, body size, and wick size, to determine buy and sell pressure. It also takes into account the distribution of volume within the candle to calculate relative pressures. This should provide a more nuanced perspective on the balance between buy and sell activity.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Beta Was this translation helpful? Give feedback.
All reactions