Author: Alexey Volchanskiy 2016
PriceLines

This script is designed to enhance your trading chart by automatically visualizing price levels. It acts as a visual aid, helping traders quickly identify significant price points and currency fluctuations at a glance without having to manually draw dozens of lines.

Core Functionality

The primary purpose of the script is to populate your chart with horizontal lines across a specific price range. Instead of looking at a blank screen, you can see a structured "grid" of price levels that helps in recognizing market structure and historical price action.

Key Features and Logic:

  • Dynamic Price Range (Auto-Range): The script features an intelligent scaling system. If enabled, it looks at the current visible price on your chart and automatically expands the drawing area to encompass enough space for comfortable viewing. It calculates the highest and lowest prices currently shown and creates a buffer zone so that the lines cover the entire visible area dynamically.

  • Hierarchical Line System: The script doesn't just draw identical lines; it distinguishes between "Major" and "Minor" levels:

    • Primary Levels: Every time the price hits a specific secondary interval (defined by your settings), the script draws a thicker, more prominent line. This highlights the most significant psychological price barriers.
    • Secondary Levels: In between those major points, it draws thinner, dashed lines to represent smaller price increments.
  • Precision Adjustment: The logic includes built-in "smart rounding." It detects how many decimal places your specific currency pair uses (e.g., a 5-digit vs. a 3-digit broker) and adjusts its calculations automatically. This ensures that the lines are placed perfectly on valid price points rather than at awkward fractional numbers.

  • Clean Workspace Management: To ensure your chart stays organized, the script includes a management system. Every time it updates or is refreshed, it identifies and clears out any old lines it previously drew. This prevents "ghost lines" from cluttering your screen, ensuring that only the current, relevant price levels are visible.

Summary of User Experience

When you run this script, you get a clean, organized visual map of the market. It effectively transforms a raw price chart into a structured environment where major resistance and support zones are highlighted clearly, allowing you to focus on currency movements with much less manual effort.

Price Data Components
9 Views
0 Downloads
0 Favorites
PriceLines
ÿþ//+------------------------------------------------------------------+

//|                                             PriceLines.mq4 

//|                                             Alexey Volchanskiy 

//|                                             http://mql.gnomio.com 

//|  

//+------------------------------------------------------------------+

#property copyright "Alexey Volchanskiy 2016"

#property link      "http://mql.gnomio.com"

#property version "2.15"

#property description "The script Price Lines marks price levels on the chart"

#property description "It helps to recognize the currency fluctuation in one touch"



#property show_inputs

#property strict



extern bool     DeleteLines = false;

extern bool     AutoRange   = true;

extern double   BeginPrice  = 1.0;

extern double   EndPrice    = 1.7;

extern int      Step        = 25;

extern int      Step2       = 100;

extern string   LineName    = "PrLn";

extern color    LineColor1  = Yellow;

extern color    LineColor2  = Gold;

extern int      Width1      = 1;

extern int      Width2      = 2;



double step,begin,end;

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int OnStart()

  {

   begin=BeginPrice;

   end=EndPrice;

   CalculateRange();

   DeleteHLines();

   if(!DeleteLines)

      DrawHLines(begin,end);

   else

      DeleteHLines();

   return(0);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void DrawHLines(double pBegin,double pEnd)

  {

   int lnum=0;

   color clr;

   int width,BeginInt;

   while(pBegin<pEnd)

     {

      BeginInt=(int)MathRound(pBegin*MathPow(10,Digits()));

      if(BeginInt%Step2==0)

        {

         clr=LineColor2;

         width=Width2;

        }

      else

        {

         clr=LineColor1;

         width=Width1;

        }

      string name=LineName+IntegerToString(lnum);

      bool res=ObjectCreate(name,OBJ_HLINE,0,0,pBegin);

      ObjectSet(name,OBJPROP_COLOR,clr);

      ObjectSet(name,OBJPROP_STYLE,STYLE_DASH);

      ObjectSet(name,OBJPROP_WIDTH,width);

      pBegin+=step;

      lnum++;

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void DeleteHLines()

  {

   int nL=ObjectsTotal();

   string name;

   for(int n=nL-1; n>=0; n--) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! B>;L:> ?> C1K20=8N

     {

      name=ObjectName(n);

      if(ObjectType(name)!=OBJ_HLINE)

         continue;

      int nch= StringFind(name,LineName);

      if(nch == 0)

         ObjectDelete(name);

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void CalculateRange()

  {

   int k1=1;   // :>MDD8F85=B B>G=>AB8, 4;O 4-E7=0:>2KE & = 1, 4;O 5-B87=0:0 = 10

   int RoundBegin=_Digits-2;

   if(_Digits==5)

     {

      k1=10;

      RoundBegin-=1;

     }

   step=Step/MathPow(10,_Digits)*k1;

   Step2*=k1;

   if(!AutoRange) return;

   double min = WindowPriceMin();

   double max = WindowPriceMax();

   double range=(max-min)*3;

   max += range;

   min -= range;

   begin= StrToDouble(DoubleToStr(min,RoundBegin));

   end=max;

   return;

  }

//+------------------------------------------------------------------+

Comments