last ...
This commit is contained in:
@@ -402,20 +402,12 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
|
||||
//
|
||||
// Handle Partial Close Position if Reached TP 1.5 ...
|
||||
// iTarget.Clean();
|
||||
// iTarget.doRF = true;
|
||||
// iTarget.actingDistance = 10;
|
||||
// iTarget.volumeMultiplier = 0.5;
|
||||
// iTarget.target = isBullish ? entry + (1.8 * risk) : entry - (1.8 * risk);
|
||||
// // iTarget.tpValue = isBullish ? entry + (2.5 * risk) : entry - (2.5 * risk);
|
||||
// AddRef(iTarget, iTargets);
|
||||
|
||||
//
|
||||
// Reward 3 Target ...
|
||||
iTarget.Clean();
|
||||
iTarget.doRF = true;
|
||||
iTarget.actingDistance = 0;
|
||||
iTarget.target = isBullish ? entry + (3 * risk) : entry - (3 * risk);
|
||||
iTarget.doRF = false;
|
||||
iTarget.actingDistance = 5;
|
||||
iTarget.doRFOnEntry = false;
|
||||
iTarget.volumeMultiplier = 0.5;
|
||||
iTarget.target = isBullish ? entry + (4 * risk) : entry - (4 * risk);
|
||||
AddRef(iTarget, iTargets);
|
||||
|
||||
//
|
||||
@@ -432,58 +424,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
//
|
||||
// Here we Can Do Target Preparing if Signaller Restricted and
|
||||
// then ignore restrictions if required ...
|
||||
|
||||
// //
|
||||
// // Risk Free On Entry:
|
||||
// iTarget.Clean();
|
||||
// iTarget.doRF = true;
|
||||
// iTarget.actingDistance = 10 * _point; // (5 * spread) / _point;
|
||||
// iTarget.target = isBullish ? entry + risk : entry - risk; // isBullish ? entry + (2 * spread) : entry - (2 * spread);
|
||||
// AddRef(iTarget, iTargets);
|
||||
|
||||
// //
|
||||
// // Partial Close Position Half on TP 1 ...
|
||||
// // Increase Rewards to TP 3 ...
|
||||
// iTarget.Clean();
|
||||
// iTarget.actingDistance = 1;
|
||||
// iTarget.volumeMultiplier = 0.5;
|
||||
// iTarget.target = isBullish ? entry + risk : entry - risk;
|
||||
// iTarget.tpValue = isBullish ? entry + (2.5 * risk) : entry - (2.5 * risk);
|
||||
// AddRef(iTarget, iTargets);
|
||||
|
||||
// //
|
||||
// // Reset Restrictions ...
|
||||
// if (loosingTrades == 1)
|
||||
// {
|
||||
// ResetRestrictions();
|
||||
// }
|
||||
|
||||
//
|
||||
if (loosingTrades > 2)
|
||||
{
|
||||
//
|
||||
if (IsXValid(restUntil) && iBar.time > restUntil)
|
||||
{
|
||||
//
|
||||
WinTrade();
|
||||
restUntil = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
XOHCL rBar;
|
||||
bool has = rBar.Init(iZone.symbol, PERIOD_W1, 0);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
restUntil = rBar.NextAt(); // + PeriodSeconds(PERIOD_D1);
|
||||
Print("Rest Until: ", restUntil);
|
||||
}
|
||||
|
||||
//
|
||||
rBar.Clean();
|
||||
}
|
||||
}
|
||||
ResetRestrictions();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -537,9 +478,73 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
//
|
||||
SpecifiedClean(guards);
|
||||
|
||||
//
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Requirements ...
|
||||
XGuard iGuard;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Force Hedging ...
|
||||
bool forceHedging = (positionsCount >= 2);
|
||||
if (forceHedging)
|
||||
{
|
||||
//
|
||||
// Minimum Required Reward ...
|
||||
double minRequiredReward = 1.5;
|
||||
|
||||
//
|
||||
// Summarizing Risk and Reward of Collections ...
|
||||
double risk = 0;
|
||||
double reward = 0;
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
risk += positions[i].GetRisk() + positions[i].commission + (-1 * positions[i].swap);
|
||||
reward += positions[i].profit;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Can Hedge rops ...
|
||||
has = reward >= (risk * minRequiredReward);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iGuard.Clean();
|
||||
iGuard.force = true;
|
||||
iGuard.symbol = symbol;
|
||||
iGuard.period = period;
|
||||
iGuard.provider = name;
|
||||
iGuard.time = TimeCurrent();
|
||||
iGuard.action = X_GUARD_ACTION_HEDGE;
|
||||
|
||||
//
|
||||
// Validate Guard ...
|
||||
has = iGuard.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iGuard,
|
||||
guards //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(guards);
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
iGuard.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -581,11 +586,23 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
// dir //
|
||||
// );
|
||||
|
||||
//
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// result = Strategy3HasSignal(
|
||||
// bar,
|
||||
// zone,
|
||||
// targets,
|
||||
// dir //
|
||||
// );
|
||||
// }
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
result = Strategy3HasSignal(
|
||||
result = Strategy4HasSignal(
|
||||
bar,
|
||||
zone,
|
||||
targets,
|
||||
@@ -593,11 +610,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
// Print("Salam");
|
||||
}
|
||||
// //
|
||||
// if (result)
|
||||
// {
|
||||
// Print("Salam");
|
||||
// }
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1211,6 +1228,202 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Bar Has Signal Based on Strategy 4 ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Bar ...
|
||||
* @param zone: XBoxZone, reference to holds affected zone ...
|
||||
* @param targets: XTarget, reference to detected Signal's Targets collections ...
|
||||
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Strategy4HasSignal(
|
||||
XOHCL &bar,
|
||||
XBoxZone &zone,
|
||||
XTarget &targets[],
|
||||
ENUM_X_DIRECTION &dir //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
zone.Clean();
|
||||
XClean(targets);
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
XOHCL p2Bar;
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
// Read PBar ...
|
||||
result = bar.GetPreviousBar(pBar);
|
||||
result = result &&
|
||||
pBar.GetPreviousBar(p2Bar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Do ...
|
||||
// XFIMA Consolidation ...
|
||||
|
||||
//
|
||||
bool isConsolidation = fimaHelper.HasPVConsolidationZone(
|
||||
zone,
|
||||
pBar.Index(),
|
||||
true, // Force PV Break ...
|
||||
true // Force Has Sar Switch ...
|
||||
);
|
||||
|
||||
//
|
||||
isBullish =
|
||||
isConsolidation &&
|
||||
zone.IsBullish();
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isConsolidation &&
|
||||
zone.IsBearish();
|
||||
|
||||
//
|
||||
// Validate based on Bars Patterns ...
|
||||
|
||||
//
|
||||
// Reading pBar Patterns ...
|
||||
XPatternAnalysis pBarAnalysis;
|
||||
poiDetector.AnalyseBarPatterns(
|
||||
pBar,
|
||||
pBarAnalysis,
|
||||
structureConfig.barsAnalysisConfig //
|
||||
);
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
bool isPBarHasBullishPatterns =
|
||||
(bar.close > pBar.low ||
|
||||
bar.open > pBar.low) &&
|
||||
(
|
||||
//
|
||||
pBarAnalysis.IsPinned(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsEngulfed(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsMomentum(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsPiercing(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsSignalKey(X_DIRECTION_BULLISH)
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bool isPBarHasBearishPatterns =
|
||||
(bar.close < pBar.high ||
|
||||
bar.open < pBar.high) &&
|
||||
(
|
||||
//
|
||||
pBarAnalysis.IsPinned(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsEngulfed(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsMomentum(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsPiercing(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsSignalKey(X_DIRECTION_BEARISH)
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
isBullish =
|
||||
isBullish &&
|
||||
isPBarHasBullishPatterns &&
|
||||
!isPBarHasBearishPatterns;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isBearish &&
|
||||
isPBarHasBearishPatterns &&
|
||||
!isPBarHasBullishPatterns;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir = zone.dir;
|
||||
zone.to = bar.time;
|
||||
XPOIDrawConfig iConfig = structureDrawConfig.drawConfig;
|
||||
iConfig.zonesWidth = 3;
|
||||
iConfig.bullishColor = clrYellow;
|
||||
iConfig.bearishColor = clrDarkOrange;
|
||||
poiDrawer.DrawZone(zone, iConfig);
|
||||
Print("Consolidation");
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Zone ...
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// zone.Clean();
|
||||
// result = ToBox(
|
||||
// p2Bar,
|
||||
// zone,
|
||||
// dir,
|
||||
// X_BAR_PATTERN_PINNED //
|
||||
// );
|
||||
|
||||
//
|
||||
// Manage Stops ...
|
||||
if (result)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
result = zone.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Targets ...
|
||||
if (result)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zone.Clean();
|
||||
XClean(targets);
|
||||
dir = X_DIRECTION_NONE;
|
||||
}
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user