last ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,354 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXTestSetupEA
|
||||
// Description: provides implementation of XTest
|
||||
// Setup EA ...
|
||||
//
|
||||
//
|
||||
// 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 "../Test/x-saherelm.test.setup.mq5"
|
||||
#include "../Classes/x-saherelm.xea.class.mq5"
|
||||
|
||||
//
|
||||
class XSCXTestSetupEA : public XSCBaseEA
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXTestSetupEA(
|
||||
//
|
||||
// XTrade Class Requirements ...
|
||||
int slippage, // Specify Slippage
|
||||
ulong magicNumber, // Specify Magic Number
|
||||
//
|
||||
// XSCTrade Event Handlers ...
|
||||
TOnSignal onSignal = NULL, // On Signal Recieved Event Handler
|
||||
TOnModify onModifyPosition = NULL, // On Modify Position Event Handler
|
||||
TOnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
|
||||
TOnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
|
||||
TOnForceClose onForceClosePosition = NULL, // On Force Close Position Event Handler
|
||||
TOnPartialClose onPartialClosePosition = NULL, // On Partial Close Position Event Handler
|
||||
TOnDealsChanged onDealsChangedHandler = NULL, // On Deals Changed Event Handler
|
||||
TOnOrdersChanged onOrdersChangedHandler = NULL, // On Orders Changed Event Handler
|
||||
TOnPositionsChanged onPositionsChangedHandler = NULL, // On Positions Changed Event Handler
|
||||
TOnTradeStateChanged onTradeStateChangedHandler = NULL // On Trade State Changed Event Handler
|
||||
) : XSCBaseEA(slippage,
|
||||
magicNumber,
|
||||
onSignal,
|
||||
onModifyPosition,
|
||||
onStopLossTriggered,
|
||||
onTakeProfitTriggered,
|
||||
onForceClosePosition,
|
||||
onPartialClosePosition,
|
||||
onDealsChangedHandler,
|
||||
onOrdersChangedHandler,
|
||||
onPositionsChangedHandler,
|
||||
onTradeStateChangedHandler //
|
||||
)
|
||||
{
|
||||
//
|
||||
DefaultConfig();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXTestSetupEA() {}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
double Volume()
|
||||
{
|
||||
return mVolume;
|
||||
}
|
||||
|
||||
//
|
||||
void Volume(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0.01)
|
||||
{
|
||||
value = 0.01;
|
||||
}
|
||||
|
||||
//
|
||||
mVolume = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool AllowLong()
|
||||
{
|
||||
return mAllowLong;
|
||||
}
|
||||
|
||||
//
|
||||
void AllowLong(bool value)
|
||||
{
|
||||
mAllowLong = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool AllowShort()
|
||||
{
|
||||
return mAllowShort;
|
||||
}
|
||||
|
||||
//
|
||||
void AllowShort(bool value)
|
||||
{
|
||||
mAllowShort = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Add Setup ...
|
||||
bool AddSetup(XSCXTestSetup *setup)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = setup != NULL;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Add(
|
||||
setup,
|
||||
setups //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
//
|
||||
// Customize Token ...
|
||||
string GetToken() override
|
||||
{
|
||||
return GetSpecificToken(this);
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag() override
|
||||
{
|
||||
return this.GetToken();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Provider for any Guards ...
|
||||
bool CheckForGuard(XGuard &guards[]) override
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Request Fro Signals ...
|
||||
int RequestForSignal(
|
||||
XSignal &signals[] // Holds Signals ...
|
||||
) override
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = CountSetups();
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XTestConditions iConditions;
|
||||
bool iHasConditions = setups[i].GetConditions(
|
||||
iConditions,
|
||||
0,
|
||||
5 //
|
||||
);
|
||||
if (!iHasConditions)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check iConditions Signal is Valid or not ...
|
||||
bool hasSignal = iConditions.signal.IsValid();
|
||||
if (!hasSignal)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isLong = IsLong(iConditions.signal.type);
|
||||
|
||||
//
|
||||
// TODO: Implement Management ...
|
||||
|
||||
//
|
||||
AddRef(
|
||||
iConditions.signal,
|
||||
signals //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(signals);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
bool mVolume;
|
||||
bool mAllowLong;
|
||||
bool mAllowShort;
|
||||
|
||||
//
|
||||
void DefaultConfig()
|
||||
{
|
||||
//
|
||||
Volume(0.01);
|
||||
AllowLong(true);
|
||||
AllowShort(true);
|
||||
}
|
||||
|
||||
//
|
||||
// Provider(s) ...
|
||||
|
||||
//
|
||||
XSCXTestSetup *setups[];
|
||||
|
||||
//
|
||||
int CountSetups()
|
||||
{
|
||||
return ArraySize(setups);
|
||||
}
|
||||
|
||||
//
|
||||
int FindSetupIndex(
|
||||
string _symbol //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid(_symbol))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = CountSetups();
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
bool isOwn = _symbol == setups[i].GetSymbol();
|
||||
if (isOwn)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int FindSetupIndex(
|
||||
string _symbol, //
|
||||
ENUM_TIMEFRAMES _period //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid(_symbol))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsValid(_period))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = CountSetups();
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
bool isOwn =
|
||||
_symbol == setups[i].GetSymbol() &&
|
||||
_period == setups[i].GetPeriod();
|
||||
if (isOwn)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user