Author: Copyright Shimodax
SweetSpots

This script functions as a visual navigation tool designed to highlight significant price levels on your trading chart. Rather than cluttering your screen with standard grid lines, it identifies and draws horizontal markers at specific mathematical intervals, which the developer refers to as "Sweet Spots."

Core Functionality

The primary goal of this tool is to provide a clear visual map of price action by automatically plotting horizontal lines above and below the current market price. It organizes these lines into a hierarchy based on their distance and significance:

  • Primary Levels: The script identifies major milestones (based on a 100-pip interval). These are treated as significant structural points on the chart.
  • Sub-Levels: Between the major milestones, the script can be configured to display secondary markers. These provide a more granular view of the price movement without overwhelming the workspace.
  • Dynamic Thickness: To help you distinguish between different types of "Sweet Spots" at a glance, the script automatically varies the thickness of the lines. Major historical or structural zones are drawn with bolder weights, while smaller intervals appear as thinner markers.

How it Works for the User

The logic follows a systematic approach to keep your chart clean and organized:

  1. Automatic Calculation: The script takes the current market price and calculates the nearest "Sweet Spot" based on your chosen settings. It then projects lines both upwards and downwards from that point.
  2. Visual Hierarchy: It uses different line styles (such as solid vs. dotted) and colors to differentiate between major levels and minor sub-levels. This allows you to immediately see where the "big" levels are compared to the smaller increments.
  3. Efficiency: The tool is designed to refresh periodically rather than constantly, ensuring that it provides a stable visual layout without impacting the smoothness of your chart's performance.
  4. Clean Workspace Management: Every time the price moves significantly or the script updates, it clears out old markers and redraws the new ones. This ensures that your chart only displays relevant information based on where the market is currently trading.

In short, this tool acts like a high-precision ruler for your charts, highlighting specific price zones to help you better visualize market structure and potential areas of interest.

10 Views
0 Downloads
0 Favorites
SweetSpots
//+------------------------------------------------------------------+
//|                                                   SweetSpots.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright Shimodax"
#property link      "http://www.strategybuilderfx.com"

#property indicator_chart_window

/* Introduction:

   This indicator shows lines at sweet spots (50 and 100 
   pips levels). It is recommended to turn off the grid.
   
   Enjoy!

   Markus
*/

extern int NumLinesAboveBelow= 100;
extern int SweetSpotMainLevels= 100;
extern color LineColorMain= Gold;
extern int LineStyleMain= STYLE_SOLID;
extern bool ShowSubLevels= true;
extern int sublevels= 250;
extern color LineColorSub= Gold;
extern int LineStyleSub= STYLE_DOT;



//+------------------------------------------------------------------+
//| 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);
   
   deinit();  // delete all previous lines
      
   int i, ssp1, style, ssp, thickness; //sublevels= 50;
   double ds1;
   color linecolor;
   
   if (!ShowSubLevels)
      sublevels*= 2;
   
   ssp1= Bid / Point;
   ssp1= ssp1 - ssp1%sublevels;

   for (i= -NumLinesAboveBelow; i<NumLinesAboveBelow; i++) {
   
      ssp= ssp1+(i*sublevels); 
      
      if (ssp%SweetSpotMainLevels==0) {
         style= LineStyleMain;
         linecolor= LineColorMain;
      }
      else {
         style= LineStyleSub;
         linecolor= LineColorSub;
      }
      
      thickness= 1;
      
      if (ssp%(SweetSpotMainLevels*10)==0) {
         thickness= 2;      
      }

      if (ssp%(SweetSpotMainLevels*100)==0) {
         thickness= 3;      
      }
      
      ds1= ssp*Point;
      SetLevel(DoubleToStr(ds1,Digits), ds1,  linecolor, style, thickness, Time[10]);
   }

   return(0);
}


//+------------------------------------------------------------------+
//| Helper                                                           |
//+------------------------------------------------------------------+
void SetLevel(string text, double level, color col1, int linestyle, int thickness, 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);
      ObjectSet(linename, OBJPROP_WIDTH, thickness);
      
      ObjectSet(linename, OBJPROP_BACK, True);
   }
   else {
      ObjectMove(linename, 0, Time[0], level);
   }
}
      

Comments