bkp workspace ...

This commit is contained in:
2024-05-13 18:21:02 +03:30
parent d2dcdd1a64
commit 3fa288c92c
50 changed files with 36881 additions and 0 deletions
@@ -0,0 +1,558 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center RSIMA MQL5 Expert Advisor
// -------------------------------------------------
// Name: XDONCHAINEA
// Description: an Exper Advisor which used RSI and MA
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XDONCHAINEA"
#property strict
//
#include <Trade/Trade.mqh>
//
#define ShortName "XDONCHAINEA"
//
// Inputs ...
long magicNumber = 78692110;
double lotSize = 0.01;
//
double stopLoss = 200;
double takeProfit = 400;
//
//
//
//
int xdonHandler;
double xdonUpperBuffer[];
double xdonLowerBuffer[];
//
int ma20Handler;
double ma20Buffer[];
//
int ma50Handler;
double ma50Buffer[];
//
int ma100Handler;
double ma100Buffer[];
//
CTrade trade;
//
ENUM_TIMEFRAMES scPeriod = NULL;
ENUM_TIMEFRAMES mcPeriod = NULL;
ENUM_TIMEFRAMES lcPeriod = NULL;
ENUM_TIMEFRAMES hcPeriod = NULL;
//
MqlTick currentTick;
MqlRates rates[];
MqlRates scRates[];
MqlRates mcRates[];
MqlRates lcRates[];
MqlRates hcRates[];
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
trade.SetExpertMagicNumber(magicNumber);
//
xdonHandler = iCustom(
//
_Symbol,
_Period,
"x-saherelm.xdon",
//
// Inputs ...
52,
0
//
);
//
ma20Handler = iMA(
_Symbol,
_Period,
20,
0,
MODE_SMA,
PRICE_OPEN);
//
ma50Handler = iMA(
_Symbol,
_Period,
50,
0,
MODE_SMA,
PRICE_OPEN);
//
ma100Handler = iMA(
_Symbol,
_Period,
100,
0,
MODE_SMA,
PRICE_OPEN);
//
if (xdonHandler == INVALID_HANDLE ||
ma20Handler == INVALID_HANDLE ||
ma50Handler == INVALID_HANDLE ||
ma100Handler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
ArraySetAsSeries(rates, true);
ArraySetAsSeries(ma20Buffer, true);
ArraySetAsSeries(ma50Buffer, true);
ArraySetAsSeries(ma100Buffer, true);
ArraySetAsSeries(xdonUpperBuffer, true);
ArraySetAsSeries(xdonLowerBuffer, true);
//
// 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
//
// De Initialize XEA Providers ...
IndicatorRelease(ma20Handler);
IndicatorRelease(ma50Handler);
IndicatorRelease(ma100Handler);
IndicatorRelease(xdonHandler);
}
//
// On Tick Handler ...
void OnTick()
{
//
if (!IsNewBar())
{
return;
}
//
// Reading Tick ...
if (!SymbolInfoTick(_Symbol, currentTick))
{
return;
}
//
// if (scPeriod == NULL) {
// scPeriod = GetNearest
// }
//
// Prepare Rates ...
int ratesCopied = CopyRates(
_Symbol,
_Period,
0,
15,
rates);
//
int xdonUpperCopied = CopyBuffer(
xdonHandler,
0,
0,
15,
xdonUpperBuffer);
int xdonLowerCopied = CopyBuffer(
xdonHandler,
1,
0,
15,
xdonLowerBuffer);
if (xdonUpperCopied <= 0 || xdonLowerCopied <= 0)
{
return;
}
//
int ma20Copied = CopyBuffer(
ma20Handler,
0,
0,
15,
ma20Buffer);
int ma50Copied = CopyBuffer(
ma50Handler,
0,
0,
15,
ma50Buffer);
int ma100Copied = CopyBuffer(
ma100Handler,
0,
0,
15,
ma100Buffer);
if (ma20Copied <= 0 || ma50Copied <= 0 || ma100Copied <= 0)
{
return;
}
//
// BUY ...
bool buyConditions =
//
// First Condition ...
// ma20Buffer[1] < MathMin(ma50Buffer[1], ma100Buffer[1])
// //
// &&
//
// Donchain Condition ...
// Candle Must Shadow Hunt ...
(rates[1].low < xdonLowerBuffer[1] &&
MathMin(rates[1].open, rates[1].close) > xdonLowerBuffer[1])
//
||
//
(rates[1].low < xdonLowerBuffer[1] &&
rates[2].low < xdonLowerBuffer[2])
//
;
if (buyConditions)
{
//
//
double sl =
stopLoss <= 0
? 0
: currentTick.bid - (stopLoss * _Point);
if (!NormalizePrice(sl))
{
return;
}
//
double tp =
takeProfit <= 0
? 0
: currentTick.bid + (takeProfit * _Point);
if (!NormalizePrice(tp))
{
return;
}
//
trade.PositionOpen(
_Symbol,
ORDER_TYPE_BUY,
lotSize,
currentTick.ask,
sl,
tp,
ShortName);
}
//
// SELL ...
bool sellConditions =
//
// First Condition ...
// ma20Buffer[1] > MathMax(ma50Buffer[1], ma100Buffer[1])
// //
// &&
//
// Donchain Condition ...
// Candle Must Shadow Hunt ...
(rates[1].high > xdonUpperBuffer[1] &&
MathMax(rates[1].open, rates[1].close) < xdonUpperBuffer[1])
//
||
//
(rates[1].high > xdonUpperBuffer[1] &&
rates[2].high > xdonUpperBuffer[2])
//
;
if (sellConditions)
{
//
double sl =
stopLoss <= 0
? 0
: currentTick.ask - (stopLoss * _Point);
if (!NormalizePrice(sl))
{
return;
}
//
double tp =
takeProfit <= 0
? 0
: currentTick.ask + (takeProfit * _Point);
if (!NormalizePrice(tp))
{
return;
}
//
trade.PositionOpen(
_Symbol,
ORDER_TYPE_SELL,
lotSize,
currentTick.bid,
sl,
tp,
ShortName);
}
}
//
// TOOLS ...
bool IsNewBar()
{
//
static datetime prevTime = 0;
datetime currentTime = iTime(_Symbol, _Period, 0);
//
if (prevTime != currentTime)
{
//
prevTime = currentTime;
return true;
}
//
return false;
}
//
bool ValidateInputs()
{
//
bool result = true;
//
return result;
}
//
bool NormalizePrice(
double &price // What to Normal
)
{
//
bool result = false;
//
double tickSize = 0;
result = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE, tickSize);
if (!result)
{
return result;
}
//
price = NormalizeDouble(MathRound(price / tickSize) * tickSize, _Digits);
//
return result;
}
//
bool CountOpenPositions(
int &buyCount, // Buys
int &sellCount // Sells
)
{
//
bool result = false;
//
buyCount = 0;
sellCount = 0;
//
int total = PositionsTotal();
if (total <= 0)
{
return true;
}
//
for (int i = total - 1; i >= 0; i--)
{
//
ulong ticket = PositionGetTicket(i);
if (ticket <= 0)
{
continue;
}
//
bool isSelected = PositionSelectByTicket(ticket);
if (!isSelected)
{
continue;
}
//
long magic;
bool isMagicSelected = PositionGetInteger(POSITION_MAGIC, magic);
if (!isMagicSelected || (isMagicSelected && magic != magicNumber))
{
continue;
}
//
long typeInt;
ENUM_POSITION_TYPE type;
bool isTypeSelected = PositionGetInteger(POSITION_TYPE, typeInt);
if (!isTypeSelected)
{
continue;
}
//
type = (ENUM_POSITION_TYPE)typeInt;
//
if (type == POSITION_TYPE_BUY)
{
buyCount++;
}
else if (type == POSITION_TYPE_SELL)
{
sellCount++;
}
}
//
result = true;
//
return result;
}
//
bool ClosePositions(ENUM_POSITION_TYPE type)
{
//
bool result = false;
//
int total = PositionsTotal();
if (total <= 0)
{
return true;
}
//
for (int i = total - 1; i >= 0; i--)
{
//
ulong ticket = PositionGetTicket(i);
if (ticket <= 0)
{
continue;
}
//
bool isSelected = PositionSelectByTicket(ticket);
if (!isSelected)
{
continue;
}
//
long magic;
bool isMagicSelected = PositionGetInteger(POSITION_MAGIC, magic);
if (!isMagicSelected || (isMagicSelected && magic != magicNumber))
{
continue;
}
//
long typeInt;
ENUM_POSITION_TYPE pType;
bool isTypeSelected = PositionGetInteger(POSITION_TYPE, typeInt);
if (!isTypeSelected)
{
continue;
}
//
pType = (ENUM_POSITION_TYPE)typeInt;
//
if (type != pType)
{
continue;
}
//
trade.PositionClose(ticket);
}
//
result = true;
//
return result;
}
//
template <typename T>
string ToString(const T value)
{
//
return (string)value;
}
@@ -0,0 +1,494 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center RSIMA MQL5 Expert Advisor
// -------------------------------------------------
// Name: XRSIMAEA
// Description: an Exper Advisor which used RSI and MA
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XRSIMAEA"
#property strict
//
#include <Trade/Trade.mqh>
//
#define ShortName "XRSIMAEA"
//
// Inputs ...
long magicNumber = 78692110;
double lotSize = 0.01;
//
int rsiLength = 25;
int rsiLevel = 70;
//
int maLength = 25;
//
double stopLoss = 200;
double takeProfit = 100;
//
bool closeSignal = false;
//
//
//
//
int rsiHandler;
double rsiBuffer[];
//
int maHandler;
double maBuffer[];
//
CTrade trade;
//
MqlTick currentTick;
//
datetime openTimeBuy = 0;
datetime openTimeSell = 0;
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
trade.SetExpertMagicNumber(magicNumber);
//
rsiHandler = iRSI(
_Symbol,
_Period,
rsiLength,
PRICE_OPEN);
//
maHandler = iMA(
_Symbol,
PERIOD_H1,
maLength,
0,
MODE_SMA,
PRICE_OPEN);
//
if (rsiHandler == INVALID_HANDLE || maHandler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
ArraySetAsSeries(rsiBuffer, true);
ArraySetAsSeries(maBuffer, true);
//
// 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
//
// De Initialize XEA Providers ...
IndicatorRelease(rsiHandler);
IndicatorRelease(maHandler);
}
//
// On Tick Handler ...
void OnTick()
{
//
if (!IsNewBar())
{
return;
}
//
// Reading Tick ...
if (!SymbolInfoTick(_Symbol, currentTick))
{
return;
}
//
int rsiCopied = CopyBuffer(
rsiHandler,
0,
0,
2,
rsiBuffer);
if (rsiCopied < 2)
{
return;
}
//
int maCopied = CopyBuffer(
maHandler,
0,
0,
1,
maBuffer);
if (maCopied < 1)
{
return;
}
//
Comment(
"rsi[0]: " + ToString(rsiBuffer[0]) + "\n" +
"rsi[1]: " + ToString(rsiBuffer[1]) + "\n" +
"ma[0]: " + ToString(maBuffer[0]));
//
int buyCount;
int sellCount;
//
if (!CountOpenPositions(buyCount, sellCount))
{
return;
}
//
// BUY ...
if (
buyCount == 0 &&
rsiBuffer[1] >= (100 - rsiLevel) &&
rsiBuffer[0] < (100 - rsiLevel) &&
currentTick.ask > maBuffer[0])
{
//
if (closeSignal)
{
//
bool isClose = ClosePositions(POSITION_TYPE_SELL);
if (!isClose)
{
return;
}
}
//
double sl =
stopLoss <= 0
? 0
: currentTick.bid - (stopLoss * _Point);
if (!NormalizePrice(sl))
{
return;
}
//
double tp =
takeProfit <= 0
? 0
: currentTick.bid + (takeProfit * _Point);
if (!NormalizePrice(tp))
{
return;
}
//
trade.PositionOpen(
_Symbol,
ORDER_TYPE_BUY,
lotSize,
currentTick.ask,
sl,
tp,
ShortName);
}
//
// SELL ...
if (
sellCount == 0 &&
rsiBuffer[1] <= rsiLevel &&
rsiBuffer[0] > rsiLevel &&
currentTick.bid < maBuffer[0])
{
//
if (closeSignal)
{
//
bool isClose = ClosePositions(POSITION_TYPE_BUY);
if (!isClose)
{
return;
}
}
//
double sl =
stopLoss <= 0
? 0
: currentTick.ask - (stopLoss * _Point);
if (!NormalizePrice(sl))
{
return;
}
//
double tp =
takeProfit <= 0
? 0
: currentTick.ask + (takeProfit * _Point);
if (!NormalizePrice(tp))
{
return;
}
//
trade.PositionOpen(
_Symbol,
ORDER_TYPE_SELL,
lotSize,
currentTick.bid,
sl,
tp,
ShortName);
}
}
//
// TOOLS ...
bool IsNewBar()
{
//
static datetime prevTime = 0;
datetime currentTime = iTime(_Symbol, _Period, 0);
//
if (prevTime != currentTime)
{
//
prevTime = currentTime;
return true;
}
//
return false;
}
//
bool ValidateInputs()
{
//
bool result = true;
//
return result;
}
//
bool NormalizePrice(
double &price // What to Normal
)
{
//
bool result = false;
//
double tickSize = 0;
result = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE, tickSize);
if (!result)
{
return result;
}
//
price = NormalizeDouble(MathRound(price / tickSize) * tickSize, _Digits);
//
return result;
}
//
bool CountOpenPositions(
int &buyCount, // Buys
int &sellCount // Sells
)
{
//
bool result = false;
//
buyCount = 0;
sellCount = 0;
//
int total = PositionsTotal();
if (total <= 0)
{
return true;
}
//
for (int i = total - 1; i >= 0; i--)
{
//
ulong ticket = PositionGetTicket(i);
if (ticket <= 0)
{
continue;
}
//
bool isSelected = PositionSelectByTicket(ticket);
if (!isSelected)
{
continue;
}
//
long magic;
bool isMagicSelected = PositionGetInteger(POSITION_MAGIC, magic);
if (!isMagicSelected || (isMagicSelected && magic != magicNumber))
{
continue;
}
//
long typeInt;
ENUM_POSITION_TYPE type;
bool isTypeSelected = PositionGetInteger(POSITION_TYPE, typeInt);
if (!isTypeSelected)
{
continue;
}
//
type = (ENUM_POSITION_TYPE)typeInt;
//
if (type == POSITION_TYPE_BUY)
{
buyCount++;
}
else if (type == POSITION_TYPE_SELL)
{
sellCount++;
}
}
//
result = true;
//
return result;
}
//
bool ClosePositions(ENUM_POSITION_TYPE type)
{
//
bool result = false;
//
int total = PositionsTotal();
if (total <= 0)
{
return true;
}
//
for (int i = total - 1; i >= 0; i--)
{
//
ulong ticket = PositionGetTicket(i);
if (ticket <= 0)
{
continue;
}
//
bool isSelected = PositionSelectByTicket(ticket);
if (!isSelected)
{
continue;
}
//
long magic;
bool isMagicSelected = PositionGetInteger(POSITION_MAGIC, magic);
if (!isMagicSelected || (isMagicSelected && magic != magicNumber))
{
continue;
}
//
long typeInt;
ENUM_POSITION_TYPE pType;
bool isTypeSelected = PositionGetInteger(POSITION_TYPE, typeInt);
if (!isTypeSelected)
{
continue;
}
//
pType = (ENUM_POSITION_TYPE)typeInt;
//
if (type != pType)
{
continue;
}
//
trade.PositionClose(ticket);
}
//
result = true;
//
return result;
}
//
template <typename T>
string ToString(const T value)
{
//
return (string)value;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,377 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Expert Advisor
// ----------------------------------------
// Name: X121EA
// Description: this is an expert controller
// advisors which provides a mechanism for use them ...
//
// NOTE: about provider instancing in multi asset state:
// you can provide configurations using this:
//
// EURUSDb,USDCHFb|M5|0.01|X786,X92|true
// EURUSDb,GBPUSDb,USDJPYb,USDCHFb,XAUUSDb|M5,M15|0.01|X786|true
// EURUSDb,GBPUSDb,USDJPYb,USDCHFb,XAUUSDb|M5,M15|0.01|X786|true
//
// or make the instance use this:
//
// XPV(EURUSDb|M15|0.01|X92|true)XPV(GBPUSDb|M5|0.02|X786|false)
//
// if leave Configuration string blank this will used default config
// and One asset mode enabled ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121EA"
#property strict
//
// START Definitions ...
//
//
#define ShortName "X121EA"
//
// END Definitions ...
//
//
// START Inputs ...
//
//
// EA ...
input group "Common";
input bool xEAEnable = true; // Enable EA
input int xEASlippage = 10; // Slippgae
input ulong xEAMagicNumber = 1604056; // Magic Number
//
// Providers ...
input group "Providers";
input string xEAProvidersConfiguration = "EURUSDb,GBPUSDb,USDJPYb,USDCHFb,XAUUSDb|M5,M15|0.01|X786|true"; // Providers Configuration
input string xEADefaultSignalProviders = "XTEST"; // Default Allowed Signal Providers
//
// Signals ...
input group "Signals";
input bool xEAEnableLongs = true; // Enable Long Trades
input bool xEAEnableShorts = true; // Enable Short Trades
//
// Risk Management ...
input group "Risk Management";
input double xEAMaxAllowedSpread = 10; // Max Allowed Spread to Execute Signal
input int xEAMaxOpenPositions = 15; // Max Allowed Open Trades
input double xEAMinRiskAmountPerTrade = 0.001; // Min Risk Amount Per Trade
input double xEAMaxAllowedDrawDownFactor = 0.01; // Max Allowed Drawdown Factor
input double xEAMinProfitPerTrade = 0.5; // Min Acceptable Profit Per Trade
input double xEAMinProfitPerVolumeFactor = 0.01; // Min Acceptable Profit Volume Factor Per Trade
input bool xEAUseRiskAmountAsStaticVolume = true; // Use Provided Risk Amount as Static Volume
//
input group "EQM";
input int xEAMinAgeForDoSupport = 35; // Minimum Age For Supporting In Drawdown Positions when there isn't Equity
input int xEAMinAgeForUpdateSupports = 35; // Minimum Age For Update Untriggered Support Orders
//
// Alerts ...
input group "Alerts";
input bool xEAEnableAlerts = true; // Enable Events Alert
input bool xEAEnableHourlyAlerts = false; // Send Alert on each new Hour
input bool xEAEnableDailyAlerts = false; // Send Alert on each new Day
input bool xEAEnableWeeklyAlerts = false; // Send Alert on each new Week
input bool xEAEnableMonthlyAlerts = false; // Send Alert on each new Month
//
// END Inputs ...
//
//
// START Including Providers ...
//
//
// Logger Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Classes/x-saherelm.x121.xea.class.mq5"
#include "../Libraries/x-saherelm.seriallizer.lib.mq5"
//
// END Including Providers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
XSCX121EA *mX121EA;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
logTag = ShortName;
drawPrefix = logTag;
alertPrefix = logTag;
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
bool isInit = InitEAInstance();
if (!isInit)
{
return INIT_FAILED;
}
//
// 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
//
// De Initialize XEA Providers ...
delete mX121EA;
}
//
// On Tick Handler ...
void OnTick()
{
//
// Prevent Going Forward if user Disable it ...
if (xEAEnable)
{
mX121EA.OnTick();
}
}
//
// Handle Trade Events ...
void OnTrade()
{
mX121EA.OnTrade();
}
//
// Handle Signal Event ...
void OnSignalConditionsRecieved(X121MarketConditions &info)
{
}
//
// Handle StopLoss Event ...
void OnStopLossTriggered(const XDeal &deal)
{
}
//
// Handle TakeProfit Event ...
void OnTakeProfitTriggered(const XDeal &deal)
{
}
//
// Handle Deals Changed Event ...
void OnDealsChangedHandler(int count)
{
}
//
// Handle Order Changed Event ...
void OnOrdersChangedHandler(int count)
{
}
//
// Handle Position Changed Event ...
void OnPositionsChangedHandler(int count)
{
}
//
// Handle Trade State Changed ...
void OnTradeStateChangedHandler(const XOnTradeHandlerState &state)
{
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
// Validate Args ...
result =
//
xEASlippage > 0 &&
xEAMagicNumber > 0 &&
xEAMinRiskAmountPerTrade > 0 &&
StringLen(xEADefaultSignalProviders) > 0
//
// TODO: add new validations here ...
//
;
//
// Validate Providers ...
if (result)
{
//
string providers[];
SplitContent(
providers,
xEADefaultSignalProviders);
//
int providersCount = ArraySize(providers);
if (providersCount <= 0)
{
//
result = false;
return result;
}
//
string allProviders[];
GetAllProviders(allProviders);
//
bool hasError = false;
for (int i = 0; i < providersCount; i++)
{
//
string iProvider = providers[i];
if (!Contains(iProvider, allProviders))
{
//
hasError = true;
break;
}
}
//
if (hasError)
{
//
result = false;
return result;
}
}
//
// Logging State ...
string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
LogMessage(message);
//
return result;
}
//
// Initialize X121EA Class Instances ...
bool InitEAInstance()
{
//
bool result = false;
//
X121SignalProvider providers[];
//
// Try to Extract Configs ...
int configsCount = ExtractProviderConfigurations(
providers,
xEAProvidersConfiguration,
xEADefaultSignalProviders,
xEAMinRiskAmountPerTrade,
xEAUseRiskAmountAsStaticVolume);
//
mX121EA = new XSCX121EA(
_Symbol,
_Period,
xEAMagicNumber,
xEASlippage,
xEAMaxAllowedSpread,
xEAMaxOpenPositions,
xEAMinProfitPerTrade,
xEAMinProfitPerVolumeFactor,
xEAMaxAllowedDrawDownFactor,
OnStopLossTriggered,
OnTakeProfitTriggered,
OnDealsChangedHandler,
OnOrdersChangedHandler,
OnPositionsChangedHandler,
OnTradeStateChangedHandler,
//
xEAMinAgeForDoSupport,
xEAMinAgeForUpdateSupports,
OnSignalConditionsRecieved);
//
mX121EA.EnableLongs(xEAEnableLongs);
mX121EA.EnableShorts(xEAEnableShorts);
//
// Attach Providers to EA Instance ...
int providersCount = ArraySize(providers);
int addedProviders = mX121EA.AddProviders(providers);
result = addedProviders == providersCount;
//
return result;
}
//
// END Functions ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,631 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XCHE
// Description: Chandelier Exit 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 X121_XCHE Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "X121_XCHE"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 35; // Length
input int loopback = 26; // Loopback
input double multiplier1 = 3.0; // 1st Multiplier
input double multiplier2 = 3.5; // 2nd Multiplier
//
input group "Calculation";
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
//
input group "Presentation";
input bool showLongExit1Line = true; // Show 1st Long Exit
input bool showShortExit1Line = true; // Show 1st Short Exit
input bool showLongExit2Line = true; // Show 2st Long Exit
input bool showShortExit2Line = true; // Show 2st Short Exit
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 8
//
// Long Exit 1 ...
#define longExit1BufferIndex 0
double longExit1Buffer[];
//
#property indicator_label1 "X121_XCHE LE 1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_DOT
//
// Short Exit 1 ...
#define shortExit1BufferIndex 1
double shortExit1Buffer[];
//
#property indicator_label2 "X121_XCHE SE 1"
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color2 clrRed
//
// Long Exit 2 ...
#define longExit2BufferIndex 2
double longExit2Buffer[];
//
#property indicator_label3 "X121_XCHE LE 2"
#property indicator_type3 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color3 clrAqua
//
// Short Exit 2 ...
#define shortExit2BufferIndex 3
double shortExit2Buffer[];
//
#property indicator_label4 "X121_XCHE SE 2"
#property indicator_type4 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color4 clrMagenta
//
// START Arrows ...
//
// Long Exit 1 Start ...
#define longExit1StartBufferIndex 4
double longExit1StartBuffer[];
//
#property indicator_label5 "X121_XCHE LES 1"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrLime
//
// Short Exit 1 Start ...
#define shortExit1StartBufferIndex 5
double shortExit1StartBuffer[];
//
#property indicator_label6 "X121_XCHE SES 1"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrRed
//
// Long Exit 2 Start ...
#define longExit2StartBufferIndex 6
double longExit2StartBuffer[];
//
#property indicator_label7 "X121_XCHE LES 2"
#property indicator_type7 DRAW_ARROW
#property indicator_color7 clrAqua
//
// Short Exit 2 Start ...
#define shortExit2StartBufferIndex 7
double shortExit2StartBuffer[];
//
#property indicator_label8 "X121_XCHE SES 2"
#property indicator_type8 DRAW_ARROW
#property indicator_color8 clrMagenta
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
// Working Array ...
double work[][6];
#define hi1Idx 0
#define lo1Idx 1
#define hi2Idx 2
#define lo2Idx 3
#define trend1Idx 4
#define trend2Idx 5
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// 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 mPeriod 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(
//
// 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[])
{
//
if (Bars(_Symbol, _Period) < rates_total)
{
return (prev_calculated);
}
//
if (ArrayRange(work, 0) != rates_total)
{
ArrayResize(work, rates_total);
}
//
// this counts Available Bars ...
int limit;
//
limit = prev_calculated - 1;
if (limit < 0)
{
limit = 0;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
low,
close);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
result =
length >= 9 &&
loopback >= 0;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(length, loopback);
//
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()
{
//
uint arrowCode = 159;
//
// LEVEL 1 ...
//
// Long Exit 1 ...
//
// Draw Type ...
ENUM_DRAW_TYPE longExit1DrawType = showLongExit1Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE longExit1StartDrawType = showLongExit1Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(longExit1BufferIndex, longExit1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit1BufferIndex, PLOT_SHOW_DATA, showLongExit1Line);
PlotIndexSetInteger(longExit1BufferIndex, PLOT_DRAW_TYPE, longExit1DrawType);
//
// Start Buffer ...
SetIndexBuffer(longExit1StartBufferIndex, longExit1StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_DRAW_TYPE, longExit1StartDrawType);
//
// Short Exit 1 ...
//
// Draw Type ...
ENUM_DRAW_TYPE shortExit1DrawType = showShortExit1Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE shortExit1StartDrawType = showShortExit1Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(shortExit1BufferIndex, shortExit1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_SHOW_DATA, showShortExit1Line);
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_DRAW_TYPE, shortExit1DrawType);
//
// Start Buffer ...
SetIndexBuffer(shortExit1StartBufferIndex, shortExit1StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_DRAW_TYPE, shortExit1StartDrawType);
//
// LEVEL 2 ...
//
// Long Exit 2 ...
//
// Draw Type ...
ENUM_DRAW_TYPE longExit2DrawType = showLongExit2Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE longExit2StartDrawType = showLongExit2Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(longExit2BufferIndex, longExit2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit2BufferIndex, PLOT_SHOW_DATA, showLongExit2Line);
PlotIndexSetInteger(longExit2BufferIndex, PLOT_DRAW_TYPE, longExit2DrawType);
//
// Start Buffer ...
SetIndexBuffer(longExit2StartBufferIndex, longExit2StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_DRAW_TYPE, longExit2StartDrawType);
//
// Short Exit 2 ...
//
// Draw Type ...
ENUM_DRAW_TYPE shortExit2DrawType = showShortExit2Line ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE shortExit2StartDrawType = showShortExit2Line ? DRAW_ARROW : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(shortExit2BufferIndex, shortExit2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_SHOW_DATA, showShortExit2Line);
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_DRAW_TYPE, shortExit2DrawType);
//
// Start Buffer ...
SetIndexBuffer(shortExit2StartBufferIndex, shortExit2StartBuffer, INDICATOR_DATA);
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_ARROW, arrowCode);
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_DRAW_TYPE, shortExit2StartDrawType);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
int prevCalculated, // Previous Calculated
int ratesTotal, // Total Rates
const double &open[], // Rates Open ...
const double &high[], // Rates High ...
const double &low[], // Rates Low ...
const double &close[] // Rates Close ...
)
{
//
// Cleanup Buffers ...
longExit1Buffer[bar_index] = longExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index] = shortExit1StartBuffer[bar_index] = EMPTY_VALUE;
longExit2Buffer[bar_index] = longExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index] = shortExit2StartBuffer[bar_index] = EMPTY_VALUE;
//
int start = MathMax(bar_index - loopback, 0);
//
// Calculate ATR Value ...
double atrValue = 0;
for (int k = 1; k <= length && (bar_index - k - 1) >= 0; k++)
{
//
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
}
atrValue /= (double)length;
//
// Retrieve Highest High and Lowest Lows ...
double loopbackMax = high[ArrayMaximum(high, start, loopback)];
double loopbackMin = low[ArrayMinimum(low, start, loopback)];
//
// Fill Multi Dimesional Working Array ...
work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue;
work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue;
work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue;
work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue;
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
//
if (bar_index > 0)
{
//
// Calculate Trends ...
if (close[bar_index] > work[bar_index - 1][lo1Idx])
{
work[bar_index][trend1Idx] = 1;
}
//
if (close[bar_index] < work[bar_index - 1][hi1Idx])
{
work[bar_index][trend1Idx] = -1;
}
//
if (close[bar_index] > work[bar_index - 1][lo2Idx])
{
work[bar_index][trend2Idx] = 1;
}
//
if (close[bar_index] < work[bar_index - 1][hi2Idx])
{
work[bar_index][trend2Idx] = -1;
}
//
// Calculate Exit Values ...
//
// Exit 1 ...
//
// Long ...
if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1)
{
//
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
{
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
}
//
longExit1Buffer[bar_index] = work[bar_index][hi1Idx];
//
if (longExit1Buffer[bar_index - 1] == EMPTY_VALUE)
{
longExit1StartBuffer[bar_index] = longExit1Buffer[bar_index];
}
}
//
// Short ...
if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1)
{
//
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
{
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
}
//
shortExit1Buffer[bar_index] = work[bar_index][lo1Idx];
//
if (shortExit1Buffer[bar_index - 1] == EMPTY_VALUE)
{
shortExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index];
}
}
//
// Exit 2 ...
//
// Long ...
if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1)
{
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
{
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
}
//
longExit2Buffer[bar_index] = work[bar_index][hi2Idx];
//
if (longExit2Buffer[bar_index - 1] == EMPTY_VALUE)
{
longExit2StartBuffer[bar_index] = longExit2Buffer[bar_index];
}
}
//
// Short ...
if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1)
{
//
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
{
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
}
//
shortExit2Buffer[bar_index] = work[bar_index][lo2Idx];
//
if (shortExit2Buffer[bar_index - 1] == EMPTY_VALUE)
{
shortExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index];
}
}
}
}
//
// END Functions ...
//
@@ -0,0 +1,348 @@
//////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XDEMA
// Description: Super Trend 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 X121_XAMA Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "X121_XDEMA"
//
// END Constants ...
//
//
// START Inputs ...
//
//
// Market ...
input group "Market";
input int length = 200; // Length
input int shift = 0; // Shift
//
// Presentation ...
input group "Presentation";
input bool showDema = true; // Show Dema
input bool showEMA = false; // Show EMA
input bool showEMAOfEMA = false; // Show EMA of EMA
//
// END Inputs ...
//
//
// Includes Common Library ...
#include <MovingAverages.mqh>
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 6
#property indicator_plots 6
//
#define demaBufferIndex 0
double demaBuffer[];
//
#define demaColorBufferIndex 1
double demaColorBuffer[];
//
#property indicator_label1 "X121_XDEMA DEMA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrDodgerBlue, CLR_NONE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#define emaBufferIndex 2
double emaBuffer[];
//
#define emaColorBufferIndex 3
double emaColorBuffer[];
//
#property indicator_label2 "X121_XDEMA EMA"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrBlue, CLR_NONE
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
#define emaOfEMABufferIndex 4
double emaOfEMABuffer[];
//
#define emaOfEMAColorBufferIndex 5
double emaOfEMAColorBuffer[];
//
#property indicator_label3 "X121_XDEMA EMA of EMA"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrOrange, CLR_NONE
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// 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
}
//
// Do Calculations ...
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//
ArraySetAsSeries(price, true);
//
// check for data ...
if (rates_total < 2 * length - 2)
{
return 0;
}
//
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// calculate EMA ...
ExponentialMAOnBuffer(rates_total, prev_calculated, 0, length, price, emaBuffer);
//
// calculate EMA on EMA array ...
ExponentialMAOnBuffer(rates_total, prev_calculated, length - 1, length, emaBuffer, emaOfEMABuffer);
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// calculate DEMA ...
demaBuffer[i] = 2 * emaBuffer[i] - emaOfEMABuffer[i];
//
double showColorIDX = 0;
double hideColorIDX = 1;
//
demaColorBuffer[i] = hideColorIDX;
emaColorBuffer[i] = hideColorIDX;
emaOfEMAColorBuffer[i] = hideColorIDX;
//
if (showDema)
{
demaColorBuffer[i] = showColorIDX;
}
//
if (showEMA)
{
emaColorBuffer[i] = showColorIDX;
}
//
if (showEMAOfEMA)
{
emaOfEMAColorBuffer[i] = showColorIDX;
}
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
(length > 2 &&
shift >= 0)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Peaks and Vales ...
result = length;
//
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()
{
//
// DEMA ...
//
// Buffer ...
ArraySetAsSeries(demaBuffer, true);
SetIndexBuffer(demaBufferIndex, demaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(demaBufferIndex, PLOT_SHOW_DATA, showDema);
//
// Color Buffer ...
ArraySetAsSeries(demaColorBuffer, true);
SetIndexBuffer(demaColorBufferIndex, demaColorBuffer, INDICATOR_COLOR_INDEX);
//
// EMA ...
//
// Buffer ...
ArraySetAsSeries(emaBuffer, true);
SetIndexBuffer(emaBufferIndex, emaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(emaBufferIndex, PLOT_SHOW_DATA, showEMA);
//
// Color Buffer ...
ArraySetAsSeries(emaColorBuffer, true);
SetIndexBuffer(emaColorBufferIndex, emaColorBuffer, INDICATOR_COLOR_INDEX);
//
// EMA of EMA ...
//
// Buffer ...
ArraySetAsSeries(emaOfEMABuffer, true);
SetIndexBuffer(emaOfEMABufferIndex, emaOfEMABuffer, INDICATOR_DATA);
PlotIndexSetInteger(emaOfEMABufferIndex, PLOT_SHOW_DATA, showEMAOfEMA);
//
// Color Buffer ...
ArraySetAsSeries(emaOfEMAColorBuffer, true);
SetIndexBuffer(emaOfEMAColorBufferIndex, emaOfEMAColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// END Functions ...
//
@@ -0,0 +1,964 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XDSR
// Description: Dynamic Support and Resistances ...
//
// 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 XDSR Indicator"
#property strict
//
#define ShortName "XDSR"
//
// Includes ...
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// INPUT ...
//
// Maarket ...
input group "Cycles";
//
// Short ...
input group "Short";
input ENUM_X_PERIOD_METHOD scMode = X_PERIOD_MANUALLY; // Method
input ENUM_TIMEFRAMES scPeriod = PERIOD_H4; // Period
//
// Medium ...
input group "Medium";
input ENUM_X_PERIOD_METHOD mcMode = X_PERIOD_MANUALLY; // Method
input ENUM_TIMEFRAMES mcPeriod = PERIOD_H12; // Mid Period
//
// Long ...
input group "Long";
input ENUM_X_PERIOD_METHOD lcMode = X_PERIOD_MANUALLY; // Method
input ENUM_TIMEFRAMES lcPeriod = PERIOD_D1; // Long Period
//
// Hind ...
input group "Hind";
input ENUM_X_PERIOD_METHOD hcMode = X_PERIOD_MANUALLY; // Method
input ENUM_TIMEFRAMES hcPeriod = PERIOD_W1; // Hind Period
//
// BUFFERS ...
//
#property indicator_chart_window
//
#property indicator_buffers 24
#property indicator_plots 24
//
// Short ...
//
// Open ...
//
#define scOpenBufferIndex 0
#define scOpenBufferPlotIndex 0
double scOpenBuffer[];
//
#define scOpenColorBufferIndex 1
double scOpenColorBuffer[];
//
#property indicator_label1 "X121_XDSR SC O"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrGreen, clrRed
#property indicator_width1 1
//
// High ...
#define scHighBufferIndex 2
#define scHighBufferPlotIndex 1
double scHighBuffer[];
//
#property indicator_label2 "X121_XDSR SC H"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrAqua
#property indicator_width2 1
//
// Close ...
//
#define scCloseBufferIndex 3
#define scCloseBufferPlotIndex 2
double scCloseBuffer[];
//
#define scCloseColorBufferIndex 4
double scCloseColorBuffer[];
//
#property indicator_label3 "X121_XDSR SC C"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrGreen, clrRed
#property indicator_width3 1
//
// Low ...
#define scLowBufferIndex 5
#define scLowBufferPlotIndex 3
double scLowBuffer[];
//
#property indicator_label4 "X121_XDSR SC L"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrMagenta
#property indicator_width4 1
//
// Medium ...
//
// Open ...
//
#define mcOpenBufferIndex 6
#define mcOpenBufferPlotIndex 4
double mcOpenBuffer[];
//
#define mcOpenColorBufferIndex 7
double mcOpenColorBuffer[];
//
#property indicator_label5 "X121_XDSR MC O"
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_color5 clrGreen, clrRed
#property indicator_width5 1
//
// High ...
#define mcHighBufferIndex 8
#define mcHighBufferPlotIndex 5
double mcHighBuffer[];
//
#property indicator_label6 "X121_XDSR MC H"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrAqua
#property indicator_width6 1
//
// Close ...
//
#define mcCloseBufferIndex 9
#define mcCloseBufferPlotIndex 6
double mcCloseBuffer[];
//
#define mcCloseColorBufferIndex 10
double mcCloseColorBuffer[];
//
#property indicator_label7 "X121_XDSR MC C"
#property indicator_type7 DRAW_COLOR_LINE
#property indicator_color7 clrGreen, clrRed
#property indicator_width7 1
//
// Low ...
#define mcLowBufferIndex 11
#define mcLowBufferPlotIndex 7
double mcLowBuffer[];
//
#property indicator_label8 "X121_XDSR MC L"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrMagenta
#property indicator_width8 1
//
// Long ...
//
// Open ...
//
#define lcOpenBufferIndex 12
#define lcOpenBufferPlotIndex 8
double lcOpenBuffer[];
//
#define lcOpenColorBufferIndex 13
double lcOpenColorBuffer[];
//
#property indicator_label9 "X121_XDSR LC O"
#property indicator_type9 DRAW_COLOR_LINE
#property indicator_color9 clrGreen, clrRed
#property indicator_width9 1
//
// High ...
#define lcHighBufferIndex 14
#define lcHighBufferPlotIndex 9
double lcHighBuffer[];
//
#property indicator_label10 "X121_XDSR LC H"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrAqua
#property indicator_width10 1
//
// Close ...
//
#define lcCloseBufferIndex 15
#define lcCloseBufferPlotIndex 10
double lcCloseBuffer[];
//
#define lcCloseColorBufferIndex 16
double lcCloseColorBuffer[];
//
#property indicator_label11 "X121_XDSR LC C"
#property indicator_type11 DRAW_COLOR_LINE
#property indicator_color11 clrGreen, clrRed
#property indicator_width11 1
//
// Low ...
#define lcLowBufferIndex 17
#define lcLowBufferPlotIndex 11
double lcLowBuffer[];
//
#property indicator_label12 "X121_XDSR LC L"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrMagenta
#property indicator_width12 1
//
// Hind ...
//
// Open ...
//
#define hcOpenBufferIndex 18
#define hcOpenBufferPlotIndex 12
double hcOpenBuffer[];
//
#define hcOpenColorBufferIndex 19
double hcOpenColorBuffer[];
//
#property indicator_label13 "X121_XDSR HC O"
#property indicator_type13 DRAW_COLOR_LINE
#property indicator_color13 clrGreen, clrRed
#property indicator_width13 1
//
// High ...
#define hcHighBufferIndex 20
#define hcHighBufferPlotIndex 13
double hcHighBuffer[];
//
#property indicator_label14 "X121_XDSR HC H"
#property indicator_type14 DRAW_LINE
#property indicator_color14 clrAqua
#property indicator_width14 1
//
// Close ...
//
#define hcCloseBufferIndex 21
#define hcCloseBufferPlotIndex 14
double hcCloseBuffer[];
//
#define hcCloseColorBufferIndex 22
double hcCloseColorBuffer[];
//
#property indicator_label15 "X121_XDSR HC C"
#property indicator_type15 DRAW_COLOR_LINE
#property indicator_color15 clrGreen, clrRed
#property indicator_width15 1
//
// Low ...
#define hcLowBufferIndex 23
#define hcLowBufferPlotIndex 15
double hcLowBuffer[];
//
#property indicator_label16 "X121_XDSR HC L"
#property indicator_type16 DRAW_LINE
#property indicator_color16 clrMagenta
#property indicator_width16 1
//
// VARIABLES ...
//
// Cycles Definitions ...
XMarketCycle sc;
XMarketCycle mc;
XMarketCycle lc;
XMarketCycle hc;
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Initial Market Cycles ...
if (!InitMarketCycles())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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(
//
// 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;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total - 1
: (rates_total - prev_calculated);
//
// Main Loop ...
for (int i = limit; i >= 0 && !IsStopped(); i--)
{
//
// Calculate Buffers ...
CalculateBuffer(i);
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
// Short ...
IsValidCycle(
scMode,
scPeriod)
//
&&
//
// Medium ...
IsValidCycle(
mcMode,
mcPeriod)
//
&&
//
// Long ...
IsValidCycle(
lcMode,
lcPeriod)
//
&&
//
// Hind ...
IsValidCycle(
hcMode,
hcPeriod)
//
;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Short ...
//
// High ...
//
ArraySetAsSeries(scHighBuffer, true);
SetIndexBuffer(scHighBufferIndex, scHighBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(scHighBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(scHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(scHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Low ...
//
ArraySetAsSeries(scLowBuffer, true);
SetIndexBuffer(scLowBufferIndex, scLowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(scLowBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(scLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(scLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Open ...
//
ArraySetAsSeries(scOpenBuffer, true);
SetIndexBuffer(scOpenBufferIndex, scOpenBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(scOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(scOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(scOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(scOpenColorBuffer, true);
SetIndexBuffer(scOpenColorBufferIndex, scOpenColorBuffer, INDICATOR_COLOR_INDEX);
//
// Close ...
ArraySetAsSeries(scCloseBuffer, true);
SetIndexBuffer(scCloseBufferIndex, scCloseBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(scCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(scCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(scCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(scCloseColorBuffer, true);
SetIndexBuffer(scCloseColorBufferIndex, scCloseColorBuffer, INDICATOR_COLOR_INDEX);
//
// Medium ...
//
// High ...
//
ArraySetAsSeries(mcHighBuffer, true);
SetIndexBuffer(mcHighBufferIndex, mcHighBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(mcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(mcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Low ...
//
ArraySetAsSeries(mcLowBuffer, true);
SetIndexBuffer(mcLowBufferIndex, mcLowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(mcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(mcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Open ...
//
ArraySetAsSeries(mcOpenBuffer, true);
SetIndexBuffer(mcOpenBufferIndex, mcOpenBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(mcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(mcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(mcOpenColorBuffer, true);
SetIndexBuffer(mcOpenColorBufferIndex, mcOpenColorBuffer, INDICATOR_COLOR_INDEX);
//
// Close ...
ArraySetAsSeries(mcCloseBuffer, true);
SetIndexBuffer(mcCloseBufferIndex, mcCloseBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(mcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(mcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(mcCloseColorBuffer, true);
SetIndexBuffer(mcCloseColorBufferIndex, mcCloseColorBuffer, INDICATOR_COLOR_INDEX);
//
// Long ...
//
// High ...
//
ArraySetAsSeries(lcHighBuffer, true);
SetIndexBuffer(lcHighBufferIndex, lcHighBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(lcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(lcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Low ...
//
ArraySetAsSeries(lcLowBuffer, true);
SetIndexBuffer(lcLowBufferIndex, lcLowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(lcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(lcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Open ...
//
ArraySetAsSeries(lcOpenBuffer, true);
SetIndexBuffer(lcOpenBufferIndex, lcOpenBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(lcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(lcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(lcOpenColorBuffer, true);
SetIndexBuffer(lcOpenColorBufferIndex, lcOpenColorBuffer, INDICATOR_COLOR_INDEX);
//
// Close ...
ArraySetAsSeries(lcCloseBuffer, true);
SetIndexBuffer(lcCloseBufferIndex, lcCloseBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(lcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(lcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(lcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(lcCloseColorBuffer, true);
SetIndexBuffer(lcCloseColorBufferIndex, lcCloseColorBuffer, INDICATOR_COLOR_INDEX);
//
// Hind ...
//
// High ...
//
ArraySetAsSeries(hcHighBuffer, true);
SetIndexBuffer(hcHighBufferIndex, hcHighBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hcHighBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(hcHighBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(hcHighBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Low ...
//
ArraySetAsSeries(hcLowBuffer, true);
SetIndexBuffer(hcLowBufferIndex, hcLowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hcLowBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(hcLowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(hcLowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Open ...
//
ArraySetAsSeries(hcOpenBuffer, true);
SetIndexBuffer(hcOpenBufferIndex, hcOpenBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hcOpenBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(hcOpenBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(hcOpenBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(hcOpenColorBuffer, true);
SetIndexBuffer(hcOpenColorBufferIndex, hcOpenColorBuffer, INDICATOR_COLOR_INDEX);
//
// Close ...
ArraySetAsSeries(hcCloseBuffer, true);
SetIndexBuffer(hcCloseBufferIndex, hcCloseBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hcCloseBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(hcCloseBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(hcCloseBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
ArraySetAsSeries(hcCloseColorBuffer, true);
SetIndexBuffer(hcCloseColorBufferIndex, hcCloseColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
void CalculateBuffer(const int barIndex)
{
//
// First Update Market Cycles ...
UpdateMarketCycles(barIndex);
//
double bullishColorIDX = 0;
double bearishColorIDX = 1;
//
// Short ...
int scBarIndex = sc.GetBarIndex(barIndex);
XOHCL scBar1 = sc.GetBar(scBarIndex + 1);
//
bool isSCBar1Bullish = scBar1.open < scBar1.close;
//
scOpenBuffer[barIndex] = scBar1.open;
scHighBuffer[barIndex] = scBar1.high;
scCloseBuffer[barIndex] = scBar1.close;
scLowBuffer[barIndex] = scBar1.low;
//
scOpenColorBuffer[barIndex] =
isSCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
//
scCloseColorBuffer[barIndex] =
isSCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
//
// Medium ...
int mcBarIndex = mc.GetBarIndex(barIndex);
XOHCL mcBar1 = mc.GetBar(mcBarIndex + 1);
//
bool isMCBar1Bullish = mcBar1.open < mcBar1.close;
//
mcOpenBuffer[barIndex] = mcBar1.open;
mcHighBuffer[barIndex] = mcBar1.high;
mcCloseBuffer[barIndex] = mcBar1.close;
mcLowBuffer[barIndex] = mcBar1.low;
//
mcOpenColorBuffer[barIndex] =
isMCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
//
mcCloseColorBuffer[barIndex] =
isMCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
//
// Long ...
int lcBarIndex = lc.GetBarIndex(barIndex);
XOHCL lcBar1 = lc.GetBar(lcBarIndex + 1);
//
bool isLCBar1Bullish = lcBar1.open < lcBar1.close;
//
lcOpenBuffer[barIndex] = lcBar1.open;
lcHighBuffer[barIndex] = lcBar1.high;
lcCloseBuffer[barIndex] = lcBar1.close;
lcLowBuffer[barIndex] = lcBar1.low;
//
lcOpenColorBuffer[barIndex] =
isLCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
//
lcCloseColorBuffer[barIndex] =
isLCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
//
// Hind ...
int hcBarIndex = hc.GetBarIndex(barIndex);
XOHCL hcBar1 = hc.GetBar(hcBarIndex + 1);
//
bool isHCBar1Bullish = hcBar1.open < hcBar1.close;
//
hcOpenBuffer[barIndex] = hcBar1.open;
hcHighBuffer[barIndex] = hcBar1.high;
hcCloseBuffer[barIndex] = hcBar1.close;
hcLowBuffer[barIndex] = hcBar1.low;
//
hcOpenColorBuffer[barIndex] =
isHCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
//
hcCloseColorBuffer[barIndex] =
isHCBar1Bullish
? bullishColorIDX
: bearishColorIDX;
}
//
// TOOLS ...
//
// Initial Market Cycles ...
bool InitMarketCycles()
{
//
bool result = false;
//
// Short ...
sc.method = scMode;
sc.period = scPeriod;
result = sc.Init(
_Symbol,
_Period,
X_MARKET_CYCLE_SHORT);
if (!result)
{
return result;
}
//
// Medium ...
mc.method = mcMode;
mc.period = mcPeriod;
result = mc.Init(
_Symbol,
_Period,
X_MARKET_CYCLE_MEDIUM);
if (!result)
{
return result;
}
//
// Long ...
lc.method = lcMode;
lc.period = lcPeriod;
result = lc.Init(
_Symbol,
_Period,
X_MARKET_CYCLE_LONG);
if (!result)
{
return result;
}
//
// Hind ...
hc.method = hcMode;
hc.period = hcPeriod;
result = hc.Init(
_Symbol,
_Period,
X_MARKET_CYCLE_HIND);
if (!result)
{
return result;
}
//
return result;
}
//
// Update Market Cycles ...
bool UpdateMarketCycles(int barIndex)
{
//
bool result = false;
//
// Short ...
result = sc.Update(barIndex);
if (!result)
{
return result;
}
//
// Medium ...
result = mc.Update(barIndex);
if (!result)
{
return result;
}
//
// Long ...
result = lc.Update(barIndex);
if (!result)
{
return result;
}
//
// Hind ...
result = hc.Update(barIndex);
if (!result)
{
return result;
}
//
return result;
}
@@ -0,0 +1,836 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121_XICH
// Description: Ichimoku Kinko Hyo ...
//
//
// 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 X121_XICH Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_XICH"
//
// Ichimoku Golden Numbers ...
enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS
{
X_ICH_BASE = 9,
X_ICH_GOLDEN = 17,
X_ICH_CYCLE = 26,
X_ICH_PERIOD = 35,
X_ICH_STAR = 45,
X_ICH_MED = 52,
X_ICH_LONG = 63,
X_ICH_FULL = 72
};
//
// Ichimoku Lines Calculator Mode ...
enum ENUM_X_ICHIMOKU_CALCULATION_MODE
{
//
X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low
X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
// ICHIMOKU Kinko Hyo ...
//
// TENKANSEN ...
input group "Tenkan Sen";
input int tenkanSenLength = 9; // Length
input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
//
// KIJUNSEN ...
input group "Kijun Sen";
input int kijunSenLength = 26; // Length
input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
//
// SENKOUSPANB ...
input group "Senkou Span B";
input int senkouSpanBLength = 52; // Length
input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode
//
// CHIKOUSPAN ...
input group "Chikou Span";
input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type
//
input group "Presentation";
input bool showTenkanSen = true; // Show Tenkan Sen
input bool showKijunSen = true; // Show Kijun Sen
input bool showKijunSenPlus = false; // Show Kijun Sen +
input bool showKijunSenNegative = false; // Show Kijun Sen -
input bool showChikouSpan = true; // Show Chikou Span
input bool showSenkouSpanA = true; // Show Senkou Span A
input bool showSenkouSpanB = true; // Show Senkou Span B
input bool showKumo = true; // Show Kumo
input bool shiftKumo = true; // Shift Kumo to Future
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 15
#property indicator_plots 8
//
// PLOTTED Buffers ...
//
// ICHIMOKU ...
//
// TENKANSEN ...
//
#define tenkanSenBufferIndex 0
double tenkanSenBuffer[];
//
#property indicator_label1 "X121_XICH TK"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrBrown
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// KIJUNSEN ...
//
#define kijunSenBufferIndex 1
double kijunSenBuffer[];
//
#property indicator_label2 "X121_XICH KJ"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDodgerBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
#define kijunSenPlusBufferIndex 2
double kijunSenPlusBuffer[];
//
#property indicator_label3 "X121_XICH KJ+"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrMediumTurquoise
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define kijunSenNegativeBufferIndex 3
double kijunSenNegativeBuffer[];
//
#property indicator_label4 "X121_XICH KJ-"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrDarkSeaGreen
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
// CHIKOUSPAN ...
//
#define chikouSpanBufferIndex 4
double chikouSpanBuffer[];
//
#property indicator_label5 "X121_XICH CS"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrDarkGreen
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//
#define senkouABufferIndex 5
double senkouABuffer[];
//
#property indicator_label6 "X121_XICH SSA"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrLightGray
#property indicator_style6 STYLE_DASHDOTDOT
#property indicator_width6 1
//
#define senkouBBufferIndex 6
double senkouBBuffer[];
//
#property indicator_label7 "X121_XICH SSB"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrLightGray
#property indicator_style7 STYLE_DASHDOTDOT
#property indicator_width7 1
//
// KUMO ...
//
// SENKOUSPANA ...
//
#define senkouSpanABufferIndex 7
double senkouSpanABuffer[];
//
// SENKOUSPANB ...
//
#define senkouSpanBBufferIndex 8
double senkouSpanBBuffer[];
//
// KUMOCLOUD ...
//
#define kumoBufferIndex 7
//
#property indicator_label8 "X121_XICH Kumo"
#property indicator_type8 DRAW_FILLING
#property indicator_color8 clrAqua, clrMagenta
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//
// DATA Buffers ...
//
#define dTenkanBufferIndex 9
double dTenkanBuffer[];
//
#define dKijunBufferIndex 10
double dKijunBuffer[];
//
#define dChikouBufferIndex 11
double dChikouBuffer[];
//
#define dSSABufferIndex 12
double dSSABuffer[];
//
#define dSSBBufferIndex 13
double dSSBBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
int mHandler;
//
ENUM_SERIESMODE mTenkanSenTopMode = NULL;
ENUM_SERIESMODE mTenkanSenBottomMode = NULL;
//
ENUM_SERIESMODE mKijunSenTopMode = NULL;
ENUM_SERIESMODE mKijunSenBottomMode = NULL;
//
ENUM_SERIESMODE mSenkouSpanBTopMode = NULL;
ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Init Handler ...
mHandler = iIchimoku(
_Symbol,
_Period,
tenkanSenLength,
kijunSenLength,
senkouSpanBLength);
if (mHandler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
// 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
//
IndicatorRelease(mHandler);
}
//
// 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;
//
// Check Calculated Bars ...
int ichCalculatedBars = BarsCalculated(mHandler);
if (ichCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedTenkans = CopyBuffer(mHandler, TENKANSEN_LINE, 0, limit, dTenkanBuffer);
int copiedKijuns = CopyBuffer(mHandler, KIJUNSEN_LINE, 0, limit, dKijunBuffer);
int copiedChikous = CopyBuffer(mHandler, CHIKOUSPAN_LINE, 0, limit, dChikouBuffer);
int copiedSSAs = CopyBuffer(mHandler, SENKOUSPANA_LINE, 0, limit, dSSABuffer);
int copiedSSBs = CopyBuffer(mHandler, SENKOUSPANB_LINE, 0, limit, dSSBBuffer);
if (
copiedSSAs < 0 ||
copiedSSBs < 0 ||
copiedKijuns < 0 ||
copiedTenkans < 0 ||
copiedChikous < 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
(tenkanSenLength > 2 &&
kijunSenLength > tenkanSenLength &&
senkouSpanBLength > kijunSenLength)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Ichimoku ...
result = MathMax(result, tenkanSenLength);
result = MathMax(result, kijunSenLength);
result = MathMax(result, senkouSpanBLength);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// ICHIMOKU ...
//
// TENKANSEN ...
//
ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(tenkanSenBuffer, true);
SetIndexBuffer(tenkanSenBufferIndex, tenkanSenBuffer, INDICATOR_DATA);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_SHOW_DATA, showTenkanSen);
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_TYPE, tenkanSenDrawType);
//
// KIJUNSEN ...
//
ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(kijunSenBuffer, true);
SetIndexBuffer(kijunSenBufferIndex, kijunSenBuffer, INDICATOR_DATA);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_SHOW_DATA, showKijunSen);
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_TYPE, kijunSenDrawType);
//
// KIJUNSEN Plus ...
//
ENUM_DRAW_TYPE kijunSenPlusDrawType = showKijunSenPlus ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(kijunSenPlusBuffer, true);
SetIndexBuffer(kijunSenPlusBufferIndex, kijunSenPlusBuffer, INDICATOR_DATA);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHIFT, kijunSenLength);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_TYPE, kijunSenPlusDrawType);
//
// KIJUNSEN Negative ...
//
ENUM_DRAW_TYPE kijunSenNegativeDrawType = showKijunSenNegative ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(kijunSenNegativeBuffer, true);
SetIndexBuffer(kijunSenNegativeBufferIndex, kijunSenNegativeBuffer, INDICATOR_DATA);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHIFT, -kijunSenLength);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_TYPE, kijunSenNegativeDrawType);
//
// CHIKOUSPAN ...
//
ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(chikouSpanBuffer, true);
SetIndexBuffer(chikouSpanBufferIndex, chikouSpanBuffer, INDICATOR_DATA);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHIFT, -kijunSenLength);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHOW_DATA, showChikouSpan);
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_TYPE, chikouSpanDrawType);
//
// SENKOUSPAN A and B ...
int shiftSize = shiftKumo ? kijunSenLength : 0;
//
// SENKOUSPANA ...
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(senkouABuffer, true);
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
//
// SENKOUSPANB ...
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(senkouBBuffer, true);
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
//
// KUMO ...
//
// SENKOUSPANA ...
ArraySetAsSeries(senkouSpanABuffer, true);
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
// SENKOUSPANB ...
ArraySetAsSeries(senkouSpanBBuffer, true);
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
// KUMO ...
//
ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE;
//
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHIFT, shiftSize);
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(kumoBufferIndex, PLOT_DRAW_TYPE, kumoDrawType);
//
// DATA Buffers ...
//
// D Tenkan ...
ArraySetAsSeries(dTenkanBuffer, true);
SetIndexBuffer(dTenkanBufferIndex, dTenkanBuffer, INDICATOR_CALCULATIONS);
//
// D Kijun ...
ArraySetAsSeries(dKijunBuffer, true);
SetIndexBuffer(dKijunBufferIndex, dKijunBuffer, INDICATOR_CALCULATIONS);
//
// D Chikou ...
ArraySetAsSeries(dChikouBuffer, true);
SetIndexBuffer(dChikouBufferIndex, dChikouBuffer, INDICATOR_CALCULATIONS);
//
// D SSA ...
ArraySetAsSeries(dSSABuffer, true);
SetIndexBuffer(dSSABufferIndex, dSSABuffer, INDICATOR_CALCULATIONS);
//
// D SSB ...
ArraySetAsSeries(dSSBBuffer, true);
SetIndexBuffer(dSSBBufferIndex, dSSBBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// ICHIMOKU ...
//
double topValue;
double bottomValue;
//
// TENKANSEN ...
//
// Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ...
if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL)
{
//
switch (tenkanSenMode)
{
//
case X_XICH_HH_LL_MODE:
//
mTenkanSenTopMode = MODE_HIGH;
mTenkanSenBottomMode = MODE_LOW;
break;
//
case X_XICH_HO_LC_MODE:
//
mTenkanSenTopMode = MODE_OPEN;
mTenkanSenBottomMode = MODE_CLOSE;
break;
}
}
//
// Calculate Top ...
topValue = GetHighestHigh(
_Symbol,
_Period,
mTenkanSenTopMode,
tenkanSenLength,
bar_index);
//
// Calculate Bottom ...
bottomValue = GetLowestLow(
_Symbol,
_Period,
mTenkanSenBottomMode,
tenkanSenLength,
bar_index);
//
double tenkanSenValue = (topValue + bottomValue) / 2;
tenkanSenBuffer[bar_index] = tenkanSenValue;
//
// KIJUNSEN ...
//
// Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ...
if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL)
{
//
switch (kijunSenMode)
{
//
case X_XICH_HH_LL_MODE:
//
mKijunSenTopMode = MODE_HIGH;
mKijunSenBottomMode = MODE_LOW;
break;
//
case X_XICH_HO_LC_MODE:
//
mKijunSenTopMode = MODE_OPEN;
mKijunSenBottomMode = MODE_CLOSE;
break;
}
}
//
// Calculate Top ...
topValue = GetHighestHigh(
_Symbol,
_Period,
mKijunSenTopMode,
kijunSenLength,
bar_index);
//
// Calculate Bottom ...
bottomValue = GetLowestLow(
_Symbol,
_Period,
mKijunSenBottomMode,
kijunSenLength,
bar_index);
//
double kijunSenValue = (topValue + bottomValue) / 2;
kijunSenBuffer[bar_index] = kijunSenValue;
//
kijunSenPlusBuffer[bar_index] = kijunSenValue;
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
//
// CHIKOUSPAN ...
double chikouSpanValue = GetAppliedPrice(
bar_index,
chikuoSpanAppliedTo);
chikouSpanBuffer[bar_index] = chikouSpanValue;
//
// KUMO ...
//
// SENKOUSPANA ...
double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2;
senkouABuffer[bar_index] = senkouSpanAValue;
senkouSpanABuffer[bar_index] = senkouSpanAValue;
//
// SENKOUSPANB ...
//
// Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ...
if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL)
{
//
switch (senkouSpanBMode)
{
//
case X_XICH_HH_LL_MODE:
//
mSenkouSpanBTopMode = MODE_HIGH;
mSenkouSpanBBottomMode = MODE_LOW;
break;
//
case X_XICH_HO_LC_MODE:
//
mSenkouSpanBTopMode = MODE_OPEN;
mSenkouSpanBBottomMode = MODE_CLOSE;
break;
}
}
//
// Calculate Top ...
topValue = GetHighestHigh(
_Symbol,
_Period,
mSenkouSpanBTopMode,
senkouSpanBLength,
bar_index);
//
// Calculate Bottom ...
bottomValue = GetLowestLow(
_Symbol,
_Period,
mSenkouSpanBBottomMode,
senkouSpanBLength,
bar_index);
//
double senkouSpanBValue = (topValue + bottomValue) / 2;
senkouBBuffer[bar_index] = senkouSpanBValue;
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
}
//
// END Functions ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,721 @@
//////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XOSC
// Description: provides some oscillator values
// as empty 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 X121_XAMA Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "X121_XOSC"
//
// END Constants ...
//
//
// START Inputs ...
//
//
// ATR ...
input group "ATR";
input int atrLength = 14; // Length
//
// RVI ...
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
input group "RVI";
input int rviLength = 10; // Length
//
// BULLPOWER ...
input group "Bulls Power";
input int bullpLength = 13; // Length
//
// BEARPOWER ...
input group "Bears Power";
input int bearpLength = 13; // Length
//
// VOLUME ...
input group "Volumes";
input ENUM_APPLIED_VOLUME volumeAppliedTo = VOLUME_TICK; // Applied To
//
// RSI ...
input group "RSI";
input int rsiLength = 14; // Length
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
//
// CCI ...
input group "CCI";
input int cciLength = 14; // Length
input ENUM_APPLIED_PRICE cciAppliedTo = PRICE_TYPICAL; // Applied To
//
// STDDEV ...
input group "Standard Deviation";
input int stddevLength = 20; // Length
input int stddevShift = 0; // Shift
input ENUM_MA_METHOD stddevMethod = MODE_SMA; // Mode
input ENUM_APPLIED_PRICE stddevAppliedTo = PRICE_CLOSE; // AppliedTo
//
// MOMENTUM ...
input group "Momentum";
input int momentumLength = 14; // Length
input ENUM_APPLIED_PRICE momentumAppliedTo = PRICE_CLOSE; // Applied To
//
// SAR ...
input group "SAR";
input double sarStep = 0.02; // Step
input double sarMaximum = 0.2; // Maximum
//
// MACD ...
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
input group "MACD";
input int macdFastLength = 12; // Fast Length
input int macdSlowLength = 26; // Slow Length
input int macdSignaLength = 9; // Signal Length
input ENUM_APPLIED_PRICE macdAppliedTo = PRICE_CLOSE; // Applied To
//
// STOCHASTIC ...
// The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
input group "Stochastic";
input int stochKLength = 5; // K Length
input int stochDLength = 3; // D Length
input int stochSlowing = 3; // Slowing
input ENUM_MA_METHOD stochMaMethod = MODE_SMA; // Ma Method
input ENUM_STO_PRICE stochMode = STO_LOWHIGH; // Calculation Mode
//
// END Inputs ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 15
#property indicator_plots 0
//
// ATR ...
#define atrBufferIndex 0
double atrBuffer[];
//
// RVI ...
#define rviMainBufferIndex 1
#define rviSignalBufferIndex 2
double rviMainBuffer[];
double rviSignalBuffer[];
//
// BULLPOWER ...
#define bullPBufferIndex 3
double bullPBuffer[];
//
// BEARPOWER ...
#define bearPBufferIndex 4
double bearPBuffer[];
//
// VOLUME ...
#define volumeBufferIndex 5
double volumeBuffer[];
//
// RSI ...
#define rsiBufferIndex 6
double rsiBuffer[];
//
// CCI ...
#define cciBufferIndex 7
double cciBuffer[];
//
// MOMENTUM ...
#define momentumBufferIndex 8
double momentumBuffer[];
//
// SAR ...
#define sarBufferIndex 9
double sarBuffer[];
//
// MACD ...
#define macdMainBufferIndex 10
#define macdSignalBufferIndex 11
double macdMainBuffer[];
double macdSignalBuffer[];
//
// STOCHASTIC ...
#define stochMainBufferIndex 12
#define stochSignalBufferIndex 13
double stochMainBuffer[];
double stochSignalBuffer[];
//
// STANDARDDEVIATION ...
#define stddevBufferIndex 14
double stddevBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int atrHandler = INVALID_HANDLE;
int rviHandler = INVALID_HANDLE;
int bullPHandler = INVALID_HANDLE;
int bearPHandler = INVALID_HANDLE;
int volumeHandler = INVALID_HANDLE;
int rsiHandler = INVALID_HANDLE;
int cciHandler = INVALID_HANDLE;
int momentumHandler = INVALID_HANDLE;
int sarHandler = INVALID_HANDLE;
int macdHandler = INVALID_HANDLE;
int stochHandler = INVALID_HANDLE;
int stddevHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Initializing Handlers ...
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
atrLength);
//
// RVI ...
rviHandler = iRVI(
_Symbol,
_Period,
rviLength);
//
// BULLSPOWER ...
bullPHandler = iBullsPower(
_Symbol,
_Period,
bullpLength);
//
// BEARSPOWER ...
bearPHandler = iBearsPower(
_Symbol,
_Period,
bullpLength);
//
// VOLUMES ...
volumeHandler = iVolumes(
_Symbol,
_Period,
volumeAppliedTo);
//
// RSI ...
rsiHandler = iRSI(
_Symbol,
_Period,
rsiLength,
rsiAppliedTo);
//
// CCI ...
cciHandler = iCCI(
_Symbol,
_Period,
cciLength,
cciAppliedTo);
//
// MOMENTUM ...
momentumHandler = iMomentum(
_Symbol,
_Period,
momentumLength,
momentumAppliedTo);
//
// SAR ...
sarHandler = iSAR(
_Symbol,
_Period,
sarStep,
sarMaximum);
//
// MACD ...
macdHandler = iMACD(
_Symbol,
_Period,
macdFastLength,
macdSlowLength,
macdSignaLength,
macdAppliedTo);
//
// STOCHASTIC ...
stochHandler = iStochastic(
_Symbol,
_Period,
stochKLength,
stochDLength,
stochSlowing,
stochMaMethod,
stochMode);
//
// STANDARDDEVIATION ...
stddevHandler = iStdDev(
_Symbol,
_Period,
stddevLength,
stddevShift,
stddevMethod,
stddevAppliedTo);
//
bool isAllHandlersInit =
//
atrHandler != INVALID_HANDLE &&
rviHandler != INVALID_HANDLE &&
bullPHandler != INVALID_HANDLE &&
bearPHandler != INVALID_HANDLE &&
volumeHandler != INVALID_HANDLE &&
rsiHandler != INVALID_HANDLE &&
cciHandler != INVALID_HANDLE &&
momentumHandler != INVALID_HANDLE &&
sarHandler != INVALID_HANDLE &&
macdHandler != INVALID_HANDLE &&
stochHandler != INVALID_HANDLE &&
stddevHandler != INVALID_HANDLE
//
;
if (!isAllHandlersInit)
{
return INIT_FAILED;
}
//
// 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
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(atrHandler);
IndicatorRelease(rviHandler);
IndicatorRelease(bullPHandler);
IndicatorRelease(bearPHandler);
IndicatorRelease(volumeHandler);
IndicatorRelease(rsiHandler);
IndicatorRelease(cciHandler);
IndicatorRelease(momentumHandler);
IndicatorRelease(sarHandler);
IndicatorRelease(macdHandler);
IndicatorRelease(stochHandler);
IndicatorRelease(stddevHandler);
}
//
// 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;
//
// Check Calculated Bars ...
int atrCalculatedBars = BarsCalculated(atrHandler);
int rviCalculatedBars = BarsCalculated(rviHandler);
int bullPCalculatedBars = BarsCalculated(bullPHandler);
int bearPCalculatedBars = BarsCalculated(bearPHandler);
int volumeCalculatedBars = BarsCalculated(volumeHandler);
int rsiCalculatedBars = BarsCalculated(rsiHandler);
int cciCalculatedBars = BarsCalculated(cciHandler);
int momentumCalculatedBars = BarsCalculated(momentumHandler);
int sarCalculatedBars = BarsCalculated(sarHandler);
int macdCalculatedBars = BarsCalculated(macdHandler);
int stochCalculatedBars = BarsCalculated(stochHandler);
int stddevCalculatedBars = BarsCalculated(stddevHandler);
//
bool isCalculatedBarsPassed =
//
atrCalculatedBars >= maxLength &&
rviCalculatedBars >= maxLength &&
bullPCalculatedBars >= maxLength &&
bearPCalculatedBars >= maxLength &&
volumeCalculatedBars >= maxLength &&
rsiCalculatedBars >= maxLength &&
cciCalculatedBars >= maxLength &&
momentumCalculatedBars >= maxLength &&
sarCalculatedBars >= maxLength &&
macdCalculatedBars >= maxLength &&
stochCalculatedBars >= maxLength &&
stddevCalculatedBars >= maxLength
//
;
if (!isCalculatedBarsPassed)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int atrCopiedItems = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
int rviMainCopiedItems = CopyBuffer(rviHandler, MAIN_LINE, 0, limit, rviMainBuffer);
int rviSignalCopiedItems = CopyBuffer(rviHandler, SIGNAL_LINE, 0, limit, rviSignalBuffer);
int bullPCopiedItems = CopyBuffer(bullPHandler, 0, 0, limit, bullPBuffer);
int bearPCopiedItems = CopyBuffer(bearPHandler, 0, 0, limit, bearPBuffer);
int volumeCopiedItems = CopyBuffer(volumeHandler, 0, 0, limit, volumeBuffer);
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
int cciCopiedItems = CopyBuffer(cciHandler, 0, 0, limit, cciBuffer);
int momentumCopiedItems = CopyBuffer(momentumHandler, 0, 0, limit, momentumBuffer);
int sarCopiedItems = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
int macdMainCopiedItems = CopyBuffer(macdHandler, MAIN_LINE, 0, limit, macdMainBuffer);
int macdSignalCopiedItems = CopyBuffer(macdHandler, SIGNAL_LINE, 0, limit, macdSignalBuffer);
int stochMainCopiedItems = CopyBuffer(stochHandler, MAIN_LINE, 0, limit, stochMainBuffer);
int stocSignalhCopiedItems = CopyBuffer(stochHandler, SIGNAL_LINE, 0, limit, stochSignalBuffer);
int stddevCopiedItems = CopyBuffer(stddevHandler, 0, 0, limit, stddevBuffer);
//
bool isCopiedBarsPassed =
//
atrCopiedItems > 0 &&
rviMainCopiedItems > 0 &&
rviSignalCopiedItems > 0 &&
bullPCopiedItems > 0 &&
bearPCopiedItems > 0 &&
volumeCopiedItems > 0 &&
rsiCopiedItems > 0 &&
cciCopiedItems > 0 &&
momentumCopiedItems > 0 &&
sarCopiedItems > 0 &&
macdMainCopiedItems > 0 &&
macdSignalCopiedItems > 0 &&
stochMainCopiedItems > 0 &&
stocSignalhCopiedItems > 0 &&
stddevCopiedItems > 0
//
;
if (!isCopiedBarsPassed)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Do Buffers Calculation ...
// HERE We Do Not anything ...
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
result =
//
atrLength >= 2 &&
rviLength >= 2 &&
bullpLength >= 2 &&
bearpLength >= 2 &&
rsiLength >= 2 &&
cciLength >= 2 &&
momentumLength >= 2 &&
sarStep > 0 &&
sarStep < sarMaximum &&
macdFastLength >= 2 &&
macdSlowLength > macdFastLength &&
macdSignaLength >= 2 &&
stochKLength >= 2 &&
stochDLength >= 2 &&
stochSlowing >= 2 &&
stddevLength >= 2 &&
stddevShift >= 0
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(atrLength, rviLength);
result = MathMax(result, bullpLength);
result = MathMax(result, bearpLength);
result = MathMax(result, rsiLength);
result = MathMax(result, cciLength);
result = MathMax(result, momentumLength);
result = MathMax(result, macdFastLength);
result = MathMax(result, macdSlowLength);
result = MathMax(result, macdSignaLength);
result = MathMax(result, stochKLength);
result = MathMax(result, stochDLength);
result = MathMax(result, stochSlowing);
result = MathMax(result, stddevLength);
//
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()
{
//
// DATA Buffers ...
//
// ATR ...
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
// RVI ...
//
// Main ...
ArraySetAsSeries(rviMainBuffer, true);
SetIndexBuffer(rviMainBufferIndex, rviMainBuffer, INDICATOR_CALCULATIONS);
//
// Signal ...
ArraySetAsSeries(rviSignalBuffer, true);
SetIndexBuffer(rviSignalBufferIndex, rviSignalBuffer, INDICATOR_CALCULATIONS);
//
// BULLPOWER ...
ArraySetAsSeries(bullPBuffer, true);
SetIndexBuffer(bullPBufferIndex, bullPBuffer, INDICATOR_CALCULATIONS);
//
// BEARPOWER ...
ArraySetAsSeries(bearPBuffer, true);
SetIndexBuffer(bearPBufferIndex, bearPBuffer, INDICATOR_CALCULATIONS);
//
// VOLUME ...
ArraySetAsSeries(volumeBuffer, true);
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
//
// RSI ...
ArraySetAsSeries(rsiBuffer, true);
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
//
// CCI ...
ArraySetAsSeries(cciBuffer, true);
SetIndexBuffer(cciBufferIndex, cciBuffer, INDICATOR_CALCULATIONS);
//
// MOMENTUM ...
ArraySetAsSeries(momentumBuffer, true);
SetIndexBuffer(momentumBufferIndex, momentumBuffer, INDICATOR_CALCULATIONS);
//
// SAR ...
ArraySetAsSeries(sarBuffer, true);
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_CALCULATIONS);
//
// STANDARDDEVIATION ...
ArraySetAsSeries(stddevBuffer, true);
SetIndexBuffer(stddevBufferIndex, stddevBuffer, INDICATOR_CALCULATIONS);
//
// MACD ...
//
// Main ...
ArraySetAsSeries(macdMainBuffer, true);
SetIndexBuffer(macdMainBufferIndex, macdMainBuffer, INDICATOR_CALCULATIONS);
//
// Signal ...
ArraySetAsSeries(macdSignalBuffer, true);
SetIndexBuffer(macdSignalBufferIndex, macdSignalBuffer, INDICATOR_CALCULATIONS);
}
//
// END Functions ...
//
@@ -0,0 +1,580 @@
//////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XSTR
// Description: Super Trend 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 X121_XAMA Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "X121_XSTR"
//
// END Constants ...
//
//
// START Inputs ...
//
//
// Market ...
input group "ATR";
input int atrLength = 14; // Length
input double atrMultiplier = 3.0; // Multiplier
input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To
//
// Presentation ...
input group "Presentation";
input bool showTrends = true; // Show Trends
input bool fillTrends = true; // Fill Trends
//
// END Inputs ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 2
//
#define fillUpBufferIndex 0
double fillUpBuffer[];
#define fillDownBufferIndex 1
double fillDownBuffer[];
//
#define fillingPlotBufferIndex 0
//
#property indicator_label1 "X121_XSTR Filling"
#property indicator_type1 DRAW_FILLING
#property indicator_color1 clrBisque, clrPaleGreen
//
#define mainBufferIndex 2
#define mainPlotBufferIndex 1
double mainBuffer[];
//
#define mainColorBufferIndex 3
double mainColorBuffer[];
//
#property indicator_label2 "X121_XSTR"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
#property indicator_style2 STYLE_DOT
//
// DATA Buffers ...
//
#define atrBufferIndex 4
double atrBuffer[];
//
#define trendBufferIndex 5
double trendBuffer[];
//
#define upBufferIndex 6
double upBuffer[];
//
#define downBufferIndex 7
double downBuffer[];
//
#define priceBufferIndex 8
double priceBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int atrHandler = INVALID_HANDLE;
//
int changeOfTrend;
int startBearishTrend;
int startBullishTrend;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
atrHandler = iATR(
_Symbol,
_Period,
atrLength);
if (atrHandler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
// 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
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(atrHandler);
}
//
// 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[])
{
//
int numOfRequiredAtrs;
if (prev_calculated > rates_total || prev_calculated < 0)
{
numOfRequiredAtrs = rates_total;
}
else
{
//
numOfRequiredAtrs = rates_total - prev_calculated;
if (prev_calculated > 0)
{
numOfRequiredAtrs++;
}
}
//
// Checking for stop ...
if (IsStopped())
{
return 0;
}
//
// Check Number of items Copy or not ...
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
if (copiedATRs <= 0)
{
return 0;
}
//
int limit;
//
// checking for the limit start of calculation of an indicator ...
if (prev_calculated > rates_total || prev_calculated <= 0)
{
//
// starting index for calculation of all bars ...
limit = maxLength;
}
else
{
//
// starting number for calculation of new bars
limit = prev_calculated - 1;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
//
// Calculated Price ...
double price = getPrice(
atrAppliedTo,
open,
high,
low,
close,
i);
// price = (high[i] + low[i]) / 2;
priceBuffer[i] = price;
//
double atr = atrBuffer[i];
//
// Up ...
upBuffer[i] = price + (atrMultiplier * atr);
//
// Down ...
downBuffer[i] = price - (atrMultiplier * atr);
//
if (close[i] > upBuffer[i - 1])
{
//
trendBuffer[i] = 1;
if (trendBuffer[i - 1] == -1)
{
changeOfTrend = 1;
}
}
else if (close[i] < downBuffer[i - 1])
{
//
trendBuffer[i] = -1;
if (trendBuffer[i - 1] == 1)
{
changeOfTrend = 1;
}
}
else if (trendBuffer[i - 1] == 1)
{
//
trendBuffer[i] = 1;
changeOfTrend = 0;
}
else if (trendBuffer[i - 1] == -1)
{
//
trendBuffer[i] = -1;
changeOfTrend = 0;
}
//
// Down Trend Starting ...
if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0)
{
startBearishTrend = 1;
}
else
{
startBearishTrend = 0;
}
//
// Up Trend Starting ...
if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0)
{
startBullishTrend = 1;
}
else
{
startBullishTrend = 0;
}
//
if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
{
downBuffer[i] = downBuffer[i - 1];
}
//
if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
{
upBuffer[i] = upBuffer[i - 1];
}
//
if (startBearishTrend == 1)
{
upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr);
}
//
if (startBullishTrend == 1)
{
downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr);
}
//
// Draw the indicator ...
//
double colorIDX = 0;
mainColorBuffer[i] = colorIDX;
//
if (trendBuffer[i] == 1)
{
//
mainBuffer[i] = downBuffer[i];
if (changeOfTrend == 1)
{
mainBuffer[i - 1] = mainBuffer[i - 2];
changeOfTrend = 0;
}
//
colorIDX = 1;
}
else if (trendBuffer[i] == -1)
{
//
mainBuffer[i] = upBuffer[i];
if (changeOfTrend == 1)
{
//
mainBuffer[i - 1] = mainBuffer[i - 2];
changeOfTrend = 0;
}
//
colorIDX = 2;
}
//
if (showTrends)
{
mainColorBuffer[i] = colorIDX;
}
//
// Filling ...
if (fillTrends)
{
//
fillUpBuffer[i] = mainBuffer[i];
fillDownBuffer[i] = close[i];
}
else
{
//
fillUpBuffer[i] = EMPTY_VALUE;
fillDownBuffer[i] = EMPTY_VALUE;
}
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
result =
//
atrLength >= 2
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = atrLength;
//
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()
{
//
// PLOT Buffers ...
//
// FILLINGS ...
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false);
//
// MAIN ...
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends);
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
//
// DATA Buffers ...
//
// ATR ...
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
// TREND ...
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS);
//
// UP ...
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
//
// DOWN ...
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
//
// PRICE ...
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
}
//
// END Functions ...
//
//
// TEMPLATE Function ...
template <typename T>
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
{
switch (tprice)
{
case PRICE_CLOSE:
return (close[i]);
case PRICE_OPEN:
return (open[i]);
case PRICE_HIGH:
return (high[i]);
case PRICE_LOW:
return (low[i]);
case PRICE_MEDIAN:
return ((high[i] + low[i]) / 2.0);
case PRICE_TYPICAL:
return ((high[i] + low[i] + close[i]) / 3.0);
case PRICE_WEIGHTED:
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
}
return (0);
}
@@ -0,0 +1,757 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XZG
// Description: Zogzag 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 X121_XZG Indicator"
#property strict
//
#define ShortName "X121_XZG"
//
// DEFINITIONS ...
enum ENUM_X_ZG_SEARCH_MODE
{
X_ZG_SEARCH_EXTREMUM = 0, // searching for the first extremum
X_ZG_SEARCH_PEAK = 1, // searching for the next ZigZag peak
X_ZG_SEARCH_VALE = -1 // searching for the next ZigZag vale
};
//
// How to Calculate Up and Down Price ...
enum ENUM_X_ZG_PRICE_MODE
{
//
X_ZG_PRICE_HIGH_LOW_MODE = 1,
X_ZG_PRICE_OPEN_CLOSE_MODE = 2,
};
//
// INPUT ...
//
input int depth = 12; // Depth
input int deviation = 5; // Deviation
input int backStep = 3; // Back Step
input ENUM_X_ZG_PRICE_MODE mode = X_ZG_PRICE_HIGH_LOW_MODE; // Mode
//
// BUFFERS ...
//
#property indicator_chart_window
//
#property indicator_buffers 5
#property indicator_plots 3
//
// ZigZag ...
//
#define mainBufferIndex 0
#define mainBufferPlotIndex 0
double mainBuffer[];
//
#property indicator_label1 "X121_XZG Main"
#property indicator_type1 DRAW_SECTION
#property indicator_color1 clrYellow
#property indicator_width1 2
//
// Highs ...
//
// ZigZag Pointer or Line Indicator ...
#define arrowBufferIndex 1
#define arrowBufferPlotIndex 1
double arrowBuffer[];
//
#define arrowColorBufferIndex 2
double arrowColorBuffer[];
//
#property indicator_label2 "X121_XZG PV"
#property indicator_type2 DRAW_COLOR_ARROW
#property indicator_color2 clrAqua, clrMagenta
#property indicator_width2 1
//
#define highsBufferIndex 3
double highsBuffer[];
//
// Lows ...
//
#define lowsBufferIndex 4
double lowsBuffer[];
//
// VARIABLES ...
//
int mRecalc = 3; // Number of last extremes for recalculation
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// logTag = ShortName;
//
// 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(
//
// 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[] //
)
{
//
double mZGHigh[];
double mZGLow[];
if (mode == X_ZG_PRICE_OPEN_CLOSE_MODE)
{
//
ArrayCopy(
mZGHigh,
open
//
);
//
ArrayCopy(
mZGLow,
close
//
);
}
else
{
//
ArrayCopy(
mZGHigh,
high
//
);
//
ArrayCopy(
mZGLow,
low
//
);
}
//
int zigZagResult = CalcukateZigZag(
prev_calculated,
rates_total,
mZGHigh,
mZGLow
//
);
//
if (zigZagResult != rates_total)
{
return zigZagResult;
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
depth > 0 &&
deviation > 0 &&
backStep > 0
//
;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Main ...
//
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(mainBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Arrow ...
//
SetIndexBuffer(arrowBufferIndex, arrowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_SHOW_DATA, true);
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW, 159);
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW_SHIFT, 0);
PlotIndexSetDouble(arrowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Arrow Color ...
SetIndexBuffer(arrowColorBufferIndex, arrowColorBuffer, INDICATOR_COLOR_INDEX);
//
// Highs ...
SetIndexBuffer(highsBufferIndex, highsBuffer, INDICATOR_CALCULATIONS);
//
// Lows ...
SetIndexBuffer(lowsBufferIndex, lowsBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculating Zig Zag ...
int CalcukateZigZag(
const int prev_calculated,
const int rates_total,
double &high[],
double &low[]
//
)
{
//
if (rates_total < 100)
{
return 0;
}
//
// Define Variables ...
int i = 0;
//
int start = 0;
int extreme_counter = 0;
int extreme_search = X_ZG_SEARCH_EXTREMUM;
int shift = 0;
int back = 0;
int last_high_pos = 0;
int last_low_pos = 0;
//
double val = 0;
double res = 0;
double curlow = 0;
double curhigh = 0;
double last_high = 0;
double last_low = 0;
//
double colorIDX = 0;
double lastZigZagValue = 0;
//
// Initializing ...
if (prev_calculated == 0)
{
//
ArrayInitialize(mainBuffer, 0);
ArrayInitialize(highsBuffer, 0);
ArrayInitialize(lowsBuffer, 0);
//
start = depth;
}
//
// Already Calculated Before ...
if (prev_calculated > 0)
{
//
i = rates_total - 1;
//
// Searching for the third X_ZG_SEARCH_EXTREMUM from the last UnComplete Bar ...
while (extreme_counter < mRecalc && i > rates_total - 100)
{
//
res = mainBuffer[i];
if (res != 0)
{
extreme_counter++;
}
//
i--;
}
//
i++;
start = i;
//
// What type of X_ZG_SEARCH_EXTREMUM we Search for ...
if (lowsBuffer[i] != 0)
{
//
curlow = lowsBuffer[i];
extreme_search = X_ZG_SEARCH_PEAK;
}
else
{
//
curhigh = highsBuffer[i];
extreme_search = X_ZG_SEARCH_VALE;
}
//
// Clear Values ...
for (i = start + 1; i < rates_total && !IsStopped(); i++)
{
//
mainBuffer[i] = 0;
lowsBuffer[i] = 0;
highsBuffer[i] = 0;
}
}
//
// Search for High and Low Extremes ...
for (shift = start; shift < rates_total && !IsStopped(); shift++)
{
//
// Low ...
val = low[Lowest(low, depth, shift)];
if (val == last_low)
{
val = 0;
}
else
{
//
last_low = val;
//
if ((low[shift] - val) > deviation * _Point)
{
val = 0;
}
else
{
//
for (back = 1; back <= backStep; back++)
{
//
res = lowsBuffer[shift - back];
if ((res != 0) && (res > val))
{
lowsBuffer[shift - back] = 0;
}
}
}
}
//
if (low[shift] == val)
{
lowsBuffer[shift] = val;
}
else
{
lowsBuffer[shift] = 0;
}
//
// High ...
val = high[Highest(high, depth, shift)];
if (val == last_high)
{
val = 0;
}
else
{
//
last_high = val;
//
if ((val - high[shift]) > deviation * _Point)
{
val = 0;
}
else
{
//
for (back = 1; back <= backStep; back++)
{
//
res = highsBuffer[shift - back];
if ((res != 0) && (res < val))
{
highsBuffer[shift - back] = 0;
}
}
}
}
//
if (high[shift] == val)
{
highsBuffer[shift] = val;
}
else
{
highsBuffer[shift] = 0;
}
}
//
// Set Last Value ...
if (extreme_search == 0) // Undefined Values ...
{
//
last_low = 0;
last_high = 0;
}
else
{
//
last_low = curlow;
last_high = curhigh;
}
//
// Final Selection of Extreme Points for ZigZag ...
for (shift = start; shift < rates_total && !IsStopped(); shift++)
{
//
res = 0;
//
switch (extreme_search)
{
//
case X_ZG_SEARCH_EXTREMUM:
//
if (last_low == 0 && last_high == 0)
{
//
if (highsBuffer[shift] != 0)
{
//
last_high_pos = shift;
last_high = high[shift];
//
extreme_search = X_ZG_SEARCH_VALE;
//
mainBuffer[shift] = last_high;
//
res = 1;
}
//
if (lowsBuffer[shift] != 0)
{
//
last_low_pos = shift;
last_low = low[shift];
//
extreme_search = X_ZG_SEARCH_PEAK;
//
mainBuffer[shift] = last_low;
//
res = 1;
}
}
break;
//
case X_ZG_SEARCH_PEAK:
//
if (lowsBuffer[shift] != 0 && lowsBuffer[shift] < last_low && highsBuffer[shift] == 0)
{
//
mainBuffer[last_low_pos] = 0;
//
last_low_pos = shift;
last_low = lowsBuffer[shift];
//
mainBuffer[shift] = last_low;
//
res = 1;
}
//
if (highsBuffer[shift] != 0 && lowsBuffer[shift] == 0)
{
//
last_high_pos = shift;
last_high = highsBuffer[shift];
//
mainBuffer[shift] = last_high;
//
extreme_search = X_ZG_SEARCH_VALE;
//
res = 1;
}
break;
//
case X_ZG_SEARCH_VALE:
//
if (highsBuffer[shift] != 0 && highsBuffer[shift] > last_high && lowsBuffer[shift] == 0)
{
//
mainBuffer[last_high_pos] = 0;
//
last_high_pos = shift;
last_high = highsBuffer[shift];
//
mainBuffer[shift] = last_high;
}
//
if (lowsBuffer[shift] != 0 && highsBuffer[shift] == 0)
{
//
last_low_pos = shift;
last_low = lowsBuffer[shift];
//
mainBuffer[shift] = last_low;
//
extreme_search = X_ZG_SEARCH_PEAK;
}
break;
}
//
double iZigZagForColor = lastZigZagValue;
double iZigZag = mainBuffer[shift];
if (iZigZag == 0 && lastZigZagValue != 0)
{
arrowBuffer[shift] = lastZigZagValue;
}
else if (iZigZag != 0)
{
//
lastZigZagValue = iZigZag;
arrowBuffer[shift] = lastZigZagValue;
}
//
colorIDX =
lastZigZagValue > iZigZagForColor
? 0
: lastZigZagValue < iZigZagForColor
? 1
: colorIDX;
arrowColorBuffer[shift] = colorIDX;
}
//
return rates_total;
}
//
// TOOLS ...
//
// Search for the index of the highest bar ...
int Highest(
const double &mArray[],
const int mDepth,
const int mStart //
)
{
//
int result = 0;
//
if (mStart < 0)
{
return result;
}
//
double max = mArray[mStart];
result = mStart;
//
// Start searching ...
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
{
//
if (mArray[i] > max)
{
//
result = i;
max = mArray[i];
}
}
//
// Return index of the highest bar
return result;
}
//
// Search for the index of the lowest bar ...
int Lowest(
const double &mArray[],
const int mDepth,
const int mStart //
)
{
//
int result = 0;
//
if (mStart < 0)
{
return result;
}
//
double min = mArray[mStart];
result = mStart;
//
// Start searching ...
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
{
//
if (mArray[i] < min)
{
//
result = i;
min = mArray[i];
}
}
//
// Return index of the lowest bar
return result;
}
@@ -0,0 +1,775 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XCHNL
// Description: XCHL Channel 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 X121_XCHNL Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "X121_XCHNL"
//
// END Constants ...
//
//
// START Includes and Imports ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// END Includes and Imports ...
//
//
// START XSCHULL Class Definition ...
//
//
// END XSCHULL Class Definition ...
//
//
// START Inputs ...
//
//
input group "Makret Cycles";
input int shortLength = 9; // Short Length
input int mediumLength = 17; // Medium Length
input int longLength = 26; // Long Length
input int hindLength = 35; // Hind Length
//
input group "Trend";
input int numOfShoulder = 10; // Number of Shoulders for Swings
//
input group "Detection Modes";
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
//
input group "Presentation";
input bool showTrend = false; // Show Trend
input bool showSRs = false; // Show Support and Resistance
//
// END Inputs ...
//
//
// START Buffers ...
//
//
// PEKSANDVALES ...
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 0
#define sHHBufferIndex 0
#define sLLBufferIndex 1
#define mHHBufferIndex 2
#define mLLBufferIndex 3
#define lHHBufferIndex 4
#define lLLBufferIndex 5
#define hHHBufferIndex 6
#define hLLBufferIndex 7
double sHHBuffer[];
double sLLBuffer[];
double mHHBuffer[];
double mLLBuffer[];
double lHHBuffer[];
double lLLBuffer[];
double hHHBuffer[];
double hLLBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
drawPrefix = ShortName;
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Make an Instance of Hull Class ...
//
// 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 mPeriod 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
//
RemoveDraws(drawPrefix);
}
//
// 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[])
{
//
// this counts Available Bars ...
int limit;
//
limit = prev_calculated - 1;
if (limit < 0)
{
limit = 0;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
result =
//
// Validate Peaks and Vales ...
(shortLength > 2 &&
mediumLength > shortLength &&
longLength > mediumLength &&
hindLength > longLength)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Peaks and Vales ...
result = MathMax(shortLength, mediumLength);
result = MathMax(result, longLength);
result = MathMax(result, hindLength);
//
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()
{
//
ArraySetAsSeries(sHHBuffer, true);
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(sLLBuffer, true);
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(mHHBuffer, true);
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(mLLBuffer, true);
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(lHHBuffer, true);
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(lLLBuffer, true);
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(hHHBuffer, true);
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(hLLBuffer, true);
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// Calculate ...
//
// SHORT ...
//
// HIGH ...
int sHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
shortLength,
bar_index);
double sHHValue = GetAppliedPrice(
sHHIndex,
hhMode);
//
sHHBuffer[bar_index] = sHHValue;
//
// LOW ...
int sLLIndex = iLowest(
_Symbol,
_Period,
llMode,
shortLength,
bar_index);
double sLLValue = GetAppliedPrice(
sLLIndex,
llMode);
//
sLLBuffer[bar_index] = sLLValue;
//
// MEDIUM ...
//
// HIGH ...
int mHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
mediumLength,
bar_index);
double mHHValue = GetAppliedPrice(
mHHIndex,
hhMode);
//
mHHBuffer[bar_index] = mHHValue;
//
// LOW ...
int mLLIndex = iLowest(
_Symbol,
_Period,
llMode,
mediumLength,
bar_index);
double mLLValue = GetAppliedPrice(
mLLIndex,
llMode);
//
mLLBuffer[bar_index] = mLLValue;
//
// LONG ...
//
// HIGH ...
int lHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
longLength,
bar_index);
double lHHValue = GetAppliedPrice(
lHHIndex,
hhMode);
//
lHHBuffer[bar_index] = lHHValue;
//
// LOW ...
int lLLIndex = iLowest(
_Symbol,
_Period,
llMode,
longLength,
bar_index);
double lLLValue = GetAppliedPrice(
lLLIndex,
llMode);
//
lLLBuffer[bar_index] = lLLValue;
//
// HIND ...
//
// HIGH ...
int hHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
hindLength,
bar_index);
double hHHValue = GetAppliedPrice(
hHHIndex,
hhMode);
//
hHHBuffer[bar_index] = hHHValue;
//
// LOW ...
int hLLIndex = iLowest(
_Symbol,
_Period,
llMode,
hindLength,
bar_index);
double hLLValue = GetAppliedPrice(
hLLIndex,
llMode);
//
hLLBuffer[bar_index] = hLLValue;
//
// Find Swings ...
//
// High ...
int hSwing1 = FindSwing(
_Symbol,
_Period,
MODE_HIGH,
numOfShoulder,
bar_index + 1);
int hSwing2 = FindSwing(
_Symbol,
_Period,
MODE_HIGH,
numOfShoulder,
hSwing1 + 1);
//
// High ...
int hSwing3 = FindSwing(
_Symbol,
_Period,
MODE_HIGH,
numOfShoulder,
hSwing2 + 1);
// int hSwing4 = FindSwing(
// _Symbol,
// _Period,
// MODE_HIGH,
// numOfShoulder,
// hSwing3 + 1);
//
// Low ...
int lSwing1 = FindSwing(
_Symbol,
_Period,
MODE_LOW,
numOfShoulder,
bar_index + 1);
int lSwing2 = FindSwing(
_Symbol,
_Period,
MODE_LOW,
numOfShoulder,
lSwing1 + 1);
int lSwing3 = FindSwing(
_Symbol,
_Period,
MODE_LOW,
numOfShoulder,
lSwing2 + 1);
// int lSwing4 = FindSwing(
// _Symbol,
// _Period,
// MODE_LOW,
// numOfShoulder,
// lSwing3 + 1);
//
if (bar_index < 50)
{
//
bool isStrongResistance =
//
hHHBuffer[bar_index + 1] == hHHBuffer[bar_index + 2] &&
hHHBuffer[bar_index + 2] == hHHBuffer[bar_index + 3] &&
//
lHHBuffer[bar_index + 1] == lHHBuffer[bar_index + 2] &&
lHHBuffer[bar_index + 2] == lHHBuffer[bar_index + 3] &&
//
mHHBuffer[bar_index + 1] == mHHBuffer[bar_index + 2] &&
mHHBuffer[bar_index + 2] == mHHBuffer[bar_index + 3] &&
//
sHHBuffer[bar_index + 1] == sHHBuffer[bar_index + 2] &&
sHHBuffer[bar_index + 2] == sHHBuffer[bar_index + 3]
//
;
//
bool isStrongSupport =
//
hLLBuffer[bar_index + 1] == hLLBuffer[bar_index + 2] &&
hLLBuffer[bar_index + 2] == hLLBuffer[bar_index + 3] &&
//
lLLBuffer[bar_index + 1] == lLLBuffer[bar_index + 2] &&
lLLBuffer[bar_index + 2] == lLLBuffer[bar_index + 3] &&
//
mLLBuffer[bar_index + 1] == mLLBuffer[bar_index + 2] &&
mLLBuffer[bar_index + 2] == mLLBuffer[bar_index + 3] &&
//
sLLBuffer[bar_index + 1] == sLLBuffer[bar_index + 2] &&
sLLBuffer[bar_index + 2] == sLLBuffer[bar_index + 3]
//
;
//
if (isStrongResistance && showSRs)
{
//
DrawSupportResistance(
"R",
clrRed,
sHHBuffer[bar_index + 3],
bar_index + 3);
}
//
if (isStrongSupport && showSRs)
{
//
DrawSupportResistance(
"S",
clrGreen,
sLLBuffer[bar_index + 3],
bar_index + 3);
}
}
//
if (showTrend && bar_index < 20)
{
//
DrawSwing(
"High1",
MODE_HIGH,
clrAqua,
hSwing1,
hSwing2);
//
DrawSwing(
"Low1",
MODE_LOW,
clrAqua,
lSwing1,
lSwing2);
//
DrawSwing(
"High2",
MODE_HIGH,
clrMagenta,
hSwing2,
hSwing3);
//
DrawSwing(
"Low2",
MODE_LOW,
clrMagenta,
lSwing2,
lSwing3);
}
}
//
void DrawSwing(
string prefix, // Prefix ...
ENUM_SERIESMODE mode, // Swing Mode ...
color swingColor, // Color ...
int index1, // Index 1 ...
int index2 // Index 2 ...
)
{
//
if (mode != MODE_HIGH && mode != MODE_LOW)
{
return;
}
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
index1);
//
datetime time1 = GetCandleTime(
_Symbol,
_Period,
index1);
//
XOHCL c2 = GetCandle(
_Symbol,
_Period,
index2);
//
datetime time2 = GetCandleTime(
_Symbol,
_Period,
index2);
//
double value1 = -1;
double value2 = -1;
//
switch (mode)
{
//
case MODE_HIGH:
value1 = c1.high;
value2 = c2.high;
break;
//
case MODE_LOW:
value1 = c1.low;
value2 = c2.low;
break;
}
//
if (value1 == -1 || value2 == -1)
{
return;
}
//
long chartId = ChartID();
string tlName = prefix + "_" + "TrendLine";
// //
// if (IsDrawExists(tlName)) {
// RemoveDraw(tlName);
// }
//
DrawTrendLine(
chartId,
tlName,
0,
time2,
value2,
time1,
value1,
swingColor,
STYLE_DOT,
3,
false,
false,
true);
}
//
// Draw Support and Resistance ...
void DrawSupportResistance(
string prefix, // Prefix ...
color lColor, // Color ...
double price, // Support or Resistance price ...
int bar_index // Start Bar Index ...
)
{
//
datetime time1 = GetCandleTime(
_Symbol,
_Period,
bar_index);
//
datetime time2 = GetCandleTime(
_Symbol,
_Period,
bar_index - 1);
//
long chartId = ChartID();
string tlName = prefix + "_" + "TL" + "_" + (string)(NormalizePrice(price, _Symbol));
//
DrawTrendLine(
chartId,
tlName,
0,
time1,
price,
time2,
price,
lColor,
STYLE_DOT,
3,
false,
false,
true);
}
@@ -0,0 +1,365 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XDON
// Description: DONCHAIN Channel ...
//
// 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 XDON Indicator"
#property strict
//
#define ShortName "XDON"
//
// INPUT ...
//
input int length = 52; // Market Length
input double offset = 0; // Offset
//
// BUFFERS ...
//
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 8
//
#define upperOBufferIndex 0
double upperOBuffer[];
//
#property indicator_label1 "XDON OU"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrCornflowerBlue
#property indicator_width1 2
//
#define lowerOBufferIndex 1
double lowerOBuffer[];
//
#property indicator_label2 "XDON OL"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrCornflowerBlue
#property indicator_width2 2
//
#define upperCBufferIndex 2
double upperCBuffer[];
//
#property indicator_label3 "XDON CU"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrCoral
#property indicator_width3 2
//
#define lowerCBufferIndex 3
double lowerCBuffer[];
//
#property indicator_label4 "XDON CL"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrCoral
#property indicator_width4 2
//
#define upperHBufferIndex 4
double upperHBuffer[];
//
#property indicator_label5 "XDON HU"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrAquamarine
#property indicator_width5 2
//
#define lowerHBufferIndex 5
double lowerHBuffer[];
//
#property indicator_label6 "XDON HL"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrAquamarine
#property indicator_width6 2
//
#define upperLBufferIndex 6
double upperLBuffer[];
//
#property indicator_label7 "XDON LU"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrDarkOrchid
#property indicator_width7 2
//
#define lowerLBufferIndex 7
double lowerLBuffer[];
//
#property indicator_label8 "XDON LL"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrDarkOrchid
#property indicator_width8 2
//
// 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(
//
// 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[])
{
//
if (rates_total < length - 1)
{
return prev_calculated;
}
//
int start = prev_calculated == 0
? length
: prev_calculated - 1;
//
// Main Loop ...
for (int barIndex = start; barIndex < rates_total; barIndex++)
{
//
// OPEN ...
//
double upperOValue = open[ArrayMaximum(open, barIndex - length + 1, length)];
double lowerOValue = open[ArrayMinimum(open, barIndex - length + 1, length)];
//
double oDelta = MathAbs(upperOValue - lowerOValue);
double oOffsetValue = oDelta * (offset) * 0.01;
//
upperOBuffer[barIndex] = upperOValue - oOffsetValue;
lowerOBuffer[barIndex] = lowerOValue + oOffsetValue;
//
// CLOSE ...
//
double upperCValue = close[ArrayMaximum(close, barIndex - length + 1, length)];
double lowerCValue = close[ArrayMinimum(close, barIndex - length + 1, length)];
//
double cDelta = MathAbs(upperCValue - lowerCValue);
double cOffsetValue = cDelta * (offset) * 0.01;
//
upperCBuffer[barIndex] = upperCValue - cOffsetValue;
lowerCBuffer[barIndex] = lowerCValue + cOffsetValue;
//
// HIGH ...
//
double upperHValue = high[ArrayMaximum(high, barIndex - length + 1, length)];
double lowerHValue = high[ArrayMinimum(high, barIndex - length + 1, length)];
//
double hDelta = MathAbs(upperHValue - lowerHValue);
double hOffsetValue = hDelta * (offset) * 0.01;
//
upperHBuffer[barIndex] = upperHValue - hOffsetValue;
lowerHBuffer[barIndex] = lowerHValue + hOffsetValue;
//
// LOW ...
//
double upperLValue = low[ArrayMaximum(low, barIndex - length + 1, length)];
double lowerLValue = low[ArrayMinimum(low, barIndex - length + 1, length)];
//
double lDelta = MathAbs(upperLValue - lowerLValue);
double lOffsetValue = lDelta * (offset) * 0.01;
//
upperLBuffer[barIndex] = upperLValue - lOffsetValue;
lowerLBuffer[barIndex] = lowerLValue + lOffsetValue;
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result = length >= 7;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Open ...
//
// UPPER ...
SetIndexBuffer(upperOBufferIndex, upperOBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperOBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerOBufferIndex, lowerOBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerOBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// Close ...
//
// UPPER ...
SetIndexBuffer(upperCBufferIndex, upperCBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperCBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerCBufferIndex, lowerCBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerCBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// High ...
//
// UPPER ...
SetIndexBuffer(upperHBufferIndex, upperHBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperHBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerHBufferIndex, lowerHBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerHBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// Low ...
//
// UPPER ...
SetIndexBuffer(upperLBufferIndex, upperLBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upperLBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(upperLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//
// LOWER ...
SetIndexBuffer(lowerLBufferIndex, lowerLBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowerLBufferIndex, PLOT_SHOW_DATA, true);
PlotIndexSetDouble(lowerLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
@@ -0,0 +1,187 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Alert Library
// --------------------------------------
// Name: XAlert
// Description: provides Alerts abilities ...
//
//
// 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
//
// START Inputs ...
//
input group "Alerts";
input bool enableAlerts = true; // Enable Alerts
input bool logAlerts = true; // Log Alerts
input bool terminalAlerts = false; // Terminal Alerts
input bool mailAlerts = false; // Mail Alerts
input bool pushAlerts = false; // Push Alerts
//
// END Inputs ...
//
//
#include "x-saherelm.log.lib.mq5"
//
// START Global Definitions: Variables, Properties and etc ...
//
string alertPrefix = "X-Alert";
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// Initial Library if required ...
bool OnInInitAlertLibrary()
{
return false;
}
//
// DeInitial Library if required ...
void OnDeinitAlertLibrary()
{
}
//
// Attach Alert Prefix to Message ...
string PrepareAlertMessage(string message)
{
//
StringReplace(message, "\n", " | ");
//
StringConcatenate(message, alertPrefix, " > ", message);
//
return message;
}
//
// Logging an Alert ...
void LogAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !logAlerts)
{
return;
}
//
LogMessage(alertPrefix, message);
}
//
// Terminal Alert ...
void TerminalAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !terminalAlerts)
{
return;
}
//
// Prepare Message ...
message = PrepareAlertMessage(message);
// Send Terminal Alert ...
Alert(message);
}
//
// Mail Alert ...
void MailAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !mailAlerts)
{
return;
}
//
// Send Mail Alert ...
SendMail(alertPrefix, message);
}
//
// Send Push Notification ...
void PushAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !pushAlerts)
{
return;
}
//
// Prepare Message ...
message = PrepareAlertMessage(message);
//
// Send Push Notification Alert ...
SendNotification(message);
}
//
// Alert Sending ...
void SendAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts)
{
return;
}
//
// Log ...
if (logAlerts)
{
LogAlert(message);
}
//
// Terminal ...
if (terminalAlerts)
{
TerminalAlert(message);
}
//
// Mail ...
if (mailAlerts)
{
MailAlert(message);
}
//
// Push ...
if (pushAlerts)
{
PushAlert(message);
}
}
//
// END Provided Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,177 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Http Library
// ------------------------------------------
// Name: XHttp
// Description: provide http communication
// abilities ...
//
//
// 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
//
// START Model Definition ...
//
enum X_HTTP_METHOD
{
X_HTTP_GET,
X_HTTP_POST
};
//
// END Model Definition ...
//
//
// START Inputs ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// Initial Library if required ...
bool OnInInitHttpLibrary()
{
return false;
}
//
// DeInitial Library if required ...
void OnDeinitHttpLibrary()
{
}
//
// Convert enum to String ...
string ToString(X_HTTP_METHOD method)
{
//
string result = "";
//
switch (method)
{
//
case X_HTTP_GET:
result = "GET";
break;
//
case X_HTTP_POST:
result = "POST";
break;
}
//
return result;
}
//
// Send Global Request ...
int SendRequest(
X_HTTP_METHOD method, // Httm Request Method
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = -1;
//
string strMethod = ToString(method);
if (StringLen(strMethod) == 0) {
return result;
}
//
result = WebRequest(
strMethod,
url,
headers,
timeout,
payload,
response,
responseHeaders
);
//
return result;
}
//
// Get Request ...
int GetRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
) {
//
int result = SendRequest(
X_HTTP_GET,
url,
headers,
payload,
response,
responseHeaders,
timeout
);
//
return result;
}
//
// Post Request ...
int PostRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
) {
//
int result = SendRequest(
X_HTTP_POST,
url,
headers,
payload,
response,
responseHeaders,
timeout
);
//
return result;
}
//
// END Provided Functions ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,326 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Models Library
// ---------------------------------------
// Name: XModels
// Description: provides all required models ...
//
//
// 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
//
// START Inputs ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// How To Calculate Static Volume ...
enum ENUM_STATIC_VOLUME_METHODS
{
//
// Based On Deposit ...
X_STATIC_VOLUME_BASED_ON_DEPOSIT,
//
// Based On Balance ...
X_STATIC_VOLUME_BASED_ON_BALANCE,
};
//
// START Model Definitions ...
//
//
// OHCL Candel Model ...
enum ENUM_X_PRICE
{
X_PRICE_HIGH,
X_PRICE_OPEN,
X_PRICE_CLOSE,
X_PRICE_LOW
};
//
// Swing Types Enum ...
enum ENUM_X_SWING_TYPE
{
X_NO_SWING = 0,
X_SWING_HIGH = 1,
X_SWING_LOW = -1,
};
//
// Select Positions Type ...
enum ENUM_X_POSITION_SELECT_METHODS
{
X_POSITION_SELECT_NONE, // None
X_POSITION_SELECT_MAX, // Max
X_POSITION_SELECT_MIN, // Min
X_POSITION_SELECT_ALL, // Min
};
//
// XPERIOD Calculation Method ...
enum ENUM_X_PERIOD_METHOD
{
//
X_PERIOD_NOTHING, // Nothing
X_PERIOD_AUTO, // Auto Select
X_PERIOD_MANUALLY // Manually
};
//
enum ENUM_X_MARKET_CYCLES
{
//
X_MARKET_CYCLE_UNKNOWN, // Unknown Cycle
X_MARKET_CYCLE_SHORT, // Short Cycle
X_MARKET_CYCLE_MEDIUM, // Medium Cycle
X_MARKET_CYCLE_LONG, // Long Cycle
X_MARKET_CYCLE_HIND, // Hind Cycle
};
//
// Available Guard Action ...
enum ENUM_X_GUARD_ACTIONS
{
X_GUARD_ACTION_NOTHING, // Nothing
X_GUARD_ACTION_HEDGE, // Hedge
X_GUARD_PARTIAL_CLOSE, // Partial Close
X_GUARD_ACTION_TRAIL_STOP, // Trail StopLoss
X_GUARD_ACTION_FORCE_CLOSE, // Force Close
X_GUARD_ACTION_ADD_SUPPORT_SIGNAL, // Add Support Signal
X_GUARD_ACTION_CANCEL_PENDING_ORDERS, // Cancel Pending Orders
};
//
// Model Guard Info ...
struct XGuard
{
string symbol;
string provider;
ENUM_TIMEFRAMES period;
ENUM_POSITION_TYPE type;
ENUM_X_GUARD_ACTIONS action;
//
double dblPayLoad;
string strPayload;
};
//
// Describe an Specific Candle ...
struct XOHCL
{
//
double high;
double open;
double close;
double low;
//
string ToString()
{
//
string result = "";
//
result = "XOHCL(O(" + (string)open + "),H(" + (string)high + "),C(" + (string)close + "),L(" + (string)low + "))";
//
return result;
}
};
//
// Model Support and Resistance
// for Specific Bar ...
struct XOHCLSupRes
{
//
double res[];
//
double sup[];
};
//
struct XValueChanged
{
datetime at;
double from;
double to;
};
//
// Available Order Modes ...
enum ENUM_X_ORDER_MODES
{
X_ORDER_MODE_MARKET = 0, // Market Order
X_ORDER_MODE_STOP = 1, // Pending Stop Order
X_ORDER_MODE_LIMIT = 2, // Pending Limit Order
X_ORDER_MODE_STOP_LIMIT = 3, // Pending Stop Limit Order
};
//
// Model a Signal ...
struct XSignal
{
//
string providers[];
//
string symbol;
//
ENUM_TIMEFRAMES period;
//
ENUM_POSITION_TYPE type;
//
ENUM_X_ORDER_MODES mode;
//
double entry;
//
double tp;
//
double sl;
//
double r2r;
//
double volume;
//
// Support Signals ...
XSignal supports[];
//
XOHCLSupRes supportResistances;
};
//
// EXTENSION Methods ...
//
// Clear an Specific Signal Item ...
void Clean(XSignal &item)
{
//
Clean(item.providers);
//
Clean(item.supports);
//
Clean(item.supportResistances);
//
item.symbol = "";
item.type = NULL;
item.mode = NULL;
item.period = NULL;
//
item.tp = 0;
item.sl = 0;
item.r2r = 0;
item.entry = 0;
item.volume = 0;
}
//
void Clean(XOHCLSupRes &item)
{
Clean(item.sup);
Clean(item.res);
}
template <typename T>
void Add(
T &item,
T &buffer[])
{
//
ArrayResize(
buffer,
ArraySize(buffer) + 1);
//
buffer[ArraySize(buffer) - 1] = item;
}
template <typename T>
void Clean(T &buffer[])
{
//
ArrayFree(buffer);
ArrayResize(buffer, 0);
}
template <typename T>
void Copy(
T &source[], // Source Buffer ...
T &dest[], // Dest Buffer ...
bool cleanDest = true // Force Clen Dest Buffer ...
)
{
//
if (cleanDest)
{
Clean(dest);
}
//
int sourceCount = ArraySize(source);
if (sourceCount <= 0)
{
return;
}
//
for (int i = 0; i < sourceCount; i++)
{
//
T iSource = source[i];
//
Add(
iSource,
dest);
}
}
//
// END Provided Functions ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,284 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X12 Draw Library
// ------------------------------------------
// Name: X121Draw
// Description: provides Draw Requirements ...
//
//
// 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
//
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
//
// START Draw Functions ...
//
//
// Draw Signal ...
void DrawSignal(const ulong ticket, XSignal &signal)
{
//
bool isLong = IsLong(signal.type);
//
string prefix = (string)ticket + "_" + ToString(signal.period);
//
// Retrieve Time ...
datetime time = iTime(
signal.symbol,
signal.period,
0);
//
// Retrieve 3 Time ...
datetime time3 = iTime(
signal.symbol,
signal.period,
3);
//
color posColor = isLong
? clrSpringGreen
: clrTomato;
color tpColor = clrSpringGreen;
color slColor = clrTomato;
color entryColor = clrGold;
//
ENUM_LINE_STYLE vLineStyle = STYLE_DOT;
ENUM_LINE_STYLE tpLineStyle = STYLE_SOLID;
ENUM_LINE_STYLE slLineStyle = STYLE_SOLID;
ENUM_LINE_STYLE entryLineStyle = STYLE_SOLID;
//
int lineWidth = 2;
//
long chartID = ChartID();
//
// Vertical Line ...
string vlName = prefix + "_" + (string)time;
//
// DrawVerticalLine(
// chartID,
// vlName,
// 0,
// time,
// posColor,
// vLineStyle,
// lineWidth);
//
// TP ...
double profit = (MathAbs(signal.tp - signal.entry)) * signal.volume;
string tpName = prefix + "_TP_" + (string)profit;
//
DrawTrendLine(
chartID,
tpName,
0,
time3,
signal.tp,
time,
signal.tp,
tpColor,
tpLineStyle,
lineWidth);
//
// SL ...
double lost = (MathAbs(signal.sl - signal.entry)) * signal.volume;
string slName = prefix + "_SL_" + (string)lost;
//
DrawTrendLine(
chartID,
slName,
0,
time3,
signal.sl,
time,
signal.sl,
slColor,
slLineStyle,
lineWidth);
//
// TODO: Fix this ...
return;
//
// ENTRY ...
string entryName = prefix + "_ENTRY_" + (string)lost;
//
DrawTrendLine(
chartID,
entryName,
0,
time3,
signal.entry,
time,
signal.entry,
entryColor,
entryLineStyle,
lineWidth);
}
//
void DrawSignals(
XSignal &signals[], // Signals To Draw
bool drawSupportAndResistances = false // Draw Signal Support and Resistance
)
{
//
int signalsCount = ArraySize(signals);
if (signalsCount <= 0)
{
return;
}
//
for (int i = 0; i < signalsCount; i++)
{
//
XSignal iSignal = signals[i];
//
ulong iTicket = MathRand() * 10000;
//
DrawSignal(iTicket, iSignal);
//
// TODO: Remove this ...
return;
//
// Check For Draw Support and Resistances ...
bool isValidSupRes = ArraySize(iSignal.supportResistances.sup) > 0 || ArraySize(iSignal.supportResistances.res) > 0;
if (drawSupportAndResistances && isValidSupRes)
{
DrawSupportResistance(0, iSignal.supportResistances);
}
}
}
//
// Draw Support and Resistance ...
void DrawSupportResistance(
int bar_index,
XOHCLSupRes &data,
string prefix = "",
color supportColor = clrOrange,
color resistanceColor = clrOrange)
{
//
datetime barTime = GetCandleTime(
_Symbol,
_Period,
bar_index);
//
datetime prevBarTime = GetCandleTime(
_Symbol,
_Period,
bar_index + 5);
//
long chID = ChartID();
int subWindiw = 0;
int lineWidth = 1;
//
string mPrefix = prefix + "_" + (string)barTime + "_";
//
// SUPPORTS ...
//
int supCount = ArraySize(data.sup);
if (supCount > 0)
{
//
for (int i = 0; i < supCount; i++)
{
//
double iSup = data.sup[i];
//
string supTlName = mPrefix + "SUP[" + (string)(i + 1) + "]_(" + (string)iSup + ")";
//
// Draw Support ...
DrawTrendLine(
chID,
supTlName,
subWindiw,
prevBarTime,
iSup,
barTime,
iSup,
supportColor,
STYLE_DOT,
lineWidth,
true);
}
}
//
// RESISTANCES ...
//
int resCount = ArraySize(data.res);
if (resCount > 0)
{
//
for (int i = 0; i < resCount; i++)
{
//
double iRes = data.res[i];
//
string resTlName = mPrefix + "RES[" + (string)(i + 1) + "]_(" + (string)iRes + ")";
//
// Draw Support ...
DrawTrendLine(
chID,
resTlName,
subWindiw,
prevBarTime,
iRes,
barTime,
iRes,
resistanceColor,
STYLE_DOT,
lineWidth,
true);
}
}
}
//
// END Draw Functions ...
//
@@ -0,0 +1,436 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121X786
// Description: X121 X786 Signal Provider ...
//
//
// 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
//
#include "../Libraries/x-saherelm.x121.condition.parser.lib.mq5"
//
// CONDITIONS ...
//
// Longs ...
bool IsX786HasLongSignal(
const X121MarketConditions &conditions, // Specified Conditions
int index = 0 // Array Index
)
{
//
bool result = false;
//
bool long1 =
//
IsHKBullish(conditions) &&
IsSMHKBullish(conditions) &&
IsHullBullish(conditions, index) &&
IsSSLCBullish(conditions, index) &&
IsTrendBullish(conditions, index) &&
IsRibbonBullish(conditions, index) &&
IsBullishCandle(conditions.candles[1])
//
;
//
bool long2 =
//
IsTrendBullish(conditions) &&
IsNewPeakOverLast(conditions) &&
//
(
//
IsSCLowBullish(conditions) &&
(
//
IsMCLowBullish(conditions) ||
IsLCLowBullish(conditions) ||
IsHCLowBullish(conditions)
//
)
//
)
//
;
//
result =
//
long1
//
||
//
long2
//
;
//
return result;
}
//
// Shorts ...
bool IsX786HasShortSignal(
const X121MarketConditions &conditions, // Specified Conditions
int index = 0 // Array Index
)
{
//
bool result = false;
//
bool short1 =
//
IsHKBearish(conditions) &&
IsSMHKBearish(conditions) &&
IsHullBearish(conditions, index) &&
IsSSLCBearish(conditions, index) &&
IsTrendBearish(conditions, index) &&
IsRibbonBearish(conditions, index) &&
IsBearishCandle(conditions.candles[1])
//
;
//
bool short2 =
//
IsTrendBearish(conditions, index) &&
IsNewValeUnderLast(conditions) &&
//
(
//
IsSCHighBearish(conditions) &&
(
//
IsMCHighBearish(conditions) ||
IsLCHighBearish(conditions) ||
IsHCHighBearish(conditions)
//
)
//
)
//
;
//
result =
//
short1
//
||
//
short2
//
;
//
return result;
}
//
// CALCULATIONS ...
//
// Calculate Long Stop ...
double CalculateX786LongStop(const X121MarketConditions &conditions)
{
//
double result = 0;
//
double vale = conditions.xmanInfo.vales[0];
double med = (conditions.xmanInfo.sLLs[0] + conditions.xmanInfo.mLLs[0]) / 2;
double fl1 = conditions.xmanInfo.fibLevel1s[0];
//
result =
//
0
//
;
//
return result;
}
//
// Calculate Long Take Profits ...
double CalculateX786LongTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
{
//
double result = 0;
//
if (sl > 0 && entry > 0 && r2r > 0)
{
//
double riskPrice = MathAbs(entry - sl);
double rewardPrice = riskPrice * r2r;
//
result = entry + rewardPrice;
}
else
{
result = entry + PointToPrice(conditions.symbol, 60);
}
//
return result;
}
//
// Calculate Short Stop ...
double CalculateX786ShortStop(const X121MarketConditions &conditions)
{
//
double result = 0;
//
return result;
}
//
// Calculate Short Take Profits ...
double CalculateX786ShortTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
{
//
double result = 0;
//
if (sl > 0 && entry > 0 && r2r > 0)
{
//
double riskPrice = MathAbs(entry - sl);
double rewardPrice = riskPrice * r2r;
//
result = entry - rewardPrice;
}
else
{
result = entry - PointToPrice(conditions.symbol, 60);
}
//
return result;
}
//
// SIGNALS ...
//
// Generate Signal ...
bool GenerateX786Signal(
X121MarketConditions &conditions, // Specified Conditions which Holds Signal also ...
const XOHCLSupRes &supportAndResistances, // Specified Support and Resistances ...
ENUM_POSITION_TYPE type, // Specified Which Signal Type must be Generated ...
bool generateSupports = false // Specified Support Signals also Generated and Attached or not ...
)
{
//
bool result = false;
//
bool isLong = IsLong(type);
//
// Retrieve Entry Price ...
double entry = GetEntry(
conditions.symbol,
type);
//
result =
//
isLong
? IsX786HasLongSignal(conditions)
: IsX786HasShortSignal(conditions)
//
;
//
if (result)
{
//
Add(
ToString(X786),
conditions.signal.providers);
//
double sl =
//
isLong
? CalculateX786LongStop(conditions)
: CalculateX786ShortStop(conditions)
//
;
//
double r2r = 3;
//
double tp =
//
isLong
? CalculateX786LongTarget(conditions, sl, entry, r2r)
: CalculateX786ShortTarget(conditions, sl, entry, r2r)
//
;
//
double volume = 0.01;
//
conditions.hasSignal = true;
//
conditions.signal.type = type;
conditions.signal.symbol = conditions.symbol;
conditions.signal.period = conditions.period;
conditions.signal.supportResistances = supportAndResistances;
//
conditions.signal.sl = sl;
conditions.signal.tp = tp;
conditions.signal.r2r = r2r;
conditions.signal.entry = entry;
conditions.signal.volume = volume;
conditions.signal.mode = X_ORDER_MODE_MARKET;
//
if (generateSupports)
{
//
// Generate Required Support Signals ...
GenerateX786SignalSupports(conditions);
}
}
//
return result;
}
//
// SUPPORTS ...
//
// Generate Required Support Signals and Attached Them into
// Exists Signal of Conditions ...
int GenerateX786SignalSupports(
X121MarketConditions &conditions)
{
//
int result = 0;
//
return result;
}
//
// GUARDS ...
//
// Check Can Force Close All X786 Long Signals or not ...
bool CanX786ForceCloseLongs(const X121MarketConditions &conditions)
{
//
bool result = false;
//
// 1- HK Min above FL 1 ...
// 2- Trend Changed From Bullish To Bearish ...
//
double minHK = GetHKMin(conditions);
bool isMinHKOverFL1 = minHK > conditions.xmanInfo.fibLevel1s[0];
bool isTrendSwitchedToBearish = IsTrendSwitchedToBearish(conditions);
//
result =
//
// isMinHKOverFL1 &&
isTrendSwitchedToBearish
//
;
// if (result) {
// LogMessage("Test");
// }
//
return result;
}
//
// Check for Trailing Long Positions Stops ...
bool CanX786TrailLongsStop(
const X121MarketConditions &conditions,
double &newSL //
)
{
//
bool result = false;
//
double prev = GetRibbonMin(conditions, 1);
double current = GetRibbonMin(conditions);
//
result = current > prev;
if (result)
{
newSL = current;
}
else
{
newSL = -1;
}
//
return result;
}
//
// Check For Trailing Short Positions Stops ...
bool CanX786TrailShortsStop(
const X121MarketConditions &conditions,
double &newSL //
)
{
//
bool result = false;
//
double prev = GetRibbonMax(conditions, 1);
double current = GetRibbonMax(conditions);
//
result = current < prev;
if (result)
{
newSL = current;
}
else
{
newSL = -1;
}
//
return result;
}
@@ -0,0 +1,430 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121X92
// Description: X121 X92 Signal Provider ...
//
//
// 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
//
#include "../Libraries/x-saherelm.x121.condition.parser.lib.mq5"
//
// CONDITIONS ...
//
// Longs ...
bool IsX92HasLongSignal(
const X121MarketConditions &conditions, // Specified Conditions
int index = 0 // Array Index
)
{
//
bool result = false;
//
bool long1 =
//
IsNewPeak(conditions) &&
IsValeSameAs(conditions) &&
IsNewPeakUnderLast(conditions)
//
;
//
bool long2 =
//
IsSMHKBullish(conditions, index) &&
IsTrendBullish(conditions, index) &&
IsBullishCandle(conditions.candles[index + 1])
//
&&
//
(conditions.candles[index + 1].low > GetSMHKMax(conditions, index) ||
conditions.candles[index + 1].close > GetSMHKMax(conditions, index))
//
&&
//
conditions.xmanInfo.smhkHighs[index] == iSMHKHighest(conditions, index)
//
&&
//
IsSCLowBullish(conditions, index)
//
;
//
result =
//
long1
//
||
//
long2
//
;
//
return result;
}
//
// Shorts ...
bool IsX92HasShortSignal(
const X121MarketConditions &conditions, // Specified Conditions
int index = 0 // Array Index
)
{
//
bool result = false;
//
bool short1 =
//
IsNewVale(conditions) &&
IsPeakSameAs(conditions) &&
IsNewValeOverLast(conditions)
//
;
//
bool short2 =
//
IsSMHKBearish(conditions, index) &&
IsTrendBearish(conditions, index) &&
IsBearishCandle(conditions.candles[index + 1])
//
&&
//
(conditions.candles[index + 1].high < GetSMHKMin(conditions, index) ||
conditions.candles[index + 1].open < GetSMHKMin(conditions, index))
//
&&
//
conditions.xmanInfo.smhkHighs[index] == iSMHKLowest(conditions, index)
//
&&
//
IsSCHighBearish(conditions, index)
//
;
//
result =
//
short1
//
||
//
short2
//
;
//
return result;
}
//
// CALCULATIONS ...
//
// Calculate Long Stop ...
double CalculateX92LongStop(const X121MarketConditions &conditions)
{
//
double result = 0;
//
double vale = conditions.xmanInfo.vales[0];
double med = (conditions.xmanInfo.sLLs[0] + conditions.xmanInfo.mLLs[0]) / 2;
double fl1 = conditions.xmanInfo.fibLevel1s[0];
//
result =
//
0
//
;
//
return result;
}
//
// Calculate Long Take Profits ...
double CalculateX92LongTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
{
//
double result = 0;
//
if (sl > 0 && entry > 0 && r2r > 0)
{
//
double riskPrice = MathAbs(entry - sl);
double rewardPrice = riskPrice * r2r;
//
result = entry + rewardPrice;
}
else
{
result = entry + PointToPrice(conditions.symbol, 60);
}
//
return result;
}
//
// Calculate Short Stop ...
double CalculateX92ShortStop(const X121MarketConditions &conditions)
{
//
double result = 0;
//
return result;
}
//
// Calculate Short Take Profits ...
double CalculateX92ShortTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
{
//
double result = 0;
//
if (sl > 0 && entry > 0 && r2r > 0)
{
//
double riskPrice = MathAbs(entry - sl);
double rewardPrice = riskPrice * r2r;
//
result = entry - rewardPrice;
}
else
{
result = entry - PointToPrice(conditions.symbol, 60);
}
//
return result;
}
//
// SIGNALS ...
//
// Generate Signal ...
bool GenerateX92Signal(
X121MarketConditions &conditions, // Specified Conditions which Holds Signal also ...
const XOHCLSupRes &supportAndResistances, // Specified Support and Resistances ...
ENUM_POSITION_TYPE type, // Specified Which Signal Type must be Generated ...
bool generateSupports = false // Specified Support Signals also Generated and Attached or not ...
)
{
//
bool result = false;
//
bool isLong = IsLong(type);
//
// Retrieve Entry Price ...
double entry = GetEntry(
conditions.symbol,
type);
//
result =
//
isLong
? IsX92HasLongSignal(conditions)
: IsX92HasShortSignal(conditions)
//
;
//
if (result)
{
//
Add(
ToString(X92),
conditions.signal.providers);
//
double sl =
//
isLong
? CalculateX92LongStop(conditions)
: CalculateX92ShortStop(conditions)
//
;
//
double r2r = 3;
//
double tp =
//
isLong
? CalculateX92LongTarget(conditions, sl, entry, r2r)
: CalculateX92ShortTarget(conditions, sl, entry, r2r)
//
;
//
double volume = 0.01;
//
conditions.hasSignal = true;
//
conditions.signal.type = type;
conditions.signal.symbol = conditions.symbol;
conditions.signal.period = conditions.period;
conditions.signal.supportResistances = supportAndResistances;
//
conditions.signal.sl = sl;
conditions.signal.tp = tp;
conditions.signal.r2r = r2r;
conditions.signal.entry = entry;
conditions.signal.volume = volume;
conditions.signal.mode = X_ORDER_MODE_MARKET;
//
if (generateSupports)
{
//
// Generate Required Support Signals ...
GenerateX92SignalSupports(conditions);
}
}
//
return result;
}
//
// SUPPORTS ...
//
// Generate Required Support Signals and Attached Them into
// Exists Signal of Conditions ...
int GenerateX92SignalSupports(
X121MarketConditions &conditions)
{
//
int result = 0;
//
return result;
}
//
// GUARDS ...
//
// Check Can Force Close All X92 Long Signals or not ...
bool CanX92ForceCloseLongs(const X121MarketConditions &conditions)
{
//
bool result = false;
//
// 1- HK Min above FL 1 ...
// 2- Trend Changed From Bullish To Bearish ...
//
double minHK = GetHKMin(conditions);
bool isMinHKOverFL1 = minHK > conditions.xmanInfo.fibLevel1s[0];
bool isTrendSwitchedToBearish = IsTrendSwitchedToBearish(conditions);
//
result =
//
// isMinHKOverFL1 &&
isTrendSwitchedToBearish
//
;
// if (result) {
// LogMessage("Test");
// }
//
return result;
}
//
// Check for Trailing Long Positions Stops ...
bool CanX92TrailLongsStop(
const X121MarketConditions &conditions,
double &newSL //
)
{
//
bool result = false;
//
double prev = GetRibbonMin(conditions, 1);
double current = GetRibbonMin(conditions);
//
result = current > prev;
if (result)
{
newSL = current;
}
else
{
newSL = -1;
}
//
return result;
}
//
// Check For Trailing Short Positions Stops ...
bool CanX92TrailShortsStop(
const X121MarketConditions &conditions,
double &newSL //
)
{
//
bool result = false;
//
double prev = GetRibbonMax(conditions, 1);
double current = GetRibbonMax(conditions);
//
result = current < prev;
if (result)
{
newSL = current;
}
else
{
newSL = -1;
}
//
return result;
}
@@ -0,0 +1,354 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121XTEST
// Description: X121 XTEST Signal Provider ...
//
//
// 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
//
#include "../Libraries/x-saherelm.x121.condition.parser.lib.mq5"
//
// CONDITIONS ...
//
// Longs ...
bool IsXTESTHasLongSignal(
const X121MarketConditions &conditions, // Specified Conditions
int index = 0 // Array Index
)
{
//
bool result = false;
//
bool isTrendBullish = IsTrendBullish(conditions, index);
bool isCandleBullish = IsBullishCandle(conditions.candles[1]);
bool isValidTrend = ArraySize(conditions.xmanInfo.trendChanges) > 2 &&
conditions.xmanInfo.trends[0] > conditions.xmanInfo.trends[1] &&
conditions.xmanInfo.trends[0] > conditions.xmanInfo.trendChanges[0].from;
//
result =
//
isValidTrend &&
isTrendBullish &&
isCandleBullish
//
;
//
return result;
}
//
// Shorts ...
bool IsXTESTHasShortSignal(
const X121MarketConditions &conditions, // Specified Conditions
int index = 0 // Array Index
)
{
//
bool result = false;
//
bool isTrendBearish = IsTrendBearish(conditions, index);
bool isCandleBearish = IsBearishCandle(conditions.candles[1]);
bool isValidTrend = ArraySize(conditions.xmanInfo.trendChanges) > 2 &&
conditions.xmanInfo.trends[0] < conditions.xmanInfo.trends[1] &&
conditions.xmanInfo.trends[0] < conditions.xmanInfo.trendChanges[0].from;
//
result =
//
isValidTrend &&
isTrendBearish &&
isCandleBearish
//
;
//
return result;
}
//
// CALCULATIONS ...
//
// Calculate Long Stop ...
double CalculateXTESTLongStop(const X121MarketConditions &conditions)
{
//
double result = 0;
//
result =
//
conditions.xmanInfo.vales[0]
//
;
//
return result;
}
//
// Calculate Long Take Profits ...
double CalculateXTESTLongTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
{
//
double result = 0;
//
if (sl > 0 && entry > 0 && r2r > 0)
{
//
double riskPrice = MathAbs(entry - sl);
double rewardPrice = riskPrice * r2r;
//
result = entry + rewardPrice;
}
else
{
result = entry + PointToPrice(conditions.symbol, 60);
}
//
double peak = conditions.xmanInfo.peaks[1];
result =
entry >= peak
? entry + PointToPrice(conditions.symbol, 60)
: peak;
//
return result;
}
//
// Calculate Short Stop ...
double CalculateXTESTShortStop(const X121MarketConditions &conditions)
{
//
double result = 0;
//
result =
//
conditions.xmanInfo.peaks[0]
//
;
//
return result;
}
//
// Calculate Short Take Profits ...
double CalculateXTESTShortTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
{
//
double result = 0;
//
if (sl > 0 && entry > 0 && r2r > 0)
{
//
double riskPrice = MathAbs(entry - sl);
double rewardPrice = riskPrice * r2r;
//
result = entry - rewardPrice;
}
else
{
result = entry - PointToPrice(conditions.symbol, 60);
}
//
double vale = conditions.xmanInfo.vales[1];
result =
entry <= vale
? entry - PointToPrice(conditions.symbol, 60)
: vale;
//
return result;
}
//
// SIGNALS ...
//
// Generate Signal ...
bool GenerateXTESTSignal(
X121MarketConditions &conditions, // Specified Conditions which Holds Signal also ...
const XOHCLSupRes &supportAndResistances, // Specified Support and Resistances ...
ENUM_POSITION_TYPE type, // Specified Which Signal Type must be Generated ...
bool generateSupports = false // Specified Support Signals also Generated and Attached or not ...
)
{
//
bool result = false;
//
bool isLong = IsLong(type);
//
// Retrieve Entry Price ...
double entry = GetEntry(
conditions.symbol,
type);
//
result =
//
isLong
? IsXTESTHasLongSignal(conditions)
: IsXTESTHasShortSignal(conditions)
//
;
//
if (result)
{
//
Add(
ToString(XTEST),
conditions.signal.providers);
//
double sl =
//
isLong
? CalculateXTESTLongStop(conditions)
: CalculateXTESTShortStop(conditions)
//
;
//
double r2r = 1.5;
//
double tp =
//
isLong
? CalculateXTESTLongTarget(conditions, sl, entry, r2r)
: CalculateXTESTShortTarget(conditions, sl, entry, r2r)
//
;
//
double volume = 0.01;
//
conditions.hasSignal = true;
//
conditions.signal.type = type;
conditions.signal.symbol = conditions.symbol;
conditions.signal.period = conditions.period;
conditions.signal.supportResistances = supportAndResistances;
//
conditions.signal.sl = 0; // sl;
conditions.signal.tp = tp;
conditions.signal.r2r = r2r;
conditions.signal.entry = entry;
conditions.signal.volume = volume;
conditions.signal.mode = X_ORDER_MODE_MARKET;
//
if (generateSupports)
{
//
// Generate Required Support Signals ...
GenerateXTESTSignalSupports(conditions);
}
}
//
return result;
}
//
// SUPPORTS ...
//
// Generate Required Support Signals and Attached Them into
// Exists Signal of Conditions ...
int GenerateXTESTSignalSupports(
X121MarketConditions &conditions)
{
//
int result = 0;
//
return result;
}
//
// GUARDS ...
//
// Check Can Force Close All XTEST Long Signals or not ...
bool CanXTESTForceCloseLongs(const X121MarketConditions &conditions)
{
//
bool result = false;
//
bool isTrendSwitchedToBearish = IsTrendSwitchedToBearish(conditions);
//
result =
//
false
//
;
//
return result;
}
//
// Check for Trailing Long Positions Stops ...
bool CanXTESTTrailLongsStop(
const X121MarketConditions &conditions,
double &newSL //
)
{
//
bool result = false;
//
return result;
}
//
// Check For Trailing Short Positions Stops ...
bool CanXTESTTrailShortsStop(
const X121MarketConditions &conditions,
double &newSL //
)
{
//
bool result = false;
//
return result;
}
File diff suppressed because it is too large Load Diff