Files
MQL5Data/Indicators/x-saherelm.x121.xct.mq5
T

263 lines
5.5 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121 XCT
// Description: Trend Magic 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 X121 XCT Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "X121 XCT"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input int fontSize = 15; // Font Size
input string font = "Arial"; // Font
input color clr = clrYellow; // Text Color
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
//
input group "Presentation";
input bool showTimer = true; // Show Candle 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 ...
//
bool isCreatedObject;
string tag;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
//
tag = ShortName + _Symbol + ToString(_Period);
//
// 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
//
// Delete Object ...
ObjectDelete(0, tag);
//
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 ...
)
{
//
if (!showTimer)
{
return rates_total;
}
//
XBarRemainsTime barRemains;
barRemains.Init(
_Symbol,
_Period
//
);
//
string msg = barRemains
.ToString(
"",
"",
"",
"",
"",
":",
true
//
);
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
//
string _sp = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg;
//
if (IsValid(tag) && !isCreatedObject)
{
CreateIndicatorObject();
}
//
if (isCreatedObject)
{
ObjectSetString(0, tag, OBJPROP_TEXT, objText);
}
//
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 (!showTimer ||
!IsValid(tag))
{
return;
}
//
isCreatedObject = ObjectCreate(0, tag, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, tag, OBJPROP_CORNER, corner);
ObjectSetInteger(0, tag, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, tag, 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;
}
//
int mFontSize = fontSize > 0
? fontSize
: 10;
//
string mFont = IsValid(font)
? font
: "Arial";
//
ObjectSetString(0, tag, OBJPROP_FONT, mFont);
ObjectSetInteger(0, tag, OBJPROP_COLOR, clr);
ObjectSetInteger(0, tag, OBJPROP_ANCHOR, Anchor);
ObjectSetInteger(0, tag, OBJPROP_FONTSIZE, mFontSize);
}
//
// END Functions ...
//