Spread_Hi_Lo_v1a

Download script
Author: Quantum Investment Services, LLC
Spread_Hi_Lo_v1a

This script is designed as an on-screen dashboard for MetaTrader 4, providing traders with a comprehensive snapshot of real-time market data and technical statistics. Rather than using complex lines or arrows on the chart, it creates a centralized information panel that updates dynamically to help you monitor various market conditions at a glance.

Here is a breakdown of how the logic works:

Market Connectivity & Spread Monitoring

The script contains a specific recognition system for common currency pairs. It identifies which asset you are trading and automatically assigns a "standard" spread value for that pair.

  • Real-time Spread: It calculates the current difference between the Buy (Ask) and Sell (Bid) prices.
  • Visual Alerts: The color of the spread display changes based on the market conditions: it highlights differently if the spread is within the normal range, higher than expected, or neutral, allowing you to quickly identify periods of high volatility or low liquidity.

Price & Trend Analysis

The dashboard provides immediate feedback on price movement and current trends:

  • Dynamic Price Label: It displays the current market price and changes its color based on a trend analysis of a 5-minute timeframe. This tells you at a glance if the short-term momentum is bullish (Blue) or bearish (Brown).
  • Daily High/Low: The script scans the previous day's data to display the exact Highest and Lowest prices achieved, as well as the total range (the distance between the two).

Advanced Statistical Data

Beyond simple price points, the script calculates deeper averages to help with "big picture" trading:

  • Daily Average Range: The tool calculates the movement range of the last day and compares it against the average ranges of the previous 5, 10, and 20 days. It then provides a weighted average (Av) to help you understand if today's market volatility is normal or extraordinary.
  • Stop Level: It pulls technical data from the broker to display the "Stop Level," which informs you of the minimum distance required for placing stop orders.

Time & Navigation Aids

To assist with trade execution and time management, the script includes:

  • Candle Countdown: A live timer that tells you exactly how many minutes and seconds remain before the current candle closes on your chart.
  • Server Time: It displays the current server time clearly at the top of the dashboard.
  • Timeframe Identifier: It automatically detects and labels which timeframe (e.g., M15, H1, D1) you are currently viewing to ensure you don't lose track of your analysis perspective.

Visual Customization

The logic is built to be visually organized on the chart. It uses a "Write" procedure to place text labels, lines, and symbols in specific coordinates. It handles font styling, colors (such as Gold for signals or Silver for neutral data), and positions automatically, ensuring that all information remains neatly grouped in one area of your screen without cluttering the price action.

Price Data Components
Series array that contains open time of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Moving average indicator
7 Views
0 Downloads
0 Favorites
Spread_Hi_Lo_v1a
//+------------------------------------------------------------------+
//|                                                 Spread_Hi_Lo.mq4 |
//|                                  Quantum Investment Services, LLC|
//|                                 http://www.quantum-investing.com |
//+------------------------------------------------------------------+
#property copyright "Quantum Investment Services, LLC"
#property link      "support@quantum-investing.com"

#property indicator_chart_window
#property  indicator_buffers 0

#include <stdlib.mqh>

//--------------------------------------------------------------------
// Quantum Investment Services, LLC
extern string  CreatedBy         = "Quantum Investment Services, LLC"; 
//--------------------------------------------------------------------
 int MAFast_Period = 1; 
 int MAFast_Method = 0; 
 int MAFast_Apply_To = 0;
 int MAFast_Shift = 0;

 int MASlow_Period = 5; 
 int MASlow_Method = 0;
 int MASlow_Apply_To = 0;
 int MASlow_Shift = 0;

 bool    Show_Price                 = true;
 bool    Show_Buy_Sell              = false;

 int     Sebelah              = 1;  //0=Kiri_Atas, 1=Kanan_Atas
 bool    Right_Top                  = true;
extern int     Shift_Y              = -20; 
extern int     Shift_X              = 0; //default = 8
extern int     window               = 0;

 bool    Show_Background      = true;
 bool    Background_Kecil           = false;
 color   Background_S         = C'25,25,25';          //C'20,20,20';  LightSteelBlue
 bool    Show_Garis_Signals         = false;



// Untuk menentukan Warna Harga sesuai arah Trend
extern string Colors_Price  ="Colors for Price";
extern color Price_color_Up = DodgerBlue;
extern color Price_color_Dn = Brown;
extern color Price_color_Dn1= Gold;
extern color Price_color_Nt = Silver;
extern color Price_color_Hi = Silver;
extern color Price_color_Lo = Silver;

extern string Colors_Data   ="Colors for Data";
extern color Highest_Color  = DodgerBlue;
extern color Lowest_Color   = Brown;
extern color Warna_D1       = Gainsboro; 
extern color Warna_Av       = Gainsboro;
extern color SymbolColor    = Gainsboro;
extern color LineColor      = DimGray;

extern bool Show_Symbol     = true;

//--------------------------------------------------------------------
int Side = 1;
//extern int MP_Y = 0; 
//extern int MP_X = 0;
//--------------------------------------------------------------------

//--------------------------------------------------------------------
//===================================================================+
double vA, vB, vC, vX, vY, TFs,High_Lama, Low_Lama;
double TimeFrame, x, x1, y, z, a,  space,space1, baris, fontsize, cTF, cMC, cBB, cIC, cLS, cNR;
string text, fontname, Teks_Menit, Teks_Detik;

string UpSymbol="‡",  DnSymbol="ˆ", NtSymbol="n", SignalSymbol,MTF, Peringatan_RSI="", Peringatan_DM="";   //"ñ"

color SignalColor;

string Label_Teks="", Huruf="", Huruf1="", Huruf2="",Huruf3="", Teks="", Pesan="", nomor="";
double Nilai, y1, y2, y3, y4,d_A, d_B, TF, Range, bbP, bbMid, bbM, nilaiWarnaCandle,mylot,lot,balance1,margin,keuangan,Candle;
color  WarnaHarga, WarnaTrend, WarnaCandle;
int    Ukuran, Ukuran1, Ukuran2, Ukuran3,Ukuran4, n, Kolom;


// --- variabel Daili_Av --------------------------------------------
int    R1, R5, R10, R20, RAvg, i;
string Teks_ReRata = "", Teks_Rerata_Kemarin ="", Nomor="";


//+------------------------------------------------------------------+
//     expert initialization function                                |       
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);                                                               // end of init function
  }
//+------------------------------------------------------------------+
//     expert deinitialization function                              |       
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll(0,OBJ_LABEL);
   Print("shutdown error - ",ErrorDescription(GetLastError()));            // system is detached from platform
//----
//----
     for(int i = ObjectsTotal() - 1; i >= 0; i--)
     {
       string label = ObjectName(i);
       if(StringSubstr(label, 0, 4) != "MP14")
           continue;
       ObjectDelete(label);   
     }   //----
   return(0);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //double volume10  =iVolume(NULL,PERIOD_M1,0);
   //if(volume10>1) return;
   int myspread;
   string mysymbol="", ms=""; 

   if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD." || Symbol() == "AUDCAD") { mysymbol = "AUDCAD"; myspread=6;} else
   if (Symbol() == "AUDCHFm" || Symbol() == "AUDCHF." || Symbol() == "AUDCHF") { mysymbol = "AUDCHF"; myspread=6;} else
   if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY." || Symbol() == "AUDJPY") { mysymbol = "AUDJPY"; myspread=5;} else
   if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD." || Symbol() == "AUDNZD") { mysymbol = "AUDNZD"; myspread=6;} else
   if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD." || Symbol() == "AUDUSD") { mysymbol = "AUDUSD"; myspread=5;} else
   if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY." || Symbol() == "CHFJPY") { mysymbol = "CHFJPY"; myspread=5;} else
   if (Symbol() == "EURAUDm" || Symbol() == "EURAUD." || Symbol() == "EURAUD") { mysymbol = "EURAUD"; myspread=6;} else
   if (Symbol() == "EURCADm" || Symbol() == "EURCAD." || Symbol() == "EURCAD") { mysymbol = "EURCAD"; myspread=7;} else
   if (Symbol() == "EURCHFm" || Symbol() == "EURCHF." || Symbol() == "EURCHF") { mysymbol = "EURCHF"; myspread=6;} else
   if (Symbol() == "EURGBPm" || Symbol() == "EURGBP." || Symbol() == "EURGBP") { mysymbol = "EURGBP"; myspread=6;} else
   if (Symbol() == "EURJPYm" || Symbol() == "EURJPY." || Symbol() == "EURJPY") { mysymbol = "EURJPY"; myspread=6;} else
   if (Symbol() == "EURUSDm" || Symbol() == "EURUSD." || Symbol() == "EURUSD") { mysymbol = "EURUSD"; myspread=5;} else
   if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF." || Symbol() == "GBPCHF") { mysymbol = "GBPCHF"; myspread=11;} else
   if (Symbol() == "GBPCADm" || Symbol() == "GBPCAD." || Symbol() == "GBPCAD") { mysymbol = "GBPCAD"; myspread=14;} else
   if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY." || Symbol() == "GBPJPY") { mysymbol = "GBPJPY"; myspread=11;} else
   if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD." || Symbol() == "GBPUSD") { mysymbol = "GBPUSD"; myspread=5;} else
   if (Symbol() == "NZDCADm" || Symbol() == "NZDCAD." || Symbol() == "NZDCAD") { mysymbol = "NZDCAD"; myspread=9;} else
   if (Symbol() == "NZDCHFm" || Symbol() == "NZDCHF." || Symbol() == "NZDCHF") { mysymbol = "NZDCHF"; myspread=9;} else
   if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY." || Symbol() == "NZDJPY") { mysymbol = "NZDJPY"; myspread=9;} else
   if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD." || Symbol() == "NZDUSD") { mysymbol = "NZDUSD"; myspread=7;} else
   if (Symbol() == "USDCHFm" || Symbol() == "USDCHF." || Symbol() == "USDCHF") { mysymbol = "USDCHF"; myspread=5;} else
   if (Symbol() == "USDJPYm" || Symbol() == "USDJPY." || Symbol() == "USDJPY") { mysymbol = "USDJPY"; myspread=5;} else
   if (Symbol() == "USDCADm" || Symbol() == "USDCAD." || Symbol() == "USDCAD") { mysymbol = "USDCAD"; myspread=6;} else
                              { mysymbol = Symbol(); }

  string HoursofServer; 

   HoursofServer   =TimeToStr(CurTime(),Digits);
  
   
   //ObjectDelete("SM");
   //SERVER( "SM", 110, 15,3);
   //ObjectSetText( "SM", "Server Time"  , 12, "Arial Narrow Bold", Silver );
   //ObjectDelete("SM2");
  SERVER2( "SM2", 15, 14,3);
   ObjectSetText( "SM2"," "+HoursofServer+"", 12, "Arial Bold", Highest_Color );//Red


   int    counted_bars=IndicatorCounted();
//----

    TF=Period();
    if (TF==PERIOD_M1) { MTF="M1"; }
    else if (TF==PERIOD_M5){ MTF="M5"; }
    else if (TF==PERIOD_M15){ MTF="M15"; }
    else if (TF==PERIOD_M30){ MTF="M30"; }
    else if (TF==PERIOD_H1){ MTF="H1"; }
    else if (TF==PERIOD_H4){ MTF="H4"; }
    else if (TF==PERIOD_D1){ MTF="D1"; }
    else if (TF==PERIOD_MN1){ MTF="MN1"; }
    else { MTF="-"; }

//-----------------------------------------------------------------------------------------------------------------------------  +
if(Show_Price==true)
{
   x=10; y=50; y1=10;
   double mydigit,mypoint,mp;
   if((Digits==5) || (Digits==3)) mydigit=Digits-1; else mydigit=Digits;
   if((Point==0.001) || (Point==0.00001)) {mypoint=Point*10; mp=0.1;} else {mypoint=Point; mp=1;}
   // Price
   //Menampilkan Harga
   Nilai=iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0); 
   Teks=DoubleToStr(Nilai,(mydigit));
   Huruf="Footlight MT Light"; Ukuran=19; Ukuran1=7;  //34
   // WarnaHarga=WarnaLampu pada trend TF 5 menit
   d_A = iMA(Symbol(),PERIOD_M5,MAFast_Period,MAFast_Shift,MAFast_Method,MAFast_Apply_To,0);
   d_B = iMA(Symbol(),PERIOD_M5,MASlow_Period,MASlow_Shift,MASlow_Method,MASlow_Apply_To,0);
   WarnaHarga=CheckWarna(d_B, d_A, Price_color_Up, Price_color_Dn);
   Write("MP01", Right_Top, Shift_X+x, Shift_Y+y+(y1*0)-18, Teks, Ukuran, Huruf, WarnaHarga);
   Write("MP0111", Right_Top, Shift_X+x, Shift_Y+y+(y1*0), "_______________", Ukuran1, Huruf, LineColor);

   Huruf="Tahoma Bold"; Ukuran=10; 
   //Menampilkan Highest Day
   d_A=iHigh(NULL,1440,0); 
   Teks=DoubleToStr(d_A, mydigit);

   Write("MP02", Right_Top,Shift_X+x, Shift_Y+y+(y1*1), Teks, Ukuran1, Huruf, Price_color_Hi);
   Write("MP0211", Right_Top,Shift_X+x+40, Shift_Y+y+(y1*1), "High : ", Ukuran1, Huruf, Price_color_Hi);
   
   //Menampilkan Lowest Day
   d_B=iLow(NULL,1440,0); 
   Teks=DoubleToStr(d_B, mydigit);

   Write("MP03", Right_Top, Shift_X+x, Shift_Y+y+(y1*2), Teks, Ukuran1, Huruf, Price_color_Lo);
   Write("MP0311", Right_Top, Shift_X+x+40, Shift_Y+y+(y1*2), "Low : ", Ukuran1, Huruf, Price_color_Lo);
      
   //--- Informasi Hi to Lo ---
   Teks=DoubleToStr((d_A - d_B)/mypoint,0);

   Write("MP06", Right_Top, Shift_X+x, Shift_Y+y+(y1*3), Teks, Ukuran1, Huruf, Price_color_Up);
   Write("MP0611", Right_Top, Shift_X+x+40, Shift_Y+y+(y1*3), "D1 : ", Ukuran1, Huruf, Price_color_Up);
   
   //--- Informasi Daily Av ---
   R1=0; R5=0; R10=0; R20=0; RAvg=0; i=0;
   R1 =  (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/mypoint;
   for(i=1;i<=5;i++)   
     R5  = R5  + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/mypoint;
   for(i=1;i<=10;i++)
     R10 = R10 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/mypoint;
   for(i=1;i<=20;i++)
     R20 = R20 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/mypoint;

   R5 = R5/5;
   R10 = R10/10;
   R20 = R20/20;
   RAvg  =  (R1+R5+R10+R20)/4;    
   
   Teks_ReRata = (DoubleToStr(RAvg,mydigit-4));
   Teks_Rerata_Kemarin = (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/mypoint;
   
   Write("MP07", Right_Top, Shift_X+x, Shift_Y+y+(y1*4), Teks_ReRata, Ukuran1, Huruf, Warna_Av);
   Write("MP0711", Right_Top, Shift_X+x+40, Shift_Y+y+(y1*4), "Av : ", Ukuran1, Huruf, Warna_Av);
   
   //Time for Next Candle
   d_B = (Time[4]-Time[5])-MathMod(CurTime(),Time[4]-Time[5]);
   d_A = d_B/60;
   d_B = (d_A-MathFloor(d_A))*60;
   d_A = MathFloor(d_A);
   Teks_Menit = DoubleToStr(d_A,0);
   Teks_Detik = DoubleToStr(d_B,0);
   Teks=Teks_Menit+":"+Teks_Detik;

   Write("MP08", Right_Top, Shift_X+x, Shift_Y+y+(y1*7), Teks, Ukuran1, Huruf, Price_color_Hi);
   Write("MP0811", Right_Top, Shift_X+x+40, Shift_Y+y+(y1*7), "Time : ", Ukuran1, Huruf, Price_color_Hi);
   
   // --- Spread
   d_A = (Ask - Bid)/mypoint;
   Teks = (DoubleToStr(d_A,mydigit-3));
   if (((Ask - Bid)/mypoint)<myspread)
      { SignalColor=Price_color_Up;}
   else 
   if (((Ask - Bid)/mypoint)>myspread)
      { SignalColor=Price_color_Dn1;}
   else 
      { SignalColor=Price_color_Nt;}

   Write("MP09", Right_Top, Shift_X+x, Shift_Y+y+(y1*5), Teks, Ukuran1, Huruf, SignalColor);
   Write("MP0911", Right_Top, Shift_X+x+40, Shift_Y+y+(y1*5), "Sprd : ", Ukuran1, Huruf, SignalColor);

   // --- StopLevel
   d_A = MarketInfo(Symbol(), MODE_STOPLEVEL)*mp;
   Teks = (DoubleToStr(d_A,0));
   Write("MP09a", Right_Top, Shift_X+x, Shift_Y+y+(y1*6), Teks, Ukuran1, Huruf, Price_color_Up);
   Write("MP0911a", Right_Top, Shift_X+x+40, Shift_Y+y+(y1*6), "S.Lvl : ", Ukuran1, Huruf, Price_color_Up);

if (Show_Symbol==true)
   {
   Write("MP0912", Right_Top, Shift_X+x, Shift_Y+y+(y1*7.5), "____________", Ukuran1, Huruf, LineColor);
   Write("MP09121", Right_Top, Shift_X+x, Shift_Y+y+(y1*9), "____________", Ukuran1, Huruf, LineColor);

   Write("MP0913", Right_Top, Shift_X+x+8, Shift_Y+y+(y1*8.45), mysymbol, 11, Huruf, SymbolColor);
   
   string MTF;
    double TF=Period();
    if (TF==PERIOD_M1) { MTF="M1"; }
    else if (TF==PERIOD_M5){ MTF="M5"; }
    else if (TF==PERIOD_M15){ MTF="M15"; }
    else if (TF==PERIOD_M30){ MTF="M30"; }
    else if (TF==PERIOD_H1){ MTF="H1"; }
    else if (TF==PERIOD_H4){ MTF="H4"; }
    else if (TF==PERIOD_D1){ MTF="D1"; }
    else if (TF==PERIOD_MN1){ MTF="MN1"; }
    else { MTF="-"; }

   Write("MP0914", Right_Top, Shift_X+x+8, Shift_Y+y+(y1*10), MTF, 9, Huruf, Price_color_Lo);
   }   
   
   Write("MP091444", Right_Top, x-5, y-49, "Bismillah == Alhamdulillah", 6, Huruf, Price_color_Lo);
}
//----
   return(0);  // end of start funtion
  }
//+------------------------------------------------------------------+
//     expert custom function                                        |       
//+------------------------------------------------------------------+    

// Write Procedure
void Write(string LBL, double side, int pos_x, int pos_y, string text, int fontsize, string fontname, color Tcolor=CLR_NONE, int angle=0)
     {
       ObjectCreate(LBL, OBJ_LABEL, window, 0, 0);
       ObjectSetText(LBL,text, fontsize, fontname, Tcolor);
       ObjectSet(LBL, OBJPROP_CORNER, Sebelah);
       ObjectSet(LBL, OBJPROP_XDISTANCE, pos_x);
       ObjectSet(LBL, OBJPROP_YDISTANCE, pos_y);
       ObjectSetText("signal",CharToStr(164),60,"Wingdings",Gold);
         if (LBL == "MP5221")
         {
            ObjectCreate(LBL, OBJ_LABEL, window, 0, 0);
            ObjectSetText(LBL,text, fontsize, fontname, Tcolor);
            ObjectSet(LBL, OBJPROP_CORNER, Sebelah);
                ObjectSet(LBL,OBJPROP_ANGLE,0);
            ObjectSet(LBL, OBJPROP_XDISTANCE, pos_x);
            ObjectSet(LBL, OBJPROP_YDISTANCE, pos_y);
            ObjectSetText("signal",CharToStr(164),60,"Wingdings",Gold);
         }
         if (LBL == "MP091444")
         {
            ObjectCreate(LBL, OBJ_LABEL, window, 0, 0);
            ObjectSetText(LBL,text, fontsize, fontname, Tcolor);
            ObjectSet(LBL, OBJPROP_CORNER, 3);
                ObjectSet(LBL,OBJPROP_ANGLE,0);
            ObjectSet(LBL, OBJPROP_XDISTANCE, pos_x);
            ObjectSet(LBL, OBJPROP_YDISTANCE, pos_y);
         }
     }
// Function CheckWarna  
color CheckWarna(double a, double b, color U, color D)
      {
        if (a>b) { return (U); } else { return (D); }
      } 
/*
int SERVER( string Text, int xOffset, int yOffset,int iCorner) 
{  ObjectCreate(Text,OBJ_LABEL         , 0, 0, 0 );
   ObjectSet   (Text,OBJPROP_CORNER    , iCorner);
   ObjectSet   (Text,OBJPROP_XDISTANCE , 5 );//400
   ObjectSet   (Text,OBJPROP_YDISTANCE , 10 );
   ObjectSet   (Text,OBJPROP_BACK      , True );
}
*/

int SERVER2( string Text, int xOffset, int yOffset,int iCorner) 
{  ObjectCreate(Text,OBJ_LABEL         , 0, 0, 0 );
   ObjectSet   (Text,OBJPROP_CORNER    , iCorner);
   ObjectSet   (Text,OBJPROP_XDISTANCE , 5 );//300
   ObjectSet   (Text,OBJPROP_YDISTANCE , 10 );
   ObjectSet   (Text,OBJPROP_BACK      , True );
}

Comments