last ...
This commit is contained in:
@@ -2796,6 +2796,8 @@ struct XSymbolPositions
|
||||
XPosition longs[];
|
||||
XPosition shorts[];
|
||||
XPosition positions[];
|
||||
XPosition longSupports[];
|
||||
XPosition shortSupports[];
|
||||
|
||||
//
|
||||
bool forceHedge;
|
||||
@@ -3022,52 +3024,311 @@ struct XSymbolPositions
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
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++)
|
||||
int GetOldest(
|
||||
XPosition &_oldest, //
|
||||
ENUM_POSITION_TYPE _type //
|
||||
)
|
||||
{
|
||||
//
|
||||
result = _items[i].symbol == symbol;
|
||||
if (result)
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(_type);
|
||||
|
||||
//
|
||||
int count =
|
||||
isLong
|
||||
? CountLongs()
|
||||
: CountShorts();
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (isLong)
|
||||
{
|
||||
//
|
||||
_index = i;
|
||||
break;
|
||||
result = GetOldest(
|
||||
_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 ...
|
||||
@@ -3640,7 +3901,7 @@ int ExtractInProfitPositions(
|
||||
}
|
||||
|
||||
//
|
||||
int FindMaxDrawdownIndex(
|
||||
int FindMaxInDrawdownIndex(
|
||||
XPosition &positions[] // Position Collection
|
||||
)
|
||||
{
|
||||
@@ -3680,7 +3941,7 @@ int FindMaxDrawdownIndex(
|
||||
}
|
||||
|
||||
//
|
||||
int FindMinDrawdownIndex(
|
||||
int FindMinInDrawdownIndex(
|
||||
XPosition &positions[] // Position Collection
|
||||
)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user