refactor xTest EA to XGPUS5 for start Implementation ...
This commit is contained in:
@@ -254,14 +254,14 @@ struct XMarketConditions
|
||||
//
|
||||
|
||||
//
|
||||
class XCPriver : public XCBase
|
||||
class XCProvider : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
XCPriver(
|
||||
XCProvider(
|
||||
//
|
||||
// Common Requirements ...
|
||||
string xSymbol, // Which Symbol is Used
|
||||
@@ -362,7 +362,7 @@ public:
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCPriver() {}
|
||||
~XCProvider() {}
|
||||
|
||||
//
|
||||
// START Common Functions ...
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: XAUUSD
|
||||
// Name: XGPUS5
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
@@ -27,10 +27,16 @@
|
||||
input group "Commons";
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
// XCTIMER inputs ...
|
||||
input bool xGPUS5ShowCandleTimer = true; // Show Condle Remaining Time
|
||||
input color xGPUS5CandleTimerColot = clrYellow; // Candle Timer Color
|
||||
input ENUM_BASE_CORNER xGPUS5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
@@ -65,6 +71,9 @@ bool isXGPUS5NewHour;
|
||||
bool isXGPUS5NewDay;
|
||||
bool isXGPUS5NewWeek;
|
||||
bool isXGPUS5NewMonth;
|
||||
|
||||
//
|
||||
int xGPUS5CTimerHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
@@ -104,6 +113,16 @@ int OnInit()
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init XCTimer ...
|
||||
if (xGPUS5ShowCandleTimer)
|
||||
{
|
||||
if (!XGPUS5CTimerInit())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
@@ -135,6 +154,9 @@ void OnDeinit(const int reason)
|
||||
//
|
||||
// De Init XDraw Library ...
|
||||
// OnDeinitDrawLibrary();
|
||||
|
||||
//
|
||||
IndicatorRelease(xGPUS5CTimerHandler);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -266,7 +288,6 @@ void OnTick()
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xGPUS5EnableProvider)
|
||||
@@ -277,11 +298,18 @@ void OnTick()
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsNewCandle())
|
||||
// Check Can Ignore Tick or not ..
|
||||
bool canIgnoreTick = xGPUS5IsTestMode
|
||||
? !IsNewCandle()
|
||||
: !IsNewCandle() && xGPUS5WaitUntilNextCandle;
|
||||
if (canIgnoreTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
xGPUS5WaitUntilNextCandle = false;
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xGPUS5EnableProvider)
|
||||
@@ -342,6 +370,30 @@ bool ValidateInputs()
|
||||
return result;
|
||||
}
|
||||
|
||||
bool XGPUS5CTimerInit()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
xGPUS5CTimerHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xctimer.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xGPUS5CandleTimerColot,
|
||||
xGPUS5CandleTimerCorner);
|
||||
|
||||
//
|
||||
if (xGPUS5CTimerHandler == 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 ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,21 +36,21 @@ input bool xGPUS5EnableProvider = true; // Enable Provider
|
||||
input int xGPUS5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
|
||||
//
|
||||
// Alerts ...
|
||||
input bool xGPUS5EnableAlerts = true; // Enable Events Alert
|
||||
input bool xGPUS5EnableHourlyAlerts = false; // Send Alert on each new Hour
|
||||
input bool xGPUS5EnableDailyAlerts = false; // Send Alert on each new Day
|
||||
input bool xGPUS5EnableWeeklyAlerts = false; // Send Alert on each new Week
|
||||
input bool xGPUS5EnableMonthlyAlerts = true; // Send Alert on each new Month
|
||||
input bool xGPUS5EnableAlerts = true; // Enable Events Alert
|
||||
input bool xGPUS5EnableHourlyAlerts = false; // Send Alert on each new Hour
|
||||
input bool xGPUS5EnableDailyAlerts = false; // Send Alert on each new Day
|
||||
input bool xGPUS5EnableWeeklyAlerts = false; // Send Alert on each new Week
|
||||
input bool xGPUS5EnableMonthlyAlerts = false; // Send Alert on each new Month
|
||||
//
|
||||
// Reports ...
|
||||
input bool xGPUS5EnableDailyReports = false; // Send Report on each new Day
|
||||
input bool xGPUS5EnableWeeklyReports = false; // Send Report on each new Week
|
||||
input bool xGPUS5EnableMonthlyReports = true; // Send Report on each new Month
|
||||
input bool xGPUS5EnableDailyReports = false; // Send Report on each new Day
|
||||
input bool xGPUS5EnableWeeklyReports = false; // Send Report on each new Week
|
||||
input bool xGPUS5EnableMonthlyReports = false; // Send Report on each new Month
|
||||
|
||||
//
|
||||
// Trader and Expert Specific Configurations ...
|
||||
input group "XGPUS5 Trader";
|
||||
input int xGPUS5MagicNumber = 16940561; // Trader MagicNumber
|
||||
input int xGPUS5MagicNumber = 16940563; // Trader MagicNumber
|
||||
input int xGPUS5Slippage = 10; // Trader Slippage
|
||||
|
||||
//
|
||||
@@ -63,18 +63,16 @@ input bool xGPUS5AllowShortTrades = true; // Allow Short Trades
|
||||
// Risk Management Configurations ...
|
||||
input group "XGPUS5 Risk Management";
|
||||
//
|
||||
input bool xGPUS5UseVirtualTPSl = false; // Use Virtual TP SL
|
||||
//
|
||||
// Trade Count ...
|
||||
input int xGPUS5MaxAllowedTrades = 10; // Max Allowed Trades at Same Time
|
||||
input ENUM_X_CROSS_SIGNAL_METHOD xGPUS5CrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
|
||||
//
|
||||
// Max Allowed Trade Age ...
|
||||
input int xGPUS5MaxAllowedTradeAge = 2000; // Detect Long Time Trades
|
||||
input int xGPUS5MaxAllowedTradeAge = 300; // Detect Long Time Trades
|
||||
input ENUM_X_GUARD_ACTIONS xGPUS5OldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
|
||||
//
|
||||
// Trade Volume Specific Configurations ...
|
||||
input double xGPUS5StaticVolumeFactor = 0.0002; // Static Volume baesd on Balance
|
||||
input double xGPUS5StaticVolumeFactor = 0.0004; // Static Volume baesd on Balance
|
||||
input ENUM_STATIC_VOLUME_METHODS xGPUS5StaticVolumeMethod = X_STATIC_VOLUME_BASED_ON_BALANCE; // How to Calculate Static Volume
|
||||
input double xGPUS5VolumeMultiplier = 0; // Volume Increase Multiplier
|
||||
input double xGPUS5ApplyVolumeMultiplierFactor = 0; // Apply Volume Multiplier Rate based on Balance
|
||||
@@ -82,22 +80,27 @@ input double xGPUS5MaxSupportedVolumePerTradeFactor = 0;
|
||||
input double xGPUS5IncreasedMaxSupportedVolumeRate = 0; // Increase Max Supported Volume based on Balance
|
||||
//
|
||||
// Trade Profits ...
|
||||
input double xGPUS5MinRewardInPips = 150; // Minimum Reward Per Trade in Pips
|
||||
input double xGPUS5RiskFreeStepInPips = 60; // Make Trades Risk Free Steps in Pips
|
||||
input double xGPUS5RiskFreeRate = 0.6; // Volume Multiplier for Risk Free Trades
|
||||
input double xGPUS5MinRewardInPips = 60; // Minimum Reward Per Trade in Pips
|
||||
input double xGPUS5RiskFreeStepInPips = 0; // Make Trades Risk Free Steps in Pips
|
||||
input double xGPUS5RiskFreeRate = 0; // Volume Multiplier for Risk Free Trades
|
||||
//
|
||||
// Guard Riskable Money and Profits ...
|
||||
input double xGPUS5CriticalDrawDownFactor = 0.43; // Critical Allowed Drawdown Factor based on Balance
|
||||
input ENUM_X_GUARD_ACTIONS xGPUS5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Critical Drawdown
|
||||
input double xGPUS5MaxAllowedDrawDownFactor = 0.45; // Max Allowed Drawdown Factor based on Balance
|
||||
input ENUM_X_GUARD_ACTIONS xGPUS5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_10; // Specify Guard Action on Max Allowed Drawdown
|
||||
input int xGPUS5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
|
||||
input double xGPUS5CriticalDrawDownFactor = 0.10; // Critical Allowed Drawdown Factor based on Balance
|
||||
input ENUM_X_GUARD_ACTIONS xGPUS5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // Specify Guard Action on Critical Drawdown
|
||||
input double xGPUS5MaxAllowedDrawDownFactor = 0.15; // Max Allowed Drawdown Factor based on Balance
|
||||
input ENUM_X_GUARD_ACTIONS xGPUS5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Max Allowed Drawdown
|
||||
input int xGPUS5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
|
||||
|
||||
//
|
||||
// Account Conditions for Trading ...
|
||||
input double xGPUS5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
|
||||
input double xGPUS5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
|
||||
|
||||
//
|
||||
// May be Used Later as Input Params ...
|
||||
bool xGPUS5UseVirtualTPSl = false; // Use Virtual TP SL
|
||||
bool xGPUS5EnableSignalAlerts = false; // Send Signal Alert
|
||||
|
||||
//
|
||||
// Validate Inputs before Initialization ...
|
||||
bool XGPUS5ValidateInputs()
|
||||
@@ -209,7 +212,7 @@ bool XGPUS5ValidateInputs()
|
||||
//
|
||||
result =
|
||||
xGPUS5CriticalDrawDownFactor == 0 || (xGPUS5CriticalDrawDownFactor > 0 &&
|
||||
xGPUS5CriticalDrawDownFactor < 1);
|
||||
xGPUS5CriticalDrawDownFactor < 1);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
@@ -222,7 +225,7 @@ bool XGPUS5ValidateInputs()
|
||||
//
|
||||
result =
|
||||
xGPUS5MaxAllowedDrawDownFactor == 0 || (xGPUS5MaxAllowedDrawDownFactor > 0 &&
|
||||
xGPUS5MaxAllowedDrawDownFactor < 1);
|
||||
xGPUS5MaxAllowedDrawDownFactor < 1);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
|
||||
@@ -513,6 +513,9 @@ void XGPUS5HandleOpenTrades()
|
||||
// Update Reports ...
|
||||
XGPUS5UpdateReports();
|
||||
|
||||
//
|
||||
xGPUS5WaitUntilNextCandle = true;
|
||||
|
||||
//
|
||||
// Open Long Trades ...
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user