This commit is contained in:
2024-02-02 01:32:20 +03:30
parent 87f09d72f6
commit ebb772b42f
40 changed files with 46510 additions and 16 deletions
+52 -4
View File
@@ -27,10 +27,16 @@
input group "Commons";
//
// END Inputs ...
// XCTIMER inputs ...
input bool xAU5ShowCandleTimer = true; // Show Condle Remaining Time
input color xAU5CandleTimerColot = clrYellow; // Candle Timer Color
input ENUM_BASE_CORNER xAU5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer
//
// END Inputs ...
//
//
//
// START Including Providers ...
//
@@ -65,6 +71,9 @@ bool isXAU5NewHour;
bool isXAU5NewDay;
bool isXAU5NewWeek;
bool isXAU5NewMonth;
//
int xAU5CTimerHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
@@ -104,6 +113,16 @@ int OnInit()
return INIT_PARAMETERS_INCORRECT;
}
//
// Init XCTimer ...
if (xAU5ShowCandleTimer)
{
if (!XAU5CTimerInit())
{
return INIT_FAILED;
}
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
@@ -135,6 +154,9 @@ void OnDeinit(const int reason)
//
// De Init XDraw Library ...
// OnDeinitDrawLibrary();
//
IndicatorRelease(xAU5CTimerHandler);
}
//
@@ -266,7 +288,6 @@ void OnTick()
SendAlert(message);
}
//
// Prevent Going Forward if user Disable it ...
if (xAU5EnableProvider)
@@ -277,11 +298,14 @@ void OnTick()
}
//
if (!IsNewCandle())
if (!IsNewCandle() && xAU5WaitUntilNextCandle)
{
return;
}
//
xAU5WaitUntilNextCandle = false;
//
// Prevent Going Forward if user Disable it ...
if (xAU5EnableProvider)
@@ -342,6 +366,30 @@ bool ValidateInputs()
return result;
}
bool XAU5CTimerInit()
{
//
bool result = true;
//
xAU5CTimerHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xctimer.indicator",
//
// Inputs ...
xAU5CandleTimerColot,
xAU5CandleTimerCorner
);
//
if (xAU5CTimerHandler == 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 ...
//
@@ -85,10 +85,21 @@ input bool xAU5XCHMAMNAllowLongSignals = true; // Enable Long Signals
input bool xAU5XCHMAMNAllowShortSignals = true; // Enable Short Signals
//
bool xAU5IsTestMode = true;
// Check in Test Mode or not ...
bool xAU5IsTestMode = false;
//
// Detect max Input Length of Indicators ...
int xAU5MaxLengthOfInputs = 0;
//
// Detect Calculated Bars ...
int xAU5CalculatedBars = 0;
//
// Check prevent Double Signalling on Same Candle ...
bool xAU5WaitUntilNextCandle = false;
//
// Signaller Variables ...
//
@@ -297,7 +308,7 @@ bool XAU5InitIndicators()
//
// Make it Enable when we need to Log Market Conditions ...
// xAU5IsTestMode = false; // IsRunningOnTestMode();
xAU5IsTestMode = IsRunningOnTestMode();
//
// Check and Calculate Max Length in Inputs ...
@@ -865,7 +876,7 @@ bool XAU5HasLongSignal(
{
//
// Only Log Signals Time Market Conditions if is in Testing Mode ...
if (xAU5IsTestMode)
if (xAU5IsTestMode || xAU5EnableSignalAlerts)
{
//
XMarketConditions mConditions = xAU5Provider.GetLastMarketCondition();
@@ -1021,7 +1032,7 @@ bool XAU5HasShortSignal(
{
//
// Only Log Signals Time Market Conditions if is in Testing Mode ...
if (xAU5IsTestMode)
if (xAU5IsTestMode || xAU5EnableSignalAlerts)
{
//
XMarketConditions mConditions = xAU5Provider.GetLastMarketCondition();
@@ -38,14 +38,14 @@ input int xAU5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
// Alerts ...
input bool xAU5EnableAlerts = true; // Enable Events Alert
input bool xAU5EnableHourlyAlerts = false; // Send Alert on each new Hour
input bool xAU5EnableDailyAlerts = false; // Send Alert on each new Day
input bool xAU5EnableWeeklyAlerts = false; // Send Alert on each new Week
input bool xAU5EnableDailyAlerts = true; // Send Alert on each new Day
input bool xAU5EnableWeeklyAlerts = true; // Send Alert on each new Week
input bool xAU5EnableMonthlyAlerts = true; // Send Alert on each new Month
//
// Reports ...
input bool xAU5EnableDailyReports = false; // Send Report on each new Day
input bool xAU5EnableWeeklyReports = false; // Send Report on each new Week
input bool xAU5EnableMonthlyReports = true; // Send Report on each new Month
input bool xAU5EnableMonthlyReports = false; // Send Report on each new Month
//
// Trader and Expert Specific Configurations ...
@@ -63,14 +63,12 @@ input bool xAU5AllowShortTrades = true; // Allow Short Trades
// Risk Management Configurations ...
input group "XAU5 Risk Management";
//
input bool xAU5UseVirtualTPSl = false; // Use Virtual TP SL
//
// Trade Count ...
input int xAU5MaxAllowedTrades = 10; // Max Allowed Trades at Same Time
input ENUM_X_CROSS_SIGNAL_METHOD xAU5CrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
//
// Max Allowed Trade Age ...
input int xAU5MaxAllowedTradeAge = 2000; // Detect Long Time Trades
input int xAU5MaxAllowedTradeAge = 1800; // Detect Long Time Trades
input ENUM_X_GUARD_ACTIONS xAU5OldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
//
// Trade Volume Specific Configurations ...
@@ -87,9 +85,9 @@ input double xAU5RiskFreeStepInPips = 60; // Make Trades Risk Free Steps in Pips
input double xAU5RiskFreeRate = 0.6; // Volume Multiplier for Risk Free Trades
//
// Guard Riskable Money and Profits ...
input double xAU5CriticalDrawDownFactor = 0.43; // Critical Allowed Drawdown Factor based on Balance
input double xAU5CriticalDrawDownFactor = 0.30; // Critical Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xAU5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Critical Drawdown
input double xAU5MaxAllowedDrawDownFactor = 0.45; // Max Allowed Drawdown Factor based on Balance
input double xAU5MaxAllowedDrawDownFactor = 0.40; // Max Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xAU5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_10; // Specify Guard Action on Max Allowed Drawdown
input int xAU5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
@@ -98,6 +96,11 @@ input int xAU5GuardStopoutFiredAfterTouches = 5;
input double xAU5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
input double xAU5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
//
// May be Used Later as Input Params ...
bool xAU5UseVirtualTPSl = false; // Use Virtual TP SL
bool xAU5EnableSignalAlerts = false; // Send Signal Alert
//
// Validate Inputs before Initialization ...
bool XAU5ValidateInputs()
@@ -513,6 +513,9 @@ void XAU5HandleOpenTrades()
// Update Reports ...
XAU5UpdateReports();
//
xAU5WaitUntilNextCandle = true;
//
// Open Long Trades ...
if (