spread_lines

Download script
Author: Copyright 2015, MetaQuotes Software Corp.
spread_lines

This tool is designed to provide a clearer, more visual representation of the "Spread"—the difference between the buying price (Ask) and the selling price (Bid) in the financial markets. By drawing these prices directly onto your trading chart, it helps you see exactly where the market stands at any given moment.

How it Works

The script automatically identifies the current Ask and Bid prices provided by your broker and translates them into two distinct horizontal lines on your screen.

  • The Ask Line: This represents the price at which you can buy a currency or asset. You can customize its color (defaulting to a sea green) to make it easily distinguishable.
  • The Bid Line: This represents the price at which you can sell. It is typically displayed in a contrasting color (defaulting to red).

Key Features & Customization

The logic includes several options to ensure the visual data fits your specific trading style:

  • Visual Styling: You have full control over the appearance of these lines, including their thickness and the type of line style (such as solid, dashed, or dotted).
  • Spread Adjustment (SA): This is a unique feature that allows you to manually "offset" the price. If you find that your broker's displayed spread differs from what you expect, you can add or subtract a specific value to the Ask line to align it with your needs.
  • Chart Visibility: The script includes settings to manage how the tool interacts with your chart layout. You can choose whether the lines appear in the foreground and toggle the visibility of the standard "Ask Line" provided by the platform to keep your workspace clean and focused on this specific tool's data.
  • Automatic Cleanup: To ensure your charts stay tidy, the script is designed to automatically remove these lines as soon as you close the indicator, leaving no "ghost" lines behind on your workspace.

Summary for Traders

Essentially, this script removes the guesswork from pricing. Instead of constantly checking the price feed in a separate window, you can see the live buying and selling boundaries directly on your main chart, helping you make faster, more informed decisions based on the real-time spread.

12 Views
0 Downloads
0 Favorites
spread_lines
//+--------------------------------------------------------------------+
//|                         Copyright 2015, MetaQuotes Software Corp.  |
//|                                             https://www.mql5.com   |
//| Indicator : Spread Lines                                           |                                                                  |
//| Author: file45 - https://www.mql5.com/en/users/file45/publications |
//+--------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

input color Ask_Line = MediumSeaGreen; // Ask Line Color
input color Bid_Line = Red; // Bid Line Color
input int Line_Width = 1; // Line Width : 1, 2, 3, 4, 5, 6, 7, .....
input string a = " *  *  *  *  * "; // Line Style effective only if Line Width = 1
input ENUM_LINE_STYLE Line_Style = 1; // Line Style
input string b = " *  *  *  *  * "; // N.O.T.E. -> For true chart spread only, SA must = 0
input string c = " *  *  *  *  * "; // Other broker spread  - chart spread = SA +/- value 
input int SA = 0; // SA - Spread  Adjuster
input bool CF = true; // Chart on Forground
input bool SAL = true; // Show Ask Line

int OnInit() 
{
   
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{ 
   ChartForegroundSet(CF,0);
   ChartAskSet(SAL,0);
  
   ObjectCreate(0, "ALine", OBJ_HLINE , 0,Time[0], 0);
   ObjectSet("ALine", OBJPROP_STYLE, Line_Style);
   ObjectSet("ALine", OBJPROP_COLOR, Ask_Line);
   ObjectSet("ALine", OBJPROP_WIDTH, Line_Width);
   ObjectSet("ALine", OBJPROP_PRICE1, Ask + SA*Point);
    
   ObjectCreate(0, "BLine", OBJ_HLINE , 0,Time[0], 0);
   ObjectSet("BLine", OBJPROP_STYLE, Line_Style);
   ObjectSet("BLine", OBJPROP_COLOR, Bid_Line);
   ObjectSet("BLine", OBJPROP_WIDTH, Line_Width);
   ObjectSet("BLine", OBJPROP_PRICE1, Bid);
  
   return(rates_total);
}

int deinit()
{
   ObjectDelete("ALine");
   ObjectDelete("BLine");
   
   return(0);
}  

bool ChartForegroundSet(const bool value,const long chart_ID=0)
{
//--- reset the error value
   ResetLastError();
//--- set property value
   if(!ChartSetInteger(chart_ID,CHART_FOREGROUND,0,value))
   {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
      return(false);
   }
//--- successful execution
   return(true);
  }
  
 bool ChartAskSet(const bool value,const long chart_ID=0)
{
//--- reset the error value
   ResetLastError();
//--- set property value
   if(!ChartSetInteger(chart_ID,CHART_SHOW_ASK_LINE,0,value))
   {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
      return(false);
   }
//--- successful execution
   return(true);
} 

Comments