bkp till 14040626 ...

This commit is contained in:
2025-09-17 09:05:15 +03:30
parent 2bba99ea88
commit afafeca00a
123 changed files with 166574 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,977 @@
`
//
// an Structure for Holds an Specified Symbols
// Positions Info ...
struct XTradeSymbolInfo
{
//
// Properties ...
//
string symbol; // Trading Symbol
//
int longs; // All Long Trades
int shorts; // All Short Trades
//
int trades; // All Trades
//
int losses; // All Loosing Trades
int profits; // All Winning Trades
//
datetime managedStart; // Managed Start Time
//
int managedSLs; // Managed SL(s)
int managedTPs; // Managed TP(s)
int managedTrades; // Managed Trades
//
double managedBalance; // Managed Start Balance
double managedProfits; // Managed Profit(s)
//
// Constructor ...
XTradeSymbolInfo()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
symbol = NULL;
//
longs = 0;
shorts = 0;
//
trades = 0;
//
losses = 0;
profits = 0;
//
managedStart = NULL;
//
managedSLs = 0;
managedTPs = 0;
managedTrades = 0;
//
managedBalance = 0;
managedProfits = 0;
//
ZeroMemory(this);
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result = IsSpecifiedValid(symbol);
//
return result;
}
//
bool IsSameAs(XTradeSymbolInfo &item)
{
//
bool result = false;
//
result = IsValid() &&
item.IsValid() &&
symbol == item.symbol;
//
return result;
}
//
string GetRestrictionDescription(
ENUM_XTRADE_RESTRICTION_PERIOD period //
)
{
//
string result = NULL;
//
if (!IsValid() ||
!HasRestrictions(period))
{
return result;
}
//
result +=
"-------------------" + "\n" +
"Restrictions: " + "\n" +
"-------------------" + "\n" +
"Symbol: " + ToXString(symbol) + "\n" +
"Period: " + ToXString(period) + "\n" +
"Start: " + ToFormatString(managedStart) + "\n" +
"Balance: " + ToXString(managedBalance) + "\n" +
"-------------------" + "\n" +
"Trades: " + ToXString(managedTrades) + "\n" +
"SL: " + ToXString(managedSLs) + "\n" +
"TP: " + ToXString(managedTPs) + "\n" +
"Profit: " + ToXString(managedProfits) + "\n" +
"";
//
return result;
}
};
//
void SetForceCloseTradesAt(
string _forceCloseAt //
)
{
forceCloseAt = _forceCloseAt;
}
//
void SetTradeSession(
string symbol,
string start,
string end,
string name = NULL //
)
{
//
// Validate Args ...
bool has = IsValid(end) &&
IsValid(start) &&
IsValid(symbol);
if (!has)
{
return;
}
//
// Create Session ...
//
XTradeSession session;
//
session.end = end;
session.name = name;
session.start = start;
//
int sessionIDX = -1;
has = FindSymbolSession(
sessionIDX,
symbol //
);
//
if (!has)
{
//
// Add New Symbol Session ...
//
XSymbolSessions iSymbolSession;
iSymbolSession.symbol = symbol;
//
AddTradingSession(
session,
iSymbolSession //
);
//
AddRef(
iSymbolSession,
sessions //
);
//
iSymbolSession.Clean();
}
else
{
//
// Update Trading Sessions of Exists Symbol Session ...
AddTradingSession(
session,
sessions[sessionIDX] //
);
}
//
// Cleanup Resources ...
session.Clean();
}
//
void SetTradeRestrictions(
ENUM_XTRADE_RESTRICTION_PERIOD _period,
int _maxAllowedTPs,
int _maxAllowedSLs,
int _maxAllowedTrades //
)
{
//
// Normalizing Args ...
_maxAllowedTPs = NormalizeInt(_maxAllowedTPs, 0);
_maxAllowedSLs = NormalizeInt(_maxAllowedSLs, 0);
_maxAllowedTrades = NormalizeInt(_maxAllowedTrades, 0);
//
restrictionsPeriod = _period;
maxAllowedTPs = _maxAllowedTPs;
maxAllowedSLs = _maxAllowedSLs;
maxAllowedTrades = _maxAllowedTrades;
}
//
// Symbol Info ...
//
bool FindSymbolIndex(
int &index,
XTradeSymbolInfo &item //
)
{
//
bool result = false;
//
index = -1;
//
result = item.IsValid();
if (!result)
{
return result;
}
//
result = HasChild(symbols);
if (!result)
{
return result;
}
//
index = FindIndex(
item,
symbols //
);
//
result = IsValidIndex(index);
//
return result;
}
//
bool FindSymbolIndex(
int &index,
string symbol //
)
{
//
bool result = false;
//
index = -1;
//
result = IsValid(symbol) &&
HasChild(symbols);
if (!result)
{
return result;
}
//
int count = ArraySize(symbols);
for (int i = 0; i < count; i++)
{
//
result = symbols[i].symbol == symbol;
if (result)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
//
void AddOrUpdateSymbolInfo(XTradeSymbolInfo &item)
{
//
bool has = item.IsValid();
if (!has)
{
return;
}
//
int index = -1;
bool isExists = FindSymbolIndex(
index,
item //
);
if (!isExists)
{
//
AddRef(
item,
symbols //
);
}
else
{
//
symbols[index].longs += item.longs;
symbols[index].shorts += item.shorts;
symbols[index].trades += item.trades;
symbols[index].losses += item.losses;
symbols[index].profits += item.profits;
symbols[index].managedSLs += item.managedSLs;
symbols[index].managedTPs += item.managedTPs;
symbols[index].managedTrades += item.managedTrades;
symbols[index].managedProfits += item.managedProfits;
//
// Handle Remove on Managed SL based On Managed TP ...
if (item.managedTPs > 0)
{
//
symbols[index].managedSLs -= item.managedTPs;
if (symbols[index].managedSLs < 0)
{
symbols[index].managedSLs = 0;
}
}
//
// Handle Remove on Managed TP based On Managed SL ...
if (item.managedSLs > 0)
{
//
symbols[index].managedTPs -= item.managedSLs;
if (symbols[index].managedTPs < 0)
{
symbols[index].managedTPs = 0;
}
}
}
}
//
void ResetSymbolsRestrictions()
{
//
bool has = HasChild(symbols);
if (has)
{
//
string prefix = "Protector: ";
//
datetime start = TimeCurrent();
double balance = trader.mAccount.GetBalance();
bool hasRestrictions = HasRestrictions(restrictionsPeriod);
if (!hasRestrictions)
{
//
balance = 0;
start = NULL;
}
//
int count = ArraySize(symbols);
for (int i = 0; i < count; i++)
{
//
XTradeSymbolInfo iInfo = symbols[i];
if (reportRestrictions)
{
//
string message = iInfo.GetRestrictionDescription(restrictionsPeriod);
alert.SendAlert(message);
}
SaveRestrictions(iInfo);
//
symbols[i].managedSLs = 0;
symbols[i].managedTPs = 0;
symbols[i].managedTrades = 0;
symbols[i].managedProfits = 0;
symbols[i].managedStart = start;
symbols[i].managedBalance = balance;
//
iInfo.Clean();
}
//
string message = prefix + "Reset Symbols Restrictions";
HandleReportProtector(message);
}
}
//
void HandleRestrictions()
{
//
bool isNewDay = timeTracker.IsNewDay();
bool isNewHour = timeTracker.IsNewHour();
bool isNewWeek = timeTracker.IsNewWeek();
bool isNewMonth = timeTracker.IsNewMonth();
//
// Reset Force Closed Flag on new Day Starts ...
if (isNewDay)
{
isForceCloseAtTime = false;
}
//
bool canResetRestrictions =
(
//
// Hourly ...
(isNewHour &&
restrictionsPeriod == XTRADE_RESTRICATION_HOURLY)
//
||
//
// Daily ...
(isNewDay &&
restrictionsPeriod == XTRADE_RESTRICATION_DAILY)
//
||
//
// Weekly ...
(isNewWeek &&
restrictionsPeriod == XTRADE_RESTRICATION_WEEKLY)
//
||
//
// Monthly ...
(isNewMonth &&
restrictionsPeriod == XTRADE_RESTRICATION_MONTHLY)
//
)
//
;
if (canResetRestrictions)
{
ResetSymbolsRestrictions();
}
}
//
bool SaveRestrictions(XTradeSymbolInfo &info)
{
//
bool result = false;
//
if (!mSaveRestrictions)
{
return result;
}
//
result = info.IsValid();
if (!result)
{
return result;
}
//
string filePath = GetRestrictionsFilePath(info.symbol);
result = IsValid(filePath);
if (!result)
{
return result;
}
//
string content = info.GetRestrictionDescription(restrictionsPeriod);
//
result = collector.Append(
filePath,
content //
);
//
return result;
}
//
// Symbol Session ...
//
bool FindSymbolSession(
int &index,
string symbol //
)
{
//
bool result = false;
//
index = -1;
//
result = IsValid(symbol) &&
HasChild(sessions);
if (!result)
{
return result;
}
//
int count = ArraySize(sessions);
for (int i = 0; i < count; i++)
{
//
result = sessions[i].symbol == symbol;
if (result)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
//
void AddTradingSession(
XTradeSession &session,
XSymbolSessions &symbolSession //
)
{
//
bool has = session.IsValid() &&
symbolSession.IsValid();
if (!has)
{
return;
}
//
// Check Session Exists in Symbol Session ...
bool isExists = false;
if (HasChild(symbolSession.sessions))
{
//
int count = ArraySize(symbolSession.sessions);
for (int i = 0; i < count; i++)
{
//
isExists = symbolSession.sessions[i].end == session.end &&
symbolSession.sessions[i].start == session.start;
if (isExists)
{
break;
}
}
}
//
if (!isExists)
{
//
AddRef(
session,
symbolSession.sessions //
);
}
}
/**
* Check Signal Execution Conditions ...
*
* @param signal: XSignal instance reference ...
* @param executionResult: ENUM_X_SIGNAL_EXECUTION_RESULT member reference ...
*
* @return ( bool )
*/
bool CheckSignal(
XSignal &signal,
ENUM_X_SIGNAL_EXECUTION_RESULT &executionResult //
)
{
//
bool result = false;
//
// Cleanup ...
executionResult = X_SIGNAL_EXECUTION_UNKNOWN;
//
// Validate Signal ...
result = signal.IsValid();
if (!result)
{
return result;
}
//
// Reporting Signal ...
if (reportSignals)
{
//
string message = signal.GetMessage("Provided");
alert.SendAlert(message);
}
//
SaveSignal(signal);
//
// Check Trade Permission ...
if (!allowTrade)
{
//
result = false;
executionResult = X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED;
//
return result;
}
//
bool isLong = IsLong(signal.type);
bool isShort = IsShort(signal.type);
//
bool isLongAndAllowed =
isLong &&
allowLongs;
//
bool isShortAndAllowed =
isShort &&
allowShorts;
//
result = isLongAndAllowed ||
isShortAndAllowed;
if (!result)
{
//
executionResult = X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED;
//
return result;
}
//
// Check Symbol Info Exists or not ...
int symbolInfoIDX = -1;
bool isSymbolInfoExists = FindSymbolIndex(
symbolInfoIDX,
signal.symbol //
);
//
// Check Symbol Session Exists or not ...
int symbolSessionIDX = -1;
bool isSymbolSessionExists = FindSymbolSession(
symbolSessionIDX,
signal.symbol //
);
//
// Chack Trade Session Validating ...
if (isSymbolSessionExists)
{
//
result = sessions[symbolSessionIDX].CanTrade();
if (!result)
{
//
executionResult = X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED;
//
return result;
}
}
//
// Check Trade Permissions Based on SL(s) Count ...
bool hasRestrictions = restrictionsPeriod != XTRADE_RESTRICATION_NONE;
if (hasRestrictions)
{
//
// Only Can Check Restrictions when
// Symbol Info Exists ...
if (isSymbolInfoExists)
{
//
bool isTPAllowed = maxAllowedTPs == 0
? true
: symbols[symbolInfoIDX].managedTPs < maxAllowedTPs;
bool isSLAllowed = maxAllowedSLs == 0
? true
: symbols[symbolInfoIDX].managedSLs < maxAllowedSLs;
bool isTradeAllowed = maxAllowedTrades == 0
? true
: symbols[symbolInfoIDX].managedTrades < maxAllowedTrades;
//
result = isTPAllowed &&
isSLAllowed &&
isTradeAllowed;
}
//
// Report Error ...
if (!result)
{
//
executionResult = X_SIGNAL_EXECUTION_FAILED_MAX_REACHED;
//
return result;
}
}
//
return result;
}
/**
* Execute Specified Signal ...
*
* @param signal: XSignal instance reference ...
* @param conditions: XCATBEAStrategyConditions instance reference ...
*
* @return ( bool )
*/
bool Execute(XSignal &signal)
{
//
bool result = false;
//
result = signal.IsValid();
if (!result)
{
return result;
}
//
int idx = -1;
bool isExists = HasTrade(
idx,
signal //
);
result = !isExists;
if (!result)
{
return result;
}
//
ENUM_X_SIGNAL_EXECUTION_RESULT executionResult;
//
// Checking Signal For Execution ...
result = CheckSignal(
signal,
executionResult //
);
if (result)
{
//
result = trader.ExecuteSignal(
signal,
executionResult //
);
}
//
// Alert Signal Execution ...
if (reportTrades)
{
//
string executionMessage = ToString(executionResult);
//
string message = NULL;
if (result)
{
message = signal.GetMessage("Executed");
}
else
{
message = signal.GetMessage("Failed due (" + executionMessage + ")");
}
//
alert.SendAlert(message);
}
//
if (result)
{
//
// Create Symbol Info Struct ...
XTradeSymbolInfo iSymbolInfo;
//
iSymbolInfo.trades = 1;
iSymbolInfo.managedTrades = 1;
iSymbolInfo.symbol = signal.symbol;
//
bool isLong = IsLong(signal.type);
if (isLong)
{
iSymbolInfo.longs = 1;
}
else
{
iSymbolInfo.shorts = 1;
}
//
// Fill Balance for Restrications ...
bool hasRestrictions = HasRestrictions(restrictionsPeriod);
if (hasRestrictions)
{
//
// Read Balance ...
double balance = trader.mAccount.GetBalance();
iSymbolInfo.managedBalance = balance;
iSymbolInfo.managedStart = TimeCurrent();
}
//
AddOrUpdateSymbolInfo(iSymbolInfo);
//
// Create Trade Struct ...
XTradeInfo iTrade;
//
ulong positionID = trader.GetLastOpenPositionTicket();
double commission = trader.GetPositionCommission(positionID);
//
iTrade.signal = signal;
iTrade.positionID = positionID;
iTrade.commission = commission;
iTrade.signaledAt = signal.time;
iTrade.executedAt = TimeCurrent();
iTrade.conditions = signal.conditions;
//
AddRef(
iTrade,
trades //
);
}
//
return result;
}
/**
* Check Specified Symbol is Active for
* Analysing or Open Trades ...
*/
bool IsActiveSession(string symbol)
{
//
bool result = false;
//
// Validate Args ...
result = IsValid(symbol);
if (!result)
{
return result;
}
//
// TODO: Complete this ...
// //
// // Check Symbol Session Exists or not ...
// int symbolSessionIDX = -1;
// bool isSymbolSessionExists = FindSymbolSession(
// symbolSessionIDX,
// symbol //
// );
// //
// // Chack Trade Session Validating ...
// if (isSymbolSessionExists)
// {
// result = sessions[symbolSessionIDX].CanTrade();
// }
//
return result;
}
//
string forceCloseAt;
bool isForceCloseAtTime;
//
int maxAllowedTPs;
int maxAllowedSLs;
int maxAllowedTrades;
ENUM_XTRADE_RESTRICTION_PERIOD restrictionsPeriod;
XTradeSymbolInfo symbols[];
XSymbolSessions sessions[];
//
forceCloseAt = NULL;
isForceCloseAtTime = false;
//
maxAllowedTPs = 0;
maxAllowedSLs = 0;
maxAllowedTrades = 0;
restrictionsPeriod = XTRADE_RESTRICATION_NONE;
@@ -0,0 +1,747 @@
void UpdateMainPanel()
{
//
// Validate ...
if (mChartHelper == NULL ||
mainPanel == NULL)
{
return;
}
//
bool has = false;
//
// Update Main Panel Position ...
XObjPosition mainPanelPosition;
CalculateMainPanelPosition(mainPanelPosition);
if (mainPanelPosition.IsValidForRectangle())
{
//
has = mainPanel.ShiftPoint(1, mainPanelPosition.fromTime, mainPanelPosition.fromPrice);
if (has)
{
has = mainPanel.ShiftPoint(2, mainPanelPosition.toTime, mainPanelPosition.toPrice);
}
}
}
/**
* Calculate Main Window Position ...
*
* @param position: XObjPosition
*/
void CalculateMainPanelPosition(XObjPosition &position)
{
//
position.Clean();
//
// Reading Chart Helper Requirements ...
//
string mChartSymbol = mChartHelper.Symbol();
double mPoint = GetPoints(mChartSymbol);
//
ENUM_TIMEFRAMES mChartPeriod = mChartHelper.Period();
int mChartPeriodSeconds = PeriodSeconds(mChartPeriod);
//
double mChartMinPrice = mChartHelper.PriceMin();
double mChartMaxPrice = mChartHelper.PriceMax();
int mChartVisibleBarsCount = mChartHelper.VisibleBars();
int mChartFirstBarIndex = mChartHelper.FirstVisibleBar();
//
datetime mChartFirstBarTime = GetBarTime(
mChartSymbol,
mChartPeriod,
mChartFirstBarIndex //
);
//
position.fromTime = mChartFirstBarTime + (mChartPeriodSeconds);
position.fromPrice = mChartMaxPrice - (10 * mPoint);
//
position.toTime = position.fromTime + (40 * mChartPeriodSeconds);
position.toPrice = position.fromPrice - (20 * mPoint);
//
Print(" ");
//
Print("From Time: ", position.fromTime);
Print("To Time: ", position.toTime);
//
Print(" ");
//
Print("From Price: ", position.fromPrice);
Print("To Price: ", position.toPrice);
}
///////////////////////////////////////////////////////
//
// SaherElm IT Center XTest MQL5 Expert Advisor
// -------------------------------------------------
// Name: XBackTester
// Description: a Backtest Tools Strategy Tester
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XBackTester"
#property strict
//
#define ShortName "XBackTester"
//
// Imports ...
#include "../Classes/x-saherelm.x-alert.class.mq5"
#include "../Classes/x-saherelm.x-chart.helper.class.mq5"
#include "../Classes/x-saherelm.x-trade.class.mq5"
//
// Import Chart Objects ...
#include <ChartObjects/ChartObject.mqh>
#include <ChartObjects/ChartObjectsArrows.mqh>
#include <ChartObjects/ChartObjectsFibo.mqh>
#include <ChartObjects/ChartObjectsLines.mqh>
#include <ChartObjects/ChartObjectsShapes.mqh>
#include <ChartObjects/ChartObjectsTxtControls.mqh>
#include <Charts/Chart.mqh>
//
// Definitions ...
struct XObjPosition
{
//
// Props ...
datetime fromTime;
double fromPrice;
datetime toTime;
double toPrice;
//
// Constructor ...
XObjPosition()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
toPrice = 0;
fromPrice = 0;
//
toTime = NULL;
fromTime = NULL;
}
//
// Validate XWindowPosition for Rectangle ...
bool IsValidForRectangle()
{
//
bool result =
//
toPrice > 0 &&
fromPrice > 0 &&
IsSpecifiedValid(toTime) &&
IsSpecifiedValid(fromTime) &&
fromTime < toTime
//
;
//
return result;
}
};
//
// Inputs ...
//
// Common ...
input group "Common";
input long eaMagicNumber = 78692110; // Magic Number
input int eaSlippage = 10; // Slippgae
input string eaLogSuffix = ""; // Log Suffix
//
// Alert ...
// Here we Provider All Requirements for
// Configuring Alert Provider ...
input group "Alert";
input bool eAEnableAlerts = true; // Enable Alerts
input bool eALogAlerts = true; // Log Alerts
input bool eAMailAlerts = false; // Mail Alerts
input bool eAPushAlerts = false; // Push Alerts
input bool eATerminalAlerts = false; // Terminal Alerts
//
// Define Local Variables ...
//
string eaLogTag; // EA Log Prefix ...
XCAlert *eaAlert; // Alert Provider for Expert Adviser ...
XCTrade *eaTrader; // Trader of Expert Adviser ...
//
// Chart Objects and Properties ...
XCChartHelper *mChartHelper;
//
// Chart Object Class ...
//
string objSuffix;
//
// Main Panel ...
string mainPanelName;
CChartObjectRectLabel *mainPanel; // Main Panel ...
string buyButtonName;
CChartObjectButton *buyButton; // Buy Button ...
string sellButtonName;
CChartObjectButton *sellButton; // Sell Button ...
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs and Required Parameters
// for EA to Works fine ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Timer ...
if (!InitTimer())
{
return INIT_FAILED;
}
//
// Initialize all Requirements ...
if (!InitEA())
{
return INIT_FAILED;
}
//
// Initialize all GUI Objects and Classes ...
if (!InitGUI())
{
return INIT_FAILED;
}
//
// Alert Initialization ...
string msg = "Initialized Successfully ...";
eaAlert.SendAlert(msg);
//
// 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
//
// Destroy Timer ...
DestroyTimer();
//
// Destroy all GUI Requirements ...
DestroyGUI();
//
// Alert De Initialization Succeeded ...
string msg = "De Initialized Successfully ...";
eaAlert.SendAlert(msg);
//
// Destroy all EA Requirements ...
DestroyEA();
}
//
// On Tick Handler ...
void OnTick()
{
//
UpdateGUI();
}
//
// Handle On Trade Event ...
void OnTrade()
{
eaTrader.HandleOnTrade();
}
//
// On Timer ...
void OnTimer()
{
//
// TODO: Implement Time Based Functionalities ...
}
//
// Chart Event Handler ...
void OnChartEvent(
const int id,
const long &lparam,
const double &dparam,
const string &sparam //
)
{
//
// Apply Chart Event on Main Window ...
if (id == CHARTEVENT_OBJECT_CLICK)
{
//
if (mainPanel != NULL && sparam == mainPanelName)
{
//
Print("Main Panel Clicked ...");
}
}
}
//
// Custom Functions ...
/**
* Validate all Inputs of Expert Adviser ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
string errMessage = "";
//
bool isCommonValid = (
//
eaSlippage > 0 &&
eaMagicNumber > 0
//
);
if (!isCommonValid)
{
//
errMessage += "common configurations error;" + "\n";
}
//
result =
//
// Common ...
isCommonValid &&
//
// Otere ...
true
//
;
//
if (!result)
{
//
// Since here Logger not Initiallized, we Use Raw Print Command ...
Print(ShortName + " Errors: \n", errMessage);
}
//
return result;
}
/**
* Initialize Timer ...
*
* @return ( bool )
*/
bool InitTimer()
{
//
bool result = false;
//
// TODO: Initialize Timer if necessary ...
// result = EventSetTimer(1);
// result = EventSetMillisecondTimer(100);
result = true;
//
return result;
}
/**
* Destroy Timer ...
*/
void DestroyTimer()
{
//
// TODO: Use This ...
// EventKillTimer();
}
/**
* Initialize all Requirements for Working Fine ...
*
* @return ( bool )
*/
bool InitEA()
{
//
bool result = false;
//
// Locally Apply Changes on Prefix ...
eaLogTag = ShortName + ">" + eaLogSuffix;
//
// Create Instance of Alert Class and Configure it ...
eaAlert = new XCAlert();
eaAlert.SetPrefix(eaLogTag);
eaAlert.SetLogAlerts(eALogAlerts);
eaAlert.SetMailAlerts(eAMailAlerts);
eaAlert.SetPushAlerts(eAPushAlerts);
eaAlert.SetEnableAlerts(eAEnableAlerts);
eaAlert.SetTerminalAlerts(eATerminalAlerts);
//
// Create Trader Instance and Configure it ...
eaTrader = new XCTrade(
eaSlippage,
eaMagicNumber //
);
//
// TODO: Fix This ...
result = true;
//
return result;
}
/**
* Destroy all Initialized EA Requirements ...
*/
void DestroyEA()
{
//
delete eaAlert;
}
//
// GUI Events ...
/**
* Initialize all GUI Requirements for EA ...
*
* @return ( bool )
*/
bool InitGUI()
{
//
bool result = false;
//
int subWindow = 0;
ulong chartId = ChartID();
objSuffix = ShortName + "_";
//
// Initial Chart Class Instance ...
mChartHelper = new XCChartHelper(chartId);
//
// Create Main Panel ...
result = CreateMainPanel();
//
//
return result;
}
/**
* Update GUI based on Each Ticks ...
*/
void UpdateGUI()
{
//
// UpdateMainPanel();
}
/**
* Destroy all Initialized GUi Requirements ...
*/
void DestroyGUI()
{
//
delete mChartHelper;
ZeroMemory(mChartHelper);
//
delete mainPanel;
ZeroMemory(mainPanel);
}
//
// Custom Helper Functions ...
bool CreateMainPanel()
{
//
bool result = false;
//
if (mChartHelper == NULL)
{
return result;
}
//
int subWindow = 0;
//
mainPanelName = objSuffix + "Main_Panel";
mainPanel = new CChartObjectRectLabel();
result = mainPanel.Create(
mChartHelper.ChartId(),
mainPanelName,
subWindow,
10,
25,
400,
200 //
);
if (!result)
{
return result;
}
//
// Styling Main Panel ...
mainPanel.BackColor(clrDarkGray);
mainPanel.Tooltip(mainPanelName);
//
// Create Buttons ...
buyButtonName = objSuffix + "BTN_BUY";
buyButton = new CChartObjectButton();
result = buyButton.Create(
mChartHelper.ChartId(),
buyButtonName,
subWindow,
10,
25,
200,
100 //
);
if (!result)
{
return result;
}
//
// Apply Style of Buy Button ...
if (result)
{
}
//
return result;
}
//////////////////////////////////////////////////
//
// class XCEdit : public CEdit {
// //
// public:
// //
// string mValue;
// //
// bool OnSetText() {
// //
// Print("Object Edit End ...");
// return true;
// }
// };
// CEdit edtPositionId;
// //
// // EDIT Position ID ...
// int edtPositionIdStartX = btnSellStartX;
// int edtPositionIdSizeX = edtPositionIdStartX + 100;
// int edtPositionIdStartY = btnSellSizeY + 5;
// int edtPositionIdSizeY = edtPositionIdStartY + 50;
// string edtPositionIdName = objSuffix + "EDT_POS_ID";
// result = edtPositionId.Create(
// chartId,
// edtPositionIdName,
// subWindow,
// edtPositionIdStartX,
// edtPositionIdStartY,
// edtPositionIdSizeX,
// edtPositionIdSizeY //
// );
// if (result)
// {
// //
// // Apply Edit Position ID Style ...
// edtPositionId.Text(ToXString(selectedPositionID));
// edtPositionId.TextAlign(ALIGN_LEFT);
// }
//////////////////////////////////////////////////////////////////
//
CButton btnPauseReplay;
bool isVisualTesterPaused = false;
//
// Initial Btn Pause Play ...
int subWindow = 0;
int defaultGap = 5;
int defaultWidth = 100;
int defaultHeight = 30;
ulong chartId = eaExpert.eaChartHelper.ChartId();
//
int btnPauseReplayX1 = defaultGap;
int btnPauseReplayX2 = btnPauseReplayX1 + defaultWidth;
int btnPauseReplayY1 = eaExpert.eaChartHelper.Height() - defaultHeight - defaultGap;
int btnPauseReplayY2 = btnPauseReplayY1 + defaultHeight;
//
string btnPauseReplayName = ShortName + "BTN_PAUSE_REPLAY";
//
isInited = btnPauseReplay.Create(
chartId,
btnPauseReplayName,
subWindow,
btnPauseReplayX1,
btnPauseReplayY1,
btnPauseReplayX2,
btnPauseReplayY2 //
);
if (isInited)
{
//
// Apply Style ...
string btnPauseReplayText =
isVisualTesterPaused
? "Play"
: "Pause";
btnPauseReplay.Text(btnPauseReplayText);
btnPauseReplay.Color(clrAzure);
btnPauseReplay.ColorBackground(clrBlack);
}
//
//
// Update btn Pause Replay ...
string btnPauseReplayText =
isVisualTesterPaused
? "Play"
: "Pause";
btnPauseReplay.Text(btnPauseReplayText);
if (IsRunningeOnTestVisualMode())
{
//
btnPauseReplay.Show();
btnPauseReplay.Enable();
}
else
{
//
btnPauseReplay.Hide();
btnPauseReplay.Enable();
}
if (btnPauseReplay.Pressed())
{
//
if (btnPauseReplay.IsEnabled())
{
//
HandlePauseStrategyTester();
//
btnPauseReplayText =
isVisualTesterPaused
? "Play"
: "Pause";
btnPauseReplay.Text(btnPauseReplayText);
}
//
btnPauseReplay.Pressed(false);
}
void HandlePauseStrategyTester()
{
//
isVisualTesterPaused = !isVisualTesterPaused;
//
// DebugBreak();
keybd_event(VK_SPACE, 0, 0, 0);
keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff