Fix Spread Passing for Signalling and Conditions Processing ...

This commit is contained in:
2024-12-09 23:04:42 +03:30
parent 317e8b8ba3
commit 812e468151
7 changed files with 475 additions and 282 deletions
@@ -235,6 +235,60 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
mMaxAllowedSpread = value;
}
/**
* Get Min Required Ticks Verification for Spread Pass ...
*
* @return ( int )
*/
int MinRequiredTicksForSpreadPass()
{
return mMinRequiredTicksForSpreadPass;
}
/**
* Set Min Required Ticks Verification for Spread Pass ...
*
* @param value: Integer ...
*/
void MinRequiredTicksForSpreadPass(int value)
{
//
if (value < 100)
{
value = 100;
}
//
mMinRequiredTicksForSpreadPass = value;
}
/**
* Get Max Allowed Save Ticks ...
*
* @return ( int )
*/
int MaxAllowedSaveTicks()
{
return mMaxAllowedSaveTicks;
}
/**
* Set Max Allowed Save Ticks ...
*
* @param value: Integer ...
*/
void MaxAllowedSaveTicks(int value)
{
//
if (value < 150)
{
value = 150;
}
//
mMaxAllowedSaveTicks = value;
}
/**
* Get Long Signalling State ...
*
@@ -534,9 +588,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
bool result = false;
//
int length = 5;
double pointValue = GetPoints(mSymbol);
double maxAllowedSpread = MaxAllowedSpread();
int minRequiredTicksVerification = MinRequiredTicksForSpreadPass();
if (maxAllowedSpread > 0)
{
maxAllowedSpread *= pointValue;
@@ -546,193 +600,51 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
maxAllowedSpread = 0;
}
//
result = maxAllowedSpread <= 0
? true
: minRequiredTicksVerification > 0;
if (!result)
{
return result;
}
//
int ticksCount = ArraySize(mTicks);
if (ticksCount <= length)
{
return result;
}
//
int start = -1;
int end = -1;
CalculateTicksParams(
start,
end,
length + 1 //
);
result = IsValidIndex(start) &&
IsValidIndex(end);
result = ticksCount >= minRequiredTicksVerification;
if (!result)
{
return result;
}
//
end -= 1;
double spreadAVG = 0;
for (int i = start; i < end; i++)
{
spreadAVG += mTicks[i].spread;
}
spreadAVG /= length;
//
double lastSpread = mTicks[ticksCount - 1].spread;
//
result = lastSpread <= spreadAVG &&
(maxAllowedSpread <= 0
? true
: lastSpread <= maxAllowedSpread);
//
return result;
}
/**
* Check Ticks is Bullish or not ...
*
* @return ( bool )
*/
bool IsTicksBullish()
{
//
bool result = false;
//
int start = -1;
int end = -1;
int requiredBullishTicks = 5;
CalculateTicksParams(
start,
end,
requiredBullishTicks //
);
result = IsValidIndex(start) &&
IsValidIndex(end);
if (!result)
{
return result;
}
//
result = true;
for (int i = start + 1; i < end; i++)
if (maxAllowedSpread > 0)
{
//
XTick iTick = mTicks[i];
XTick prevTick = mTicks[i - 1];
//
bool isBullish = iTick.bid >= prevTick.bid;
result = result && isBullish;
if (!result)
{
break;
}
}
//
return result;
}
/**
* Check Ticks is Bearish or not ...
*
* @return ( bool )
*/
bool IsTicksBearish()
{
//
bool result = false;
//
int start = -1;
int end = -1;
int requiredBearishTicks = 5;
CalculateTicksParams(
start,
end,
requiredBearishTicks //
);
result = IsValidIndex(start) &&
IsValidIndex(end);
if (!result)
{
return result;
}
//
result = true;
for (int i = start + 1; i < end; i++)
{
//
XTick iTick = mTicks[i];
XTick prevTick = mTicks[i - 1];
//
bool isBearish = iTick.bid <= prevTick.bid;
result = result && isBearish;
if (!result)
{
break;
}
}
//
return result;
}
/**
* Check Ticks Has Momentum or not ...
*
* @return ( bool )
*/
bool IsTicksHasMomentum()
{
//
bool result = false;
//
int start = -1;
int end = -1;
int requiredTicksForMomentum = 5;
CalculateTicksParams(
start,
end,
requiredTicksForMomentum //
);
result = IsValidIndex(start) &&
IsValidIndex(end);
if (!result)
{
return result;
}
//
result = true;
int lastDiff = 0;
for (int i = start + 1; i < end; i++)
{
//
XTick iTick = mTicks[i];
XTick prevTick = mTicks[i - 1];
//
int timeDiff = MathAbs((int)iTick.time - (int)prevTick.bid);
if (lastDiff <= 0)
{
lastDiff = timeDiff;
}
result = result && timeDiff >= lastDiff;
if (!result)
{
break;
int end = -1;
int start = -1;
result = CalculateTicksParams(
start,
end,
minRequiredTicksVerification //
);
if (!result) {
return result;
}
//
lastDiff = timeDiff;
for (int i = start; i < end; i++)
{
//
XTick iTick = mTicks[i];
//
result = iTick.spread <= maxAllowedSpread;
if (!result)
{
break;
}
}
}
//
@@ -1475,14 +1387,18 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
// Props ...
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...
bool mForceDisabled; // Force Disabled ...
bool mAllowLong; // Allow Long Signals
bool mAllowShort; // Allow Short Signals
double mR2R; // Risk/Rewar Ratio ...
double mVolume; // Static Volume Per Trades ...
double mMaxAllowedSpread; // Max Allowed Spread ...
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...
bool mForceDisabled; // Force Disabled ...
bool mAllowLong; // Allow Long Signals
bool mAllowShort; // Allow Short Signals
double mR2R; // Risk/Rewar Ratio ...
double mVolume; // Static Volume Per Trades ...
//
double mMaxAllowedSpread; // Max Allowed Spread ...
int mMinRequiredTicksForSpreadPass; // Min Required Ticks Verification for Spread Pass ...
int mMaxAllowedSaveTicks; // Max Allowed Save Ticks ...
//
long mChartID; // Chart ID ...
@@ -1506,6 +1422,8 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
//
R2R(1);
Volume(0.01);
MaxAllowedSaveTicks(150);
MinRequiredTicksForSpreadPass(100);
//
ChartIdentification(0);
@@ -1598,7 +1516,6 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
mVisionDetector.MaxNumberOfRequiredPOIs(poiRequired);
mVisionDetector.Init();
//
}
@@ -1636,7 +1553,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
void CleanupTicks()
{
//
int maxRequiredTicks = 50;
int maxRequiredTicks = MaxAllowedSaveTicks();
int ticksCount = ArraySize(mTicks);
if (!IsValidSize(ticksCount) ||
ticksCount <= maxRequiredTicks)
@@ -1686,12 +1603,15 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
* @param end: Integer Reference to End ...
* @param numOfLastTicks: Integer Max Number of Required N Last Ticks ...
*/
void CalculateTicksParams(
bool CalculateTicksParams(
int &start,
int &end,
int numOfLastTicks = 5 //
)
{
//
bool result = 0;
//
start = -1;
end = -1;
@@ -1712,6 +1632,13 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
{
end = count;
}
//
result = IsValidIndex(start) &&
IsValidIndex(end);
//
return result;
}
//