last ...
This commit is contained in:
@@ -4401,6 +4401,25 @@ public:
|
|||||||
int maxAllowed = MaxAllowedTrades();
|
int maxAllowed = MaxAllowedTrades();
|
||||||
bool perDirection = UseMaxAllowedPerDirection();
|
bool perDirection = UseMaxAllowedPerDirection();
|
||||||
|
|
||||||
|
//
|
||||||
|
XPosition positions[];
|
||||||
|
int positionsCount = mTrader.GetPositions(positions);
|
||||||
|
bool hasPositions = IsValidSize(positionsCount);
|
||||||
|
|
||||||
|
//
|
||||||
|
double minProfitPerTrade = MinProfitPerTrade();
|
||||||
|
double minProfitPerTradeVolumeFactor = minProfitPerTradeVolumeFactor();
|
||||||
|
|
||||||
|
//
|
||||||
|
XSymbolPositions symbolPositions[];
|
||||||
|
int smybolPositionsCount = ExtractSymbolPositions(
|
||||||
|
positions,
|
||||||
|
symbolPositions,
|
||||||
|
minProfitPerTrade,
|
||||||
|
minProfitPerTradeVolumeFactor //
|
||||||
|
);
|
||||||
|
bool hasSymbolPositions = IsValidSize(smybolPositionsCount);
|
||||||
|
|
||||||
//
|
//
|
||||||
for (int i = 0; i < signalsCount; i++)
|
for (int i = 0; i < signalsCount; i++)
|
||||||
{
|
{
|
||||||
@@ -4408,10 +4427,47 @@ public:
|
|||||||
XSignal iSignal = tmpSignals[i];
|
XSignal iSignal = tmpSignals[i];
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isSignalValid = false;
|
bool isLong = IsLong(iSignal.type);
|
||||||
|
|
||||||
//
|
//
|
||||||
isSignalValid = IsSignalDelayPassed(iSignal);
|
bool isSignalValid = false;
|
||||||
|
bool hasSameTypeSignal = false;
|
||||||
|
bool isFirstSymbolSignal = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Symbol Index ...
|
||||||
|
int symbolIDX = FindSymbolIndex(
|
||||||
|
iSignal.symbol,
|
||||||
|
symbolPositions //
|
||||||
|
);
|
||||||
|
bool isValidSymbolIDX = IsValidIndex(symbolIDX);
|
||||||
|
if (!isValidSymbolIDX)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// We Sure it is First Signal of Smybol in a While ...
|
||||||
|
hasSameTypeSignal = false;
|
||||||
|
isFirstSymbolSignal = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// We Sure it isnt First Signal of Symbol at current State ...
|
||||||
|
isFirstSymbolSignal = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Has Same Type Signal or not ...
|
||||||
|
hasSameTypeSignal =
|
||||||
|
isLong
|
||||||
|
? symbolPositions[symbolIDX].longs > 1
|
||||||
|
: symbolPositions[symbolIDX].shorts > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Delay Passed ...
|
||||||
|
isSignalValid = IsSignalDelayPassed(
|
||||||
|
iSignal,
|
||||||
|
symbolPositions[symbolIDX] //
|
||||||
|
);
|
||||||
if (!isSignalValid)
|
if (!isSignalValid)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -4422,22 +4478,12 @@ public:
|
|||||||
if (mCloseOnOpposit)
|
if (mCloseOnOpposit)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Select Signal Opposit Positions ...
|
int oppositCount =
|
||||||
ENUM_X_POSITION_TYPES iOpposit = GetOppositPositionType(iSignal.type);
|
isLong
|
||||||
|
? symbolPositions[symbolIDX].CountShorts()
|
||||||
//
|
: symbolPositions[symbolIDX].CountLongs();
|
||||||
XPosition iPositions[];
|
bool hasOpposit = IsValidSize(oppositCount);
|
||||||
int iPositionsCount = mTrader.GetPositions(
|
if (hasOpposit) {
|
||||||
iPositions,
|
|
||||||
iSignal.symbol,
|
|
||||||
NULL, // All Providers ...
|
|
||||||
NULL, // All Periods ...
|
|
||||||
iOpposit // Opposit Positions ...
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (IsValidSize(iPositionsCount))
|
|
||||||
{
|
|
||||||
//
|
//
|
||||||
string comment = "Close due Opposit ...";
|
string comment = "Close due Opposit ...";
|
||||||
|
|
||||||
@@ -4491,10 +4537,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
isSignalValid =
|
isFirstOfSymbol =
|
||||||
iSupportsCount <= 0
|
|
||||||
? iSymbolsPositionsCount < maxAllowed
|
//
|
||||||
: iSymbolsPositionsCount - iSupportsCount < maxAllowed;
|
isSignalValid =
|
||||||
|
iSupportsCount <= 0
|
||||||
|
? iSymbolsPositionsCount < maxAllowed
|
||||||
|
: iSymbolsPositionsCount - iSupportsCount < maxAllowed;
|
||||||
if (!isSignalValid)
|
if (!isSignalValid)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -4507,7 +4556,6 @@ public:
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Only Accept Next Same Type when Previous in Profit ...
|
// Only Accept Next Same Type when Previous in Profit ...
|
||||||
bool isSameTypeExists = false;
|
|
||||||
if (isSignalValid)
|
if (isSignalValid)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -4599,6 +4647,7 @@ public:
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Multiply Signal Volume ...
|
// Multiply Signal Volume ...
|
||||||
|
// Create First Signal Opposit Protector ...
|
||||||
if (isSignalValid)
|
if (isSignalValid)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -4647,6 +4696,9 @@ public:
|
|||||||
double volumeMultiplier = IncreaseNextSignalsVolumeMultiplier();
|
double volumeMultiplier = IncreaseNextSignalsVolumeMultiplier();
|
||||||
iSignal.volume = iSignal.volume * (multiplier * volumeMultiplier);
|
iSignal.volume = iSignal.volume * (multiplier * volumeMultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -4948,7 +5000,8 @@ protected:
|
|||||||
//
|
//
|
||||||
// Check Delay Between Two Signals ...
|
// Check Delay Between Two Signals ...
|
||||||
bool IsSignalDelayPassed(
|
bool IsSignalDelayPassed(
|
||||||
XSignal &signal //
|
XSignal &signal,
|
||||||
|
XSymbolPositions &positions //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -4972,29 +5025,18 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Retrieve Positions ...
|
XPosition youngest;
|
||||||
// Based On Provider and Symbol and TimeFrame ...
|
int youngestAge = positions.GetYoungest(
|
||||||
XPosition positions[];
|
youngest,
|
||||||
int positionsCount = mTrader.GetPositions(
|
iSignal.type //
|
||||||
positions,
|
|
||||||
signal.symbol,
|
|
||||||
NULL, // signal.provider,
|
|
||||||
NULL, // signal.period,
|
|
||||||
ToPositionType(signal.type),
|
|
||||||
true // Filter By Magic ...
|
|
||||||
);
|
);
|
||||||
result = !IsValidSize(positionsCount);
|
result = !IsValidIndex(youngestAge);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
XPosition youngest;
|
|
||||||
int youngestAge = GetYoungest(
|
|
||||||
youngest,
|
|
||||||
positions //
|
|
||||||
);
|
|
||||||
result = youngestAge >= delay;
|
result = youngestAge >= delay;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -2796,6 +2796,8 @@ struct XSymbolPositions
|
|||||||
XPosition longs[];
|
XPosition longs[];
|
||||||
XPosition shorts[];
|
XPosition shorts[];
|
||||||
XPosition positions[];
|
XPosition positions[];
|
||||||
|
XPosition longSupports[];
|
||||||
|
XPosition shortSupports[];
|
||||||
|
|
||||||
//
|
//
|
||||||
bool forceHedge;
|
bool forceHedge;
|
||||||
@@ -3022,52 +3024,311 @@ struct XSymbolPositions
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
};
|
int GetOldest(
|
||||||
|
XPosition &_oldest, //
|
||||||
//
|
ENUM_POSITION_TYPE _type //
|
||||||
bool IsContainsSymbol(
|
)
|
||||||
string symbol,
|
|
||||||
int &_index,
|
|
||||||
XSymbolPositions &_items[] //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
_index = -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid(symbol);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = ArraySize(_items);
|
|
||||||
result = IsValidSize(itemsCount);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
result = _items[i].symbol == symbol;
|
int result = -1;
|
||||||
if (result)
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(_type);
|
||||||
|
|
||||||
|
//
|
||||||
|
int count =
|
||||||
|
isLong
|
||||||
|
? CountLongs()
|
||||||
|
: CountShorts();
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isLong)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
_index = i;
|
result = GetOldest(
|
||||||
break;
|
_oldest,
|
||||||
|
longs //
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = GetOldest(
|
||||||
|
_oldest,
|
||||||
|
shorts //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
int GetYoungest(
|
||||||
}
|
XPosition &_youngest, //
|
||||||
|
ENUM_POSITION_TYPE _type //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(_type);
|
||||||
|
|
||||||
|
//
|
||||||
|
int count =
|
||||||
|
isLong
|
||||||
|
? CountLongs()
|
||||||
|
: CountShorts();
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isLong)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = GetYoungest(
|
||||||
|
_youngest,
|
||||||
|
longs //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = GetYoungest(
|
||||||
|
_youngest,
|
||||||
|
shorts //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int GetMaxInProfit(
|
||||||
|
XPosition _position,
|
||||||
|
ENUM_POSITION_TYPE _type //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(_type);
|
||||||
|
|
||||||
|
//
|
||||||
|
int count =
|
||||||
|
isLong
|
||||||
|
? CountLongs()
|
||||||
|
: CountShorts();
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isLong)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMaxProfitIndex(
|
||||||
|
longs //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = longs[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMaxProfitIndex(
|
||||||
|
shorts //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = shorts[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int GetMinInProfit(
|
||||||
|
XPosition _position,
|
||||||
|
ENUM_POSITION_TYPE _type //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(_type);
|
||||||
|
|
||||||
|
//
|
||||||
|
int count =
|
||||||
|
isLong
|
||||||
|
? CountLongs()
|
||||||
|
: CountShorts();
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isLong)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMinProfitIndex(
|
||||||
|
longs //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = longs[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMinProfitIndex(
|
||||||
|
shorts //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = shorts[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int GetMaxInDrawdown(
|
||||||
|
XPosition _position,
|
||||||
|
ENUM_POSITION_TYPE _type //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(_type);
|
||||||
|
|
||||||
|
//
|
||||||
|
int count =
|
||||||
|
isLong
|
||||||
|
? CountLongs()
|
||||||
|
: CountShorts();
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isLong)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMaxInDrawdownIndex(
|
||||||
|
longs //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = longs[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMaxInDrawdownIndex(
|
||||||
|
shorts //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = shorts[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int GetMinInDrawdown(
|
||||||
|
XPosition _position,
|
||||||
|
ENUM_POSITION_TYPE _type //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(_type);
|
||||||
|
|
||||||
|
//
|
||||||
|
int count =
|
||||||
|
isLong
|
||||||
|
? CountLongs()
|
||||||
|
: CountShorts();
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isLong)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMinInDrawdownIndex(
|
||||||
|
longs //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = longs[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = FindMinInDrawdownIndex(
|
||||||
|
shorts //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValidIndex(result))
|
||||||
|
{
|
||||||
|
_position = shorts[result];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// TypeDefs ...
|
// TypeDefs ...
|
||||||
@@ -3640,7 +3901,7 @@ int ExtractInProfitPositions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
int FindMaxDrawdownIndex(
|
int FindMaxInDrawdownIndex(
|
||||||
XPosition &positions[] // Position Collection
|
XPosition &positions[] // Position Collection
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -3680,7 +3941,7 @@ int FindMaxDrawdownIndex(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
int FindMinDrawdownIndex(
|
int FindMinInDrawdownIndex(
|
||||||
XPosition &positions[] // Position Collection
|
XPosition &positions[] // Position Collection
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user