This tool is designed to provide traders with a real-time visual dashboard that monitors three critical market cost factors simultaneously: the Spread, and the Swap rates for both buying and selling positions. Instead of requiring you to manually dig through complex market depth menus, this script pulls this data automatically and displays it clearly on your trading screen.
How the Logic Works
1. Real-Time Data Retrieval The script constantly communicates with the market server to fetch three specific pieces of information for the currency pair or asset you are currently viewing:
- Market Spread: The difference between the current buy and sell prices (the transaction cost).
- Long Swap (Buy Swap): The interest rate paid or received when holding a "buy" position overnight.
- Short Swap (Sell Swap): The interest rate paid or received when holding a "sell" position overnight.
2. Dynamic Calculation and Formatting Once the script retrieves these numbers, it performs two main actions:
- Normalization: It rounds the swap rates to two decimal places. This ensures the data is presented in a clean, readable format rather than showing long strings of unnecessary digits.
- Label Assignment: It organizes these figures into specific categories so you can distinguish between the costs of going "Long" versus "Short" at a glance.
3. Visual Interface Generation Rather than just outputting numbers in a text log, the script creates a dedicated visual display area. It generates a series of labels and automatically places them on your chart using specific coordinates:
- Spread Monitor: Displays the current market spread in gold text.
- Buy Swap Monitor: Displays the cost for long positions in blue text.
- Sell Swap Monitor: Displays the cost for short positions in red text.
By grouping these metrics into a single "Monitor" window, the script allows you to keep an eye on your holding costs and transaction spreads instantly as market conditions fluctuate.
//+------------------------------------------------------------------+
//| spread swap.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
//----
double swaplong,swapshort;
int spread;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("spread/swap monitor ("+Symbol()+")");
//----
return(0);}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
spread=MarketInfo(Symbol(),13);
swaplong=NormalizeDouble(MarketInfo(Symbol(),18),2);
swapshort=NormalizeDouble(MarketInfo(Symbol(),19),2);
//----
ObjectCreate("spread/swap monitor1", OBJ_LABEL, WindowFind("spread/swap monitor ("+Symbol()+")"), 0, 0);
ObjectSetText("spread/swap monitor1","Current Spread :", 9, "Arial Black", Gold);
ObjectSet("spread/swap monitor", OBJPROP_CORNER, 0);
ObjectSet("spread/swap monitor1", OBJPROP_XDISTANCE, 200);
ObjectSet("spread/swap monitor1", OBJPROP_YDISTANCE, 2);
//----
ObjectCreate("spread/swap monitor2", OBJ_LABEL, WindowFind("spread/swap monitor ("+Symbol()+")"), 0, 0);
ObjectSetText("spread/swap monitor2",DoubleToStr(spread ,0),9, "Arial Black", Gold);
ObjectSet("spread/swap monitor2", OBJPROP_CORNER, 0);
ObjectSet("spread/swap monitor2", OBJPROP_XDISTANCE, 320);
ObjectSet("spread/swap monitor2", OBJPROP_YDISTANCE, 2);
//----
ObjectCreate("spread/swap monitor3", OBJ_LABEL, WindowFind("spread/swap monitor ("+Symbol()+")"), 0, 0);
ObjectSetText("spread/swap monitor3","Buy Swap :", 9, "Arial Black", Blue);
ObjectSet("spread/swap monitor3", OBJPROP_CORNER, 0);
ObjectSet("spread/swap monitor3", OBJPROP_XDISTANCE, 470);
ObjectSet("spread/swap monitor3", OBJPROP_YDISTANCE, 2);
//----
ObjectCreate("spread/swap monitor4", OBJ_LABEL, WindowFind("spread/swap monitor ("+Symbol()+")"), 0, 0);
ObjectSetText("spread/swap monitor4",DoubleToStr( swaplong ,2),9, "Arial Black", Blue);
ObjectSet("spread/swap monitor4", OBJPROP_CORNER, 0);
ObjectSet("spread/swap monitor4", OBJPROP_XDISTANCE, 550);
ObjectSet("spread/swap monitor4", OBJPROP_YDISTANCE, 2);
//----
ObjectCreate("spread/swap monitor5", OBJ_LABEL, WindowFind("spread/swap monitor ("+Symbol()+")"), 0, 0);
ObjectSetText("spread/swap monitor5","Sell Swap :", 9, "Arial Black", Red);
ObjectSet("spread/swap monitor5", OBJPROP_CORNER, 0);
ObjectSet("spread/swap monitor5", OBJPROP_XDISTANCE, 660);
ObjectSet("spread/swap monitor5", OBJPROP_YDISTANCE, 2);
//----
ObjectCreate("spread/swap monitor6", OBJ_LABEL, WindowFind("spread/swap monitor ("+Symbol()+")"), 0, 0);
ObjectSetText("spread/swap monitor6",DoubleToStr( swapshort ,2),9, "Arial Black", Red);
ObjectSet("spread/swap monitor6", OBJPROP_CORNER, 0);
ObjectSet("spread/swap monitor6", OBJPROP_XDISTANCE, 740);
ObjectSet("spread/swap monitor6", OBJPROP_YDISTANCE, 2);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments