last ...
This commit is contained in:
@@ -37,13 +37,17 @@ public:
|
||||
void XSCXSRBRStrategy(
|
||||
//
|
||||
// Base ...
|
||||
string _symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES _period, // Trading TimeFrame
|
||||
ENUM_TIMEFRAMES _analyzingPeriod, // Analyzing Timeframe
|
||||
double _volume, // Voluem
|
||||
double _r2r, // Risk/Reward Ratio
|
||||
int _slippage, // Trader Slippage
|
||||
long _magicNumber, // Trader Magic Number
|
||||
string _symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES _period, // Trading TimeFrame
|
||||
ENUM_TIMEFRAMES _analyzingPeriod, // Analyzing Timeframe
|
||||
double _volume, // Voluem
|
||||
double _r2r, // Risk/Reward Ratio
|
||||
int _slippage, // Trader Slippage
|
||||
long _magicNumber, // Trader Magic Number
|
||||
bool _useTPSLAsPoint = false, // Converts TP and SL by Provided Points
|
||||
bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points
|
||||
double _tpPoint = 0, // TP As Point
|
||||
double _slPoint = 0, // SL As Point
|
||||
bool _allowLong = true,
|
||||
bool _allowShort = true,
|
||||
int _maxAllowedLongs = 0,
|
||||
@@ -55,6 +59,10 @@ public:
|
||||
_r2r,
|
||||
_slippage,
|
||||
_magicNumber,
|
||||
_useTPSLAsPoint,
|
||||
_forceMaxTPSLAsPoint,
|
||||
_tpPoint,
|
||||
_slPoint,
|
||||
_allowLong,
|
||||
_allowShort,
|
||||
_maxAllowedLongs,
|
||||
@@ -105,7 +113,7 @@ public:
|
||||
double entry = 0;
|
||||
double reward = 0;
|
||||
double r2r = R2R();
|
||||
ENUM_POSITION_TYPE type;
|
||||
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
@@ -139,16 +147,6 @@ public:
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
double hh4 = cBar.FindHighest(
|
||||
4,
|
||||
MODE_HIGH //
|
||||
);
|
||||
double ll4 = cBar.FindHighest(
|
||||
4,
|
||||
MODE_LOW //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Analyzing Period Contains a Trend or not ...
|
||||
|
||||
@@ -158,16 +156,33 @@ public:
|
||||
bool isInBearishTrend = false;
|
||||
|
||||
//
|
||||
isInBullishTrend = cBar.HasBullishTrend(
|
||||
// Verify Pressure for Signals ...
|
||||
bool verifyPressure = true;
|
||||
bool checkTrensByMethod2 = false;
|
||||
|
||||
//
|
||||
bool checkHammer = false;
|
||||
bool checkMorningStar = false;
|
||||
bool checkBullishEngulfing = true;
|
||||
|
||||
//
|
||||
bool checkShootingStar = false;
|
||||
bool checkEveningStar = false;
|
||||
bool checkBearishEngulfing = true;
|
||||
|
||||
//
|
||||
isInBullishTrend = bar.HasBullishTrend(
|
||||
highSwingBars,
|
||||
lowSwingBars //
|
||||
lowSwingBars,
|
||||
checkTrensByMethod2 //
|
||||
);
|
||||
if (!isInBullishTrend)
|
||||
{
|
||||
//
|
||||
isInBearishTrend = cBar.HasBearishTrend(
|
||||
isInBearishTrend = bar.HasBearishTrend(
|
||||
highSwingBars,
|
||||
lowSwingBars //
|
||||
lowSwingBars,
|
||||
checkTrensByMethod2 //
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,9 +191,37 @@ public:
|
||||
result = isInBullishTrend || isInBearishTrend;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
ResetRequirements();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (isInBullishTrend)
|
||||
{
|
||||
//
|
||||
DrawBullishTrend(
|
||||
cBar,
|
||||
highSwingBars,
|
||||
lowSwingBars,
|
||||
ChartID(),
|
||||
true,
|
||||
true //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
DrawBearishTrend(
|
||||
cBar,
|
||||
highSwingBars,
|
||||
lowSwingBars,
|
||||
ChartID(),
|
||||
true,
|
||||
true //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Here We have to Decide Trend or Reversal Act ...
|
||||
|
||||
@@ -215,47 +258,31 @@ public:
|
||||
XOHCL tmpSWH[];
|
||||
XOHCL tmpSWL[];
|
||||
|
||||
//
|
||||
bool isSupportRejected = IsSupportRejected(support, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
|
||||
bool isResistanceBreaked = IsResistanceBreaked(resistance, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
|
||||
|
||||
//
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
tmpSWH,
|
||||
tmpSWL,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Check Price Place ...
|
||||
(
|
||||
//
|
||||
(ll4 < support.high ||
|
||||
(MathAbs(ll4 - support.high) <= threshold))
|
||||
//
|
||||
&&
|
||||
//
|
||||
hh4 > support.high
|
||||
//
|
||||
)
|
||||
isBullishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Candlestick Pattern ...
|
||||
(
|
||||
//
|
||||
cBar.HasBullishTrend(
|
||||
tmpSWH,
|
||||
tmpSWL,
|
||||
true //
|
||||
)
|
||||
isSupportRejected
|
||||
//
|
||||
&&
|
||||
||
|
||||
//
|
||||
(
|
||||
//
|
||||
cBar.IsHammer()
|
||||
//
|
||||
||
|
||||
//
|
||||
cBar.IsMorningStar()
|
||||
//
|
||||
||
|
||||
//
|
||||
cBar.IsBullishEngulfing()
|
||||
//
|
||||
)
|
||||
isResistanceBreaked
|
||||
//
|
||||
)
|
||||
//
|
||||
@@ -266,10 +293,28 @@ public:
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_BUY;
|
||||
sl = support.low - threshold;
|
||||
|
||||
//
|
||||
support.Clean();
|
||||
if (isSupportRejected)
|
||||
{
|
||||
//
|
||||
sl = support.low - threshold;
|
||||
RemoveSupport(support);
|
||||
support.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (isResistanceBreaked)
|
||||
{
|
||||
//
|
||||
sl = resistance.low - threshold;
|
||||
RemoveResistance(resistance);
|
||||
resistance.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
RemoveDraws(XTLSBullishTrendToken);
|
||||
RemoveDraws(XTLSBearishTrendToken);
|
||||
}
|
||||
}
|
||||
else if (isInBearishTrend)
|
||||
@@ -283,47 +328,31 @@ public:
|
||||
XOHCL tmpSWH[];
|
||||
XOHCL tmpSWL[];
|
||||
|
||||
//
|
||||
bool isSupportBreaked = IsSupportBreaked(support, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
|
||||
bool isResistanceRejected = IsResistanceRejected(resistance, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
|
||||
|
||||
//
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpSWH,
|
||||
tmpSWL,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Check Price Place ...
|
||||
(
|
||||
//
|
||||
(hh4 > resistance.low ||
|
||||
(MathAbs(hh4 - resistance.low) <= threshold))
|
||||
//
|
||||
&&
|
||||
//
|
||||
ll4 < resistance.low
|
||||
//
|
||||
)
|
||||
isBearishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Candlestick Pattern ...
|
||||
(
|
||||
//
|
||||
cBar.HasBearishTrend(
|
||||
tmpSWH,
|
||||
tmpSWL,
|
||||
true //
|
||||
)
|
||||
isSupportBreaked
|
||||
//
|
||||
&&
|
||||
||
|
||||
//
|
||||
(
|
||||
//
|
||||
cBar.IsShootingStar()
|
||||
//
|
||||
||
|
||||
//
|
||||
cBar.IsEveningStar()
|
||||
//
|
||||
||
|
||||
//
|
||||
cBar.IsBearishEngulfing()
|
||||
//
|
||||
)
|
||||
isResistanceRejected
|
||||
//
|
||||
)
|
||||
//
|
||||
@@ -334,13 +363,35 @@ public:
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_SELL;
|
||||
sl = resistance.high + threshold;
|
||||
|
||||
//
|
||||
resistance.Clean();
|
||||
if (isSupportBreaked)
|
||||
{
|
||||
//
|
||||
sl = support.high + threshold;
|
||||
RemoveSupport(support);
|
||||
support.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (isResistanceRejected)
|
||||
{
|
||||
//
|
||||
sl = resistance.high + threshold;
|
||||
RemoveResistance(resistance);
|
||||
resistance.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
RemoveDraws(XTLSBullishTrendToken);
|
||||
RemoveDraws(XTLSBearishTrendToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Trend Reversal Direction Signal ...
|
||||
@@ -356,12 +407,68 @@ public:
|
||||
// since we are in Bullish Trend and
|
||||
// we must do Trend Reversal Trading ...
|
||||
|
||||
//
|
||||
XOHCL tmpSWH[];
|
||||
XOHCL tmpSWL[];
|
||||
|
||||
//
|
||||
bool isSupportBreaked = IsSupportBreaked(support, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
|
||||
bool isResistanceRejected = IsResistanceRejected(resistance, verifyPressure, checkShootingStar, checkEveningStar, checkBearishEngulfing);
|
||||
|
||||
//
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpSWH,
|
||||
tmpSWL,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
false
|
||||
true // isBearishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isSupportBreaked
|
||||
//
|
||||
||
|
||||
//
|
||||
isResistanceRejected
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_SELL;
|
||||
|
||||
//
|
||||
if (isSupportBreaked)
|
||||
{
|
||||
//
|
||||
sl = support.high + threshold;
|
||||
RemoveSupport(support);
|
||||
support.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (isResistanceRejected)
|
||||
{
|
||||
//
|
||||
sl = resistance.high + threshold;
|
||||
RemoveResistance(resistance);
|
||||
resistance.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
RemoveDraws(XTLSBullishTrendToken);
|
||||
RemoveDraws(XTLSBearishTrendToken);
|
||||
}
|
||||
}
|
||||
else if (isInBearishTrend)
|
||||
{
|
||||
@@ -370,12 +477,68 @@ public:
|
||||
// since we are in Bearish Trend and
|
||||
// we must do Trend Reversal Trading ...
|
||||
|
||||
//
|
||||
XOHCL tmpSWH[];
|
||||
XOHCL tmpSWL[];
|
||||
|
||||
//
|
||||
bool isSupportRejected = IsSupportRejected(support, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
|
||||
bool isResistanceBreaked = IsResistanceBreaked(resistance, verifyPressure, checkHammer, checkMorningStar, checkBullishEngulfing);
|
||||
|
||||
//
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
tmpSWH,
|
||||
tmpSWL,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
false
|
||||
true // isBullishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isSupportRejected
|
||||
//
|
||||
||
|
||||
//
|
||||
isResistanceBreaked
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
if (isSupportRejected)
|
||||
{
|
||||
//
|
||||
sl = support.low - threshold;
|
||||
RemoveSupport(support);
|
||||
support.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (isResistanceBreaked)
|
||||
{
|
||||
//
|
||||
sl = resistance.low - threshold;
|
||||
RemoveResistance(resistance);
|
||||
resistance.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
RemoveDraws(XTLSBullishTrendToken);
|
||||
RemoveDraws(XTLSBearishTrendToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,12 +546,18 @@ public:
|
||||
// Make Sure Signal Exists ...
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
RemoveDraws(XTLSBullishTrendToken);
|
||||
RemoveDraws(XTLSBearishTrendToken);
|
||||
|
||||
//
|
||||
ResetRequirements();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
entry = GetEntry(mSymbol, type);
|
||||
CalculateTPSLBtPrice(
|
||||
CalculateTPSLByPrice(
|
||||
sl,
|
||||
tp,
|
||||
type,
|
||||
@@ -467,12 +636,18 @@ private:
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (support.IsValid())
|
||||
{
|
||||
RemoveSupport(support);
|
||||
}
|
||||
|
||||
//
|
||||
// Finding Analyzing Bar ...
|
||||
result = bar.Init(
|
||||
mSymbol,
|
||||
mPeriod, // mAnalyzingPeriod,
|
||||
1 //
|
||||
mAnalyzingPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
@@ -489,12 +664,24 @@ private:
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawSupport(support, ChartID(), 5);
|
||||
|
||||
//
|
||||
if (resistance.IsValid())
|
||||
{
|
||||
RemoveResistance(resistance);
|
||||
}
|
||||
|
||||
//
|
||||
// Find Resistance Bar based on Analyzing Bar ...
|
||||
result = bar.HasResistance(
|
||||
resistance //
|
||||
);
|
||||
|
||||
//
|
||||
DrawResistance(resistance, ChartID(), 5);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -504,6 +691,20 @@ private:
|
||||
void ResetRequirements()
|
||||
{
|
||||
//
|
||||
if (IsSupportBreaked(support, false))
|
||||
{
|
||||
//
|
||||
RemoveSupport(support);
|
||||
support.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (IsResistanceBreaked(resistance, false))
|
||||
{
|
||||
//
|
||||
RemoveResistance(resistance);
|
||||
resistance.Clean();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user