last ...
This commit is contained in:
@@ -0,0 +1,766 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XSCXOBVGStrategy
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
/// Imports ...
|
||||
#include "../Helpers/x-saherelm.xtm.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xstr.helper.mq5"
|
||||
#include "../Classes/x-saherelm.xstrategy.class.mq5"
|
||||
|
||||
//
|
||||
string XOBVGStartegyToken = "XOBVG";
|
||||
|
||||
//
|
||||
class XSCXOBVGStrategy : public XSCBaseStrategy
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XSCXOBVGStrategy(
|
||||
//
|
||||
// Base ...
|
||||
string _symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES _period, // Trading TimeFrame
|
||||
ENUM_TIMEFRAMES _hindPeriod, // Hind Period
|
||||
ENUM_TIMEFRAMES _mediestPeriod, // Mediest Period
|
||||
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,
|
||||
int _maxAllowedShorts = 0 //
|
||||
) : XSCBaseStrategy(_symbol,
|
||||
_period,
|
||||
_volume,
|
||||
_r2r,
|
||||
_slippage,
|
||||
_magicNumber,
|
||||
_useTPSLAsPoint,
|
||||
_forceMaxTPSLAsPoint,
|
||||
_tpPoint,
|
||||
_slPoint,
|
||||
_allowLong,
|
||||
_allowShort,
|
||||
_maxAllowedLongs,
|
||||
_maxAllowedShorts //
|
||||
)
|
||||
{
|
||||
//
|
||||
mHindPeriod = _hindPeriod;
|
||||
mMediestPeriod = _mediestPeriod;
|
||||
|
||||
//
|
||||
SetAlertPrefix(GetTag());
|
||||
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXOBVGStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Getter / Setter (s) ...
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES HindPeriod()
|
||||
{
|
||||
return mHindPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
void HindPeriod(ENUM_TIMEFRAMES value)
|
||||
{
|
||||
mHindPeriod = value;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES MediestPeriod()
|
||||
{
|
||||
return mMediestPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
void MediestPeriod(ENUM_TIMEFRAMES value)
|
||||
{
|
||||
mMediestPeriod = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
//
|
||||
// Customize Strategy Identifier ...
|
||||
string GetTag() override
|
||||
{
|
||||
return XOBVGStartegyToken;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Conditions For Signal ...
|
||||
bool HasSignal(
|
||||
XSignal &signal //
|
||||
) override
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
signal.Clean();
|
||||
|
||||
//
|
||||
double sl = 0;
|
||||
double tp = 0;
|
||||
double risk = 0;
|
||||
double entry = 0;
|
||||
double reward = 0;
|
||||
double r2r = R2R();
|
||||
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
bool hasLong = false;
|
||||
bool hasShort = false;
|
||||
|
||||
//
|
||||
XOHCL tmpHSW[];
|
||||
XOHCL tmpLSW[];
|
||||
|
||||
//
|
||||
bool useHammer = true;
|
||||
bool useMorningStar = false;
|
||||
bool useBullishEngulfing = true;
|
||||
bool useBullishMaurubozu = true;
|
||||
|
||||
//
|
||||
bool useShootingStar = true;
|
||||
bool useEveningStar = false;
|
||||
bool useBearishEngulfing = true;
|
||||
bool useBearishMaurubozu = true;
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ll3 = cBar.FindLowest(
|
||||
3,
|
||||
MODE_LOW //
|
||||
);
|
||||
double hh3 = cBar.FindHighest(
|
||||
3,
|
||||
MODE_HIGH //
|
||||
);
|
||||
|
||||
//
|
||||
result = hindBar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
result = hindBar.Init(
|
||||
mSymbol,
|
||||
mHindPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBullishOrderBlock = hindBullishOrderBlock.IsValid();
|
||||
bool hasBearishOrderBlock = hindBearishOrderBlock.IsValid();
|
||||
result =
|
||||
//
|
||||
hasBullishOrderBlock
|
||||
//
|
||||
||
|
||||
//
|
||||
hasBearishOrderBlock
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hasBullishOrderBlock = hindBar.HasBullishOrderBlock(hindBullishOrderBlock);
|
||||
hasBearishOrderBlock = hindBar.HasBearishOrderBlock(hindBearishOrderBlock);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
hasBullishOrderBlock
|
||||
//
|
||||
||
|
||||
//
|
||||
hasBearishOrderBlock
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasBullishOrderBlock)
|
||||
{
|
||||
//
|
||||
DrawBullishOrderBlock(
|
||||
hindBullishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Try to Detect and Order Block Inside this ...
|
||||
// in Mediest ...
|
||||
result = medBar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
result = medBar.Init(
|
||||
mSymbol,
|
||||
mMediestPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = medBar.HasBullishOrderBlock(medBullishOrderBlock);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBullishOrderBlock(
|
||||
medBullishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Order Block Is Inside HINDOB ...
|
||||
result =
|
||||
//
|
||||
(medBullishOrderBlock.low >= hindBullishOrderBlock.low &&
|
||||
medBullishOrderBlock.low <= hindBullishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(medBullishOrderBlock.high <= hindBullishOrderBlock.high &&
|
||||
medBullishOrderBlock.high >= hindBullishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Check Price ...
|
||||
result =
|
||||
//
|
||||
ll3 < medBullishOrderBlock.high &&
|
||||
ll3 > hindBullishOrderBlock.low
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
hasLong = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Detect and FVG Inside ...
|
||||
result = medBar.HasBullishFVG(
|
||||
fvgUpper,
|
||||
fvgLower //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBullishFVG(
|
||||
medBar,
|
||||
fvgUpper,
|
||||
fvgLower,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(fvgLower >= hindBullishOrderBlock.low &&
|
||||
fvgLower <= hindBullishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper <= hindBullishOrderBlock.high &&
|
||||
fvgUpper >= hindBullishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
//
|
||||
// Check Price ...
|
||||
result =
|
||||
//
|
||||
ll3 < fvgUpper &&
|
||||
ll3 > hindBullishOrderBlock.low
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
hasLong = result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasBearishOrderBlock)
|
||||
{
|
||||
//
|
||||
DrawBearishOrderBlock(
|
||||
hindBearishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Try to Detect and Order Block Inside this ...
|
||||
// in Mediest ...
|
||||
result = medBar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
result = medBar.Init(
|
||||
mSymbol,
|
||||
mMediestPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = medBar.HasBearishOrderBlock(medBearishOrderBlock);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBearishOrderBlock(
|
||||
medBearishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Order Block Is Inside HINDOB ...
|
||||
result =
|
||||
//
|
||||
(medBullishOrderBlock.low >= hindBearishOrderBlock.low &&
|
||||
medBearishOrderBlock.low <= hindBearishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(medBearishOrderBlock.high <= hindBearishOrderBlock.high &&
|
||||
medBearishOrderBlock.high >= hindBearishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Detect and FVG Inside ...
|
||||
result = medBar.HasBearishFVG(
|
||||
fvgUpper,
|
||||
fvgLower //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBearishFVG(
|
||||
medBar,
|
||||
fvgUpper,
|
||||
fvgLower,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(fvgLower >= hindBearishOrderBlock.low &&
|
||||
fvgLower <= hindBearishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper <= hindBearishOrderBlock.high &&
|
||||
fvgUpper >= hindBearishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = hasLong || hasShort;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (hasLong)
|
||||
{
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
bool isHammer = !useHammer
|
||||
? false
|
||||
: cBar.IsHammer();
|
||||
bool isMorningStar = !useMorningStar
|
||||
? false
|
||||
: cBar.IsMorningStar();
|
||||
bool isBullishMarubozu = !useBullishEngulfing
|
||||
? false
|
||||
: cBar.IsBullishMarubozu();
|
||||
bool isBullishEngulfing = !useBullishMaurubozu
|
||||
? false
|
||||
: cBar.IsBullishEngulfing();
|
||||
|
||||
//
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Find Swing Low Above of EMA ...
|
||||
// Find Swing High Above of EMA ...
|
||||
// Fins Swing Low Below of EMA ...
|
||||
// Detect Bullish Pattern ...
|
||||
hasLong =
|
||||
//
|
||||
true
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isHammer
|
||||
//
|
||||
||
|
||||
//
|
||||
isMorningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishMarubozu
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishEngulfing
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
if (hasLong)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
// sl = tmpLSW[ArraySize(tmpLSW) - 1].low;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasShort)
|
||||
{
|
||||
//
|
||||
// Short ...
|
||||
bool isShootingStar = !useShootingStar
|
||||
? false
|
||||
: cBar.IsShootingStar();
|
||||
bool isEveningStar = !useEveningStar
|
||||
? false
|
||||
: cBar.IsEveningStar();
|
||||
bool isBearishEngulfing = !useBearishEngulfing
|
||||
? false
|
||||
: cBar.IsBearishEngulfing();
|
||||
bool isBearishMaurubozu = !useBearishMaurubozu
|
||||
? false
|
||||
: cBar.IsBearishMarubozu();
|
||||
|
||||
//
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
hasShort =
|
||||
//
|
||||
false
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isShootingStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isEveningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishEngulfing
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishMaurubozu
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
if (hasShort)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_SELL;
|
||||
|
||||
//
|
||||
// sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = hasLong || hasShort;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
entry = GetEntry(mSymbol, type);
|
||||
CalculateTPSLByPrice(
|
||||
sl,
|
||||
tp,
|
||||
type,
|
||||
entry,
|
||||
r2r //
|
||||
);
|
||||
|
||||
//
|
||||
result = signal.Prepare(
|
||||
mSymbol,
|
||||
GetTag(),
|
||||
mPeriod,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
mVolume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mHindPeriod; // Hind Period
|
||||
ENUM_TIMEFRAMES mMediestPeriod; // Mediest Period
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
XOHCL hindBar;
|
||||
XOHCL hindBullishOrderBlock;
|
||||
XOHCL hindBearishOrderBlock;
|
||||
|
||||
//
|
||||
XOHCL medBar;
|
||||
XOHCL medBullishOrderBlock;
|
||||
XOHCL medBearishOrderBlock;
|
||||
|
||||
//
|
||||
double fvgUpper;
|
||||
double fvgLower;
|
||||
};
|
||||
|
||||
//
|
||||
@@ -5409,3 +5409,440 @@ int pivotsCount = ArraySize(pivots);
|
||||
// ;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Try to Detect and Order Block Inside this ...
|
||||
// in Mediest ...
|
||||
result = medBar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
result = medBar.Init(
|
||||
mSymbol,
|
||||
mMediestPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = medBar.HasBullishOrderBlock(medBullishOrderBlock);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBullishOrderBlock(
|
||||
medBullishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Order Block Is Inside HINDOB ...
|
||||
result =
|
||||
//
|
||||
(medBullishOrderBlock.low >= hindBullishOrderBlock.low &&
|
||||
medBullishOrderBlock.low <= hindBullishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(medBullishOrderBlock.high <= hindBullishOrderBlock.high &&
|
||||
medBullishOrderBlock.high >= hindBullishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Check Price ...
|
||||
result =
|
||||
//
|
||||
ll3 < medBullishOrderBlock.high &&
|
||||
ll3 > hindBullishOrderBlock.low
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
hasLong = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Detect and FVG Inside ...
|
||||
result = medBar.HasBullishFVG(
|
||||
fvgUpper,
|
||||
fvgLower //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBullishFVG(
|
||||
medBar,
|
||||
fvgUpper,
|
||||
fvgLower,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(fvgLower >= hindBullishOrderBlock.low &&
|
||||
fvgLower <= hindBullishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper <= hindBullishOrderBlock.high &&
|
||||
fvgUpper >= hindBullishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
//
|
||||
// Check Price ...
|
||||
result =
|
||||
//
|
||||
ll3 < fvgUpper &&
|
||||
ll3 > hindBullishOrderBlock.low
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
hasLong = result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
// Try to Detect and Order Block Inside this ...
|
||||
// in Mediest ...
|
||||
result = medBar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
result = medBar.Init(
|
||||
mSymbol,
|
||||
mMediestPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = medBar.HasBearishOrderBlock(medBearishOrderBlock);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
medBar.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBearishOrderBlock(
|
||||
medBearishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Order Block Is Inside HINDOB ...
|
||||
result =
|
||||
//
|
||||
(medBullishOrderBlock.low >= hindBearishOrderBlock.low &&
|
||||
medBearishOrderBlock.low <= hindBearishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(medBearishOrderBlock.high <= hindBearishOrderBlock.high &&
|
||||
medBearishOrderBlock.high >= hindBearishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Detect and FVG Inside ...
|
||||
result = medBar.HasBearishFVG(
|
||||
fvgUpper,
|
||||
fvgLower //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DrawBearishFVG(
|
||||
medBar,
|
||||
fvgUpper,
|
||||
fvgLower,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(fvgLower >= hindBearishOrderBlock.low &&
|
||||
fvgLower <= hindBearishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper <= hindBearishOrderBlock.high &&
|
||||
fvgUpper >= hindBearishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
hindBar.Clean();
|
||||
hindBullishOrderBlock.Clean();
|
||||
hindBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
medBar.Clean();
|
||||
medBullishOrderBlock.Clean();
|
||||
medBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
result = hasLong || hasShort;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (hasLong)
|
||||
{
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
bool isHammer = !useHammer
|
||||
? false
|
||||
: cBar.IsHammer();
|
||||
bool isMorningStar = !useMorningStar
|
||||
? false
|
||||
: cBar.IsMorningStar();
|
||||
bool isBullishMarubozu = !useBullishEngulfing
|
||||
? false
|
||||
: cBar.IsBullishMarubozu();
|
||||
bool isBullishEngulfing = !useBullishMaurubozu
|
||||
? false
|
||||
: cBar.IsBullishEngulfing();
|
||||
|
||||
//
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Find Swing Low Above of EMA ...
|
||||
// Find Swing High Above of EMA ...
|
||||
// Fins Swing Low Below of EMA ...
|
||||
// Detect Bullish Pattern ...
|
||||
hasLong =
|
||||
//
|
||||
true
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isHammer
|
||||
//
|
||||
||
|
||||
//
|
||||
isMorningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishMarubozu
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishEngulfing
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
if (hasLong)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
// sl = tmpLSW[ArraySize(tmpLSW) - 1].low;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasShort)
|
||||
{
|
||||
//
|
||||
// Short ...
|
||||
bool isShootingStar = !useShootingStar
|
||||
? false
|
||||
: cBar.IsShootingStar();
|
||||
bool isEveningStar = !useEveningStar
|
||||
? false
|
||||
: cBar.IsEveningStar();
|
||||
bool isBearishEngulfing = !useBearishEngulfing
|
||||
? false
|
||||
: cBar.IsBearishEngulfing();
|
||||
bool isBearishMaurubozu = !useBearishMaurubozu
|
||||
? false
|
||||
: cBar.IsBearishMarubozu();
|
||||
|
||||
//
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
hasShort =
|
||||
//
|
||||
false
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isShootingStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isEveningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishEngulfing
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishMaurubozu
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
if (hasShort)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_SELL;
|
||||
|
||||
//
|
||||
// sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
|
||||
}
|
||||
}
|
||||
|
||||
+32
-216
@@ -814,11 +814,9 @@ void FindSupport()
|
||||
|
||||
//
|
||||
datetime at = NULL;
|
||||
double support = 0;
|
||||
XOHCL support;
|
||||
bool hasSupport = cBar.HasSupport(
|
||||
support,
|
||||
at //
|
||||
);
|
||||
support);
|
||||
if (!hasSupport)
|
||||
{
|
||||
return;
|
||||
@@ -828,21 +826,7 @@ void FindSupport()
|
||||
eaBarTracker.Waits();
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"Support-" + ToString((int)at),
|
||||
0,
|
||||
at,
|
||||
support,
|
||||
TimeCurrent(),
|
||||
support,
|
||||
clrAqua,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
);
|
||||
DrawSupport(support, ChartID());
|
||||
|
||||
//
|
||||
Print("Support Detected ...");
|
||||
@@ -866,11 +850,9 @@ void FindResistance()
|
||||
|
||||
//
|
||||
datetime at = NULL;
|
||||
double resistance = 0;
|
||||
XOHCL resistance;
|
||||
bool hasResistance = cBar.HasResistance(
|
||||
resistance,
|
||||
at //
|
||||
);
|
||||
resistance);
|
||||
if (!hasResistance)
|
||||
{
|
||||
return;
|
||||
@@ -880,21 +862,7 @@ void FindResistance()
|
||||
eaBarTracker.Waits();
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"Resistance-" + ToString((int)at),
|
||||
0,
|
||||
at,
|
||||
resistance,
|
||||
TimeCurrent(),
|
||||
resistance,
|
||||
clrMagenta,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
);
|
||||
DrawResistance(resistance, ChartID());
|
||||
|
||||
//
|
||||
Print("Resistance Detected ...");
|
||||
@@ -917,19 +885,13 @@ void FindBullishTrend()
|
||||
}
|
||||
|
||||
//
|
||||
double hSwings[];
|
||||
datetime hSwingTimes[];
|
||||
|
||||
//
|
||||
double lSwings[];
|
||||
datetime lSwingTimes[];
|
||||
XOHCL hSwings[];
|
||||
XOHCL lSwings[];
|
||||
|
||||
//
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
hSwings,
|
||||
hSwingTimes,
|
||||
lSwings,
|
||||
lSwingTimes,
|
||||
false // Method 2 ...
|
||||
);
|
||||
if (!isBullishTrend)
|
||||
@@ -941,85 +903,13 @@ void FindBullishTrend()
|
||||
eaBarTracker.Waits();
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"HSING-BULLTrend-" + ToString((int)hSwingTimes[ArraySize(hSwingTimes) - 1]) + "," + ToString((int)hSwingTimes[0]),
|
||||
0,
|
||||
hSwingTimes[ArraySize(hSwingTimes) - 1],
|
||||
hSwings[ArraySize(hSwings) - 1],
|
||||
hSwingTimes[0],
|
||||
hSwings[0],
|
||||
clrAqua,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
DrawBullishTrend(
|
||||
cBar,
|
||||
hSwings,
|
||||
lSwings,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"LSING-BULLTrend-" + ToString((int)lSwingTimes[ArraySize(lSwingTimes) - 1]) + "," + ToString((int)lSwingTimes[0]),
|
||||
0,
|
||||
lSwingTimes[ArraySize(lSwingTimes) - 1],
|
||||
lSwings[ArraySize(lSwings) - 1],
|
||||
lSwingTimes[0],
|
||||
lSwings[0],
|
||||
clrMagenta,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Draw Arrow On Swing Highs ...
|
||||
for (int i = 0; i < ArraySize(hSwings); i++)
|
||||
{
|
||||
//
|
||||
double iPrice = hSwings[i];
|
||||
datetime iTime = hSwingTimes[i];
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
ChartID(),
|
||||
"HSIGN-BULLTrend-Arrow-" + ToString((int)iTime),
|
||||
0,
|
||||
iTime,
|
||||
iPrice,
|
||||
234,
|
||||
ANCHOR_BOTTOM,
|
||||
clrAqua,
|
||||
STYLE_SOLID,
|
||||
2 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Arrow On Swing Highs ...
|
||||
for (int i = 0; i < ArraySize(lSwings); i++)
|
||||
{
|
||||
//
|
||||
double iPrice = lSwings[i];
|
||||
datetime iTime = lSwingTimes[i];
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
ChartID(),
|
||||
"LSIGN-BULLTrend-Arrow-" + ToString((int)iTime),
|
||||
0,
|
||||
iTime,
|
||||
iPrice,
|
||||
233,
|
||||
ANCHOR_TOP,
|
||||
clrMagenta,
|
||||
STYLE_SOLID,
|
||||
2 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Print("Bullish Trend Detected ...");
|
||||
}
|
||||
@@ -1041,19 +931,13 @@ void FindBearishTrend()
|
||||
}
|
||||
|
||||
//
|
||||
double hSwings[];
|
||||
datetime hSwingTimes[];
|
||||
|
||||
//
|
||||
double lSwings[];
|
||||
datetime lSwingTimes[];
|
||||
XOHCL hSwings[];
|
||||
XOHCL lSwings[];
|
||||
|
||||
//
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
hSwings,
|
||||
hSwingTimes,
|
||||
lSwings,
|
||||
lSwingTimes,
|
||||
false // Method 2 ...
|
||||
);
|
||||
if (!isBearishTrend)
|
||||
@@ -1065,92 +949,21 @@ void FindBearishTrend()
|
||||
eaBarTracker.Waits();
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"HSING-BEARTrend-" + ToString((int)hSwingTimes[ArraySize(hSwingTimes) - 1]) + "," + ToString((int)hSwingTimes[0]),
|
||||
0,
|
||||
hSwingTimes[ArraySize(hSwingTimes) - 1],
|
||||
hSwings[ArraySize(hSwings) - 1],
|
||||
hSwingTimes[0],
|
||||
hSwings[0],
|
||||
clrAqua,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
DrawBearishTrend(
|
||||
cBar,
|
||||
hSwings,
|
||||
lSwings,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"LSING-BEARTrend-" + ToString((int)lSwingTimes[ArraySize(lSwingTimes) - 1]) + "," + ToString((int)lSwingTimes[0]),
|
||||
0,
|
||||
lSwingTimes[ArraySize(lSwingTimes) - 1],
|
||||
lSwings[ArraySize(lSwings) - 1],
|
||||
lSwingTimes[0],
|
||||
lSwings[0],
|
||||
clrMagenta,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Draw Arrow On Swing Highs ...
|
||||
for (int i = 0; i < ArraySize(hSwings); i++)
|
||||
{
|
||||
//
|
||||
double iPrice = hSwings[i];
|
||||
datetime iTime = hSwingTimes[i];
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
ChartID(),
|
||||
"HSIGN-BEARTrend-Arrow-" + ToString((int)iTime),
|
||||
0,
|
||||
iTime,
|
||||
iPrice,
|
||||
234,
|
||||
ANCHOR_BOTTOM,
|
||||
clrAqua,
|
||||
STYLE_SOLID,
|
||||
2 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Arrow On Swing Highs ...
|
||||
for (int i = 0; i < ArraySize(lSwings); i++)
|
||||
{
|
||||
//
|
||||
double iPrice = lSwings[i];
|
||||
datetime iTime = lSwingTimes[i];
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
ChartID(),
|
||||
"LSIGN-BEARTrend-Arrow-" + ToString((int)iTime),
|
||||
0,
|
||||
iTime,
|
||||
iPrice,
|
||||
233,
|
||||
ANCHOR_TOP,
|
||||
clrMagenta,
|
||||
STYLE_SOLID,
|
||||
2 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Print("Bearish Trend Detected ...");
|
||||
}
|
||||
|
||||
//
|
||||
// Find Bullish Order Block ...
|
||||
void FindBullishOrderBlock() {
|
||||
void FindBullishOrderBlock()
|
||||
{
|
||||
//
|
||||
XOHCL cBar;
|
||||
bool isInited = cBar.Init(
|
||||
@@ -1168,7 +981,8 @@ void FindBullishOrderBlock() {
|
||||
bool hasOB = cBar.HasBullishOrderBlock(
|
||||
obBar //
|
||||
);
|
||||
if (!hasOB) {
|
||||
if (!hasOB)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1178,7 +992,7 @@ void FindBullishOrderBlock() {
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"BULLOB-H-" + ToString((int) obBar.time),
|
||||
"BULLOB-H-" + ToString((int)obBar.time),
|
||||
0,
|
||||
obBar.time,
|
||||
obBar.high,
|
||||
@@ -1195,7 +1009,7 @@ void FindBullishOrderBlock() {
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"BULLOB-L-" + ToString((int) obBar.time),
|
||||
"BULLOB-L-" + ToString((int)obBar.time),
|
||||
0,
|
||||
obBar.time,
|
||||
obBar.low,
|
||||
@@ -1215,7 +1029,8 @@ void FindBullishOrderBlock() {
|
||||
|
||||
//
|
||||
// Find Bearish Order Block ...
|
||||
void FindBearishOrderBlock() {
|
||||
void FindBearishOrderBlock()
|
||||
{
|
||||
//
|
||||
XOHCL cBar;
|
||||
bool isInited = cBar.Init(
|
||||
@@ -1233,7 +1048,8 @@ void FindBearishOrderBlock() {
|
||||
bool hasOB = cBar.HasBearishOrderBlock(
|
||||
obBar //
|
||||
);
|
||||
if (!hasOB) {
|
||||
if (!hasOB)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1243,7 +1059,7 @@ void FindBearishOrderBlock() {
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"BEAROB-H-" + ToString((int) obBar.time),
|
||||
"BEAROB-H-" + ToString((int)obBar.time),
|
||||
0,
|
||||
obBar.time,
|
||||
obBar.high,
|
||||
@@ -1260,7 +1076,7 @@ void FindBearishOrderBlock() {
|
||||
//
|
||||
DrawTrendLine(
|
||||
ChartID(),
|
||||
"BEAROB-L-" + ToString((int) obBar.time),
|
||||
"BEAROB-L-" + ToString((int)obBar.time),
|
||||
0,
|
||||
obBar.time,
|
||||
obBar.low,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XTestPivotsEA
|
||||
// Name: XSTestEA
|
||||
// Description: an Exper Advisor which used XTestSetup
|
||||
// to Analyse Market ...
|
||||
//
|
||||
@@ -16,11 +16,11 @@
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTestPivotsEA"
|
||||
#property description "SaherElm XSTestEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XTestPivotsEA"
|
||||
#define ShortName "XSTestEA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
|
||||
//
|
||||
#include "../Strategies/x-saherelm.xobvg.strategy.mq5"
|
||||
#include "../Strategies/x-saherelm.xsrbr.strategy.mq5"
|
||||
#include "../Strategies/x-saherelm.xemrng.strategy.mq5"
|
||||
|
||||
@@ -50,7 +51,7 @@ double eaTPPoint = 200;
|
||||
double eaSLPoint = 100;
|
||||
|
||||
//
|
||||
double eaR2R = 1.5;
|
||||
double eaR2R = 2;
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
@@ -79,6 +80,9 @@ int OnInit()
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// EventSetTimer(1);
|
||||
// EventSetMillisecondTimer(100);
|
||||
@@ -200,7 +204,8 @@ bool InitialEA()
|
||||
|
||||
//
|
||||
bool useXSRBR = false;
|
||||
bool useXEMRNG = true;
|
||||
bool useXEMRNG = false;
|
||||
bool useXOBVG = true;
|
||||
|
||||
//
|
||||
// EURUSD ...
|
||||
@@ -257,8 +262,8 @@ bool InitialEA()
|
||||
eaSLPoint, // SL
|
||||
eaAllowLong,
|
||||
eaAllowShort,
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
||||
);
|
||||
eurusdM15SRBRStrategy.SetAlertLogAlerts(true);
|
||||
@@ -292,6 +297,34 @@ bool InitialEA()
|
||||
eurusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
|
||||
RegisterStrategy(eurusdM5EMRNGStrategy);
|
||||
}
|
||||
|
||||
//
|
||||
// XOBVG ...
|
||||
if (useXOBVG)
|
||||
{
|
||||
//
|
||||
XSCXOBVGStrategy *eurusdM5OBVGStrategy;
|
||||
eurusdM5OBVGStrategy = new XSCXOBVGStrategy(
|
||||
eurusdSymbol,
|
||||
PERIOD_M5,
|
||||
PERIOD_H2, // Analyzing Period
|
||||
eaVolume,
|
||||
eaR2R, // R2R ...
|
||||
eaSlippage,
|
||||
magicNumber,
|
||||
false, // Use TP SL Point
|
||||
false, // Use Max
|
||||
eaTPPoint, // TP
|
||||
eaSLPoint, // SL
|
||||
eaAllowLong,
|
||||
eaAllowShort,
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts // Max Shorts
|
||||
);
|
||||
eurusdM5OBVGStrategy.SetAlertLogAlerts(true);
|
||||
eurusdM5OBVGStrategy.SetAlertEnableAlerts(true);
|
||||
RegisterStrategy(eurusdM5OBVGStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -324,8 +357,8 @@ bool InitialEA()
|
||||
eaSLPoint, // SL
|
||||
eaAllowLong,
|
||||
eaAllowShort,
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
||||
);
|
||||
usdchfM5SRBRStrategy.SetAlertLogAlerts(true);
|
||||
@@ -391,8 +424,8 @@ bool InitialEA()
|
||||
eaSLPoint, // SL
|
||||
eaAllowLong,
|
||||
eaAllowShort,
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
||||
);
|
||||
usdjpyM5SRBRStrategy.SetAlertLogAlerts(true);
|
||||
@@ -458,8 +491,8 @@ bool InitialEA()
|
||||
eaSLPoint, // SL
|
||||
eaAllowLong,
|
||||
eaAllowShort,
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
||||
);
|
||||
gbpusdM5SRBRStrategy.SetAlertLogAlerts(true);
|
||||
@@ -525,8 +558,8 @@ bool InitialEA()
|
||||
eaSLPoint, // SL
|
||||
eaAllowLong,
|
||||
eaAllowShort,
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts, // Max Shorts
|
||||
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
||||
);
|
||||
xauusdM5SRBRStrategy.SetAlertLogAlerts(true);
|
||||
|
||||
@@ -0,0 +1,552 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| VWAP.mq5 |
|
||||
//| Copyright 2015, SOL Digital Consultoria LTDA |
|
||||
//| http://www.soldigitalconsultoria.com.br |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2015, SOL Digital Consultoria LTDA"
|
||||
#property link "http://www.soldigitalconsultoria.com.br"
|
||||
#property version "1.47"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//--- plot VWAP
|
||||
#property indicator_label1 "VWAP Daily"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrRed
|
||||
#property indicator_style1 STYLE_DASH
|
||||
#property indicator_width1 2
|
||||
|
||||
#property indicator_label2 "VWAP Weekly"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrBlue
|
||||
#property indicator_style2 STYLE_DASH
|
||||
#property indicator_width2 2
|
||||
|
||||
#property indicator_label3 "VWAP Monthly"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGreen
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 2
|
||||
|
||||
#property indicator_label4 "VWAP Level 01"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrGray
|
||||
#property indicator_style4 STYLE_DASH
|
||||
#property indicator_width4 2
|
||||
|
||||
#property indicator_label5 "VWAP Level 02"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrYellow
|
||||
#property indicator_style5 STYLE_DASH
|
||||
#property indicator_width5 2
|
||||
|
||||
#property indicator_label6 "VWAP Level 03"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrGreen
|
||||
#property indicator_style6 STYLE_DASH
|
||||
#property indicator_width6 2
|
||||
|
||||
#property indicator_label7 "VWAP Level 04"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrBlack
|
||||
#property indicator_style7 STYLE_DASH
|
||||
#property indicator_width7 2
|
||||
|
||||
#property indicator_label8 "VWAP Level 05"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrBlue
|
||||
#property indicator_style8 STYLE_DASH
|
||||
#property indicator_width8 2
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
enum DATE_TYPE
|
||||
{
|
||||
DAILY,
|
||||
WEEKLY,
|
||||
MONTHLY
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
enum PRICE_TYPE
|
||||
{
|
||||
OPEN,
|
||||
CLOSE,
|
||||
HIGH,
|
||||
LOW,
|
||||
OPEN_CLOSE,
|
||||
HIGH_LOW,
|
||||
CLOSE_HIGH_LOW,
|
||||
OPEN_CLOSE_HIGH_LOW
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
datetime CreateDateTime(DATE_TYPE nReturnType=DAILY,datetime dtDay=D'2000.01.01 00:00:00',int pHour=0,int pMinute=0,int pSecond=0)
|
||||
{
|
||||
datetime dtReturnDate;
|
||||
MqlDateTime timeStruct;
|
||||
|
||||
TimeToStruct(dtDay,timeStruct);
|
||||
timeStruct.hour = pHour;
|
||||
timeStruct.min = pMinute;
|
||||
timeStruct.sec = pSecond;
|
||||
dtReturnDate=(StructToTime(timeStruct));
|
||||
|
||||
if(nReturnType==WEEKLY)
|
||||
{
|
||||
while(timeStruct.day_of_week!=0)
|
||||
{
|
||||
dtReturnDate=(dtReturnDate-86400);
|
||||
TimeToStruct(dtReturnDate,timeStruct);
|
||||
}
|
||||
}
|
||||
|
||||
if(nReturnType==MONTHLY)
|
||||
{
|
||||
timeStruct.day=1;
|
||||
dtReturnDate=(StructToTime(timeStruct));
|
||||
}
|
||||
|
||||
return dtReturnDate;
|
||||
}
|
||||
|
||||
sinput string Indicator_Name="Volume Weighted Average Price (VWAP)";
|
||||
input PRICE_TYPE Price_Type = CLOSE_HIGH_LOW;
|
||||
input bool Enable_Daily = true;
|
||||
input bool Enable_Weekly = true;
|
||||
input bool Enable_Monthly = true;
|
||||
input bool Enable_Level_01 = false;
|
||||
input int VWAP_Level_01_Period = 5;
|
||||
input bool Enable_Level_02 = false;
|
||||
input int VWAP_Level_02_Period = 13;
|
||||
input bool Enable_Level_03 = false;
|
||||
input int VWAP_Level_03_Period = 20;
|
||||
input bool Enable_Level_04 = false;
|
||||
input int VWAP_Level_04_Period = 30;
|
||||
input bool Enable_Level_05 = false;
|
||||
input int VWAP_Level_05_Period = 40;
|
||||
|
||||
bool Show_Daily_Value = true;
|
||||
bool Show_Weekly_Value = true;
|
||||
bool Show_Monthly_Value = true;
|
||||
|
||||
double VWAP_Buffer_Daily[];
|
||||
double VWAP_Buffer_Weekly[];
|
||||
double VWAP_Buffer_Monthly[];
|
||||
double VWAP_Buffer_01[];
|
||||
double VWAP_Buffer_02[];
|
||||
double VWAP_Buffer_03[];
|
||||
double VWAP_Buffer_04[];
|
||||
double VWAP_Buffer_05[];
|
||||
|
||||
double nPriceArr[];
|
||||
double nTotalTPV[];
|
||||
double nTotalVol[];
|
||||
double nSumDailyTPV = 0, nSumWeeklyTPV = 0, nSumMonthlyTPV = 0;
|
||||
double nSumDailyVol = 0, nSumWeeklyVol = 0, nSumMonthlyVol = 0;
|
||||
|
||||
int nIdxDaily=0,nIdxWeekly=0,nIdxMonthly=0,nIdx=0;
|
||||
|
||||
bool bIsFirstRun=true;
|
||||
|
||||
ENUM_TIMEFRAMES LastTimePeriod=PERIOD_MN1;
|
||||
|
||||
string sDailyStr = "";
|
||||
string sWeeklyStr = "";
|
||||
string sMonthlyStr = "";
|
||||
string sLevel01Str = "";
|
||||
string sLevel02Str = "";
|
||||
string sLevel03Str = "";
|
||||
string sLevel04Str = "";
|
||||
string sLevel05Str = "";
|
||||
datetime dtLastDay=CreateDateTime(DAILY),dtLastWeek=CreateDateTime(WEEKLY),dtLastMonth=CreateDateTime(MONTHLY);
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
|
||||
SetIndexBuffer(0,VWAP_Buffer_Daily,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,VWAP_Buffer_Weekly,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,VWAP_Buffer_Monthly,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,VWAP_Buffer_01,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,VWAP_Buffer_02,INDICATOR_DATA);
|
||||
SetIndexBuffer(5,VWAP_Buffer_03,INDICATOR_DATA);
|
||||
SetIndexBuffer(6,VWAP_Buffer_04,INDICATOR_DATA);
|
||||
SetIndexBuffer(7,VWAP_Buffer_05,INDICATOR_DATA);
|
||||
|
||||
ObjectCreate(0,"VWAP_Daily",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_YDISTANCE,40);
|
||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_COLOR,indicator_color1);
|
||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Daily",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Daily",OBJPROP_TEXT," ");
|
||||
|
||||
ObjectCreate(0,"VWAP_Weekly",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_YDISTANCE,60);
|
||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_COLOR,indicator_color2);
|
||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Weekly",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Weekly",OBJPROP_TEXT," ");
|
||||
|
||||
ObjectCreate(0,"VWAP_Monthly",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_YDISTANCE,80);
|
||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_COLOR,indicator_color3);
|
||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Monthly",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Monthly",OBJPROP_TEXT," ");
|
||||
|
||||
ObjectCreate(0,"VWAP_Level_01",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_YDISTANCE,100);
|
||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_COLOR,indicator_color4);
|
||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Level_01",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Level_01",OBJPROP_TEXT," ");
|
||||
|
||||
ObjectCreate(0,"VWAP_Level_02",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_YDISTANCE,120);
|
||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_COLOR,indicator_color5);
|
||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Level_02",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Level_02",OBJPROP_TEXT," ");
|
||||
|
||||
ObjectCreate(0,"VWAP_Level_03",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_YDISTANCE,140);
|
||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_COLOR,indicator_color6);
|
||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Level_03",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Level_03",OBJPROP_TEXT," ");
|
||||
|
||||
ObjectCreate(0,"VWAP_Level_04",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_YDISTANCE,160);
|
||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_COLOR,indicator_color7);
|
||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Level_04",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Level_04",OBJPROP_TEXT," ");
|
||||
|
||||
ObjectCreate(0,"VWAP_Level_05",OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_CORNER,3);
|
||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_XDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_YDISTANCE,180);
|
||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_COLOR,indicator_color8);
|
||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,"VWAP_Level_05",OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,"VWAP_Level_05",OBJPROP_TEXT," ");
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int pReason)
|
||||
{
|
||||
ObjectDelete(0,"VWAP_Daily");
|
||||
ObjectDelete(0,"VWAP_Weekly");
|
||||
ObjectDelete(0,"VWAP_Monthly");
|
||||
ObjectDelete(0,"VWAP_Level_01");
|
||||
ObjectDelete(0,"VWAP_Level_02");
|
||||
ObjectDelete(0,"VWAP_Level_03");
|
||||
ObjectDelete(0,"VWAP_Level_04");
|
||||
ObjectDelete(0,"VWAP_Level_05");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
|
||||
if(PERIOD_CURRENT!=LastTimePeriod)
|
||||
{
|
||||
bIsFirstRun=true;
|
||||
LastTimePeriod=PERIOD_CURRENT;
|
||||
}
|
||||
|
||||
if(rates_total>prev_calculated || bIsFirstRun)
|
||||
{
|
||||
ArrayResize(nPriceArr,rates_total);
|
||||
ArrayResize(nTotalTPV,rates_total);
|
||||
ArrayResize(nTotalVol,rates_total);
|
||||
|
||||
if(Enable_Daily) {nIdx = nIdxDaily; nSumDailyTPV = 0; nSumDailyVol = 0;}
|
||||
if(Enable_Weekly) {nIdx = nIdxWeekly; nSumWeeklyTPV = 0; nSumWeeklyVol = 0;}
|
||||
if(Enable_Monthly) {nIdx = nIdxMonthly; nSumMonthlyTPV = 0; nSumMonthlyVol = 0;}
|
||||
|
||||
for(; nIdx<rates_total; nIdx++)
|
||||
{
|
||||
if(CreateDateTime(DAILY,time[nIdx])!=dtLastDay)
|
||||
{
|
||||
nIdxDaily=nIdx;
|
||||
nSumDailyTPV = 0;
|
||||
nSumDailyVol = 0;
|
||||
}
|
||||
if(CreateDateTime(WEEKLY,time[nIdx])!=dtLastWeek)
|
||||
{
|
||||
nIdxWeekly=nIdx;
|
||||
nSumWeeklyTPV = 0;
|
||||
nSumWeeklyVol = 0;
|
||||
}
|
||||
if(CreateDateTime(MONTHLY,time[nIdx])!=dtLastMonth)
|
||||
{
|
||||
nIdxMonthly=nIdx;
|
||||
nSumMonthlyTPV = 0;
|
||||
nSumMonthlyVol = 0;
|
||||
}
|
||||
|
||||
nPriceArr[nIdx] = 0;
|
||||
nTotalTPV[nIdx] = 0;
|
||||
nTotalVol[nIdx] = 0;
|
||||
|
||||
switch(Price_Type)
|
||||
{
|
||||
case OPEN:
|
||||
nPriceArr[nIdx]=open[nIdx];
|
||||
break;
|
||||
case CLOSE:
|
||||
nPriceArr[nIdx]=close[nIdx];
|
||||
break;
|
||||
case HIGH:
|
||||
nPriceArr[nIdx]=high[nIdx];
|
||||
break;
|
||||
case LOW:
|
||||
nPriceArr[nIdx]=low[nIdx];
|
||||
break;
|
||||
case HIGH_LOW:
|
||||
nPriceArr[nIdx]=(high[nIdx]+low[nIdx])/2;
|
||||
break;
|
||||
case OPEN_CLOSE:
|
||||
nPriceArr[nIdx]=(open[nIdx]+close[nIdx])/2;
|
||||
break;
|
||||
case CLOSE_HIGH_LOW:
|
||||
nPriceArr[nIdx]=(close[nIdx]+high[nIdx]+low[nIdx])/3;
|
||||
break;
|
||||
case OPEN_CLOSE_HIGH_LOW:
|
||||
nPriceArr[nIdx]=(open[nIdx]+close[nIdx]+high[nIdx]+low[nIdx])/4;
|
||||
break;
|
||||
default:
|
||||
nPriceArr[nIdx]=(close[nIdx]+high[nIdx]+low[nIdx])/3;
|
||||
break;
|
||||
}
|
||||
|
||||
if(tick_volume[nIdx])
|
||||
{
|
||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * tick_volume[nIdx]);
|
||||
nTotalVol[nIdx] = (double)tick_volume[nIdx];
|
||||
} else if(volume[nIdx]) {
|
||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * volume[nIdx]);
|
||||
nTotalVol[nIdx] = (double)volume[nIdx];
|
||||
}
|
||||
|
||||
if(Enable_Daily && (nIdx>=nIdxDaily))
|
||||
{
|
||||
nSumDailyTPV += nTotalTPV[nIdx];
|
||||
nSumDailyVol += nTotalVol[nIdx];
|
||||
|
||||
if(nSumDailyVol)
|
||||
VWAP_Buffer_Daily[nIdx]=(nSumDailyTPV/nSumDailyVol);
|
||||
|
||||
if((sDailyStr!="VWAP Daily: "+(string)NormalizeDouble(VWAP_Buffer_Daily[nIdx],_Digits)) && Show_Daily_Value)
|
||||
{
|
||||
sDailyStr="VWAP Daily: "+(string)NormalizeDouble(VWAP_Buffer_Daily[nIdx],_Digits);
|
||||
ObjectSetString(0,"VWAP_Daily",OBJPROP_TEXT,sDailyStr);
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Weekly && (nIdx>=nIdxWeekly))
|
||||
{
|
||||
nSumWeeklyTPV += nTotalTPV[nIdx];
|
||||
nSumWeeklyVol += nTotalVol[nIdx];
|
||||
|
||||
if(nSumWeeklyVol)
|
||||
VWAP_Buffer_Weekly[nIdx]=(nSumWeeklyTPV/nSumWeeklyVol);
|
||||
|
||||
if((sWeeklyStr!="VWAP Weekly: "+(string)NormalizeDouble(VWAP_Buffer_Weekly[nIdx],_Digits)) && Show_Weekly_Value)
|
||||
{
|
||||
sWeeklyStr="VWAP Weekly: "+(string)NormalizeDouble(VWAP_Buffer_Weekly[nIdx],_Digits);
|
||||
ObjectSetString(0,"VWAP_Weekly",OBJPROP_TEXT,sWeeklyStr);
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Monthly && (nIdx>=nIdxMonthly))
|
||||
{
|
||||
nSumMonthlyTPV += nTotalTPV[nIdx];
|
||||
nSumMonthlyVol += nTotalVol[nIdx];
|
||||
|
||||
if(nSumMonthlyVol)
|
||||
VWAP_Buffer_Monthly[nIdx]=(nSumMonthlyTPV/nSumMonthlyVol);
|
||||
|
||||
if((sMonthlyStr!="VWAP Monthly: "+(string)NormalizeDouble(VWAP_Buffer_Monthly[nIdx],_Digits)) && Show_Monthly_Value)
|
||||
{
|
||||
sMonthlyStr="VWAP Monthly: "+(string)NormalizeDouble(VWAP_Buffer_Monthly[nIdx],_Digits);
|
||||
ObjectSetString(0,"VWAP_Monthly",OBJPROP_TEXT,sMonthlyStr);
|
||||
}
|
||||
}
|
||||
|
||||
dtLastDay=CreateDateTime(DAILY,time[nIdx]);
|
||||
dtLastWeek=CreateDateTime(WEEKLY,time[nIdx]);
|
||||
dtLastMonth=CreateDateTime(MONTHLY,time[nIdx]);
|
||||
}
|
||||
|
||||
if(Enable_Level_01)
|
||||
{
|
||||
int nStartPos=(prev_calculated>VWAP_Level_01_Period) ?(prev_calculated-VWAP_Level_01_Period) : VWAP_Level_01_Period;
|
||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
||||
{
|
||||
double nSumTotalTPV = 0;
|
||||
double nSumTotalVol = 0;
|
||||
VWAP_Buffer_01[nIdx] = EMPTY_VALUE;
|
||||
|
||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_01_Period; nSubIdx++)
|
||||
{
|
||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
||||
}
|
||||
if(nSumTotalVol)
|
||||
VWAP_Buffer_01[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
||||
else
|
||||
VWAP_Buffer_01[nIdx]=0;
|
||||
if(sLevel01Str!="VWAP Level 01 ("+(string)VWAP_Level_01_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_01[nIdx],_Digits))
|
||||
{
|
||||
sLevel01Str = "VWAP Level 01 (" + (string)VWAP_Level_01_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_01[nIdx], _Digits);
|
||||
ObjectSetString(0,"VWAP_Level_01",OBJPROP_TEXT,sLevel01Str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Level_02)
|
||||
{
|
||||
int nStartPos=(prev_calculated>VWAP_Level_02_Period) ?(prev_calculated-VWAP_Level_02_Period) : VWAP_Level_02_Period;
|
||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
||||
{
|
||||
double nSumTotalTPV = 0;
|
||||
double nSumTotalVol = 0;
|
||||
VWAP_Buffer_02[nIdx] = EMPTY_VALUE;
|
||||
|
||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_02_Period; nSubIdx++)
|
||||
{
|
||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
||||
}
|
||||
if(nSumTotalVol)
|
||||
VWAP_Buffer_02[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
||||
else
|
||||
VWAP_Buffer_02[nIdx]=0;
|
||||
if(sLevel02Str!="VWAP Level 02 ("+(string)VWAP_Level_02_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_02[nIdx],_Digits))
|
||||
{
|
||||
sLevel02Str = "VWAP Level 02 (" + (string)VWAP_Level_02_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_02[nIdx], _Digits);
|
||||
ObjectSetString(0,"VWAP_Level_02",OBJPROP_TEXT,sLevel02Str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Level_03)
|
||||
{
|
||||
int nStartPos=(prev_calculated>VWAP_Level_03_Period) ?(prev_calculated-VWAP_Level_03_Period) : VWAP_Level_03_Period;
|
||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
||||
{
|
||||
double nSumTotalTPV = 0;
|
||||
double nSumTotalVol = 0;
|
||||
VWAP_Buffer_03[nIdx] = EMPTY_VALUE;
|
||||
|
||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_03_Period; nSubIdx++)
|
||||
{
|
||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
||||
}
|
||||
if(nSumTotalVol)
|
||||
VWAP_Buffer_03[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
||||
else
|
||||
VWAP_Buffer_03[nIdx]=0;
|
||||
if(sLevel03Str!="VWAP Level 03 ("+(string)VWAP_Level_03_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_03[nIdx],_Digits))
|
||||
{
|
||||
sLevel03Str = "VWAP Level 03 (" + (string)VWAP_Level_03_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_03[nIdx], _Digits);
|
||||
ObjectSetString(0,"VWAP_Level_03",OBJPROP_TEXT,sLevel03Str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Level_04)
|
||||
{
|
||||
int nStartPos=(prev_calculated>VWAP_Level_04_Period) ?(prev_calculated-VWAP_Level_04_Period) : VWAP_Level_04_Period;
|
||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
||||
{
|
||||
double nSumTotalTPV = 0;
|
||||
double nSumTotalVol = 0;
|
||||
VWAP_Buffer_04[nIdx] = EMPTY_VALUE;
|
||||
|
||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_04_Period; nSubIdx++)
|
||||
{
|
||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
||||
}
|
||||
if(nSumTotalVol)
|
||||
VWAP_Buffer_04[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
||||
else
|
||||
VWAP_Buffer_04[nIdx]=0;
|
||||
if(sLevel04Str!="VWAP Level 04 ("+(string)VWAP_Level_04_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_04[nIdx],_Digits))
|
||||
{
|
||||
sLevel04Str = "VWAP Level 04 (" + (string)VWAP_Level_04_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_04[nIdx], _Digits);
|
||||
ObjectSetString(0,"VWAP_Level_04",OBJPROP_TEXT,sLevel04Str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Level_05)
|
||||
{
|
||||
int nStartPos=(prev_calculated>VWAP_Level_05_Period) ?(prev_calculated-VWAP_Level_05_Period) : VWAP_Level_05_Period;
|
||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
||||
{
|
||||
double nSumTotalTPV = 0;
|
||||
double nSumTotalVol = 0;
|
||||
VWAP_Buffer_05[nIdx] = EMPTY_VALUE;
|
||||
|
||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_05_Period; nSubIdx++)
|
||||
{
|
||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
||||
}
|
||||
if(nSumTotalVol)
|
||||
VWAP_Buffer_05[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
||||
else
|
||||
VWAP_Buffer_05[nIdx]=0;
|
||||
if(sLevel05Str!="VWAP Level 05 ("+(string)VWAP_Level_05_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_05[nIdx],_Digits))
|
||||
{
|
||||
sLevel05Str = "VWAP Level 05 (" + (string)VWAP_Level_05_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_05[nIdx], _Digits);
|
||||
ObjectSetString(0,"VWAP_Level_05",OBJPROP_TEXT,sLevel05Str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bIsFirstRun=false;
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,165 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XVWAP
|
||||
// Description: VWap Implementation ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XVWAP Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XVWAP"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// #define hideColorIDX 0
|
||||
// #define bullColorIDX 1
|
||||
// #define bearColorIDX 2
|
||||
|
||||
// //
|
||||
// #define bullpBufferIndex 1
|
||||
// double bullpBuffer[];
|
||||
|
||||
// //
|
||||
// #property indicator_label1 ""
|
||||
// #property indicator_type1 DRAW_COLOR_LINE
|
||||
// #property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
||||
// #property indicator_style1 STYLE_DOT
|
||||
// #property indicator_width1 1
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Main ...
|
||||
// ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
// ArraySetAsSeries(mainBuffer, true);
|
||||
// ArraySetAsSeries(mainBufferColor, true);
|
||||
// PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
||||
// SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
// PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
||||
// SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -3474,11 +3474,14 @@ struct XOHCL
|
||||
while (!isEnough)
|
||||
{
|
||||
//
|
||||
bool isInited = cBar.Init(
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIDX //
|
||||
);
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = cBar.IsBullish();
|
||||
|
||||
@@ -626,6 +626,10 @@ bool MoveArrow(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// if point position is not set, move it to the current bar having Bid price ...
|
||||
@@ -642,7 +646,7 @@ bool MoveArrow(
|
||||
|
||||
//
|
||||
// move the anchor point ...
|
||||
result = ObjectMove(chartID, name, 0, time, price);
|
||||
result = ObjectMove(chartID, objName, 0, time, price);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -657,10 +661,14 @@ bool DeleteArrow(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete an arrow ...
|
||||
result = !ObjectDelete(chartID, name);
|
||||
result = !ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -676,10 +684,14 @@ bool ArrowCodeChange(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change the arrow code ...
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, code);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -695,10 +707,14 @@ bool ArrowAnchorChange(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change anchor type ...
|
||||
result = !ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor);
|
||||
result = !ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -815,6 +831,10 @@ bool MoveHorizontalLine(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// if the line price is not set, move it to the current Bid price level ...
|
||||
@@ -825,7 +845,7 @@ bool MoveHorizontalLine(
|
||||
|
||||
//
|
||||
// move a horizontal line ...
|
||||
result = ObjectMove(chartID, name, 0, 0, price);
|
||||
result = ObjectMove(chartID, objName, 0, 0, price);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -840,10 +860,14 @@ bool DeleteHorizontalLine(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete a horizontal line ...
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -937,6 +961,10 @@ bool MoveVerticalLine(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// if line time is not set, move the line to the last bar ...
|
||||
@@ -947,7 +975,7 @@ bool MoveVerticalLine(
|
||||
|
||||
//
|
||||
// move the vertical line ...
|
||||
result = ObjectMove(chartID, name, 0, time, 0);
|
||||
result = ObjectMove(chartID, objName, 0, time, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -962,10 +990,14 @@ bool DeleteVerticalLine(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete the vertical line ...
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1001,11 +1033,15 @@ bool DrawRectangle(
|
||||
// Set anchor points' coordinates if they are not set ...
|
||||
ChangeRectangleEmptyPoints(time1, price1, time2, price2);
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// Create a rectangle by the given coordinates ...
|
||||
result = ObjectCreate(
|
||||
chartID,
|
||||
name,
|
||||
objName,
|
||||
OBJ_RECTANGLE,
|
||||
subWindow,
|
||||
time1,
|
||||
@@ -1020,41 +1056,41 @@ bool DrawRectangle(
|
||||
|
||||
//
|
||||
// Set rectangle color ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
||||
|
||||
//
|
||||
// Set the style of rectangle lines
|
||||
ObjectSetInteger(chartID, name, OBJPROP_STYLE, style);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style);
|
||||
|
||||
//
|
||||
// Set width of the rectangle lines ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
||||
|
||||
//
|
||||
// Enable (true) or disable (false) the mode of filling the rectangle ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_FILL, fill);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_FILL, fill);
|
||||
|
||||
//
|
||||
// Display in the foreground (false) or background (true) ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_BACK, back);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
||||
|
||||
//
|
||||
// Enable (true) or disable (false) the mode of highlighting the rectangle for moving
|
||||
// when creating a graphical object using ObjectCreate function, the object cannot be
|
||||
// highlighted and moved by default. Inside this method, selection parameter
|
||||
// is true by default making it possible to highlight and move the object
|
||||
ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
||||
|
||||
//
|
||||
ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
||||
|
||||
//
|
||||
// Hide (true) or display (false) graphical object name in the object list ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
||||
|
||||
//
|
||||
// Set the priority for receiving the event of a mouse click in the chart ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
||||
|
||||
//
|
||||
// Successful execution
|
||||
@@ -1073,6 +1109,10 @@ bool RectanglePointChange(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// if point position is not set, move it to the current bar having Bid price ...
|
||||
@@ -1089,7 +1129,7 @@ bool RectanglePointChange(
|
||||
|
||||
//
|
||||
// Move the anchor point ...
|
||||
result = ObjectMove(chartID, name, pointIndex, time, price);
|
||||
result = ObjectMove(chartID, objName, pointIndex, time, price);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1104,9 +1144,13 @@ bool DeleteRectangle(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1263,17 +1307,21 @@ bool MoveRectangleLabel(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// move the rectangle label ...
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1288,10 +1336,14 @@ bool DeleteRectangleLabel(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete the label ...
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1308,17 +1360,21 @@ bool ChangeSizeRectangleLabel(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change label size ...
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1334,10 +1390,14 @@ bool RectLabelChangeBorderType(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change border type ...
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1442,6 +1502,10 @@ bool ChangeTrendLinePoint(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// if point position is not set, move it to the current bar having Bid price ...
|
||||
@@ -1458,7 +1522,7 @@ bool ChangeTrendLinePoint(
|
||||
|
||||
//
|
||||
// move trend line's anchor point ...
|
||||
result = ObjectMove(chartID, name, pointindex, time, price);
|
||||
result = ObjectMove(chartID, objName, pointindex, time, price);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1473,10 +1537,14 @@ bool DeleteTrendLine(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete a trend line ...
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1628,6 +1696,10 @@ bool MoveText(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -1645,7 +1717,7 @@ bool MoveText(
|
||||
|
||||
//
|
||||
// move the anchor point ...
|
||||
result = ObjectMove(chartID, name, 0, time, price);
|
||||
result = ObjectMove(chartID, objName, 0, time, price);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1661,10 +1733,14 @@ bool ChangeText(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change object text ...
|
||||
result = ObjectSetString(chartID, name, OBJPROP_TEXT, text);
|
||||
result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1679,10 +1755,14 @@ bool DeleteText(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete the object ...
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1920,10 +2000,14 @@ bool FibonacciLevelsSet(
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// set the number of levels ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_LEVELS, levels);
|
||||
|
||||
//
|
||||
// set the properties of levels in the loop ...
|
||||
@@ -1931,24 +2015,24 @@ bool FibonacciLevelsSet(
|
||||
{
|
||||
//
|
||||
// level value ...
|
||||
ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]);
|
||||
ObjectSetDouble(chartID, objName, OBJPROP_LEVELVALUE, i, values[i]);
|
||||
|
||||
//
|
||||
// level color ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_LEVELCOLOR, i, colors[i]);
|
||||
|
||||
//
|
||||
// level style ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_LEVELSTYLE, i, styles[i]);
|
||||
|
||||
//
|
||||
// level width ...
|
||||
ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_LEVELWIDTH, i, widths[i]);
|
||||
|
||||
//
|
||||
// level description ...
|
||||
// ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1));
|
||||
ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]);
|
||||
ObjectSetString(chartID, objName, OBJPROP_LEVELTEXT, i, descriptions[i]);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1968,6 +2052,10 @@ bool FibonacciPointChange(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// if point position is not set, move it to the current bar having Bid price ...
|
||||
@@ -1984,7 +2072,7 @@ bool FibonacciPointChange(
|
||||
|
||||
//
|
||||
// move the anchor point ...
|
||||
result = ObjectMove(chartID, name, pointIndex, time, price);
|
||||
result = ObjectMove(chartID, objName, pointIndex, time, price);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -1999,10 +2087,14 @@ bool DeleteFibonachi(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete the object ...
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2081,9 +2173,13 @@ bool EventCreate(
|
||||
{
|
||||
time = TimeCurrent();
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
result = ObjectCreate(chartID, name, OBJ_EVENT, subWindow, time, 0);
|
||||
result = ObjectCreate(chartID, objName, OBJ_EVENT, subWindow, time, 0);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
@@ -2091,32 +2187,32 @@ bool EventCreate(
|
||||
|
||||
//
|
||||
// set event text
|
||||
ObjectSetString(chartID, name, OBJPROP_TEXT, text);
|
||||
ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
||||
|
||||
//
|
||||
// set color
|
||||
ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
||||
|
||||
//
|
||||
// set anchor point width if the object is highlighted
|
||||
ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width);
|
||||
|
||||
//
|
||||
// display in the foreground false or background true
|
||||
ObjectSetInteger(chartID, name, OBJPROP_BACK, back);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
||||
|
||||
//
|
||||
// enable true or disable false the mode of moving event by mouse
|
||||
ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
||||
|
||||
//
|
||||
// hide true or display false graphical object name in the object list
|
||||
ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
||||
|
||||
//
|
||||
// set the priority for receiving the event of a mouse click in the chart
|
||||
ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
||||
|
||||
//
|
||||
// successful execution
|
||||
@@ -2133,10 +2229,14 @@ bool EventTextChange(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change object text
|
||||
result = ObjectSetString(chartID, name, OBJPROP_TEXT, text);
|
||||
result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2152,6 +2252,10 @@ bool EventMove(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// if time is not set, move event to the last bar
|
||||
@@ -2162,7 +2266,7 @@ bool EventMove(
|
||||
|
||||
//
|
||||
// move the object
|
||||
result = ObjectMove(chartID, name, 0, time, 0);
|
||||
result = ObjectMove(chartID, objName, 0, time, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2177,10 +2281,14 @@ bool EventDelete(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete the object
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2215,10 +2323,14 @@ bool ButtonCreate(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// create the button
|
||||
result = ObjectCreate(chartID, name, OBJ_BUTTON, subWindow, 0, 0);
|
||||
result = ObjectCreate(chartID, objName, OBJ_BUTTON, subWindow, 0, 0);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
@@ -2226,62 +2338,62 @@ bool ButtonCreate(
|
||||
|
||||
//
|
||||
// set button coordinates
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y);
|
||||
|
||||
//
|
||||
// set button size
|
||||
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height);
|
||||
|
||||
//
|
||||
// set the chart's corner, relative to which point coordinates are defined
|
||||
ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner);
|
||||
|
||||
//
|
||||
// set the text
|
||||
ObjectSetString(chartID, name, OBJPROP_TEXT, text);
|
||||
ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
||||
|
||||
//
|
||||
// set text font
|
||||
ObjectSetString(chartID, name, OBJPROP_FONT, font);
|
||||
ObjectSetString(chartID, objName, OBJPROP_FONT, font);
|
||||
|
||||
//
|
||||
// set font size
|
||||
ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize);
|
||||
|
||||
//
|
||||
// set text color
|
||||
ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr);
|
||||
|
||||
//
|
||||
// set background color
|
||||
ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, bgColor);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor);
|
||||
|
||||
//
|
||||
// set border color
|
||||
ObjectSetInteger(chartID, name, OBJPROP_BORDER_COLOR, borderColor);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_BORDER_COLOR, borderColor);
|
||||
|
||||
//
|
||||
// display in the foreground false or background true
|
||||
ObjectSetInteger(chartID, name, OBJPROP_BACK, back);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_BACK, back);
|
||||
|
||||
//
|
||||
// set button state
|
||||
ObjectSetInteger(chartID, name, OBJPROP_STATE, state);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_STATE, state);
|
||||
|
||||
//
|
||||
// enable true or disable false the mode of moving the button by mouse
|
||||
ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection);
|
||||
ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection);
|
||||
|
||||
//
|
||||
// hide true or display false graphical object name in the object list
|
||||
ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden);
|
||||
|
||||
//
|
||||
// set the priority for receiving the event of a mouse click in the chart
|
||||
ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder);
|
||||
ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2301,16 +2413,20 @@ bool ButtonMove(
|
||||
|
||||
//
|
||||
// move the button
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2330,16 +2446,20 @@ bool ButtonChangeSize(
|
||||
|
||||
//
|
||||
// change the button size
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2355,10 +2475,14 @@ bool ButtonChangeCorner(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change anchor corner
|
||||
result = ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner);
|
||||
result = ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2374,10 +2498,14 @@ bool ButtonTextChange(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// change object text
|
||||
result = ObjectSetString(chartID, name, OBJPROP_TEXT, text);
|
||||
result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2392,10 +2520,14 @@ bool ButtonDelete(
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Name ...
|
||||
string objName = drawPrefix + "_" + name;
|
||||
|
||||
//
|
||||
// delete the button
|
||||
result = ObjectDelete(chartID, name);
|
||||
result = ObjectDelete(chartID, objName);
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
@@ -81,6 +81,7 @@ public:
|
||||
void ~XSCXEMRNGStrategy()
|
||||
{
|
||||
delete mTMHelper;
|
||||
delete mSTRHelper;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -0,0 +1,823 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XSCXOBVGStrategy
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
/// Imports ...
|
||||
#include "../Helpers/x-saherelm.xosc.helper.mq5"
|
||||
#include "../Classes/x-saherelm.xstrategy.class.mq5"
|
||||
|
||||
//
|
||||
string XOBVGStartegyToken = "XOBVG";
|
||||
|
||||
//
|
||||
class XSCXOBVGStrategy : public XSCBaseStrategy
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XSCXOBVGStrategy(
|
||||
//
|
||||
// Base ...
|
||||
string _symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES _period, // Trading TimeFrame
|
||||
ENUM_TIMEFRAMES _analyzingPeriod, // Analyzing Period
|
||||
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,
|
||||
int _maxAllowedShorts = 0 //
|
||||
) : XSCBaseStrategy(_symbol,
|
||||
_period,
|
||||
_volume,
|
||||
_r2r,
|
||||
_slippage,
|
||||
_magicNumber,
|
||||
_useTPSLAsPoint,
|
||||
_forceMaxTPSLAsPoint,
|
||||
_tpPoint,
|
||||
_slPoint,
|
||||
_allowLong,
|
||||
_allowShort,
|
||||
_maxAllowedLongs,
|
||||
_maxAllowedShorts //
|
||||
)
|
||||
{
|
||||
//
|
||||
mAnalyzingPeriod = _analyzingPeriod;
|
||||
|
||||
//
|
||||
SetAlertPrefix(GetTag());
|
||||
|
||||
//
|
||||
PrepareRequirements();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
oBar.Clean();
|
||||
oBullishOrderBlock.Clean();
|
||||
oBearishOrderBlock.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXOBVGStrategy()
|
||||
{
|
||||
delete oscHelper;
|
||||
}
|
||||
|
||||
//
|
||||
// Getter / Setter (s) ...
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES AnalyzingPeriod()
|
||||
{
|
||||
return mAnalyzingPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
void AnalyzingPeriod(ENUM_TIMEFRAMES value)
|
||||
{
|
||||
mAnalyzingPeriod = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
//
|
||||
// Customize Strategy Identifier ...
|
||||
string GetTag() override
|
||||
{
|
||||
return XOBVGStartegyToken;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Conditions For Signal ...
|
||||
bool HasSignal(
|
||||
XSignal &signal //
|
||||
) override
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
signal.Clean();
|
||||
|
||||
//
|
||||
double sl = 0;
|
||||
double tp = 0;
|
||||
double risk = 0;
|
||||
double entry = 0;
|
||||
double reward = 0;
|
||||
double r2r = R2R();
|
||||
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
bool hasLong = false;
|
||||
bool hasShort = false;
|
||||
|
||||
//
|
||||
// For Trend ...
|
||||
XOHCL tmpHSW[];
|
||||
XOHCL tmpLSW[];
|
||||
|
||||
//
|
||||
// For Verifications ...
|
||||
|
||||
//
|
||||
bool useHammer = true;
|
||||
bool useMorningStar = false;
|
||||
bool useBullishEngulfing = true;
|
||||
bool useBullishMaurubozu = true;
|
||||
|
||||
//
|
||||
bool useShootingStar = true;
|
||||
bool useEveningStar = false;
|
||||
bool useBearishEngulfing = true;
|
||||
bool useBearishMaurubozu = true;
|
||||
|
||||
//
|
||||
// Bar On Trading Period ...
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 3 Bar LL and HH ...
|
||||
double ll3 = cBar.FindLowest(
|
||||
3,
|
||||
MODE_LOW //
|
||||
);
|
||||
double hh3 = cBar.FindHighest(
|
||||
3,
|
||||
MODE_HIGH //
|
||||
);
|
||||
|
||||
//
|
||||
double atr = oscHelper.GetATR(1);
|
||||
|
||||
//
|
||||
// Check OB Finder Bar ...
|
||||
result = oBar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Init OB Finder Bar ...
|
||||
result = oBar.Init(
|
||||
mSymbol,
|
||||
mAnalyzingPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBullishOrderBlock = oBullishOrderBlock.IsValid();
|
||||
bool hasBearishOrderBlock = oBearishOrderBlock.IsValid();
|
||||
|
||||
//
|
||||
// Here we Have to Check Order Block Age ...
|
||||
|
||||
//
|
||||
if (hasBullishOrderBlock)
|
||||
{
|
||||
//
|
||||
int age = oBullishOrderBlock.Index();
|
||||
result = age <= 26;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
oBar.Clean();
|
||||
oBullishOrderBlock.Clean();
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
fvgTouchDate = NULL;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasBearishOrderBlock)
|
||||
{
|
||||
//
|
||||
int age = oBearishOrderBlock.Index();
|
||||
result = age <= 26;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
oBar.Clean();
|
||||
oBearishOrderBlock.Clean();
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
fvgTouchDate = NULL;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
hasBullishOrderBlock = oBullishOrderBlock.IsValid();
|
||||
hasBearishOrderBlock = oBearishOrderBlock.IsValid();
|
||||
result =
|
||||
//
|
||||
hasBullishOrderBlock
|
||||
//
|
||||
||
|
||||
//
|
||||
hasBearishOrderBlock
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Detect Order Blocks ...
|
||||
hasBullishOrderBlock = oBar.HasBullishOrderBlock(oBullishOrderBlock);
|
||||
hasBearishOrderBlock = oBar.HasBearishOrderBlock(oBearishOrderBlock);
|
||||
|
||||
//
|
||||
// Check OB Detected ...
|
||||
result =
|
||||
//
|
||||
hasBullishOrderBlock
|
||||
//
|
||||
||
|
||||
//
|
||||
hasBearishOrderBlock
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
oBar.Clean();
|
||||
oBullishOrderBlock.Clean();
|
||||
oBearishOrderBlock.Clean();
|
||||
|
||||
//
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
fvgTouchDate = NULL;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (hasBullishOrderBlock)
|
||||
{
|
||||
//
|
||||
DrawBullishOrderBlock(
|
||||
oBullishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Detect an FVG Inside Order Block in Trading Period ...
|
||||
result = FindBullishFVGInsideOrderBlock();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
oBar.Clean();
|
||||
oBullishOrderBlock.Clean();
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
fvgTouchDate = NULL;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now We Have to Waits Until Price reached the FVG ...
|
||||
if (!isFVGTouched)
|
||||
{
|
||||
//
|
||||
isFVGTouched = ll3 < fvgUpper;
|
||||
fvgTouchDate = TimeCurrent();
|
||||
}
|
||||
|
||||
//
|
||||
result = isFVGTouched;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we Have to Wait for Pressure ...
|
||||
|
||||
//
|
||||
bool isHammer = !useHammer
|
||||
? false
|
||||
: cBar.IsHammer();
|
||||
bool isMorningStar = !useMorningStar
|
||||
? false
|
||||
: cBar.IsMorningStar();
|
||||
bool isBullishMarubozu = !useBullishEngulfing
|
||||
? false
|
||||
: cBar.IsBullishMarubozu();
|
||||
bool isBullishEngulfing = !useBullishMaurubozu
|
||||
? false
|
||||
: cBar.IsBullishEngulfing();
|
||||
|
||||
//
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
hasLong =
|
||||
//
|
||||
true
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isHammer
|
||||
//
|
||||
||
|
||||
//
|
||||
isMorningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishMarubozu
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishEngulfing
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
result = hasLong;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Check FVG Touch Date ...
|
||||
int cTimeSec = (int)TimeCurrent();
|
||||
int tTimeSec = (int)fvgTouchDate;
|
||||
int periodSec = PeriodSeconds(mPeriod);
|
||||
int touchAge = (cTimeSec - tTimeSec) / periodSec;
|
||||
if (touchAge >= 10)
|
||||
{
|
||||
//
|
||||
oBar.Clean();
|
||||
oBullishOrderBlock.Clean();
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
fvgTouchDate = NULL;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
type = POSITION_TYPE_BUY;
|
||||
sl = cBar.low - atr;
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (hasBearishOrderBlock)
|
||||
{
|
||||
//
|
||||
DrawBearishOrderBlock(
|
||||
oBearishOrderBlock,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
// Detect an FVG Inside Order Block in Trading Period ...
|
||||
result = FindBearishFVGInsideOrderBlock();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
oBar.Clean();
|
||||
oBearishOrderBlock.Clean();
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
fvgTouchDate = NULL;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now We Have to Waits Until Price reached the FVG ...
|
||||
if (!isFVGTouched)
|
||||
{
|
||||
//
|
||||
isFVGTouched = hh3 > fvgLower;
|
||||
fvgTouchDate = TimeCurrent();
|
||||
}
|
||||
|
||||
//
|
||||
result = isFVGTouched;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we Have to Wait for Pressure ...
|
||||
|
||||
//
|
||||
// Short ...
|
||||
bool isShootingStar = !useShootingStar
|
||||
? false
|
||||
: cBar.IsShootingStar();
|
||||
bool isEveningStar = !useEveningStar
|
||||
? false
|
||||
: cBar.IsEveningStar();
|
||||
bool isBearishEngulfing = !useBearishEngulfing
|
||||
? false
|
||||
: cBar.IsBearishEngulfing();
|
||||
bool isBearishMaurubozu = !useBearishMaurubozu
|
||||
? false
|
||||
: cBar.IsBearishMarubozu();
|
||||
|
||||
//
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
hasShort =
|
||||
//
|
||||
true
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isShootingStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isEveningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishEngulfing
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishMaurubozu
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
result = hasShort;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Check FVG Touch Date ...
|
||||
int cTimeSec = (int)TimeCurrent();
|
||||
int tTimeSec = (int)fvgTouchDate;
|
||||
int periodSec = PeriodSeconds(mPeriod);
|
||||
int touchAge = (cTimeSec - tTimeSec) / periodSec;
|
||||
if (touchAge >= 10)
|
||||
{
|
||||
//
|
||||
oBar.Clean();
|
||||
oBearishOrderBlock.Clean();
|
||||
fvgUpper = 0;
|
||||
fvgLower = 0;
|
||||
fvgTouchDate = NULL;
|
||||
isFVGTouched = false;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
type = POSITION_TYPE_SELL;
|
||||
sl = cBar.high + atr;
|
||||
}
|
||||
|
||||
//
|
||||
result = hasLong || hasShort;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
entry = GetEntry(mSymbol, type);
|
||||
CalculateTPSLByPrice(
|
||||
sl,
|
||||
tp,
|
||||
type,
|
||||
entry,
|
||||
r2r //
|
||||
);
|
||||
|
||||
//
|
||||
result = signal.Prepare(
|
||||
mSymbol,
|
||||
GetTag(),
|
||||
mPeriod,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
mVolume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mAnalyzingPeriod; // Analyzing Period
|
||||
|
||||
//
|
||||
XOSCInputs oscInputs;
|
||||
XSCXOSCHelper *oscHelper;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
XOHCL oBar;
|
||||
XOHCL oBullishOrderBlock;
|
||||
XOHCL oBearishOrderBlock;
|
||||
|
||||
//
|
||||
double fvgUpper;
|
||||
double fvgLower;
|
||||
bool isFVGTouched;
|
||||
datetime fvgTouchDate;
|
||||
|
||||
//
|
||||
void PrepareRequirements()
|
||||
{
|
||||
//
|
||||
oscInputs.Default();
|
||||
oscHelper = new XSCXOSCHelper();
|
||||
oscHelper.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
oscInputs //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool FindBullishFVGInsideOrderBlock()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = oBullishOrderBlock.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int totalBars = iBars(
|
||||
mSymbol,
|
||||
mPeriod //
|
||||
);
|
||||
int maxAllowed = totalBars / 10;
|
||||
|
||||
//
|
||||
for (int i = 0; i < maxAllowed; i++)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = iBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = iBar.HasBullishFVG(
|
||||
fvgUpper,
|
||||
fvgLower //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check FVG has Correlation by OB ...
|
||||
result =
|
||||
//
|
||||
// Full Inside ...
|
||||
(fvgUpper <= oBullishOrderBlock.high &&
|
||||
fvgLower >= oBullishOrderBlock.low)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper > oBullishOrderBlock.high &&
|
||||
fvgLower >= oBullishOrderBlock.low &&
|
||||
fvgLower <= oBullishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper > oBullishOrderBlock.low &&
|
||||
fvgUpper <= oBullishOrderBlock.high &&
|
||||
fvgLower < oBullishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
DrawBullishFVG(
|
||||
iBar,
|
||||
fvgUpper,
|
||||
fvgLower,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool FindBearishFVGInsideOrderBlock()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = oBearishOrderBlock.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int totalBars = iBars(
|
||||
mSymbol,
|
||||
mPeriod //
|
||||
);
|
||||
int maxAllowed = totalBars / 10;
|
||||
|
||||
//
|
||||
for (int i = 0; i < maxAllowed; i++)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = iBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = iBar.HasBearishFVG(
|
||||
fvgUpper,
|
||||
fvgLower //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check FVG has Correlation by OB ...
|
||||
result =
|
||||
//
|
||||
// Full Inside ...
|
||||
(fvgUpper <= oBearishOrderBlock.high &&
|
||||
fvgLower >= oBearishOrderBlock.low)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper > oBearishOrderBlock.high &&
|
||||
fvgLower >= oBearishOrderBlock.low &&
|
||||
fvgLower <= oBearishOrderBlock.high)
|
||||
//
|
||||
||
|
||||
//
|
||||
(fvgUpper > oBearishOrderBlock.low &&
|
||||
fvgUpper <= oBearishOrderBlock.high &&
|
||||
fvgLower < oBearishOrderBlock.low)
|
||||
//
|
||||
;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
DrawBearishFVG(
|
||||
iBar,
|
||||
fvgUpper,
|
||||
fvgLower,
|
||||
ChartID() //
|
||||
);
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,446 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XSCXEMRNGStrategy
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
|
||||
//
|
||||
/// Imports ...
|
||||
#include "../Helpers/x-saherelm.xtm.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xstr.helper.mq5"
|
||||
#include "../Classes/x-saherelm.xstrategy.class.mq5"
|
||||
|
||||
//
|
||||
string XEMRNGStartegyToken = "XEMRNG";
|
||||
|
||||
//
|
||||
class XSCXEMRNGStrategy : public XSCBaseStrategy
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XSCXEMRNGStrategy(
|
||||
//
|
||||
// Base ...
|
||||
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,
|
||||
int _maxAllowedShorts = 0 //
|
||||
) : XSCBaseStrategy(_symbol,
|
||||
_period,
|
||||
_volume,
|
||||
_r2r,
|
||||
_slippage,
|
||||
_magicNumber,
|
||||
_useTPSLAsPoint,
|
||||
_forceMaxTPSLAsPoint,
|
||||
_tpPoint,
|
||||
_slPoint,
|
||||
_allowLong,
|
||||
_allowShort,
|
||||
_maxAllowedLongs,
|
||||
_maxAllowedShorts //
|
||||
)
|
||||
{
|
||||
//
|
||||
ConfigureRequirements();
|
||||
|
||||
//
|
||||
SetAlertPrefix(GetTag());
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXEMRNGStrategy()
|
||||
{
|
||||
delete mTMHelper;
|
||||
}
|
||||
|
||||
//
|
||||
// Getter / Setter (s) ...
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
//
|
||||
// Customize Strategy Identifier ...
|
||||
string GetTag() override
|
||||
{
|
||||
return XEMRNGStartegyToken;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Conditions For Signal ...
|
||||
bool HasSignal(
|
||||
XSignal &signal //
|
||||
) override
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
signal.Clean();
|
||||
|
||||
//
|
||||
double sl = 0;
|
||||
double tp = 0;
|
||||
double risk = 0;
|
||||
double entry = 0;
|
||||
double reward = 0;
|
||||
double r2r = R2R();
|
||||
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
int start = 0;
|
||||
int count = 5;
|
||||
|
||||
//
|
||||
double tms[];
|
||||
ArraySetAsSeries(tms, true);
|
||||
mTMHelper.CopyMain(
|
||||
start,
|
||||
count,
|
||||
tms //
|
||||
);
|
||||
|
||||
//
|
||||
XSTRConditions strConditions;
|
||||
result = mSTRHelper.GetConditions(
|
||||
strConditions,
|
||||
start,
|
||||
count //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
1 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double hh5 = cBar.FindHighest(
|
||||
5,
|
||||
MODE_HIGH //
|
||||
);
|
||||
double ll5 = cBar.FindLowest(
|
||||
5,
|
||||
MODE_LOW //
|
||||
);
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasLong = false;
|
||||
bool hasShort = false;
|
||||
|
||||
//
|
||||
XOHCL tmpHSW[];
|
||||
XOHCL tmpLSW[];
|
||||
|
||||
//
|
||||
bool useHammer = true;
|
||||
bool useMorningStar = false;
|
||||
bool useBullishEngulfing = true;
|
||||
bool useBullishMaurubozu = true;
|
||||
|
||||
//
|
||||
bool useShootingStar = true;
|
||||
bool useEveningStar = false;
|
||||
bool useBearishEngulfing = true;
|
||||
bool useBearishMaurubozu = true;
|
||||
|
||||
//
|
||||
// Long ...
|
||||
|
||||
//
|
||||
bool isHammer = !useHammer
|
||||
? false
|
||||
: cBar.IsHammer();
|
||||
bool isMorningStar = !useMorningStar
|
||||
? false
|
||||
: cBar.IsMorningStar();
|
||||
bool isBullishMarubozu = !useBullishEngulfing
|
||||
? false
|
||||
: cBar.IsBullishMarubozu();
|
||||
bool isBullishEngulfing = !useBullishMaurubozu
|
||||
? false
|
||||
: cBar.IsBullishEngulfing();
|
||||
|
||||
//
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Find Swing Low Above of EMA ...
|
||||
// Find Swing High Above of EMA ...
|
||||
// Fins Swing Low Below of EMA ...
|
||||
// Detect Bullish Pattern ...
|
||||
hasLong =
|
||||
//
|
||||
cBar.IsBullish()
|
||||
//
|
||||
&&
|
||||
//
|
||||
isBullishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
cBar.close > tms[1]
|
||||
//
|
||||
&&
|
||||
//
|
||||
ll5 < tms[1]
|
||||
//
|
||||
&&
|
||||
//
|
||||
strConditions.isTrendSwitchedToBullish
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isHammer
|
||||
//
|
||||
||
|
||||
//
|
||||
isMorningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishMarubozu
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishEngulfing
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
if (hasLong)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
sl = tmpLSW[ArraySize(tmpLSW) - 1].low;
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
bool isShootingStar = !useShootingStar
|
||||
? false
|
||||
: cBar.IsShootingStar();
|
||||
bool isEveningStar = !useEveningStar
|
||||
? false
|
||||
: cBar.IsEveningStar();
|
||||
bool isBearishEngulfing = !useBearishEngulfing
|
||||
? false
|
||||
: cBar.IsBearishEngulfing();
|
||||
bool isBearishMaurubozu = !useBearishMaurubozu
|
||||
? false
|
||||
: cBar.IsBearishMarubozu();
|
||||
|
||||
//
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
hasShort =
|
||||
//
|
||||
cBar.IsBearish()
|
||||
//
|
||||
&&
|
||||
//
|
||||
isBearishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
cBar.close < tms[1]
|
||||
//
|
||||
&&
|
||||
//
|
||||
hh5 > tms[1]
|
||||
//
|
||||
&&
|
||||
//
|
||||
strConditions.isTrendSwitchedToBearish
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isShootingStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isEveningStar
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishEngulfing
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishMaurubozu
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
if (hasShort)
|
||||
{
|
||||
//
|
||||
type = POSITION_TYPE_SELL;
|
||||
|
||||
//
|
||||
sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
|
||||
}
|
||||
|
||||
//
|
||||
result = hasLong || hasShort;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
entry = GetEntry(mSymbol, type);
|
||||
CalculateTPSLByPrice(
|
||||
sl,
|
||||
tp,
|
||||
type,
|
||||
entry,
|
||||
r2r //
|
||||
);
|
||||
|
||||
//
|
||||
result = signal.Prepare(
|
||||
mSymbol,
|
||||
GetTag(),
|
||||
mPeriod,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
mVolume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
XTMInputs mTMInputs; // Tren Magic Inputs ...
|
||||
XSCXTMHelper *mTMHelper; // Trend Magic Helper Class ...
|
||||
|
||||
//
|
||||
XSTRInputs mSTRInputs; // Super Trend Inputs ...
|
||||
XSCXSTRHelper *mSTRHelper; // Super Trend Helper Class ...
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
|
||||
//
|
||||
// Set Default TM Inputs ...
|
||||
void ConfigureRequirements()
|
||||
{
|
||||
//
|
||||
mTMInputs.maShift = 0;
|
||||
mTMInputs.maPeriod = 100;
|
||||
mTMInputs.maMethod = MODE_EMA;
|
||||
mTMInputs.maAppliedTo = PRICE_CLOSE;
|
||||
|
||||
//
|
||||
mTMInputs.showLine = true;
|
||||
|
||||
//
|
||||
mTMHelper = new XSCXTMHelper();
|
||||
|
||||
//
|
||||
mTMHelper.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mTMInputs //
|
||||
);
|
||||
|
||||
//
|
||||
mSTRInputs.length = 14;
|
||||
mSTRInputs.multiplier = 3.5;
|
||||
mSTRInputs.appliedTo = PRICE_CLOSE;
|
||||
|
||||
//
|
||||
mSTRInputs.showTrends = true;
|
||||
mSTRInputs.fillTrends = false;
|
||||
|
||||
//
|
||||
mSTRHelper = new XSCXSTRHelper();
|
||||
mSTRHelper.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mSTRInputs //
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user