last works ...
This commit is contained in:
+121
-102
@@ -45,6 +45,127 @@ enum ENUM_X_SWING_TYPE
|
||||
X_SWING_LOW = -1,
|
||||
};
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE ToSeriesMode(ENUM_X_SWING_TYPE value)
|
||||
{
|
||||
//
|
||||
ENUM_SERIESMODE result = MODE_HIGH;
|
||||
|
||||
//
|
||||
switch (value)
|
||||
{
|
||||
//
|
||||
case X_SWING_HIGH:
|
||||
result = MODE_HIGH;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_SWING_LOW:
|
||||
result = MODE_LOW;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Swing Points ...
|
||||
int FindSwing(
|
||||
string mSymbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Period ...
|
||||
ENUM_X_SWING_TYPE mode, // Swing Based On Price mode ...
|
||||
int mLength, // Loopback ...
|
||||
int bar_index // BarIndex ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (StringLen(mSymbol) == 0 || (mode != X_SWING_HIGH && mode != X_SWING_LOW))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int current = bar_index;
|
||||
int founded = FindNextSwing(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mode,
|
||||
(mLength * 2) + 1,
|
||||
current - mLength);
|
||||
|
||||
//
|
||||
while (founded != current)
|
||||
{
|
||||
//
|
||||
current = FindNextSwing(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mode,
|
||||
mLength,
|
||||
current + 1);
|
||||
|
||||
//
|
||||
founded = FindNextSwing(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mode,
|
||||
(mLength * 2) + 1,
|
||||
current - mLength);
|
||||
}
|
||||
|
||||
//
|
||||
result = current;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Next Swing ...
|
||||
int FindNextSwing(
|
||||
string mSymbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Period ...
|
||||
ENUM_X_SWING_TYPE mode, // Swing Based On Price mode ...
|
||||
int mLength, // Loopback ...
|
||||
int bar_index // BarIndex ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (bar_index < 0)
|
||||
{
|
||||
mLength += bar_index;
|
||||
bar_index = 0;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mSeriesMode = ToSeriesMode(mode);
|
||||
|
||||
//
|
||||
result = mode == X_SWING_HIGH
|
||||
? iHighest(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mSeriesMode,
|
||||
mLength,
|
||||
bar_index)
|
||||
: iLowest(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mSeriesMode,
|
||||
mLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XPERIOD Calculation Method ...
|
||||
enum ENUM_X_PERIOD_METHOD
|
||||
@@ -1399,108 +1520,6 @@ struct XOHCL
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Swings (Highs nd Lows) ...
|
||||
int FindSwing(
|
||||
ENUM_X_SWING_TYPE swing, // Swing Based On Price mode ...
|
||||
int mLength // Loopback ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid() ||
|
||||
!IsValid(swing))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int current = Index();
|
||||
int founded = FindNextSwing(
|
||||
swing,
|
||||
(mLength * 2) + 1,
|
||||
current - mLength
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
while (founded != current)
|
||||
{
|
||||
//
|
||||
current = FindNextSwing(
|
||||
swing,
|
||||
mLength,
|
||||
current + 1
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
founded = FindNextSwing(
|
||||
swing,
|
||||
(mLength * 2) + 1,
|
||||
current - mLength
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
result = current;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Next Swing ...
|
||||
int FindNextSwing(
|
||||
ENUM_X_SWING_TYPE swing, // Swing Based On Price mode ...
|
||||
int from, // from Bar Index
|
||||
int mLength // Loopback ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid() ||
|
||||
!IsValid(swing))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (from < 0)
|
||||
{
|
||||
mLength += from;
|
||||
from = 0;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mMode = swing == X_SWING_HIGH
|
||||
? MODE_HIGH
|
||||
: MODE_LOW;
|
||||
|
||||
//
|
||||
result = swing == X_SWING_HIGH
|
||||
? iHighest(
|
||||
symbol,
|
||||
period,
|
||||
mMode,
|
||||
mLength,
|
||||
from)
|
||||
: iLowest(
|
||||
symbol,
|
||||
period,
|
||||
mMode,
|
||||
mLength,
|
||||
from);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Lowest Bar Index ...
|
||||
int FindHighestIndex(
|
||||
|
||||
@@ -1840,13 +1840,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
|
||||
ENUM_ORDER_TYPE 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
|
||||
string mSymbol = NULL, // Trading Symbol
|
||||
string mProvider = NULL, // Signal Provider
|
||||
ENUM_TIMEFRAMES mPeriod = NULL, // Trading Timeframe
|
||||
ENUM_X_POSITION_TYPE 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
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -3374,8 +3374,8 @@ bool IsTypeFilterPassed(
|
||||
//
|
||||
bool result = type == NULL || type == X_POSITION_TYPE_ALL
|
||||
? true
|
||||
: ((type == X_POSITION_TYPE_LONG && item.type == POSITION_TYPE_BUY) ||
|
||||
(type == X_POSITION_TYPE_SHORT && item.type == POSITION_TYPE_SELL));
|
||||
: ((type == X_POSITION_TYPE_LONG && ((int)item.type == (int)POSITION_TYPE_BUY || (int)item.type == (int)ORDER_TYPE_BUY)) ||
|
||||
(type == X_POSITION_TYPE_SHORT && ((int)item.type == (int)POSITION_TYPE_SELL || (int)item.type == (int)ORDER_TYPE_SELL)));
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -4319,4 +4319,225 @@ void CountPositions(
|
||||
shortVolumes = iPosition.volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Drawings ...
|
||||
bool DrawTrendState(
|
||||
long chartId,
|
||||
string _prefix,
|
||||
XOHCL &_bar,
|
||||
double &support,
|
||||
double &resistance,
|
||||
int shoulders = 10,
|
||||
int subWindow = 0,
|
||||
color resistanceColor = clrRed,
|
||||
color supportColor = clrGreen,
|
||||
color swingHighColor = clrAqua,
|
||||
color swingLowColor = clrMagenta //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(_prefix) &&
|
||||
_bar.IsValid()
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Low Swings ...
|
||||
|
||||
//
|
||||
int firstSwingLowIndex = FindSwing(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
X_SWING_LOW,
|
||||
shoulders,
|
||||
_bar.Index() + 1 //
|
||||
);
|
||||
XOHCL firstSwingLowBar;
|
||||
result = firstSwingLowBar.Init(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
firstSwingLowIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int secondSwingLowIndex = FindSwing(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
X_SWING_LOW,
|
||||
shoulders,
|
||||
firstSwingLowIndex + 1 //
|
||||
);
|
||||
XOHCL secondSwingLowBar;
|
||||
result = secondSwingLowBar.Init(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
secondSwingLowIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
support = secondSwingLowBar.low;
|
||||
|
||||
//
|
||||
string lowSwingTrendLineName = _prefix + "_Low_Swing_Trend";
|
||||
|
||||
//
|
||||
result = DrawTrendLine(
|
||||
chartId,
|
||||
lowSwingTrendLineName,
|
||||
subWindow,
|
||||
secondSwingLowBar.time,
|
||||
secondSwingLowBar.low,
|
||||
firstSwingLowBar.time,
|
||||
firstSwingLowBar.low,
|
||||
swingLowColor,
|
||||
STYLE_SOLID,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
true // Ray Right ...
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string lowSwingSupportLineName = _prefix + "_Low_Swing_Support";
|
||||
|
||||
//
|
||||
result = DrawTrendLine(
|
||||
chartId,
|
||||
lowSwingSupportLineName,
|
||||
subWindow,
|
||||
secondSwingLowBar.time,
|
||||
secondSwingLowBar.low,
|
||||
firstSwingLowBar.time,
|
||||
secondSwingLowBar.low,
|
||||
supportColor,
|
||||
STYLE_SOLID,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
true // Ray Right ...
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find High Swings ...
|
||||
|
||||
//
|
||||
int firstSwingHighIndex = FindSwing(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
X_SWING_HIGH,
|
||||
shoulders,
|
||||
_bar.Index() + 1 //
|
||||
);
|
||||
XOHCL firstSwingHighBar;
|
||||
result = firstSwingHighBar.Init(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
firstSwingHighIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int secondSwingHighIndex = FindSwing(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
X_SWING_HIGH,
|
||||
shoulders,
|
||||
firstSwingHighIndex + 1 //
|
||||
);
|
||||
XOHCL secondSwingHighBar;
|
||||
result = secondSwingHighBar.Init(
|
||||
_bar.symbol,
|
||||
_bar.period,
|
||||
secondSwingHighIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
resistance = secondSwingHighBar.high;
|
||||
|
||||
//
|
||||
string highSwingTrendLineName = _prefix + "_High_Swing_Trend";
|
||||
|
||||
//
|
||||
result = DrawTrendLine(
|
||||
chartId,
|
||||
highSwingTrendLineName,
|
||||
subWindow,
|
||||
secondSwingHighBar.time,
|
||||
secondSwingHighBar.high,
|
||||
firstSwingHighBar.time,
|
||||
firstSwingHighBar.high,
|
||||
swingHighColor,
|
||||
STYLE_SOLID,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
true // Ray Right ...
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string highSwingResistanceLineName = _prefix + "_High_Swing_Resistance";
|
||||
|
||||
//
|
||||
result = DrawTrendLine(
|
||||
chartId,
|
||||
highSwingResistanceLineName,
|
||||
subWindow,
|
||||
secondSwingHighBar.time,
|
||||
secondSwingHighBar.high,
|
||||
firstSwingHighBar.time,
|
||||
secondSwingHighBar.high,
|
||||
resistanceColor,
|
||||
STYLE_SOLID,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
true // Ray Right ...
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user