Hi at the moment this is indicator that displays the spread as text on chart.
I would like to add an extra input whereby if the spread goes over a set, user-defined figure/Input it plays an audio alert for a few seconds, also a pop-up window is preferable too.
The current Input Parameters are:
font_color (default = Red) — color of the spread indicator.
font_size (default = 14) — size of the spread indicator.
font_face (default = "Arial") — font of the spread indicator.
corner (default = 0/ANCHOR_LEFT_UPPER) — location for the spread indicator. In MT4: 0 — for top-left corner, 1 — top-right, 2 — bottom-left, 3 — bottom-right. In MT5 it's quite obvious.
spread_distance_x (default = 10) — horizontal distance from the corner to indicator.
spread_distance_y (default = 130) — vertical distance from the corner to indicator.
normalize (default = false) — if true then the spread value is normalized and is given in conventional pips. If false then the spread is given in the current pips as is. Can be useful for nonstandard quotes.
N.b on ‘normalize’… my price quotes are to 5 decimal places. When ‘normalize’ is set to false (default) I receive a value 10x’s that of when set to true. The true value corresponds to actual pips. E.g. if spread is 2.4 then set to false indicator displays 24, set to true 2.4. I just wanted to point this out first incase it prevents issue later.
Any help gratefully appreciated.
Here is the source code:
//±-----------------------------------------------------------------+
#property indicator_chart_window
extern color font_color = Red;
extern int font_size = 14;
extern string font_face = “Arial”;
extern int corner = 0; //0 - for top-left corner, 1 - top-right, 2 - bottom-left, 3 - bottom-right
extern int spread_distance_x = 10;
extern int spread_distance_y = 130;
extern bool normalize = false; //If true then the spread is normalized to traditional pips
double Poin;
int n_digits = 0;
double divider = 1;
//±-----------------------------------------------------------------+
//| Custom indicator initialization function |
//±-----------------------------------------------------------------+
int init()
{
//Checking for unconvetional Point digits number
if (Point == 0.00001) Poin = 0.0001; //5 digits
else if (Point == 0.001) Poin = 0.01; //3 digits
else Poin = Point; //Normal
ObjectCreate(“Spread”, OBJ_LABEL, 0, 0, 0);
ObjectSet(“Spread”, OBJPROP_CORNER, corner);
ObjectSet(“Spread”, OBJPROP_XDISTANCE, spread_distance_x);
ObjectSet(“Spread”, OBJPROP_YDISTANCE, spread_distance_y);
double spread = MarketInfo(Symbol(), MODE_SPREAD);
if ((Poin > Point) && (normalize))
{
divider = 10.0;
n_digits = 1;
}
ObjectSetText(“Spread”, “Spread: " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits) + " points.”, font_size, font_face, font_color);
return(0);
}
//±-----------------------------------------------------------------+
//| Custom indicator deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
ObjectDelete(“Spread”);
return(0);
}
//±-----------------------------------------------------------------+
//| Custom indicator iteration function |
//±-----------------------------------------------------------------+
int start()
{
RefreshRates();
double spread = (Ask - Bid) / Point;
ObjectSetText(“Spread”, “Spread: " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits) + " points.”, font_size, font_face, font_color);
return(0);
}
//±-----------------------------------------------------------------+