last ...
This commit is contained in:
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Imports ...
|
// Imports ...
|
||||||
#include <Generic/HashMap.mqh>
|
|
||||||
#include "../Classes/x-saherelm.xea.class.mq5"
|
#include "../Classes/x-saherelm.xea.class.mq5"
|
||||||
#include "../Classes/x-saherelm.x121.provider.class.mq5"
|
#include "../Classes/x-saherelm.x121.provider.class.mq5"
|
||||||
|
|
||||||
@@ -30,450 +29,6 @@
|
|||||||
// Define On Signal Event Handler Type Specified for X5 ...
|
// Define On Signal Event Handler Type Specified for X5 ...
|
||||||
typedef void (*TX121OnSignal)(X121ProviderDescriptor &descriptor);
|
typedef void (*TX121OnSignal)(X121ProviderDescriptor &descriptor);
|
||||||
|
|
||||||
//
|
|
||||||
class XSCPositionHolder
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor(s) ...
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCPositionHolder()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Cleanup ...
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
Clean(mItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool AddItem(XPosition &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = item.IsValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = !HasItem(item);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
item,
|
|
||||||
mItems //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int AddItems(XPosition &items[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = ArraySize(items);
|
|
||||||
if (itemsCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iItem = items[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isAdded = AddItem(iItem);
|
|
||||||
if (isAdded)
|
|
||||||
{
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool AddOrUpdateItem(XPosition &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = item.IsValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool hasItem = HasItem(item);
|
|
||||||
if (!hasItem)
|
|
||||||
{
|
|
||||||
result = AddItem(item);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = RemoveItem(item);
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
result = AddItem(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int AddOrUpdateItem(XPosition &items[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = ArraySize(items);
|
|
||||||
if (itemsCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iItem = items[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isAddOrUpdated = AddOrUpdateItem(iItem);
|
|
||||||
if (isAddOrUpdated)
|
|
||||||
{
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool HasItem(XPosition &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemIDX = FindItem(item);
|
|
||||||
result = itemIDX >= 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int FindItem(XPosition &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!item.IsValid())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = CountItems();
|
|
||||||
if (itemsCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iItem = mItems[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isSame = IsItemSameAs(item, iItem);
|
|
||||||
if (isSame)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool GetByIndex(
|
|
||||||
int index,
|
|
||||||
XPosition &item //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
NormalizeIndex(
|
|
||||||
index,
|
|
||||||
mItems //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
item = mItems[index];
|
|
||||||
|
|
||||||
//
|
|
||||||
result = item.IsValid();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool RemoveItem(XPosition &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = HasItem(item);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemIDX = FindItem(item);
|
|
||||||
result = ArrayRemove(
|
|
||||||
mItems,
|
|
||||||
itemIDX,
|
|
||||||
1 //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int RemoveItems(XPosition &items[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = ArraySize(items);
|
|
||||||
if (itemsCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iItem = items[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isRemoved = RemoveItem(iItem);
|
|
||||||
if (isRemoved)
|
|
||||||
{
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int CountItems()
|
|
||||||
{
|
|
||||||
return ArraySize(mItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool IsItemSameAs(
|
|
||||||
XPosition &source,
|
|
||||||
XPosition &dest // Compare Source with this ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
dest.IsValid() &&
|
|
||||||
source.IsValid() &&
|
|
||||||
source.symbol == dest.symbol &&
|
|
||||||
source.period == dest.period &&
|
|
||||||
source.ticket == dest.ticket &&
|
|
||||||
source.openAt == dest.openAt &&
|
|
||||||
source.provider == dest.provider
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
bool GetMaxInDrawdown(
|
|
||||||
XPosition &item // Result
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
item.Clean();
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = CountItems();
|
|
||||||
result = IsValidSize(itemsCount);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxIDX = -1;
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iItem = mItems[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool canSelect =
|
|
||||||
//
|
|
||||||
iItem.profit < 0
|
|
||||||
//
|
|
||||||
&&
|
|
||||||
//
|
|
||||||
(
|
|
||||||
//
|
|
||||||
(maxIDX == -1 && !item.IsValid())
|
|
||||||
? true
|
|
||||||
: item.profit < iItem.profit
|
|
||||||
//
|
|
||||||
)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
if (canSelect)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
maxIDX = i;
|
|
||||||
item = iItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = maxIDX > -1 && item.IsValid();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool GetMaxInProfit(
|
|
||||||
XPosition &item // Result
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
item.Clean();
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = CountItems();
|
|
||||||
result = IsValidSize(itemsCount);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxIDX = -1;
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iItem = mItems[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool canSelect =
|
|
||||||
//
|
|
||||||
iItem.profit > 0
|
|
||||||
//
|
|
||||||
&&
|
|
||||||
//
|
|
||||||
(
|
|
||||||
//
|
|
||||||
(maxIDX == -1 && !item.IsValid())
|
|
||||||
? true
|
|
||||||
: item.profit < iItem.profit
|
|
||||||
//
|
|
||||||
)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
if (canSelect)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
maxIDX = i;
|
|
||||||
item = iItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = maxIDX > -1 && item.IsValid();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Private ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
XPosition mItems[];
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Class Definition ...
|
// Class Definition ...
|
||||||
|
|
||||||
@@ -857,88 +412,41 @@ public:
|
|||||||
bool equityReached = !mTrader.CheckEquityForTrade();
|
bool equityReached = !mTrader.CheckEquityForTrade();
|
||||||
bool maxAllowedReached = !mTrader.CheckPositionsForTrade();
|
bool maxAllowedReached = !mTrader.CheckPositionsForTrade();
|
||||||
bool enableEQM = equityReached || maxAllowedReached;
|
bool enableEQM = equityReached || maxAllowedReached;
|
||||||
if (!enableEQM)
|
// if (!enableEQM)
|
||||||
{
|
|
||||||
//
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
string eqmMessage = "EQM Enabled: " + "\n";
|
|
||||||
if (equityReached)
|
|
||||||
{
|
|
||||||
eqmMessage += "- Max Equity Reached ..." + "\n";
|
|
||||||
}
|
|
||||||
if (maxAllowedReached)
|
|
||||||
{
|
|
||||||
eqmMessage += "- Max Allowed Positions Reached ...";
|
|
||||||
}
|
|
||||||
// mAlert.Alert(eqmMessage);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve InDrawdown Positions Count ...
|
|
||||||
// Separate based on Directions and Symbols ...
|
|
||||||
// Accept Only One Signal based on each symbol Indirect ...
|
|
||||||
// for Fittion Positions to HedgeEnable in Long Time Positions ...
|
|
||||||
|
|
||||||
// //
|
|
||||||
// int descriptorsCount = CountDescriptors();
|
|
||||||
// if (descriptorsCount <= 0)
|
|
||||||
// {
|
// {
|
||||||
|
// //
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// //
|
//
|
||||||
// XSignal supportSignals[];
|
string mSymbols[];
|
||||||
// for (int i = 0; i < descriptorsCount; i++)
|
XSCPositionHolder *mHolders[];
|
||||||
// {
|
int symbolsCount = FilterSymbolBasedPositions(
|
||||||
// //
|
mSymbols,
|
||||||
// X121ProviderDescriptor iDescriptor = mDescriptors[i];
|
mHolders //
|
||||||
|
);
|
||||||
|
|
||||||
// //
|
//
|
||||||
// XSignal iSupportSignals[];
|
for (int i = 0; i < symbolsCount; i++)
|
||||||
// int iSupportSignalsCount = iDescriptor
|
{
|
||||||
// .provider
|
//
|
||||||
// .GenerateEQMSupportSignals(
|
string iSymbol = mSymbols[i];
|
||||||
// iSupportSignals //
|
XSCPositionHolder *iHolder = mHolders[i];
|
||||||
// );
|
|
||||||
// if (iSupportSignalsCount <= 0)
|
|
||||||
// {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //
|
//
|
||||||
// Copy(
|
XPosition iMaxInDP;
|
||||||
// iSupportSignals,
|
bool hasMaxInDP = iHolder.GetMaxInDrawdown(iMaxInDP);
|
||||||
// supportSignals,
|
if (!hasMaxInDP)
|
||||||
// false //
|
{
|
||||||
// );
|
continue;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// int supportSignalsCount = ArraySize(supportSignals);
|
// Try to Protect a Position ...
|
||||||
// if (supportSignalsCount <= 0)
|
ProtectPosition(iMaxInDP);
|
||||||
// {
|
}
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //
|
//
|
||||||
// ENUM_X_SIGNAL_EXECUTION_RESULT states[];
|
|
||||||
// int executedSupports = mTrader.ExecuteSignals(
|
|
||||||
// supportSignals,
|
|
||||||
// states,
|
|
||||||
// ORDER_TIME_GTC,
|
|
||||||
// NULL,
|
|
||||||
// false // Ignore Policies ...
|
|
||||||
// );
|
|
||||||
// if (executedSupports > 0)
|
|
||||||
// {
|
|
||||||
// //
|
|
||||||
// string message = "EQM Execute (" + ToString(executedSupports) + ") Support Signals ...";
|
|
||||||
|
|
||||||
// //
|
|
||||||
// mAlert.Alert(message);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -958,6 +466,9 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double profit = CalculatePositionsProfit(positions);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trail Positions Stop ...
|
// Trail Positions Stop ...
|
||||||
for (int i = 0; i < positionsCount; i++)
|
for (int i = 0; i < positionsCount; i++)
|
||||||
@@ -978,6 +489,9 @@ public:
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// When Position in Profit, Trail SL ...
|
// When Position in Profit, Trail SL ...
|
||||||
|
if (profit > 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
if (iPosition.profit > 0)
|
if (iPosition.profit > 0)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1162,9 +676,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// When Position in Drawdown Trail TP ...
|
// When Position in Drawdown Trail TP ...
|
||||||
|
if (profit < 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
if (iPosition.profit < 0)
|
if (iPosition.profit < 0)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1301,6 +819,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Here we Can Filter Signals before Sending them to Execution ...
|
// Here we Can Filter Signals before Sending them to Execution ...
|
||||||
@@ -1402,14 +921,14 @@ public:
|
|||||||
//
|
//
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (profit > 0 && symbolProfit > 0)
|
// else if (profit > 0 && symbolProfit > 0)
|
||||||
{
|
// {
|
||||||
//
|
// //
|
||||||
AddRef(
|
// AddRef(
|
||||||
iSignal,
|
// iSignal,
|
||||||
signals //
|
// signals //
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -1461,6 +980,8 @@ public:
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
string message = "Position (" + ToString(track.ticket) + ", " + track.symbol + ") Dropped in Profit ...";
|
string message = "Position (" + ToString(track.ticket) + ", " + track.symbol + ") Dropped in Profit ...";
|
||||||
|
|
||||||
|
//
|
||||||
mAlert.Alert(message);
|
mAlert.Alert(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1470,6 +991,8 @@ public:
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
string message = "Position (" + ToString(track.ticket) + ", " + track.symbol + ") Dropped in Drawdown ...";
|
string message = "Position (" + ToString(track.ticket) + ", " + track.symbol + ") Dropped in Drawdown ...";
|
||||||
|
|
||||||
|
//
|
||||||
mAlert.Alert(message);
|
mAlert.Alert(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1497,78 +1020,16 @@ public:
|
|||||||
//
|
//
|
||||||
// Here i Have to Detect In DrawDown Positions ...
|
// Here i Have to Detect In DrawDown Positions ...
|
||||||
|
|
||||||
//
|
|
||||||
XPosition positions[];
|
|
||||||
int positionsCount = mTrader.GetInDrawdownPositions(
|
|
||||||
positions);
|
|
||||||
if (!IsValidSize(positionsCount))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Create a HashMap for Holding Positions ...
|
|
||||||
CHashMap<string, XSCPositionHolder *> symbolMap;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Loop Through Positions ...
|
|
||||||
for (int i = 0; i < positionsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iPosition = positions[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool hasIKey = symbolMap.ContainsKey(iPosition.symbol);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Empty Class Pointer ...
|
|
||||||
XSCPositionHolder *mHolder = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add new to Map ...
|
|
||||||
if (!hasIKey)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mHolder = new XSCPositionHolder();
|
|
||||||
if (symbolMap.TrySetValue(iPosition.symbol, mHolder))
|
|
||||||
{
|
|
||||||
mHolder.AddOrUpdateItem(iPosition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Update Exists in Map ...
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (symbolMap.TryGetValue(iPosition.symbol, mHolder))
|
|
||||||
{
|
|
||||||
mHolder.AddOrUpdateItem(iPosition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Now we Have a Map which Filled Based on Separate Symbols and InDrawDown Positions ...
|
|
||||||
int mapCount = symbolMap.Count();
|
|
||||||
if (!IsValidSize(mapCount))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
string mSymbols[];
|
string mSymbols[];
|
||||||
XSCPositionHolder *mHolders[];
|
XSCPositionHolder *mHolders[];
|
||||||
mapCount = symbolMap.CopyTo(
|
int symbolsCount = FilterSymbolBasedPositions(
|
||||||
mSymbols,
|
mSymbols,
|
||||||
mHolders //
|
mHolders //
|
||||||
);
|
);
|
||||||
if (!IsValidSize(mapCount))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
for (int i = 0; i < mapCount; i++)
|
for (int i = 0; i < symbolsCount; i++)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
string iSymbol = mSymbols[i];
|
string iSymbol = mSymbols[i];
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Imports ...
|
// Imports ...
|
||||||
|
#include <Generic/HashMap.mqh>
|
||||||
#include "../Classes/x-saherelm.base.class.mq5"
|
#include "../Classes/x-saherelm.base.class.mq5"
|
||||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||||
@@ -1265,6 +1266,870 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
class XSCPositionHolder
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Public ...
|
||||||
|
public:
|
||||||
|
//
|
||||||
|
// Props ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Constructor(s) ...
|
||||||
|
|
||||||
|
//
|
||||||
|
XSCPositionHolder()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tools ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup ...
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
Clean(mItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool AddItem(XPosition &item)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = !HasItem(item);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
AddRef(
|
||||||
|
item,
|
||||||
|
mItems //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int AddItems(XPosition &items[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = ArraySize(items);
|
||||||
|
if (itemsCount <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = items[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isAdded = AddItem(iItem);
|
||||||
|
if (isAdded)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool AddOrUpdateItem(XPosition &item)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool hasItem = HasItem(item);
|
||||||
|
if (!hasItem)
|
||||||
|
{
|
||||||
|
result = AddItem(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = RemoveItem(item);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
result = AddItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int AddOrUpdateItem(XPosition &items[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = ArraySize(items);
|
||||||
|
if (itemsCount <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = items[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isAddOrUpdated = AddOrUpdateItem(iItem);
|
||||||
|
if (isAddOrUpdated)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool HasItem(XPosition &item)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemIDX = FindItem(item);
|
||||||
|
result = itemIDX >= 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int FindItem(XPosition &item)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!item.IsValid())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
if (itemsCount <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isSame = IsItemSameAs(item, iItem);
|
||||||
|
if (isSame)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetByIndex(
|
||||||
|
int index,
|
||||||
|
XPosition &item //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
NormalizeIndex(
|
||||||
|
index,
|
||||||
|
mItems //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
item = mItems[index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool RemoveItem(XPosition &item)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = HasItem(item);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemIDX = FindItem(item);
|
||||||
|
result = ArrayRemove(
|
||||||
|
mItems,
|
||||||
|
itemIDX,
|
||||||
|
1 //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int RemoveItems(XPosition &items[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = ArraySize(items);
|
||||||
|
if (itemsCount <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = items[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isRemoved = RemoveItem(iItem);
|
||||||
|
if (isRemoved)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int CountItems()
|
||||||
|
{
|
||||||
|
return ArraySize(mItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool IsItemSameAs(
|
||||||
|
XPosition &source,
|
||||||
|
XPosition &dest // Compare Source with this ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
dest.IsValid() &&
|
||||||
|
source.IsValid() &&
|
||||||
|
source.symbol == dest.symbol &&
|
||||||
|
source.period == dest.period &&
|
||||||
|
source.ticket == dest.ticket &&
|
||||||
|
source.openAt == dest.openAt &&
|
||||||
|
source.provider == dest.provider
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Custom Functions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetMaxInDrawdown(
|
||||||
|
XPosition &item // Result
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int maxIDX = -1;
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool canSelect =
|
||||||
|
//
|
||||||
|
iItem.profit < 0
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
(
|
||||||
|
//
|
||||||
|
(maxIDX == -1 && !item.IsValid())
|
||||||
|
? true
|
||||||
|
: item.profit < iItem.profit
|
||||||
|
//
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (canSelect)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
maxIDX = i;
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = maxIDX > -1 && item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetMaxInProfit(
|
||||||
|
XPosition &item // Result
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int maxIDX = -1;
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool canSelect =
|
||||||
|
//
|
||||||
|
iItem.profit > 0
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
(
|
||||||
|
//
|
||||||
|
(maxIDX == -1 && !item.IsValid())
|
||||||
|
? true
|
||||||
|
: item.profit < iItem.profit
|
||||||
|
//
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (canSelect)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
maxIDX = i;
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = maxIDX > -1 && item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetFarestEntry(
|
||||||
|
XPosition &item, // Result
|
||||||
|
string symbol = NULL,
|
||||||
|
string provider = NULL,
|
||||||
|
ENUM_TIMEFRAMES period = NULL,
|
||||||
|
ENUM_POSITION_TYPE type = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isFiltersPassed =
|
||||||
|
//
|
||||||
|
iItem.IsFiltersPassed(
|
||||||
|
symbol,
|
||||||
|
provider,
|
||||||
|
period,
|
||||||
|
type //
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isFiltersPassed)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Additional Filtering ...
|
||||||
|
bool isValidEntry =
|
||||||
|
//
|
||||||
|
!item.IsValid()
|
||||||
|
? true
|
||||||
|
: item.entry < iItem.entry
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (isValidEntry)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetNearestEntry(
|
||||||
|
XPosition &item, // Result
|
||||||
|
string symbol = NULL,
|
||||||
|
string provider = NULL,
|
||||||
|
ENUM_TIMEFRAMES period = NULL,
|
||||||
|
ENUM_POSITION_TYPE type = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isFiltersPassed =
|
||||||
|
//
|
||||||
|
iItem.IsFiltersPassed(
|
||||||
|
symbol,
|
||||||
|
provider,
|
||||||
|
period,
|
||||||
|
type //
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isFiltersPassed)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Additional Filtering ...
|
||||||
|
bool isValidEntry =
|
||||||
|
//
|
||||||
|
!item.IsValid()
|
||||||
|
? true
|
||||||
|
: item.entry > iItem.entry
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (isValidEntry)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetFarestSL(
|
||||||
|
XPosition &item, // Result
|
||||||
|
string symbol = NULL,
|
||||||
|
string provider = NULL,
|
||||||
|
ENUM_TIMEFRAMES period = NULL,
|
||||||
|
ENUM_POSITION_TYPE type = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isFiltersPassed =
|
||||||
|
//
|
||||||
|
iItem.IsFiltersPassed(
|
||||||
|
symbol,
|
||||||
|
provider,
|
||||||
|
period,
|
||||||
|
type //
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isFiltersPassed)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Additional Filtering ...
|
||||||
|
bool isValidEntry =
|
||||||
|
//
|
||||||
|
!item.IsValid()
|
||||||
|
? true
|
||||||
|
: item.sl < iItem.sl
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (isValidEntry)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetNearestSL(
|
||||||
|
XPosition &item, // Result
|
||||||
|
string symbol = NULL,
|
||||||
|
string provider = NULL,
|
||||||
|
ENUM_TIMEFRAMES period = NULL,
|
||||||
|
ENUM_POSITION_TYPE type = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isFiltersPassed =
|
||||||
|
//
|
||||||
|
iItem.IsFiltersPassed(
|
||||||
|
symbol,
|
||||||
|
provider,
|
||||||
|
period,
|
||||||
|
type //
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isFiltersPassed)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Additional Filtering ...
|
||||||
|
bool isValidEntry =
|
||||||
|
//
|
||||||
|
!item.IsValid()
|
||||||
|
? true
|
||||||
|
: item.sl > iItem.sl
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (isValidEntry)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetFarestTP(
|
||||||
|
XPosition &item, // Result
|
||||||
|
string symbol = NULL,
|
||||||
|
string provider = NULL,
|
||||||
|
ENUM_TIMEFRAMES period = NULL,
|
||||||
|
ENUM_POSITION_TYPE type = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isFiltersPassed =
|
||||||
|
//
|
||||||
|
iItem.IsFiltersPassed(
|
||||||
|
symbol,
|
||||||
|
provider,
|
||||||
|
period,
|
||||||
|
type //
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isFiltersPassed)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Additional Filtering ...
|
||||||
|
bool isValidEntry =
|
||||||
|
//
|
||||||
|
!item.IsValid()
|
||||||
|
? true
|
||||||
|
: item.tp < iItem.tp
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (isValidEntry)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetNearestTP(
|
||||||
|
XPosition &item, // Result
|
||||||
|
string symbol = NULL,
|
||||||
|
string provider = NULL,
|
||||||
|
ENUM_TIMEFRAMES period = NULL,
|
||||||
|
ENUM_POSITION_TYPE type = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
item.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
int itemsCount = CountItems();
|
||||||
|
result = IsValidSize(itemsCount);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < itemsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iItem = mItems[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isFiltersPassed =
|
||||||
|
//
|
||||||
|
iItem.IsFiltersPassed(
|
||||||
|
symbol,
|
||||||
|
provider,
|
||||||
|
period,
|
||||||
|
type //
|
||||||
|
)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isFiltersPassed)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Additional Filtering ...
|
||||||
|
bool isValidEntry =
|
||||||
|
//
|
||||||
|
!item.IsValid()
|
||||||
|
? true
|
||||||
|
: item.tp > iItem.tp
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (isValidEntry)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
item = iItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = item.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Private ...
|
||||||
|
private:
|
||||||
|
//
|
||||||
|
// Props ...
|
||||||
|
XPosition mItems[];
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Class Definition ...
|
// Class Definition ...
|
||||||
|
|
||||||
@@ -2973,6 +3838,87 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Position Filter ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int FilterSymbolBasedPositions(
|
||||||
|
string &symbols[], // Hold Symbols ...
|
||||||
|
XSCPositionHolder *&holders[] // Holder Class Instances ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
XPosition positions[];
|
||||||
|
int positionsCount = mTrader.GetPositions(
|
||||||
|
positions //
|
||||||
|
);
|
||||||
|
if (!IsValidSize(positionsCount))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create a HashMap for Holding Positions ...
|
||||||
|
CHashMap<string, XSCPositionHolder *> symbolMap;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through Positions ...
|
||||||
|
for (int i = 0; i < positionsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iPosition = positions[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool hasIKey = symbolMap.ContainsKey(iPosition.symbol);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Empty Class Pointer ...
|
||||||
|
XSCPositionHolder *mHolder = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add new to Map ...
|
||||||
|
if (!hasIKey)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
mHolder = new XSCPositionHolder();
|
||||||
|
if (symbolMap.TrySetValue(iPosition.symbol, mHolder))
|
||||||
|
{
|
||||||
|
mHolder.AddOrUpdateItem(iPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Update Exists in Map ...
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (symbolMap.TryGetValue(iPosition.symbol, mHolder))
|
||||||
|
{
|
||||||
|
mHolder.AddOrUpdateItem(iPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Now we Have a Map which Filled Based on Separate Symbols and InDrawDown Positions ...
|
||||||
|
int mapCount = symbolMap.Count();
|
||||||
|
if (!IsValidSize(mapCount))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = symbolMap.CopyTo(
|
||||||
|
symbols,
|
||||||
|
holders //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Private ...
|
// Private ...
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -33,12 +33,12 @@
|
|||||||
// Inputs ...
|
// Inputs ...
|
||||||
long x121EAMagicNumber = 78692110; // Magic Number
|
long x121EAMagicNumber = 78692110; // Magic Number
|
||||||
int x121EASlippage = 10; // Slippgae
|
int x121EASlippage = 10; // Slippgae
|
||||||
string x121EASymbols = "EURUSDb,USDCHFb,USDJPYb,GBPUSDb,XAUUSDb,AUDUSDb,USDCADb,NZDUSDb"; // Symbols
|
string x121EASymbols = "EURUSDb,USDCHFb,USDJPYb,GBPUSDb"; // Symbols
|
||||||
//
|
//
|
||||||
bool x121EAAllowLong = true; // Allow Long Trades
|
bool x121EAAllowLong = true; // Allow Long Trades
|
||||||
bool x121EAAllowShort = true; // Allow Short Trades
|
bool x121EAAllowShort = true; // Allow Short Trades
|
||||||
int x121EAManageInterval = 0; // Manager Check Intervals Seconds
|
int x121EAManageInterval = 0; // Manager Check Intervals Seconds
|
||||||
int x121EAMaxAllowedPositions = 10; // Max Allowed Positions
|
int x121EAMaxAllowedPositions = 5; // Max Allowed Positions
|
||||||
double x121EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
|
double x121EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
|
||||||
double x121EAMinProfitPerTrade = 3; // Min Profit Per Trade based On Volume Factor (Hedge)
|
double x121EAMinProfitPerTrade = 3; // Min Profit Per Trade based On Volume Factor (Hedge)
|
||||||
double x121EAMinProfitPerVolumeFactor = 0.01; // Min Volume Factor for Calculating Profit (Hedge)
|
double x121EAMinProfitPerVolumeFactor = 0.01; // Min Volume Factor for Calculating Profit (Hedge)
|
||||||
@@ -291,7 +291,7 @@ void ConfigureDescriptor(
|
|||||||
//
|
//
|
||||||
// XHK ...
|
// XHK ...
|
||||||
iDescriptor.inputs.hkInputs.drawHikenAshi = false;
|
iDescriptor.inputs.hkInputs.drawHikenAshi = false;
|
||||||
iDescriptor.inputs.hkInputs.drawSmoothedHikenAshi = true;
|
iDescriptor.inputs.hkInputs.drawSmoothedHikenAshi = false;
|
||||||
|
|
||||||
//
|
//
|
||||||
// XMC ...
|
// XMC ...
|
||||||
|
|||||||
Reference in New Issue
Block a user