Critical Points1

Download script
Author: emsjoflo
Critical Points1

The Critical Points script is designed to provide traders with a visual map of potential support and resistance levels on a trading chart. It automates the creation and positioning of several horizontal lines based on a combination of moving averages and Fibonacci-based calculations, helping to identify key price zones at a glance.

Core Logic and Functionality

1. Baseline Calculation (Moving Average) The script begins by identifying a central "anchor" point using a Simple Moving Average (SMA). This average represents the mean price of the asset over a specific period (set by the user). By using an SMA, the script ensures that the critical points are tied to the current trend of the market rather than just static historical prices.

2. Fibonacci-Based Zone Mapping Once the baseline (the Moving Average) is established, the script projects 16 distinct horizontal lines both above and below that baseline. These lines are calculated using a series of specific numerical offsets inspired by the Fibonacci sequence (e.g., 21, 34, 55, 89, 144, 233, 377, and 610).

  • Upper Zones: The script projects eight lines upward from the average to identify potential "ceiling" areas where price might face resistance.
  • Lower Zones: The script projects eight lines downward from the average to identify potential "floor" areas where price might find support.

3. Dynamic Visual Updates Rather than drawing static lines that remain fixed on the screen, the script is programmed to be dynamic. As new price data arrives and the Moving Average shifts, the script automatically detects these changes. It then updates the position of the existing horizontal lines in real-time. This ensures that the "Critical Points" always move in harmony with the current market movement.

4. Visual Distinction To make the data easy to read, each of the 16 lines is assigned a unique color and a specific dashed line style. This allows traders to quickly differentiate between the various layers of the Fibonacci zones, making it easier to identify which "level" the price is currently interacting with.

Summary for the User

In simple terms, this tool takes the average price of the market and draws a "grid" of support and resistance levels around it based on mathematical proportions. It does the heavy lifting of calculating these complex levels automatically and moves them along with the live price action so you can always see where the next significant turning points might occur.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
20 Views
0 Downloads
0 Favorites
Critical Points1
//+------------------------------------------------------------------+
//|                                              Critical Points.mq4 |
//|                                                         emsjoflo |
//|                                  automaticforex.invisionzone.com |
//+------------------------------------------------------------------+
#property copyright "emsjoflo"
#property link      "automaticforex.invisionzone.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int       SMAPeriod=157;
extern int       Fib1=21;
extern int       Fib2=34;
extern int       Fib3=55;
extern int       Fib4=89;
extern int       Fib5=144;
extern int       Fib6=233;
extern int       Fib7=377;
extern int       Fib8=610;
extern color     Color1=Khaki;
extern color     Color2=LightGreen;
extern color     Color3=LightSkyBlue;
extern color     Color4=Plum;
extern color     Color5=LightSalmon;
extern color     Color6=Tomato;
extern color     Color7=Magenta;
extern color     Color8=Aqua;


double Line1,Line_1,Line2,Line_2,Line3,Line_3,Line4,Line_4,Line5,Line_5,Line6,Line_6,Line7,Line_7,Line8,Line_8,MAVal,MAValOld;

//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
ObjectDelete("cp1");
ObjectDelete("cp2");
ObjectDelete("cp3");
ObjectDelete("cp4");
ObjectDelete("cp5");
ObjectDelete("cp_1");
ObjectDelete("cp_2");
ObjectDelete("cp_3");
ObjectDelete("cp_4");
ObjectDelete("cp_5");


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
      
   MAVal=iMA(NULL,0,SMAPeriod,0,MODE_SMA,0,1);
   Line1=MAVal+Fib1*Point;
   Line2=MAVal+Fib2*Point;
   Line3=MAVal+Fib3*Point;
   Line4=MAVal+Fib4*Point;
   Line5=MAVal+Fib5*Point;
   Line6=MAVal+Fib6*Point;
   Line7=MAVal+Fib7*Point;
   Line8=MAVal+Fib8*Point;
   Line_1=MAVal-Fib1*Point;
   Line_2=MAVal-Fib2*Point;
   Line_3=MAVal-Fib3*Point;
   Line_4=MAVal-Fib4*Point;
   Line_5=MAVal-Fib5*Point;   
   Line_6=MAVal-Fib6*Point;
   Line_7=MAVal-Fib7*Point;
   Line_8=MAVal-Fib8*Point;   

   if(ObjectFind("cp1") != 0)
      {
      ObjectCreate("cp1", OBJ_HLINE, 0, Time[20], Line1);
      ObjectSet("cp1", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp1", OBJPROP_COLOR, Color1);
      }
      else
      {
      ObjectMove("cp1", 0, Time[20], Line1);
      }
      
   if(ObjectFind("cp2") != 0)
      {
      ObjectCreate("cp2", OBJ_HLINE, 0, Time[20], Line2);
      ObjectSet("cp2", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp2", OBJPROP_COLOR, Color2);
      }
      else
      {
      ObjectMove("cp2", 0, Time[20], Line2);
      }
      
    if(ObjectFind("cp3") != 0)
      {
      ObjectCreate("cp3", OBJ_HLINE, 0, Time[20], Line3);
      ObjectSet("cp3", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp3", OBJPROP_COLOR, Color3);
      }
      else
      {
      ObjectMove("cp3", 0, Time[20], Line3);
      }
      
   if(ObjectFind("cp4") != 0)
      {
      ObjectCreate("cp4", OBJ_HLINE, 0, Time[20], Line4);
      ObjectSet("cp4", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp4", OBJPROP_COLOR, Color4);
      }
      else
      {
      ObjectMove("cp4", 0, Time[20], Line4);
      }
         
 
   if(ObjectFind("cp5") != 0)
      {
      ObjectCreate("cp5", OBJ_HLINE, 0, Time[20], Line5);
      ObjectSet("cp5", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp5", OBJPROP_COLOR, Color5);
      }
      else
      {
      ObjectMove("cp5", 0, Time[20], Line5);
      }

   if(ObjectFind("cp6") != 0)
      {
      ObjectCreate("cp6", OBJ_HLINE, 0, Time[20], Line6);
      ObjectSet("cp6", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp6", OBJPROP_COLOR, Color6);
      }
      else
      {
      ObjectMove("cp6", 0, Time[20], Line6);
      }
  
   if(ObjectFind("cp7") != 0)
      {
      ObjectCreate("cp7", OBJ_HLINE, 0, Time[20], Line7);
      ObjectSet("cp7", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp7", OBJPROP_COLOR, Color7);
      }
      else
      {
      ObjectMove("cp7", 0, Time[20], Line7);
      }

   if(ObjectFind("cp8") != 0)
      {
      ObjectCreate("cp8", OBJ_HLINE, 0, Time[20], Line8);
      ObjectSet("cp8", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp8", OBJPROP_COLOR, Color8);
      }
      else
      {
      ObjectMove("cp8", 0, Time[20], Line8);
      }
      
  if(ObjectFind("cp_1") != 0)
      {
      ObjectCreate("cp_1", OBJ_HLINE, 0, Time[20], Line_1);
      ObjectSet("cp_1", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_1", OBJPROP_COLOR, Color1);
      }
      else
      {
      ObjectMove("cp_1", 0, Time[20], Line_1);
      }
      
   if(ObjectFind("cp_2") != 0)
      {
      ObjectCreate("cp_2", OBJ_HLINE, 0, Time[20], Line_2);
      ObjectSet("cp_2", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_2", OBJPROP_COLOR, Color2);
      }
      else
      {
      ObjectMove("cp_2", 0, Time[20], Line_2);
      }
      
    if(ObjectFind("cp_3") != 0)
      {
      ObjectCreate("cp_3", OBJ_HLINE, 0, Time[20], Line_3);
      ObjectSet("cp_3", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_3", OBJPROP_COLOR, Color3);
      }
      else ObjectMove("cp_3", 0, Time[20], Line_3);
      
      
   if(ObjectFind("cp_4") != 0)
      {
      ObjectCreate("cp_4", OBJ_HLINE, 0, Time[20], Line_4);
      ObjectSet("cp_4", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_4", OBJPROP_COLOR, Color4);
      }
      else ObjectMove("cp_4", 0, Time[20], Line_4);
     
         
  
   if(ObjectFind("cp_5") != 0)
      {
      ObjectCreate("cp_5", OBJ_HLINE, 0, Time[20], Line_5);
      ObjectSet("cp_5", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_5", OBJPROP_COLOR, Color5);
      }
      else
      {
      ObjectMove("cp_5", 0, Time[20], Line_5);
      }
 
   if(ObjectFind("cp_6") != 0)
      {
      ObjectCreate("cp_6", OBJ_HLINE, 0, Time[20], Line_6);
      ObjectSet("cp_6", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_6", OBJPROP_COLOR, Color6);
      }
      else
      {
      ObjectMove("cp_6", 0, Time[20], Line_6);
      }
  
   if(ObjectFind("cp_7") != 0)
      {
      ObjectCreate("cp_7", OBJ_HLINE, 0, Time[20], Line_7);
      ObjectSet("cp_7", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_7", OBJPROP_COLOR, Color7);
      }
      else
      {
      ObjectMove("cp_7", 0, Time[20], Line_7);
      }

   if(ObjectFind("cp_8") != 0)
      {
      ObjectCreate("cp_8", OBJ_HLINE, 0, Time[20], Line_8);
      ObjectSet("cp_8", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("cp_8", OBJPROP_COLOR, Color8);
      }
      else
      {
      ObjectMove("cp_8", 0, Time[20], Line_8);
      }
      
//----
   return(0);
  }
  
//+------------------------------------------------------------------+

Comments