#property version "1.00"
#property strict
#property indicator_chart_window
input string strOBJ_string = "ShowTime_";
input int intOBJ_ShowWindow = 0;
input ENUM_BASE_CORNER intOBJ_ShowCorner = 1;
double Show_SPREAD=0;
string Show_String="";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
EventSetTimer(1);
DeleteTimeObject(strOBJ_string, StringLen(strOBJ_string));
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
EventKillTimer();
DeleteTimeObject(strOBJ_string, StringLen(strOBJ_string));
//----
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
int TF_Remaining_Total_Second = (int)iTime(NULL, 240, 0) + 60 * 240 - (int)TimeCurrent(); //
int TF_Remaining_Total_Minute = (int)MathFloor(TF_Remaining_Total_Second / 60); //
int TF_Remaining_Hour = (int)MathFloor(MathFloor(TF_Remaining_Total_Second / 60) /60); //
int TF_Remaining_Minute = (int)MathMod(TF_Remaining_Total_Minute,60); //
int TF_Remaining_Second = TF_Remaining_Total_Second - 60 * TF_Remaining_Total_Minute; //
string ShowHour=IntegerToString(TF_Remaining_Hour,0); //
string ShowMinute= IDNumberToString(TF_Remaining_Minute,2); //
string ShowSeconds=IDNumberToString(TF_Remaining_Second,2); //
//------------------------------------------------------------------------------------------------------------------------------------------
Show_String= ShowHour+":"+ShowMinute+":"+ShowSeconds;
DrawLabel(strOBJ_string+"Time1", Show_String, 0, 5, White, 14, "Arial", intOBJ_ShowCorner, intOBJ_ShowWindow, true);
//----------------------------------------------------------------------------------------------------------------------------------------------
double SPREAD=MarketInfo(NULL,MODE_SPREAD);
if(!(Show_SPREAD==SPREAD))
{
Show_SPREAD=SPREAD;
printf("---------------------------SPREAD:" + TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) + " ("+DoubleToStr(Show_SPREAD,2) + ")------------");
}
Show_String=(string)NormalizeDouble(MarketInfo(Symbol(), MODE_TICKVALUE), 2)+"| " +(string)Show_SPREAD;
DrawLabel(strOBJ_string+"TICKVALUE|SPREAD", Show_String, 0, 55, Yellow, 13, "Arial", intOBJ_ShowCorner, intOBJ_ShowWindow, true);
//----------------------------------------------------------------------------------------------------------------------------------------------
Show_String=DoubleToStr(MarketInfo(Symbol(), MODE_MARGINREQUIRED), 2);
DrawLabel(strOBJ_string+"MARGINREQUIRED", Show_String, 0, 80, Yellow, 12, "Arial", intOBJ_ShowCorner, intOBJ_ShowWindow, true);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
int TM_Second = 60-TimeSeconds(TimeCurrent());
DrawLabel(strOBJ_string+"Time5tf0", IDNumberToString(TM_Second,2), 0, 25, Yellow, 14,"Arial" ,intOBJ_ShowCorner, intOBJ_ShowWindow,true);
DrawLabel(strOBJ_string+"Time5tf1", DoubleToStr(MarketInfo(Symbol(), MODE_SWAPLONG), 2)+"L", 30, 28, Coral, 8,"Arial" ,intOBJ_ShowCorner, intOBJ_ShowWindow,true); //SWAPLONG
DrawLabel(strOBJ_string+"Time5tf2", DoubleToStr(MarketInfo(Symbol(), MODE_SWAPSHORT),2)+"S", 30, 42, Coral, 8,"Arial" ,intOBJ_ShowCorner, intOBJ_ShowWindow,true); //SWAPSHORT
if(!(IsConnected()))
{
DrawLabel(strOBJ_string+"Time5tf", "IsConnected", 5, 25, Yellow, 12,"Arial" ,intOBJ_ShowCorner, intOBJ_ShowWindow,true);
ObjectDelete(strOBJ_string+"Time5tf0");
ObjectDelete(strOBJ_string+"Time5tf1");
ObjectDelete(strOBJ_string+"Time5tf2");
}
}
//+------------------------------------------------------------------+
void DrawLabel(string obj_Name, string obj_Text, int obj_X, int obj_Y, color obj_Color, int obj_Size, string obj_Font, int obj_Coner, int obj_Window, bool obj_ShowBackup) {
//ObjectDelete(obj_Name);
int FindObjectRtn=ObjectFind(obj_Name);
if(FindObjectRtn<0)
{
ObjectCreate(obj_Name, OBJ_LABEL, obj_Window, 0, 0);
ObjectSetText(obj_Name, obj_Text, obj_Size, obj_Font, obj_Color);
ObjectSet(obj_Name, OBJPROP_CORNER, obj_Coner);
ObjectSet(obj_Name, OBJPROP_XDISTANCE, obj_X);
ObjectSet(obj_Name, OBJPROP_YDISTANCE, obj_Y);
ObjectSet(obj_Name, OBJPROP_BACK, obj_ShowBackup);
}
else
{
ObjectSetText(obj_Name, obj_Text, obj_Size, obj_Font, obj_Color);
ObjectSet(obj_Name, OBJPROP_CORNER, obj_Coner);
ObjectSet(obj_Name, OBJPROP_XDISTANCE, obj_X);
ObjectSet(obj_Name, OBJPROP_YDISTANCE, obj_Y);
ObjectSet(obj_Name, OBJPROP_BACK, obj_ShowBackup);
}
}
void DeleteTimeObject(string TipTxt, int TxtLen)
{
int ObjTotal=ObjectsTotal();
for(int i = ObjTotal; i>=0; i--){
string ObjName=ObjectName(i);
if(StringSubstr(ObjName,0,TxtLen) == TipTxt){
ObjectDelete(ObjName);
}
}
ObjTotal=0;
}
string IDNumberToString(int CalNumber, int SN)
{
string strNumber;
int StrLen;
StrLen=SN-StringLen(IntegerToString(CalNumber));
switch(StrLen)
{
case 1:
strNumber = "0"+IntegerToString(CalNumber);
break;
case 2:
strNumber = "00"+IntegerToString(CalNumber);
break;
case 3:
strNumber = "000"+IntegerToString(CalNumber);
break;
case 4:
strNumber = "0000"+IntegerToString(CalNumber);
break;
case 5:
strNumber = "00000"+IntegerToString(CalNumber);
break;
default:
strNumber = IntegerToString(CalNumber);
break;
}
return(strNumber);
}
复制代码