Author: Cubesteak
nPipLines

This tool is designed for traders who need a clear visual reference for price levels on their trading charts. Instead of manually drawing horizontal lines to mark different price zones, this script automates the process by creating a structured "ladder" of price levels based on the current market price.

How it Works

The logic follows a systematic approach to organize your chart:

1. Dynamic Level Detection The script first identifies the current market price (the opening price of the current bar). It then performs a series of internal calculations to determine a "base price." This base is calculated mathematically to ensure that the resulting lines are aligned correctly with the currency's specific decimal places, preventing them from appearing out of sync with the actual market ticks.

2. Symmetrical Distribution Once the base price is established, the script generates a set number of horizontal lines (defined by you in the settings). These lines are distributed symmetrically around the current price:

  • Half of the lines are projected above the current price.
  • The other half are projected below the current price.

3. Precise Spacing The distance between each line is governed by a "Pip Gap" setting. The script calculates this gap automatically so that the visual spacing remains consistent across the chart, regardless of how many lines you choose to display.

4. Visual Customization To ensure the tool fits your specific trading style, the logic allows for several visual adjustments:

  • Line Quantity: You can decide exactly how many levels to see at once.
  • Color & Style: You can customize the color (e.g., FireBrick), thickness, and style (Solid, Dashed, Dotted) to make the levels stand out.
  • Update Behavior: You can choose whether the lines should update constantly as the price moves or remain fixed until a specific condition is met.

Key Benefits for the User

  • Automated Organization: It eliminates the repetitive task of drawing individual lines, ensuring perfectly even spacing every time.
  • Clean Charting: By centering the lines around the current market price, it provides an immediate "neighborhood" view of where the price is currently trading relative to nearby zones.
  • Consistency: Because the script uses precise math to handle decimals, the lines will always align correctly with the platform's pricing system, providing a reliable visual anchor for your analysis.
3 Views
0 Downloads
0 Favorites
nPipLines
//+------------------------------------------------------------------+
//|                                                    nPipLines.mq4 |
//|                                                        Cubesteak |
//|                                                www.cubesteak.net |
//+------------------------------------------------------------------+
#property copyright "Cubesteak"
#property link      "www.cubesteak.net"

#property indicator_chart_window
//---- input parameters
extern int       nLines=10;
extern int       nPipGap=25;
extern color     LineColor=FireBrick;
extern int       LineSize = 0; // Integer value to set/get object line width. Can be from 1 to 5. 
extern int       LineStyle = STYLE_SOLID ; // STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style. 
extern bool      ContinuousUpdate = false;

int DidIt = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

for (int x = nLines;x>=0;x--)
{
   DeleteLine(x);
}
DidIt = 0;
DrawLines();

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
for (int x = nLines;x>=0;x--)
{
   DeleteLine(x);
}

   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   if (ContinuousUpdate) DrawLines();
   else if (DidIt == 0 ) { DrawLines(); DidIt = 1;}
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

void MakeLine(double ThisPrice, int Unique)
{
   string ThisLine = StringConcatenate("nPipLine",Unique);
   bool foo = ObjectCreate(ThisLine, OBJ_HLINE, 0,0,0);
   ObjectSet(ThisLine,OBJPROP_PRICE1,ThisPrice);
   ObjectSet(ThisLine,OBJPROP_COLOR,LineColor);
   ObjectSet(ThisLine,OBJPROP_WIDTH,LineSize);
   ObjectSet(ThisLine,OBJPROP_STYLE,LineStyle);
}

void DeleteLine(int Unique)
{
   string ThisLine = StringConcatenate("nPipLine",Unique);
   ObjectDelete(ThisLine);
}


void DrawLines()
{
   double CurPrice = Open[0];
   //Print("curprice",CurPrice);

   int Ord = CurPrice;
   //Print("ord",Ord);

   double AftDec = CurPrice - Ord;

   //Print ("aftdec:",AftDec);

   int PlacesToMove = Digits - 2;

   //Print ("places to move:",PlacesToMove);

   int MultValue = MathPow(10,PlacesToMove);

   //Print ("MultValue:",MultValue);

   double PartValue = AftDec * MultValue;

   //Print ("PartValue:",PartValue);
 
   int PlaceValue = MathRound(PartValue);
 
   //Print ("PlaceValue:",PlaceValue);

   int StartValue = AftDec * MultValue;

   //Print ("StartValue:",StartValue);

   double NewAftDec = StartValue / ((MultValue*0.1)/(0.1));

   //Print ("NewAftDec:",NewAftDec);

   if (PlaceValue > StartValue) double StartPrice = Ord + NewAftDec + (5/(MathPow(10,PlacesToMove+1)));
   else StartPrice = Ord + NewAftDec;

   //Print("StartPrice:",StartPrice);

   double LinePrice = NormalizeDouble(StartPrice,Digits);

   //Print("LinePrice:",LinePrice);

   double dPipGap = (nPipGap * Point) - (0.1*Point) ;

   //Print("dPipGap:",dPipGap);

   int half = nLines / 2;

   //Print("half:",half);


   for (int x = 0;x<=half;x++)
   {
      MakeLine(LinePrice, x);
      LinePrice += dPipGap;
   }

   LinePrice = NormalizeDouble(StartPrice,Digits);

   for (x = nLines;x>half;x--)
   {
      MakeLine(LinePrice, x);
      LinePrice -= dPipGap;
   }

}

Comments