SDX-SweetSpots1
Download scriptThe SweetSpots indicator is designed to provide traders with a visual framework of key price levels directly on their trading charts. Rather than relying on complex mathematical formulas or erratic market movements, this tool creates a structured "grid" of horizontal lines based on fixed price intervals.
How the Logic Works
The script functions by identifying specific price benchmarks and plotting them automatically to help visualize potential areas of interest. Here is the breakdown of its internal logic:
1. Price Interval Calculation The indicator looks at the current market price and rounds it down to the nearest significant increment. Specifically, it calculates "Sweet Spots" based on intervals of 50 pips (or points, depending on your broker's pricing). This ensures that the lines are consistently spaced across the chart.
2. Dynamic Level Generation Instead of showing just one line, the script automatically generates a range of levels above and below the current market price. You can customize how many lines appear in either direction (defaulting to 10). This allows you to see a broader context of the surrounding "grid" at any given time.
3. Visual Distinction To help differentiate between major and minor levels, the script applies two different visual styles:
- Primary Levels: Every 100 points, the script draws a solid line using a primary color. These represent the "major" benchmarks.
- Secondary Levels: The intervals of 50 points (that are not multiples of 100) are drawn as dotted lines in a secondary color. These represent the "minor" benchmarks.
4. Real-Time Updates & Efficiency The script is designed to be "lightweight." It does not redraw every single calculation instantly with every micro-movement of the market; instead, it updates at set intervals. This ensures that your platform remains smooth and responsive while still providing up-to-date visual information as the price moves.
5. Automatic Cleanup The indicator includes a "cleanup" mechanism. When you remove the tool from your chart, it automatically deletes all the lines it created, ensuring your workspace stays clean and free of leftover graphics.
Summary for the Trader
Think of this tool as a permanent, automated ruler for your chart. It ignores market "noise" and simply places a clear map of horizontal boundaries where prices have historically rounded off. It helps you identify where price might encounter resistance or support based on standard numerical increments.
//+------------------------------------------------------------------+
//| SweetSpots.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright Shimodax"
#property link "http://www.strategybuilderfx.com"
#property indicator_chart_window
extern int LinesAboveBelow= 10;
extern color LineColorMain= LightGray;
extern color LineColorSub= Gray;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
int deinit()
{
int obj_total= ObjectsTotal();
for (int i= obj_total; i>=0; i--) {
string name= ObjectName(i);
if (StringSubstr(name,0,11)=="[SweetSpot]")
ObjectDelete(name);
}
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
static datetime timelastupdate= 0;
static datetime lasttimeframe= 0;
// no need to update these buggers too often
if (CurTime()-timelastupdate < 600 && Period()==lasttimeframe)
return (0);
int i, ssp1, style, ssp;
double ds1;
color linecolor;
ssp1= Bid / Point;
ssp1= ssp1 - ssp1%50;
for (i= -LinesAboveBelow; i<LinesAboveBelow; i++) {
ssp= ssp1+(i*50);
if (ssp%100==0) {
style= STYLE_SOLID;
linecolor= LineColorMain;
}
else {
style= STYLE_DOT;
linecolor= LineColorSub;
}
ds1= ssp*Point;
SetLevel(DoubleToStr(ds1,Digits), ds1, linecolor, style, Time[10]);
}
return(0);
}
//+------------------------------------------------------------------+
//| Helper |
//+------------------------------------------------------------------+
void SetLevel(string text, double level, color col1, int linestyle, datetime startofday)
{
int digits= Digits;
string linename= "[SweetSpot] " + text + " Line",
pricelabel;
// create or move the horizontal line
if (ObjectFind(linename) != 0) {
ObjectCreate(linename, OBJ_HLINE, 0, 0, level);
ObjectSet(linename, OBJPROP_STYLE, linestyle);
ObjectSet(linename, OBJPROP_COLOR, col1);
}
else {
ObjectMove(linename, 0, Time[0], level);
}
}
Comments