//+------------------------------------------------------------------+
//| SpreadMonitor.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql4.com |
//+------------------------------------------------------------------+
#property indicator_chart_window
input int XAxis = 25;
input int YAxis = 25;
input int FontSize = 10;
input int LineSpace = 7;
double dLastSpread = 0.0;
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
for (int i=0;i<14;i++)
ObjectDelete(StringConcatenate("SpreadMonitor_",i));
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
double dCurrentSpread = Ask-Bid;
SetLabel("SpreadMonitor_0","卖价:",XAxis,YAxis,"Arial",FontSize,Tomato);
SetLabel("SpreadMonitor_1",DoubleToString(Ask,Digits),XAxis+FontSize*7,YAxis,"Arial",FontSize,Tomato);
SetLabel("SpreadMonitor_2","买价:",XAxis,YAxis+LineSpace+FontSize,"Arial",FontSize,Aqua);
SetLabel("SpreadMonitor_3",DoubleToString(Bid,Digits),XAxis+FontSize*7,YAxis+LineSpace+FontSize,"Arial",FontSize,Aqua);
SetLabel("SpreadMonitor_4","点差: ",XAxis,YAxis+2*(LineSpace+FontSize),"Arial",FontSize,Red);
SetLabel("SpreadMonitor_5",DoubleToString(dCurrentSpread,Digits),XAxis+FontSize*7,YAxis+2*(LineSpace+FontSize),"Arial",FontSize,Red);
SetLabel("SpreadMonitor_6","交易商时间: ",XAxis,YAxis+3*(LineSpace+FontSize),"Arial",FontSize-2,White);
SetLabel("SpreadMonitor_7",TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),XAxis+FontSize*7,YAxis+3*(LineSpace+FontSize),"Arial",FontSize-2,White);
//--- return value of prev_calculated for next call
dLastSpread = dCurrentSpread;
return(rates_total);
}
void SetLabel(string nm,string tx,int xd,int yd,string fn,int fs,color ct)
{
if(ObjectFind(nm)<0)
ObjectCreate(nm,OBJ_LABEL,0,0,0); //--- create the Label object
ObjectSet(nm,OBJPROP_STYLE,STYLE_SOLID);
ObjectSet(nm,OBJPROP_XDISTANCE,xd);
ObjectSet(nm,OBJPROP_YDISTANCE,yd);
ObjectSet(nm,OBJPROP_COLOR,ct);
ObjectSetText(nm,tx,fs,fn,ct);
}
|