complete XCA Indicator, implements it's Helper and Add all Conditions, and also rename XSTRCCI tProject o XCAEA and only use XCA and XOSC inside it ...
This commit is contained in:
@@ -0,0 +1,611 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: XCXCAEASignaller ...
|
||||
// Description: Class for XCAEA Signaller ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm Class for XCAEA Signaller"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-cobject.class.mq5"
|
||||
#include "../Helpers/xcaea.helper.mq5"
|
||||
#include "../Libraries/xcaea.signaller.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
class XCXCAEASignaller : XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
bool useGuards;
|
||||
XCAEAInputs inputs;
|
||||
XBarTracker barTraker;
|
||||
XCXCAEAHelper *helper;
|
||||
bool continuesRFTillTarget;
|
||||
XCAEAStrategyConditions mConditions;
|
||||
XCAEAStrategyConditions mConditionsCollection[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCXCAEASignaller(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period //
|
||||
)
|
||||
{
|
||||
//
|
||||
symbol = _symbol;
|
||||
period = _period;
|
||||
Init();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCXCAEASignaller()
|
||||
{
|
||||
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 = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Check Bar Processing ...
|
||||
if (!barTraker.CanProcessBar())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL pPBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
result =
|
||||
result &&
|
||||
pBar.GetPreviousBar(pPBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
pPBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Setup Conditions ...
|
||||
XBoxZone signalBox;
|
||||
bool hasSignalBox = false;
|
||||
ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
XCAEAConditions conditions;
|
||||
hasSignalBox = DetectXCAEAConditions(
|
||||
conditions,
|
||||
signalBox,
|
||||
signalBoxDir,
|
||||
helper,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
|
||||
//
|
||||
isBullish = hasSignalBox &&
|
||||
IsBullish(signalBoxDir);
|
||||
|
||||
//
|
||||
isBearish = hasSignalBox &&
|
||||
IsBearish(signalBoxDir);
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Do What we Want ...
|
||||
barTraker.Waits();
|
||||
|
||||
//
|
||||
// Draw Signal Box ...
|
||||
XCBoxObject *iObj;
|
||||
bool isCreated = helper.poiDrawer.DrawBox(
|
||||
signalBox,
|
||||
iObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
mObjects.Add(iObj);
|
||||
ZeroMemory(iObj);
|
||||
|
||||
//
|
||||
Print("Signal Box ...");
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Conditions ...
|
||||
mConditions.symbol = symbol;
|
||||
mConditions.period = period;
|
||||
|
||||
//
|
||||
double spread = GetSpread(symbol);
|
||||
|
||||
//
|
||||
double entry =
|
||||
isBullish
|
||||
? signalBox.upper
|
||||
: signalBox.lower;
|
||||
|
||||
//
|
||||
double sl =
|
||||
isBullish
|
||||
? signalBox.lower
|
||||
: signalBox.upper;
|
||||
|
||||
//
|
||||
double risk =
|
||||
isBullish
|
||||
? entry - sl
|
||||
: sl - entry;
|
||||
risk += spread;
|
||||
if (risk >= maxAllowedSLDistanceInPoint * points) {
|
||||
//
|
||||
// Fix Risk in Big Distances ...
|
||||
double hh5 = zBar.FindHighest(5, MODE_HIGH);
|
||||
double ll5 = zBar.FindLowest(5, MODE_LOW);
|
||||
|
||||
//
|
||||
double hhll5Delta = hh5 - ll5;
|
||||
double riskDelta = hhll5Delta / 2;
|
||||
risk = riskDelta;
|
||||
}
|
||||
|
||||
//
|
||||
double rewardTP = risk * tpReward;
|
||||
|
||||
//
|
||||
double tp =
|
||||
isBullish
|
||||
? entry + rewardTP
|
||||
: entry - rewardTP;
|
||||
|
||||
//
|
||||
// Filling ...
|
||||
mConditions.sl = sl;
|
||||
mConditions.tp = tp;
|
||||
mConditions.pivot =
|
||||
isBullish
|
||||
? sl
|
||||
: entry;
|
||||
mConditions.point =
|
||||
isBullish
|
||||
? entry
|
||||
: sl;
|
||||
mConditions.dir = signalBoxDir;
|
||||
mConditions.provider = "XCAEA";
|
||||
mConditions.signalBox = signalBox;
|
||||
mConditions.setupTime = zBar.time;
|
||||
mConditions.conditions = conditions;
|
||||
|
||||
//
|
||||
// Select RF Rewards ...
|
||||
if (continuesRFTillTarget)
|
||||
{
|
||||
//
|
||||
double rfReward = 1;
|
||||
while (rfReward < tpReward)
|
||||
{
|
||||
//
|
||||
double rewardRF = risk * rfReward;
|
||||
double rfTP =
|
||||
isBullish
|
||||
? entry + rewardRF
|
||||
: entry - rewardRF;
|
||||
|
||||
//
|
||||
Add(
|
||||
rfTP,
|
||||
mConditions.targets //
|
||||
);
|
||||
|
||||
//
|
||||
rfReward++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resource ...
|
||||
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
pPBar.Clean();
|
||||
|
||||
//
|
||||
signalBox.Clean();
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Trigger Conditions for Specified Signal ...
|
||||
*
|
||||
* @param conditions: XCAEAStrategyConditions instance Reference, Specified Signal Conditions ...
|
||||
* @param maxAllowedSetupAge: specified Setup Age for Expiration (if bigger than Zero) ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectSignalTrigger(
|
||||
XCAEAStrategyConditions &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: XCAEAGuard 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(
|
||||
XCAEAGuard &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 ...
|
||||
XCAEAStrategyConditions tmpItems[];
|
||||
Copy(
|
||||
mConditionsCollection,
|
||||
tmpItems //
|
||||
);
|
||||
|
||||
//
|
||||
// Prese Item Data ...
|
||||
bool isBullish = IsBullish(mConditions.dir);
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCAEAStrategyConditions 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()
|
||||
{
|
||||
//
|
||||
useGuards = false;
|
||||
continuesRFTillTarget = true;
|
||||
|
||||
//
|
||||
barTraker.Init(
|
||||
symbol,
|
||||
period //
|
||||
);
|
||||
|
||||
//
|
||||
inputs.Default();
|
||||
|
||||
//
|
||||
// Configure Indicators ...
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
inputs.ccInputs.showCandles = true;
|
||||
|
||||
//
|
||||
// XCT ...
|
||||
inputs.ctInputs.showCandleTime = true;
|
||||
|
||||
//
|
||||
// XCA ...
|
||||
|
||||
//
|
||||
inputs.caInputs.supResSmoothingLength = 7;
|
||||
inputs.caInputs.supResSmoothingMode = X_MA_MODE_NONE;
|
||||
|
||||
//
|
||||
inputs.caInputs.showKI = true;
|
||||
inputs.caInputs.showSar = true;
|
||||
inputs.caInputs.showTrend = true;
|
||||
inputs.caInputs.showSwings = false;
|
||||
inputs.caInputs.showLongCycle = false;
|
||||
inputs.caInputs.showHindCycle = false;
|
||||
inputs.caInputs.showFiboLevel1 = false;
|
||||
inputs.caInputs.showFiboLevel2 = false;
|
||||
inputs.caInputs.showFiboLevel3 = false;
|
||||
inputs.caInputs.showShortCycle = false;
|
||||
inputs.caInputs.showMediumCycle = false;
|
||||
inputs.caInputs.showPeaksAndVales = true;
|
||||
inputs.caInputs.showPeakAndValeGolden = true;
|
||||
inputs.caInputs.showSupportAndResistance = 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;
|
||||
|
||||
//
|
||||
// XCAEA Helper ...
|
||||
helper = new XCXCAEAHelper();
|
||||
helper.Init(
|
||||
symbol,
|
||||
period,
|
||||
inputs //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* DeInitialize ...
|
||||
*/
|
||||
void DeInit()
|
||||
{
|
||||
//
|
||||
inputs.Clean();
|
||||
ZeroMemory(helper);
|
||||
|
||||
//
|
||||
mConditions.Clean();
|
||||
Clean(mConditionsCollection);
|
||||
|
||||
//
|
||||
mObjects.Clear();
|
||||
mBarObjects.Clear();
|
||||
|
||||
//
|
||||
barTraker.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user