I use the function below. Nothing really fancy, simple calculations
if (current_spread > max_spread) {max_spread = current_spread;}
if (current_spread < min_spread) {min_spread = current_spread;}
max_spread and min_spread are static variables, which means that they stay in memory.
void DrawSpreadInfo()
{
static bool allow_draw = true;
if (allow_draw==false) {return;}
if (MQLInfoInteger(MQL_TESTER) && !MQLInfoInteger(MQL_VISUAL_MODE)) {allow_draw=false;} // Allowed to draw only once in testing mode
static bool passed = false;
static double max_spread = 0;
static double min_spread = EMPTY_VALUE;
static double avg_spread = 0;
static double avg_add = 0;
static double avg_cnt = 0;
double custom_point = CustomPoint(Symbol());
double current_spread = 0;
if (custom_point > 0) {
current_spread = (SymbolInfoDouble(Symbol(),SYMBOL_ASK)-SymbolInfoDouble(Symbol(),SYMBOL_BID))/custom_point;
}
if (current_spread > max_spread) {max_spread = current_spread;}
if (current_spread < min_spread) {min_spread = current_spread;}
avg_cnt++;
avg_add = avg_add + current_spread;
avg_spread = avg_add / avg_cnt;
int x=0; int y=0;
string name;
// create objects
if (passed == false)
{
passed=true;
name="fxd_spread_current_label";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+1);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 18);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "Spread:");
}
name="fxd_spread_max_label";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+148);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+17);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrOrangeRed);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "max:");
}
name="fxd_spread_avg_label";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+148);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+9);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "avg:");
}
name="fxd_spread_min_label";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+148);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrGold);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "min:");
}
name="fxd_spread_current";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+93);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 18);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "0");
}
name="fxd_spread_max";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+173);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+17);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrOrangeRed);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "0");
}
name="fxd_spread_avg";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+173);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+9);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "0");
}
name="fxd_spread_min";
if (ObjectFind(0, name)==-1) {
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+173);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrGold);
ObjectSetString(0, name, OBJPROP_FONT, "Arial");
ObjectSetString(0, name, OBJPROP_TEXT, "0");
}
}
ObjectSetString(0, "fxd_spread_current", OBJPROP_TEXT, DoubleToStr(current_spread,2));
ObjectSetString(0, "fxd_spread_max", OBJPROP_TEXT, DoubleToStr(max_spread,2));
ObjectSetString(0, "fxd_spread_avg", OBJPROP_TEXT, DoubleToStr(avg_spread,2));
ObjectSetString(0, "fxd_spread_min", OBJPROP_TEXT, DoubleToStr(min_spread,2));
}