add MQL5Test Workspace Content as BKP Solution ...
This commit is contained in:
@@ -0,0 +1,304 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCEABaseProvider
|
||||
// Description: provides base requirements for
|
||||
// Specific Sgnal Provider ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Notified a Signal was Appears ...
|
||||
typedef void (*OnSignal)(
|
||||
XSignal &signal);
|
||||
|
||||
//
|
||||
// Notified a Guard Appears ...
|
||||
typedef void (*OnGuard)(XGuard &guard);
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Base Class for All of our EA's ...
|
||||
class XSCEABaseProvider
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCEABaseProvider()
|
||||
{
|
||||
mSymbol = _Symbol;
|
||||
mPeriod = _Period;
|
||||
}
|
||||
void XSCEABaseProvider(
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mTag = mSymbol + "," + ToString(mPeriod);
|
||||
|
||||
//
|
||||
mIsInTestMode = IsRunningOnTestMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCEABaseProvider()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
bool CanIgnoreTick() {
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
bool result = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare State ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
mCanIgnoreTick = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
ProcessBuffers();
|
||||
|
||||
//
|
||||
if (mCanIgnoreTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
mWaitUntilNewCandle = false;
|
||||
|
||||
//
|
||||
ProcessTick();
|
||||
}
|
||||
|
||||
//
|
||||
virtual void PrepareTag();
|
||||
|
||||
//
|
||||
// Initialize Indicators and Requirements ...
|
||||
virtual bool Init();
|
||||
|
||||
//
|
||||
virtual int GetMaxLength();
|
||||
|
||||
//
|
||||
virtual int GetCalculatedBars();
|
||||
|
||||
//
|
||||
// Handle Update Buffers ...
|
||||
virtual void ProcessBuffers()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Tick Event ...
|
||||
virtual void ProcessTick()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Guards ...
|
||||
virtual bool GuardCheck(XGuard &guards[]);
|
||||
|
||||
//
|
||||
// Add Specific On Signal Event Handler ...
|
||||
int AddOnSignalEventHandler(OnSignal handler)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
mSignalEventHandlers,
|
||||
ArraySize(mSignalEventHandlers) + 1);
|
||||
|
||||
//
|
||||
int result = ArraySize(mSignalEventHandlers) - 1;
|
||||
mSignalEventHandlers[result] = handler;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove All On Signal Event Handler ...
|
||||
void ReoveOnSignalEventHandlers()
|
||||
{
|
||||
//
|
||||
ArrayFree(mSignalEventHandlers);
|
||||
}
|
||||
|
||||
//
|
||||
// Notify a Signal Found on all Event Listeners ...
|
||||
void NotifyOnSignalEvent(XSignal &info)
|
||||
{
|
||||
//
|
||||
int listenerCount = ArraySize(mSignalEventHandlers);
|
||||
if (listenerCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Listeners ...
|
||||
for (int i = 0; i < listenerCount; i++)
|
||||
{
|
||||
//
|
||||
OnSignal listener = mSignalEventHandlers[i];
|
||||
|
||||
//
|
||||
listener(info);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
string mTag;
|
||||
|
||||
//
|
||||
bool mIsNewCandle;
|
||||
bool mIsInTestMode;
|
||||
bool mCanIgnoreTick;
|
||||
bool mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Signal Event Handlers ...
|
||||
OnSignal mSignalEventHandlers[];
|
||||
};
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Model Signal Providers Definitions ...
|
||||
struct XBaseSignalProvider
|
||||
{
|
||||
//
|
||||
// Provider use Which Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Provider use Which Time Frame ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Risk Amount Per Trades Related to Time Frames ...
|
||||
// Percent of Available Balance ...
|
||||
double riskAmount;
|
||||
|
||||
//
|
||||
// Desired Magic Number ...
|
||||
ulong magicNumber;
|
||||
};
|
||||
|
||||
//
|
||||
struct XLastSignal
|
||||
{
|
||||
datetime at;
|
||||
string provider;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Add Specific Provider to List ...
|
||||
void Add(
|
||||
XBaseSignalProvider &item, // item want to add
|
||||
XBaseSignalProvider &buffer[] // Destination buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user