Implement Position Protector ...

need to test BE Hedge ...
This commit is contained in:
2024-09-18 21:13:23 +03:30
parent dbdbb3a276
commit 9393c9ecfe
7 changed files with 623 additions and 119 deletions
+145 -10
View File
@@ -5187,7 +5187,10 @@ struct XLinearRegressionWorkStruct
//
// Constructor ...
XLinearRegressionWorkStruct() : dataSize(-1), period(-1) {}
XLinearRegressionWorkStruct()
: dataSize(-1), period(-1)
{
}
};
//
@@ -7257,7 +7260,9 @@ bool CalculateTPSLByPrice(
return result;
}
//
/**
* Retrieve Current Tick ...
*/
bool GetTick(
string mSymbol,
MqlTick &tick //
@@ -7266,6 +7271,140 @@ bool GetTick(
return SymbolInfoTick(mSymbol, tick);
}
/**
* Retrieve Tick Entry ...
*/
double GetTickEnty(
MqlTick &mTick,
ENUM_POSITION_TYPE type,
string mSymbol = NULL //
)
{
//
double result = 0;
//
mSymbol = NormalizeSymbol(mSymbol);
//
result =
IsLong(type)
? mTick.ask
: mTick.bid;
result = NormalizePrice(result, mSymbol);
//
return result;
}
/**
* Retrieve Tick Exit ...
*/
double GetTickExit(
MqlTick &mTick,
ENUM_POSITION_TYPE type,
string mSymbol = NULL //
)
{
//
double result = 0;
//
mSymbol = NormalizeSymbol(mSymbol);
//
result =
IsLong(type)
? mTick.bid
: mTick.ask;
result = NormalizePrice(result, mSymbol);
//
return result;
}
/**
* Calculate Momentum Changes based on Given Price
*/
double CalculateMomentum(
double currentPrice,
double previousPrice //
)
{
//
double result = 0;
//
return result;
}
/**
* Detect Possible Momentum Changes
* Using MqlTick ...
*/
bool DetectMomentumChange(
ENUM_POSITION_TYPE type,
string mSymbol = NULL,
int mLength = 14 //
)
{
//
bool result = false;
//
mSymbol = NormalizeSymbol(mSymbol);
//
MqlTick ticks[];
int copied = CopyTicks(
mSymbol,
ticks,
COPY_TICKS_ALL,
0,
mLength + 1 //
);
//
result = copied > mLength;
if (!result)
{
return result;
}
//
double previousPrice = GetTickExit(
ticks[mLength],
type,
mSymbol //
);
for (int i = mLength - 1; i >= 0; i--)
{
//
double currentPrice = GetTickExit(
ticks[i],
type,
mSymbol //
);
//
double momentum = CalculateMomentum(
currentPrice,
previousPrice //
);
//
if (fabs(momentum) > 1.0)
{
//
result = true;
break;
}
}
//
return result;
}
//
// Symbols ...
@@ -8261,8 +8400,7 @@ double MAOnArray(
{
//
// Mode SMA ...
case MODE_SMA:
{
case MODE_SMA: {
//
total = ArrayCopy(arr, array, 0, shift + ma_shift, period);
if (ArrayResize(buf, total) < 0)
@@ -8295,8 +8433,7 @@ double MAOnArray(
//
// Mode EMA ...
case MODE_EMA:
{
case MODE_EMA: {
//
if (ArrayResize(buf, total) < 0)
{
@@ -8328,8 +8465,7 @@ double MAOnArray(
//
// Mode SMMA ...
case MODE_SMMA:
{
case MODE_SMMA: {
//
if (ArrayResize(buf, total) < 0)
{
@@ -8372,8 +8508,7 @@ double MAOnArray(
//
// Mode LWMA ...
case MODE_LWMA:
{
case MODE_LWMA: {
//
if (ArrayResize(buf, total) < 0)
{