The indicator is supposed to draw a red circle using wingdings under an up candle when its volume is higher than the individual volumes of the previous two up candles.
The same logic for down candles. Using text, e.g. draw a letter O, instead of wingdings also does not work.
Suggestions are welcome.
//+------------------------------------------------------------------+//| Vifta-a.mq4 |//| Change of Behaviour Indicator |//+------------------------------------------------------------------+#property copyright"Copyright 2025, MetaQuotes Ltd."#property link"https://www.mql5.com"#property version"1.08"#property strict#property indicator_chart_windowinputint LookbackBars = 100; // Number of bars to checkinputint TextOffset = 20; // Distance of circle from the candle (in pixels)inputint FontSize = 14; // Wingdings font size//+------------------------------------------------------------------+//| Initialization |//+------------------------------------------------------------------+intOnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Main Calculation |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
if (rates_total < 10)
return(0);
for (int i = rates_total - 2; i >= rates_total - LookbackBars && i >= 2; i--)
{
bool isUp = close[i] > open[i];
bool isDown = close[i] < open[i];
int found = 0;
int last1 = -1, last2 = -1;
// Search backwards for last two matching bars (same direction)for (int j = i - 1; j >= 0 && found < 2; j--)
{
if (isUp && close[j] > open[j])
{
if (last1 == -1) last1 = j;
else last2 = j;
found++;
}
elseif (isDown && close[j] < open[j])
{
if (last1 == -1) last1 = j;
else last2 = j;
found++;
}
}
// Proceed only if both previous same-direction bars foundif (last1 != -1 && last2 != -1)
{
if (volume[i] > volume[last1] && volume[i] > volume[last2])
{
string objName = "COB_" + IntegerToString(i);
// Fix ObjectFind() logicif (ObjectFind(objName) == -1) // Correct way to check if object exists
{
bool success = ObjectCreate(objName, OBJ_TEXT, 0, time[i], 0); // Y set to 0, we'll adjust using YDISTANCEif (success)
{
ObjectSetText(objName, "l", FontSize, "Wingdings", clrRed); // 'l' in Wingdings is a solid circleObjectSetInteger(ChartID(), objName, OBJPROP_YDISTANCE, TextOffset); // Ensuring correct Y distance positioning
}
else
{
Print("Failed to create object: ", objName);
}
}
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
The indicator is supposed to draw a red circle using wingdings under an up candle when its volume is higher than the individual volumes of the previous two up candles.
The same logic for down candles. Using text, e.g. draw a letter O, instead of wingdings also does not work.
Suggestions are welcome.