last ...
This commit is contained in:
@@ -637,12 +637,12 @@ struct XPosition
|
||||
//
|
||||
// Check Items Passed Specific Filters or not ...
|
||||
bool IsFiltersPassed(
|
||||
string mSymbol = NULL, // Trading Symbol
|
||||
string mProvider = NULL, // Signal Provider
|
||||
ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe
|
||||
string mSymbol = NULL, // Trading Symbol
|
||||
string mProvider = NULL, // Signal Provider
|
||||
ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe
|
||||
ENUM_X_POSITION_TYPES mType = NULL, // Long (Buy), Short (Sell)
|
||||
ulong mMagic = NULL, // Magic Number
|
||||
bool mFilterByMagic = true // Get Only Self Open Positions
|
||||
ulong mMagic = NULL, // Magic Number
|
||||
bool mFilterByMagic = true // Get Only Self Open Positions
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1922,13 +1922,13 @@ struct XOrder
|
||||
//
|
||||
// Check Items Passed Specific Filters or not ...
|
||||
bool IsFiltersPassed(
|
||||
string mSymbol = NULL, // Trading Symbol
|
||||
string mProvider = NULL, // Signal Provider
|
||||
ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe
|
||||
string mSymbol = NULL, // Trading Symbol
|
||||
string mProvider = NULL, // Signal Provider
|
||||
ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe
|
||||
ENUM_X_POSITION_TYPES mType = NULL, // Long (Buy), Short (Sell)
|
||||
ENUM_ORDER_STATE mState = NULL, // Order State
|
||||
ulong mMagic = NULL, // Magic Number
|
||||
bool mFilterByMagic = true // Get Only Self Open Positions
|
||||
ENUM_ORDER_STATE mState = NULL, // Order State
|
||||
ulong mMagic = NULL, // Magic Number
|
||||
bool mFilterByMagic = true // Get Only Self Open Positions
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -2476,7 +2476,7 @@ struct XGuard
|
||||
string symbol; // Trading Symbol ...
|
||||
string provider; // Signal Provider ...
|
||||
ENUM_TIMEFRAMES period; // Trading Timeframe ...
|
||||
ENUM_X_POSITION_TYPES type; // Position Type ...
|
||||
ENUM_X_POSITION_TYPES type; // Position Type ...
|
||||
ENUM_X_GUARD_ACTIONS action; // Which Action to Do ...
|
||||
|
||||
//
|
||||
@@ -2496,11 +2496,11 @@ struct XGuard
|
||||
//
|
||||
// Global Initializer ...
|
||||
bool Init(
|
||||
string mSymbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Timeframe ...
|
||||
ENUM_X_GUARD_ACTIONS mAction, // Which Action to Do ...
|
||||
string mSymbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Timeframe ...
|
||||
ENUM_X_GUARD_ACTIONS mAction, // Which Action to Do ...
|
||||
ENUM_X_POSITION_TYPES mType = NULL, // Position Type ...
|
||||
string mProvider = NULL, // Signal Provider ...
|
||||
string mProvider = NULL, // Signal Provider ...
|
||||
double mDblPayLoad = NULL,
|
||||
string mStrPayload = NULL //
|
||||
)
|
||||
@@ -2773,6 +2773,161 @@ struct XTrail
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
struct XSymbolPositions
|
||||
{
|
||||
//
|
||||
string symbol;
|
||||
|
||||
//
|
||||
double profit;
|
||||
double longsProfit;
|
||||
double shortsProfit;
|
||||
|
||||
//
|
||||
double volume;
|
||||
double longsVolume;
|
||||
double shortsVolume;
|
||||
|
||||
//
|
||||
double requiredProfitForHedge;
|
||||
|
||||
//
|
||||
XPosition longs[];
|
||||
XPosition shorts[];
|
||||
XPosition positions[];
|
||||
|
||||
//
|
||||
XSymbolPositions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
bool Update(
|
||||
double mMinProfitPerTrade,
|
||||
double mMinProfitPerVolumeFactor //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool hasChild = HasChild();
|
||||
if (!hasChild)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Types ...
|
||||
ExtractPositions(
|
||||
positions,
|
||||
longs,
|
||||
shorts //
|
||||
);
|
||||
|
||||
//
|
||||
int numOfLongs = 0;
|
||||
int numOfShorts = 0;
|
||||
CountPositions(
|
||||
positions,
|
||||
numOfLongs,
|
||||
longsProfit,
|
||||
longsVolume,
|
||||
numOfShorts,
|
||||
shortsProfit,
|
||||
shortsVolume //
|
||||
);
|
||||
|
||||
//
|
||||
profit = longsProfit + shortsProfit;
|
||||
volume = longsVolume + shortsVolume;
|
||||
requiredProfitForHedge = SpecifiedCalculateRequiredProfitForHedge(
|
||||
positions,
|
||||
mMinProfitPerTrade,
|
||||
mMinProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
|
||||
//
|
||||
profit = 0;
|
||||
longsProfit = 0;
|
||||
shortsProfit = 0;
|
||||
|
||||
//
|
||||
volume = 0;
|
||||
longsVolume = 0;
|
||||
shortsVolume = 0;
|
||||
|
||||
//
|
||||
requiredProfitForHedge = 0;
|
||||
|
||||
//
|
||||
Clean(longs);
|
||||
Clean(shorts);
|
||||
Clean(positions);
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(symbol);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Has Child ...
|
||||
bool HasChild()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = Count();
|
||||
result = IsValidSize(count);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count ...
|
||||
int Count()
|
||||
{
|
||||
return ArraySize(positions);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// TypeDefs ...
|
||||
|
||||
@@ -4646,6 +4801,126 @@ void ExtractPositions(
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
int FindSymbolIndex(
|
||||
string mSymbol,
|
||||
XSymbolPositions &mItems[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid(mSymbol))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(mItems);
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XSymbolPositions iItem = mItems[i];
|
||||
|
||||
//
|
||||
if (iItem.symbol == mSymbol)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int ExtractSymbolPositions(
|
||||
XPosition &positions[],
|
||||
XSymbolPositions &items[], // Holds Result
|
||||
double mMinProfitPerTrade,
|
||||
double mMinProfitPerVolumeFactor //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Clean(items);
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
if (!iPosition.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
int itemIDX = FindSymbolIndex(
|
||||
iPosition.symbol,
|
||||
items //
|
||||
);
|
||||
if (!IsValidIndex(itemIDX))
|
||||
{
|
||||
//
|
||||
// Add New One ...
|
||||
XSymbolPositions item;
|
||||
item.symbol = iPosition.symbol;
|
||||
|
||||
//
|
||||
AddRef(
|
||||
item,
|
||||
items //
|
||||
);
|
||||
itemIDX = FindSymbolIndex(iPosition.symbol, items);
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
iPosition,
|
||||
items[itemIDX].positions //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(items);
|
||||
if (IsValidSize(result))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < result; i++)
|
||||
{
|
||||
//
|
||||
items[i].Update(
|
||||
mMinProfitPerTrade,
|
||||
mMinProfitPerVolumeFactor //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Drawings ...
|
||||
bool DrawTrendState(
|
||||
|
||||
Reference in New Issue
Block a user