last ...
This commit is contained in:
@@ -110,6 +110,12 @@ class XCXCATBEASignaller : XCBase
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Signalling Methods ...
|
||||
bool allowSignallingBasedOnConditions; // Signalling and Entry based on Market Conditions ...
|
||||
bool allowSignallingBasedOnTriggerBlocks; // Signalling Based on Trigger Block Detection ...
|
||||
bool allowSignallingBasedOnTriggerBlocksInsideOther; // Signalling based on Trigger Blocks inside other Trigger Blocks ...
|
||||
|
||||
//
|
||||
bool allowDraws; // Allow Draws or not ...
|
||||
bool allowGuards; // Allow Guards or not ...
|
||||
@@ -126,7 +132,12 @@ class XCXCATBEASignaller : XCBase
|
||||
XTriggerBlockValidationRules validations; // Trigger Block Validations ...
|
||||
|
||||
//
|
||||
XBoxZone unavailableZones[]; // Un Available Zones ...
|
||||
XBoxZone cPeak; // Current Peak ...
|
||||
XBoxZone cVale; // Current Vale ...
|
||||
XBoxZone unavailableZones[]; // Un Available Zones ...
|
||||
XTriggerBlock cTriggerBlock; // Currently Selected Trigger Block ...
|
||||
XTriggerBlock triggerBlocks[]; // Founded Trigger Blocks ...
|
||||
XTriggerBlock cInsideTriggerBlock; // a TriggerBlock which Currently Selected Trigger Block is Inside it ...
|
||||
|
||||
//
|
||||
XCATBEAStrategyConditions mConditions;
|
||||
@@ -195,6 +206,8 @@ class XCXCATBEASignaller : XCBase
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
int barIndex = 0;
|
||||
cTriggerBlock.Clean();
|
||||
cInsideTriggerBlock.Clean();
|
||||
|
||||
//
|
||||
// Check Guards ...
|
||||
@@ -320,6 +333,42 @@ class XCXCATBEASignaller : XCBase
|
||||
drawer.Draw(bar.time);
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Blocks and Collect them ...
|
||||
XTriggerBlock iTriggerBlock;
|
||||
X121XCatbConditions iConditions;
|
||||
has = DetectTriggerBlock(
|
||||
helper,
|
||||
barAnalyser,
|
||||
iTriggerBlock,
|
||||
iConditions,
|
||||
validations,
|
||||
filters,
|
||||
barIndex,
|
||||
10 // Loopback ...
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Add Trigger Block to Collection if not Exists ...
|
||||
AddIfNotExists(
|
||||
iTriggerBlock,
|
||||
triggerBlocks //
|
||||
);
|
||||
}
|
||||
iConditions.Clean();
|
||||
iTriggerBlock.Clean();
|
||||
|
||||
//
|
||||
// Draw Trigger Blocks ...
|
||||
if (allowDraws)
|
||||
{
|
||||
//
|
||||
// Handle To Updating ...
|
||||
// datetime cTime = TimeCurrent();
|
||||
// DrawTriggerBlocks(cTime);
|
||||
}
|
||||
|
||||
//
|
||||
// Here we Check Active Session ...
|
||||
// and Prevent Moving forward if there is not
|
||||
@@ -372,93 +421,274 @@ class XCXCATBEASignaller : XCBase
|
||||
helper.Update(barIndex);
|
||||
|
||||
//
|
||||
// Trigger Block Detection ...
|
||||
result = DetectTriggerBlock(
|
||||
helper,
|
||||
barAnalyser,
|
||||
mConditions.triggerBlock,
|
||||
mConditions.conditions,
|
||||
validations,
|
||||
filters,
|
||||
barIndex,
|
||||
10 // Loopback ...
|
||||
);
|
||||
if (result)
|
||||
// Detect Signal Setup Based on Market Conditions ...
|
||||
if (!result &&
|
||||
allowSignallingBasedOnConditions)
|
||||
{
|
||||
//
|
||||
// Prepare Condition ...
|
||||
|
||||
//
|
||||
// Prepare Signal ...
|
||||
mConditions.dir =
|
||||
mConditions
|
||||
.triggerBlock
|
||||
.GetDirection();
|
||||
mConditions.symbol = symbol;
|
||||
mConditions.period = period;
|
||||
mConditions.provider = provider;
|
||||
mConditions.reward = riskToRewardRatio;
|
||||
mConditions.time = mConditions.conditions.bars[0].time;
|
||||
mConditions.setupTime = mConditions.conditions.bars[0].time;
|
||||
|
||||
//
|
||||
// Prepare Target ...
|
||||
double targets[];
|
||||
for (int i = 1; i <= riskToRewardRatio; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(double)i,
|
||||
targets //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate SL Additions ...
|
||||
double iATR = 0;
|
||||
if (barIndex > 0 &&
|
||||
barIndex < ArraySize(helper.atrBuffer))
|
||||
{
|
||||
iATR = helper.atrBuffer[barIndex];
|
||||
}
|
||||
double slAdditional = slATRMultiplier * iATR;
|
||||
|
||||
//
|
||||
// Preparing Signal ...
|
||||
result = ToSignal(
|
||||
mConditions.triggerBlock.trigger,
|
||||
mConditions.triggerBlock.signal,
|
||||
targets,
|
||||
slAdditional //
|
||||
// Detect Signalling Zone ...
|
||||
result = DetectSignalZone(
|
||||
helper,
|
||||
barAnalyser,
|
||||
mConditions.conditions,
|
||||
mConditions.pivotZone,
|
||||
barIndex,
|
||||
10 // Loopback ...
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mConditions.triggerBlock.signal.provider = provider;
|
||||
mConditions.sl = mConditions.triggerBlock.signal.sl;
|
||||
mConditions.tp = mConditions.triggerBlock.signal.tp;
|
||||
mConditions.pivot = mConditions.triggerBlock.signal.sl;
|
||||
mConditions.entry = mConditions.triggerBlock.signal.entry;
|
||||
mConditions.point = mConditions.triggerBlock.signal.entry;
|
||||
mConditions.type = ToPositionType(mConditions.triggerBlock.signal.type);
|
||||
// Filling Conditions of Strategy ...
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Signal Setup Based on Trigger Block Detection ...
|
||||
if (!result &&
|
||||
allowSignallingBasedOnTriggerBlocks)
|
||||
{
|
||||
//
|
||||
// Detect Trigger Block ...
|
||||
result = DetectTriggerBlock(
|
||||
helper,
|
||||
barAnalyser,
|
||||
mConditions.triggerBlock,
|
||||
mConditions.conditions,
|
||||
validations,
|
||||
filters,
|
||||
barIndex,
|
||||
10 // Loopback ...
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Use Trigger Block ...
|
||||
UseTriggerBlock(mConditions.triggerBlock);
|
||||
|
||||
//
|
||||
// Draw Trigger Block ...
|
||||
if (allowDraws)
|
||||
// Prepare Condition ...
|
||||
|
||||
//
|
||||
// Prepare Signal ...
|
||||
mConditions.dir =
|
||||
mConditions
|
||||
.triggerBlock
|
||||
.GetDirection();
|
||||
mConditions.symbol = symbol;
|
||||
mConditions.period = period;
|
||||
mConditions.provider = provider;
|
||||
mConditions.reward = riskToRewardRatio;
|
||||
mConditions.time = mConditions.conditions.bars[0].time;
|
||||
mConditions.setupTime = mConditions.conditions.bars[0].time;
|
||||
|
||||
//
|
||||
// Prepare Target ...
|
||||
double targets[];
|
||||
for (int i = 1; i <= riskToRewardRatio; i++)
|
||||
{
|
||||
//
|
||||
DrawTriggerBlock(
|
||||
mConditions.triggerBlock,
|
||||
drawer.drawer,
|
||||
mObjects,
|
||||
NULL, // To ...
|
||||
false // Draw Signal ...
|
||||
Add(
|
||||
(double)i,
|
||||
targets //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate SL Additions ...
|
||||
double iATR = 0;
|
||||
if (barIndex > 0 &&
|
||||
barIndex < ArraySize(helper.atrBuffer))
|
||||
{
|
||||
iATR = helper.atrBuffer[barIndex];
|
||||
}
|
||||
double slAdditional = slATRMultiplier * iATR;
|
||||
|
||||
//
|
||||
// Preparing Signal ...
|
||||
result = ToSignal(
|
||||
mConditions.triggerBlock.trigger,
|
||||
mConditions.triggerBlock.signal,
|
||||
targets,
|
||||
slAdditional //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mConditions.triggerBlock.signal.provider = provider;
|
||||
mConditions.sl = mConditions.triggerBlock.signal.sl;
|
||||
mConditions.tp = mConditions.triggerBlock.signal.tp;
|
||||
mConditions.pivot = mConditions.triggerBlock.signal.sl;
|
||||
mConditions.entry = mConditions.triggerBlock.signal.entry;
|
||||
mConditions.point = mConditions.triggerBlock.signal.entry;
|
||||
mConditions.type = ToPositionType(mConditions.triggerBlock.signal.type);
|
||||
|
||||
//
|
||||
// Draw Trigger Block ...
|
||||
if (allowDraws)
|
||||
{
|
||||
//
|
||||
DrawTriggerBlock(
|
||||
mConditions.triggerBlock,
|
||||
drawer.drawer,
|
||||
mObjects,
|
||||
NULL, // To ...
|
||||
false // Draw Signal ...
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Signal Setup Based On Trigger Blocks Second Entry ...
|
||||
if (!result &&
|
||||
allowSignallingBasedOnTriggerBlocksInsideOther)
|
||||
{
|
||||
//
|
||||
// First We Hvae to Select Peak and Vale ...
|
||||
|
||||
//
|
||||
// Check Peak and Vale Exists ...
|
||||
int peakIDX = GetYoungest(detector.peakPivots);
|
||||
int valeIDX = GetYoungest(detector.valePivots);
|
||||
result = IsValidIndex(peakIDX) &&
|
||||
IsValidIndex(valeIDX);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
cPeak = detector.peakPivots[peakIDX];
|
||||
cVale = detector.valePivots[valeIDX];
|
||||
|
||||
//
|
||||
// Trigger Block Detection ...
|
||||
result = HasChild(triggerBlocks) &&
|
||||
ArraySize(triggerBlocks) > 1;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Check Newest Trigger Block ...
|
||||
int newestIDX = GetYoungest(triggerBlocks);
|
||||
result = IsValidIndex(newestIDX);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
cTriggerBlock = triggerBlocks[newestIDX];
|
||||
|
||||
//
|
||||
// Check Trigger Block is New ...
|
||||
int toIDX = cTriggerBlock.ToIndex() == 0;
|
||||
bool isNewest = toIDX == 0;
|
||||
if (isNewest)
|
||||
{
|
||||
//
|
||||
// Now we have to Check Newest Trigger Block Place ...
|
||||
int insideTBIDX = DetectInsideTriggerBlock(
|
||||
cTriggerBlock,
|
||||
cInsideTriggerBlock,
|
||||
triggerBlocks //
|
||||
);
|
||||
|
||||
//
|
||||
// Check InsideTB is Exists and Valid ...
|
||||
result =
|
||||
cInsideTriggerBlock.IsValid() &&
|
||||
IsValidIndex(insideTBIDX);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Remove Peak from Detector Collections ...
|
||||
// and Make it unavailable ...
|
||||
ArrayRemove(
|
||||
detector.peakPivots,
|
||||
peakIDX,
|
||||
1 //
|
||||
);
|
||||
AddRef(
|
||||
cPeak,
|
||||
unavailableZones //
|
||||
);
|
||||
|
||||
//
|
||||
// Remove Vale from Detector Collections ...
|
||||
// and Make it unavailable ...
|
||||
ArrayRemove(
|
||||
detector.peakPivots,
|
||||
peakIDX,
|
||||
1 //
|
||||
);
|
||||
AddRef(
|
||||
cVale,
|
||||
unavailableZones //
|
||||
);
|
||||
|
||||
//
|
||||
// Remove Selected Trigger Block ...
|
||||
// and Make it unavailable ...
|
||||
RemoveTriggerBlock(
|
||||
cTriggerBlock,
|
||||
triggerBlocks //
|
||||
);
|
||||
UseTriggerBlock(cTriggerBlock);
|
||||
|
||||
//
|
||||
// Remove Selected Inside Trigger Block ...
|
||||
// and Make it unavailable ...
|
||||
RemoveTriggerBlock(
|
||||
cInsideTriggerBlock,
|
||||
triggerBlocks //
|
||||
);
|
||||
UseTriggerBlock(cInsideTriggerBlock);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
unavailableZones,
|
||||
maxAllowedCollection //
|
||||
);
|
||||
|
||||
//
|
||||
// Draw Trigger Blocks if Allowed ...
|
||||
if (allowDraws)
|
||||
{
|
||||
//
|
||||
//
|
||||
// Draw Blocks ...
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
// mObjects.Clear();
|
||||
|
||||
//
|
||||
// Detected Block ...
|
||||
DrawTriggerBlock(
|
||||
cTriggerBlock,
|
||||
drawer.drawer,
|
||||
mObjects,
|
||||
cTime,
|
||||
false // Draw Signal ...
|
||||
);
|
||||
|
||||
//
|
||||
// Inside Block ...
|
||||
DrawTriggerBlock(
|
||||
cInsideTriggerBlock,
|
||||
drawer.drawer,
|
||||
mObjects,
|
||||
cTime,
|
||||
false // Draw Signal ...
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Print("Salam ...");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Signal Setup Exists or not ...
|
||||
result = mConditions.IsValid() &&
|
||||
mConditions.IsSetuped();
|
||||
|
||||
@@ -617,6 +847,14 @@ class XCXCATBEASignaller : XCBase
|
||||
*/
|
||||
void Init(XCATBEASignallerInputs &inputs)
|
||||
{
|
||||
//
|
||||
maxAllowedCollection = 50;
|
||||
|
||||
//
|
||||
allowSignallingBasedOnConditions = false;
|
||||
allowSignallingBasedOnTriggerBlocks = true;
|
||||
allowSignallingBasedOnTriggerBlocksInsideOther = false;
|
||||
|
||||
//
|
||||
bool has = inputs.IsValid();
|
||||
if (!has)
|
||||
@@ -714,12 +952,16 @@ class XCXCATBEASignaller : XCBase
|
||||
* @return ( int )
|
||||
*/
|
||||
int AddConditionsIfNotExists(
|
||||
int maxAllowed = 10 //
|
||||
int maxAllowed = 50 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
maxAllowed = maxAllowedCollection;
|
||||
|
||||
//
|
||||
bool isSetuped = IsValid(mConditions.setupTime) &&
|
||||
HasDirection(mConditions.dir);
|
||||
@@ -788,6 +1030,178 @@ class XCXCATBEASignaller : XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add TriggerBlock if not Exists
|
||||
* inside a Collection ...
|
||||
*/
|
||||
int AddIfNotExists(
|
||||
XTriggerBlock &tb,
|
||||
XTriggerBlock &tbs[],
|
||||
int maxAllowed = 50 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
maxAllowed = maxAllowedCollection;
|
||||
|
||||
//
|
||||
// First Validate ...
|
||||
if (!tb.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Exists ...
|
||||
// and prevent moving forward if exists ...
|
||||
int idx = -1;
|
||||
bool isExists = FindTriggerBlockIndex(
|
||||
idx,
|
||||
tb,
|
||||
tbs //
|
||||
);
|
||||
result = !isExists;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Add if not Exists ...
|
||||
AddRef(
|
||||
tb,
|
||||
tbs //
|
||||
);
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
CleanupArray(
|
||||
tbs,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
result = ArraySize(tbs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use Specified Trigger Block and Make it Un Available ...
|
||||
*
|
||||
* @param tb: XTriggerBlock instance reference, Specified Used Trigger Block ...
|
||||
*/
|
||||
void UseTriggerBlock(XTriggerBlock &tb)
|
||||
{
|
||||
//
|
||||
bool has = tb.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Trigger Box ...
|
||||
has = tb.trigger.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
tb.trigger,
|
||||
unavailableZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Order Block Box ...
|
||||
has = tb.ob.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
tb.ob,
|
||||
unavailableZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Fair Value Gap ...
|
||||
has = tb.fvg.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
tb.fvg,
|
||||
unavailableZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Following Liquidity ...
|
||||
has = tb.fLiquidity.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
tb.fLiquidity,
|
||||
unavailableZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Reversal Liquidity ...
|
||||
has = tb.rLiquidity.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
tb.rLiquidity,
|
||||
unavailableZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Cleaning Up ...
|
||||
CleanupArray(
|
||||
unavailableZones,
|
||||
maxAllowedCollection //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw Exists Trigger Blocks ...
|
||||
*/
|
||||
void DrawTriggerBlocks(datetime to = NULL)
|
||||
{
|
||||
//
|
||||
// Check Has Child of trigger Blocks ...
|
||||
bool has = HasChild(triggerBlocks);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through Blocks ...
|
||||
int count = ArraySize(triggerBlocks);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Draw Indexed Trigger Block ...
|
||||
DrawTriggerBlock(
|
||||
triggerBlocks[i],
|
||||
drawer.drawer,
|
||||
mObjects,
|
||||
to,
|
||||
false //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
@@ -797,6 +1211,7 @@ class XCXCATBEASignaller : XCBase
|
||||
string provider;
|
||||
CArrayObj *mObjects;
|
||||
ENUM_TIMEFRAMES period;
|
||||
int maxAllowedCollection; // Max Allowed Collection Items ...
|
||||
|
||||
//
|
||||
// Initialize and Configure POI Detector and Drawer ...
|
||||
|
||||
Reference in New Issue
Block a user