This commit is contained in:
2024-07-17 19:23:17 +03:30
parent 3294ea9f21
commit b4bc3774b0
6 changed files with 1355 additions and 131 deletions
+149 -6
View File
@@ -21,6 +21,7 @@
//
/// Imports ...
#include "../Libraries/x-saherelm.tools.lib.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
#include "../Classes/x-saherelm.xalert.class.mq5"
@@ -45,12 +46,16 @@ public:
//
// Constructors ...
void XSCBaseStrategy(
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period, // Trading 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
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,
@@ -63,12 +68,16 @@ public:
mVolume = _volume;
mSymbol = _symbol;
mPeriod = _period;
mTPPoint = _tpPoint;
mSLPoint = _slPoint;
mSlippage = _slippage;
mAllowLong = _allowLong;
mAllowShort = _allowShort;
mMagicNumber = _magicNumber;
mUseTPSLAsPoint = _useTPSLAsPoint;
mMaxAllowedLongs = _maxAllowedLongs;
mMaxAllowedShorts = _maxAllowedShorts;
mForceMaxTPSLAsPoint = _forceMaxTPSLAsPoint;
//
mForceDisabled = false;
@@ -272,6 +281,68 @@ public:
mRequiredShoulders = value;
}
//
bool UseTPSLAsPoint()
{
return mUseTPSLAsPoint;
}
//
void UseTPSLAsPoint(bool value)
{
mUseTPSLAsPoint = value;
}
//
bool ForceMaxTPSLAsPoint()
{
return mForceMaxTPSLAsPoint;
}
//
void ForceMaxTPSLAsPoint(bool value)
{
mForceMaxTPSLAsPoint = value;
}
//
double TPPoint()
{
return mTPPoint;
}
//
void TPPoint(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mTPPoint = value;
}
//
double SLPoint()
{
return mSLPoint;
}
//
void SLPoint(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mSLPoint = value;
}
//
// Virtual Methods ...
@@ -423,6 +494,72 @@ public:
}
}
//
// Check TP and SL ...
double points = GetPoints(signal.symbol);
if (mUseTPSLAsPoint)
{
//
double sl = 0;
double tp = 0;
bool isCalculated = !(mSLPoint > 0 || mTPPoint > 0)
? false
: CalculateTPSLByPoint(
sl,
tp,
signal.type,
signal.entry,
points,
mR2R,
mSLPoint,
mTPPoint //
);
if (isCalculated)
{
//
signal.sl = sl;
signal.tp = tp;
}
}
else if (mForceMaxTPSLAsPoint)
{
//
if (mSLPoint > 0)
{
//
double risk = signal.GetRisk();
double riskPoints = risk / points;
//
if (riskPoints > mSLPoint)
{
//
signal.sl =
isLong
? signal.entry - (mSLPoint * points)
: signal.entry + (mSLPoint * points);
}
}
//
if (mTPPoint > 0)
{
//
double reward = signal.GetReward();
double rewardPoints = reward / points;
//
if (rewardPoints > mTPPoint)
{
//
signal.tp =
isLong
? signal.entry + (mTPPoint * points)
: signal.entry - (mTPPoint * points);
}
}
}
//
ENUM_X_SIGNAL_EXECUTION_RESULT state;
result = trader.ExecuteSignal(
@@ -474,6 +611,12 @@ protected:
int mMaxAllowedLongs; // Max Allowed Longs
int mMaxAllowedShorts; // Max Allowed Shorts
//
bool mUseTPSLAsPoint; // Converts TP and SL by Provided Points
bool mForceMaxTPSLAsPoint; // Force Max TP and SL by Provided Points
double mTPPoint; // TP As Point
double mSLPoint; // SL As Point
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...
+99
View File
@@ -5310,3 +5310,102 @@ int pivotsCount = ArraySize(pivots);
mSetups[i].ForceState(false);
}
}
///////////////////////////////////////////////////////////
// //
// result =
// //
// // Check Price Place ...
// (
// //
// (hh4 > resistance.low ||
// (MathAbs(hh4 - resistance.low) <= threshold))
// //
// &&
// //
// ll4 < resistance.low
// //
// )
// //
// &&
// //
// // Check Candlestick Pattern ...
// (
// //
// cBar.HasBearishTrend(
// tmpSWH,
// tmpSWL,
// true //
// )
// //
// &&
// //
// (
// //
// cBar.IsShootingStar()
// //
// ||
// //
// cBar.IsEveningStar()
// //
// ||
// //
// cBar.IsBearishEngulfing()
// //
// )
// //
// )
// //
// ;
// //
// result =
// //
// // Check Price Place ...
// (
// //
// (ll4 < support.high ||
// (MathAbs(ll4 - support.high) <= threshold))
// //
// &&
// //
// hh4 > support.high
// //
// )
// //
// &&
// //
// // Check Candlestick Pattern ...
// (
// //
// cBar.HasBullishTrend(
// tmpSWH,
// tmpSWL,
// true //
// )
// //
// &&
// //
// (
// //
// cBar.IsHammer()
// //
// ||
// //
// cBar.IsMorningStar()
// //
// ||
// //
// cBar.IsBullishEngulfing()
// //
// )
// //
// )
// //
// ;
+67 -3
View File
@@ -197,15 +197,79 @@ bool InitialEA()
1.5, // R2R ...
mSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
200, // TP
100, // SL
eaAllowLong,
eaAllowShort,
0, // Max Longs
0, // Max Shorts
X_SIGNALLING_TREND_DIRECTION //
0, // Max Longs
0, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdM5SRBRStrategy);
//
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *eurusdM15SRBRStrategy;
eurusdM15SRBRStrategy = new XSCXSRBRStrategy(
eurusdSymbol,
PERIOD_M15,
PERIOD_M30,
eaVolume,
1.5, // R2R ...
mSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
200, // TP
100, // SL
eaAllowLong,
eaAllowShort,
0, // Max Longs
0, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
eurusdM15SRBRStrategy.SetAlertLogAlerts(true);
eurusdM15SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(eurusdM15SRBRStrategy);
}
//
// USDCHF ...
string usdchfSymbol = "USDCHFb";
if (IsValid(usdchfSymbol))
{
//
// MAGIC NUMBER ...
long magicNumber = mMagicNumber + 2;
//
// Register XSRBR on EURUSD in M5 ...
XSCXSRBRStrategy *usdchfM5SRBRStrategy;
usdchfM5SRBRStrategy = new XSCXSRBRStrategy(
usdchfSymbol,
PERIOD_M5,
PERIOD_H1,
eaVolume,
1.5, // R2R ...
mSlippage,
magicNumber,
true, // Use TP SL Point
false, // Use Max
200, // TP
100, // SL
eaAllowLong,
eaAllowShort,
0, // Max Longs
0, // Max Shorts
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
);
usdchfM5SRBRStrategy.SetAlertLogAlerts(true);
usdchfM5SRBRStrategy.SetAlertEnableAlerts(true);
RegisterStrategy(usdchfM5SRBRStrategy);
}
//
+1 -1
View File
@@ -6411,7 +6411,7 @@ bool CalculateTPSLByPoint(
}
//
bool CalculateTPSLBtPrice(
bool CalculateTPSLByPrice(
double &mSL, // Hold SL
double &mTP, // Hold TP
ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell)
+745 -28
View File
@@ -26,6 +26,693 @@
//
// Definitions ...
string XTLSHammerToken = "XHammer";
string XTLSSupportToken = "XSupport";
string XTLSSwingLowToken = "XSwingLow";
string XTLSSwingHighToken = "XSwingHigh";
string XTLSResistanceToken = "XResistance";
string XTLSBullishFVGToken = "XBullishFVG";
string XTLSBearishFVGToken = "XBearishFVG";
string XTLSMorningStarToken = "XMorningStar";
string XTLSEveningStarToken = "XEveningStar";
string XTLSShootingStarToken = "XShootingStar";
string XTLSBullishTrendToken = "XBullishTrend";
string XTLSBearishTrendToken = "XBearishTrend";
string XTLSBullishEngulfingToken = "XBullishEngulfing";
string XTLSBearishEngulfingToken = "XBearishEngulfing";
string XTLSBullishOrderBlockToken = "XBullishOrderBlock";
string XTLSBearishOrderBlockToken = "XBearishOrderBlock";
//
// Helper Tools ...
//
bool IsSupportBreaked(
XOHCL &bar, // Support Bar
bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure
bool checkShootingStar = true, // Check Shooting Star Pattern for Pressure Verifications
bool checkEveningStar = true, // Check Evening Star Pattern for Pressure Verifications
bool checkBearishEngulfingStar = true, // Check Bearish Engulfing Pattern for Pressure Verifications
double _threshold = 0, // Upper and Lower threshold of Pivot
double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break
int _loopback = 3 // Verification Loopback
)
{
//
bool result = false;
//
if (_breakVerificationPoint < 0)
{
_breakVerificationPoint = 15;
}
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
double points = GetPoints(bar.symbol);
//
double threshold = 0;
if (_threshold > 0)
{
threshold = _threshold * points;
}
//
double price = GetBid(bar.symbol);
//
// Check Price is Below of Support High ...
result = price < bar.high + threshold;
if (!result)
{
return result;
}
//
// Check Break Verification ...
if (_breakVerificationPoint > 0)
{
//
result = (bar.high + threshold) - price >= _breakVerificationPoint * points;
if (!result)
{
return result;
}
}
//
if (_verifyPressure && _loopback > 0)
{
//
// Verify Pressure by Candlestick Patterns ...
// We need last 3 Candle ...
//
for (int i = 0; i < _loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
// Shooting Star ...
bool isShootingStar = !checkShootingStar
? false
: iBar.IsShootingStar();
if (isShootingStar)
{
//
DrawShootingStar(
iBar,
ChartID() //
);
}
//
// Evening Star ...
bool isEveningStar = !checkEveningStar
? false
: iBar.IsEveningStar();
if (isEveningStar)
{
//
DrawEveningStar(
iBar,
ChartID() //
);
}
//
// BearishEngulfing ...
bool isBearishEngulfing = !checkBearishEngulfingStar
? false
: iBar.IsBearishEngulfing();
if (isBearishEngulfing)
{
//
DrawBearishEngulfing(
iBar,
ChartID() //
);
}
//
result =
//
isShootingStar
//
||
//
isEveningStar
//
||
//
isBearishEngulfing
//
;
if (result)
{
break;
}
}
}
//
return result;
}
//
bool IsSupportRejected(
XOHCL &bar, // Support Bar
bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure
bool checkHammer = true, // Check Hammer Pattern for Pressure Verifications
bool checkMorningStar = true, // Check Morning Star Pattern for Pressure Verifications
bool checkBullishEngulfing = true, // Check Bullish Engulfing Pattern for Pressure Verifications
double _threshold = 0, // Upper and Lower threshold of Pivot
double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break
int _loopback = 3 // Verification Loopback
)
{
//
bool result = false;
//
if (_breakVerificationPoint < 0)
{
_breakVerificationPoint = 15;
}
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
double points = GetPoints(bar.symbol);
//
double threshold = 0;
if (_threshold > 0)
{
threshold = _threshold * points;
}
//
double price = GetBid(bar.symbol);
//
XOHCL cBar;
result = cBar.Init(
bar.symbol,
bar.period,
0 //
);
if (!result)
{
return result;
}
//
double ll2 = cBar.FindLowest(
2,
MODE_LOW //
);
//
// Check Price is Below of Support High ...
result =
//
price > bar.high + threshold &&
(
//
ll2 < bar.high
//
||
//
ll2 < bar.high - threshold
//
||
//
(threshold > 0 && MathAbs(ll2 - price) > 0 && MathAbs(ll2 - price) <= threshold)
//
)
//
;
if (!result)
{
return result;
}
//
// Check Break Verification ...
if (_breakVerificationPoint > 0)
{
//
result = MathAbs((bar.high + threshold) - price) >= _breakVerificationPoint * points;
if (!result)
{
return result;
}
}
//
if (_verifyPressure && _loopback > 0)
{
//
// Verify Pressure by Candlestick Patterns ...
// We need last 3 Candle ...
//
for (int i = 0; i < _loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
// Hammer ...
bool isHammer = !checkHammer
? false
: iBar.IsHammer();
if (isHammer)
{
//
DrawHammer(
iBar,
ChartID() //
);
}
//
// Morning Star ...
bool isMorningStar = !checkMorningStar
? false
: iBar.IsMorningStar();
if (isMorningStar)
{
//
DrawMorningStar(
iBar,
ChartID() //
);
}
//
// BullishEngulfing ...
bool isBullishEngulfing = !checkBullishEngulfing
? false
: iBar.IsBullishEngulfing();
if (isBullishEngulfing)
{
//
DrawBullishEngulfing(
iBar,
ChartID() //
);
}
//
result =
//
isHammer
//
||
//
isMorningStar
//
||
//
isBullishEngulfing
//
;
if (result)
{
break;
}
}
}
//
return result;
}
//
bool IsResistanceBreaked(
XOHCL &bar, // Resistance Bar
bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure
bool checkHammer = true, // Check Hammer Pattern for Pressure Verifications
bool checkMorningStar = true, // Check Morning Star Pattern for Pressure Verifications
bool checkBullishEngulfing = true, // Check Bullish Engulfing Pattern for Pressure Verifications
double _threshold = 0, // Upper and Lower threshold of Pivot
double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break
int _loopback = 3 // Verification Loopback
)
{
//
bool result = false;
//
if (_breakVerificationPoint < 0)
{
_breakVerificationPoint = 15;
}
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
double points = GetPoints(bar.symbol);
//
double threshold = 0;
if (_threshold > 0)
{
threshold = _threshold * points;
}
//
double price = GetBid(bar.symbol);
//
// Check Price is Below of Support High ...
result = price > bar.low - threshold;
if (!result)
{
return result;
}
//
// Check Break Verification ...
if (_breakVerificationPoint > 0)
{
//
result = price - (bar.low - threshold) >= _breakVerificationPoint * points;
if (!result)
{
return result;
}
}
//
if (_verifyPressure && _loopback > 0)
{
//
// Verify Pressure by Candlestick Patterns ...
// We need last 3 Candle ...
//
for (int i = 0; i < _loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
// Hammer ...
bool isHammer = !checkHammer
? false
: iBar.IsHammer();
if (isHammer)
{
//
DrawHammer(
iBar,
ChartID() //
);
}
//
// Morning Star ...
bool isMorningStar = !checkMorningStar
? false
: iBar.IsMorningStar();
if (isMorningStar)
{
//
DrawMorningStar(
iBar,
ChartID() //
);
}
//
// BullishEngulfing ...
bool isBullishEngulfing = !checkBullishEngulfing
? false
: iBar.IsBullishEngulfing();
if (isBullishEngulfing)
{
//
DrawBullishEngulfing(
iBar,
ChartID() //
);
}
//
result =
//
isHammer
//
||
//
isMorningStar
//
||
//
isBullishEngulfing
//
;
if (result)
{
break;
}
}
}
//
return result;
}
//
bool IsResistanceRejected(
XOHCL &bar, // Resistance Bar
bool _verifyPressure = true, // Verify Candlestick Patterns for Prove Pressure
bool checkShootingStar = true, // Check Shooting Star Pattern for Pressure Verifications
bool checkEveningStar = true, // Check Evening Star Pattern for Pressure Verifications
bool checkBearishEngulfingStar = true, // Check Bearish Engulfing Pattern for Pressure Verifications
double _threshold = 0, // Upper and Lower threshold of Pivot
double _breakVerificationPoint = 15, // Price Distance for Verify Pivot Break
int _loopback = 3 // Verification Loopback
)
{
//
bool result = false;
//
if (_breakVerificationPoint < 0)
{
_breakVerificationPoint = 15;
}
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
double points = GetPoints(bar.symbol);
//
double threshold = 0;
if (_threshold > 0)
{
threshold = _threshold * points;
}
//
double price = GetBid(bar.symbol);
//
XOHCL cBar;
result = cBar.Init(
bar.symbol,
bar.period,
0 //
);
if (!result)
{
return result;
}
//
double hh2 = cBar.FindHighest(
2,
MODE_HIGH //
);
//
// Check Price is Below of Support High ...
result =
//
price < bar.low - threshold &&
(
//
hh2 > bar.low
//
||
//
hh2 > bar.low - threshold
//
||
//
(threshold > 0 && MathAbs(hh2 - price) > 0 && MathAbs(hh2 - price) <= threshold))
//
;
if (!result)
{
return result;
}
//
// Check Break Verification ...
if (_breakVerificationPoint > 0)
{
//
result = MathAbs((bar.low - threshold) - price) >= _breakVerificationPoint * points;
if (!result)
{
return result;
}
}
//
if (_verifyPressure && _loopback > 0)
{
//
// Verify Pressure by Candlestick Patterns ...
// We need last 3 Candle ...
//
for (int i = 0; i < _loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
// Shooting Star ...
bool isShootingStar = !checkShootingStar
? false
: iBar.IsShootingStar();
if (isShootingStar)
{
//
DrawShootingStar(
iBar,
ChartID() //
);
}
//
// Evening Star ...
bool isEveningStar = !checkEveningStar
? false
: iBar.IsEveningStar();
if (isEveningStar)
{
//
DrawEveningStar(
iBar,
ChartID() //
);
}
//
// BearishEngulfing ...
bool isBearishEngulfing = !checkBearishEngulfingStar
? false
: iBar.IsBearishEngulfing();
if (isBearishEngulfing)
{
//
DrawBearishEngulfing(
iBar,
ChartID() //
);
}
//
result =
//
isShootingStar
//
||
//
isEveningStar
//
||
//
isBearishEngulfing
//
;
if (result)
{
break;
}
}
}
//
return result;
}
//
// Drawing Tools ...
@@ -36,7 +723,7 @@
//
string GetHammerTag(XOHCL &bar)
{
return "Hammer-" + GetBarTimeTag(bar);
return XTLSHammerToken + "-" + GetBarTimeTag(bar);
}
//
@@ -84,7 +771,7 @@ void RemoveHammer(XOHCL &bar)
//
string GetShootingStarTag(XOHCL &bar)
{
return "ShootingStar-" + GetBarTimeTag(bar);
return XTLSShootingStarToken + "-" + GetBarTimeTag(bar);
}
//
@@ -132,7 +819,7 @@ void RemoveShootingStar(XOHCL &bar)
//
string GetBullishEngulfingTag(XOHCL &bar)
{
return "BullishEngulfing-" + GetBarTimeTag(bar);
return XTLSBullishEngulfingToken + "-" + GetBarTimeTag(bar);
}
//
@@ -190,7 +877,7 @@ void RemoveBullishEngulfing(XOHCL &bar)
//
string GetBearishEngulfingTag(XOHCL &bar)
{
return "BearishEngulfing-" + GetBarTimeTag(bar);
return XTLSBearishEngulfingToken + "-" + GetBarTimeTag(bar);
}
//
@@ -248,7 +935,7 @@ void RemoveBearishEngulfing(XOHCL &bar)
//
string GetMorningStarTag(XOHCL &bar)
{
return "MorningStar-" + GetBarTimeTag(bar);
return XTLSMorningStarToken + "-" + GetBarTimeTag(bar);
}
//
@@ -296,7 +983,7 @@ void RemoveMorningStar(XOHCL &bar)
//
string GetEveningStarTag(XOHCL &bar)
{
return "EveningStar-" + GetBarTimeTag(bar);
return XTLSEveningStarToken + "-" + GetBarTimeTag(bar);
}
//
@@ -344,7 +1031,7 @@ void RemoveEveningStar(XOHCL &bar)
//
string GetSwingHighTag(XOHCL &bar)
{
return "SwingHigh-" + GetBarTimeTag(bar);
return XTLSSwingHighToken + "-" + GetBarTimeTag(bar);
}
//
@@ -392,7 +1079,7 @@ void RemoveSwingHigh(XOHCL &bar)
//
string GetSwingLowTag(XOHCL &bar)
{
return "SwingLow-" + GetBarTimeTag(bar);
return XTLSSwingLowToken + "-" + GetBarTimeTag(bar);
}
//
@@ -440,7 +1127,7 @@ void RemoveSwingLow(XOHCL &bar)
//
string GetBullishFVGTag(XOHCL &bar)
{
return "BullishFVG-" + GetBarTimeTag(bar);
return XTLSBullishFVGToken + "-" + GetBarTimeTag(bar);
}
//
@@ -508,7 +1195,7 @@ void RemoveBullishFVG(XOHCL &bar)
//
string GetBearishFVGTag(XOHCL &bar)
{
return "BearishFVG-" + GetBarTimeTag(bar);
return XTLSBearishFVGToken + "-" + GetBarTimeTag(bar);
}
//
@@ -576,7 +1263,7 @@ void RemoveBearishFVG(XOHCL &bar)
//
string GetBullishOrderBlockTag(XOHCL &bar)
{
return "BullishOrderBlock-" + GetBarTimeTag(bar);
return XTLSBullishOrderBlockToken + "-" + GetBarTimeTag(bar);
}
//
@@ -613,7 +1300,8 @@ bool DrawBullishOrderBlock(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -634,7 +1322,8 @@ bool DrawBullishOrderBlock(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -654,7 +1343,7 @@ void RemoveBullishOrderBlock(XOHCL &bar)
//
string GetBearishOrderBlockTag(XOHCL &bar)
{
return "BearishOrderBlock-" + GetBarTimeTag(bar);
return XTLSBearishOrderBlockToken + "-" + GetBarTimeTag(bar);
}
//
@@ -691,7 +1380,8 @@ bool DrawBearishOrderBlock(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -712,7 +1402,8 @@ bool DrawBearishOrderBlock(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -732,7 +1423,7 @@ void RemoveBearishOrderBlock(XOHCL &bar)
//
string GetSupportTag(XOHCL &bar)
{
return "Support-" + GetBarTimeTag(bar);
return XTLSSupportToken + "-" + GetBarTimeTag(bar);
}
//
@@ -839,7 +1530,7 @@ void RemoveSupport(XOHCL &bar)
//
string GetResistanceTag(XOHCL &bar)
{
return "Resistance-" + GetBarTimeTag(bar);
return XTLSResistanceToken + "-" + GetBarTimeTag(bar);
}
//
@@ -946,7 +1637,7 @@ void RemoveResistance(XOHCL &bar)
//
string GetBullishTrendTag(XOHCL &bar)
{
return "BullishTrend-" + GetBarTimeTag(bar);
return XTLSBullishTrendToken + "-" + GetBarTimeTag(bar);
}
//
@@ -960,9 +1651,9 @@ bool DrawBullishTrend(
color clr = clrAqua,
ENUM_LINE_STYLE style = STYLE_DOT,
uint width = 1,
uchar swingHighArrow = 202,
uchar swingHighArrow = 108,
color swingHighColor = clrAqua,
uchar swingLowArrow = 202,
uchar swingLowArrow = 108,
color swingLowColor = clrMagenta //
)
{
@@ -997,7 +1688,8 @@ bool DrawBullishTrend(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -1022,7 +1714,8 @@ bool DrawBullishTrend(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -1098,7 +1791,7 @@ void RemoveBullishTrend(XOHCL &bar)
//
string GetBearishTrendTag(XOHCL &bar)
{
return "BearishTrend-" + GetBarTimeTag(bar);
return XTLSBearishTrendToken + "-" + GetBarTimeTag(bar);
}
//
@@ -1112,9 +1805,9 @@ bool DrawBearishTrend(
color clr = clrMagenta,
ENUM_LINE_STYLE style = STYLE_DOT,
uint width = 1,
uchar swingHighArrow = 202,
uchar swingHighArrow = 108,
color swingHighColor = clrMagenta,
uchar swingLowArrow = 202,
uchar swingLowArrow = 108,
color swingLowColor = clrAqua //
)
{
@@ -1149,7 +1842,8 @@ bool DrawBearishTrend(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -1174,7 +1868,8 @@ bool DrawBearishTrend(
false,
ray //
);
if (!result) {
if (!result)
{
return result;
}
@@ -1244,6 +1939,28 @@ void RemoveBearishTrend(XOHCL &bar)
RemoveDraws(GetBearishTrendTag(bar));
}
//
void RemoveAllToolsDraws()
{
//
RemoveDraws(XTLSHammerToken);
RemoveDraws(XTLSSupportToken);
RemoveDraws(XTLSSwingLowToken);
RemoveDraws(XTLSSwingHighToken);
RemoveDraws(XTLSBullishFVGToken);
RemoveDraws(XTLSBearishFVGToken);
RemoveDraws(XTLSResistanceToken);
RemoveDraws(XTLSMorningStarToken);
RemoveDraws(XTLSEveningStarToken);
RemoveDraws(XTLSShootingStarToken);
RemoveDraws(XTLSBullishTrendToken);
RemoveDraws(XTLSBearishTrendToken);
RemoveDraws(XTLSBullishEngulfingToken);
RemoveDraws(XTLSBearishEngulfingToken);
RemoveDraws(XTLSBullishOrderBlockToken);
RemoveDraws(XTLSBearishOrderBlockToken);
}
//
//
//
+294 -93
View File
@@ -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();
}
}
};