151 lines
3.4 KiB
Plaintext
151 lines
3.4 KiB
Plaintext
void GetLongTimeTrades(
|
|
int life, // Max Candle Passed after Trades Open
|
|
ENUM_TIMEFRAMES period, // Calculate Candles based on time frame
|
|
XSignal &result[] // Holds Result
|
|
)
|
|
{
|
|
//
|
|
CleanBuffer(result);
|
|
|
|
//
|
|
// Normalize Period ...
|
|
if (period == EMPTY_VALUE)
|
|
{
|
|
period = _Period;
|
|
}
|
|
|
|
//
|
|
XSignal positions[];
|
|
GetAllPositions(positions);
|
|
int count = ArraySize(positions);
|
|
if (count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Current Time Frame Candle Index ...
|
|
int currentBarIndex = 0;
|
|
|
|
//
|
|
// Loop through Positions ...
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XSignal trade = positions[i];
|
|
|
|
//
|
|
// Retrieve Trade Open Bar Index based on Current Period ...
|
|
int tradeOpenBarIndex = iBarShift(
|
|
mSymbol,
|
|
period,
|
|
trade.time);
|
|
|
|
//
|
|
// Calculate Trade Life ...
|
|
int diff = MathAbs(currentBarIndex - tradeOpenBarIndex);
|
|
if (diff >= life)
|
|
{
|
|
//
|
|
ArrayResize(
|
|
result,
|
|
ArraySize(result) + 1);
|
|
result[ArraySize(result) - 1] = trade;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Close All Longs Positions ...
|
|
void CloseLongPositions(
|
|
XSignal &closed[] // holds Closed Positions
|
|
)
|
|
{
|
|
//
|
|
ArrayFree(closed);
|
|
ArrayResize(closed, 0);
|
|
|
|
//
|
|
// Count all Specified Positions ...
|
|
int total = CountLongs();
|
|
if (total <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XSignal longPositions[];
|
|
GetLongPositions(longPositions);
|
|
|
|
//
|
|
int longPositionsSize = ArraySize(longPositions);
|
|
if (longPositionsSize == 0 || longPositionsSize != total)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < total; i++)
|
|
{
|
|
//
|
|
XSignal signal = longPositions[i];
|
|
bool isClosed = Close(signal.ticket);
|
|
if (isClosed)
|
|
{
|
|
//
|
|
ArrayResize(
|
|
closed,
|
|
ArraySize(closed) + 1);
|
|
closed[ArraySize(closed) - 1] = signal;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Close All Shorts Positions ...
|
|
void CloseShortPositions(
|
|
XSignal &closed[] // holds Closed Positions
|
|
)
|
|
{
|
|
//
|
|
ArrayFree(closed);
|
|
ArrayResize(closed, 0);
|
|
|
|
//
|
|
// Count all Specified Positions ...
|
|
int total = CountShorts();
|
|
if (total <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XSignal shortPositions[];
|
|
GetShortPositions(shortPositions);
|
|
|
|
//
|
|
int shortPositionsSize = ArraySize(shortPositions);
|
|
if (shortPositionsSize == 0 || shortPositionsSize != total)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < total; i++)
|
|
{
|
|
//
|
|
XSignal signal = shortPositions[i];
|
|
bool isClosed = Close(signal.ticket);
|
|
if (isClosed)
|
|
{
|
|
//
|
|
ArrayResize(
|
|
closed,
|
|
ArraySize(closed) + 1);
|
|
closed[ArraySize(closed) - 1] = signal;
|
|
}
|
|
}
|
|
}
|