265 lines
5.1 KiB
Plaintext
265 lines
5.1 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 color clr = clrYellow; // Text Color
|
|
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
|
|
|
//
|
|
input group "Presentation";
|
|
input bool showCandleTime = 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 ...
|
|
//
|
|
|
|
//
|
|
// END Global Definitions: Variables, Properties and etc ...
|
|
//
|
|
|
|
//
|
|
// START Event Handlers ...
|
|
//
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
// Validate Inputs ...
|
|
if (showCandleTime)
|
|
{
|
|
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
|
|
|
|
//
|
|
// Delete Object ...
|
|
ObjectDelete(0, ShortName);
|
|
|
|
//
|
|
Comment("");
|
|
}
|
|
|
|
//
|
|
// Calculating what we want ...
|
|
int OnCalculate(
|
|
//
|
|
// total Candles on chart ...
|
|
const int rates_total,
|
|
//
|
|
// total calculated Candles on charts ...
|
|
const int prev_calculated,
|
|
//
|
|
// history of Candles Open Time ...
|
|
const datetime &time[],
|
|
//
|
|
// history of Candles Open Price ...
|
|
const double &open[],
|
|
//
|
|
// history of Candles High Price ...
|
|
const double &high[],
|
|
//
|
|
// history of Candles Low Price ...
|
|
const double &low[],
|
|
//
|
|
// history of Candles Close Price ...
|
|
const double &close[],
|
|
//
|
|
// history of Tick Volumes on Candle ...
|
|
const long &tick_volume[],
|
|
//
|
|
// history of Trade Volumes ...
|
|
const long &volume[],
|
|
//
|
|
// history of Candles Spread Price ...
|
|
const int &spread[])
|
|
{
|
|
//
|
|
ArraySetAsSeries(time, true);
|
|
|
|
//
|
|
if (!showCandleTime)
|
|
{
|
|
return rates_total;
|
|
}
|
|
|
|
//
|
|
XCandleRemains remainTime;
|
|
GetCandleRemainsTime(
|
|
remainTime,
|
|
_Symbol,
|
|
_Period,
|
|
0);
|
|
|
|
//
|
|
string msg = ToString(
|
|
remainTime,
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
":",
|
|
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;
|
|
|
|
//
|
|
ObjectSetInteger(0, ShortName, OBJPROP_COLOR, clr);
|
|
ObjectSetString(0, ShortName, OBJPROP_TEXT, objText);
|
|
ObjectSetInteger(0, ShortName, OBJPROP_FONTSIZE, 10);
|
|
ObjectSetString(0, ShortName, OBJPROP_FONT, "Courier");
|
|
|
|
//
|
|
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 (!showCandleTime)
|
|
{
|
|
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 ...
|
|
//
|