last works on XOSCS ...
This commit is contained in:
+1393
-22
File diff suppressed because it is too large
Load Diff
@@ -22,8 +22,400 @@
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-trade.lib.mq5"
|
||||
|
||||
//
|
||||
// Enumeration ...
|
||||
|
||||
//
|
||||
// Guard Actions ...
|
||||
enum ENUM_GUARD_ACTIONS
|
||||
{
|
||||
X_GUARD_ACTION_NONE, // Nothing to Do
|
||||
X_GUARD_ACTION_CLOSE, // Close Specified Position
|
||||
X_GUARD_ACTION_CLOSE_ALL, // Close All Positions
|
||||
X_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions
|
||||
X_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position
|
||||
X_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position
|
||||
X_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position
|
||||
X_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position
|
||||
X_GUARD_ACTION_HEDGE, // Hedge Specified Positions
|
||||
};
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Conditions Struct ...
|
||||
struct XSTRCCIStrategyConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
double sl;
|
||||
double tp;
|
||||
double pivot;
|
||||
double point;
|
||||
double sls[];
|
||||
string provider;
|
||||
double targets[];
|
||||
|
||||
//
|
||||
datetime time;
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
XBoxZone signalBox;
|
||||
ENUM_X_DIRECTION dir;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
ENUM_X_DIRECTION signalDir;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XSTRCCIStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
pivot = 0;
|
||||
point = 0;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
provider = NULL;
|
||||
|
||||
//
|
||||
time = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
Clean(sls);
|
||||
Clean(targets);
|
||||
|
||||
//
|
||||
signalBox.Clean();
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
signalDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period) &&
|
||||
IsSpecifiedValid(time);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bullish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBullishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(signalDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBullish(signalDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bearish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBearishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(signalDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBearish(signalDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Up and Triggering Up ...
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Setup Age ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetSetupAge()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsSetuped())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Model a Guard Action ...
|
||||
struct XSTRCCIGuard
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
ENUM_GUARD_ACTIONS action;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
string symbol;
|
||||
string provider;
|
||||
|
||||
//
|
||||
// Specified Position ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// Partial Close ...
|
||||
double volumeMultiplier;
|
||||
|
||||
//
|
||||
// SL Trial ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// TP Trial ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XSTRCCIGuard()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
time = NULL;
|
||||
action = X_GUARD_ACTION_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
provider = NULL;
|
||||
|
||||
//
|
||||
ticket = 0;
|
||||
|
||||
//
|
||||
volumeMultiplier = 0;
|
||||
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(time) &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(provider) &&
|
||||
action != X_GUARD_ACTION_NONE
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Model Based On Specified Guard Actions ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add Guard to Collection ...
|
||||
*
|
||||
* @param guard: XSTRCCIGuard instance ...
|
||||
* @param guards: XSTRCCIGuard instance Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int AddGuard(
|
||||
XSTRCCIGuard &guard,
|
||||
XSTRCCIGuard &guards[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!guard.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
guard,
|
||||
guards //
|
||||
);
|
||||
|
||||
//
|
||||
result = ArraySize(guards);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -22,6 +22,7 @@
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-cobject.class.mq5"
|
||||
#include "../Helpers/xstrcci.helper.mq5"
|
||||
#include "../Libraries/xstrcci.signaller.lib.mq5"
|
||||
|
||||
@@ -35,25 +36,340 @@ class XCXSTRCCISignaller : XCBase
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
bool useGuards;
|
||||
double rfReward;
|
||||
bool isPassedBoxes;
|
||||
XSTRCCIInputs inputs;
|
||||
XCXSTRCCIHelper *helper;
|
||||
bool continuesRFTillTarget;
|
||||
XSTRCCIStrategyConditions mConditions;
|
||||
XSTRCCIStrategyConditions mConditionsCollection[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCXSTRCCISignaller()
|
||||
XCXSTRCCISignaller(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period //
|
||||
)
|
||||
{
|
||||
//
|
||||
symbol = _symbol;
|
||||
period = _period;
|
||||
Init();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCXSTRCCISignaller()
|
||||
{
|
||||
DeInit();
|
||||
}
|
||||
|
||||
//
|
||||
// Properties ...
|
||||
|
||||
string GetSymbol()
|
||||
{
|
||||
return symbol;
|
||||
}
|
||||
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return period;
|
||||
}
|
||||
|
||||
//
|
||||
// Signaller Tools ...
|
||||
|
||||
/**
|
||||
* Detect Setup Conditions based on Signalling ...
|
||||
*
|
||||
* @param maxAllowedSLDistanceInPoint: int, Max Allowed SL Distance in Points (if Bigger thn Zero Provided) ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectSignalSetup(
|
||||
double tpReward = 3,
|
||||
double maxAllowedSLDistanceInPoint = 300 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Trigger Conditions for Specified Signal ...
|
||||
*
|
||||
* @param conditions: XSTRCCIStrategyConditions instance Reference, Specified Signal Conditions ...
|
||||
* @param maxAllowedSetupAge: specified Setup Age for Expiration (if bigger than Zero) ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectSignalTrigger(
|
||||
XSTRCCIStrategyConditions &conditions,
|
||||
int maxAllowedSetupAge = 60 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = conditions.IsSetuped();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime setupTime = conditions.setupTime;
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(setupDir);
|
||||
bool isBearish = IsBearish(setupDir);
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
double points = GetPoints(symbol);
|
||||
|
||||
//
|
||||
// Check Signal Validation ...
|
||||
// IMPORTANT: since all Validations done in SetUp Process ...
|
||||
// here we only Execute Signal ...
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
conditions.triggerTime = cTime;
|
||||
conditions.type = isBullish
|
||||
? X_POSITION_TYPE_LONG
|
||||
: X_POSITION_TYPE_SHORT;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Guards bsed on Signalling Class ...
|
||||
*
|
||||
* @param guards: XSTRCCIGuard instance Collection, Holds Provided Guards ...
|
||||
* @param positions: XPosition instance Collection, Provides Signalling Based Positions for Apply Guards on them ...
|
||||
* @param provider: X121SMCStrategySignalProviderData instance Reference, Specified Data for Cycles ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectGuards(
|
||||
XSTRCCIGuard &guards[],
|
||||
const XPosition &positions[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Conditions to Conditions Collection if not Exists ...
|
||||
*
|
||||
* @param maxAllowed: int, Specified Max Allowed Holding Conditions ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int AddConditionsIfNotExists(
|
||||
int maxAllowed = 10 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
bool isSetuped = IsValid(mConditions.setupTime) &&
|
||||
HasDirection(mConditions.dir);
|
||||
if (!isSetuped)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(mConditionsCollection);
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
// Copy Original Items ...
|
||||
XSTRCCIStrategyConditions tmpItems[];
|
||||
Copy(
|
||||
mConditionsCollection,
|
||||
tmpItems //
|
||||
);
|
||||
|
||||
//
|
||||
// Prese Item Data ...
|
||||
bool isBullish = IsBullish(mConditions.dir);
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XSTRCCIStrategyConditions iItem = tmpItems[i];
|
||||
|
||||
//
|
||||
bool canRemove = mConditions.dir == iItem.dir &&
|
||||
mConditions.pivot == iItem.pivot;
|
||||
if (canRemove)
|
||||
{
|
||||
//
|
||||
ArrayRemove(
|
||||
mConditionsCollection,
|
||||
i,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpItems);
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
mConditions,
|
||||
mConditionsCollection //
|
||||
);
|
||||
|
||||
//
|
||||
// Remove Olds ...
|
||||
CleanupArray(
|
||||
mConditionsCollection,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
result = ArraySize(mConditionsCollection);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
CArrayObj mObjects;
|
||||
CArrayObj mBarObjects;
|
||||
|
||||
/**
|
||||
* Initialize ...
|
||||
*/
|
||||
void Init()
|
||||
{
|
||||
//
|
||||
rfReward = 2;
|
||||
useGuards = false;
|
||||
isPassedBoxes = false;
|
||||
continuesRFTillTarget = true;
|
||||
|
||||
//
|
||||
inputs.Default();
|
||||
|
||||
//
|
||||
// Configure Indicators ...
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
inputs.ccInputs.showCandles = true;
|
||||
|
||||
//
|
||||
// XCT ...
|
||||
inputs.ctInputs.showCandleTime = true;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
inputs.strInputs.showStr = true;
|
||||
inputs.strInputs.showVidya = true;
|
||||
inputs.strInputs.showStrUpper = false;
|
||||
inputs.strInputs.showStrLower = false;
|
||||
inputs.strInputs.showStrSMLow = true;
|
||||
inputs.strInputs.showStrSMHigh = true;
|
||||
|
||||
//
|
||||
// XOSCS ...
|
||||
inputs.oscsInputs.rsiLength = 5;
|
||||
inputs.oscsInputs.mfiLength = 5;
|
||||
inputs.oscsInputs.rviLength = 5;
|
||||
inputs.oscsInputs.cciLength = 5;
|
||||
|
||||
//
|
||||
// Oscillators Views ...
|
||||
inputs.showCCI = false;
|
||||
inputs.showRSI = false;
|
||||
inputs.showMFI = false;
|
||||
inputs.showRVI = false;
|
||||
inputs.showMACD = false;
|
||||
|
||||
//
|
||||
// XSTRCCI Helper ...
|
||||
helper = new XCXSTRCCIHelper();
|
||||
helper.Init(
|
||||
symbol,
|
||||
period,
|
||||
inputs //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* DeInitialize ...
|
||||
*/
|
||||
void DeInit()
|
||||
{
|
||||
//
|
||||
inputs.Clean();
|
||||
ZeroMemory(helper);
|
||||
|
||||
//
|
||||
mConditions.Clean();
|
||||
Clean(mConditionsCollection);
|
||||
|
||||
//
|
||||
mObjects.Clear();
|
||||
mBarObjects.Clear();
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user