238 lines
4.8 KiB
Plaintext
238 lines
4.8 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Indicator
|
|
// ---------------------------------------------
|
|
// Name: XCTime
|
|
// Description: Timing Indicator ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://saherelm.ir"
|
|
#property version "1.00"
|
|
#property description "SaherElm XCTime Indicator"
|
|
#property strict
|
|
|
|
//
|
|
// START Constants ...
|
|
//
|
|
|
|
//
|
|
#define ShortName "XCTime"
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
|
|
//
|
|
// END Constants ...
|
|
//
|
|
|
|
//
|
|
// START Inputs ...
|
|
//
|
|
|
|
//
|
|
input color clr = clrYellow; // Text Color
|
|
input ENUM_BASE_CORNER corner = CORNER_LEFT_LOWER; // Text Position
|
|
|
|
//
|
|
input group "Presentation";
|
|
input bool showTime = true; // Show Time
|
|
|
|
//
|
|
// END Inputs ...
|
|
//
|
|
|
|
//
|
|
// START Buffers ...
|
|
//
|
|
|
|
//
|
|
#property indicator_chart_window
|
|
|
|
//
|
|
#property indicator_buffers 0
|
|
#property indicator_plots 0
|
|
|
|
//
|
|
// END Buffers ...
|
|
//
|
|
|
|
//
|
|
// START Global Definitions: Variables, Properties and etc ...
|
|
//
|
|
|
|
//
|
|
// END Global Definitions: Variables, Properties and etc ...
|
|
//
|
|
|
|
//
|
|
// START Event Handlers ...
|
|
//
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
// Validate Inputs ...
|
|
if (showTime)
|
|
{
|
|
CreateIndicatorObject();
|
|
}
|
|
else
|
|
{
|
|
ObjectDelete(0, ShortName);
|
|
}
|
|
|
|
//
|
|
// Set Indicator ShortName ...
|
|
SetIndicatorName();
|
|
|
|
//
|
|
// Init Succeed ...
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//
|
|
// DeInitialization ...
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//
|
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
// REASON_REMOVE 1 Program removed from a chart
|
|
// REASON_RECOMPILE 2 Program recompiled
|
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
// REASON_CHARTCLOSE 4 Chart closed
|
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
// REASON_TEMPLATE 7 Another chart template applied
|
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
// REASON_CLOSE 9 Terminal closed
|
|
|
|
//
|
|
ulong chID = FindChartID(
|
|
_Symbol,
|
|
_Period
|
|
//
|
|
);
|
|
|
|
//
|
|
// Delete Object ...
|
|
ObjectDelete(chID, ShortName);
|
|
|
|
//
|
|
Comment("");
|
|
}
|
|
|
|
//
|
|
// Calculating what we want ...
|
|
int OnCalculate(
|
|
const int rates_total, // Total Bars on Chart ...
|
|
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
const datetime &time[], // History of Open Time ...
|
|
const double &open[], // History of Open Price ...
|
|
const double &high[], // History of High Price ...
|
|
const double &low[], // History of Low Price ...
|
|
const double &close[], // History of Close Price ...
|
|
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
const long &volume[], // History of Trade Volumes ...
|
|
const int &spread[] // History of Spread Price ...
|
|
)
|
|
{
|
|
//
|
|
ArraySetAsSeries(time, true);
|
|
|
|
//
|
|
if (!showTime)
|
|
{
|
|
return rates_total;
|
|
}
|
|
|
|
//
|
|
ulong chID = FindChartID(
|
|
_Symbol,
|
|
_Period
|
|
//
|
|
);
|
|
|
|
//s
|
|
int offset = TimeGMTOffset();
|
|
string timeString =
|
|
"Local: " + string(TimeLocal()) +
|
|
", Server: " + string(TimeTradeServer());
|
|
timeString = timeString;
|
|
|
|
//
|
|
string objText = timeString;
|
|
|
|
//
|
|
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr);
|
|
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
|
|
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
|
|
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Arial");
|
|
|
|
//
|
|
return rates_total;
|
|
}
|
|
|
|
//
|
|
// END Event Handlers ...
|
|
//
|
|
|
|
//
|
|
// START Functions ...
|
|
//
|
|
|
|
//
|
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
void SetIndicatorName()
|
|
{
|
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
}
|
|
|
|
//
|
|
void CreateIndicatorObject()
|
|
{
|
|
//
|
|
if (!showTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
|
|
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
|
|
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
|
|
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
|
|
|
|
//
|
|
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
|
|
switch (corner)
|
|
{
|
|
case CORNER_LEFT_UPPER:
|
|
Anchor = ANCHOR_LEFT_UPPER;
|
|
break;
|
|
case CORNER_RIGHT_UPPER:
|
|
Anchor = ANCHOR_RIGHT_UPPER;
|
|
break;
|
|
case CORNER_LEFT_LOWER:
|
|
Anchor = ANCHOR_LEFT_LOWER;
|
|
break;
|
|
case CORNER_RIGHT_LOWER:
|
|
Anchor = ANCHOR_RIGHT_LOWER;
|
|
break;
|
|
}
|
|
|
|
//
|
|
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
|
|
}
|
|
|
|
//
|
|
// END Functions ...
|
|
//
|