add support for XCTimer on XUSPY5 EA ...

This commit is contained in:
2024-02-10 15:19:31 +03:30
parent 469414c66b
commit 946b2bfe58
7 changed files with 765 additions and 12 deletions
+49 -4
View File
@@ -27,10 +27,16 @@
input group "Commons";
//
// END Inputs ...
// XCTIMER inputs ...
input bool xUSPY5ShowCandleTimer = true; // Show Condle Remaining Time
input color xUSPY5CandleTimerColot = clrYellow; // Candle Timer Color
input ENUM_BASE_CORNER xUSPY5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer
//
// END Inputs ...
//
//
//
// START Including Providers ...
//
@@ -65,6 +71,9 @@ bool isXUSPY5NewHour;
bool isXUSPY5NewDay;
bool isXUSPY5NewWeek;
bool isXUSPY5NewMonth;
//
int xUSPY5CTimerHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
@@ -104,6 +113,16 @@ int OnInit()
return INIT_PARAMETERS_INCORRECT;
}
//
// Init XCTimer ...
if (xUSPY5ShowCandleTimer)
{
if (!XUSPY5CTimerInit())
{
return INIT_FAILED;
}
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
@@ -135,6 +154,9 @@ void OnDeinit(const int reason)
//
// De Init XDraw Library ...
// OnDeinitDrawLibrary();
//
IndicatorRelease(xUSPY5CTimerHandler);
}
//
@@ -266,7 +288,6 @@ void OnTick()
SendAlert(message);
}
//
// Prevent Going Forward if user Disable it ...
if (xUSPY5EnableProvider)
@@ -275,7 +296,7 @@ void OnTick()
// Handle Processing on XUSPY5 Signal Provider ...
XUSPY5SignalProviderDoControlState();
}
//
// Check Can Ignore Tick or not ..
bool canIgnoreTick = xUSPY5IsTestMode
@@ -349,6 +370,30 @@ bool ValidateInputs()
return result;
}
bool XUSPY5CTimerInit()
{
//
bool result = true;
//
xUSPY5CTimerHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xctimer.indicator",
//
// Inputs ...
xUSPY5CandleTimerColot,
xUSPY5CandleTimerCorner);
//
if (xUSPY5CTimerHandler == INVALID_HANDLE)
{
result = false;
}
//
return result;
}
//
// END Functions ...
//
@@ -0,0 +1,206 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCTimer Indicator
// ---------------------------------------------
// Name: XCTimer
// 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 XCTimer Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XCTimer"
//
// END Constants ...
//
//
// START Inputs ...
//
input color clr = clrYellow;
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER;
//
// END Inputs ...
//
//
// START Buffers ...
//
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
CreateIndicatorObject();
//
// 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);
}
//
// Calculations ...
//
// 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);
//
int m = int(time[0] + PeriodSeconds() - TimeCurrent());
int s = m % 60;
m = (m - s) / 60;
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp = "", _m = "", _s = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
if (m < 10)
_m = "0";
if (s < 10)
_s = "0";
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in " + _m + IntegerToString(m) + ":" + _s + IntegerToString(s);
//
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()
{
//
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 ...
//
+49 -4
View File
@@ -27,10 +27,16 @@
input group "Commons";
//
// END Inputs ...
// XCTIMER inputs ...
input bool xUSPY5ShowCandleTimer = true; // Show Condle Remaining Time
input color xUSPY5CandleTimerColot = clrYellow; // Candle Timer Color
input ENUM_BASE_CORNER xUSPY5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer
//
// END Inputs ...
//
//
//
// START Including Providers ...
//
@@ -65,6 +71,9 @@ bool isXUSPY5NewHour;
bool isXUSPY5NewDay;
bool isXUSPY5NewWeek;
bool isXUSPY5NewMonth;
//
int xUSPY5CTimerHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
@@ -104,6 +113,16 @@ int OnInit()
return INIT_PARAMETERS_INCORRECT;
}
//
// Init XCTimer ...
if (xUSPY5ShowCandleTimer)
{
if (!XUSPY5CTimerInit())
{
return INIT_FAILED;
}
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
@@ -135,6 +154,9 @@ void OnDeinit(const int reason)
//
// De Init XDraw Library ...
// OnDeinitDrawLibrary();
//
IndicatorRelease(xUSPY5CTimerHandler);
}
//
@@ -266,7 +288,6 @@ void OnTick()
SendAlert(message);
}
//
// Prevent Going Forward if user Disable it ...
if (xUSPY5EnableProvider)
@@ -275,7 +296,7 @@ void OnTick()
// Handle Processing on XUSPY5 Signal Provider ...
XUSPY5SignalProviderDoControlState();
}
//
// Check Can Ignore Tick or not ..
bool canIgnoreTick = xUSPY5IsTestMode
@@ -349,6 +370,30 @@ bool ValidateInputs()
return result;
}
bool XUSPY5CTimerInit()
{
//
bool result = true;
//
xUSPY5CTimerHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xctimer.indicator",
//
// Inputs ...
xUSPY5CandleTimerColot,
xUSPY5CandleTimerCorner);
//
if (xUSPY5CTimerHandler == INVALID_HANDLE)
{
result = false;
}
//
return result;
}
//
// END Functions ...
//
+206
View File
@@ -0,0 +1,206 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCTimer Indicator
// ---------------------------------------------
// Name: XCTimer
// 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 XCTimer Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XCTimer"
//
// END Constants ...
//
//
// START Inputs ...
//
input color clr = clrYellow;
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER;
//
// END Inputs ...
//
//
// START Buffers ...
//
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
CreateIndicatorObject();
//
// 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);
}
//
// Calculations ...
//
// 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);
//
int m = int(time[0] + PeriodSeconds() - TimeCurrent());
int s = m % 60;
m = (m - s) / 60;
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp = "", _m = "", _s = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
if (m < 10)
_m = "0";
if (s < 10)
_s = "0";
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in " + _m + IntegerToString(m) + ":" + _s + IntegerToString(s);
//
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()
{
//
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 ...
//
@@ -27,10 +27,16 @@
input group "Commons";
//
// END Inputs ...
// XCTIMER inputs ...
input bool xUSPY5ShowCandleTimer = true; // Show Condle Remaining Time
input color xUSPY5CandleTimerColot = clrYellow; // Candle Timer Color
input ENUM_BASE_CORNER xUSPY5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer
//
// END Inputs ...
//
//
//
// START Including Providers ...
//
@@ -65,6 +71,9 @@ bool isXUSPY5NewHour;
bool isXUSPY5NewDay;
bool isXUSPY5NewWeek;
bool isXUSPY5NewMonth;
//
int xUSPY5CTimerHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
@@ -104,6 +113,16 @@ int OnInit()
return INIT_PARAMETERS_INCORRECT;
}
//
// Init XCTimer ...
if (xUSPY5ShowCandleTimer)
{
if (!XUSPY5CTimerInit())
{
return INIT_FAILED;
}
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
@@ -135,6 +154,9 @@ void OnDeinit(const int reason)
//
// De Init XDraw Library ...
// OnDeinitDrawLibrary();
//
IndicatorRelease(xUSPY5CTimerHandler);
}
//
@@ -266,7 +288,6 @@ void OnTick()
SendAlert(message);
}
//
// Prevent Going Forward if user Disable it ...
if (xUSPY5EnableProvider)
@@ -275,7 +296,7 @@ void OnTick()
// Handle Processing on XUSPY5 Signal Provider ...
XUSPY5SignalProviderDoControlState();
}
//
// Check Can Ignore Tick or not ..
bool canIgnoreTick = xUSPY5IsTestMode
@@ -349,6 +370,30 @@ bool ValidateInputs()
return result;
}
bool XUSPY5CTimerInit()
{
//
bool result = true;
//
xUSPY5CTimerHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xctimer.indicator",
//
// Inputs ...
xUSPY5CandleTimerColot,
xUSPY5CandleTimerCorner);
//
if (xUSPY5CTimerHandler == INVALID_HANDLE)
{
result = false;
}
//
return result;
}
//
// END Functions ...
//
@@ -0,0 +1,206 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCTimer Indicator
// ---------------------------------------------
// Name: XCTimer
// 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 XCTimer Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XCTimer"
//
// END Constants ...
//
//
// START Inputs ...
//
input color clr = clrYellow;
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER;
//
// END Inputs ...
//
//
// START Buffers ...
//
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
CreateIndicatorObject();
//
// 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);
}
//
// Calculations ...
//
// 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);
//
int m = int(time[0] + PeriodSeconds() - TimeCurrent());
int s = m % 60;
m = (m - s) / 60;
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp = "", _m = "", _s = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
if (m < 10)
_m = "0";
if (s < 10)
_s = "0";
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in " + _m + IntegerToString(m) + ":" + _s + IntegerToString(s);
//
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()
{
//
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 ...
//
Binary file not shown.