cleanup and backup old styles and try toimplement new POI Detector ...

This commit is contained in:
2024-11-11 14:06:29 -08:00
parent 051ff51800
commit d239d9c580
35 changed files with 15195 additions and 16227 deletions
+927
View File
@@ -0,0 +1,927 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCBaseExpert
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.x-alert.class.mq5"
#include "../Classes/x-saherelm.x-trade.class.mq5"
#include "../Helpers/x-saherelm.xcc.helper.mq5"
#include "../Helpers/x-saherelm.xct.helper.mq5"
//
// Definitions ...
string XCBaseExpertToken = "XCBaseEA";
//
// Inputs ...
//
// Implementations ...
class XCBaseExpert : public XCBaseAlert
{
//
public:
//
//
XCTrade *mTrader; // Trader of Expert Adviser ...
//
// Constructur(s) ...
void XCBaseExpert()
{
}
//
// Deconstructor ...
void ~XCBaseExpert()
{
}
//
// Getter(s) / Setter(s) ...
//
// Common ...
/**
* Get Magic Number ...
*
* @return ( long )
*/
long MagicNumber()
{
return mMagicNumber;
}
/**
* Set Magic Number ...
*
* @param value: Long ...
*/
void MagicNumber(long value)
{
mMagicNumber = value;
}
/**
* Get Slippage ...
*
* @return ( int )
*/
int Slippage()
{
return mSlippage;
}
/**
* Set Slippage ...
*
* @param value: Integer ...
*/
void Slippage(int value)
{
mSlippage = value;
}
/**
* Get Tag Prefix ...
*
* @return ( string )
*/
string TagPrefix()
{
return mTagPrefix;
}
/**
* Set Tag Prefix ...
*
* @param value: String ...
*/
void TagPrefix(string value)
{
mTagPrefix = value;
}
//
// Symbol ...
/**
* Get Period ...
*
* @return ( ENUM_TIMEFRAMES )
*/
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
/**
* Set Period ...
*
* @param value: ENUM_TIMEFRAMES member ...
*/
void SetPeriod(ENUM_TIMEFRAMES value)
{
mPeriod = value;
}
/**
* Get Symbol ...
*
* @return ( string )
*/
string GetSymbol()
{
return mSymbol;
}
/**
* Set Symbol ...
*
* @param value: String ...
*/
void SetSymbol(string value)
{
mSymbol = value;
}
/**
* Get Multi Symbol is Enable or Not ...
*
* @return ( bool )
*/
bool MultiSymbol()
{
return mMultiSymbol;
}
/**
* Set Multi Symbol is Enable or Not ...
*
* @param value: Boolean ...
*/
void MultiSymbol(bool value)
{
mMultiSymbol = value;
}
/**
* Get Multi Provided Symbols ...
*
* @return ( string )
*/
string Symbols()
{
return mSymbols;
}
/**
* Set Multi Provided Symbols ...
*
* @param value: String ...
*/
void Symbols(string value)
{
mSymbols = value;
}
//
// Signalling ...
/**
* Get Force Disable Signalling ...
*
* @return ( bool )
*/
bool Disabled()
{
return mDisabled;
}
/**
* Set Force Disable Signalling ...
*
* @param value: Boolean ...
*/
void Disabled(bool value)
{
mDisabled = value;
}
/**
* Get Allow Long Signals ...
*
* @return ( bool )
*/
bool AllowLong()
{
return mAllowLong;
}
/**
* Set Allow Long Signals ...
*
* @param value: Boolean ...
*/
void AllowLong(bool value)
{
mAllowLong = value;
}
/**
* Get Allow Short Signalling ...
*
* @return ( bool )
*/
bool AllowShort()
{
return mAllowShort;
}
/**
* Set Allow Short Signalling ...
*
* @param value: Boolean ...
*/
void AllowShort(bool value)
{
mAllowShort = value;
}
//
// Reports ...
/**
* Get Report New Month State ...
*
* @return ( bool )
*/
bool ReportNewMonths()
{
return mReportNewMonths;
}
/**
* Set Report New Month State ...
*
* @param value: Boolean ...
*/
void ReportNewMonths(bool value)
{
mReportNewMonths = value;
}
/**
* Get Report New Weeks State ...
*
* @return ( bool )
*/
bool ReportNewWeeks()
{
return mReportNewWeeks;
}
/**
* Set Report New Weeks State ...
*
* @param value: Boolean ...
*/
void ReportNewWeeks(bool value)
{
mReportNewWeeks = value;
}
/**
* Get Report New Days State ...
*
* @return ( bool )
*/
bool ReportNewDays()
{
return mReportNewDays;
}
/**
* Set Report New Days State ...
*
* @param value: Boolean ...
*/
void ReportNewDays(bool value)
{
mReportNewDays = value;
}
/**
* Get Report New Hours State ...
*
* @return ( bool )
*/
bool ReportNewHours()
{
return mReportNewHours;
}
/**
* Set Report New Hours State ...
*
* @param value: Boolean ...
*/
void ReportNewHours(bool value)
{
mReportNewHours = value;
}
//
// Actions ...
/**
* Handle Expert OnInit Event ...
*
* @return ( bool )
*/
bool HandleOnInit()
{
//
bool result = false;
//
string message = "";
//
// Validate Input ...
result = ValidateInputs();
if (!result)
{
//
message = "Invalid Inputs ....";
//
Alert(message);
}
//
// Initial All Requirements ...
result = InitEA();
if (!result)
{
return result;
}
//
// Initial All GUI Requirements ...
result = InitGUI();
if (!result)
{
return result;
}
//
message = "Initialized Successfully ...";
Alert(message);
//
return result;
}
/**
* Handle Expert OnDeInit Event ...
*/
void HandleOnDeInit()
{
//
// Destroy all GUI Requirements ...
DestroyGUI();
//
// Alert De Initialization Succeeded ...
string msg = "De Initialized Successfully ...";
Alert(msg);
//
// Destroy all EA Requirements ...
DestroyEA();
}
/**
* Handle Expert OnTick Event ...
*/
void HandleOnTick()
{
//
UpdateGUI();
HandleReportTime();
HandleStrategiesOnTick();
}
/**
* Handle Expert OnTrade Event ...
*/
void HandleOnTrade()
{
mTrader.HandleOnTrade();
}
/**
* Handle Expert OnTimer Event ...
*/
void HandleOnTimer()
{
}
/**
* Handle Expert OnChart Event ...
*/
void HandleOnChartEvent(
const int id,
const long &lparam,
const double &dparam,
const string &sparam //
)
{
}
//
// Virtual Actions ...
/**
* Apply Default Configurations ...
*/
virtual void DefaultConfigure()
{
//
// Commons ...
Slippage(10);
TagPrefix("");
MagicNumber(1694056);
//
// Symbol ...
SetSymbol(_Symbol);
SetPeriod(_Period);
MultiSymbol(false);
Symbols("EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb");
//
// Signalling ...
Disabled(false);
AllowLong(true);
AllowShort(true);
//
string tag = GetTag();
//
// Alert ...
SetAlertPrefix(tag);
SetAlertLogAlerts(true);
SetAlertPushAlerts(true);
SetAlertMailAlerts(false);
SetAlertEnableAlerts(true);
SetAlertTerminalAlerts(false);
//
// Reports ...
ReportNewDays(true);
ReportNewWeeks(false);
ReportNewHours(false);
ReportNewMonths(false);
}
/**
* Vaslidate Inputs ...
*
* @return ( virtual bool )
*/
virtual bool ValidateInputs()
{
//
bool result = false;
//
string errMessage = "";
//
bool isCommonValid = (
//
mSlippage > 0 &&
mMagicNumber > 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 ...
errMessage = " Errors: \n" + errMessage;
Alert(errMessage);
}
//
return result;
}
//
// Initializers and DeInitializers ...
/**
* Initial EA Requirements ...
*
* @return ( virtual bool )
*/
virtual bool InitEA()
{
//
bool result = false;
//
// Initialize Indicator Helpers ...
//
// Bar Timer ...
XCTInputs ctInputs;
ctInputs.Default(); // Default Configurations ...
mCTHelper = new XCXCTHelper();
result = mCTHelper.Init(
_Symbol,
_Period,
ctInputs //
);
if (!result)
{
return result;
}
//
// Bar Styles ...
XCCInputs ccInputs;
ccInputs.Default(); // Default Configurations ...
mCCHelper = new XCXCCHelper();
result = mCCHelper.Init(
_Symbol,
_Period,
ccInputs //
);
if (!result)
{
return result;
}
//
// Create Trader Instance and Configure it ...
mTrader = new XCTrade(
mSlippage,
mMagicNumber //
);
//
return result;
}
/**
* Destroy Initialized Requirements ...
*/
virtual void DestroyEA()
{
//
delete mCTHelper;
delete mCCHelper;
}
/**
* GUI Initialize if required ...
*
* @return ( virtual bool )
*/
virtual bool InitGUI()
{
//
bool result = false;
//
result = true;
//
return result;
}
/**
* Update All GUI Contents ...
*/
virtual void UpdateGUI()
{
}
/**
* Destroy all Initialized GUi Elements ...
*/
virtual void DestroyGUI()
{
}
//
// Event Handlers ...
/**
* Calls When a Position's SL Triggered ...
*
* @param deal: XDeal instance ...
*/
virtual void HandleOnStopLossTriggered(const XDeal &deal)
{
HandleReportBalance();
}
/**
* Calls When a Position's TP Triggered ...
*
* @param deal: XDeal instance ...
*/
virtual void HandleOnTakeProfitTriggered(const XDeal &deal)
{
HandleReportBalance();
}
/**
* Handle Force Close a Position ...
*
* @param ticket: Position Ticket ...
* @param position: XPosition ...
* @param comment: Closing Comment ...
*/
virtual void HandleOnPositionForceClosed(
const ulong ticket,
const XPosition &position,
const string comment //
)
{
HandleReportBalance();
}
/**
* Handle Position Modified ...
*
* @param ticket: ULONG ...
* @param profit: Double ...
* @param comment: String ...
*/
virtual void HandleOnPositionModified(
const ulong ticket,
const double profit,
const string comment //
)
{
}
/**
* Handle Position Partially Closed ...
*
* @param ticket: ULONG ...
* @param profit: Double ...
* @param comment: String ...
*/
virtual void HandleOnPositionPartialClosed(
const ulong ticket,
const double profit,
const string comment //
)
{
}
/**
* Do All Signalling Processing Here ...
*/
virtual void HandleStrategiesOnTick()
{
}
//
// Time Handlers ...
virtual void HandleOnNewMonth()
{
}
virtual void HandleOnNewWeek()
{
}
virtual void HandleOnNewDay()
{
}
virtual void HandleOnNewHour()
{
}
/**
* Generate Identifier Tag ...
*
* @return ( virtual string )
*/
virtual string GetTag()
{
//
string result = NULL;
//
string tagPrefix = TagPrefix();
if (IsValid(tagPrefix))
{
result = tagPrefix;
}
else
{
result = "";
}
//
result =
XCBaseExpertToken + result;
//
return result;
}
//
protected:
//
//
// Props ...
//
XTimeTracker mTimeTracker; // Time Tracker for Providing Reports ...
XCXCTHelper *mCTHelper; // Bar Timer Indicator Helper class ...
XCXCCHelper *mCCHelper; // Chart Styler Indicator Helper Class ...
//
// Actions ...
/**
* Report Account Balance ...
*/
void HandleReportBalance()
{
//
if (!IsRunningOnTestMode())
{
return;
}
//
string msg = "Balance: " + ToString(mTrader.mAccount.GetBalance());
Log(msg);
}
/**
* Time Reporting based on Inputs ...
*/
void HandleReportTime()
{
//
// Monthly Report ....
if (mTimeTracker.IsNewMonth())
{
//
HandleOnNewMonth();
//
if (mReportNewMonths)
{
//
string msg = "New Month ...";
//
Alert(msg);
}
}
//
// Weekly Report ....
if (mTimeTracker.IsNewWeek())
{
//
HandleOnNewWeek();
//
if (mReportNewWeeks)
{
//
string msg = "New Week ...";
//
Alert(msg);
}
}
//
// Daily Report ....
if (mTimeTracker.IsNewDay())
{
//
HandleOnNewDay();
//
if (mReportNewDays)
{
//
string msg = "New Day ...";
//
Alert(msg);
}
}
//
// Hourly Report ....
if (mTimeTracker.IsNewHour())
{
//
HandleOnNewHour();
//
if (mReportNewHours)
{
//
string msg = "New Hour ...";
//
Alert(msg);
}
}
}
//
private:
//
//
// Props ...
//
// Common ...
long mMagicNumber; // Magic Number ...
int mSlippage; // Slippage ...
string mTagPrefix; // Tag Prefix ...
//
// Symbol ...
ENUM_TIMEFRAMES mPeriod; // Period ...
string mSymbol; // Symbol ...
bool mMultiSymbol; // Multi Symbol is Enable or Not ...
string mSymbols; // Multi Provided Symbols ...
//
// Signalling ...
bool mDisabled; // Force Disable Signalling ...
bool mAllowLong; // Allow Long Signals ...
bool mAllowShort; // Allow Short Signals ...
//
// Reports ...
bool mReportNewMonths; // Report New Month ...
bool mReportNewWeeks; // Report New Weeks ...
bool mReportNewDays; // Report New Days ...
bool mReportNewHours; // Report New Hours ...
//
};
//