Add Support for Sar Changes Detection ...

This commit is contained in:
2024-12-10 01:38:29 +03:30
parent 812e468151
commit b5cec1f52a
4 changed files with 453 additions and 119 deletions
@@ -25,6 +25,9 @@
#include "../../Classes/x-saherelm.x-poi.class.mq5"
#include "../Libraries/x-121.smc.lib.mq5"
//
// Definitions ...
//
// Implementations ...
@@ -47,6 +50,7 @@ class XC121SMCCycleHelper : public XCBase
// Constructor(s) ...
XC121SMCCycleHelper()
{
Default();
}
//
@@ -59,6 +63,33 @@ class XC121SMCCycleHelper : public XCBase
//
// Getter/Setter(s) ...
/**
* Get Max llowed Changes to Save ...
*
* @return ( int )
*/
int MaxAllowedSavedChanges()
{
return mMaxAllowedSavedChanges;
}
/**
* Set Max llowed Changes to Save ...
*
* @param value: Integer ...
*/
void MaxAllowedSavedChanges(int value)
{
//
if (value < 10)
{
value = 10;
}
//
mMaxAllowedSavedChanges = value;
}
//
// Actions ...
@@ -627,6 +658,15 @@ class XC121SMCCycleHelper : public XCBase
//
// Virtuals ...
/**
* Set Default Properties Values ...
*/
virtual void Default()
{
//
MaxAllowedSavedChanges(50);
}
//
protected:
//
@@ -643,102 +683,69 @@ class XC121SMCCycleHelper : public XCBase
)
{
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
XOHCL changeBar;
int index =
barIndex <= 0
? 1
: barIndex;
bool isInited = false;
string symbol = GetSymbol();
//
// Retrieve Bar ...
XOHCL bar;
isInited = GetBar(bar, index);
bool isInited = GetBar(
changeBar,
index //
);
if (!isInited)
{
return;
}
//
// Retrieve Previous Bar ...
XOHCL pBar;
int pIndex = index + 1;
isInited = GetBar(pBar, pIndex);
if (!isInited)
{
return;
}
// Detect Sar Change ...
bool isSarSwitchedToBullish = conditions.x121Conditions.isSarSwitchedToBullish;
bool isSarSwitchedToBearish = conditions.x121Conditions.isSarSwitchedToBearish;
bool isSarChanged = isSarSwitchedToBullish ||
isSarSwitchedToBearish;
//
XTick xTick;
isInited = xTick.Init(symbol);
if (!isInited)
if (period == PERIOD_M1)
{
return;
//
if (isSarChanged)
{
//
XValueChange sarChanged;
//
datetime time = changeBar.time;
double after = conditions.x121Conditions.sarBuffer[1];
double before = conditions.x121Conditions.sarBuffer[2];
ENUM_X_DIRECTION dir =
isSarSwitchedToBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Initialize Model ...
isInited = sarChanged.Init(
before,
after,
dir,
time //
);
if (isInited)
{
//
isInited = AddSarChange(sarChanged);
if (isInited)
{
Print("Sar Switched ...");
}
}
}
}
//
bool isSarAttached =
bar.close > conditions.x121Conditions.sarBuffer[0];
if (isSarAttached)
{
Print("Sar Attached ...");
}
// //
// bool isSarBullish =
// conditions.x121Conditions.sarBuffer[index] < bar.low;
// bool isSarBullishPrev =
// conditions.x121Conditions.sarBuffer[pIndex] < pBar.low;
// //
// bool isSarBearish =
// conditions.x121Conditions.sarBuffer[index] > bar.high;
// bool isSarBearishPrev =
// conditions.x121Conditions.sarBuffer[pIndex] > pBar.high;
// //
// bool isSarSwitchedToBullish =
// isSarBullish &&
// !isSarBullishPrev &&
// isSarBearishPrev;
// //
// bool isSarSwitchedToBearish =
// isSarBearish &&
// !isSarBearishPrev &&
// isSarBullishPrev;
// //
// if (isSarSwitchedToBullish ||
// isSarSwitchedToBearish)
// {
// Print("Sar Switched ...");
// }
// //
// bool isSarBullish =
// conditions.x121Conditions.sarBuffer[1] < xTick.ask &&
// conditions.x121Conditions.sarBuffer[1] < xTick.bid &&
// conditions.x121Conditions.isSarBullish;
// //
// bool isSarBearish =
// conditions.x121Conditions.sarBuffer[1] > xTick.ask &&
// conditions.x121Conditions.sarBuffer[1] > xTick.bid &&
// conditions.x121Conditions.isSarBearish;
//
// Detect Sar Changes ...
// bool isSarChanged = (isSarBullish &&
// !isSarBearish) ||
// (isSarBearish &&
// !isSarBullish);
// if (isSarChanged)
// {
// Print("SarChaned");
// }
//
// Detect Peak Changes ...
@@ -752,6 +759,11 @@ class XC121SMCCycleHelper : public XCBase
// Props ...
XCBarAnalyser *mBarAnalyser;
//
// Change Holders ...
int mMaxAllowedSavedChanges; // Max llowed Changes to Save ...
XValueChange mSarChanges[]; // Holds Parabolic Sar Direction Changes ...
//
// Actions ...
@@ -854,4 +866,67 @@ class XC121SMCCycleHelper : public XCBase
//
return result;
}
//
// Change Values Actions ...
/**
* Count Saved Parabolic Sar Changes ...
*
* @return ( int )
*/
int CountSarChanges()
{
return ArraySize(mSarChanges);
}
/**
* Add Specified Parabolic Sar Changed Item ...
*
* @param value: XValueChange instance Reference ...
*
* @return ( bool )
*/
bool AddSarChange(XValueChange &value)
{
//
bool result = false;
//
result = value.IsValid();
if (!result)
{
return result;
}
//
int beforeCount = CountSarChanges();
//
AddIfNotExists(
value,
mSarChanges //
);
//
int afterCount = CountSarChanges();
//
result = afterCount == beforeCount + 1;
if (result)
{
//
// Cleaning Up Unused Items ...
int maxAllowed = MaxAllowedSavedChanges();
CleanupArray(
mSarChanges,
maxAllowed //
);
}
//
return result;
}
//
};