Initial Commit ...
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// False Positives ...
|
||||
!(
|
||||
(
|
||||
(xEU5Conditions.isXTSCurrentUnderNearest ||
|
||||
xEU5Conditions.isXTSCurrentCrossedUnderNearest)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXTSCurrentUnderMediest ||
|
||||
xEU5Conditions.isXTSCurrentCrossedUnderMediest)
|
||||
//
|
||||
)
|
||||
//
|
||||
? (xEU5Conditions.isXLHPriceInSignalRange
|
||||
? (
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
: (xEU5Conditions.isXLHPriceOverSignal ||
|
||||
xEU5Conditions.isXLHPriceCrossedOverSignal)
|
||||
? (
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
: (xEU5Conditions.isXLHPriceUnderSignal ||
|
||||
xEU5Conditions.isXLHPriceCrossedUnderSignal)
|
||||
? (
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
: true
|
||||
//
|
||||
)
|
||||
//
|
||||
// Just Current XTS Min and Faest ...
|
||||
: (xEU5Conditions.isXLHPriceInSignalRange
|
||||
? (
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
: (xEU5Conditions.isXLHPriceOverSignal ||
|
||||
xEU5Conditions.isXLHPriceCrossedOverSignal)
|
||||
? (
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
: (
|
||||
xEU5Conditions.isXLHPriceUnderSignal ||
|
||||
xEU5Conditions.isXLHPriceCrossedUnderSignal)
|
||||
? (
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
: true
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
@@ -0,0 +1,236 @@
|
||||
|
||||
//
|
||||
// Handle Indirectional Supports ...
|
||||
void XEU5HandleIndirectionalSupport()
|
||||
{
|
||||
//
|
||||
// Disable Indirections ...
|
||||
if (!xEU5EnableIndirectionalSupportTrades)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XSignal signals[];
|
||||
xEU5Trader.GetSignals(
|
||||
signals);
|
||||
int signalsCount = ArraySize(signals);
|
||||
if (signalsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Open Positions ...
|
||||
for (int i = 0; i < signalsCount; i++)
|
||||
{
|
||||
//
|
||||
// Retrieve i Signal ...
|
||||
XSignal iSignal = signals[i];
|
||||
|
||||
//
|
||||
// Generate iSignals Default Comment ...
|
||||
string iDefComment = xEU5Trader.GenerateSignalComment(iSignal);
|
||||
|
||||
//
|
||||
// Check Trade is Main Trade or not ...
|
||||
bool isMainTrade = iSignal.comment == iDefComment;
|
||||
if (!isMainTrade)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Trade Age Bigger Than 5 and Smaller Than 10 candle ...
|
||||
int iSignalAge = xEU5Trader.GetSignalAge(iSignal);
|
||||
bool isAgeVerified = iSignalAge >= 5; // && iSignalAge < 145;
|
||||
if (!isAgeVerified)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Has InDD Before ...
|
||||
string comment = XEU5GenerateIndirectionalSupportComment(iSignal.ticket);
|
||||
XSignal inDDs[];
|
||||
xEU5Trader.FilterSignals(
|
||||
inDDs,
|
||||
comment);
|
||||
int inDDsCount = ArraySize(inDDs);
|
||||
bool hasInDD = inDDsCount >= 1;
|
||||
if (hasInDD)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check iSignal doesn't have sl ...
|
||||
bool isSLPassed = iSignal.sl <= 0;
|
||||
if (!isSLPassed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isILong = iSignal.type == X_SIGNAL_LONG;
|
||||
double exitPrice = GetExit(
|
||||
iSignal.symbol,
|
||||
iSignal.type);
|
||||
|
||||
//
|
||||
// Check Trade Profit isNegative and Has Enough Price Distance ...
|
||||
double priceDistance = PipsToPrice(10);
|
||||
double iSignalHitPrice = isILong
|
||||
? iSignal.entry - priceDistance
|
||||
: iSignal.entry + priceDistance;
|
||||
bool isPriceDistanceReached = isILong
|
||||
? exitPrice <= iSignalHitPrice
|
||||
: exitPrice >= iSignalHitPrice;
|
||||
if (!isPriceDistanceReached)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Requirements for Indirectional Support Trade ...
|
||||
string symbol = iSignal.symbol;
|
||||
ulong magic = iSignal.magicNumber;
|
||||
datetime time = iTime(iSignal.symbol, _Period, 0);
|
||||
ENUM_X_SIGNAL_TYPE type = xEU5Trader.GetSignalIndirectionType(iSignal);
|
||||
|
||||
//
|
||||
bool isLong = type == X_SIGNAL_LONG;
|
||||
double entry = GetEntry(
|
||||
symbol,
|
||||
type);
|
||||
double spread = GetSpread(iSignal.symbol);
|
||||
|
||||
//
|
||||
double risk = PipsToPrice(2);
|
||||
double reward = PipsToPrice(xEU5RiskFreeStepInPips); // PipsToPrice(xEU5RiskFreeStepInPips); // xEU5MinReward;
|
||||
double riskFreeRate = xEU5RiskFreeRate;
|
||||
double riskFreeStep = xEU5RiskFreeStepInPips;
|
||||
double volume = xEU5StaticVolume; // iSignal.volume;
|
||||
|
||||
//
|
||||
double sl = 0;
|
||||
// isLong
|
||||
// ? (entry - risk) - spread
|
||||
// : (entry + risk) + spread;
|
||||
double tp = isLong
|
||||
? entry + reward
|
||||
: entry - reward;
|
||||
|
||||
//
|
||||
// Generate Indirectional Support Signal ...
|
||||
XSignal inDSSignal = {};
|
||||
inDSSignal.tp = tp;
|
||||
inDSSignal.sl = sl;
|
||||
inDSSignal.type = type;
|
||||
inDSSignal.time = time;
|
||||
inDSSignal.entry = entry;
|
||||
inDSSignal.symbol = symbol;
|
||||
inDSSignal.volume = volume;
|
||||
inDSSignal.comment = comment;
|
||||
inDSSignal.magicNumber = magic;
|
||||
inDSSignal.riskFreeRate = riskFreeRate;
|
||||
inDSSignal.riskFreeStep = riskFreeStep;
|
||||
|
||||
//
|
||||
// Check Generated Signal Validation ...
|
||||
bool isInDSignalValid = IsValid(inDSSignal, xEU5MagicNumber);
|
||||
if (!isInDSignalValid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute Signal ...
|
||||
ENUM_EXECUTION_SIGNAL_RESULT executionResult = xEU5Trader.ExecuteSignal(
|
||||
inDSSignal,
|
||||
false, // Ignore TP/SL Virtuals ...
|
||||
true, // Ignore Number of Trades ...
|
||||
true // Check Account Conditions ...
|
||||
);
|
||||
bool isExecuted = executionResult == X_TRADER_SUCCEED_EXECUTION;
|
||||
if (isExecuted)
|
||||
{
|
||||
//
|
||||
// TODO: Alert this ...
|
||||
LogMessage("InDirectional Support Trade Executed for: " + (string)iSignal.ticket);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// TODO: Alert this ...
|
||||
LogMessage("Error in Executing Indirectional Support Trade for: " + (string)iSignal.ticket + "\n" + GetSignalExecutionError(executionResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Comment ...
|
||||
string XEU5GenerateIndirectionalSupportComment(ulong ticket)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += XEU5_INDIRECTION_SUPPORT_ID + "(" + (string)ticket + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Comment is Indirectional or not ...
|
||||
bool XEU5IsIndirectionalSupport(string comment)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int pos = StringFind(
|
||||
comment,
|
||||
XEU5_INDIRECTION_SUPPORT_ID);
|
||||
result = pos >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Parent Position Ticket ...
|
||||
ulong XEU5GetIndirectionalParentTicket(string comment)
|
||||
{
|
||||
//
|
||||
ulong result = -1;
|
||||
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XEU5IsIndirectionalSupport(comment))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Parent ...
|
||||
string ticketStr = ExtractString(
|
||||
comment,
|
||||
XEU5_INDIRECTION_SUPPORT_ID + "(",
|
||||
")");
|
||||
if (StringLen(ticketStr) > 0)
|
||||
{
|
||||
result = (ulong)ticketStr;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,696 @@
|
||||
//
|
||||
// XTAM Short Signal Checking ...
|
||||
bool XEU5XTAMHasShortSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!xEU5MXTAMEnableSignaller ||
|
||||
!xEU5MXTAMAllowShortSignals)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAMaBuffer[1] < xTMMaBuffer[1] &&
|
||||
xAMAMaBuffer[2] < xTMMaBuffer[2]
|
||||
//
|
||||
&&
|
||||
//
|
||||
xEU5Conditions.isXAMABearish
|
||||
//
|
||||
&&
|
||||
//
|
||||
xEU5Conditions.isXTMBearish
|
||||
//
|
||||
&&
|
||||
//
|
||||
xEU5Conditions.isXFIUnderZero
|
||||
//
|
||||
&&
|
||||
//
|
||||
xEU5Conditions.isXTSCurrentMin
|
||||
//
|
||||
&&
|
||||
//
|
||||
xEU5Conditions.isXTSCurrentUnderFarest
|
||||
//
|
||||
&&
|
||||
//
|
||||
!xEU5Conditions.isXOBDSwingHigh
|
||||
//
|
||||
&&
|
||||
//
|
||||
!(
|
||||
//
|
||||
xEU5Conditions.isXCHMASCVale &&
|
||||
xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCVale
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
(
|
||||
(
|
||||
xEU5Conditions.isXTSCurrentUnderNearest ||
|
||||
xEU5Conditions.isXTSCurrentCrossedUnderNearest) ||
|
||||
(xEU5Conditions.isXTSCurrentUnderMediest ||
|
||||
xEU5Conditions.isXTSCurrentCrossedUnderMediest))
|
||||
? (
|
||||
//
|
||||
(
|
||||
//
|
||||
(xEU5Conditions.isXLHPriceUnderSignal ||
|
||||
xEU5Conditions.isXLHPriceInSignalRange ||
|
||||
xEU5Conditions.isXLHPriceCrossedUnderSignal)
|
||||
? !(
|
||||
(xEU5Conditions.isXLHLowAttachedLL &&
|
||||
xEU5Conditions.isXLHHHSameInLength &&
|
||||
xEU5Conditions.isXCHLHSCMCLLSame)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLLDecreased &&
|
||||
(xEU5Conditions.isXCHLHSCMCLLSame ||
|
||||
xEU5Conditions.isXCHLHMCLCHHSame))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSameHHs &&
|
||||
xEU5Conditions.isXLHHHIncreased)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHLHSCMCHHSame)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSameLLs ||
|
||||
xEU5Conditions.isXLHLowAttachedLL ||
|
||||
xEU5Conditions.isXLHHHSameInLength)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLLSameInLength &&
|
||||
//
|
||||
(
|
||||
//
|
||||
xEU5Conditions.isXLHHHSameInLength
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCTrendsUp &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCTrendsDown &&
|
||||
xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMASCFastUnderSlow &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCOverMax &&
|
||||
xEU5Conditions.isXCHMASCUnderMax)
|
||||
//
|
||||
||
|
||||
//
|
||||
(
|
||||
xEU5Conditions.isXCHMALCPeak &&
|
||||
(
|
||||
//
|
||||
xEU5Conditions.isXCHMAMCVale
|
||||
//
|
||||
||
|
||||
//
|
||||
xEU5Conditions.isXCHMAMCPeak
|
||||
//
|
||||
||
|
||||
//
|
||||
xEU5Conditions.isXLHHHDecreased
|
||||
//
|
||||
||
|
||||
//
|
||||
xEU5Conditions.isXLHLLIncreased
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMASCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCFastOverSlow &&
|
||||
xEU5Conditions.isXTDBullCrossedUnderBear)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSCMCHHSame &&
|
||||
(xEU5Conditions.isXTDBullCrossedUnderBear
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
(!xEU5Conditions.isXCHMAMCTrendsUp &&
|
||||
!xEU5Conditions.isXCHMAMCTrendsDown))
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCTrendsUp &&
|
||||
xEU5Conditions.isXCHMALCTrendsUp &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHMCLCLLSame &&
|
||||
xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHHHDecreased &&
|
||||
(
|
||||
//
|
||||
xEU5Conditions.isXRSIVale
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
: (xEU5Conditions.isXLHPriceOverSignal ||
|
||||
xEU5Conditions.isXLHPriceCrossedOverSignal)
|
||||
? (
|
||||
!(
|
||||
xEU5Conditions.isXCHLHSameHHs
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCOverMin &&
|
||||
xEU5Conditions.isXCHMASCUnderMin)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHLHSCMCHHSame)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLLIncreased &&
|
||||
(xEU5Conditions.isXLHHHIncreased
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCPeak &&
|
||||
xEU5Conditions.isXLHHHSameInLength &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLLSameInLength &&
|
||||
(
|
||||
//
|
||||
xEU5Conditions.isXLHHHSameInLength
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCPeak &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXTDSignalVale &&
|
||||
xEU5Conditions.isXTDBullishVale)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHHHSameInLength &&
|
||||
(
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCOverMax &&
|
||||
(xEU5Conditions.isXCHMASCUnderMax ||
|
||||
xEU5Conditions.isXCHMASCCrossedUnderMax))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCVale &&
|
||||
xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMALCVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMALCVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXTDSignalVale &&
|
||||
xEU5Conditions.isXTDBullishVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHMAMCTrendsUp &&
|
||||
xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHMCLCHHSame ||
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCPeak &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHHHIncreased &&
|
||||
xEU5Conditions.isXCHMASCTrendsDown &&
|
||||
xEU5Conditions.isXCHMAMCTrendsDown &&
|
||||
xEU5Conditions.isXCHMASCFastUnderSlow &&
|
||||
xEU5Conditions.isXCHMAMCFastUnderSlow)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
(
|
||||
xEU5Conditions.isXLHLLSameInLength &&
|
||||
(
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCTrendsDown &&
|
||||
xEU5Conditions.isXCHMAMCTrendsDown &&
|
||||
xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMASCFastUnderSlow &&
|
||||
xEU5Conditions.isXCHMAMCFastUnderSlow &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
))
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
: (
|
||||
!xEU5Conditions.isXLHPriceOverSignal &&
|
||||
!xEU5Conditions.isXLHPriceUnderSignal &&
|
||||
!xEU5Conditions.isXLHPriceInSignalRange &&
|
||||
!xEU5Conditions.isXLHPriceCrossedOverSignal &&
|
||||
!xEU5Conditions.isXLHPriceCrossedUnderSignal)
|
||||
? !(
|
||||
//
|
||||
(xEU5Conditions.isXLHHHSameInLength &&
|
||||
xEU5Conditions.isXLHLLSameInLength)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCTrendsUp &&
|
||||
xEU5Conditions.isXCHMALCTrendsUp &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
)
|
||||
: true)
|
||||
//
|
||||
)
|
||||
: true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
(
|
||||
(xEU5Conditions.isXTDBullOverBear ||
|
||||
(xEU5Conditions.isXTDBullUnderBear ||
|
||||
xEU5Conditions.isXTDBullCrossedUnderBear)) &&
|
||||
(xEU5Conditions.isXTDSignalUnderBear ||
|
||||
xEU5Conditions.isXTDSignalCrossedUnderBear))
|
||||
? !(
|
||||
(xEU5Conditions.isXTMVale &&
|
||||
xEU5Conditions.isXAMAVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXLHLLSameInLength)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXTDSignalVale &&
|
||||
xEU5Conditions.isXTDBullishVale &&
|
||||
xEU5Conditions.isXLHLLIncreased &&
|
||||
xEU5Conditions.isXLHHHSameInLength)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLLIncreased &&
|
||||
xEU5Conditions.isXLHHHSameInLength &&
|
||||
xEU5Conditions.isXLHPriceCrossedUnderSignal)
|
||||
//
|
||||
)
|
||||
: true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
(xEU5Conditions.isXLHPriceUnderSignal ||
|
||||
xEU5Conditions.isXLHPriceCrossedUnderSignal)
|
||||
? !(
|
||||
//
|
||||
(xEU5Conditions.isXLHLLSameInLength &&
|
||||
(
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCFastOverSlow &&
|
||||
(xEU5Conditions.isXCHMALCPeak ||
|
||||
xEU5Conditions.isXCHMAMCVale))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLowAttachedLL &&
|
||||
xEU5Conditions.isXCHLHSameHHs)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHHHSameInLength &&
|
||||
(
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCOverMin &&
|
||||
xEU5Conditions.isXCHMASCUnderMin)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSCMCLLSame &&
|
||||
xEU5Conditions.isXCHLHMCLCHHSame)
|
||||
//
|
||||
||
|
||||
(
|
||||
//
|
||||
(xEU5Conditions.isXLHLLSameInLength &&
|
||||
//
|
||||
(
|
||||
(xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSCMCHHSame &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSCMCLLSame &&
|
||||
(xEU5Conditions.isXCHLHMCLCHHSame ||
|
||||
xEU5Conditions.isXCHMALCFastOverSlow))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
((xEU5Conditions.isXTDSignalVale &&
|
||||
xEU5Conditions.isXTDBullishVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSCMCLLSame &&
|
||||
xEU5Conditions.isXCHMALCFastOverSlow))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHLHSCMCLLSame &&
|
||||
xEU5Conditions.isXLHLowAttachedLL)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
(
|
||||
//
|
||||
xEU5Conditions.isXCHMAMCVale
|
||||
//
|
||||
||
|
||||
//
|
||||
xEU5Conditions.isXCHMASCFastOverSlow
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
xEU5Conditions.isXCHLHSameLLs
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXAMAVale &&
|
||||
xEU5Conditions.isXCHMALCPeak &&
|
||||
xEU5Conditions.isXCHLHSCMCLLSame &&
|
||||
xEU5Conditions.isXCHLHMCLCHHSame)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
))
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLLIncreased &&
|
||||
xEU5Conditions.isXCHMASCFastOverSlow &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow &&
|
||||
xEU5Conditions.isXRSICrossedOverLongExit &&
|
||||
xEU5Conditions.isXLHPriceCrossedUnderSignal)
|
||||
//
|
||||
)
|
||||
: xEU5Conditions.isXLHPriceInSignalRange
|
||||
? (
|
||||
//
|
||||
(
|
||||
xEU5Conditions.isXLHHHSameInLength
|
||||
? !(
|
||||
//
|
||||
xEU5Conditions.isXCHLHSameLLs
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCVale &&
|
||||
xEU5Conditions.isXCHMALCVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCVale &&
|
||||
xEU5Conditions.isXCHMALCVale)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXTDSignalVale ||
|
||||
xEU5Conditions.isXLHLLSameInLength)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMALCPeak &&
|
||||
xEU5Conditions.isXLHHHIncreased &&
|
||||
xEU5Conditions.isXCHLHMCLCHHSame)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCVale &&
|
||||
((xEU5Conditions.isXCHMAMCTrendsUp &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMALCTrendsDown &&
|
||||
xEU5Conditions.isXCHMALCFastUnderSlow)
|
||||
//
|
||||
))
|
||||
//
|
||||
)
|
||||
: true
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
: (xEU5Conditions.isXLHPriceOverSignal ||
|
||||
xEU5Conditions.isXLHPriceCrossedOverSignal)
|
||||
? !(
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMALCPeak)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHHHSameInLength &&
|
||||
(
|
||||
//
|
||||
xEU5Conditions.isXLHLLSameInLength
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMALCVale &&
|
||||
xEU5Conditions.isXCHMAMCTrendsUp &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXLHLLSameInLength &&
|
||||
(
|
||||
//
|
||||
xEU5Conditions.isXFICrossedUnderZero
|
||||
//
|
||||
||
|
||||
//
|
||||
xEU5Conditions.isXTDBullCrossedUnderBear
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMAMCFastOverSlow)
|
||||
//
|
||||
||
|
||||
//
|
||||
(xEU5Conditions.isXCHMASCOverMax &&
|
||||
xEU5Conditions.isXCHMASCUnderMax)
|
||||
//
|
||||
))
|
||||
//
|
||||
)
|
||||
: true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
!(
|
||||
//
|
||||
xEU5Conditions.isXCHMAMCPeak &&
|
||||
xEU5Conditions.isXCHMALCPeak &&
|
||||
xEU5Conditions.isXLHHHIncreased &&
|
||||
xEU5Conditions.isXLHHHSameInLength &&
|
||||
xEU5Conditions.isXLHPriceInSignalRange &&
|
||||
xEU5Conditions.isXTSCurrentCrossedUnderFarest
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,262 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTS Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
enum ENUM_X_PERIOD_METHOD
|
||||
{
|
||||
//
|
||||
X_PERIOD_NOTHING,
|
||||
//
|
||||
X_PERIOD_AUTO,
|
||||
//
|
||||
X_PERIOD_MANUALLY
|
||||
};
|
||||
|
||||
enum ENUM_X_XTS_BUFFER_LINES
|
||||
{
|
||||
X_XTS_CURRENT_LINE = 0,
|
||||
X_XTS_NEAREST_LINE = 1,
|
||||
X_XTS_MEDIEST_LINE = 2,
|
||||
X_XTS_FAREST_LINE = 3,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "XTS Indicator";
|
||||
|
||||
//
|
||||
input group "XTS Current Period";
|
||||
input ENUM_APPLIED_PRICE xTSCurrentAppliedTo = PRICE_CLOSE; // Current Applied To
|
||||
//
|
||||
input group "XTS Nearest Period";
|
||||
input ENUM_X_PERIOD_METHOD xTSNearestMethod = X_PERIOD_AUTO; // How to Find Nearest Period
|
||||
input ENUM_TIMEFRAMES xTSNearestPeriod = NULL; // Nearest Time Frame
|
||||
input ENUM_APPLIED_PRICE xTSNearestAppliedTo = PRICE_CLOSE; // Nearest Applied To
|
||||
//
|
||||
input group "XTS Mediest Period";
|
||||
input ENUM_X_PERIOD_METHOD xTSMediestMethod = X_PERIOD_AUTO; // How to Find Mediest Period
|
||||
input ENUM_TIMEFRAMES xTSMediestPeriod = NULL; // Mediest Time Frame
|
||||
input ENUM_APPLIED_PRICE xTSMediestAppliedTo = PRICE_CLOSE; // Mediest Applied To
|
||||
//
|
||||
input group "XTS Farest Period";
|
||||
input ENUM_X_PERIOD_METHOD xTSFarestMethod = X_PERIOD_AUTO; // How to Find Farest Period
|
||||
input ENUM_TIMEFRAMES xTSFarestPeriod = NULL; // Farest Time Frame
|
||||
input ENUM_APPLIED_PRICE xTSFarestAppliedTo = PRICE_CLOSE; // Farest Applied To
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTSHandler = INVALID_HANDLE;
|
||||
double xTSCurrentBuffer[];
|
||||
double xTSNearestBuffer[];
|
||||
double xTSMediestBuffer[];
|
||||
double xTSFarestBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XTSValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XTS Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XTSInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Indicator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTS Handler ...
|
||||
ArraySetAsSeries(xTSCurrentBuffer, true);
|
||||
ArraySetAsSeries(xTSNearestBuffer, true);
|
||||
ArraySetAsSeries(xTSMediestBuffer, true);
|
||||
ArraySetAsSeries(xTSFarestBuffer, true);
|
||||
xTSHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xts.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
"",
|
||||
xTSCurrentAppliedTo,
|
||||
"",
|
||||
xTSNearestMethod,
|
||||
xTSNearestPeriod,
|
||||
xTSNearestAppliedTo,
|
||||
"",
|
||||
xTSMediestMethod,
|
||||
xTSMediestPeriod,
|
||||
xTSMediestAppliedTo,
|
||||
"",
|
||||
xTSFarestMethod,
|
||||
xTSFarestPeriod,
|
||||
xTSFarestAppliedTo
|
||||
//
|
||||
);
|
||||
if (xTSHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTS Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XTSReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTSHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTSReadBuffers(
|
||||
int xTSItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XTS Current ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_CURRENT_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSCurrentBuffer);
|
||||
|
||||
//
|
||||
// XTS Nearest ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_NEAREST_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSNearestBuffer);
|
||||
|
||||
//
|
||||
// XTS Mediest ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_MEDIEST_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSMediestBuffer);
|
||||
|
||||
//
|
||||
// XTS Farest ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_FAREST_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSFarestBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTS Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTSIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xTSCurrentBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTS Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,558 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTS Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XTS
|
||||
// Description: Time Sections Indicator ...
|
||||
//
|
||||
//
|
||||
// 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 XTS Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XTS"
|
||||
|
||||
enum ENUM_X_PERIOD_METHOD
|
||||
{
|
||||
//
|
||||
X_PERIOD_NOTHING,
|
||||
//
|
||||
X_PERIOD_AUTO,
|
||||
//
|
||||
X_PERIOD_MANUALLY
|
||||
};
|
||||
|
||||
//
|
||||
// XTS Indicator States ...
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Current Period";
|
||||
input ENUM_APPLIED_PRICE currentAppliedTo = PRICE_CLOSE; // Current Applied To
|
||||
//
|
||||
input group "Nearest Period";
|
||||
input ENUM_X_PERIOD_METHOD nearestMethod = X_PERIOD_AUTO; // How to Find Nearest Period
|
||||
input ENUM_TIMEFRAMES nearestPeriod = NULL; // Nearest Time Frame
|
||||
input ENUM_APPLIED_PRICE nearestAppliedTo = PRICE_CLOSE; // Nearest Applied To
|
||||
//
|
||||
input group "Mediest Period";
|
||||
input ENUM_X_PERIOD_METHOD mediestMethod = X_PERIOD_AUTO; // How to Find Mediest Period
|
||||
input ENUM_TIMEFRAMES mediestPeriod = NULL; // Mediest Time Frame
|
||||
input ENUM_APPLIED_PRICE mediestAppliedTo = PRICE_CLOSE; // Mediest Applied To
|
||||
//
|
||||
input group "Farest Period";
|
||||
input ENUM_X_PERIOD_METHOD farestMethod = X_PERIOD_AUTO; // How to Find Farest Period
|
||||
input ENUM_TIMEFRAMES farestPeriod = NULL; // Farest Time Frame
|
||||
input ENUM_APPLIED_PRICE farestAppliedTo = PRICE_CLOSE; // Farest Applied To
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// Current ...
|
||||
#define currentBufferIndex 0
|
||||
|
||||
double currentBuffer[];
|
||||
|
||||
#property indicator_label1 "XTS C"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
#define nearestBufferIndex 1
|
||||
|
||||
double nearestBuffer[];
|
||||
|
||||
#property indicator_label2 "XTS N"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
#define mediestBufferIndex 2
|
||||
|
||||
double mediestBuffer[];
|
||||
|
||||
#property indicator_label3 "XTS M"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrLime
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
#define farestBufferIndex 3
|
||||
|
||||
double farestBuffer[];
|
||||
|
||||
#property indicator_label4 "XTS F"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrLightBlue
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mNearestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mMediestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mFarestPeriod = NULL;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
OnDeinitDrawLibrary();
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = 0; i < limit && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
ArraySetAsSeries(currentBuffer, true);
|
||||
SetIndexBuffer(currentBufferIndex, currentBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(currentBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
ArraySetAsSeries(nearestBuffer, true);
|
||||
SetIndexBuffer(nearestBufferIndex, nearestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(nearestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
ArraySetAsSeries(mediestBuffer, true);
|
||||
SetIndexBuffer(mediestBufferIndex, mediestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mediestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
ArraySetAsSeries(farestBuffer, true);
|
||||
SetIndexBuffer(farestBufferIndex, farestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(farestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Current ...
|
||||
CalculateCurrent(bar_index);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
CalculateNearest(bar_index);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
CalculateMediest(bar_index);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
CalculateFarest(bar_index);
|
||||
|
||||
//
|
||||
// Commenting ...
|
||||
string comment = GenerateDescriptionComment();
|
||||
Comment(comment);
|
||||
}
|
||||
|
||||
//
|
||||
// Current ...
|
||||
void CalculateCurrent(int bar_index)
|
||||
{
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
currentAppliedTo);
|
||||
|
||||
//
|
||||
currentBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
void CalculateNearest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mNearestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (nearestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mNearestPeriod = GetNearestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mNearestPeriod = nearestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mNearestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
nearestAppliedTo);
|
||||
|
||||
//
|
||||
nearestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
void CalculateMediest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mMediestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (mediestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mMediestPeriod = GetMediestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mMediestPeriod = mediestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mMediestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
mediestAppliedTo);
|
||||
|
||||
//
|
||||
mediestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
void CalculateFarest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mFarestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (farestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mFarestPeriod = GetFarestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mFarestPeriod = farestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mFarestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
farestAppliedTo);
|
||||
|
||||
//
|
||||
farestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Comment ...
|
||||
string GenerateDescriptionComment()
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += "Nearest : " + EnumToString(mNearestPeriod) + "\n";
|
||||
result += "Mediest : " + EnumToString(mMediestPeriod) + "\n";
|
||||
result += "Farest : " + EnumToString(mFarestPeriod) + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,262 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTS Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
enum ENUM_X_PERIOD_METHOD
|
||||
{
|
||||
//
|
||||
X_PERIOD_NOTHING,
|
||||
//
|
||||
X_PERIOD_AUTO,
|
||||
//
|
||||
X_PERIOD_MANUALLY
|
||||
};
|
||||
|
||||
enum ENUM_X_XTS_BUFFER_LINES
|
||||
{
|
||||
X_XTS_CURRENT_LINE = 0,
|
||||
X_XTS_NEAREST_LINE = 1,
|
||||
X_XTS_MEDIEST_LINE = 2,
|
||||
X_XTS_FAREST_LINE = 3,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "XTS Oscillator";
|
||||
|
||||
//
|
||||
input group "XTS Current Period";
|
||||
input ENUM_APPLIED_PRICE xTSCurrentAppliedTo = PRICE_CLOSE; // Current Applied To
|
||||
//
|
||||
input group "XTS Nearest Period";
|
||||
input ENUM_X_PERIOD_METHOD xTSNearestMethod = X_PERIOD_AUTO; // How to Find Nearest Period
|
||||
input ENUM_TIMEFRAMES xTSNearestPeriod = NULL; // Nearest Time Frame
|
||||
input ENUM_APPLIED_PRICE xTSNearestAppliedTo = PRICE_CLOSE; // Nearest Applied To
|
||||
//
|
||||
input group "XTS Mediest Period";
|
||||
input ENUM_X_PERIOD_METHOD xTSMediestMethod = X_PERIOD_AUTO; // How to Find Mediest Period
|
||||
input ENUM_TIMEFRAMES xTSMediestPeriod = NULL; // Mediest Time Frame
|
||||
input ENUM_APPLIED_PRICE xTSMediestAppliedTo = PRICE_CLOSE; // Mediest Applied To
|
||||
//
|
||||
input group "XTS Farest Period";
|
||||
input ENUM_X_PERIOD_METHOD xTSFarestMethod = X_PERIOD_AUTO; // How to Find Farest Period
|
||||
input ENUM_TIMEFRAMES xTSFarestPeriod = NULL; // Farest Time Frame
|
||||
input ENUM_APPLIED_PRICE xTSFarestAppliedTo = PRICE_CLOSE; // Farest Applied To
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTSHandler = INVALID_HANDLE;
|
||||
double xTSCurrentBuffer[];
|
||||
double xTSNearestBuffer[];
|
||||
double xTSMediestBuffer[];
|
||||
double xTSFarestBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XTSValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XTS Oscillator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XTSInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTS Handler ...
|
||||
ArraySetAsSeries(xTSCurrentBuffer, true);
|
||||
ArraySetAsSeries(xTSNearestBuffer, true);
|
||||
ArraySetAsSeries(xTSMediestBuffer, true);
|
||||
ArraySetAsSeries(xTSFarestBuffer, true);
|
||||
xTSHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xts.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
"",
|
||||
xTSCurrentAppliedTo,
|
||||
"",
|
||||
xTSNearestMethod,
|
||||
xTSNearestPeriod,
|
||||
xTSNearestAppliedTo,
|
||||
"",
|
||||
xTSMediestMethod,
|
||||
xTSMediestPeriod,
|
||||
xTSMediestAppliedTo,
|
||||
"",
|
||||
xTSFarestMethod,
|
||||
xTSFarestPeriod,
|
||||
xTSFarestAppliedTo
|
||||
//
|
||||
);
|
||||
if (xTSHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTS Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XTSReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTSHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTSReadBuffers(
|
||||
int xTSItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XTS Current ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_CURRENT_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSCurrentBuffer);
|
||||
|
||||
//
|
||||
// XTS Nearest ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_NEAREST_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSNearestBuffer);
|
||||
|
||||
//
|
||||
// XTS Mediest ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_MEDIEST_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSMediestBuffer);
|
||||
|
||||
//
|
||||
// XTS Farest ...
|
||||
CopyBuffer(
|
||||
xTSHandler,
|
||||
X_XTS_FAREST_LINE,
|
||||
0,
|
||||
xTSItemsPerTick,
|
||||
xTSFarestBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTS Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTSIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xTSCurrentBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTS Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,558 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTS Oscillator
|
||||
// ---------------------------------------------
|
||||
// Name: XTS
|
||||
// Description: Time Sections Oscillator ...
|
||||
//
|
||||
//
|
||||
// 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 XTS Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XTS"
|
||||
|
||||
enum ENUM_X_PERIOD_METHOD
|
||||
{
|
||||
//
|
||||
X_PERIOD_NOTHING,
|
||||
//
|
||||
X_PERIOD_AUTO,
|
||||
//
|
||||
X_PERIOD_MANUALLY
|
||||
};
|
||||
|
||||
//
|
||||
// XTS Oscillator States ...
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Current Period";
|
||||
input ENUM_APPLIED_PRICE currentAppliedTo = PRICE_CLOSE; // Current Applied To
|
||||
//
|
||||
input group "Nearest Period";
|
||||
input ENUM_X_PERIOD_METHOD nearestMethod = X_PERIOD_AUTO; // How to Find Nearest Period
|
||||
input ENUM_TIMEFRAMES nearestPeriod = NULL; // Nearest Time Frame
|
||||
input ENUM_APPLIED_PRICE nearestAppliedTo = PRICE_CLOSE; // Nearest Applied To
|
||||
//
|
||||
input group "Mediest Period";
|
||||
input ENUM_X_PERIOD_METHOD mediestMethod = X_PERIOD_AUTO; // How to Find Mediest Period
|
||||
input ENUM_TIMEFRAMES mediestPeriod = NULL; // Mediest Time Frame
|
||||
input ENUM_APPLIED_PRICE mediestAppliedTo = PRICE_CLOSE; // Mediest Applied To
|
||||
//
|
||||
input group "Farest Period";
|
||||
input ENUM_X_PERIOD_METHOD farestMethod = X_PERIOD_AUTO; // How to Find Farest Period
|
||||
input ENUM_TIMEFRAMES farestPeriod = NULL; // Farest Time Frame
|
||||
input ENUM_APPLIED_PRICE farestAppliedTo = PRICE_CLOSE; // Farest Applied To
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// Current ...
|
||||
#define currentBufferIndex 0
|
||||
|
||||
double currentBuffer[];
|
||||
|
||||
#property indicator_label1 "XTS C"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
#define nearestBufferIndex 1
|
||||
|
||||
double nearestBuffer[];
|
||||
|
||||
#property indicator_label2 "XTS N"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
#define mediestBufferIndex 2
|
||||
|
||||
double mediestBuffer[];
|
||||
|
||||
#property indicator_label3 "XTS M"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrLime
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
#define farestBufferIndex 3
|
||||
|
||||
double farestBuffer[];
|
||||
|
||||
#property indicator_label4 "XTS F"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrLightBlue
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mNearestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mMediestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mFarestPeriod = NULL;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Oscillator ShortName ...
|
||||
SetOscillatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
OnDeinitDrawLibrary();
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = 0; i < limit && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
ArraySetAsSeries(currentBuffer, true);
|
||||
SetIndexBuffer(currentBufferIndex, currentBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(currentBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
ArraySetAsSeries(nearestBuffer, true);
|
||||
SetIndexBuffer(nearestBufferIndex, nearestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(nearestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
ArraySetAsSeries(mediestBuffer, true);
|
||||
SetIndexBuffer(mediestBufferIndex, mediestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mediestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
ArraySetAsSeries(farestBuffer, true);
|
||||
SetIndexBuffer(farestBufferIndex, farestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(farestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Oscillator Short Name and also we can define Buffers Labels ...
|
||||
void SetOscillatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Current ...
|
||||
CalculateCurrent(bar_index);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
CalculateNearest(bar_index);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
CalculateMediest(bar_index);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
CalculateFarest(bar_index);
|
||||
|
||||
//
|
||||
// Commenting ...
|
||||
string comment = GenerateDescriptionComment();
|
||||
Comment(comment);
|
||||
}
|
||||
|
||||
//
|
||||
// Current ...
|
||||
void CalculateCurrent(int bar_index)
|
||||
{
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
currentAppliedTo);
|
||||
|
||||
//
|
||||
currentBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
void CalculateNearest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mNearestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (nearestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mNearestPeriod = GetNearestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mNearestPeriod = nearestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mNearestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
nearestAppliedTo);
|
||||
|
||||
//
|
||||
nearestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
void CalculateMediest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mMediestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (mediestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mMediestPeriod = GetMediestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mMediestPeriod = mediestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mMediestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
mediestAppliedTo);
|
||||
|
||||
//
|
||||
mediestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
void CalculateFarest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mFarestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (farestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mFarestPeriod = GetFarestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mFarestPeriod = farestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mFarestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
farestAppliedTo);
|
||||
|
||||
//
|
||||
farestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Comment ...
|
||||
string GenerateDescriptionComment()
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += "Nearest : " + EnumToString(mNearestPeriod) + "\n";
|
||||
result += "Mediest : " + EnumToString(mMediestPeriod) + "\n";
|
||||
result += "Farest : " + EnumToString(mFarestPeriod) + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user