SDX-SweetSpots_v1
Download scriptThis tool is designed to simplify price action analysis by automatically identifying and visualizing specific "zones" on your trading chart. Instead of requiring you to manually plot levels, the script dynamically maps out a grid of horizontal reference lines based on the current market price.
How it Works
The logic operates by analyzing the current live price of the asset and calculating fixed mathematical intervals. It focuses on every 50-point movement to create a structured visual guide. Here is the breakdown of its behavior:
Dynamic Zone Mapping The script looks at the current market value and calculates the nearest "sweet spot" based on 50-unit increments. From that starting point, it projects a series of horizontal lines both above and below the current price. This allows you to see the surrounding price environment instantly as the market moves.
Visual Hierarchy To prevent the chart from becoming cluttered while still providing depth, the script uses two distinct visual styles:
- Primary Levels: Every 100 units, the script draws a solid line using a primary color. These represent major milestones in the price action.
- Secondary Levels: For the 50-unit intervals in between, the script draws dotted lines using a secondary, more subtle color. These act as "sub-zones" to help you gauge finer price movements.
Automated Maintenance The tool is built to be "set and forget." It automatically handles the creation, positioning, and updating of these lines as the market fluctuates. When you remove the tool or change timeframes, it is designed to clean up after itself by removing the temporary lines it created, ensuring your chart remains clean and professional.
Efficiency Design To ensure your trading platform runs smoothly, the script does not refresh every millisecond. It intelligently updates only when necessary (every 10 minutes or when the timeframe changes), providing a stable visual experience without putting unnecessary strain on your computer's resources.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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, 0, level);
}
}
Comments