SDX-SweetSpots_v2

Download script
Author: Copyright Shimodax
SDX-SweetSpots_v2

This tool is designed to provide traders with a visual roadmap of significant price levels on their trading charts. Instead of requiring you to manually identify key price zones, the script automatically calculates and plots a series of horizontal reference lines based on specific mathematical increments.

Core Functionality

The primary purpose of this script is to identify what it calls "Sweet Spots"—specific price points that may represent psychological or structural milestones in the market. It does this by taking the current live market price and projecting a grid of levels both above and below that price.

How it Works

  • Dynamic Grid Generation: The script looks at the current market price and rounds it to the nearest 50-point increment. From that base point, it creates a series of horizontal lines extending in both directions (up and down) based on a user-defined range.
  • Visual Hierarchy: To help you distinguish between different types of levels, the script uses two distinct visual styles:
    • Major Levels: Every 100th point is highlighted with a solid line and a primary color (default is Red). These represent significant milestones.
    • Minor Levels: The intermediate points (the 50-point marks) are displayed as dotted lines in a secondary color (default is Green). These provide more granular context for price movement.
  • Automatic Management: The tool is designed to be "clean." It automatically handles the creation and positioning of these lines on your chart. When you remove the indicator, it includes a cleanup process to ensure that all generated "SweetSpot" lines are removed from your chart, keeping your workspace organized.
  • Performance Optimization: To ensure your trading platform remains fast and responsive, the script does not refresh every single millisecond. It is programmed to update at specific intervals, only recalculating when necessary or when a significant amount of time has passed, which minimizes the impact on your computer's performance.

User Experience

For the trader, this means you don't have to guess where the next "round number" or significant level might be. The script populates your screen with a structured grid, allowing you to see at a glance how close the current price is to major resistance (solid lines) or minor support/resistance zones (dotted lines).

12 Views
0 Downloads
0 Favorites
SDX-SweetSpots_v2
//+------------------------------------------------------------------+
//|                                                   SweetSpots.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright Shimodax"
#property link      "http://www.strategybuilderfx.com"
//----
#property indicator_chart_window
//----
extern int LinesAboveBelow= 10;
extern color LineColorMain= Red;
extern color LineColorSub= Green;
//+------------------------------------------------------------------+
//| 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