add MQL5Test Workspace Content as BKP Solution ...

This commit is contained in:
2024-04-22 07:42:50 +03:30
parent ec0a03203e
commit f7fd579a9d
197 changed files with 80113 additions and 0 deletions
@@ -0,0 +1,470 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXAMAHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XAMAInputs
{
//
// Makret ...
int length; // Length
int fastEMA; // Fast EMA Length
int slowEMA; // Slow EMA Length
int maShift; // Shift
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Presentation ...
bool showLine; // Show Line
};
//
// Index of Lines ...
enum ENUM_XAMA_BUFFERS
{
//
// Main Requirements ...
XAMA_LINE = 0,
XAMA_STATE_LINE = 1,
};
//
// XAMA Indicator States ...
enum ENUM_XAMA_STATES
{
X_XAMA_BULLISH = 0,
X_XAMA_BEARISH = 2,
X_XAMA_NEUTURAL = 1,
};
//
// Retrieve Info Model ...
struct XAMAInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double value;
//
// State ...
ENUM_XAMA_STATES state;
//
// Conditions ...
//
// Detect Trend is Bullish or not ...
bool isBullish;
//
// Detect Trend is Switched to Bullish Or not ...
bool isSwitchedBullish;
//
// Detect Trend is Bearish or not ...
bool isBearish;
//
// Detect Trend is Switched to Bearish Or not ...
bool isSwitchedBearish;
//
// Detect Trend is Neutural or not ...
bool isNeutural;
//
// Detect Trend is Switched to Neutural Or not ...
bool isSwitchedNeutural;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXAMAHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double valueBuffer[];
double stateBuffer[];
//
// Constructor ...
void XSCXAMAHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XAMAInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXAMAHelper(symbol,
period,
config.length,
config.fastEMA,
config.slowEMA,
config.maShift,
config.appliedTo,
config.showLine);
}
void XSCXAMAHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int length = 52,
//
// Fast EMA Length ...
int fastEMA = 2,
//
// Slow EMA Length ...
int slowEMA = 30,
//
// Shift ...
int maShift = 0,
//
// Applied To ...
ENUM_APPLIED_PRICE appliedTo = PRICE_LOW,
//
// Presentation ...
//
// Show Line ...
bool showLine = true
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mLength = length;
mFastEMA = fastEMA;
mSlowEMA = slowEMA;
mMaShift = maShift;
mShowLine = showLine;
mAppliedTo = appliedTo;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXAMAHelper()
{
}
//
// START Properties ...
//
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XAMA" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mLength >= 2)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xama",
//
// Inputs ...
//
// Makret ...
"",
//
// Length ...
mLength,
//
// Fast EMA Length ...
mFastEMA,
//
// Slow EMA Length ...
mSlowEMA,
//
// Shift ...
mMaShift,
//
// Applied To ...
mAppliedTo,
//
// Presentation ...
"",
//
// Show Line ...
mShowLine
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XAMAInputs GetConfig()
{
//
XAMAInputs result;
//
result.length = mLength;
result.fastEMA = mFastEMA;
result.slowEMA = mSlowEMA;
result.maShift = mMaShift;
result.appliedTo = mAppliedTo;
result.showLine = mShowLine;
//
return result;
}
//
// Set Config ...
bool SetConfig(XAMAInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mFastEMA = config.fastEMA;
mSlowEMA = config.slowEMA;
mMaShift = config.maShift;
mAppliedTo = config.appliedTo;
mShowLine = config.showLine;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// VALUE ...
ArraySetAsSeries(valueBuffer, true);
CopyBuffer(
mHandler,
XAMA_LINE,
barIndex,
mLoopbackBars,
valueBuffer);
//
// STATE ...
ArraySetAsSeries(stateBuffer, true);
CopyBuffer(
mHandler,
XAMA_STATE_LINE,
barIndex,
mLoopbackBars,
stateBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XAMAInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XAMAInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
result.value = valueBuffer[barIndex];
//
ENUM_XAMA_STATES state = (ENUM_XAMA_STATES)stateBuffer[barIndex];
ENUM_XAMA_STATES prevState = (ENUM_XAMA_STATES)stateBuffer[barIndex + 1];
result.state = state;
//
result.isBullish = state == X_XAMA_BULLISH;
result.isBearish = state == X_XAMA_BEARISH;
result.isNeutural = state == X_XAMA_NEUTURAL;
//
result.isSwitchedBullish =
state == X_XAMA_BULLISH && prevState != X_XAMA_BULLISH;
result.isSwitchedBearish =
state == X_XAMA_BEARISH && prevState != X_XAMA_BEARISH;
result.isSwitchedNeutural =
state == X_XAMA_NEUTURAL && prevState != X_XAMA_NEUTURAL;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int mLength;
//
// Fast EMA Length ...
int mFastEMA;
//
// Slow EMA Length ...
int mSlowEMA;
//
// Shift ...
int mMaShift;
//
// Applied To ...
ENUM_APPLIED_PRICE mAppliedTo;
//
// Presentation ...
//
// Show Line ...
bool mShowLine;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,330 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCCHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
struct XCCInputs
{
//
// Chart Style ...
color upColor; // Up Color
color downColor; // Down Color
color lineColor; // Line mode and Doji candlestick Color
color bearishColor; // Bullish Color
color bullishColor; // Bearish Color
color volumesColor; // Volumes Color
//
// Presentation ...
bool showCandles; // Show Candles
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXCCHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Constructor ...
void XSCXCCHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XCCInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXCCHelper(symbol,
period,
config.upColor,
config.downColor,
config.lineColor,
config.bearishColor,
config.bullishColor,
config.volumesColor,
config.showCandles);
}
void XSCXCCHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Chart Style ...
//
// Up Color ...
color upColor = clrLime,
//
// Down Color ...
color downColor = clrRed,
//
// Line mode and Doji candlestick Color ...
color lineColor = clrLime,
//
// Bearish Color ...
color bearishColor = clrRed,
//
// Bullish Color ...
color bullishColor = clrLime,
//
// Volumes Color ...
color volumesColor = clrGreen,
//
// Presentations ...
//
// Show Candles ...
bool showCandles = false
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mUpColor = upColor;
mDownColor = downColor;
mLineColor = lineColor;
mBearishColor = bearishColor;
mBullishColor = bullishColor;
mVolumesColor = volumesColor;
mShowCandles = showCandles;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXCCHelper()
{
}
//
// START Properties ...
//
//
// Show Candles ...
bool ShowCandles(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowCandles == show)
{
return true;
}
//
mShowCandles = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XCC" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xcc",
//
// Inputs ...
//
// Chart Style ...
"",
//
// Up Color ...
mUpColor,
//
// Down Color ...
mDownColor,
//
// Line mode and Doji candlestick Color ...
mLineColor,
//
// Bullish Color ...
mBearishColor,
//
// Bearish Color ...
mBullishColor,
//
// Volumes Color ...
mVolumesColor,
//
// Presentation ...
"",
//
// Show Candles ...
mShowCandles
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XCCInputs GetConfig()
{
//
XCCInputs result;
//
result.upColor = mUpColor;
result.downColor = mDownColor;
result.lineColor = mLineColor;
result.bearishColor = mBearishColor;
result.bullishColor = mBullishColor;
result.volumesColor = mVolumesColor;
result.showCandles = mShowCandles;
//
return result;
}
//
// Set Config ...
bool SetConfig(XCCInputs &config)
{
//
bool result = false;
//
mUpColor = config.upColor;
mDownColor = config.downColor;
mLineColor = config.lineColor;
mBearishColor = config.bearishColor;
mBullishColor = config.bullishColor;
mVolumesColor = config.volumesColor;
mShowCandles = config.showCandles;
//
result = Init();
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Chart Style ...
//
// Up Color ...
color mUpColor;
//
// Down Color ...
color mDownColor;
//
// Line mode and Doji candlestick Color ...
color mLineColor;
//
// Bullish Color ...
color mBearishColor;
//
// Bearish Color ...
color mBullishColor;
//
// Volumes Color ...
color mVolumesColor;
//
// Presentation ...
//
// Show Candles ...
bool mShowCandles;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,648 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCHEHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XCHEInputs
{
//
// Market ...
int length; // Length
int loopback; // Loopback
double multiplier1; // 1st Multiplier
double multiplier2; // 2nd Multiplier
//
// Calculation ...
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to
//
// Presentation ...
bool showLongExit1Line; // Show 1st Long Exit
bool showShortExit1Line; // Show 1st Short Exit
bool showLongExit2Line; // Show 2st Long Exit
bool showShortExit2Line; // Show 2st Short Exit
};
//
// Index of Lines ...
enum ENUM_XCHE_BUFFERS
{
//
// Main Requirements ...
XCHE_1ST_LONG_EXIT_LINE = 0,
XCHE_1ST_SHORT_EXIT_LINE = 1,
XCHE_2ND_LONG_EXIT_LINE = 2,
XCHE_2ND_SHORT_EXIT_LINE = 3,
};
//
// Retrieve Info Model ...
struct XCHEInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double longExit1;
double longExit2;
double shortExit1;
double shortExit2;
//
// Conditions ...
//
bool isLongExit1Start;
bool isShortExit1Start;
//
bool isLongExit2Start;
bool isShortExit2Start;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXCHEHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double longExit1Buffer[];
double shortExit1Buffer[];
double longExit2Buffer[];
double shortExit2Buffer[];
//
// Constructor ...
void XSCXCHEHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XCHEInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXCHEHelper(symbol,
period,
config.length,
config.loopback,
config.multiplier1,
config.multiplier2,
config.upAppliedTo,
config.downAppliedTo,
config.showLongExit1Line,
config.showShortExit1Line,
config.showLongExit2Line,
config.showShortExit2Line);
}
void XSCXCHEHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int length = 35,
//
// Loopback ...
int loopback = 26,
//
// 1st Multiplier ...
double multiplier1 = 3.0,
//
// 2nd Multiplier ...
double multiplier2 = 3.5,
//
// Calculation ...
//
// Up Zone Applied to ...
ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH,
//
// Down Zone Applied to ...
ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW,
//
// Presentation ...
//
// Show 1st Long Exit ...
bool showLongExit1Line = true,
//
// Show 1st Short Exit ...
bool showShortExit1Line = true,
//
// Show 2st Long Exit ...
bool showLongExit2Line = true,
//
// Show 2st Short Exit ...
bool showShortExit2Line = true
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mLength = length;
mLoopback = loopback;
mMultiplier1 = multiplier1;
mMultiplier2 = multiplier2;
mUpAppliedTo = upAppliedTo;
mDownAppliedTo = downAppliedTo;
mShowLongExit1Line = showLongExit1Line;
mShowShortExit1Line = showShortExit1Line;
mShowLongExit2Line = showLongExit2Line;
mShowShortExit2Line = showShortExit2Line;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXCHEHelper()
{
}
//
// START Properties ...
//
//
// Show 1st Long Exit ...
bool ShowLongExit1Line(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowLongExit1Line == show)
{
return true;
}
//
mShowLongExit1Line = show;
result = Init();
//
return result;
}
//
// Show 1st Short Exit ...
bool ShowShortExit1Line(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowShortExit1Line == show)
{
return true;
}
//
mShowShortExit1Line = show;
result = Init();
//
return result;
}
//
// Show 2st Long Exit ...
bool ShowLongExit2Line(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowLongExit2Line == show)
{
return true;
}
//
mShowLongExit2Line = show;
result = Init();
//
return result;
}
//
// Show 2st Short Exit ...
bool ShowShortExit2Line(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowShortExit1Line == show)
{
return true;
}
//
mShowShortExit1Line = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XCHE" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Inputs ...
//
//
result =
mLength >= 9 &&
mLoopback >= 0;
if (!result)
{
return result;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xche",
//
// Inputs ...
//
// Market ...
"",
//
// Length ...
mLength,
//
// Loopback ...
mLoopback,
//
// 1st Multiplier ...
mMultiplier1,
//
// 2nd Multiplier ...
mMultiplier2,
//
// Calculation ...
"",
//
// Up Zone Applied to ...
mUpAppliedTo,
//
// Down Zone Applied to ...
mDownAppliedTo,
//
// Presentation ...
"",
//
// Show 1st Long Exit ...
mShowLongExit1Line,
//
// Show 1st Short Exit ...
mShowShortExit1Line,
//
// Show 2st Long Exit ...
mShowLongExit2Line,
//
// Show 2st Short Exit ...
mShowShortExit2Line
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XCHEInputs GetConfig()
{
//
XCHEInputs result;
//
result.length = mLength;
result.loopback = mLoopback;
result.multiplier1 = mMultiplier1;
result.multiplier2 = mMultiplier2;
result.upAppliedTo = mUpAppliedTo;
result.downAppliedTo = mDownAppliedTo;
result.showLongExit1Line = mShowLongExit1Line;
result.showShortExit1Line = mShowShortExit1Line;
result.showLongExit2Line = mShowLongExit2Line;
result.showShortExit2Line = mShowShortExit2Line;
//
return result;
}
//
// Set Config ...
bool SetConfig(XCHEInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mLoopback = config.loopback;
mMultiplier1 = config.multiplier1;
mMultiplier2 = config.multiplier2;
mUpAppliedTo = config.upAppliedTo;
mDownAppliedTo = config.downAppliedTo;
mShowLongExit1Line = config.showLongExit1Line;
mShowShortExit1Line = config.showShortExit1Line;
mShowLongExit2Line = config.showLongExit2Line;
mShowShortExit2Line = config.showShortExit2Line;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// LEVEL 1 ..
//
// LONG Exit ...
ArraySetAsSeries(longExit1Buffer, true);
CopyBuffer(
mHandler,
XCHE_1ST_LONG_EXIT_LINE,
barIndex,
mLoopbackBars,
longExit1Buffer);
//
// SHORT Exit ...
ArraySetAsSeries(shortExit1Buffer, true);
CopyBuffer(
mHandler,
XCHE_1ST_SHORT_EXIT_LINE,
barIndex,
mLoopbackBars,
shortExit1Buffer);
//
// LEVEL 2 ..
//
// LONG Exit ...
ArraySetAsSeries(longExit2Buffer, true);
CopyBuffer(
mHandler,
XCHE_2ND_LONG_EXIT_LINE,
barIndex,
mLoopbackBars,
longExit2Buffer);
//
// SHORT Exit ...
ArraySetAsSeries(shortExit2Buffer, true);
CopyBuffer(
mHandler,
XCHE_2ND_SHORT_EXIT_LINE,
barIndex,
mLoopbackBars,
shortExit2Buffer);
}
//
// Retrieve Info at Specific Bar Index ...
XCHEInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XCHEInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
double longExit1 = longExit1Buffer[barIndex];
double longExit1Prev = longExit1Buffer[barIndex + 1];
double shortExit1 = shortExit1Buffer[barIndex];
double shortExit1Prev = shortExit1Buffer[barIndex + 1];
//
double longExit2 = longExit2Buffer[barIndex];
double longExit2Prev = longExit2Buffer[barIndex + 1];
double shortExit2 = shortExit2Buffer[barIndex];
double shortExit2Prev = shortExit2Buffer[barIndex + 1];
//
result.longExit1 = longExit1;
result.shortExit1 = shortExit1;
result.longExit2 = longExit2;
result.shortExit2 = shortExit2;
//
result.isLongExit1Start =
longExit1 != EMPTY_VALUE &&
longExit1Prev == EMPTY_VALUE;
//
result.isShortExit1Start =
shortExit1 != EMPTY_VALUE &&
shortExit1Prev == EMPTY_VALUE;
//
result.isLongExit2Start =
longExit2 != EMPTY_VALUE &&
longExit2Prev == EMPTY_VALUE;
//
result.isShortExit2Start =
shortExit2 != EMPTY_VALUE &&
shortExit2Prev == EMPTY_VALUE;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int mLength;
//
// Loopback ...
int mLoopback;
//
// 1st Multiplier ...
double mMultiplier1;
//
// 2nd Multiplier ...
double mMultiplier2;
//
// Calculation ...
//
// Up Zone Applied to ...
ENUM_APPLIED_PRICE mUpAppliedTo;
//
// Down Zone Applied to ...
ENUM_APPLIED_PRICE mDownAppliedTo;
//
// Presentation ...
//
// Show 1st Long Exit ...
bool mShowLongExit1Line;
//
// Show 1st Short Exit ...
bool mShowShortExit1Line;
//
// Show 2st Long Exit ...
bool mShowLongExit2Line;
//
// Show 2st Short Exit ...
bool mShowShortExit2Line;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,432 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXHKHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XHKInputs
{
//
// Presentation ...
bool drawCandles; // Draw Hiken Ashi Candle
bool drawCandleLines; // Show HikenAshi Lines
};
//
// Index of Lines ...
enum ENUM_XHK_BUFFERS
{
//
// Main Requirements ...
XHK_OPEN_LINE = 0,
XHK_HIGH_LINE = 1,
XHK_LOW_LINE = 2,
XHK_CLOSE_LINE = 3,
};
//
// Retrieve Info Model ...
struct XHKInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double open;
double high;
double low;
double close;
//
// Conditions ...
//
// Detect Candle is Bullish or not ...
bool isBullish;
//
// Detect Candle is Bearish or not ...
bool isBearish;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXHKHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double openBuffer[];
double highBuffer[];
double lowBuffer[];
double closeBuffer[];
//
// Constructor ...
void XSCXHKHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XHKInputs &config // Indicator Properties ...
//
) : XSCBaseHelper(symbol, period)
{
//
XSCXHKHelper(symbol,
period,
config.drawCandles,
config.drawCandleLines);
}
void XSCXHKHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Presentation ...
//
// Draw Hiken Ashi Candle ...
bool drawCandles = true,
//
// Show HikenAshi Lines ...
bool drawCandleLines = false
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mDrawCandles = drawCandles;
mDrawCandleLines = drawCandleLines;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXHKHelper()
{
}
//
// START Properties ...
//
//
// Draw Candles ...
bool DrawCandles(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mDrawCandles == show)
{
return true;
}
//
mDrawCandles = show;
result = Init();
//
return result;
}
//
// Show HikenAshi Lines ...
bool DrawCandleLines(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mDrawCandleLines == show)
{
return true;
}
//
mDrawCandleLines = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XHK" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xhk",
//
// Inputs ...
//
// Presentation ...
"",
//
// Draw Hiken Ashi Candle ...
mDrawCandles,
//
// Show HikenAshi Lines ...
mDrawCandleLines
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XHKInputs GetConfig()
{
//
XHKInputs result;
//
result.drawCandles = mDrawCandles;
result.drawCandleLines = mDrawCandleLines;
//
return result;
}
//
// Set Config ...
bool SetConfig(XHKInputs &config)
{
//
bool result = false;
//
mDrawCandles = config.drawCandles;
mDrawCandleLines = config.drawCandleLines;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// OPEN ...
ArraySetAsSeries(openBuffer, true);
CopyBuffer(
mHandler,
XHK_OPEN_LINE,
barIndex,
mLoopbackBars,
openBuffer);
//
// HIGH ...
ArraySetAsSeries(highBuffer, true);
CopyBuffer(
mHandler,
XHK_HIGH_LINE,
barIndex,
mLoopbackBars,
highBuffer);
//
// LOW ...
ArraySetAsSeries(lowBuffer, true);
CopyBuffer(
mHandler,
XHK_LOW_LINE,
barIndex,
mLoopbackBars,
lowBuffer);
//
// CLOSE ...
ArraySetAsSeries(closeBuffer, true);
CopyBuffer(
mHandler,
XHK_CLOSE_LINE,
barIndex,
mLoopbackBars,
closeBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XHKInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XHKInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
double open = openBuffer[barIndex];
double high = highBuffer[barIndex];
double low = lowBuffer[barIndex];
double close = closeBuffer[barIndex];
//
result.open = open;
result.high = high;
result.low = low;
result.close = close;
//
result.isBullish = open < close;
result.isBearish = open >= close;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Presentation ...
//
// Draw Hiken Ashi Candle ...
bool mDrawCandles;
//
// Show HikenAshi Lines ...
bool mDrawCandleLines;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,565 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXHULLHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XHULLInputs
{
//
// Market ...
int length; // Length
double divisor; // Divisor (Speed)
//
// Calculation ...
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to
//
// Presentation ...
bool showUpZone; // Show Up Zone
bool showDownZone; // Show Down Zone
};
//
// Index of Lines ...
enum ENUM_XHULL_BUFFERS
{
//
// Main Requirements ...
XHULL_UP_ZONE_LINE = 0,
XHULL_UP_ZONE_STATE_LINE = 1,
XHULL_DOWN_ZONE_LINE = 2,
XHULL_DOWN_ZONE_STATE_LINE = 3,
};
//
// Hull States ...
enum XHULL_ZONE_STATES
{
XHULL_STATE_NEUTURAL = 0,
XHULL_STATE_BULLISH = 1,
XHULL_STATE_BEARISH = 2
};
//
// Retrieve Info Model ...
struct XHULLInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double up;
XHULL_ZONE_STATES upState;
double down;
XHULL_ZONE_STATES downState;
//
// Conditions ...
//
bool isUpBullish;
bool isUpNeutural;
bool isUpBearish;
//
bool isUpSwitchedToBullish;
bool isUpSwitchedToBearish;
bool isUpSwitchedToNeutural;
//
bool isDownBullish;
bool isDownBearish;
bool isDownNeutural;
//
bool isDownSwitchedToBullish;
bool isDownSwitchedToBearish;
bool isDownSwitchedToNeutural;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXHULLHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double upBuffer[];
double upStateBuffer[];
double downBuffer[];
double downStateBuffer[];
//
// Constructor ...
void XSCXHULLHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XHULLInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXHULLHelper(symbol,
period,
config.length,
config.divisor,
config.upAppliedTo,
config.downAppliedTo,
config.showUpZone,
config.showDownZone);
}
void XSCXHULLHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int length = 72,
//
// Divisor (Speed) ...
double divisor = 2.0,
//
// Calculation ...
//
// Up Zone Applied to ...
ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH,
//
// Down Zone Applied to ...
ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW,
//
// Presentation ...
//
// Show Up Zone ...
bool showUpZone = true,
//
// Show Down Zone ...
bool showDownZone = true
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mLength = length;
mDivisor = divisor;
mUpAppliedTo = upAppliedTo;
mDownAppliedTo = downAppliedTo;
mShowUpZone = showUpZone;
mShowDownZone = showDownZone;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXHULLHelper()
{
}
//
// START Properties ...
//
//
// Show Up Zone ...
bool ShowUpZone(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowUpZone == show)
{
return true;
}
//
mShowUpZone = show;
result = Init();
//
return result;
}
//
// Show Down Zone ...
bool ShowDownZone(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowDownZone == show)
{
return true;
}
//
mShowDownZone = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XHULL" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Inputs ...
//
result =
mLength >= 9 &&
mDivisor >= 0.5;
if (!result)
{
return result;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xhull",
//
// Inputs ...
//
// Market ...
"",
//
// Length ...
mLength,
//
// Divisor (Speed) ...
mDivisor,
//
// Calculation ...
"",
//
// Up Zone Applied to ...
mUpAppliedTo,
//
// Down Zone Applied to ...
mDownAppliedTo,
//
// Presentation ...
"",
//
// Show Up Zone ...
mShowUpZone,
//
// Show Down Zone ...
mShowDownZone
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XHULLInputs GetConfig()
{
//
XHULLInputs result;
//
result.length = mLength;
result.divisor = mDivisor;
result.upAppliedTo = mUpAppliedTo;
result.downAppliedTo = mDownAppliedTo;
result.showUpZone = mShowUpZone;
result.showDownZone = mShowDownZone;
//
return result;
}
//
// Set Config ...
bool SetConfig(XHULLInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mDivisor = config.divisor;
mUpAppliedTo = config.upAppliedTo;
mDownAppliedTo = config.downAppliedTo;
mShowUpZone = config.showUpZone;
mShowDownZone = config.showDownZone;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// UP ...
ArraySetAsSeries(upBuffer, true);
CopyBuffer(
mHandler,
XHULL_UP_ZONE_LINE,
barIndex,
mLoopbackBars,
upBuffer);
//
// UP State ...
ArraySetAsSeries(upStateBuffer, true);
CopyBuffer(
mHandler,
XHULL_UP_ZONE_STATE_LINE,
barIndex,
mLoopbackBars,
upStateBuffer);
//
// DOWN ...
ArraySetAsSeries(downBuffer, true);
CopyBuffer(
mHandler,
XHULL_DOWN_ZONE_LINE,
barIndex,
mLoopbackBars,
downBuffer);
//
// DOWN State ...
ArraySetAsSeries(downStateBuffer, true);
CopyBuffer(
mHandler,
XHULL_DOWN_ZONE_STATE_LINE,
barIndex,
mLoopbackBars,
downStateBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XHULLInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XHULLInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
double up = upBuffer[barIndex];
XHULL_ZONE_STATES upState = (XHULL_ZONE_STATES)upStateBuffer[barIndex];
XHULL_ZONE_STATES upStatePrev = (XHULL_ZONE_STATES)upStateBuffer[barIndex + 1];
//
double down = downBuffer[barIndex];
XHULL_ZONE_STATES downState = (XHULL_ZONE_STATES)downStateBuffer[barIndex];
XHULL_ZONE_STATES downStatePrev = (XHULL_ZONE_STATES)downStateBuffer[barIndex + 1];
//
result.up = up;
result.upState = upState;
result.down = down;
result.downState = downState;
//
result.isUpBullish = upState = XHULL_STATE_BULLISH;
result.isUpBearish = upState = XHULL_STATE_BEARISH;
result.isUpNeutural = upState = XHULL_STATE_NEUTURAL;
//
result.isUpSwitchedToBullish = upState == XHULL_STATE_BULLISH &&
upStatePrev != XHULL_STATE_BULLISH;
result.isUpSwitchedToBearish = upState == XHULL_STATE_BEARISH &&
upStatePrev != XHULL_STATE_BEARISH;
result.isUpSwitchedToNeutural = upState == XHULL_STATE_NEUTURAL &&
upStatePrev != XHULL_STATE_NEUTURAL;
//
result.isDownBullish = downState = XHULL_STATE_BULLISH;
result.isDownBearish = downState = XHULL_STATE_BEARISH;
result.isDownNeutural = downState = XHULL_STATE_NEUTURAL;
//
result.isDownSwitchedToBullish = downState == XHULL_STATE_BULLISH &&
downStatePrev != XHULL_STATE_BULLISH;
result.isDownSwitchedToBearish = downState == XHULL_STATE_BEARISH &&
downStatePrev != XHULL_STATE_BEARISH;
result.isDownSwitchedToNeutural = downState == XHULL_STATE_NEUTURAL &&
downStatePrev != XHULL_STATE_NEUTURAL;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int mLength;
//
// Divisor (Speed) ...
double mDivisor;
//
// Calculation ...
//
// Up Zone Applied to ...
ENUM_APPLIED_PRICE mUpAppliedTo;
//
// Down Zone Applied to ...
ENUM_APPLIED_PRICE mDownAppliedTo;
//
// Presentation ...
//
// Show Up Zone ...
bool mShowUpZone;
//
// Show Down Zone ...
bool mShowDownZone;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,908 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXMRBHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XMRBInputs
{
//
// Ribbon 1 ...
int fast1Length; // Fast
int slow1Length; // Slow
//
// Ribbon 2 ...
int fast2Length; // Fast
int slow2Length; // Slow
//
// Ribbon 3 ...
int fast3Length; // Fast
int slow3Length; // Slow
//
// Ribbon 4 ...
int fast4Length; // Fast
int slow4Length; // Slow
//
// Ribbon 5 ...
int fast5Length; // Fast
int slow5Length; // Slow
//
// Calculation ...
ENUM_MA_METHOD ribbonMode; // Mode
ENUM_APPLIED_PRICE ribbonAppliedTo; // Applied To
//
// Presentation ...
bool showFastMa; // Show Fast
bool showSlowMa; // Show Slow
bool showRibbon; // Show Ribbon
};
//
// Index of Lines ...
enum ENUM_XMRB_BUFFERS
{
//
// Main Requirements ...
XMRB_FAST_LINE = 0,
XMRB_SLOW_LINE = 1,
//
// RIBBON 1 ...
XMRB_R1_FAST_LINE = 2,
XMRB_R1_SLOW_LINE = 3,
//
// RIBBON 2 ...
XMRB_R2_FAST_LINE = 4,
XMRB_R2_SLOW_LINE = 5,
//
// RIBBON 3 ...
XMRB_R3_FAST_LINE = 6,
XMRB_R3_SLOW_LINE = 7,
//
// RIBBON 4 ...
XMRB_R4_FAST_LINE = 8,
XMRB_R4_SLOW_LINE = 9,
//
// RIBBON 5 ...
XMRB_R5_FAST_LINE = 10,
XMRB_R5_SLOW_LINE = 11,
};
//
// Retrieve Info Model ...
struct XMRBInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double fast;
double slow;
double fastR1;
double slowR1;
double fastR2;
double slowR2;
double fastR3;
double slowR3;
double fastR4;
double slowR4;
double fastR5;
double slowR5;
//
// Conditions ...
//
bool isFastOverSlow;
bool isFastCrossedOverSlow;
bool isFastUnderSlow;
bool isFastCrossedUnderSlow;
//
bool isR1FastOverSlow;
bool isR1FastCrossedOverSlow;
bool isR1FastUnderSlow;
bool isR1FastCrossedUnderSlow;
//
bool isR2FastOverSlow;
bool isR2FastCrossedOverSlow;
bool isR2FastUnderSlow;
bool isR2FastCrossedUnderSlow;
//
bool isR3FastOverSlow;
bool isR3FastCrossedOverSlow;
bool isR3FastUnderSlow;
bool isR3FastCrossedUnderSlow;
//
bool isR4FastOverSlow;
bool isR4FastCrossedOverSlow;
bool isR4FastUnderSlow;
bool isR4FastCrossedUnderSlow;
//
bool isR5FastOverSlow;
bool isR5FastCrossedOverSlow;
bool isR5FastUnderSlow;
bool isR5FastCrossedUnderSlow;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXMRBHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double fastBuffer[];
double slowBuffer[];
double fastR1Buffer[];
double slowR1Buffer[];
double fastR2Buffer[];
double slowR2Buffer[];
double fastR3Buffer[];
double slowR3Buffer[];
double fastR4Buffer[];
double slowR4Buffer[];
double fastR5Buffer[];
double slowR5Buffer[];
//
// Constructor ...
void XSCXMRBHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XMRBInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXMRBHelper(symbol,
period,
config.fast1Length,
config.slow1Length,
config.fast2Length,
config.slow2Length,
config.fast3Length,
config.slow3Length,
config.fast4Length,
config.slow4Length,
config.fast5Length,
config.slow5Length,
config.ribbonMode,
config.ribbonAppliedTo,
config.showFastMa,
config.showSlowMa,
config.showRibbon);
}
void XSCXMRBHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Ribbon 1 ...
int fast1Length = 3,
int slow1Length = 5,
//
// Ribbon 2 ...
int fast2Length = 8,
int slow2Length = 13,
//
// Ribbon 3 ...
int fast3Length = 21,
int slow3Length = 34,
//
// Ribbon 4 ...
int fast4Length = 55,
int slow4Length = 89,
//
// Ribbon 5 ...
int fast5Length = 144,
int slow5Length = 233,
//
// Calculation ...
//
// Mode ...
ENUM_MA_METHOD ribbonMode = MODE_EMA,
//
// Applied To ...
ENUM_APPLIED_PRICE ribbonAppliedTo = PRICE_CLOSE,
//
// Presentation ...
//
// Show Fast ...
bool showFastMa = true,
//
// Show Slow ...
bool showSlowMa = true,
//
// Show Ribbon ...
bool showRibbon = false
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mFast1Length = fast1Length;
mSlow1Length = slow1Length;
mFast2Length = fast2Length;
mSlow2Length = slow2Length;
mFast3Length = fast3Length;
mSlow3Length = slow3Length;
mFast4Length = fast4Length;
mSlow4Length = slow4Length;
mFast5Length = fast5Length;
mSlow5Length = slow5Length;
mRibbonMode = ribbonMode;
mRibbonAppliedTo = ribbonAppliedTo;
mShowFastMa = showFastMa;
mShowSlowMa = showSlowMa;
mShowRibbon = showRibbon;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXMRBHelper()
{
}
//
// START Properties ...
//
//
// Show Fast ...
bool ShowFast(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowFastMa == show)
{
return true;
}
//
mShowFastMa = show;
result = Init();
//
return result;
}
//
// Show Slow ...
bool ShowSlow(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowSlowMa == show)
{
return true;
}
//
mShowSlowMa = show;
result = Init();
//
return result;
}
//
// Show Ribbon ...
bool ShowRibbon(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowRibbon == show)
{
return true;
}
//
mShowRibbon = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XMRB" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Inputs ...
result =
//
(mFast1Length > 2 &&
mFast2Length > mFast1Length &&
mFast3Length > mFast2Length &&
mFast4Length > mFast3Length &&
mFast5Length > mFast4Length &&
mSlow1Length > mFast1Length &&
mSlow2Length > mFast2Length &&
mFast3Length > mFast3Length &&
mSlow4Length > mFast4Length &&
mSlow5Length > mFast5Length &&
mSlow2Length > mSlow1Length &&
mFast3Length > mSlow2Length &&
mSlow4Length > mFast3Length &&
mSlow5Length > mSlow4Length
//
)
//
;
if (!result)
{
return result;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xmrb",
//
// Inputs ...
//
// Ribbon 1 ...
"",
mFast1Length,
mSlow1Length,
//
// Ribbon 2 ...
"",
mFast2Length,
mSlow2Length,
//
// Ribbon 3 ...
"",
mFast3Length,
mSlow3Length,
//
// Ribbon 4 ...
"",
mFast4Length,
mSlow4Length,
//
// Ribbon 5 ...
"",
mFast5Length,
mSlow5Length,
//
// Calculation ...
"",
//
// Mode ...
mRibbonMode,
//
// Applied To ...
mRibbonAppliedTo,
//
// Presentation ...
"",
//
// Show Fast ...
mShowFastMa,
//
// Show Slow ...
mShowSlowMa,
//
// Show Ribbon ...
mShowRibbon
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XMRBInputs GetConfig()
{
//
XMRBInputs result;
//
result.fast1Length = mFast1Length;
result.slow1Length = mSlow1Length;
result.fast2Length = mFast2Length;
result.slow2Length = mSlow2Length;
result.fast3Length = mFast3Length;
result.slow3Length = mSlow3Length;
result.fast4Length = mFast4Length;
result.slow4Length = mSlow4Length;
result.fast5Length = mFast5Length;
result.slow5Length = mSlow5Length;
result.ribbonMode = mRibbonMode;
result.ribbonAppliedTo = mRibbonAppliedTo;
result.showFastMa = mShowFastMa;
result.showSlowMa = mShowSlowMa;
result.showRibbon = mShowRibbon;
//
return result;
}
//
// Set Config ...
bool SetConfig(XMRBInputs &config)
{
//
bool result = false;
//
mFast1Length = config.fast1Length;
mSlow1Length = config.slow1Length;
mFast2Length = config.fast2Length;
mSlow2Length = config.slow2Length;
mFast3Length = config.fast3Length;
mSlow3Length = config.slow3Length;
mFast4Length = config.fast4Length;
mSlow4Length = config.slow4Length;
mFast5Length = config.fast5Length;
mSlow5Length = config.slow5Length;
mRibbonMode = config.ribbonMode;
mRibbonAppliedTo = config.ribbonAppliedTo;
mShowFastMa = config.showFastMa;
mShowSlowMa = config.showSlowMa;
mShowRibbon = config.showRibbon;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// FAST ...
ArraySetAsSeries(fastBuffer, true);
CopyBuffer(
mHandler,
XMRB_FAST_LINE,
barIndex,
mLoopbackBars,
fastBuffer);
//
// SLOW ...
ArraySetAsSeries(slowBuffer, true);
CopyBuffer(
mHandler,
XMRB_SLOW_LINE,
barIndex,
mLoopbackBars,
slowBuffer);
//
// RIBBON 1 ...
//
// FAST ...
ArraySetAsSeries(fastR1Buffer, true);
CopyBuffer(
mHandler,
XMRB_R1_FAST_LINE,
barIndex,
mLoopbackBars,
fastR1Buffer);
//
// SLOW ...
ArraySetAsSeries(slowR1Buffer, true);
CopyBuffer(
mHandler,
XMRB_R1_SLOW_LINE,
barIndex,
mLoopbackBars,
slowR1Buffer);
//
// RIBBON 2 ...
//
// FAST ...
ArraySetAsSeries(fastR2Buffer, true);
CopyBuffer(
mHandler,
XMRB_R2_FAST_LINE,
barIndex,
mLoopbackBars,
fastR2Buffer);
//
// SLOW ...
ArraySetAsSeries(slowR2Buffer, true);
CopyBuffer(
mHandler,
XMRB_R2_SLOW_LINE,
barIndex,
mLoopbackBars,
slowR2Buffer);
//
// RIBBON 3 ...
//
// FAST ...
ArraySetAsSeries(fastR3Buffer, true);
CopyBuffer(
mHandler,
XMRB_R3_FAST_LINE,
barIndex,
mLoopbackBars,
fastR3Buffer);
//
// SLOW ...
ArraySetAsSeries(slowR3Buffer, true);
CopyBuffer(
mHandler,
XMRB_R3_SLOW_LINE,
barIndex,
mLoopbackBars,
slowR3Buffer);
//
// RIBBON 4 ...
//
// FAST ...
ArraySetAsSeries(fastR4Buffer, true);
CopyBuffer(
mHandler,
XMRB_R4_FAST_LINE,
barIndex,
mLoopbackBars,
fastR4Buffer);
//
// SLOW ...
ArraySetAsSeries(slowR4Buffer, true);
CopyBuffer(
mHandler,
XMRB_R4_SLOW_LINE,
barIndex,
mLoopbackBars,
slowR4Buffer);
//
// RIBBON 5 ...
//
// FAST ...
ArraySetAsSeries(fastR5Buffer, true);
CopyBuffer(
mHandler,
XMRB_R5_FAST_LINE,
barIndex,
mLoopbackBars,
fastR5Buffer);
//
// SLOW ...
ArraySetAsSeries(slowR5Buffer, true);
CopyBuffer(
mHandler,
XMRB_R5_SLOW_LINE,
barIndex,
mLoopbackBars,
slowR5Buffer);
}
//
// Retrieve Info at Specific Bar Index ...
XMRBInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XMRBInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
double fast = fastBuffer[barIndex];
double fastPrev = fastBuffer[barIndex + 1];
double slow = slowBuffer[barIndex];
double slowPrev = slowBuffer[barIndex + 1];
double fastR1 = fastR1Buffer[barIndex];
double fastR1Prev = fastR1Buffer[barIndex + 1];
double slowR1 = slowR1Buffer[barIndex];
double slowR1Prev = slowR1Buffer[barIndex + 1];
double fastR2 = fastR2Buffer[barIndex];
double fastR2Prev = fastR2Buffer[barIndex + 1];
double slowR2 = slowR2Buffer[barIndex];
double slowR2Prev = slowR2Buffer[barIndex + 1];
double fastR3 = fastR3Buffer[barIndex];
double fastR3Prev = fastR3Buffer[barIndex + 1];
double slowR3 = slowR3Buffer[barIndex];
double slowR3Prev = slowR3Buffer[barIndex + 1];
double fastR4 = fastR4Buffer[barIndex];
double fastR4Prev = fastR4Buffer[barIndex + 1];
double slowR4 = slowR4Buffer[barIndex];
double slowR4Prev = slowR4Buffer[barIndex + 1];
double fastR5 = fastR5Buffer[barIndex];
double fastR5Prev = fastR5Buffer[barIndex + 1];
double slowR5 = slowR5Buffer[barIndex];
double slowR5Prev = slowR5Buffer[barIndex + 1];
//
result.fast = fast;
result.slow = slow;
result.fastR1 = fastR1;
result.slowR1 = slowR1;
result.fastR2 = fastR2;
result.slowR2 = slowR2;
result.fastR3 = fastR3;
result.slowR3 = slowR3;
result.fastR4 = fastR4;
result.slowR4 = slowR4;
result.fastR5 = fastR5;
result.slowR5 = slowR5;
//
result.isFastOverSlow =
fast > slow;
result.isFastCrossedOverSlow =
fast > slow && fastPrev <= slowPrev;
result.isFastUnderSlow =
fast < slow;
result.isFastCrossedUnderSlow =
fast < slow && fastPrev >= slowPrev;
//
result.isR1FastOverSlow =
fastR1 > slowR1;
result.isR1FastCrossedOverSlow =
fastR1 > slowR1 && fastR1Prev <= slowR1Prev;
result.isR1FastUnderSlow =
fastR1 < slowR1;
result.isR1FastCrossedUnderSlow =
fastR1 < slowR1 && fastR1Prev >= slowR1Prev;
//
result.isR2FastOverSlow =
fastR2 > slowR2;
result.isR2FastCrossedOverSlow =
fastR2 > slowR2 && fastR2Prev <= slowR2Prev;
result.isR2FastUnderSlow =
fastR2 < slowR2;
result.isR2FastCrossedUnderSlow =
fastR2 < slowR2 && fastR2Prev >= slowR2Prev;
//
result.isR3FastOverSlow =
fastR3 > slowR3;
result.isR3FastCrossedOverSlow =
fastR3 > slowR3 && fastR3Prev <= slowR3Prev;
result.isR3FastUnderSlow =
fastR3 < slowR3;
result.isR3FastCrossedUnderSlow =
fastR3 < slowR3 && fastR3Prev >= slowR3Prev;
//
result.isR4FastOverSlow =
fastR4 > slowR4;
result.isR4FastCrossedOverSlow =
fastR4 > slowR4 && fastR4Prev <= slowR4Prev;
result.isR4FastUnderSlow =
fastR4 < slowR4;
result.isR4FastCrossedUnderSlow =
fastR4 < slowR4 && fastR4Prev >= slowR4Prev;
//
result.isR5FastOverSlow =
fastR5 > slowR5;
result.isR5FastCrossedOverSlow =
fastR5 > slowR5 && fastR5Prev <= slowR5Prev;
result.isR5FastUnderSlow =
fastR5 < slowR5;
result.isR5FastCrossedUnderSlow =
fastR5 < slowR5 && fastR5Prev >= slowR5Prev;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Ribbon 1 ...
int mFast1Length;
int mSlow1Length;
//
// Ribbon 2 ...
int mFast2Length;
int mSlow2Length;
//
// Ribbon 3 ...
int mFast3Length;
int mSlow3Length;
//
// Ribbon 4 ...
int mFast4Length;
int mSlow4Length;
//
// Ribbon 5 ...
int mFast5Length;
int mSlow5Length;
//
// Calculation ...
//
// Mode ...
ENUM_MA_METHOD mRibbonMode;
//
// Applied To ...
ENUM_APPLIED_PRICE mRibbonAppliedTo;
//
// Presentation ...
//
// Show Fast ...
bool mShowFastMa;
//
// Show Slow ...
bool mShowSlowMa;
//
// Show Ribbon ...
bool mShowRibbon;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,518 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXPVHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XPVInputs
{
//
// Makret Cycles ...
int shortLength; // Short Length
int mediumLength; // Medium Length
int longLength; // Long Length
int hindLength; // Hind Length
//
// Detection Modes ...
ENUM_SERIESMODE hhMode; // Highest High Calculation Method
ENUM_SERIESMODE llMode; // Lowest Low Calculation Method
//
// Presentation ...
bool showPeaksAndVales; // Show Peaks and Vales
bool showLevels; // Show Levels
};
//
// Index of Lines ...
enum ENUM_XPV_BUFFERS
{
//
// Main Requirements ...
XPV_PEAKS_LINE = 0,
XPV_VALES_LINE = 1,
};
//
// Retrieve Info Model ...
struct XPVInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double peak;
double vale;
//
// Conditions ...
//
// Determines New Peaks Happens ...
bool isNewPeak;
//
// Determines New Vales Happens ...
bool isNewVale;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXPVHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double peaksBuffer[];
double valesBuffer[];
//
// Constructor ...
void XSCXPVHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XPVInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXPVHelper(symbol,
period,
config.shortLength,
config.mediumLength,
config.longLength,
config.hindLength,
config.hhMode,
config.llMode,
config.showPeaksAndVales,
config.showLevels);
}
void XSCXPVHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Short Length ...
int shortLength = 9,
//
// Medium Length
int mediumLength = 17,
//
// Long Length ...
int longLength = 26,
//
// Hind Length ...
int hindLength = 35,
//
// Detection Mode ...
//
// Highest High Calculation Method ...
ENUM_SERIESMODE hhMode = MODE_HIGH,
//
// Lowest Low Calculation Method ...
ENUM_SERIESMODE llMode = MODE_LOW,
//
// Presentations ...
//
// Show Peaks and Vales ...
bool showPeaksAndVales = false,
//
// Show Levels ...
bool showLevels = false
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mHHMode = hhMode;
mLLMode = llMode;
mLongLength = longLength;
mHindLength = hindLength;
mShowLevels = showLevels;
mShortLength = shortLength;
mMediumLength = mediumLength;
mShowPeaksAndVales = showPeaksAndVales;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXPVHelper()
{
}
//
// START Properties ...
//
//
// Show Levels ...
bool ShowLevels(
bool show // Show or Hide Levels
)
{
//
bool result = false;
//
if (mShowLevels == show)
{
return true;
}
//
mShowLevels = show;
result = Init();
//
return result;
}
//
// Show Peaks and Vales ...
bool ShowPeaksAnVales(
bool show // Show or Hide Levels
)
{
//
bool result = false;
//
if (mShowPeaksAndVales == show)
{
return true;
}
//
mShowPeaksAndVales = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XPV" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mShortLength > 2 &&
mMediumLength > mShortLength &&
mLongLength > mMediumLength &&
mHindLength > mLongLength)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xpv",
//
// Inputs ...
//
// Market ...
"",
//
// Short Length ...
mShortLength,
//
// Medium Length
mMediumLength,
//
// Long Length ...
mLongLength,
//
// Hind Length ...
mHindLength,
//
// Detection Mode ...
"",
//
// Highest High Calculation Method ...
mHHMode,
//
// Lowest Low Calculation Method ...
mLLMode,
//
// Presentations ...
"",
//
// Show Peaks and Vales ...
mShowPeaksAndVales,
//
// Show Levels ...
mShowLevels
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XPVInputs GetConfig()
{
//
XPVInputs result;
//
result.shortLength = mShortLength;
result.mediumLength = mMediumLength;
result.longLength = mLongLength;
result.hindLength = mHindLength;
result.hhMode = mHHMode;
result.llMode = mLLMode;
result.showPeaksAndVales = mShowPeaksAndVales;
result.showLevels = mShowLevels;
//
return result;
}
//
// Set Config ...
bool SetConfig(XPVInputs &config)
{
//
bool result = false;
//
mShortLength = config.shortLength;
mMediumLength = config.mediumLength;
mLongLength = config.longLength;
mHindLength = config.hindLength;
mHHMode = config.hhMode;
mLLMode = config.llMode;
mShowPeaksAndVales = config.showPeaksAndVales;
mShowLevels = config.showLevels;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// PEAKS ...
ArraySetAsSeries(peaksBuffer, true);
CopyBuffer(
mHandler,
XPV_PEAKS_LINE,
barIndex,
mLoopbackBars,
peaksBuffer);
//
// VALES ...
ArraySetAsSeries(valesBuffer, true);
CopyBuffer(
mHandler,
XPV_VALES_LINE,
barIndex,
mLoopbackBars,
valesBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XPVInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XPVInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
result.peak = peaksBuffer[barIndex];
result.vale = valesBuffer[barIndex];
//
result.isNewPeak =
peaksBuffer[barIndex] != peaksBuffer[barIndex + 1];
result.isNewVale =
valesBuffer[barIndex] != valesBuffer[barIndex + 1];
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Short Length ...
int mShortLength;
//
// Medium Length
int mMediumLength;
//
// Long Length ...
int mLongLength;
//
// Hind Length ...
int mHindLength;
//
// Detection Mode ...
//
// Highest High Calculation Method ...
ENUM_SERIESMODE mHHMode;
//
// Lowest Low Calculation Method ...
ENUM_SERIESMODE mLLMode;
//
// Presentations ...
//
// Show Peaks and Vales ...
bool mShowPeaksAndVales;
//
// Show Levels ...
bool mShowLevels;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,509 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXSSLCHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XSSLCInputs
{
//
// Market ...
int length; // Length
//
// Calculation ...
ENUM_MA_METHOD method; // Method
ENUM_APPLIED_PRICE upAppliedTo; // Up Applied To
ENUM_APPLIED_PRICE downAppliedTo; // Down Applied To
//
// Presentation ...
bool showUp; // Show Up
bool showDown; // Show Down
};
//
// Index of Lines ...
enum ENUM_XSSLC_BUFFERS
{
//
// Main Requirements ...
XSSLC_UP_LINE = 0,
XSSLC_DOWN_LINE = 1,
};
//
// Retrieve Info Model ...
struct XSSLCInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double up;
double down;
//
// Conditions ...
//
// Detect Trend is Bullish or not ...
bool isBullish;
//
// Detect Trend is Switched to Bullish Or not ...
bool isSwitchedBullish;
//
// Detect Trend is Bearish or not ...
bool isBearish;
//
// Detect Trend is Switched to Bearish Or not ...
bool isSwitchedBearish;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXSSLCHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double upBuffer[];
double downBuffer[];
//
// Constructor ...
void XSCXSSLCHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XSSLCInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXSSLCHelper(symbol,
period,
config.length,
config.method,
config.upAppliedTo,
config.downAppliedTo,
config.showUp,
config.showDown);
}
void XSCXSSLCHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int length = 36,
//
// Calculation ...
//
// Method ...
ENUM_MA_METHOD method = MODE_SMA,
//
// Up Applied To ...
ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH,
//
// Down Applied To ...
ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW,
//
// Presentation ...
//
// Show Up ...
bool showUp = true,
//
// Show Down ...
bool showDown = true
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mLength = length;
mMethod = method;
mUpAppliedTo = upAppliedTo;
mDownAppliedTo = downAppliedTo;
//
mShowUp = showUp;
mShowDown = showDown;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXSSLCHelper()
{
}
//
// START Properties ...
//
//
// Show Up ...
bool ShowUp(
bool show // Show or Hide Line
)
{
//
bool result = false;
//
if (mShowUp == show)
{
return true;
}
//
mShowUp = show;
result = Init();
//
return result;
}
//
// Show Down ...
bool ShowDown(
bool show // Show or Hide Line
)
{
//
bool result = false;
//
if (mShowDown == show)
{
return true;
}
//
mShowDown = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XSSLC" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mLength >= 2)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xsslc",
//
// Inputs ...
//
// Market ...
"",
//
// Length ...
mLength,
//
// Calculation ...
"",
//
// Method ...
mMethod,
//
// Up Applied To ...
mUpAppliedTo,
//
// Down Applied To ...
mDownAppliedTo,
//
// Presentation ...
"",
//
// Show Up ...
mShowUp,
//
// Show Down ...
mShowDown
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XSSLCInputs GetConfig()
{
//
XSSLCInputs result;
//
result.length = mLength;
result.method = mMethod;
result.upAppliedTo = mUpAppliedTo;
result.downAppliedTo = mDownAppliedTo;
result.showUp = mShowUp;
result.showDown = mShowDown;
//
return result;
}
//
// Set Config ...
bool SetConfig(XSSLCInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mMethod = config.method;
mUpAppliedTo = config.upAppliedTo;
mDownAppliedTo = config.downAppliedTo;
mShowUp = config.showUp;
mShowDown = config.showDown;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// UP ...
ArraySetAsSeries(upBuffer, true);
CopyBuffer(
mHandler,
XSSLC_UP_LINE,
barIndex,
mLoopbackBars,
upBuffer);
//
// DOWN ...
ArraySetAsSeries(downBuffer, true);
CopyBuffer(
mHandler,
XSSLC_DOWN_LINE,
barIndex,
mLoopbackBars,
downBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XSSLCInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XSSLCInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
double up = upBuffer[barIndex];
double upPrev = upBuffer[barIndex + 1];
double down = downBuffer[barIndex];
double downPrev = downBuffer[barIndex + 1];
//
result.up = up;
result.down = down;
//
result.isBullish = up > down;
result.isBearish = up < down;
//
result.isSwitchedBullish =
up > down &&
upPrev <= downPrev;
result.isSwitchedBearish =
up < down &&
upPrev >= downPrev;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int mLength;
//
// Calculation ...
//
// Method ...
ENUM_MA_METHOD mMethod;
//
// Up Applied To ...
ENUM_APPLIED_PRICE mUpAppliedTo;
//
// Down Applied To ...
ENUM_APPLIED_PRICE mDownAppliedTo;
//
// Presentation ...
//
// Show Up ...
bool mShowUp;
//
// Show Down ...
bool mShowDown;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,468 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXTMHelper
// Description: provides all Indicator
// Helper 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
//
// START Definitions ...
//
//
// Inputs ...
struct XTMInputs
{
//
// Makret ...
int length; // Length
int shift; // Shift
//
// Calculations ...
ENUM_MA_METHOD method; // Method
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Presentation ...
bool showLine; // Show Line
};
//
// Index of Lines ...
enum ENUM_XTM_BUFFERS
{
//
// Main Requirements ...
XTM_LINE = 0,
XTM_STATE_LINE = 1,
};
//
// XTM Indicator States ...
enum ENUM_XTM_STATES
{
X_XTM_BULLISH = 0,
X_XTM_BEARISH = 2,
X_XTM_NEUTURAL = 1,
};
//
// Retrieve Info Model ...
struct XTMInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double value;
//
// State ...
ENUM_XTM_STATES state;
//
// Conditions ...
//
// Detect Trend is Bullish or not ...
bool isBullish;
//
// Detect Trend is Switched to Bullish Or not ...
bool isSwitchedBullish;
//
// Detect Trend is Bearish or not ...
bool isBearish;
//
// Detect Trend is Switched to Bearish Or not ...
bool isSwitchedBearish;
//
// Detect Trend is Neutural or not ...
bool isNeutural;
//
// Detect Trend is Switched to Neutural Or not ...
bool isSwitchedNeutural;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXTMHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double valueBuffer[];
double stateBuffer[];
//
// Constructor ...
void XSCXTMHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XTMInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXTMHelper(symbol,
period,
config.length,
config.shift,
config.method,
config.appliedTo,
config.showLine);
}
void XSCXTMHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int length = 35,
//
// Shift ...
int shift = 0,
//
// Calculations ...
//
// Method ...
ENUM_MA_METHOD method = MODE_SMA,
//
// Applied To ...
ENUM_APPLIED_PRICE appliedTo = PRICE_LOW,
//
// Presentation ...
//
// Show Line ...
bool showLine = true
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mShift = shift;
mLength = length;
mMethod = method;
mShowLine = showLine;
mAppliedTo = appliedTo;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXTMHelper()
{
}
//
// START Properties ...
//
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XTM" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mLength >= 2)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xtm",
//
// Inputs ...
//
// Makret ...
"",
//
// Length ...
mLength,
//
// Shift ...
mShift,
//
// Calculations ...
"",
//
// Method ...
mMethod,
//
// Applied To ...
mAppliedTo,
//
// Presentation ...
"",
//
// Show Line ...
mShowLine
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XTMInputs GetConfig()
{
//
XTMInputs result;
//
result.length = mLength;
result.shift = mShift;
result.method = mMethod;
result.appliedTo = mAppliedTo;
result.showLine = mShowLine;
//
return result;
}
//
// Set Config ...
bool SetConfig(XTMInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mShift = config.shift;
mMethod = config.method;
mAppliedTo = config.appliedTo;
mShowLine = config.showLine;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// VALUE ...
ArraySetAsSeries(valueBuffer, true);
CopyBuffer(
mHandler,
XTM_LINE,
barIndex,
mLoopbackBars,
valueBuffer);
//
// STATE ...
ArraySetAsSeries(stateBuffer, true);
CopyBuffer(
mHandler,
XTM_STATE_LINE,
barIndex,
mLoopbackBars,
stateBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XTMInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XTMInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
result.value = valueBuffer[barIndex];
//
ENUM_XTM_STATES state = (ENUM_XTM_STATES)stateBuffer[barIndex];
ENUM_XTM_STATES prevState = (ENUM_XTM_STATES)stateBuffer[barIndex + 1];
result.state = state;
//
result.isBullish = state == X_XTM_BULLISH;
result.isBearish = state == X_XTM_BEARISH;
result.isNeutural = state == X_XTM_NEUTURAL;
//
result.isSwitchedBullish =
state == X_XTM_BULLISH && prevState != X_XTM_BULLISH;
result.isSwitchedBearish =
state == X_XTM_BEARISH && prevState != X_XTM_BEARISH;
result.isSwitchedNeutural =
state == X_XTM_NEUTURAL && prevState != X_XTM_NEUTURAL;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Makret ...
//
// Length ...
int mLength;
//
// Shift ...
int mShift;
//
// Calculations ...
//
// Method ...
ENUM_MA_METHOD mMethod;
//
// Applied To ...
ENUM_APPLIED_PRICE mAppliedTo;
//
// Presentation ...
//
// Show Line ...
bool mShowLine;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
@@ -0,0 +1,965 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121Provider
// Description: X121 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
//
// START Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Classes/x-saherelm.xprovider.class.mq5"
#include "../Helpers/x-saherelm.x121.xcc.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xhk.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xtm.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xpv.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xama.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xmrb.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xche.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xich.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xtrnd.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xsslc.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xhull.helper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// Here we Have to Define an Input Structure Model
// for Provider Class to Handle Helpers Definitions ...
struct X121ProviderInputs
{
//
// XCC ...
// Candle Styling ...
XCCInputs xccConfig;
//
// XHK ...
// HikenAshi Candle Representing ...
XHKInputs xhkConfig;
//
// XTM ...
// Trend Magic ...
XTMInputs xtmConfig;
//
// XPV ...
// Peaks And Vales ...
XPVInputs xpvConfig;
//
// XAMA ...
// Adaptive Moving Average ...
XAMAInputs xamaConfig;
//
// XMRB ...
// Moving Average Ribbon ...
XMRBInputs xmrbConfig;
//
// XCHE ...
// Chandelier Exit Points ...
XCHEInputs xcheConfig;
//
// XICH ...
// Ichimopku Kinko Hyo ...
XICHInputs xichConfig;
//
// XTRND ...
// Trend Detector ...
XTRNDInputs xtrndConfig;
//
// XSSLC ...
// SSL Channel ...
XSSLCInputs xsslcConfig;
//
// XHULL ...
// Hull Trend Detection Channel ...
XHULLInputs xhullConfig;
};
//
// Model Market Sense based On Current Captured conditions ...
struct X121MarketConditions
{
//
// Commonly Used Info ...
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Check Current Market Condition has Signal or not ...
bool hasSignal;
//
// If has any Signal, Models it's related info here ...
XSignalInfo signal;
//
// INDICATORS Market Sense ...
//
// XCC ...
// there is not any Info provided here ...
//
// XHK ...
XHKInfo xhkInfo;
//
// XTM ...
XTMInfo xtmInfo;
//
// XPV ...
XPVInfo xpvInfo;
//
// XAMA ...
XAMAInfo xamaInfo;
//
// XMRB ...
XMRBInfo xmrbInfo;
//
// XCHE ...
XCHEInfo xcheInfo;
//
// XICH ...
XICHInfo xichInfo;
//
// XTRND ...
XTRNDInfo xtrndInfo;
//
// XSSLC ...
XSSLCInfo xsslcInfo;
//
// XHULL ...
XHULLInfo xhullInfo;
};
//
// Notified a Signal was Appears ...
typedef void (*TOnSignalConditions)(
X121MarketConditions &info);
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Base Class for All of our EA's ...
class XSCX121Provider : public XSCEABaseProvider
{
//
// Public ...
public:
//
// Props ...
X121ProviderInputs providedConfig;
X121ProviderInputs currentConfig;
X121ProviderInputs cleanConfig;
//
// Indicator Helper Classes Instance ...
//
// XCC ...
XSCXCCHelper *mXCCHelper;
//
// XHK ...
XSCXHKHelper *mXHKHelper;
//
// XTM ...
XSCXTMHelper *mXTMHelper;
//
// XPV ...
XSCXPVHelper *mXPVHelper;
//
// XAMA ...
XSCXAMAHelper *mXAMAHelper;
//
// XMRB ...
XSCXMRBHelper *mXMRBHelper;
//
// XCHE ...
XSCXCHEHelper *mXCHEHelper;
//
// XICH ...
XSCXICHHelper *mXICHHelper;
//
// XTRND ...
XSCXTRNDHelper *mXTRNDHelper;
//
// XSSLC ...
XSCXSSLCHelper *mXSSLCHelper;
//
// XHULL ...
XSCXHULLHelper *mXHULLHelper;
//
// Define Helpers ...
//
// Constructor ...
void XSCX121Provider() : XSCEABaseProvider(_Symbol, _Period){};
void XSCX121Provider(
string symbol, // Trading Symbol ...
ENUM_TIMEFRAMES period // Trading Time Frame ...
) : XSCEABaseProvider(symbol, period)
{
//
// Prepare Default and Clean Config ...
// in this Config non of Indicators doesn't Draw anything on chart ...
X121ProviderInputs configs;
//
// XCC ...
// Candle Styling ...
configs.xccConfig.upColor = clrLime;
configs.xccConfig.downColor = clrRed;
configs.xccConfig.lineColor = clrLime;
configs.xccConfig.bearishColor = clrRed;
configs.xccConfig.bullishColor = clrLime;
configs.xccConfig.volumesColor = clrGreen;
configs.xccConfig.showCandles = true;
//
// XHK ...
// HikenAshi Candle Representing ...
configs.xhkConfig.drawCandles = false;
configs.xhkConfig.drawCandleLines = false;
//
// XTM ...
// Trend Magic ...
configs.xtmConfig.length = 35;
configs.xtmConfig.shift = 0;
configs.xtmConfig.method = MODE_SMA;
configs.xtmConfig.appliedTo = PRICE_LOW;
configs.xtmConfig.showLine = false;
//
// XPV ...
// Peaks And Vales ...
configs.xpvConfig.shortLength = 9;
configs.xpvConfig.mediumLength = 17;
configs.xpvConfig.longLength = 26;
configs.xpvConfig.hindLength = 35;
configs.xpvConfig.hhMode = MODE_HIGH;
configs.xpvConfig.llMode = MODE_LOW;
configs.xpvConfig.showPeaksAndVales = false;
configs.xpvConfig.showLevels = false;
//
// XAMA ...
// Adaptive Moving Average ...
configs.xamaConfig.length = 52;
configs.xamaConfig.fastEMA = 2;
configs.xamaConfig.slowEMA = 30;
configs.xamaConfig.maShift = 0;
configs.xamaConfig.appliedTo = PRICE_LOW;
configs.xamaConfig.showLine = false;
//
// XMRB ...
// Moving Average Ribbon ...
configs.xmrbConfig.fast1Length = 3;
configs.xmrbConfig.slow1Length = 5;
configs.xmrbConfig.fast2Length = 8;
configs.xmrbConfig.slow2Length = 13;
configs.xmrbConfig.fast3Length = 21;
configs.xmrbConfig.slow3Length = 34;
configs.xmrbConfig.fast4Length = 55;
configs.xmrbConfig.slow4Length = 89;
configs.xmrbConfig.fast5Length = 144;
configs.xmrbConfig.slow5Length = 233;
configs.xmrbConfig.ribbonMode = MODE_EMA;
configs.xmrbConfig.ribbonAppliedTo = PRICE_CLOSE;
configs.xmrbConfig.showFastMa = false;
configs.xmrbConfig.showSlowMa = false;
configs.xmrbConfig.showRibbon = false;
//
// XCHE ...
// Chandelier Exit Points ...
configs.xcheConfig.length = 35;
configs.xcheConfig.loopback = 26;
configs.xcheConfig.multiplier1 = 3;
configs.xcheConfig.multiplier2 = 3;
configs.xcheConfig.upAppliedTo = PRICE_HIGH;
configs.xcheConfig.downAppliedTo = PRICE_LOW;
configs.xcheConfig.showLongExit1Line = false;
configs.xcheConfig.showShortExit1Line = false;
configs.xcheConfig.showLongExit2Line = false;
configs.xcheConfig.showShortExit2Line = false;
//
// XICH ...
// Ichimopku Kinko Hyo ...
configs.xichConfig.tenkanSenLength = 9;
configs.xichConfig.tenkanSenMode = X_XICH_HH_LL_MODE;
configs.xichConfig.kijunSenLength = 26;
configs.xichConfig.kijunSenMode = X_XICH_HH_LL_MODE;
configs.xichConfig.senkouSpanBLength = 52;
configs.xichConfig.senkouSpanBMode = X_XICH_HH_LL_MODE;
configs.xichConfig.chikuoSpanAppliedTo = PRICE_CLOSE;
configs.xichConfig.showTenkanSen = false;
configs.xichConfig.showKijunSen = false;
configs.xichConfig.showKijunSenPlus = false;
configs.xichConfig.showKijunSenNegative = false;
configs.xichConfig.showChikouSpan = false;
configs.xichConfig.showSenkouSpanA = false;
configs.xichConfig.showSenkouSpanB = false;
configs.xichConfig.showKumo = false;
configs.xichConfig.shiftKumo = true;
//
// XTRND ...
// Trend Detector ...
configs.xtrndConfig.cycleLength = 2;
configs.xtrndConfig.numberOfVerifications = 2;
configs.xtrndConfig.hhMode = MODE_HIGH;
configs.xtrndConfig.llMode = MODE_LOW;
configs.xtrndConfig.l1Method = X_PERIOD_AUTO;
configs.xtrndConfig.l1Period = NULL;
configs.xtrndConfig.l2Method = X_PERIOD_AUTO;
configs.xtrndConfig.l2Period = NULL;
configs.xtrndConfig.l3Method = X_PERIOD_AUTO;
configs.xtrndConfig.l3Period = NULL;
configs.xtrndConfig.showConsolidations = false;
configs.xtrndConfig.showTrend = false;
configs.xtrndConfig.showL1Trend = false;
configs.xtrndConfig.showL2Trend = false;
configs.xtrndConfig.showL3Trend = false;
//
// XSSLC ...
// SSL Channel ...
configs.xsslcConfig.length = 36;
configs.xsslcConfig.method = MODE_SMA;
configs.xsslcConfig.upAppliedTo = PRICE_HIGH;
configs.xsslcConfig.downAppliedTo = PRICE_LOW;
configs.xsslcConfig.showUp = false;
configs.xsslcConfig.showDown = false;
//
// XHULL ...
// Hull Trend Detection Channel ...
configs.xhullConfig.length = 72;
configs.xhullConfig.divisor = 2;
configs.xhullConfig.upAppliedTo = PRICE_HIGH;
configs.xhullConfig.downAppliedTo = PRICE_LOW;
configs.xhullConfig.showUpZone = false;
configs.xhullConfig.showDownZone = false;
//
// Clean Config ...
cleanConfig = configs;
//
XSCX121Provider(symbol, period, configs);
}
void XSCX121Provider(
string symbol, // Trading Symbol ...
ENUM_TIMEFRAMES period, // Trading Time Frame ...
X121ProviderInputs &config // Configs ...
)
{
//
mTag = "X121Provider|" + mSymbol + "," + ToString(mPeriod);
// //
// mCTimerHandler = iCustom(
// mSymbol,
// mPeriod,
// "x-saherelm.x121.xct",
// //
// // Inputs ...
// clrYellow,
// CORNER_RIGHT_LOWER,
// true
// //
// );
//
currentConfig = config;
providedConfig = config;
//
// Here we Have to Make Provided Config in Clean Style ...
PrepareCleanConfig();
}
//
// Deconstructor ...
void ~XSCX121Provider()
{
//
IndicatorRelease(mCTimerHandler);
//
// De construct Helpers ...
delete mXCCHelper;
delete mXHKHelper;
delete mXTMHelper;
delete mXPVHelper;
delete mXAMAHelper;
delete mXMRBHelper;
delete mXCHEHelper;
delete mXICHHelper;
delete mXTRNDHelper;
delete mXSSLCHelper;
delete mXHULLHelper;
}
//
bool Init()
{
//
bool result = false;
//
// Instantiate all Indicators Helper Classes ...
//
// // XCC ...
// mXCCHelper = new XSCXCCHelper(
// mSymbol,
// mPeriod,
// currentConfig.xccConfig);
// result = mXCCHelper.Init();
// if (!result)
// {
// return result;
// }
// //
// // XHK ...
// mXHKHelper = new XSCXHKHelper(
// mSymbol,
// mPeriod,
// currentConfig.xhkConfig);
// result = mXHKHelper.Init();
// if (!result)
// {
// return result;
// };
//
// XTM ...
// mXTMHelper = new XSCXTMHelper(
// mSymbol,
// mPeriod,
// currentConfig.xtmConfig);
// result = mXTMHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XPV ...
// mXPVHelper = new XSCXPVHelper(
// mSymbol,
// mPeriod,
// currentConfig.xpvConfig);
// result = mXPVHelper.Init();
// if (!result)
// {
// LogMessage("XPV Error: ");
// return result;
// };
// //
// // XAMA ...
// mXAMAHelper = new XSCXAMAHelper(
// mSymbol,
// mPeriod,
// currentConfig.xamaConfig);
// result = mXAMAHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XMRB ...
// mXMRBHelper = new XSCXMRBHelper(
// mSymbol,
// mPeriod,
// currentConfig.xmrbConfig);
// result = mXMRBHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XCHE ...
// mXCHEHelper = new XSCXCHEHelper(
// mSymbol,
// mPeriod,
// currentConfig.xcheConfig);
// result = mXCHEHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XICH ...
// mXICHHelper = new XSCXICHHelper(
// mSymbol,
// mPeriod,
// currentConfig.xichConfig);
// result = mXICHHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XTRND ...
// mXTRNDHelper = new XSCXTRNDHelper(
// mSymbol,
// mPeriod,
// currentConfig.xtrndConfig);
// result = mXTRNDHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XSSLC ...
// mXSSLCHelper = new XSCXSSLCHelper(
// mSymbol,
// mPeriod,
// currentConfig.xsslcConfig);
// result = mXSSLCHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XHULL ...
// mXHULLHelper = new XSCXHULLHelper(
// mSymbol,
// mPeriod,
// currentConfig.xhullConfig);
// result = mXHULLHelper.Init();
// if (!result)
// {
// return result;
// };
//
return result;
}
//
virtual void ProcessBuffers()
{
}
//
virtual void ProcessTick()
{
ProcessSignals();
}
//
// Generate Market Sense ...
X121MarketConditions GetMarketConditions(
int barIndex // Specified Bar Index
)
{
//
X121MarketConditions result;
//
// Fill Common Data ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barIndex = barIndex;
//
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
result.barTime = barTime;
//
result.xhkInfo = mXHKHelper.GetInfo(barIndex);
result.xtmInfo = mXTMHelper.GetInfo(barIndex);
result.xpvInfo = mXPVHelper.GetInfo(barIndex);
result.xamaInfo = mXAMAHelper.GetInfo(barIndex);
result.xmrbInfo = mXMRBHelper.GetInfo(barIndex);
result.xcheInfo = mXCHEHelper.GetInfo(barIndex);
result.xichInfo = mXICHHelper.GetInfo(barIndex);
result.xtrndInfo = mXTRNDHelper.GetInfo(barIndex);
result.xsslcInfo = mXSSLCHelper.GetInfo(barIndex);
result.xhullInfo = mXHULLHelper.GetInfo(barIndex);
//
return result;
}
//
// Add Specific On SignalConditions Event Handler ...
int AddOnSignalConditionEventHandler(TOnSignalConditions handler)
{
//
ArrayResize(
mSignalConditionsEventHandlers,
ArraySize(mSignalConditionsEventHandlers) + 1);
//
int result = ArraySize(mSignalConditionsEventHandlers) - 1;
mSignalConditionsEventHandlers[result] = handler;
//
return result;
}
//
// Remove All On Signal Event Handler ...
void ReoveOnSignalEventHandlers()
{
//
ArrayFree(mSignalConditionsEventHandlers);
}
//
// Notify a Signal Found on all Event Listeners ...
void NotifyOnSignalConditionsEvent(X121MarketConditions &info)
{
//
int listenerCount = ArraySize(mSignalConditionsEventHandlers);
if (listenerCount <= 0)
{
return;
}
//
// Loop Through Listeners ...
for (int i = 0; i < listenerCount; i++)
{
//
TOnSignalConditions listener = mSignalConditionsEventHandlers[i];
//
listener(info);
}
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// CCandle Timer ...
int mCTimerHandler;
//
// Signal Event Handlers ...
TOnSignalConditions mSignalConditionsEventHandlers[];
//
// Make Provided Config in Clean Style ...
void PrepareCleanConfig()
{
//
cleanConfig = providedConfig;
//
// XCC ...
// Candle Styling ...
cleanConfig.xccConfig.showCandles = true;
//
// XHK ...
// HikenAshi Candle Representing ...
cleanConfig.xhkConfig.drawCandles = false;
cleanConfig.xhkConfig.drawCandleLines = false;
//
// XTM ...
// Trend Magic ...
cleanConfig.xtmConfig.showLine = false;
//
// XPV ...
// Peaks And Vales ...
cleanConfig.xpvConfig.showPeaksAndVales = false;
cleanConfig.xpvConfig.showLevels = false;
//
// XAMA ...
// Adaptive Moving Average ...
cleanConfig.xamaConfig.showLine = false;
//
// XMRB ...
// Moving Average Ribbon ...
cleanConfig.xmrbConfig.showFastMa = false;
cleanConfig.xmrbConfig.showSlowMa = false;
cleanConfig.xmrbConfig.showRibbon = false;
//
// XCHE ...
// Chandelier Exit Points ...
cleanConfig.xcheConfig.showLongExit1Line = false;
cleanConfig.xcheConfig.showShortExit1Line = false;
cleanConfig.xcheConfig.showLongExit2Line = false;
cleanConfig.xcheConfig.showShortExit2Line = false;
//
// XICH ...
// Ichimopku Kinko Hyo ...
cleanConfig.xichConfig.showTenkanSen = false;
cleanConfig.xichConfig.showKijunSen = false;
cleanConfig.xichConfig.showKijunSenPlus = false;
cleanConfig.xichConfig.showKijunSenNegative = false;
cleanConfig.xichConfig.showChikouSpan = false;
cleanConfig.xichConfig.showSenkouSpanA = false;
cleanConfig.xichConfig.showSenkouSpanB = false;
cleanConfig.xichConfig.showKumo = false;
//
// XTRND ...
// Trend Detector ...
cleanConfig.xtrndConfig.showConsolidations = false;
cleanConfig.xtrndConfig.showTrend = false;
cleanConfig.xtrndConfig.showL1Trend = false;
cleanConfig.xtrndConfig.showL2Trend = false;
cleanConfig.xtrndConfig.showL3Trend = false;
//
// XSSLC ...
// SSL Channel ...
cleanConfig.xsslcConfig.showUp = false;
cleanConfig.xsslcConfig.showDown = false;
//
// XHULL ...
// Hull Trend Detection Channel ...
cleanConfig.xhullConfig.showUpZone = false;
cleanConfig.xhullConfig.showDownZone = false;
}
//
// Here we are Capture Conditions and Check Signals ...
// The Signals Must be Unique for each providers ...
void ProcessSignals()
{
//
X121MarketConditions conditions = GetMarketConditions(1);
//
// BUY ...
//
Clean(conditions.signal);
bool hasLongSignal = HasLongSignal(conditions);
if (hasLongSignal)
{
//
NotifyOnSignalEvent(
conditions.signal);
NotifyOnSignalConditionsEvent(conditions);
mWaitUntilNewCandle = true;
return;
}
//
// SELL ...
//
Clean(conditions.signal);
bool hasShortignal = HasShortSignal(conditions);
if (hasShortignal)
{
//
NotifyOnSignalEvent(
conditions.signal);
NotifyOnSignalConditionsEvent(conditions);
mWaitUntilNewCandle = true;
return;
}
}
//
// Check has Long Signal on Each Strategies ...
bool HasLongSignal(X121MarketConditions &conditions)
{
//
bool result = false;
//
if (result)
{
}
//
return result;
}
//
// Check has Short Signal on Each Strategies ...
bool HasShortSignal(X121MarketConditions &conditions)
{
//
bool result = false;
//
if (result)
{
}
//
return result;
}
};
//
// START Definitions ...
//
//
// Model Signal Providers Definitions ...
struct X121SignalProvider
{
//
// Provider use Which Symbol ...
string symbol;
//
// Provider use Which Time Frame ...
ENUM_TIMEFRAMES period;
//
// Risk Amount Per Trades Related to Time Frames ...
// Percent of Available Balance ...
double riskAmount;
//
// Desired Magic Number ...
ulong magicNumber;
//
// Provider ...
XSCX121Provider provider;
};
//
// END Definitions ...
//
//
// START Usefull Functions ...
//
//
// Add Specific Provider to List ...
void Add(
X121SignalProvider &item, // item want to add
X121SignalProvider &buffer[] // Destination buffer
)
{
//
ArrayResize(
buffer,
ArraySize(buffer) + 1);
//
buffer[ArraySize(buffer) - 1] = item;
}
//
// Generate Identifier Tag ...
string GenerateTag(X121SignalProvider &descriptor)
{
//
string result = "";
//
result = descriptor.symbol + "," + ToString(descriptor.period);
//
return result;
}
//
// END Usefull Functions ...
//
@@ -0,0 +1,262 @@
//+------------------------------------------------------------------+
//| Demo_iIchimoku.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property description "The indicator demonstrates how to obtain data"
#property description "of indicator buffers for the iIchimoku technical indicator."
#property description "A symbol and timeframe used for calculation of the indicator,"
#property description "are set by the symbol and period parameters."
#property description "The method of creation of the handle is set through the 'type' parameter (function type)."
#property description "All other parameters just like in the standard Ichimoku Kinko Hyo."
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 4
//--- the Tenkan_sen plot
#property indicator_label1 "Tenkan_sen"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- the Kijun_sen plot
#property indicator_label2 "Kijun_sen"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- the Senkou_Span plot
#property indicator_label3 "Senkou Span A;Senkou Span B" // two fields will be shown in Data Window
#property indicator_type3 DRAW_FILLING
#property indicator_color3 clrSandyBrown, clrThistle
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- the Chikou_Span plot
#property indicator_label4 "Chinkou_Span"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrLime
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//+------------------------------------------------------------------+
//| Enumeration of the methods of handle creation |
//+------------------------------------------------------------------+
enum Creation
{
Call_iIchimoku, // use iIchimoku
Call_IndicatorCreate // use IndicatorCreate
};
//--- input parameters
input Creation type=Call_iIchimoku; // type of the function
input int tenkan_sen=9; // period of Tenkan-sen
input int kijun_sen=26; // period of Kijun-sen
input int senkou_span_b=52; // period of Senkou Span B
input string symbol=" "; // symbol
input ENUM_TIMEFRAMES period=PERIOD_CURRENT; // timeframe
//--- indicator buffer
double Tenkan_sen_Buffer[];
double Kijun_sen_Buffer[];
double Senkou_Span_A_Buffer[];
double Senkou_Span_B_Buffer[];
double Chinkou_Span_Buffer[];
//--- variable for storing the handle of the iIchimoku indicator
int handle;
//--- variable for storing
string name=symbol;
//--- name of the indicator on a chart
string short_name;
//--- we will keep the number of values in the Ichimoku Kinko Hyo indicator
int bars_calculated=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- assignment of arrays to indicator buffers
SetIndexBuffer(0,Tenkan_sen_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,Kijun_sen_Buffer,INDICATOR_DATA);
SetIndexBuffer(2,Senkou_Span_A_Buffer,INDICATOR_DATA);
SetIndexBuffer(3,Senkou_Span_B_Buffer,INDICATOR_DATA);
SetIndexBuffer(4,Chinkou_Span_Buffer,INDICATOR_DATA);
//--- set the shift for the Senkou Span channel of kijun_sen bars in the future direction
PlotIndexSetInteger(2,PLOT_SHIFT,kijun_sen);
//--- setting a shift for the Chikou Span line is not required, since the Chinkou data Span
//--- is already stored with a shift in iIchimoku
//--- determine the symbol the indicator is drawn for
name=symbol;
//--- delete spaces to the right and to the left
StringTrimRight(name);
StringTrimLeft(name);
//--- if it results in zero length of the 'name' string
if(StringLen(name)==0)
{
//--- take the symbol of the chart the indicator is attached to
name=_Symbol;
}
//--- create handle of the indicator
if(type==Call_iIchimoku)
handle=iIchimoku(name,period,tenkan_sen,kijun_sen,senkou_span_b);
else
{
//--- fill the structure with parameters of the indicator
MqlParam pars[3];
//--- periods and shifts of the Alligator lines
pars[0].type=TYPE_INT;
pars[0].integer_value=tenkan_sen;
pars[1].type=TYPE_INT;
pars[1].integer_value=kijun_sen;
pars[2].type=TYPE_INT;
pars[2].integer_value=senkou_span_b;
//--- create handle
handle=IndicatorCreate(name,period,IND_ICHIMOKU,3,pars);
}
//--- if the handle is not created
if(handle==INVALID_HANDLE)
{
//--- tell about the failure and output the error code
PrintFormat("Failed to create handle of the iIchimoku indicator for the symbol %s/%s, error code %d",
name,
EnumToString(period),
GetLastError());
//--- the indicator is stopped early
return(INIT_FAILED);
}
//--- show the symbol/timeframe the Ichimoku Kinko Hyo indicator is calculated for
short_name=StringFormat("iIchimoku(%s/%s, %d, %d ,%d)",name,EnumToString(period),
tenkan_sen,kijun_sen,senkou_span_b);
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- normal initialization of the indicator
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- number of values copied from the iIchimoku indicator
int values_to_copy;
//--- determine the number of values calculated in the indicator
int calculated=BarsCalculated(handle);
if(calculated<=0)
{
PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
return(0);
}
//--- if it is the first start of calculation of the indicator or if the number of values in the iIchimoku indicator changed
//---or if it is necessary to calculated the indicator for two or more bars (it means something has changed in the price history)
if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1)
{
//--- if the Tenkan_sen_Buffer array is greater than the number of values in the iIchimoku indicator for symbol/period, then we don't copy everything
//--- otherwise, we copy less than the size of indicator buffers
if(calculated>rates_total) values_to_copy=rates_total;
else values_to_copy=calculated;
}
else
{
//--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()
//--- for calculation not more than one bar is added
values_to_copy=(rates_total-prev_calculated)+1;
}
//--- fill the arrays with values of the Ichimoku Kinko Hyo indicator
//--- if FillArraysFromBuffer returns false, it means the information is nor ready yet, quit operation
if(!FillArraysFromBuffers(Tenkan_sen_Buffer,Kijun_sen_Buffer,Senkou_Span_A_Buffer,Senkou_Span_B_Buffer,Chinkou_Span_Buffer,
kijun_sen,handle,values_to_copy)) return(0);
//--- form the message
string comm=StringFormat("%s ==> Updated value in the indicator %s: %d",
TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS),
short_name,
values_to_copy);
//--- display the service message on the chart
Comment(comm);
//--- memorize the number of values in the Ichimoku Kinko Hyo indicator
bars_calculated=calculated;
//--- return the prev_calculated value for the next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Filling indicator buffers from the iIchimoku indicator |
//+------------------------------------------------------------------+
bool FillArraysFromBuffers(double &tenkan_sen_buffer[], // indicator buffer of the Tenkan-sen line
double &kijun_sen_buffer[], // indicator buffer of the Kijun_sen line
double &senkou_span_A_buffer[], // indicator buffer of the Senkou Span A line
double &senkou_span_B_buffer[], // indicator buffer of the Senkou Span B line
double &chinkou_span_buffer[], // indicator buffer of the Chinkou Span line
int senkou_span_shift, // shift of the Senkou Span lines in the future direction
int ind_handle, // handle of the iIchimoku indicator
int amount // number of copied values
)
{
//--- reset error code
ResetLastError();
//--- fill a part of the Tenkan_sen_Buffer array with values from the indicator buffer that has 0 index
if(CopyBuffer(ind_handle,0,0,amount,tenkan_sen_buffer)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("1.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- fill a part of the Kijun_sen_Buffer array with values from the indicator buffer that has index 1
if(CopyBuffer(ind_handle,1,0,amount,kijun_sen_buffer)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("2.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- fill a part of the Chinkou_Span_Buffer array with values from the indicator buffer that has index 2
//--- if senkou_span_shift>0, the line is shifted in the future direction by senkou_span_shift bars
if(CopyBuffer(ind_handle,2,-senkou_span_shift,amount,senkou_span_A_buffer)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("3.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- fill a part of the Senkou_Span_A_Buffer array with values from the indicator buffer that has index 3
//--- if senkou_span_shift>0, the line is shifted in the future direction by senkou_span_shift bars
if(CopyBuffer(ind_handle,3,-senkou_span_shift,amount,senkou_span_B_buffer)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("4.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- fill a part of the Senkou_Span_B_Buffer array with values from the indicator buffer that has 0 index
//--- when copying Chinkou Span, we don't need to consider the shift, since the Chinkou Span data
//--- is already stored with a shift in iIchimoku
if(CopyBuffer(ind_handle,4,0,amount,chinkou_span_buffer)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("5.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- everything is fine
return(true);
}
//+------------------------------------------------------------------+
//| Indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(handle!=INVALID_HANDLE)
IndicatorRelease(handle);
//--- clear the chart after deleting the indicator
Comment("");
}
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,675 @@
//+------------------------------------------------------------------+
//| ATRStopLoss_Ind.mq5 |
//| Rosh Jardine |
//| https://roshjardine.com |
//+------------------------------------------------------------------+
#property copyright "Rosh Jardine (MQL5/MQL4)"
#property link "https://roshjardine.com"
#property version "1.00"
#property description "Based on https://www.mql5.com/en/forum/349885 , this indicator will draw ATR based stop loss calculation with adjustable multiplier and ATR period."
#property description "This indicator includes helper functions and example to run calculation via function call so the calculation logic can be placed in external include file"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_color1 Orchid
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
#property indicator_color2 Blue
#property indicator_label1 "Up"
#property indicator_label2 "Dn"
//---- input parameters
input int Length=10; //how many look back periods to check the price
input int ATRperiod=10;
input double Kv=2.5;
//---- indicator buffers
double UpBuffer1[];
double DnBuffer1[];
double smin[];
double smax[];
double trend[];
int AtrHandle;
double AtrBfr[1];
int bars_calculated;
string short_name;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
bars_calculated = 0;
short_name="ATRStopLoss_Ind";
AtrHandle = iATR(_Symbol,_Period,ATRperiod);
if(AtrHandle==INVALID_HANDLE)
{
return(INIT_FAILED);
}
ArrayInitialize(AtrBfr,EMPTY_VALUE);
SetIndexBuffer(0,UpBuffer1);
SetIndexBuffer(1,DnBuffer1);
SetIndexBuffer(2,smin);
SetIndexBuffer(3,smax);
SetIndexBuffer(4,trend);
IndicatorSetInteger(INDICATOR_DIGITS,Digits());
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,Length);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,Length);
PlotIndexSetInteger(0,PLOT_SHIFT,0);
PlotIndexSetInteger(1,PLOT_SHIFT,0);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int limit;
if(rates_total<=Length)
return(0);
if(prev_calculated<1)
{
/*
int shift;
ArrayInitialize(UpBuffer1,EMPTY_VALUE);
ArrayInitialize(DnBuffer1,EMPTY_VALUE);
ArrayInitialize(smin,EMPTY_VALUE);
ArrayInitialize(smax,EMPTY_VALUE);
ArrayInitialize(trend,EMPTY_VALUE);
ArraySetAsSeries(UpBuffer1,true);
ArraySetAsSeries(DnBuffer1,true);
ArraySetAsSeries(smin,true);
ArraySetAsSeries(smax,true);
ArraySetAsSeries(trend,true);
limit = rates_total-Length-1;
for (shift=limit;shift>=0;shift--)
{
smin[shift] = -100000; smax[shift] = 100000;
for(int i=Length-1;i>=0;i--)
{
int copybuffer = CopyBuffer(AtrHandle,0,shift+i,1,AtrBfr);
if (copybuffer<1)
{
StopIndicator();
}
smin[shift] = MathMax( smin[shift], iHigh(_Symbol,_Period,shift+i) - Kv*AtrBfr[0]);
smax[shift] = MathMin( smax[shift], iLow(_Symbol,_Period,shift+i) + Kv*AtrBfr[0]);
}
trend[shift]= trend[shift+1];
if ( iClose(_Symbol,_Period,shift) > smax[shift+1] )
{
trend[shift] = 1;
}
if ( iClose(_Symbol,_Period,shift) < smin[shift+1] )
{
trend[shift] = -1;
}
if ( trend[shift] >0 )
{
if( smin[shift]<smin[shift+1] ) smin[shift]=smin[shift+1];
UpBuffer1[shift] = smin[shift];
DnBuffer1[shift] = EMPTY_VALUE;
}
if ( trend[shift] <0 )
{
if( smax[shift]>smax[shift+1] ) smax[shift]=smax[shift+1];
UpBuffer1[shift] = EMPTY_VALUE;
DnBuffer1[shift] = smax[shift];
}
}
*/
limit = rates_total-Length-1;
if(!AtrStopFirstRun(limit,UpBuffer1,DnBuffer1,smin,smax,trend,AtrHandle,AtrBfr,Length,_Symbol,_Period,Kv))
{
StopIndicator();
}
bars_calculated = limit;
return(rates_total);
}
else
{
limit=prev_calculated-Length-1;
if(limit>bars_calculated)
{
if(!AtrStopNextRun(bars_calculated+1,UpBuffer1,DnBuffer1,smin,smax,trend,AtrHandle,AtrBfr,Length,_Symbol,_Period,Kv,false))
{
StopIndicator();
}
bars_calculated +=1;
}
else
{
if(!AtrStopNextRun(bars_calculated+1,UpBuffer1,DnBuffer1,smin,smax,trend,AtrHandle,AtrBfr,Length,_Symbol,_Period,Kv,true))
{
StopIndicator();
}
}
/*
if (limit>bars_calculated)
{
ArrayResize(UpBuffer1,bars_calculated+1);
ArrayResize(DnBuffer1,bars_calculated+1);
ArrayResize(smin,bars_calculated+1);
ArrayResize(smax,bars_calculated+1);
ArrayResize(trend,bars_calculated+1);
UpBuffer1[0] = DnBuffer1[0]= smin[0] = smax[0] = trend[0] = EMPTY_VALUE;
bars_calculated +=1;
}
for(int j=0;j<=1;j++)
{
smin[j] = -100000; smax[j] = 100000;
for(int k=0;k<=Length-1;k++)
{
int copybuffer = CopyBuffer(AtrHandle,0,j+k,1,AtrBfr);
if (copybuffer<1)
{
StopIndicator();
}
smin[j] = MathMax( smin[j], iHigh(_Symbol,_Period,j+k) - Kv*AtrBfr[0]);
smax[j] = MathMin( smax[j], iLow(_Symbol,_Period,j+k) + Kv*AtrBfr[0]);
}
trend[j]= trend[j+1];
if ( iClose(_Symbol,_Period,j) > smax[j+1] ) trend[j] = 1;
if ( iClose(_Symbol,_Period,j) < smin[j+1] ) trend[j] = -1;
if ( trend[j] >0 )
{
if( smin[j]<smin[j+1] ) smin[j]=smin[j+1];
UpBuffer1[j] = smin[j];
DnBuffer1[j] = EMPTY_VALUE;
}
if ( trend[j] <0 )
{
if( smax[j]>smax[j+1] ) smax[j]=smax[j+1];
UpBuffer1[j] = EMPTY_VALUE;
DnBuffer1[j] = smax[j];
}
}*/
return(rates_total);
}
}
/************************************ AS HELPERS ************************************/
bool AtrStopNextRun(int newlimit,double &upbfr[],
double &dnbfr[],double &min[],
double &max[],double &trd[],int &atrhandler,
double &atrbuffer[],int atrlength,
const string symbol,ENUM_TIMEFRAMES tframe,
double multiplier,bool samebar)
{
if(!samebar)
{
ArrayResize(upbfr,newlimit);
ArrayResize(dnbfr,newlimit);
ArrayResize(min,newlimit);
ArrayResize(max,newlimit);
ArrayResize(trd,newlimit);
upbfr[0] = dnbfr[0]= min[0] = max[0] = trd[0] = EMPTY_VALUE;
}
else
{
upbfr[0] = dnbfr[0]= min[0] = max[0] = trd[0] = EMPTY_VALUE;
}
for(int j=0; j<=1; j++)
{
min[j] = -100000;
max[j] = 100000;
for(int k=0; k<=atrlength-1; k++)
{
int copybuffer = CopyBuffer(atrhandler,0,j+k,1,atrbuffer);
if(copybuffer<1)
{
return(false);
}
min[j] = MathMax(smin[j], iHigh(symbol,tframe,j+k) - multiplier*AtrBfr[0]);
max[j] = MathMin(smax[j], iLow(symbol,tframe,j+k) + multiplier*AtrBfr[0]);
}
trd[j]= trd[j+1];
if(iClose(symbol,tframe,j) > max[j+1])
{
trd[j] = 1;
}
if(iClose(symbol,tframe,j) < min[j+1])
{
trd[j] = -1;
}
if(trd[j] >0)
{
if(min[j]<min[j+1])
{
min[j] = min[j+1];
}
upbfr[j] = min[j];
dnbfr[j] = EMPTY_VALUE;
}
if(trend[j] <0)
{
if(max[j]>max[j+1])
{
max[j]=max[j+1];
}
upbfr[j] = EMPTY_VALUE;
dnbfr[j] = max[j];
}
}
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool AtrStopFirstRun(int limit,double &upbfr[],
double &dnbfr[],double &min[],
double &max[],double &trd[],int &atrhandler,
double &atrbuffer[],int atrlength,
const string symbol,ENUM_TIMEFRAMES tframe,
double multiplier
)
{
ArrayInitialize(upbfr,EMPTY_VALUE);
ArrayInitialize(dnbfr,EMPTY_VALUE);
ArrayInitialize(min,EMPTY_VALUE);
ArrayInitialize(max,EMPTY_VALUE);
ArrayInitialize(trd,EMPTY_VALUE);
ArraySetAsSeries(upbfr,true);
ArraySetAsSeries(dnbfr,true);
ArraySetAsSeries(min,true);
ArraySetAsSeries(max,true);
ArraySetAsSeries(trd,true);
int shift = 0;
for(shift=limit; shift>=0; shift--)
{
min[shift] = -100000;
max[shift] = 100000;
for(int i=atrlength-1; i>=0; i--)
{
int copybuffer = CopyBuffer(atrhandler,0,shift+i,1,atrbuffer);
if(copybuffer<1)
{
return(false);
}
min[shift] = MathMax(min[shift], iHigh(symbol,tframe,shift+i) - multiplier*atrbuffer[0]);
max[shift] = MathMin(max[shift], iLow(symbol,tframe,shift+i) + multiplier*atrbuffer[0]);
}
trd[shift] = trd[shift+1];
if(iClose(symbol,tframe,shift) > max[shift+1])
{
trd[shift] = 1;
}
if(iClose(symbol,tframe,shift) < min[shift+1])
{
trd[shift] = -1;
}
if(trd[shift] >0)
{
if(min[shift]<min[shift+1])
{
min[shift] = min[shift+1];
}
upbfr[shift] = min[shift];
dnbfr[shift] = EMPTY_VALUE;
}
if(trd[shift] <0)
{
if(max[shift]>max[shift+1])
{
max[shift] = max[shift+1];
}
upbfr[shift] = EMPTY_VALUE;
dnbfr[shift] = max[shift];
}
}
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void StopIndicator()
{
IndicatorRelease(AtrHandle);
ChartIndicatorDelete(ChartID(),0,short_name);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(AtrHandle!=INVALID_HANDLE)
IndicatorRelease(AtrHandle);
}
//---
//--- MQL4
//---
#ifdef __MQL4__
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//---- input parameters
extern int Length=10;
extern int ATRperiod=10;
extern double Kv=2.5;
double UpBuffer1[];
double DnBuffer1[];
double smin[];
double smax[];
double trend[];
double AtrBfr[1];
int bars_calculated;
string short_name;
int OnInit()
{
bars_calculated = 0;
short_name="ATRStopLoss_Ind";
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
IndicatorBuffers(5);
SetIndexBuffer(0,UpBuffer1);
SetIndexBuffer(1,DnBuffer1);
SetIndexBuffer(2,smin);
SetIndexBuffer(3,smax);
SetIndexBuffer(4,trend);
IndicatorShortName(short_name);
SetIndexLabel(0,"Up");
SetIndexLabel(1,"Dn");
SetIndexDrawBegin(0,Length);
SetIndexDrawBegin(1,Length);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int limit;
if(rates_total<=Length)
{
return(0);
}
if(prev_calculated<1)
{
/*
int shift;
ArrayInitialize(UpBuffer1,EMPTY_VALUE);
ArrayInitialize(DnBuffer1,EMPTY_VALUE);
ArrayInitialize(smin,EMPTY_VALUE);
ArrayInitialize(smax,EMPTY_VALUE);
ArrayInitialize(trend,EMPTY_VALUE);
ArraySetAsSeries(UpBuffer1,true);
ArraySetAsSeries(DnBuffer1,true);
ArraySetAsSeries(smin,true);
ArraySetAsSeries(smax,true);
ArraySetAsSeries(trend,true);
limit = rates_total-Length-1;
for (shift=limit;shift>=0;shift--)
{
smin[shift] = -100000;
smax[shift] = 100000;
for(int i=Length-1;i>=0;i--)
{
smin[shift] = MathMax( smin[shift], iHigh(_Symbol,_Period,shift+i) - Kv*iATR(Symbol(),Period(),ATRperiod,shift+i));
smax[shift] = MathMin( smax[shift], iLow(_Symbol,_Period,shift+i) + Kv*iATR(Symbol(),Period(),ATRperiod,shift+i));
}
trend[shift]= trend[shift+1];
if ( iClose(_Symbol,_Period,shift) > smax[shift+1] )
{
trend[shift] = 1;
}
if ( iClose(_Symbol,_Period,shift) < smin[shift+1] )
{
trend[shift] = -1;
}
if ( trend[shift] >0 )
{
if( smin[shift]<smin[shift+1] ) smin[shift]=smin[shift+1];
UpBuffer1[shift] = smin[shift];
DnBuffer1[shift] = EMPTY_VALUE;
}
if ( trend[shift] <0 )
{
if( smax[shift]>smax[shift+1] ) smax[shift]=smax[shift+1];
UpBuffer1[shift] = EMPTY_VALUE;
DnBuffer1[shift] = smax[shift];
}
}
*/
/*** AS FUNCTION CALL EXAMPLE ***/
limit = rates_total-Length-1;
if(!AtrStopFirstRun(limit,UpBuffer1,DnBuffer1,smin,smax,trend,Length,Symbol(),Period(),Kv))
{
return(0);
}
bars_calculated = limit;
return(rates_total);
}
else
{
limit = prev_calculated-Length-1;
/*** AS FUNCTION CALL EXAMPLE ***/
if(limit>bars_calculated)
{
if(!AtrStopNextRun(bars_calculated+1,UpBuffer1,DnBuffer1,smin,smax,trend,Length,Symbol(),Period(),Kv,false))
{
return(0);
}
}
if(!AtrStopNextRun(bars_calculated+1,UpBuffer1,DnBuffer1,smin,smax,trend,Length,Symbol(),Period(),Kv,true))
{
return(0);
}
/*
if (limit>bars_calculated)
{
ArrayResize(UpBuffer1,bars_calculated+1);
ArrayResize(DnBuffer1,bars_calculated+1);
ArrayResize(smin,bars_calculated+1);
ArrayResize(smax,bars_calculated+1);
ArrayResize(trend,bars_calculated+1);
UpBuffer1[0] = DnBuffer1[0]= smin[0] = smax[0] = trend[0] = EMPTY_VALUE;
bars_calculated +=1;
}
for(int j=0;j<=1;j++)
{
smin[j] = -100000;
smax[j] = 100000;
for(int k=0;k<=Length-1;k++)
{
smin[j] = MathMax( smin[j], iHigh(Symbol(),Period(),j+k) - Kv*iATR(Symbol(),Period(),ATRperiod,j+k));
smax[j] = MathMin( smax[j], iLow(Symbol(),Period(),j+k) + Kv*AtrBfr[0]);
}
trend[j]= trend[j+1];
if ( iClose(Symbol(),Period(),j) > smax[j+1] ) trend[j] = 1;
if ( iClose(Symbol(),Period(),j) < smin[j+1] ) trend[j] = -1;
if ( trend[j] >0 )
{
if( smin[j]<smin[j+1] ) smin[j]=smin[j+1];
UpBuffer1[j] = smin[j];
DnBuffer1[j] = EMPTY_VALUE;
}
if ( trend[j] <0 )
{
if( smax[j]>smax[j+1] ) smax[j]=smax[j+1];
UpBuffer1[j] = EMPTY_VALUE;
DnBuffer1[j] = smax[j];
}
}
*/
return(rates_total);
}
}
/************************************ AS HELPERS ************************************/
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool AtrStopFirstRun(int limit,double &upbfr[],
double &dnbfr[],double &min[],
double &max[],double &trd[],int atrlength,
const string symbol,const int tframe,
double multiplier
)
{
ArrayInitialize(upbfr,EMPTY_VALUE);
ArrayInitialize(dnbfr,EMPTY_VALUE);
ArrayInitialize(min,EMPTY_VALUE);
ArrayInitialize(max,EMPTY_VALUE);
ArrayInitialize(trd,EMPTY_VALUE);
ArraySetAsSeries(upbfr,true);
ArraySetAsSeries(dnbfr,true);
ArraySetAsSeries(min,true);
ArraySetAsSeries(max,true);
ArraySetAsSeries(trd,true);
int shift = 0;
for(shift=limit; shift>=0; shift--)
{
min[shift] = -100000;
max[shift] = 100000;
for(int i=atrlength-1; i>=0; i--)
{
min[shift] = MathMax(min[shift], iHigh(symbol,tframe,shift+i) - multiplier*iATR(symbol,tframe,ATRperiod,shift+1));
max[shift] = MathMin(max[shift], iLow(symbol,tframe,shift+i) + multiplier*iATR(symbol,tframe,ATRperiod,shift+1));
}
trd[shift] = trd[shift+1];
if(iClose(symbol,tframe,shift) > max[shift+1])
{
trd[shift] = 1;
}
if(iClose(symbol,tframe,shift) < min[shift+1])
{
trd[shift] = -1;
}
if(trd[shift] >0)
{
if(min[shift]<min[shift+1])
{
min[shift] = min[shift+1];
}
upbfr[shift] = min[shift];
dnbfr[shift] = EMPTY_VALUE;
}
if(trd[shift] <0)
{
if(max[shift]>max[shift+1])
{
max[shift]= max[shift+1];
}
upbfr[shift] = EMPTY_VALUE;
dnbfr[shift] = max[shift];
}
}
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool AtrStopNextRun(int newlimit,double &upbfr[],
double &dnbfr[],double &min[],
double &max[],double &trd[],int atrlength,
const string symbol,const int tframe,
double multiplier,bool samebar)
{
if(!samebar)
{
ArrayResize(upbfr,newlimit);
ArrayResize(dnbfr,newlimit);
ArrayResize(min,newlimit);
ArrayResize(max,newlimit);
ArrayResize(trd,newlimit);
upbfr[0] = dnbfr[0]= min[0] = max[0] = trd[0] = EMPTY_VALUE;
}
else
{
upbfr[0] = dnbfr[0]= min[0] = max[0] = trd[0] = EMPTY_VALUE;
}
for(int j=0; j<=1; j++)
{
min[j] = -100000;
max[j] = 100000;
for(int k=0; k<=atrlength-1; k++)
{
min[j] = MathMax(smin[j], iHigh(symbol,tframe,j+k) - multiplier*iATR(symbol,tframe,ATRperiod,j+k));
max[j] = MathMin(smax[j], iLow(symbol,tframe,j+k) + multiplier*iATR(symbol,tframe,ATRperiod,j+k));
}
trd[j] = trd[j+1];
if(iClose(symbol,tframe,j) > max[j+1])
{
trd[j] = 1;
}
if(iClose(symbol,tframe,j) < min[j+1])
{
trd[j] = -1;
}
if(trd[j] >0)
{
if(min[j]<min[j+1])
{
min[j] = min[j+1];
}
upbfr[j] = min[j];
dnbfr[j] = EMPTY_VALUE;
}
if(trend[j] <0)
{
if(max[j]>max[j+1])
{
max[j] = max[j+1];
}
upbfr[j] = EMPTY_VALUE;
dnbfr[j] = max[j];
}
}
return(true);
}
#endif
//+------------------------------------------------------------------+
@@ -0,0 +1,62 @@
//+------------------------------------------------------------------+
//| CandleTimeStationary|
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property strict
//---- input parameters
input color Clock_Color = clrDimGray;
input ENUM_BASE_CORNER Corner = CORNER_RIGHT_UPPER;
string objname="Spread&Bar";
double s1[];
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
ObjectCreate(0, objname, OBJ_LABEL,0, 0, 0);
ObjectSetInteger(0, objname, OBJPROP_CORNER, Corner);
ObjectSetInteger(0, objname, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, objname, OBJPROP_YDISTANCE, 2);
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
switch (Corner)
{
case CORNER_LEFT_UPPER: Anchor=ANCHOR_LEFT_UPPER; break;
case CORNER_RIGHT_UPPER: Anchor=ANCHOR_RIGHT_UPPER; break;
case CORNER_LEFT_LOWER: Anchor=ANCHOR_LEFT_LOWER; break;
case CORNER_RIGHT_LOWER: Anchor=ANCHOR_RIGHT_LOWER; break;
}
ObjectSetInteger(0, objname, OBJPROP_ANCHOR, Anchor);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason) { ObjectDelete(0, objname); }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spreads[])
{
ArraySetAsSeries(time, true);
int m=int(time[0]+PeriodSeconds()-TimeCurrent());
int s=m%60;
m=(m-s)/60;
long spread=SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp="",_m="",_s="";
if (spread<10) _sp="..";
else if (spread<100) _sp=".";
if (m<10) _m="0";
if (s<10) _s="0";
ObjectSetString(0, objname, OBJPROP_TEXT, "Spread: " +IntegerToString(spread)+_sp+" Next Bar in "+_m+IntegerToString(m)+":"+_s+IntegerToString(s));
ObjectSetInteger(0, objname, OBJPROP_FONTSIZE, 10);
ObjectSetInteger(0, objname, OBJPROP_COLOR, Clock_Color);
ObjectSetString(0, objname, OBJPROP_FONT, "Courier");
return(rates_total);
}
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,172 @@
//+------------------------------------------------------------------+
//| DemoTradeEventProcessing.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
input int days=7; // depth of trade history in days
int orders; // number of active orders
int positions; // number of open positions
int deals; // number of deals in the trade history cache
int history_orders; // number of orders in the trade history cache
bool started=false; // flag of initialization of the counters
//--- let's set the limits of the trade history on the global scope
datetime start; // start date for trade history in cache
datetime end; // end date for trade history in cache
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
end=TimeCurrent();
start=end-days*PeriodSeconds(PERIOD_D1);
PrintFormat("Limits of the history to be loaded: start - %s, end - %s",
TimeToString(start),TimeToString(end));
InitCounters();
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(started) SimpleTradeProcessor();
else InitCounters();
}
//+------------------------------------------------------------------+
//| Called when a Trade event comes |
//+------------------------------------------------------------------+
void OnTrade()
{
if(started) SimpleTradeProcessor();
else InitCounters();
}
//+------------------------------------------------------------------+
//| initialization of the counters of positions, orders and deals |
//+------------------------------------------------------------------+
void InitCounters()
{
ResetLastError();
//--- load history
bool selected=HistorySelect(start,end);
if(!selected)
{
PrintFormat("%s. Failed to load the history from %s to %s to the cache. Error code: %d",
__FUNCTION__,TimeToString(start),TimeToString(end),GetLastError());
return;
}
//--- get current value
orders=OrdersTotal();
positions=PositionsTotal();
deals=HistoryDealsTotal();
history_orders=HistoryOrdersTotal();
started=true;
Print("The counters of orders, positions and deals are successfully initialized");
}
//+------------------------------------------------------------------+
//| a simple example of processing changes in trade and history |
//+------------------------------------------------------------------+
void SimpleTradeProcessor()
{
end=TimeCurrent();
ResetLastError();
//--- load history
bool selected=HistorySelect(start,end);
if(!selected)
{
PrintFormat("%s. Failed to load the history from %s to %s to the cache. Error code: %d",
__FUNCTION__,TimeToString(start),TimeToString(end),GetLastError());
return;
}
//--- get current value
int curr_orders=OrdersTotal();
int curr_positions=PositionsTotal();
int curr_deals=HistoryDealsTotal();
int curr_history_orders=HistoryOrdersTotal();
//--- check if the number of active orders has been changed
if(curr_orders!=orders)
{
//--- number of active orders has been changed
PrintFormat("Number of orders has been changed. Previous value is %d, current value is %d",
orders,curr_orders);
/*
other actions connected with change of orders
*/
//--- update value
orders=curr_orders;
}
//--- changes in the number of open positions
if(curr_positions!=positions)
{
//--- number of open positions has been changed
PrintFormat("Number of positions has been changed. Previous value is %d, current value is %d",
positions,curr_positions);
/*
other actions connected with change of positions
*/
//--- update value
positions=curr_positions;
}
//--- changes in the number of deals in the trade history cache
if(curr_deals!=deals)
{
//--- number of deals in the trade history cache has been changed
PrintFormat("Number of deals has been changed. Previous value is %d, current value is %d",
deals,curr_deals);
/*
other actions connected with change of deals
*/
//--- update value
deals=curr_deals;
}
//--- changes in the number of history orders in the trade history cache
if(curr_history_orders!=history_orders)
{
//--- number of history orders in the trade history cache has been changed
PrintFormat("Number of orders in the history has been changed. Previous value is %d, current value is %d",
history_orders,curr_history_orders);
/*
other actions connected with change of the number of orders in the trade history cache
*/
//--- update value
history_orders=curr_history_orders;
}
//--- checking if it is necessary to change the limits of th trade history to be requested in cache
CheckStartDateInTradeHistory();
}
//+------------------------------------------------------------------+
//| changing the start date for requesting of the trade history |
//+------------------------------------------------------------------+
void CheckStartDateInTradeHistory()
{
//--- initial interval, as if we started working right now
datetime curr_start=TimeCurrent()-days*PeriodSeconds(PERIOD_D1);
//--- make sure that the start limit of the trade history has not gone
//--- more than 1 day over intended date
if(curr_start-start>PeriodSeconds(PERIOD_D1))
{
//--- we should correct the start date of history to be loaded in the cache
start=curr_start;
PrintFormat("New start limit of the trade history to be loaded: start => %s",
TimeToString(start));
//--- now load the trade history for the corrected period again
HistorySelect(start,end);
//--- correct the number of deals and orders in the history for further comparison
history_orders=HistoryOrdersTotal();
deals=HistoryDealsTotal();
}
}
//+------------------------------------------------------------------+
@@ -0,0 +1,247 @@
//------------------------------------------------------------------
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property link "www.forex-station.com"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrLimeGreen
#property indicator_color2 clrOrangeRed
#property indicator_width1 2
#property indicator_width2 2
#property strict
//
//
//
//
//
enum enPrices
{
pr_close, // Close
pr_open, // Open
pr_high, // High
pr_low, // Low
pr_median, // Median
pr_typical, // Typical
pr_weighted, // Weighted
pr_average, // Average (high+low+open+close)/4
pr_medianb, // Average median body (open+close)/2
pr_tbiased, // Trend biased price
pr_tbiased2, // Trend biased (extreme) price
pr_haclose, // Heiken ashi close
pr_haopen , // Heiken ashi open
pr_hahigh, // Heiken ashi high
pr_halow, // Heiken ashi low
pr_hamedian, // Heiken ashi median
pr_hatypical, // Heiken ashi typical
pr_haweighted, // Heiken ashi weighted
pr_haaverage, // Heiken ashi average
pr_hamedianb, // Heiken ashi median body
pr_hatbiased, // Heiken ashi trend biased price
pr_hatbiased2 // Heiken ashi trend biased (extreme) price
};
enum enColorOn
{
chg_onZero, // Change color on zero cross
chg_onOuter, // Change color on levels cross
chg_onOuter2, // Change color on opposite levels cross
chg_onSlope // Change color on slope change
};
input int DspPeriod = 14; // DSP period
input enPrices Price = pr_median; // DSP price
extern int SignalPeriod = 9; // Signal period
input enColorOn ColorOn = chg_onOuter; // Change color on :
double val[],histu[],histd[],levelu[],leveld[],state[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int OnInit()
{
IndicatorBuffers(6);
SetIndexBuffer( 0, histu); SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer( 1, histd); SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer( 2, val);
SetIndexBuffer( 3, levelu);
SetIndexBuffer( 4, leveld);
SetIndexBuffer( 5, state);
IndicatorShortName("DSP bars ("+(string)DspPeriod+")");
return(0);
}
void OnDeinit(const int reason) { }
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int counted_bars = prev_calculated;
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
int limit=MathMin(rates_total-counted_bars,rates_total-1);
//
//
//
//
//
double alphas = 2.0/(1.0+SignalPeriod);
double alpham = 2.0/(1.0+DspPeriod);
for(int i=limit; i>=0 && !_StopFlag; i--)
{
double price = getPrice(Price,open,close,high,low,i,rates_total);
val[i] = iEma(price,alpham,i,rates_total,0)-iEma(price,alpham/2.0,i,rates_total,1);
levelu[i] = (i<Bars-1) ? (val[i]>0) ? levelu[i+1]+alphas*(val[i]-levelu[i+1]) : levelu[i+1] : 0;
leveld[i] = (i<Bars-1) ? (val[i]<0) ? leveld[i+1]+alphas*(val[i]-leveld[i+1]) : leveld[i+1] : 0;
switch(ColorOn)
{
case chg_onOuter : state[i] = (val[i]>levelu[i]) ? 1 : (val[i]<leveld[i]) ? -1 : 0; break;
case chg_onOuter2 : state[i] = (val[i]>levelu[i]) ? 1 : (val[i]<leveld[i]) ? -1 : (i<rates_total-1) ? state[i+1]: 0; break;
case chg_onZero : state[i] = (val[i]>0) ? 1 : (val[i]<0) ? -1 : 0; break;
default : state[i] = (i<rates_total-1) ? (val[i]>val[i+1]) ? 1 : (val[i]<val[i+1]) ? -1 : state[i+1] : 0;
}
histu[i] = EMPTY_VALUE; histd[i] = EMPTY_VALUE;
if (state[i] == 1) { histu[i] = high[i]; histd[i] = low[i]; }
if (state[i] == -1) { histd[i] = high[i]; histu[i] = low[i]; }
}
return(rates_total);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
double workEma[][2];
double iEma(double price, double alpha, int r, int _bars, int instanceNo=0)
{
if (ArrayRange(workEma,0)!= _bars) ArrayResize(workEma,_bars); r=_bars-r-1;
workEma[r][instanceNo] = price;
if (r>0 && alpha!=-1)
workEma[r][instanceNo] = workEma[r-1][instanceNo]+alpha*(price-workEma[r-1][instanceNo]);
return(workEma[r][instanceNo]);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
//
#define _priceInstances 1
#define _priceInstancesSize 4
double workHa[][_priceInstances*_priceInstancesSize];
double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars, int instanceNo=0)
{
if (tprice>=pr_haclose)
{
if (ArrayRange(workHa,0)!= bars) ArrayResize(workHa,bars); instanceNo*=_priceInstancesSize;
int r = bars-i-1;
//
//
//
//
//
double haOpen;
if (r>0)
haOpen = (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0;
else haOpen = (open[i]+close[i])/2;
double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0;
double haHigh = MathMax(high[i], MathMax(haOpen,haClose));
double haLow = MathMin(low[i] , MathMin(haOpen,haClose));
if(haOpen <haClose) { workHa[r][instanceNo+0] = haLow; workHa[r][instanceNo+1] = haHigh; }
else { workHa[r][instanceNo+0] = haHigh; workHa[r][instanceNo+1] = haLow; }
workHa[r][instanceNo+2] = haOpen;
workHa[r][instanceNo+3] = haClose;
//
//
//
//
//
switch (tprice)
{
case pr_haclose: return(haClose);
case pr_haopen: return(haOpen);
case pr_hahigh: return(haHigh);
case pr_halow: return(haLow);
case pr_hamedian: return((haHigh+haLow)/2.0);
case pr_hamedianb: return((haOpen+haClose)/2.0);
case pr_hatypical: return((haHigh+haLow+haClose)/3.0);
case pr_haweighted: return((haHigh+haLow+haClose+haClose)/4.0);
case pr_haaverage: return((haHigh+haLow+haClose+haOpen)/4.0);
case pr_hatbiased:
if (haClose>haOpen)
return((haHigh+haClose)/2.0);
else return((haLow+haClose)/2.0);
case pr_hatbiased2:
if (haClose>haOpen) return(haHigh);
if (haClose<haOpen) return(haLow);
return(haClose);
}
}
//
//
//
//
//
switch (tprice)
{
case pr_close: return(close[i]);
case pr_open: return(open[i]);
case pr_high: return(high[i]);
case pr_low: return(low[i]);
case pr_median: return((high[i]+low[i])/2.0);
case pr_medianb: return((open[i]+close[i])/2.0);
case pr_typical: return((high[i]+low[i]+close[i])/3.0);
case pr_weighted: return((high[i]+low[i]+close[i]+close[i])/4.0);
case pr_average: return((high[i]+low[i]+close[i]+open[i])/4.0);
case pr_tbiased:
if (close[i]>open[i])
return((high[i]+close[i])/2.0);
else return((low[i]+close[i])/2.0);
case pr_tbiased2:
if (close[i]>open[i]) return(high[i]);
if (close[i]<open[i]) return(low[i]);
return(close[i]);
}
return(0);
}
@@ -0,0 +1,143 @@
#property copyright "Copyright 2021, mfx123 & Conor Dailey"
#property version "1.00"
#property description "No need to tick anything below"
#property strict
#property indicator_chart_window
string total;
double total_sl, total_tp;
double prev_total_sl, prev_total_tp;
string label = "sltp";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
total_sl = GetTotalSLValue();
total_tp = GetTotalTPValue();
ObjectCreate(0, label, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, label, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, label, OBJPROP_XDISTANCE, 0);
ObjectSetInteger(0, label, OBJPROP_YDISTANCE, 50);
ObjectSetInteger(0, label, OBJPROP_COLOR, clrGoldenrod);
ObjectSetString(0, label, OBJPROP_FONT, "Arial");
ObjectSetInteger(0, label, OBJPROP_FONTSIZE, 16);
ObjectSetInteger(0, label, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, label, OBJPROP_BACK, false);
ObjectSetInteger(0, label, OBJPROP_SELECTED, true);
ObjectSetInteger(0, label, OBJPROP_SELECTABLE, true);
ObjectSetInteger(0, label, OBJPROP_ZORDER, 0);
Display_Info();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0, label);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
int GetMultiplier(string s)
{
int m = 0;
int digits = SymbolInfoInteger(s, SYMBOL_DIGITS);
if(digits == 5)
m = 10000;
if(digits == 4)
m = 1000;
if(digits == 2 || digits == 3)
m = 100;
if(digits == 1)
m = 10;
return(m);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetPips2Dbl(string s)
{
int digits = SymbolInfoInteger(s, SYMBOL_DIGITS);
double p = 0;
if(digits == 5 || digits == 3)
p = SymbolInfoDouble(s, SYMBOL_POINT) * 10;
else
p = SymbolInfoDouble(s, SYMBOL_POINT);
return(p);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetTotalSLValue()
{
double sl_value = 0, total_sl_value = 0, delta;
for(int v = PositionsTotal() - 1; v >= 0; v--)
{
ulong positionticket = PositionGetTicket(v);
if(PositionSelectByTicket(positionticket))
{
if(PositionGetDouble(POSITION_SL) != 0)
{
delta = (SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_SIZE)) * GetPips2Dbl(PositionGetString(POSITION_SYMBOL));
sl_value = ((MathAbs(PositionGetDouble(POSITION_PRICE_OPEN) - PositionGetDouble(POSITION_SL)) * delta) * PositionGetDouble(POSITION_VOLUME)) * GetMultiplier(PositionGetString(POSITION_SYMBOL));
sl_value -= PositionGetDouble(POSITION_SWAP);
sl_value = -(sl_value);
total_sl_value += sl_value;
}
}
}
return(NormalizeDouble(total_sl_value, 2));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetTotalTPValue()
{
double tp_value = 0, total_tp_value = 0, delta;
for(int v = PositionsTotal() - 1; v >= 0; v--)
{
ulong positionticket = PositionGetTicket(v);
if(PositionSelectByTicket(positionticket))
{
if(PositionGetDouble(POSITION_TP) != 0)
{
delta = (SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_SIZE)) * GetPips2Dbl(PositionGetString(POSITION_SYMBOL));
tp_value = ((MathAbs(PositionGetDouble(POSITION_PRICE_OPEN) - PositionGetDouble(POSITION_TP)) * delta) * PositionGetDouble(POSITION_VOLUME)) * GetMultiplier(PositionGetString(POSITION_SYMBOL));
tp_value -= PositionGetDouble(POSITION_SWAP);
total_tp_value += tp_value;
}
}
}
return(NormalizeDouble(total_tp_value, 2));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Display_Info()
{
total = ""
+ "SL: $ " + DoubleToString(total_sl, 2) + " " + "TP: $ " + DoubleToString(total_tp, 2);
ObjectSetString(0, label, OBJPROP_TEXT, total);
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
total_sl = GetTotalSLValue();
total_tp = GetTotalTPValue();
if((total_sl != prev_total_sl) || (total_tp != prev_total_tp))
{
Display_Info();
prev_total_sl = total_sl;
prev_total_tp = total_tp;
}
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -0,0 +1,87 @@
//+------------------------------------------------------------------+
//| Heiken_Ashi.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 DodgerBlue, Red
#property indicator_label1 "Heiken Ashi Open;Heiken Ashi High;Heiken Ashi Low;Heiken Ashi Close"
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
IndicatorSetString(INDICATOR_SHORTNAME,"Heiken Ashi");
//--- sets drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Heiken Ashi |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,
const datetime &Time[],
const double &Open[],
const double &High[],
const double &Low[],
const double &Close[],
const long &TickVolume[],
const long &Volume[],
const int &Spread[])
{
int i,limit;
//--- preliminary calculations
if(prev_calculated==0)
{
//--- set first candle
ExtLBuffer[0]=Low[0];
ExtHBuffer[0]=High[0];
ExtOBuffer[0]=Open[0];
ExtCBuffer[0]=Close[0];
limit=1;
}
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
double haOpen=(ExtOBuffer[i-1]+ExtCBuffer[i-1])/2;
double haClose=(Open[i]+High[i]+Low[i]+Close[i])/4;
double haHigh=MathMax(High[i],MathMax(haOpen,haClose));
double haLow=MathMin(Low[i],MathMin(haOpen,haClose));
ExtLBuffer[i]=haLow;
ExtHBuffer[i]=haHigh;
ExtOBuffer[i]=haOpen;
ExtCBuffer[i]=haClose;
//--- set candle color
if(haOpen<haClose) ExtColorBuffer[i]=0.0; // set color DodgerBlue
else ExtColorBuffer[i]=1.0; // set color Red
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,115 @@
//+------------------------------------------------------------------+
//| SSL Channel Chart.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_label1 "Bears"
#property indicator_color1 clrOrange
#property indicator_type1 DRAW_LINE
#property indicator_width1 2
#property indicator_label2 "Bulls"
#property indicator_color2 clrAqua
#property indicator_type2 DRAW_LINE
#property indicator_width2 2
//------------------------------------------------------------------
//---- input parameters
input ENUM_MA_METHOD MA_Method = MODE_SMA; // Method
input int Lb = 10;
//---- buffers
double ssld[];
double sslu[];
double Hlv[];
int hMAHigh;
int hMALow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, ssld, INDICATOR_DATA);
SetIndexBuffer(1, sslu, INDICATOR_DATA);
SetIndexBuffer(2, Hlv, INDICATOR_CALCULATIONS);
hMAHigh = iMA(_Symbol, PERIOD_CURRENT, Lb, 0, MA_Method, PRICE_HIGH);
hMALow = iMA(_Symbol, PERIOD_CURRENT, Lb, 0, MA_Method, PRICE_LOW);
if(hMAHigh==INVALID_HANDLE)Print(" Failed to get handle of the iMA indicator");
if(hMALow==INVALID_HANDLE)Print(" Failed to get handle of the iMA indicator");
ArraySetAsSeries(ssld,true);
ArraySetAsSeries(sslu,true);
ArraySetAsSeries(Hlv,true);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int counted_bars = prev_calculated;
int i,limit;
double MAHigh[];
double MALow[];
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMax(rates_total - counted_bars - Lb, 1);
CopyBuffer(hMAHigh, 0, 0, limit+1, MAHigh);
CopyBuffer(hMALow, 0, 0, limit+1, MALow);
for(i=limit; i>=0; i--)
{
Hlv[i]=Hlv[i+1];
if (close[rates_total-1-i] > MAHigh[limit-i]) Hlv[i]= 1;
if (close[rates_total-1-i] < MALow[limit-i]) Hlv[i]= -1;
if(Hlv[i]==-1)
{
ssld[i] = MAHigh[limit-i];
sslu[i] = MALow[limit-i];
}
else
{
ssld[i] = MALow[limit-i];
sslu[i] = MAHigh[limit-i];
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,115 @@
//+------------------------------------------------------------------+
//| SSL Channel Chart.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_label1 "Bears"
#property indicator_color1 clrOrange
#property indicator_type1 DRAW_LINE
#property indicator_width1 2
#property indicator_label2 "Bulls"
#property indicator_color2 clrAqua
#property indicator_type2 DRAW_LINE
#property indicator_width2 2
//------------------------------------------------------------------
//---- input parameters
input ENUM_MA_METHOD MA_Method = MODE_SMA; // Method
input int Lb = 10;
//---- buffers
double ssld[];
double sslu[];
double Hlv[];
int hMAHigh;
int hMALow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, ssld, INDICATOR_DATA);
SetIndexBuffer(1, sslu, INDICATOR_DATA);
SetIndexBuffer(2, Hlv, INDICATOR_CALCULATIONS);
hMAHigh = iMA(_Symbol, PERIOD_CURRENT, Lb, 0, MA_Method, PRICE_HIGH);
hMALow = iMA(_Symbol, PERIOD_CURRENT, Lb, 0, MA_Method, PRICE_LOW);
if(hMAHigh==INVALID_HANDLE)Print(" Failed to get handle of the iMA indicator");
if(hMALow==INVALID_HANDLE)Print(" Failed to get handle of the iMA indicator");
ArraySetAsSeries(ssld,true);
ArraySetAsSeries(sslu,true);
ArraySetAsSeries(Hlv,true);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int counted_bars = prev_calculated;
int i,limit;
double MAHigh[];
double MALow[];
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMax(rates_total - counted_bars - Lb, 1);
CopyBuffer(hMAHigh, 0, 0, limit+1, MAHigh);
CopyBuffer(hMALow, 0, 0, limit+1, MALow);
for(i=limit; i>=0; i--)
{
Hlv[i]=Hlv[i+1];
if (close[rates_total-1-i] > MAHigh[limit-i]) Hlv[i]= 1;
if (close[rates_total-1-i] < MALow[limit-i]) Hlv[i]= -1;
if(Hlv[i]==-1)
{
ssld[i] = MAHigh[limit-i];
sslu[i] = MALow[limit-i];
}
else
{
ssld[i] = MALow[limit-i];
sslu[i] = MAHigh[limit-i];
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -0,0 +1,505 @@
//+------------------------------------------------------------------+
//| TradeControl_en.mq5 |
//| Copyright KlimMalgin |
//| |
//+------------------------------------------------------------------+
#property copyright "KlimMalgin"
#property link ""
#property version "1.00"
datetime start_date = 0; // Date, from which we begin to read history
int OrdersPrev = 0; // Number of orders at the time of previous OnTrade() call
int PositionsPrev = 0; // Number of positions at the time of previous OnTrade() call
ulong LastOrderTicket = 0; // Ticket of the last processed order
int _GetLastError=0; // Error code
long state=0; // Order state
/*
*
* Structure that stores information about positions
*
*/
struct _position
{
long type, // Position type
magic; // Magic number for position
datetime time; // Time of position opening
double volume, // Position volume
priceopen, // Position price
sl, // Stop Loss level for opened position
tp, // Take Profit level for opened position
pricecurrent, // Symbol current price
comission, // Commission
swap, // Accumulated swap
profit; // Current profit
string symbol, // Symbol, by which the position has been opened
comment; // Comment to position
};
int _ExpertPositionsTotal = 0;
_position PositionList[], // Array that stores info about position
PrevPositionList[];
/*
*
* Structure that stores information about orders
*
*/
struct _orders
{
datetime time_setup, // Time of order placement
time_expiration, // Time of order expiration
time_done; // Time of order execution or cancellation
long type, // Order type
state, // Order state
type_filling, // Type of execution by remainder
type_time, // Order lifetime
ticket; // Order ticket
long magic, // Id of Expert Advisor, that placed an order
// (intended to ensure that each Expert
// must place it's own unique number)
position_id; // Position id, that is placed on order,
// when it is executed. Each executed order invokes a
// deal, that opens new or changes existing
// position. Id of that position is placed on
// executed order in this moment.
double volume_initial, // Initial volume on order placement
volume_current, // Unfilled volume
price_open, // Price, specified in the order
sl, // Stop Loss level
tp, // Take Profit level
price_current, // Current price by order symbol
price_stoplimit; // Price of placing Limit order when StopLimit order is triggered
string symbol, // Symbol, by which the order has been placed
comment; // Comment
};
int _ExpertOrdersTotal = 0;
_orders OrderList[], // Arrays that store info about orders
PrevOrderList[];
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
start_date = 0;
OrdersPrev = OrdersTotal();
PositionsPrev = PositionsTotal();
GetPosition(PrevPositionList);
GetOrders(PrevOrderList);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| OnTrade function |
//+------------------------------------------------------------------+
void OnTrade()
{
//---
GetPosition(PositionList);
GetOrders(OrderList);
datetime dc = TimeCurrent();
HistorySelect(start_date,dc);
Alert("The Trade event occurred");
if (OrdersPrev < OrdersTotal())
{
OrderGetTicket(OrdersTotal()-1);// Select the last order to work with
_GetLastError=GetLastError();
Print("Error #",_GetLastError);ResetLastError();
//--
if (OrderGetInteger(ORDER_STATE) == ORDER_STATE_STARTED)
{
Alert(OrderGetTicket(OrdersTotal()-1),"Order has arrived for processing");
LastOrderTicket = OrderGetTicket(OrdersTotal()-1); // Saving the order ticket for further work
}
state = OrderGetInteger(ORDER_STATE);
if (state == ORDER_STATE_PLACED)
{
switch(OrderGetInteger(ORDER_TYPE))
{
case 2:
Alert("Pending order Buy Limit #", OrderGetTicket(OrdersTotal()-1)," accepted!");
break;
case 3:
Alert("Pending order Sell Limit #", OrderGetTicket(OrdersTotal()-1)," accepted!");
break;
case 4:
Alert("Pending order Buy Stop #", OrderGetTicket(OrdersTotal()-1)," accepted!");
break;
case 5:
Alert("Pending order Sell Stop #", OrderGetTicket(OrdersTotal()-1)," accepted!");
break;
case 6:
Alert("Pending order Buy Stop Limit #", OrderGetTicket(OrdersTotal()-1)," accepted!");
break;
case 7:
Alert("Pending order Sell Stop Limit #", OrderGetTicket(OrdersTotal()-1)," accepted!");
break;
}
}
}
else if(OrdersPrev > OrdersTotal())
{
state = HistoryOrderGetInteger(LastOrderTicket,ORDER_STATE);
// If order is not found, generate an error
_GetLastError=GetLastError();
if (_GetLastError != 0){Alert("Error #",_GetLastError," Order ",LastOrderTicket," is not found!");LastOrderTicket = 0;}
Print("Error #",_GetLastError," state: ",state);ResetLastError();
// If order is fully executed
if (state == ORDER_STATE_FILLED)
{
// Then analyze the last deal
// --
Alert(LastOrderTicket, "Order executed, going to deal");
switch(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_ENTRY))
{
// Entering the market
case DEAL_ENTRY_IN:
Alert(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_ORDER),
" order invoked deal #",HistoryDealGetTicket(HistoryDealsTotal()-1));
switch(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE))
{
case 0:
// If volumes of position and deal are equal, then position has just been opened
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL))
&& (PositionGetDouble(POSITION_VOLUME) == HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_VOLUME)))
{
Alert("Buy position has been opened on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL));
}
else
// If volumes of position and deal are not equal, then position has been incremented
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL))
&& (PositionGetDouble(POSITION_VOLUME) > HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_VOLUME)))
{
Alert("Buy position has incremented on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL));
}
break;
case 1:
// If volumes of position and deal are equal, then position has just been opened
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL))
&& (PositionGetDouble(POSITION_VOLUME) == HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_VOLUME)))
{
Alert("Sell position has been opened on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL));
}
else
// If volumes of position and deal are not equal, then position has been incremented
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL))
&& (PositionGetDouble(POSITION_VOLUME) > HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_VOLUME)))
{
Alert("Sell position has incremented on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL));
}
break;
default:
Alert("Unprocessed code of type: ",
HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE));
break;
}
break;
// Âûõîä èç ðûíêà
case DEAL_ENTRY_OUT:
Alert(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_ORDER),
" order invoked deal #",HistoryDealGetTicket(HistoryDealsTotal()-1));
switch(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE))
{
case 0:
// If position, we tried to close, is still present, then we have closed only part of it
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL)) == true)
{
Alert("Part of Sell position has been closed on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL),
" with profit = ",
HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PROFIT));
}
else
// If position is not found, then it is fully closed
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL)) == false)
{
Alert("Sell position has been closed on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL),
" with profit = ",
HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PROFIT));
}
break;
case 1:
// If position, we tried to close, is still present, then we have closed only part of it
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL)) == true)
{
Alert("Part of Buy position has been closed on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL),
" with profit = ",
HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PROFIT));
}
else
// If position is not found, then it is fully closed
if (PositionSelect(HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL)) == false)
{
Alert("Buy position has been closed on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL),
" with profit = ",
HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PROFIT));
}
break;
default:
Alert("Unprocessed code of type: ",
HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE));
break;
}
break;
// Reverse
case DEAL_ENTRY_INOUT:
Alert(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_ORDER),
" order invoked deal #",HistoryDealGetTicket(HistoryDealsTotal()-1));
switch(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE))
{
case 0:
Alert("Sell is reversed to Buy on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL),
" resulting profit = ",
HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PROFIT));
break;
case 1:
Alert("Buy is reversed to Sell on pair ",
HistoryDealGetString(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_SYMBOL),
" resulting profit = ",
HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PROFIT));
break;
default:
Alert("Unprocessed code of type: ",
HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE));
break;
}
break;
// Indicates the state record
case DEAL_ENTRY_STATE:
Alert("Indicates the state record. Unprocessed code of direction: ",
HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_TYPE));
break;
}
// --
}
}
if ((PositionsPrev == PositionsTotal()) && (OrdersPrev == OrdersTotal()))
{
string _alerts = "";
bool modify = false;
for (int i=0;i<_ExpertPositionsTotal;i++)
{
if (PrevPositionList[i].sl != PositionList[i].sl)
{
_alerts += "On pair "+PositionList[i].symbol+" Stop Loss changed from "+ PrevPositionList[i].sl +" to "+ PositionList[i].sl +"\n";
modify = true;
}
if (PrevPositionList[i].tp != PositionList[i].tp)
{
_alerts += "On pair "+PositionList[i].symbol+" Take Profit changed from "+ PrevPositionList[i].tp +" to "+ PositionList[i].tp +"\n";
modify = true;
}
}
for (int i = 0;i<_ExpertOrdersTotal;i++)
{
if (PrevOrderList[i].sl != OrderList[i].sl)
{
_alerts += "Order "+OrderList[i].ticket+" has changed Stop Loss from "+ PrevOrderList[i].sl +" to "+ OrderList[i].sl +"\n";
modify = true;
}
if (PrevOrderList[i].tp != OrderList[i].tp)
{
_alerts += "Order "+OrderList[i].ticket+" has changed Take Profit from "+ PrevOrderList[i].tp +" to "+ OrderList[i].tp +"\n";
modify = true;
}
}
if (modify == true)
{
Alert(_alerts);
modify = false;
}
}
GetPosition(PrevPositionList);
GetOrders(PrevOrderList);
OrdersPrev = OrdersTotal();
PositionsPrev = PositionsTotal();
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
void GetPosition(_position &Array[])
{
int _GetLastError=0,_PositionsTotal=PositionsTotal();
int temp_value=(int)MathMax(_PositionsTotal,1);
ArrayResize(Array, temp_value);
_ExpertPositionsTotal=0;
for(int z=_PositionsTotal-1; z>=0; z--)
{
if(!PositionSelect(PositionGetSymbol(z)))
{
_GetLastError=GetLastError();
Print("OrderSelect() - Error #",_GetLastError);
continue;
}
else
{
// If the position is found, then put its info to the array
Array[z].type = PositionGetInteger(POSITION_TYPE);
Array[z].time = PositionGetInteger(POSITION_TIME);
Array[z].magic = PositionGetInteger(POSITION_MAGIC);
Array[z].volume = PositionGetDouble(POSITION_VOLUME);
Array[z].priceopen = PositionGetDouble(POSITION_PRICE_OPEN);
Array[z].sl = PositionGetDouble(POSITION_SL);
Array[z].tp = PositionGetDouble(POSITION_TP);
Array[z].pricecurrent = PositionGetDouble(POSITION_PRICE_CURRENT);
Array[z].comission = PositionGetDouble(POSITION_COMMISSION);
Array[z].swap = PositionGetDouble(POSITION_SWAP);
Array[z].profit = PositionGetDouble(POSITION_PROFIT);
Array[z].symbol = PositionGetString(POSITION_SYMBOL);
Array[z].comment = PositionGetString(POSITION_COMMENT);
_ExpertPositionsTotal++;
}
}
temp_value=(int)MathMax(_ExpertPositionsTotal,1);
ArrayResize(Array,temp_value);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Function GetOrders() |
//+------------------------------------------------------------------+
void GetOrders(_orders &OrdersList[])
{
int _GetLastError=0,_OrdersTotal=OrdersTotal();
int temp_value=(int)MathMax(_OrdersTotal,1);
ArrayResize(OrdersList,temp_value);
_ExpertOrdersTotal=0;
for(int z=_OrdersTotal-1; z>=0; z--)
{
if(!OrderGetTicket(z))
{
_GetLastError=GetLastError();
Print("GetOrders() - Error #",_GetLastError);
continue;
}
else
{
OrdersList[z].ticket = OrderGetTicket(z);
OrdersList[z].time_setup = OrderGetInteger(ORDER_TIME_SETUP);
OrdersList[z].time_expiration = OrderGetInteger(ORDER_TIME_EXPIRATION);
OrdersList[z].time_done = OrderGetInteger(ORDER_TIME_DONE);
OrdersList[z].type = OrderGetInteger(ORDER_TYPE);
OrdersList[z].state = OrderGetInteger(ORDER_STATE);
OrdersList[z].type_filling = OrderGetInteger(ORDER_TYPE_FILLING);
OrdersList[z].type_time = OrderGetInteger(ORDER_TYPE_TIME);
OrdersList[z].magic = OrderGetInteger(ORDER_MAGIC);
OrdersList[z].position_id = OrderGetInteger(ORDER_POSITION_ID);
OrdersList[z].volume_initial = OrderGetDouble(ORDER_VOLUME_INITIAL);
OrdersList[z].volume_current = OrderGetDouble(ORDER_VOLUME_CURRENT);
OrdersList[z].price_open = OrderGetDouble(ORDER_PRICE_OPEN);
OrdersList[z].sl = OrderGetDouble(ORDER_SL);
OrdersList[z].tp = OrderGetDouble(ORDER_TP);
OrdersList[z].price_current = OrderGetDouble(ORDER_PRICE_CURRENT);
OrdersList[z].price_stoplimit = OrderGetDouble(ORDER_PRICE_STOPLIMIT);
OrdersList[z].symbol = OrderGetString(ORDER_SYMBOL);
OrdersList[z].comment = OrderGetString(ORDER_COMMENT);
_ExpertOrdersTotal++;
}
}
temp_value=(int)MathMax(_ExpertOrdersTotal,1);
ArrayResize(OrdersList,temp_value);
}
//+------------------------------------------------------------------+
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,640 @@
///////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_PV Peaks and Vales Indicator
// -----------------------------------------------------------
// Name: X121_PV
// Description: Market Peaks and Vales
// Market Analysor ...
//
//
// 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_PV Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_PV"
//
// END Constants ...
//
//
// 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 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 showPeaksAndVales = true; // Show Peaks and Vales
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 12
#property indicator_plots 4
//
// PEKSANDVALES ...
//
// PEAKS ...
//
#define peaksBufferIndex 0
double peaksBuffer[];
//
#property indicator_label1 "X121_PV PEAKS"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrAqua
#property indicator_width1 3
//
// VALES ...
//
#define valesBufferIndex 1
double valesBuffer[];
//
#property indicator_label2 "X121_PV VALES"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta
#property indicator_width2 3
//
#define rUpBufferIndex 2
#define rUpPlotBufferIndex 2
double rUpBuffer[];
//
#define rUpColorBufferIndex 3
double rUpColorBuffer[];
//
#property indicator_label3 "X121_PV R UP"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrAqua, CLR_NONE
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define rDownBufferIndex 4
#define rDownPlotBufferIndex 3
double rDownBuffer[];
//
#define rDownColorBufferIndex 5
double rDownColorBuffer[];
//
#property indicator_label4 "X121_PV R Down"
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_color4 clrMagenta, CLR_NONE
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
// DATA Buffers ...
//
#define sHHBufferIndex 6
double sHHBuffer[];
#define sLLBufferIndex 7
double sLLBuffer[];
//
#define mHHBufferIndex 8
double mHHBuffer[];
//
#define mLLBufferIndex 9
double mLLBuffer[];
//
#define lHHBufferIndex 10
double lHHBuffer[];
//
#define lLLBufferIndex 11
double lLLBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
double lastPeak;
double lastVale;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = 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();
//
// 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
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// 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 =
//
// Validate Peaks and Vales ...
(shortLength > 2 &&
mediumLength > shortLength &&
longLength > mediumLength)
//
;
//
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);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// RANGE ...
//
// PEAKS and VALES ...
ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE;
//
// PEAKS ...
ArraySetAsSeries(peaksBuffer, true);
SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA);
PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225);
PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW_SHIFT, -20);
PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
//
// VALES ...
ArraySetAsSeries(valesBuffer, true);
SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA);
PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225);
PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW_SHIFT, 20);
PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0);
//
PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
//
// UP Buffer ...
ArraySetAsSeries(rUpBuffer, true);
SetIndexBuffer(rUpBufferIndex, rUpBuffer, INDICATOR_DATA);
PlotIndexSetInteger(rUpBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(rUpBufferIndex, PLOT_SHOW_DATA, false);
//
// UP Color Buffer ...
ArraySetAsSeries(rUpColorBuffer, true);
SetIndexBuffer(rUpColorBufferIndex, rUpColorBuffer, INDICATOR_COLOR_INDEX);
//
// DOWN Buffer ...
ArraySetAsSeries(rDownBuffer, true);
SetIndexBuffer(rDownBufferIndex, rDownBuffer, INDICATOR_DATA);
PlotIndexSetInteger(rDownBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(rDownPlotBufferIndex, PLOT_SHOW_DATA, false);
//
// DOWN Color Buffer ...
ArraySetAsSeries(rDownColorBuffer, true);
SetIndexBuffer(rDownColorBufferIndex, rDownColorBuffer, INDICATOR_COLOR_INDEX);
//
// DATA Buffers ...
//
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);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// Calculate ...
//
double rUpColorIDX = 1;
double rDownColorIDX = 1;
//
// PEAKS and VALES ...
//
// SHORT ...
//
// HH Buffer ...
int sHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
shortLength,
bar_index);
double sHHValue = GetAppliedPrice(
sHHIndex,
hhMode);
//
sHHBuffer[bar_index] = sHHValue;
//
// LL Buffer ...
int sLLIndex = iLowest(
_Symbol,
_Period,
llMode,
shortLength,
bar_index);
double sLLValue = GetAppliedPrice(
sLLIndex,
llMode);
//
sLLBuffer[bar_index] = sLLValue;
//
// MEDIUM ...
//
// HH Buffer ...
int mHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
mediumLength,
bar_index);
double mHHValue = GetAppliedPrice(
mHHIndex,
hhMode);
//
mHHBuffer[bar_index] = mHHValue;
//
// LL Buffer ...
int mLLIndex = iLowest(
_Symbol,
_Period,
llMode,
mediumLength,
bar_index);
double mLLValue = GetAppliedPrice(
mLLIndex,
llMode);
//
mLLBuffer[bar_index] = mLLValue;
//
// LONG ...
//
// HH Buffer ...
int lHHIndex = iHighest(
_Symbol,
_Period,
hhMode,
longLength,
bar_index);
double lHHValue = GetAppliedPrice(
lHHIndex,
hhMode);
//
lHHBuffer[bar_index] = lHHValue;
//
// LL Buffer ...
int lLLIndex = iLowest(
_Symbol,
_Period,
llMode,
longLength,
bar_index);
double lLLValue = GetAppliedPrice(
lLLIndex,
llMode);
//
lLLBuffer[bar_index] = lLLValue;
//
// RANGE ...
//
// UP ...
double rUpValue = (sHHValue + mHHValue + lHHValue) / 3;
rUpBuffer[bar_index] = rUpValue;
//
// DOWN ...
double rDownValue = (sLLValue + mLLValue + lLLValue) / 3;
rDownBuffer[bar_index] = rDownValue;
//
// Detecting Peaks and Vales ...
//
// PEAKS ...
bool isPeak = rUpValue == lHHValue &&
lHHValue == mHHValue &&
mHHValue == sHHValue;
//
if (isPeak && lastPeak != rUpValue)
{
//
if (showPeaksAndVales)
{
rUpColorIDX = 0;
}
//
lastPeak = rUpValue;
peaksBuffer[bar_index] = lastPeak;
}
else
{
peaksBuffer[bar_index] = 0;
}
//
// VALES ...
bool isVale = rDownValue == lLLValue &&
lLLValue == mLLValue &&
mLLValue == sLLValue;
if (isVale && lastVale != rDownValue)
{
//
if (showPeaksAndVales)
{
rDownColorIDX = 0;
}
//
lastVale = rDownValue;
valesBuffer[bar_index] = lastVale;
}
else
{
valesBuffer[bar_index] = 0;
}
//
// Set Default Colors ...
//
rUpColorBuffer[bar_index] = rUpColorIDX;
rDownColorBuffer[bar_index] = rDownColorIDX;
}
//
// END Functions ...
//
@@ -0,0 +1,459 @@
///////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_XTRND Trends Indicator
// -----------------------------------------------------------
// Name: X121_XTRND
// Description: Market Trend Detector ...
// Market Analysor ...
//
//
// 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_XTRND Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_XTRND"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Makret";
input int cycleLength = 2; // Cycle Length to Check
input int numberOfVerifications = 2; // Number of Verifications
//
input group "Calculation";
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Detect Up
input ENUM_SERIESMODE llMode = MODE_LOW; // Detect Low
//
input group "Presentation";
input bool showConsolidations = false; // Show Consolidations
input bool showTrend = true; // Show Trend
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 4
#property indicator_plots 4
//
// Higher High ...
#define hhBufferIndex 0
#define hhPlotBufferIndex 0
double hhBuffer[];
#define hhColorBufferIndex 1
double hhColorBuffer[];
//
#property indicator_label1 "X121_XTRND U"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// Lower Low ...
#define llBufferIndex 2
#define llPlotBufferIndex 1
double llBuffer[];
#define llColorBufferIndex 3
double llColorBuffer[];
//
#property indicator_label2 "X121_XTRND D"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrLightGray, clrAqua, clrMagenta
#property indicator_style2 STYLE_DOT
#property indicator_width2 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;
}
//
logTag = 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();
//
// 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
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// 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 =
//
(cycleLength > 0 &&
numberOfVerifications > 0)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Peaks and Vales ...
result = MathMax(
cycleLength,
numberOfVerifications);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ENUM_DRAW_TYPE drawType = showTrend ? DRAW_COLOR_LINE : DRAW_NONE;
//
// HH Buffer ...
//
// SERIES ...
ArraySetAsSeries(hhBuffer, true);
SetIndexBuffer(hhBufferIndex, hhBuffer, INDICATOR_DATA);
//
// PLOT Config ...
PlotIndexSetInteger(hhPlotBufferIndex, PLOT_SHOW_DATA, showTrend);
PlotIndexSetInteger(hhPlotBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(hhPlotBufferIndex, PLOT_DRAW_TYPE, drawType);
//
// COLOR Buffer ...
ArraySetAsSeries(hhColorBuffer, true);
SetIndexBuffer(hhColorBufferIndex, hhColorBuffer, INDICATOR_COLOR_INDEX);
//
// LL Buffer ...
//
// SERIES ...
ArraySetAsSeries(llBuffer, true);
SetIndexBuffer(llBufferIndex, llBuffer, INDICATOR_DATA);
//
// PLOT Config ...
PlotIndexSetInteger(llPlotBufferIndex, PLOT_SHOW_DATA, showTrend);
PlotIndexSetInteger(llPlotBufferIndex, PLOT_DRAW_TYPE, drawType);
PlotIndexSetInteger(llPlotBufferIndex, PLOT_DRAW_BEGIN, maxLength);
//
// COLOR Buffer ...
ArraySetAsSeries(llColorBuffer, true);
SetIndexBuffer(llColorBufferIndex, llColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// HIGHER Highs ...
double hh = GetHighestHigh(
_Symbol,
_Period,
hhMode,
cycleLength,
bar_index);
//
hhBuffer[bar_index] = hh;
//
// LOWER Lows ...
double ll = GetLowestLow(
_Symbol,
_Period,
llMode,
cycleLength,
bar_index);
//
llBuffer[bar_index] = ll;
//
// Set Default Color ...
// in Consolidations use index 0 for CLR_NONE ...
double hhColorIDX = showConsolidations ? 1 : 0;
double llColorIDX = showConsolidations ? 1 : 0;
//
// Calculate Cycle Changes ...
//
int cycleCLength = cycleLength * numberOfVerifications;
bool isCycleCLengthPassed = MathAbs(ArraySize(hhBuffer) - bar_index) > cycleCLength + 1;
//
if (isCycleCLengthPassed)
{
//
bool isLowestLowUp = true; // ll > llBuffer[bar_index + 1];
bool isLowestLowDown = true; // ll < llBuffer[bar_index + 1];
bool isHighsestHighUp = true; // hh > hhBuffer[bar_index + 1];
bool isHighsestHighDown = true; // hh < hhBuffer[bar_index + 1];
for (int i = bar_index; i < bar_index + cycleCLength; i++)
{
//
double iHH = hhBuffer[i];
double iLL = llBuffer[i];
//
if (hh < iHH)
{
isHighsestHighUp = false;
}
else if (hh > iHH)
{
isHighsestHighDown = false;
}
//
if (ll < iLL)
{
isLowestLowUp = false;
}
else if (ll > iLL)
{
isLowestLowDown = false;
}
}
//
// Detect Trends and Change Colors ...
//
if (isLowestLowUp &&
isHighsestHighUp)
{
//
hhColorIDX = 2;
llColorIDX = 2;
}
//
if (isLowestLowDown &&
isHighsestHighDown)
{
//
hhColorIDX = 3;
llColorIDX = 3;
}
}
//
hhColorBuffer[bar_index] = hhColorIDX;
llColorBuffer[bar_index] = llColorIDX;
}
//
// END Functions ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,216 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Hull Class Library
// ----------------------------------------------
// Name: XSCHull
// Description: provides all Hull 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
//
// START Definitions ...
//
//
struct XHullData
{
//
double value;
double value3;
//
double wsum1;
double wsum2;
double wsum3;
//
double lsum1;
double lsum2;
double lsum3;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class For Hull Calculations ...
class XSCHull
{
//
public:
//
// Constructor ...
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
{
//
// These are a way above to assign Private variables at Construct time ...
}
//
// Deconstructor ...
~XSCHull()
{
ArrayFree(mData);
}
//
// Initial Hull ...
bool Init(int period, double divisor)
{
//
bool result = false;
//
mFullPeriod = (int)(period > 1 ? period : 1);
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (divisor > 1 ? divisor : 1) : 1);
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
//
mArraySize = -1;
mWeight1 = mWeight2 = mWeight3 = 1;
//
result = true;
//
return result;
}
//
// CalCulate Specific Value ...
double Calculate(
double value,
int i,
int bars)
{
//
double result = 0;
//
if (mArraySize < bars)
{
//
mArraySize = ArrayResize(mData, bars + 500);
if (mArraySize < bars)
return result;
}
//
mData[i].value = value;
if (i > mFullPeriod)
{
//
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
}
else
{
//
mData[i].wsum1 = mData[i].wsum2 =
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
{
//
if (w1 > 0)
{
//
mData[i].wsum1 += mData[i - k].value * w1;
mData[i].lsum1 += mData[i - k].value;
mWeight1 += w1;
}
//
mData[i].wsum2 += mData[i - k].value * w2;
mData[i].lsum2 += mData[i - k].value;
mWeight2 += w2;
}
}
//
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
//
if (i > mSqrtPeriod)
{
//
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
}
else
{
//
mData[i].wsum3 =
mData[i].lsum3 = mWeight3 = 0;
//
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
{
//
mData[i].wsum3 += mData[i - k].value3 * w3;
mData[i].lsum3 += mData[i - k].value3;
mWeight3 += w3;
}
}
//
result = mData[i].wsum3 / mWeight3;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
int mFullPeriod;
int mHalfPeriod;
int mSqrtPeriod;
int mArraySize;
double mWeight1;
double mWeight2;
double mWeight3;
//
XHullData mData[];
};
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,235 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XATRSLHLP Indicator Helper for Signal Providers
// --------------------------------------------------------------------------
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
/////////////////////////////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Includes ...
//
//
// Includes ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
#include "../../Libraries/x-saherelm.models.lib.mq5"
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes ...
//
//
// START Constants/Enums ...
//
//
// XPeaksAndVales Exported Buffers ...
enum ENUM_X_XATRSL_BUFFERS
{
//
X_ATRSL_UP_LINE = 0,
X_ATRSL_DOWN_LINE = 1,
X_ATRSL_SAR_LINE = 2,
X_ATRSL_RMA_LINE = 3,
X_ATRSL_WMA_LINE = 4,
X_ATRSL_MA1_LINE = 5,
X_ATRSL_SMA_LINE = 6,
X_ATRSL_EMA_LINE = 7,
X_ATRSL_ATR_LINE = 8,
};
//
// END Constants/Enums ...
//
//
// START Definitions ...
//
//
double atrslUpBuffer[];
double atrslDownBuffer[];
double atrslSarBuffer[];
//
int atrslHandler = INVALID_HANDLE;
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
bool XATRSLHLPOnInit()
{
//
bool result = false;
//
ArraySetAsSeries(atrslUpBuffer, true);
ArraySetAsSeries(atrslSarBuffer, true);
ArraySetAsSeries(atrslDownBuffer, true);
//
// Initial Handler ...
atrslHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xatrsl",
//
// Inputs ...
//
// MARKET ...
"",
14,
0.02,
0.2,
PRICE_HIGH,
PRICE_LOW,
//
// PRESENTATION ...
"",
false,
false,
true
//
);
result = atrslHandler != INVALID_HANDLE;
//
return result;
}
//
void XATRSLHLPOnDeInit()
{
//
// Release Indicators ...
IndicatorRelease(atrslHandler);
}
//
void XATRSLHLPReadBuffers()
{
//
// UP ...
CopyBuffer(
atrslHandler,
X_ATRSL_UP_LINE,
0,
10,
atrslUpBuffer);
//
// DOWN ...
CopyBuffer(
atrslHandler,
X_ATRSL_DOWN_LINE,
0,
10,
atrslDownBuffer);
//
// SAR ...
CopyBuffer(
atrslHandler,
X_ATRSL_SAR_LINE,
0,
10,
atrslSarBuffer);
}
//
// END Handler Functions ...
//
//
// START Helper Functions ...
//
//
// Calculate Change Rate For Specific Bar ...
double XATRSLHLPGetChangeRate(
int bar_index // Bar Index ...
)
{
//
double result = 0;
//
if (!XATRSLHLPIsValidArraySize(bar_index))
{
return result;
}
//
result = MathAbs(atrslUpBuffer[bar_index] - atrslDownBuffer[bar_index]);
//
return result;
}
//
// Calculate Change Rate For Specific Lenght ...
double XATRSLHLPGetRangeChangeRate(
int bar_index, // Bar Index ...
int length = 5 // Loopback Length ...
)
{
//
double result = 0;
//
int size = bar_index + length;
if (!XATRSLHLPIsValidArraySize(size))
{
return result;
}
//
double summary = 0;
for (int i = bar_index; i < size; i++)
{
summary += MathAbs(atrslUpBuffer[i] - atrslDownBuffer[i]);
}
//
result = summary / size;
//
return result;
}
//
// Check Array Size ...
bool XATRSLHLPIsValidArraySize(int bar_index)
{
//
bool result = false;
//
int rCount = ArraySize(atrslUpBuffer);
result = rCount > bar_index + 1;
//
return result;
}
//
// END Helper Functions ...
//
@@ -0,0 +1,938 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XICHIHLP Indicator Helper for Signal Providers
// --------------------------------------------------------------------------
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
/////////////////////////////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Includes ...
//
//
// Includes ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
#include "../../Libraries/x-saherelm.models.lib.mq5"
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes ...
//
//
// START Constants/Enums ...
//
//
// 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
};
//
// Ichimoku Indicator Exported Buffers ...
enum ENUM_X_ICHIMOKU_BUFFERS
{
//
X_TENKANSEN_LINE = 0,
X_KIJUNSEN_LINE = 1,
X_CHIKOUSPAN_LINE = 4,
X_SENKOUSPAN_A_LINE = 5,
X_SENKOUSPAN_B_LINE = 6,
};
//
// Model Ichimoku Data ...
struct XIchiInfo
{
//
int bar;
//
double tenkanSen;
double kijunSen;
//
double chikouSpan;
//
double senkouSpanA;
double senkouSpanB;
//
double senkouSpanAFuture;
double senkouSpanBFuture;
};
//
double ichiPivots[];
//
// END Constants/Enums ...
//
//
// START Definitions ...
//
//
double ichiTenkanSenBuffer[];
double ichiKijunSenBuffer[];
double ichiChikouSpanBuffer[];
double ichiSenkouSpanABuffer[];
double ichiSenkouSpanBBuffer[];
//
int ichiHandler = INVALID_HANDLE;
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
bool XICHIHLPOnInit()
{
//
bool result = false;
//
ArraySetAsSeries(ichiTenkanSenBuffer, true);
ArraySetAsSeries(ichiKijunSenBuffer, true);
ArraySetAsSeries(ichiChikouSpanBuffer, true);
ArraySetAsSeries(ichiSenkouSpanABuffer, true);
ArraySetAsSeries(ichiSenkouSpanBBuffer, true);
//
ArraySetAsSeries(ichiPivots, true);
//
// Initial Handler ...
ichiHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xich",
//
// Inputs ...
//
// TENKANSEN ...
"",
9,
X_XICH_HH_LL_MODE,
//
// KIJUNSEN ...
"",
26,
X_XICH_HH_LL_MODE,
//
// SENKOUSPANB ...
"",
52,
X_XICH_HH_LL_MODE,
//
// CHIKOUSPAN ...
"",
PRICE_CLOSE,
//
// PRESENTATION ...
"",
true,
true,
false,
false,
false,
false,
false,
true,
true // Shift Kumo ...
//
);
result = ichiHandler != INVALID_HANDLE;
//
return result;
}
//
void XICHIHLPOnDeInit()
{
//
// Release Indicators ...
IndicatorRelease(ichiHandler);
}
//
void XICHIHLPReadBuffers()
{
//
// TENKANSEN ...
CopyBuffer(
ichiHandler,
X_TENKANSEN_LINE,
0,
26,
ichiTenkanSenBuffer);
//
// KIJUNSEN ...
CopyBuffer(
ichiHandler,
X_KIJUNSEN_LINE,
0,
26,
ichiKijunSenBuffer);
//
// CHIKOUSPAN ...
CopyBuffer(
ichiHandler,
X_CHIKOUSPAN_LINE,
27,
52,
ichiChikouSpanBuffer);
//
// SENKOUSPANA ...
CopyBuffer(
ichiHandler,
X_SENKOUSPAN_A_LINE,
-26,
52,
ichiSenkouSpanABuffer);
//
// SENKOUSPANB ...
CopyBuffer(
ichiHandler,
X_SENKOUSPAN_B_LINE,
-26,
52,
ichiSenkouSpanBBuffer);
//
XICHIHLPFindPivotPoints();
}
//
// END Handler Functions ...
//
//
// START Helper Functions ...
//
//
// Retrieve Ichimoku Data at Specific Bar Index ...
XIchiInfo XICHIHLPGetInfo(
int bar_index // Bar Index ...
)
{
//
XIchiInfo result = {};
//
result.bar = bar_index;
result.tenkanSen = ichiTenkanSenBuffer[bar_index];
result.kijunSen = ichiKijunSenBuffer[bar_index];
result.chikouSpan = ichiChikouSpanBuffer[bar_index + 26];
result.senkouSpanA = ichiSenkouSpanABuffer[bar_index + 26];
result.senkouSpanB = ichiSenkouSpanBBuffer[bar_index + 26];
result.senkouSpanAFuture = ichiSenkouSpanABuffer[bar_index];
result.senkouSpanBFuture = ichiSenkouSpanBBuffer[bar_index];
//
return result;
}
//
// Check Tenkan Sen Over Kijun Sen ...
bool XICHIHLPIsTenkanSenOverKijunSen(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
//
result =
//
point.tenkanSen > point.kijunSen
//
;
//
return result;
}
//
// Is Tenkan Sen Under Kijun Sen ...
bool XICHIHLPIsTenkanSenUnderKijunSen(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
//
result =
//
point.tenkanSen < point.kijunSen
//
;
//
return result;
}
//
// Tenkan Sen Croosed Over Kijun Sen ...
bool XICHIHLPIsTenkanSenCrossedOverKijunSen(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
result =
//
point.tenkanSen > point.kijunSen &&
pointPrev.tenkanSen <= pointPrev.kijunSen
//
;
//
return result;
}
//
// Tenkan Sen Croosed Under Kijun Sen ...
bool XICHIHLPIsTenkanSenCrossedUnderKijunSen(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
result =
//
point.tenkanSen < point.kijunSen &&
pointPrev.tenkanSen >= pointPrev.kijunSen
//
;
//
return result;
}
//
// Check Kumo is Bullish ...
bool XICHIHLPIsKumoBullish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double ssa = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double ssb = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
result =
//
ssa > ssb
//
;
//
return result;
}
//
// Check Kumo is Bearish ...
bool XICHIHLPIsKumoBearish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double ssa = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double ssb = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
result =
//
ssa < ssb
//
;
//
return result;
}
//
// Check Kumo is Change to Bullish ...
bool XICHIHLPIsKumoSwitchedToBullish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double ssa = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double ssb = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
double ssaPrev = onFuture
? pointPrev.senkouSpanAFuture
: pointPrev.senkouSpanA;
//
double ssbPrev = onFuture
? pointPrev.senkouSpanBFuture
: pointPrev.senkouSpanB;
//
result =
//
ssa > ssb &&
ssaPrev <= ssbPrev
//
;
//
return result;
}
//
// Check Kumo is Change to Bearish ...
bool XICHIHLPIsKumoSwitchedToBearish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double ssa = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double ssb = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
double ssaPrev = onFuture
? pointPrev.senkouSpanAFuture
: pointPrev.senkouSpanA;
//
double ssbPrev = onFuture
? pointPrev.senkouSpanBFuture
: pointPrev.senkouSpanB;
//
result =
//
ssa < ssb &&
ssaPrev >= ssbPrev
//
;
//
return result;
}
//
// TENKANSEN and SENKOUSPAN ...
//
bool XICHIHLPIsTenkanSenCrossedOverSenkouSpanA(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double destPrev = onFuture
? pointPrev.senkouSpanAFuture
: pointPrev.senkouSpanA;
//
result =
//
point.tenkanSen > dest &&
pointPrev.tenkanSen <= destPrev
//
;
//
return result;
}
//
bool XICHIHLPIsTenkanSenCrossedUnderSenkouSpanA(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double destPrev = onFuture
? pointPrev.senkouSpanAFuture
: pointPrev.senkouSpanA;
//
result =
//
point.tenkanSen < dest &&
pointPrev.tenkanSen >= destPrev
//
;
//
return result;
}
//
bool XICHIHLPIsTenkanSenCrossedOverSenkouSpanB(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
double destPrev = onFuture
? pointPrev.senkouSpanBFuture
: pointPrev.senkouSpanB;
//
result =
//
point.tenkanSen > dest &&
pointPrev.tenkanSen <= destPrev
//
;
//
return result;
}
//
bool XICHIHLPIsTenkanSenCrossedUnderSenkouSpanB(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
double destPrev = onFuture
? pointPrev.senkouSpanBFuture
: pointPrev.senkouSpanB;
//
result =
//
point.tenkanSen < dest &&
pointPrev.tenkanSen >= destPrev
//
;
//
return result;
}
//
// KIJUNSEN and SENKOUSPAN ...
//
bool XICHIHLPIsKijunSenCrossedOverSenkouSpanA(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double destPrev = onFuture
? pointPrev.senkouSpanAFuture
: pointPrev.senkouSpanA;
//
result =
//
point.kijunSen > dest &&
pointPrev.kijunSen <= destPrev
//
;
//
return result;
}
//
bool XICHIHLPIsKijunSenCrossedUnderSenkouSpanA(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanAFuture
: point.senkouSpanA;
//
double destPrev = onFuture
? pointPrev.senkouSpanAFuture
: pointPrev.senkouSpanA;
//
result =
//
point.kijunSen < dest &&
pointPrev.kijunSen >= destPrev
//
;
//
return result;
}
//
bool XICHIHLPIsKijunSenCrossedOverSenkouSpanB(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
double destPrev = onFuture
? pointPrev.senkouSpanBFuture
: pointPrev.senkouSpanB;
//
result =
//
point.kijunSen > dest &&
pointPrev.kijunSen <= destPrev
//
;
//
return result;
}
//
bool XICHIHLPIsKijunSenCrossedUnderSenkouSpanB(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
XIchiInfo point = XICHIHLPGetInfo(bar_index);
XIchiInfo pointPrev = XICHIHLPGetInfo(bar_index + 1);
//
double dest = onFuture
? point.senkouSpanBFuture
: point.senkouSpanB;
//
double destPrev = onFuture
? pointPrev.senkouSpanBFuture
: pointPrev.senkouSpanB;
//
result =
//
point.kijunSen < dest &&
pointPrev.kijunSen >= destPrev
//
;
//
return result;
}
//
bool XICHIHLPIsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(ichiTenkanSenBuffer);
result = rCount > bar_index + 1;
//
return result;
}
//
// SUPPORT and RESISTANCE ...
//
// Find Pivot Areas in Ichimooku ...
void XICHIHLPFindPivotPoints()
{
//
double smoothingPoint = 3;
int verifications = 3;
//
// FLATS ...
double tmpFlats[];
int tmpFlatsCount = 0;
//
// TenkanSen Flats ...
FindSameValueInBuffer(
tmpFlats,
ichiTenkanSenBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
ichiPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// KijunSen Flats ...
FindSameValueInBuffer(
tmpFlats,
ichiKijunSenBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
ichiPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// SenkouSpanA Flats ...
FindSameValueInBuffer(
tmpFlats,
ichiSenkouSpanABuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
ichiPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// SenkouSpanB Flats ...
FindSameValueInBuffer(
tmpFlats,
ichiSenkouSpanBBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
ichiPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
}
//
// Extract Support and Resistances ...
XOHCLSupRes XICHIHLPFindCandleSupprtAndResistance(
int bar_index, // Bar Index ...
int count = 3 // Number of Requireds ...
)
{
//
XOHCLSupRes result = ExtractSupportAndResistance(
bar_index,
ichiPivots,
count,
_Symbol,
_Period);
//
return result;
}
//
// END Helper Functions ...
//
@@ -0,0 +1,309 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XMCHLP Indicator Helper for Signal Providers
// --------------------------------------------------------------------------
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
/////////////////////////////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Includes ...
//
//
// Includes ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
#include "../../Libraries/x-saherelm.models.lib.mq5"
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes ...
//
//
// START Constants/Enums ...
//
//
// XMC Exported Buffers ...
enum ENUM_X_XMC_BUFFERS
{
//
X_MC_FAST_LINE = 0,
X_MC_SLOW_LINE = 1,
X_MC_VERIFIER_LINE = 2,
};
//
// END Constants/Enums ...
//
//
// START Definitions ...
//
//
double mcFastBuffer[];
double mcSlowBuffer[];
double mcVerifierBuffer[];
//
int mcHandler = INVALID_HANDLE;
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
bool XMCHLPOnInit()
{
//
bool result = false;
//
ArraySetAsSeries(mcFastBuffer, true);
ArraySetAsSeries(mcSlowBuffer, true);
ArraySetAsSeries(mcVerifierBuffer, true);
//
// Initial Handler ...
mcHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xmc",
//
// Inputs ...
//
// FAST ...
"",
9,
0,
MODE_EMA,
PRICE_CLOSE,
//
// SLOW ...
"",
18,
0,
MODE_EMA,
PRICE_CLOSE,
//
// VERIFIER ...
"",
50,
0,
MODE_EMA,
PRICE_CLOSE,
//
"",
false,
false,
false
//
);
result = mcHandler != INVALID_HANDLE;
//
return result;
}
//
void XMCHLPOnDeInit()
{
//
// Release Indicators ...
IndicatorRelease(mcHandler);
}
//
void XMCHLPReadBuffers()
{
//
// FAST ...
CopyBuffer(
mcHandler,
X_MC_FAST_LINE,
0,
52,
mcFastBuffer);
//
// SLOW ...
CopyBuffer(
mcHandler,
X_MC_SLOW_LINE,
0,
52,
mcSlowBuffer);
//
// VERIFIER ...
CopyBuffer(
mcHandler,
X_MC_VERIFIER_LINE,
0,
52,
mcVerifierBuffer);
}
//
// END Handler Functions ...
//
//
// START Helper Functions ...
//
//
// Check Fast Over Slow ...
bool XMCHLPIsFastOverSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMCHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsOver(
mcFastBuffer,
mcSlowBuffer,
bar_index)
//
;
//
return result;
}
//
// Check Fast Crossed Over Slow ...
bool XMCHLPIsFastCrossedOverSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMCHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsCrossOver(
mcFastBuffer,
mcSlowBuffer,
bar_index)
//
;
//
return result;
}
//
// Check Fast Under Slow ...
bool XMCHLPIsFastUnderSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMCHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsUnder(
mcFastBuffer,
mcSlowBuffer,
bar_index)
//
;
//
return result;
}
//
// Check Fast Crossed Under Slow ...
bool XMCHLPIsFastCrossedUnderSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMCHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsCrossUnder(
mcFastBuffer,
mcSlowBuffer,
bar_index)
//
;
//
return result;
}
//
bool XMCHLPIsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(mcFastBuffer);
result = rCount > bar_index + 1;
//
return result;
}
//
// END Helper Functions ...
//
@@ -0,0 +1,314 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XMRBHLP Indicator Helper for Signal Providers
// --------------------------------------------------------------------------
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
/////////////////////////////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Includes ...
//
//
// Includes ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
#include "../../Libraries/x-saherelm.models.lib.mq5"
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes ...
//
//
// START Constants/Enums ...
//
//
// XMRB Exported Buffers ...
enum ENUM_X_XMRB_BUFFERS
{
//
X_MRB_FAST_LINE = 0,
X_MRB_SLOW_LINE = 1,
//
X_MRB_FAST_1_LINE = 2,
X_MRB_FAST_2_LINE = 3,
X_MRB_FAST_3_LINE = 4,
X_MRB_FAST_4_LINE = 5,
X_MRB_FAST_5_LINE = 6,
//
X_MRB_SLOW_1_LINE = 7,
X_MRB_SLOW_2_LINE = 8,
X_MRB_SLOW_3_LINE = 9,
X_MRB_SLOW_4_LINE = 10,
X_MRB_SLOW_5_LINE = 11,
};
//
// END Constants/Enums ...
//
//
// START Definitions ...
//
//
double mrbFastBuffer[];
double mrbSlowBuffer[];
//
int mrbHandler = INVALID_HANDLE;
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
bool XMRBHLPOnInit()
{
//
bool result = false;
//
ArraySetAsSeries(mrbFastBuffer, true);
ArraySetAsSeries(mrbSlowBuffer, true);
//
// Initial Handler ...
mrbHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xmrb",
//
// Inputs ...
//
"",
3,
5,
//
"",
8,
13,
//
"",
21,
34,
//
"",
55,
89,
//
"",
144,
233,
//
"",
MODE_EMA,
PRICE_CLOSE,
//
"",
false,
false,
false
//
);
result = mrbHandler != INVALID_HANDLE;
//
return result;
}
//
void XMRBHLPOnDeInit()
{
//
// Release Indicators ...
IndicatorRelease(mrbHandler);
}
//
void XMRBHLPReadBuffers()
{
//
// FAST ...
CopyBuffer(
mrbHandler,
X_MRB_FAST_LINE,
0,
52,
mrbFastBuffer);
//
// SLOW ...
CopyBuffer(
mrbHandler,
X_MRB_SLOW_LINE,
0,
52,
mrbSlowBuffer);
}
//
// END Handler Functions ...
//
//
// START Helper Functions ...
//
//
// Check Fast Over Slow ...
bool XMRBHLPIsFastOverSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMRBHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsOver(
mrbFastBuffer,
mrbSlowBuffer,
bar_index)
//
;
//
return result;
}
//
// Check Fast Crossed Over Slow ...
bool XMRBHLPIsFastCrossedOverSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMRBHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsCrossOver(
mrbFastBuffer,
mrbSlowBuffer,
bar_index)
//
;
//
return result;
}
//
// Check Fast Under Slow ...
bool XMRBHLPIsFastUnderSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMRBHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsUnder(
mrbFastBuffer,
mrbSlowBuffer,
bar_index)
//
;
//
return result;
}
//
// Check Fast Crossed Under Slow ...
bool XMRBHLPIsFastCrossedUnderSlow(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!XMRBHLPIsValidArraySize(bar_index))
{
return result;
}
//
result =
//
IsCrossUnder(
mrbFastBuffer,
mrbSlowBuffer,
bar_index)
//
;
//
return result;
}
//
bool XMRBHLPIsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(mrbFastBuffer);
result = rCount > bar_index + 1;
//
return result;
}
//
// END Helper Functions ...
//
@@ -0,0 +1,803 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XPVHLP Indicator Helper for Signal Providers
// --------------------------------------------------------------------------
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
/////////////////////////////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Includes ...
//
//
// Includes ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
#include "../../Libraries/x-saherelm.models.lib.mq5"
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes ...
//
//
// START Constants/Enums ...
//
//
// XPeaksAndVales Exported Buffers ...
enum ENUM_X_XPV_BUFFERS
{
//
// PEAKSANDVALES ...
X_PV_P_LINE = 0,
X_PV_V_LINE = 1,
//
// SUPPORTRESISTANCE ...
X_PV_R_LINE = 2,
X_PV_S_LINE = 4,
//
// SHORT ...
X_PV_SHH_LINE = 6,
X_PV_SLL_LINE = 7,
//
// MEDIUM ...
X_PV_MHH_LINE = 8,
X_PV_MLL_LINE = 9,
//
// LONG ...
X_PV_LHH_LINE = 10,
X_PV_LLL_LINE = 11,
//
// HIND ...
X_PV_HHH_LINE = 12,
X_PV_HLL_LINE = 13,
};
//
// END Constants/Enums ...
//
//
// START Definitions ...
//
//
double pvPivots[];
//
double pvPBuffer[];
double pvVBuffer[];
double pvRBuffer[];
double pvSBuffer[];
double pvSHHBuffer[];
double pvSLLBuffer[];
double pvMHHBuffer[];
double pvMLLBuffer[];
double pvLHHBuffer[];
double pvLLLBuffer[];
double pvHHHBuffer[];
double pvHLLBuffer[];
//
int mpvHandler = INVALID_HANDLE;
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
bool XPVHLPOnInit()
{
//
bool result = false;
//
ArraySetAsSeries(pvPivots, true);
//
ArraySetAsSeries(pvPBuffer, true);
ArraySetAsSeries(pvVBuffer, true);
ArraySetAsSeries(pvRBuffer, true);
ArraySetAsSeries(pvSBuffer, true);
ArraySetAsSeries(pvSHHBuffer, true);
ArraySetAsSeries(pvSLLBuffer, true);
ArraySetAsSeries(pvMHHBuffer, true);
ArraySetAsSeries(pvMLLBuffer, true);
ArraySetAsSeries(pvLHHBuffer, true);
ArraySetAsSeries(pvLLLBuffer, true);
ArraySetAsSeries(pvHHHBuffer, true);
ArraySetAsSeries(pvHLLBuffer, true);
//
// Initial Handler ...
mpvHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xpv",
//
// Inputs ...
//
// MARKET ...
"",
9,
17,
26,
35,
//
// TREND ...
"",
10,
//
// DETECTION ...
"",
MODE_HIGH,
MODE_LOW,
//
"",
true,
false,
false,
false
//
);
result = mpvHandler != INVALID_HANDLE;
//
return result;
}
//
void XPVHLPOnDeInit()
{
//
// Release Indicators ...
IndicatorRelease(mpvHandler);
}
//
void XPVHLPReadBuffers(int bar_index = 0)
{
//
// PEAKS ...
CopyBuffer(
mpvHandler,
X_PV_P_LINE,
bar_index,
bar_index + 100,
pvPBuffer);
//
// VALES ...
CopyBuffer(
mpvHandler,
X_PV_V_LINE,
bar_index,
bar_index + 100,
pvVBuffer);
//
// R ...
CopyBuffer(
mpvHandler,
X_PV_R_LINE,
bar_index,
bar_index + 100,
pvRBuffer);
//
// S ...
CopyBuffer(
mpvHandler,
X_PV_S_LINE,
bar_index,
bar_index + 100,
pvSBuffer);
//
// SHORT ...
//
// HIGH ...
CopyBuffer(
mpvHandler,
X_PV_SHH_LINE,
bar_index,
bar_index + 100,
pvSHHBuffer);
//
// LOW ...
CopyBuffer(
mpvHandler,
X_PV_SLL_LINE,
bar_index,
bar_index + 100,
pvSLLBuffer);
//
// MEIUM ...
//
// HIGH ...
CopyBuffer(
mpvHandler,
X_PV_MHH_LINE,
bar_index,
bar_index + 100,
pvMHHBuffer);
//
// LOW ...
CopyBuffer(
mpvHandler,
X_PV_MLL_LINE,
bar_index,
bar_index + 100,
pvMLLBuffer);
//
// LONG ...
//
// HIGH ...
CopyBuffer(
mpvHandler,
X_PV_LHH_LINE,
bar_index,
bar_index + 100,
pvLHHBuffer);
//
// LOW ...
CopyBuffer(
mpvHandler,
X_PV_LLL_LINE,
bar_index,
bar_index + 100,
pvLLLBuffer);
//
// HIND ...
//
// HIGH ...
CopyBuffer(
mpvHandler,
X_PV_HHH_LINE,
bar_index,
bar_index + 100,
pvHHHBuffer);
//
// LOW ...
CopyBuffer(
mpvHandler,
X_PV_HLL_LINE,
bar_index,
bar_index + 100,
pvHLLBuffer);
//
XPVHLPFindPivotPoints();
}
//
// END Handler Functions ...
//
//
// START Helper Functions ...
//
//
// Check isPeak ...
bool XPVHLPIsPeak(int bar_index)
{
//
bool result = false;
//
if (!XPVHLPIsValidArraySize(bar_index))
{
return result;
}
//
result = pvRBuffer[bar_index] == pvHHHBuffer[bar_index] &&
pvHHHBuffer[bar_index] == pvLHHBuffer[bar_index] &&
pvLHHBuffer[bar_index] == pvMHHBuffer[bar_index] &&
pvMHHBuffer[bar_index] == pvSHHBuffer[bar_index];
//
return result;
}
//
// Check isVale ...
bool XPVHLPIsVale(int bar_index)
{
//
bool result = false;
//
if (!XPVHLPIsValidArraySize(bar_index))
{
return result;
}
//
result = pvSBuffer[bar_index] == pvHLLBuffer[bar_index] &&
pvHLLBuffer[bar_index] == pvLLLBuffer[bar_index] &&
pvLLLBuffer[bar_index] == pvMLLBuffer[bar_index] &&
pvMLLBuffer[bar_index] == pvSLLBuffer[bar_index];
//
return result;
}
//
// Is Strong Support ...
bool XPVHLPIsStrongSupport(int bar_index)
{
//
bool result = false;
//
if (!XPVHLPIsValidArraySize(bar_index + 3))
{
return result;
}
//
result =
//
pvHLLBuffer[bar_index + 1] == pvHLLBuffer[bar_index + 2] &&
pvHLLBuffer[bar_index + 2] == pvHLLBuffer[bar_index + 3] &&
//
pvLLLBuffer[bar_index + 1] == pvLLLBuffer[bar_index + 2] &&
pvLLLBuffer[bar_index + 2] == pvLLLBuffer[bar_index + 3] &&
//
pvMLLBuffer[bar_index + 1] == pvMLLBuffer[bar_index + 2] &&
pvMLLBuffer[bar_index + 2] == pvMLLBuffer[bar_index + 3] &&
//
pvSLLBuffer[bar_index + 1] == pvSLLBuffer[bar_index + 2] &&
pvSLLBuffer[bar_index + 2] == pvSLLBuffer[bar_index + 3]
//
;
//
return result;
}
//
// Is Strong Resistance ...
bool XPVHLPIsStrongResistance(int bar_index)
{
//
bool result = false;
//
if (!XPVHLPIsValidArraySize(bar_index + 2))
{
return result;
}
//
result =
//
pvHHHBuffer[bar_index + 1] == pvHHHBuffer[bar_index + 2] &&
pvHHHBuffer[bar_index + 2] == pvHHHBuffer[bar_index + 3] &&
//
pvLHHBuffer[bar_index + 1] == pvLHHBuffer[bar_index + 2] &&
pvLHHBuffer[bar_index + 2] == pvLHHBuffer[bar_index + 3] &&
//
pvMHHBuffer[bar_index + 1] == pvMHHBuffer[bar_index + 2] &&
pvMHHBuffer[bar_index + 2] == pvMHHBuffer[bar_index + 3] &&
//
pvSHHBuffer[bar_index + 1] == pvSHHBuffer[bar_index + 2] &&
pvSHHBuffer[bar_index + 2] == pvSHHBuffer[bar_index + 3]
//
;
//
return result;
}
//
// Retrieve Highs ...
double XPVHLPGetMaxHH(int bar_index)
{
//
double result = 0;
//
if (!XPVHLPIsValidArraySize(bar_index))
{
return result;
}
//
result = MathMax(pvSHHBuffer[bar_index], pvMHHBuffer[bar_index]);
result = MathMax(result, pvLHHBuffer[bar_index]);
result = MathMax(result, pvHHHBuffer[bar_index]);
//
return result;
}
double XPVHLPGetMinHH(int bar_index)
{
//
double result = 0;
//
if (!XPVHLPIsValidArraySize(bar_index))
{
return result;
}
//
result = MathMin(pvSHHBuffer[bar_index], pvMHHBuffer[bar_index]);
result = MathMin(result, pvLHHBuffer[bar_index]);
result = MathMin(result, pvHHHBuffer[bar_index]);
//
return result;
}
//
// Retrieve Lows ...
double XPVHLPGetMaxLL(int bar_index)
{
//
double result = 0;
//
if (!XPVHLPIsValidArraySize(bar_index))
{
return result;
}
//
result = MathMax(pvSLLBuffer[bar_index], pvMLLBuffer[bar_index]);
result = MathMax(result, pvLLLBuffer[bar_index]);
result = MathMax(result, pvHLLBuffer[bar_index]);
//
return result;
}
double XPVHLPGetMinLL(int bar_index)
{
//
double result = 0;
//
if (!XPVHLPIsValidArraySize(bar_index))
{
return result;
}
//
result = MathMin(pvSLLBuffer[bar_index], pvMLLBuffer[bar_index]);
result = MathMin(result, pvLLLBuffer[bar_index]);
result = MathMin(result, pvHLLBuffer[bar_index]);
//
return result;
}
//
bool XPVHLPIsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(pvRBuffer);
result = rCount > bar_index + 1;
//
return result;
}
//
// SUPPORT and RESISTANCE ...
//
// Find Pivot Areas in PV ...
void XPVHLPFindPivotPoints()
{
//
double smoothingPoint = 3;
int verifications = 26;
//
// FLATS ...
double tmpFlats[];
int tmpFlatsCount = 0;
//
// PEAKS and VALES ...
//
// R ...
FindSameValueInBuffer(
tmpFlats,
pvRBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// S ...
FindSameValueInBuffer(
tmpFlats,
pvSBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// CYCLES ...
//
// SHORT ...
// LEVEL 1 ...
//
// HH ...
FindSameValueInBuffer(
tmpFlats,
pvSHHBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// LL ...
FindSameValueInBuffer(
tmpFlats,
pvSLLBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// MEDIUM ...
// LEVEL 2 ...
//
// HH ...
FindSameValueInBuffer(
tmpFlats,
pvMHHBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// LL ...
FindSameValueInBuffer(
tmpFlats,
pvMLLBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// LONG ...
// LEVEL 3 ...
//
// HH ...
FindSameValueInBuffer(
tmpFlats,
pvLHHBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// LL ...
FindSameValueInBuffer(
tmpFlats,
pvLLLBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// HINDMOST ...
// LEVEL 4 ...
//
// HH ...
FindSameValueInBuffer(
tmpFlats,
pvHHHBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// LL ...
FindSameValueInBuffer(
tmpFlats,
pvHLLBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// PEAKS and VALES ...
//
// PEAKS ...
FindSameValueInBuffer(
tmpFlats,
pvPBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
//
// VALES ...
FindSameValueInBuffer(
tmpFlats,
pvVBuffer);
tmpFlatsCount = ArraySize(tmpFlats);
if (tmpFlatsCount > 0)
{
//
AddsIfNotExists(
tmpFlats,
pvPivots,
smoothingPoint);
//
Clean(tmpFlats);
}
}
//
// Extract Support and Resistances ...
XOHCLSupRes XPVHLPFindCandleSupprtAndResistance(
int bar_index, // Bar Index ...
int count = 3 // Number of Requireds ...
)
{
//
XOHCLSupRes result = ExtractSupportAndResistance(
bar_index,
pvPivots,
count,
_Symbol,
_Period);
//
return result;
}
//
// END Helper Functions ...
//
@@ -0,0 +1,324 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XATRSL Indicator Provider
// Description: ATR Stop Loss ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XPeaksAndVales Exported Buffers ...
enum ENUM_X_XATRSL_BUFFERS
{
//
X_ATRSL_UP_LINE = 0,
X_ATRSL_DOWN_LINE = 1,
X_ATRSL_SAR_LINE = 2,
X_ATRSL_RMA_LINE = 3,
X_ATRSL_WMA_LINE = 4,
X_ATRSL_MA1_LINE = 5,
X_ATRSL_SMA_LINE = 6,
X_ATRSL_EMA_LINE = 7,
X_ATRSL_ATR_LINE = 8,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXATRSLHelper
{
//
public:
//
// Properties ...
double upBuffer[];
double downBuffer[];
double sarBuffer[];
double rmaBuffer[];
double wmaBuffer[];
double ma1Buffer[];
double smaBuffer[];
double emaBuffer[];
double atrBuffer[];
//
// Constructor ...
void XSCXATRSLHelper() {
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXATRSLHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// MARKET ...
int length = 14, // Length
double step = 0.02, // Increment Step
double maximum = 0.2, // Maximum
ENUM_APPLIED_PRICE highAppliedTo = PRICE_HIGH, // High Line Applied To
ENUM_APPLIED_PRICE lowAppliedTo = PRICE_LOW // Low Line Applied To
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// MARKET ...
mLength = length;
mStep = step;
mMaximum = maximum;
mHighAppliedTo = highAppliedTo;
mLowAppliedTo = lowAppliedTo;
//
mTag = "XATRSL " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xatrsl",
//
// Inputs ...
//
// MARKET ...
"",
mLength,
mStep,
mMaximum,
mHighAppliedTo,
mLowAppliedTo,
//
// PRESENTATION ...
"",
false,
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
ArraySetAsSeries(upBuffer, true);
ArraySetAsSeries(downBuffer, true);
ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(rmaBuffer, true);
ArraySetAsSeries(wmaBuffer, true);
ArraySetAsSeries(ma1Buffer, true);
ArraySetAsSeries(smaBuffer, true);
ArraySetAsSeries(emaBuffer, true);
ArraySetAsSeries(atrBuffer, true);
}
//
// DeConstructor ...
void ~XSCXATRSLHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// UP ...
CopyBuffer(
mHandler,
X_ATRSL_UP_LINE,
0,
mNumberOfItemsReadPerTick,
upBuffer);
//
// DOWN ...
CopyBuffer(
mHandler,
X_ATRSL_DOWN_LINE,
0,
mNumberOfItemsReadPerTick,
downBuffer);
//
// SAR ...
CopyBuffer(
mHandler,
X_ATRSL_SAR_LINE,
0,
mNumberOfItemsReadPerTick,
sarBuffer);
//
// RMA ...
CopyBuffer(
mHandler,
X_ATRSL_RMA_LINE,
0,
mNumberOfItemsReadPerTick,
rmaBuffer);
//
// WMA ...
CopyBuffer(
mHandler,
X_ATRSL_WMA_LINE,
0,
mNumberOfItemsReadPerTick,
wmaBuffer);
//
// MA1 ...
CopyBuffer(
mHandler,
X_ATRSL_MA1_LINE,
0,
mNumberOfItemsReadPerTick,
ma1Buffer);
//
// MA 1 ...
CopyBuffer(
mHandler,
X_ATRSL_SMA_LINE,
0,
mNumberOfItemsReadPerTick,
smaBuffer);
//
// EMA ...
CopyBuffer(
mHandler,
X_ATRSL_EMA_LINE,
0,
mNumberOfItemsReadPerTick,
emaBuffer);
//
// ATR ...
CopyBuffer(
mHandler,
X_ATRSL_ATR_LINE,
0,
mNumberOfItemsReadPerTick,
atrBuffer);
}
//
// START Tools Functions ...
//
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
// MARKET ...
//
// Length ...
int mLength;
//
// Increment Step ...
double mStep;
//
// Maximum ...
double mMaximum;
//
// High Line Applied To ...
ENUM_APPLIED_PRICE mHighAppliedTo;
//
// Low Line Applied To ...
ENUM_APPLIED_PRICE mLowAppliedTo;
//
string mTag;
//
int mHandler;
};
@@ -0,0 +1,215 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XHikenAshi Indicator Provider
// Description: Provides Features ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XHikenAshi Exported Buffers ...
enum ENUM_X_HIKENASHI_BUFFERS
{
//
X_HK_OPEN_LINE = 0,
X_HK_HIGH_LINE = 1,
X_HK_LOW_LINE = 2,
X_HK_CLOSE_LINE = 3,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXHKHelper
{
//
public:
//
// Properties ...
double openBuffer[];
double highBuffer[];
double lowBuffer[];
double closeBuffer[];
//
// Constructor ...
void XSCXHKHelper() {
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXHKHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
mTag = "XHK " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xhk",
//
// Inputs ...
"",
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
ArraySetAsSeries(openBuffer, true);
ArraySetAsSeries(highBuffer, true);
ArraySetAsSeries(lowBuffer, true);
ArraySetAsSeries(closeBuffer, true);
}
//
// DeConstructor ...
void ~XSCXHKHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// OPEN ...
CopyBuffer(
mHandler,
X_HK_OPEN_LINE,
0,
mNumberOfItemsReadPerTick,
openBuffer);
//
// HIGH ...
CopyBuffer(
mHandler,
X_HK_HIGH_LINE,
0,
mNumberOfItemsReadPerTick,
highBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_HK_LOW_LINE,
0,
mNumberOfItemsReadPerTick,
lowBuffer);
//
// CLOSE ...
CopyBuffer(
mHandler,
X_HK_CLOSE_LINE,
0,
mNumberOfItemsReadPerTick,
closeBuffer);
}
//
// START Tools Functions ...
//
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
string mTag;
//
int mHandler;
};
@@ -0,0 +1,690 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XIchimoku Indicator Provider
// Description: Provides Features ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// 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
};
//
// Ichimoku Indicator Exported Buffers ...
enum ENUM_X_ICHIMOKU_BUFFERS
{
//
X_TENKANSEN_LINE = 0,
X_KIJUNSEN_LINE = 1,
X_CHIKOUSPAN_LINE = 4,
X_SENKOUSPAN_A_LINE = 5,
X_SENKOUSPAN_B_LINE = 6,
};
//
// Model Ichimoku Data ...
struct XIchiInfo
{
//
int bar;
//
double tenkanSen;
double kijunSen;
//
double senkouSpanA;
double senkouSpanB;
//
double senkouSpanAFuture;
double senkouSpanBFuture;
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXICHHelper
{
//
// Public ...
public:
//
// Properties ...
double tenkanSenBuffer[];
double kijunSenBuffer[];
double chikouSpanBuffer[];
double senkouSpanABuffer[];
double senkouSpanBBuffer[];
//
// Constructor ...
void XSCXICHHelper()
{
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXICHHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// TenkanSen ...
int tenkanSenLength = 9,
ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE,
//
// KijunSen ...
int kijunSenLength = 26,
ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE,
//
// Senkou Span B ...
int senkouSpanBLength = 52,
ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE,
//
// Chikou Span ...
ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// TenkanSen ...
mKijunSenMode = kijunSenMode;
mKijunSenLength = kijunSenLength;
//
// KijunSen ...
mTenkanSenMode = tenkanSenMode;
mTenkanSenLength = tenkanSenLength;
//
// Senkou Span B ...
mSenkouSpanBMode = senkouSpanBMode;
mSenkouSpanBLength = senkouSpanBLength;
//
mSenkouSpanBTopMode = NULL;
mSenkouSpanBBottomMode = NULL;
//
// Chikou Span ...
mChikuoSpanAppliedTo = chikuoSpanAppliedTo;
//
mTag = "XICH " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xich",
//
// Inputs ...
//
// TENKANSEN ...
"",
mTenkanSenLength,
mTenkanSenMode,
//
// KIJUNSEN ...
"",
kijunSenLength,
kijunSenMode,
//
// SENKOUSPANB ...
"",
senkouSpanBLength,
senkouSpanBMode,
//
// CHIKOUSPAN ...
"",
mChikuoSpanAppliedTo,
//
// PRESENTATION ...
"",
false,
false,
false,
false,
false,
false,
false,
false,
true // Shift Kumo ...
//
);
if (mHandler == INVALID_HANDLE)
{
//
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
ArraySetAsSeries(tenkanSenBuffer, true);
ArraySetAsSeries(kijunSenBuffer, true);
ArraySetAsSeries(chikouSpanBuffer, true);
ArraySetAsSeries(senkouSpanABuffer, true);
ArraySetAsSeries(senkouSpanBBuffer, true);
}
//
// DeConstructor ...
void ~XSCXICHHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// TENKANSEN ...
CopyBuffer(
mHandler,
X_TENKANSEN_LINE,
0,
mNumberOfItemsReadPerTick,
tenkanSenBuffer);
//
// KIJUNSEN ...
CopyBuffer(
mHandler,
X_KIJUNSEN_LINE,
0,
mNumberOfItemsReadPerTick,
kijunSenBuffer);
//
// CHIKOUSPAN ...
CopyBuffer(
mHandler,
X_CHIKOUSPAN_LINE,
mKijunSenLength - 1,
mNumberOfItemsReadPerTick,
chikouSpanBuffer);
//
// SENKOUSPANA ...
CopyBuffer(
mHandler,
X_SENKOUSPAN_A_LINE,
-mKijunSenLength + 1,
mNumberOfItemsReadPerTick,
senkouSpanABuffer);
//
// SENKOUSPANB ...
CopyBuffer(
mHandler,
X_SENKOUSPAN_B_LINE,
-mKijunSenLength + 1,
mNumberOfItemsReadPerTick,
senkouSpanBBuffer);
}
//
// START Tools Functions ...
//
//
// Retrieve Ichimoku Data at Specific Bar Index ...
XIchiInfo GetInfo(
int bar_index // Bar Index ...
)
{
//
XIchiInfo result = {};
//
result.bar = bar_index;
result.tenkanSen = tenkanSenBuffer[bar_index];
result.kijunSen = kijunSenBuffer[bar_index];
result.senkouSpanA = senkouSpanABuffer[bar_index + mKijunSenLength];
result.senkouSpanB = senkouSpanBBuffer[bar_index + mKijunSenLength];
result.senkouSpanAFuture = senkouSpanABuffer[bar_index];
result.senkouSpanBFuture = senkouSpanBBuffer[bar_index];
//
return result;
}
//
// Check Tenkan Sen Over Kijun Sen ...
bool IsTenkanSenOverKijunSen(
int bar_index // Bar Index ...
) {
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result =
//
tenkanSenBuffer[bar_index] > kijunSenBuffer[bar_index]
//
;
//
return result;
}
//
// Is Tenkan Sen Under Kijun Sen ...
bool IsTenkanSenUnderKijunSen(
int bar_index // Bar Index ...
) {
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result =
//
tenkanSenBuffer[bar_index] < kijunSenBuffer[bar_index]
//
;
//
return result;
}
//
// Tenkan Sen Croosed Over Kijun Sen ...
bool IsTenkanSenCrossedOverKijunSen(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 2))
{
return result;
}
//
result = IsCrossOver(
tenkanSenBuffer,
kijunSenBuffer,
bar_index);
//
return result;
}
//
// Tenkan Sen Croosed Under Kijun Sen ...
bool IsTenkanSenCrossedUnderKijunSen(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 2))
{
return result;
}
//
result = IsCrossUnder(
tenkanSenBuffer,
kijunSenBuffer,
bar_index);
//
return result;
}
//
// Check Kumo is Bullish ...
bool IsKumoBullish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
int start = 0;
//
if (!onFuture)
{
start = (mKijunSenLength - bar_index);
}
else
{
start = (mKijunSenLength - bar_index) * 2;
}
//
if (!IsValidArraySize(start))
{
return result;
}
//
result =
//
senkouSpanABuffer[start + 1] > senkouSpanBBuffer[start + 1] &&
senkouSpanABuffer[start] > senkouSpanBBuffer[start]
//
;
//
return result;
}
//
// Check Kumo is Bearish ...
bool IsKumoBearish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
int start = 0;
//
if (!onFuture)
{
start = (mKijunSenLength - bar_index);
}
else
{
start = (mKijunSenLength - bar_index) * 2;
}
//
if (!IsValidArraySize(start))
{
return result;
}
//
result =
//
senkouSpanABuffer[start + 1] < senkouSpanBBuffer[start + 1] &&
senkouSpanABuffer[start] < senkouSpanBBuffer[start]
//
;
//
return result;
}
//
// Check Kumo is Change to Bullish ...
bool IsKumoSwitchedToBullish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
int start = 0;
//
if (!onFuture)
{
start = (mKijunSenLength - bar_index);
}
else
{
start = (mKijunSenLength - bar_index) * 2;
}
//
if (!IsValidArraySize(start))
{
return result;
}
//
result =
//
senkouSpanABuffer[start + 1] > senkouSpanBBuffer[start + 1] &&
senkouSpanABuffer[start] <= senkouSpanBBuffer[start]
//
;
//
return result;
}
//
// Check Kumo is Change to Bearish ...
bool IsKumoSwitchedToBearish(
int bar_index, // Bar Index ...
bool onFuture = false // Future Check ...
)
{
//
bool result = false;
//
int start = 0;
//
if (!onFuture)
{
start = (mKijunSenLength - bar_index);
}
else
{
start = (mKijunSenLength - bar_index) * 2;
}
//
if (!IsValidArraySize(start))
{
return result;
}
//
result =
//
senkouSpanABuffer[start + 1] < senkouSpanBBuffer[start + 1] &&
senkouSpanABuffer[start] >= senkouSpanBBuffer[start]
//
;
//
return result;
}
//
// Check Ichimokou Common Conditions for Long Trades ...
// TenkanSen > Kumo
// KijunSen > Kumo
// ChikouSpan > Kumo
// Kumo has Good Body
bool CheckCommonLongConditions() {
//
bool result = false;
//
// TODO: Complete this ...
//
return result;
}
//
// Check Ichimoku Common Conditions for Short Trades ...
// TenkanSen < Kumo
// KijunSen < Kumo
// ChikouSpan < Kumo
// Kumo has Good Body
bool CheckCommonShortConditions() {
//
bool result = false;
//
// TODO: Complete this ...
//
return result;
}
//
// END Tools Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
// TenkanSen ...
int mTenkanSenLength;
ENUM_X_ICHIMOKU_CALCULATION_MODE mTenkanSenMode;
//
// KijunSen ...
int mKijunSenLength;
ENUM_X_ICHIMOKU_CALCULATION_MODE mKijunSenMode;
//
// Senkou Span B ...
int mSenkouSpanBLength;
ENUM_X_ICHIMOKU_CALCULATION_MODE mSenkouSpanBMode;
//
ENUM_SERIESMODE mSenkouSpanBTopMode;
ENUM_SERIESMODE mSenkouSpanBBottomMode;
//
// Chikou Span ...
ENUM_APPLIED_PRICE mChikuoSpanAppliedTo;
//
string mTag;
//
int mHandler;
//
bool IsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(tenkanSenBuffer);
result = rCount > bar_index + 1;
//
return result;
}
};
@@ -0,0 +1,418 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XMC Indicator Provider
// Description: Provides Features ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XMC Exported Buffers ...
enum ENUM_X_XMC_BUFFERS
{
//
X_MC_FAST_LINE = 0,
X_MC_SLOW_LINE = 1,
X_MC_VERIFIER_LINE = 2,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXMCHelper
{
//
public:
//
// Properties ...
double fastBuffer[];
double slowBuffer[];
double verifierBuffer[];
//
// Constructor ...
void XSCXMCHelper() {
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXMCHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// FAST ...
int fastMaLength = 9,
int fastMaShift = 0,
ENUM_MA_METHOD fastMaMethod = MODE_EMA,
ENUM_APPLIED_PRICE fastMaAppliedTo = PRICE_CLOSE,
//
// SLOW ...
int slowMaLength = 18,
int slowMaShift = 0,
ENUM_MA_METHOD slowMaMethod = MODE_EMA,
ENUM_APPLIED_PRICE slowMaAppliedTo = PRICE_CLOSE,
//
// VERIFIER ...
int verifierMaLength = 50,
int verifierMaShift = 0,
ENUM_MA_METHOD verifierMaMethod = MODE_EMA,
ENUM_APPLIED_PRICE verifierMaAppliedTo = PRICE_CLOSE
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// FAST ...
mFastMaLength = fastMaLength;
mFastMaShift = fastMaShift;
mFastMaMethod = fastMaMethod;
mFastMaAppliedTo = fastMaAppliedTo;
//
// SLOW ...
mSlowMaLength = slowMaLength;
mSlowMaShift = slowMaShift;
mSlowMaMethod = slowMaMethod;
mSlowMaAppliedTo = slowMaAppliedTo;
//
// VERIFIER ...
mVerifierMaLength = verifierMaLength;
mVerifierMaShift = verifierMaShift;
mVerifierMaMethod = verifierMaMethod;
mVerifierMaAppliedTo = verifierMaAppliedTo;
//
mTag = "XMC " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xmc",
//
// Inputs ...
//
// FAST ...
"",
mFastMaLength,
mFastMaShift,
mFastMaMethod,
mFastMaAppliedTo,
//
// SLOW ...
"",
mSlowMaLength,
mSlowMaShift,
mSlowMaMethod,
mSlowMaAppliedTo,
//
// VERIFIER ...
"",
mVerifierMaLength,
mVerifierMaShift,
mVerifierMaMethod,
mVerifierMaAppliedTo,
//
"",
false,
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
ArraySetAsSeries(fastBuffer, true);
ArraySetAsSeries(slowBuffer, true);
ArraySetAsSeries(verifierBuffer, true);
}
//
// DeConstructor ...
void ~XSCXMCHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// FAST ...
CopyBuffer(
mHandler,
X_MC_FAST_LINE,
0,
mNumberOfItemsReadPerTick,
fastBuffer);
//
// SLOW ...
CopyBuffer(
mHandler,
X_MC_SLOW_LINE,
0,
mNumberOfItemsReadPerTick,
slowBuffer);
//
// VERIFIER ...
CopyBuffer(
mHandler,
X_MC_VERIFIER_LINE,
0,
mNumberOfItemsReadPerTick,
verifierBuffer);
}
//
// START Tools Functions ...
//
//
// Check Fast Over Slow ...
bool IsFastOverSlow(
int bar_index // Bar Index ...
) {
//
bool result = false;
//
if (!IsValidArraySize(bar_index)) {
return result;
}
//
result =
//
IsOver(
fastBuffer,
slowBuffer,
bar_index
)
//
;
//
return result;
}
//
// Check Fast Crossed Over Slow ...
bool IsFastCrossedOverSlow(
int bar_index // Bar Index ...
) {
//
bool result = false;
//
if (!IsValidArraySize(bar_index)) {
return result;
}
//
result =
//
IsCrossOver(
fastBuffer,
slowBuffer,
bar_index
)
//
;
//
return result;
}
//
// Check Fast Under Slow ...
bool IsFastUnderSlow(
int bar_index // Bar Index ...
) {
//
bool result = false;
//
if (!IsValidArraySize(bar_index)) {
return result;
}
//
result =
//
IsUnder(
fastBuffer,
slowBuffer,
bar_index
)
//
;
//
return result;
}
//
// Check Fast Crossed Under Slow ...
bool IsFastCrossedUnderSlow(
int bar_index // Bar Index ...
) {
//
bool result = false;
//
if (!IsValidArraySize(bar_index)) {
return result;
}
//
result =
//
IsCrossUnder(
fastBuffer,
slowBuffer,
bar_index
)
//
;
//
return result;
}
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
// FAST ...
int mFastMaLength;
int mFastMaShift;
ENUM_MA_METHOD mFastMaMethod;
ENUM_APPLIED_PRICE mFastMaAppliedTo;
//
// SLOW ...
int mSlowMaLength;
int mSlowMaShift;
ENUM_MA_METHOD mSlowMaMethod;
ENUM_APPLIED_PRICE mSlowMaAppliedTo;
//
// VERIFIER ...
int mVerifierMaLength;
int mVerifierMaShift;
ENUM_MA_METHOD mVerifierMaMethod;
ENUM_APPLIED_PRICE mVerifierMaAppliedTo;
//
string mTag;
//
int mHandler;
//
bool IsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(fastBuffer);
result = rCount > bar_index + 1;
//
return result;
}
};
@@ -0,0 +1,575 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XPPSR Indicator Provider
// Description: Provides Features ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XPERIOD Calculation Method ...
// USED For Multiple Time Frames ...
enum ENUM_X_PERIOD_METHOD
{
//
X_PERIOD_NOTHING,
//
X_PERIOD_AUTO,
//
X_PERIOD_MANUALLY
};
//
// XPPSR Exported Buffers ...
enum ENUM_X_XPPSR_BUFFERS
{
//
// LEVEL 1 ...
X_PPSR_L1_R_LINE = 0,
X_PPSR_L1_R1_LINE = 1,
X_PPSR_L1_R2_LINE = 2,
X_PPSR_L1_S_LINE = 3,
X_PPSR_L1_S1_LINE = 4,
X_PPSR_L1_S2_LINE = 5,
//
// LEVEL 2 ...
X_PPSR_L2_R_LINE = 6,
X_PPSR_L2_R1_LINE = 7,
X_PPSR_L2_R2_LINE = 8,
X_PPSR_L2_S_LINE = 9,
X_PPSR_L2_S1_LINE = 10,
X_PPSR_L2_S2_LINE = 11,
//
// LEVEL 3 ...
X_PPSR_L3_R_LINE = 12,
X_PPSR_L3_R1_LINE = 13,
X_PPSR_L3_R2_LINE = 14,
X_PPSR_L3_S_LINE = 15,
X_PPSR_L3_S1_LINE = 16,
X_PPSR_L3_S2_LINE = 17,
//
// LEVEL 4 ...
X_PPSR_L4_R_LINE = 18,
X_PPSR_L4_R1_LINE = 19,
X_PPSR_L4_R2_LINE = 20,
X_PPSR_L4_S_LINE = 21,
X_PPSR_L4_S1_LINE = 22,
X_PPSR_L4_S2_LINE = 23,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXPPSRHelper
{
//
public:
//
// Properties ...
//
// LEVEL 1 ...
double l1RBuffer[];
double l1R1Buffer[];
double l1R2Buffer[];
double l1SBuffer[];
double l1S1Buffer[];
double l1S2Buffer[];
//
// LEVEL 2 ...
double l2RBuffer[];
double l2R1Buffer[];
double l2R2Buffer[];
double l2SBuffer[];
double l2S1Buffer[];
double l2S2Buffer[];
//
// LEVEL 3 ...
double l3RBuffer[];
double l3R1Buffer[];
double l3R2Buffer[];
double l3SBuffer[];
double l3S1Buffer[];
double l3S2Buffer[];
//
// LEVEL 4 ...
double l4RBuffer[];
double l4R1Buffer[];
double l4R2Buffer[];
double l4SBuffer[];
double l4S1Buffer[];
double l4S2Buffer[];
//
// Constructor ...
void XSCXPPSRHelper()
{
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXPPSRHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// LEVEL 1 ...
ENUM_X_PERIOD_METHOD l1Method = X_PERIOD_AUTO,
ENUM_TIMEFRAMES l1Period = NULL,
ENUM_SERIESMODE l1HHMode = MODE_HIGH,
ENUM_SERIESMODE l1LLMode = MODE_LOW,
//
// LEVEL 2 ...
ENUM_X_PERIOD_METHOD l2Method = X_PERIOD_AUTO,
ENUM_TIMEFRAMES l2Period = NULL,
ENUM_SERIESMODE l2HHMode = MODE_HIGH,
ENUM_SERIESMODE l2LLMode = MODE_LOW,
//
// LEVEL 3 ...
ENUM_X_PERIOD_METHOD l3Method = X_PERIOD_AUTO,
ENUM_TIMEFRAMES l3Period = NULL,
ENUM_SERIESMODE l3HHMode = MODE_HIGH,
ENUM_SERIESMODE l3LLMode = MODE_LOW,
//
// LEVEL 4 ...
ENUM_X_PERIOD_METHOD l4Method = X_PERIOD_AUTO,
ENUM_TIMEFRAMES l4Period = NULL,
ENUM_SERIESMODE l4HHMode = MODE_HIGH,
ENUM_SERIESMODE l4LLMode = MODE_LOW
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// LEVEL 1 ...
mL1Method = l1Method;
mL1Period = l1Period;
mL1HHMode = l1HHMode;
mL1LLMode = l1LLMode;
//
// LEVEL 2 ...
mL2Method = l2Method;
mL2Period = l2Period;
mL2HHMode = l2HHMode;
mL2LLMode = l2LLMode;
//
// LEVEL 3 ...
mL3Method = l3Method;
mL3Period = l3Period;
mL3HHMode = l3HHMode;
mL3LLMode = l3LLMode;
//
// LEVEL 4 ...
mL4Method = l4Method;
mL4Period = l4Period;
mL4HHMode = l4HHMode;
mL4LLMode = l4LLMode;
//
mTag = "XPPSR " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xppsr",
//
// Inputs ...
//
// LEVEL 1 ...
"",
mL1Method,
mL1Period,
mL1HHMode,
mL1LLMode,
//
// LEVEL 2 ...
"",
mL2Method,
mL2Period,
mL2HHMode,
mL2LLMode,
//
// LEVEL 3 ...
"",
mL3Method,
mL3Period,
mL3HHMode,
mL3LLMode,
//
// LEVEL 4 ...
"",
mL4Method,
mL4Period,
mL4HHMode,
mL4LLMode,
//
"",
"",
false,
false,
false,
false,
"",
false,
false,
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
// LEVEL 1 ...
ArraySetAsSeries(l1RBuffer, true);
ArraySetAsSeries(l1R1Buffer, true);
ArraySetAsSeries(l1R2Buffer, true);
ArraySetAsSeries(l1SBuffer, true);
ArraySetAsSeries(l1S1Buffer, true);
ArraySetAsSeries(l1S2Buffer, true);
//
// LEVEL 2 ...
ArraySetAsSeries(l2RBuffer, true);
ArraySetAsSeries(l2R1Buffer, true);
ArraySetAsSeries(l2R2Buffer, true);
ArraySetAsSeries(l2SBuffer, true);
ArraySetAsSeries(l2S1Buffer, true);
ArraySetAsSeries(l2S2Buffer, true);
//
// LEVEL 3 ...
ArraySetAsSeries(l3RBuffer, true);
ArraySetAsSeries(l3R1Buffer, true);
ArraySetAsSeries(l3R2Buffer, true);
ArraySetAsSeries(l3SBuffer, true);
ArraySetAsSeries(l3S1Buffer, true);
ArraySetAsSeries(l3S2Buffer, true);
//
// LEVEL 4 ...
ArraySetAsSeries(l4RBuffer, true);
ArraySetAsSeries(l4R1Buffer, true);
ArraySetAsSeries(l4R2Buffer, true);
ArraySetAsSeries(l4SBuffer, true);
ArraySetAsSeries(l4S1Buffer, true);
ArraySetAsSeries(l4S2Buffer, true);
}
//
// DeConstructor ...
void ~XSCXPPSRHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// LEVEL 1 ...
CopyBuffer(
mHandler,
X_PPSR_L1_R_LINE,
0,
mNumberOfItemsReadPerTick,
l1RBuffer);
CopyBuffer(
mHandler,
X_PPSR_L1_R1_LINE,
0,
mNumberOfItemsReadPerTick,
l1R1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L1_R2_LINE,
0,
mNumberOfItemsReadPerTick,
l1R2Buffer);
CopyBuffer(
mHandler,
X_PPSR_L1_S_LINE,
0,
mNumberOfItemsReadPerTick,
l1SBuffer);
CopyBuffer(
mHandler,
X_PPSR_L1_S1_LINE,
0,
mNumberOfItemsReadPerTick,
l1S1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L1_S2_LINE,
0,
mNumberOfItemsReadPerTick,
l1S2Buffer);
//
// LEVEL 2 ...
CopyBuffer(
mHandler,
X_PPSR_L2_R_LINE,
0,
mNumberOfItemsReadPerTick,
l2RBuffer);
CopyBuffer(
mHandler,
X_PPSR_L2_R1_LINE,
0,
mNumberOfItemsReadPerTick,
l2R1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L2_R2_LINE,
0,
mNumberOfItemsReadPerTick,
l2R2Buffer);
CopyBuffer(
mHandler,
X_PPSR_L2_S_LINE,
0,
mNumberOfItemsReadPerTick,
l2SBuffer);
CopyBuffer(
mHandler,
X_PPSR_L2_S1_LINE,
0,
mNumberOfItemsReadPerTick,
l2S1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L2_S2_LINE,
0,
mNumberOfItemsReadPerTick,
l2S2Buffer);
//
// LEVEL 3 ...
CopyBuffer(
mHandler,
X_PPSR_L3_R_LINE,
0,
mNumberOfItemsReadPerTick,
l3RBuffer);
CopyBuffer(
mHandler,
X_PPSR_L3_R1_LINE,
0,
mNumberOfItemsReadPerTick,
l3R1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L3_R2_LINE,
0,
mNumberOfItemsReadPerTick,
l3R2Buffer);
CopyBuffer(
mHandler,
X_PPSR_L3_S_LINE,
0,
mNumberOfItemsReadPerTick,
l3SBuffer);
CopyBuffer(
mHandler,
X_PPSR_L3_S1_LINE,
0,
mNumberOfItemsReadPerTick,
l3S1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L3_S2_LINE,
0,
mNumberOfItemsReadPerTick,
l3S2Buffer);
//
// LEVEL 4 ...
CopyBuffer(
mHandler,
X_PPSR_L4_R_LINE,
0,
mNumberOfItemsReadPerTick,
l4RBuffer);
CopyBuffer(
mHandler,
X_PPSR_L4_R1_LINE,
0,
mNumberOfItemsReadPerTick,
l4R1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L4_R2_LINE,
0,
mNumberOfItemsReadPerTick,
l4R2Buffer);
CopyBuffer(
mHandler,
X_PPSR_L4_S_LINE,
0,
mNumberOfItemsReadPerTick,
l4SBuffer);
CopyBuffer(
mHandler,
X_PPSR_L4_S1_LINE,
0,
mNumberOfItemsReadPerTick,
l4S1Buffer);
CopyBuffer(
mHandler,
X_PPSR_L4_S2_LINE,
0,
mNumberOfItemsReadPerTick,
l4S2Buffer);
}
//
// START Tools Functions ...
//
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
// LEVEL 1 ...
ENUM_X_PERIOD_METHOD mL1Method;
ENUM_TIMEFRAMES mL1Period;
ENUM_SERIESMODE mL1HHMode;
ENUM_SERIESMODE mL1LLMode;
//
// LEVEL 2 ...
ENUM_X_PERIOD_METHOD mL2Method;
ENUM_TIMEFRAMES mL2Period;
ENUM_SERIESMODE mL2HHMode;
ENUM_SERIESMODE mL2LLMode;
//
// LEVEL 3 ...
ENUM_X_PERIOD_METHOD mL3Method;
ENUM_TIMEFRAMES mL3Period;
ENUM_SERIESMODE mL3HHMode;
ENUM_SERIESMODE mL3LLMode;
//
// LEVEL 4 ...
ENUM_X_PERIOD_METHOD mL4Method;
ENUM_TIMEFRAMES mL4Period;
ENUM_SERIESMODE mL4HHMode;
ENUM_SERIESMODE mL4LLMode;
//
string mTag;
//
int mHandler;
//
bool IsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(l1RBuffer);
result = rCount > bar_index + 1;
//
return result;
}
};
@@ -0,0 +1,707 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XPV Indicator Provider
// Description: Peaks and Vales ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XPeaksAndVales Exported Buffers ...
enum ENUM_X_XPV_BUFFERS
{
//
// PEAKSANDVALES ...
X_PV_P_LINE = 0,
X_PV_V_LINE = 1,
//
// SUPPORTRESISTANCE ...
X_PV_R_LINE = 2,
X_PV_S_LINE = 4,
//
// SHORT ...
X_PV_SHH_LINE = 6,
X_PV_SLL_LINE = 7,
//
// MEDIUM ...
X_PV_MHH_LINE = 8,
X_PV_MLL_LINE = 9,
//
// LONG ...
X_PV_LHH_LINE = 10,
X_PV_LLL_LINE = 11,
//
// HIND ...
X_PV_HHH_LINE = 12,
X_PV_HLL_LINE = 13,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXPVHelper
{
//
public:
//
// Properties ...
double pBuffer[];
double vBuffer[];
double rBuffer[];
double sBuffer[];
double sHHBuffer[];
double sLLBuffer[];
double mHHBuffer[];
double mLLBuffer[];
double lHHBuffer[];
double lLLBuffer[];
double hHHBuffer[];
double hLLBuffer[];
//
// Constructor ...
void XSCXPVHelper()
{
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXPVHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// MARKET ...
int shortLength = 9,
int mediumLength = 17,
int longLength = 26,
int hindLength = 35,
//
// TREND ...
int numOfShoulder = 10,
//
// DETECTION ...
ENUM_SERIESMODE hhMode = MODE_HIGH,
ENUM_SERIESMODE llMode = MODE_LOW
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// MARKET ...
mShortLength = shortLength;
mMediumLength = mediumLength;
mLongLength = longLength;
mHindLength = hindLength;
//
// TREND ...
mNumOfShoulder = numOfShoulder;
//
// DETECTION ...
mHhMode = hhMode;
mLlMode = llMode;
//
mTag = "XPV " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xpv",
//
// Inputs ...
//
// MARKET ...
"",
mShortLength,
mMediumLength,
mLongLength,
mHindLength,
//
// TREND ...
"",
mNumOfShoulder,
//
// DETECTION ...
"",
mHhMode,
mLlMode,
//
"",
false,
false,
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
// PEAKSANDVALES ...
ArraySetAsSeries(pBuffer, true);
ArraySetAsSeries(vBuffer, true);
//
// RESISTANCESUPPORT ...
ArraySetAsSeries(rBuffer, true);
ArraySetAsSeries(sBuffer, true);
//
// SHORT ...
ArraySetAsSeries(sHHBuffer, true);
ArraySetAsSeries(sLLBuffer, true);
//
// MEDIUM ...
ArraySetAsSeries(mHHBuffer, true);
ArraySetAsSeries(mLLBuffer, true);
//
// LONG ...
ArraySetAsSeries(lHHBuffer, true);
ArraySetAsSeries(lLLBuffer, true);
//
// HIND ...
ArraySetAsSeries(lHHBuffer, true);
ArraySetAsSeries(lLLBuffer, true);
}
//
// DeConstructor ...
void ~XSCXPVHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// PEAKS ...
CopyBuffer(
mHandler,
X_PV_P_LINE,
0,
mNumberOfItemsReadPerTick,
pBuffer);
//
// VALES ...
CopyBuffer(
mHandler,
X_PV_V_LINE,
0,
mNumberOfItemsReadPerTick,
vBuffer);
//
// R ...
CopyBuffer(
mHandler,
X_PV_R_LINE,
0,
mNumberOfItemsReadPerTick,
rBuffer);
//
// S ...
CopyBuffer(
mHandler,
X_PV_S_LINE,
0,
mNumberOfItemsReadPerTick,
sBuffer);
//
// SHORT ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_SHH_LINE,
0,
mNumberOfItemsReadPerTick,
sHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_SLL_LINE,
0,
mNumberOfItemsReadPerTick,
sLLBuffer);
//
// MEIUM ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_MHH_LINE,
0,
mNumberOfItemsReadPerTick,
mHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_MLL_LINE,
0,
mNumberOfItemsReadPerTick,
mLLBuffer);
//
// LONG ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_LHH_LINE,
0,
mNumberOfItemsReadPerTick,
lHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_LLL_LINE,
0,
mNumberOfItemsReadPerTick,
lLLBuffer);
//
// HIND ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_HHH_LINE,
0,
mNumberOfItemsReadPerTick,
hHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_HLL_LINE,
0,
mNumberOfItemsReadPerTick,
hLLBuffer);
}
//
// START Tools Functions ...
//
//
// Check isPeak ...
bool IsPeak(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result = rBuffer[bar_index] == hHHBuffer[bar_index] &&
hHHBuffer[bar_index] == lHHBuffer[bar_index] &&
lHHBuffer[bar_index] == mHHBuffer[bar_index] &&
mHHBuffer[bar_index] == sHHBuffer[bar_index];
//
return result;
}
//
// Check isVale ...
bool IsVale(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result = sBuffer[bar_index] == hLLBuffer[bar_index] &&
hLLBuffer[bar_index] == lLLBuffer[bar_index] &&
lLLBuffer[bar_index] == mLLBuffer[bar_index] &&
mLLBuffer[bar_index] == sLLBuffer[bar_index];
//
return result;
}
//
// Is Strong Support ...
bool IsStrongSupport(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 3))
{
return result;
}
//
result =
//
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]
//
;
//
return result;
}
//
// Is Strong Resistance ...
bool IsStrongResistance(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 2))
{
return result;
}
//
result =
//
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]
//
;
//
return result;
}
//
// Find Last Strong Support ...
double GetLastStrongSupport(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
double result = 0;
//
bool isBarIndexSupport = IsStrongSupport(bar_index);
if (isBarIndexSupport)
{
length += bar_index;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (IsStrongSupport(i))
{
//
result = sLLBuffer[i];
break;
}
}
//
return result;
}
//
// Find Last Strong Resistance ...
double GetLastStrongResistance(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
double result = 0;
//
bool isBarIndexResistance = IsStrongResistance(bar_index);
if (isBarIndexResistance)
{
length += bar_index;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (IsStrongResistance(i))
{
//
result = sHHBuffer[i];
break;
}
}
//
return result;
}
//
// Find Strong Support Break Stop ...
bool IsSupportBreakedStop(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
bool result = false;
//
bool isBaIndexSupport = IsStrongSupport(bar_index);
if (isBaIndexSupport)
{
return result;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
bool isAllStrongSupport = true;
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (!IsStrongSupport(i) && isAllStrongSupport)
{
//
isAllStrongSupport = false;
break;
}
}
//
result = !isBaIndexSupport && isAllStrongSupport;
//
return result;
}
//
// Find Strong Resistance Break Stop ...
bool IsResistanceBreakedStop(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
bool result = false;
//
bool isBaIndexResistance = IsStrongResistance(bar_index);
if (isBaIndexResistance)
{
return result;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
bool isAllStrongResistance = true;
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (!IsStrongResistance(i) && isAllStrongResistance)
{
//
isAllStrongResistance = false;
break;
}
}
//
result = !isBaIndexResistance && isAllStrongResistance;
//
return result;
}
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
// MARKET ...
int mShortLength;
int mMediumLength;
int mLongLength;
int mHindLength;
//
// TREND ...
int mNumOfShoulder;
//
// DETECTION ...
ENUM_SERIESMODE mHhMode;
ENUM_SERIESMODE mLlMode;
//
string mTag;
//
int mHandler;
//
bool IsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(rBuffer);
result = rCount > bar_index + 1;
//
return result;
}
};
@@ -0,0 +1,332 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XSSLC Indicator Provider
// Description: SSL Channel ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XPeaksAndVales Exported Buffers ...
enum ENUM_X_XSSLC_BUFFERS
{
//
X_SSLC_UP_LINE = 0,
X_SSLC_DOWN_LINE = 1,
X_SSLC_UP_MA_LINE = 2,
X_SSLC_DOWN_MA_LINE = 3,
X_SSLC_KPI_LINE = 4,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXSSLCHelper
{
//
public:
//
// Properties ...
double upBuffer[];
double downBuffer[];
double kpiBuffer[];
//
// Constructor ...
void XSCXSSLCHelper()
{
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXSSLCHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// MARKET ...
int length = 10, // Length
//
// CALCULATION ...
ENUM_MA_METHOD method = MODE_SMA, // Method
ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH, // Up Applied To
ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW // Down Applied To
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// MARKET ...
mLength = length;
//
// CALCULATION ...
mMethod = method;
mUpAppliedTo = upAppliedTo;
mDownAppliedTo = downAppliedTo;
//
mTag = "XSSLC " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xsslc",
//
// Inputs ...
//
// MARKET ...
"",
mLength,
//
// CALCULATION ...
"",
mMethod,
mUpAppliedTo,
mDownAppliedTo,
//
// PRESENTATION ...
"",
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
ArraySetAsSeries(upBuffer, true);
ArraySetAsSeries(downBuffer, true);
ArraySetAsSeries(kpiBuffer, true);
}
//
// DeConstructor ...
void ~XSCXSSLCHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// UP ...
CopyBuffer(
mHandler,
X_SSLC_UP_LINE,
0,
mNumberOfItemsReadPerTick,
upBuffer);
//
// DOWN ...
CopyBuffer(
mHandler,
X_SSLC_DOWN_LINE,
0,
mNumberOfItemsReadPerTick,
downBuffer);
//
// KPI ...
CopyBuffer(
mHandler,
X_SSLC_KPI_LINE,
0,
mNumberOfItemsReadPerTick,
kpiBuffer);
}
//
// START Tools Functions ...
//
//
// Check Up Buffer Crossed Over Down ...
bool IsUpCrossedOverDown(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 1))
{
return result;
}
//
result =
//
upBuffer[bar_index] > downBuffer[bar_index] &&
upBuffer[bar_index + 1] <= downBuffer[bar_index + 1]
//
;
//
return result;
}
//
// Check Up Buffer Crossed Under Down ...
bool IsUpCrossedUnderDown(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 1))
{
return result;
}
//
result =
//
upBuffer[bar_index] < downBuffer[bar_index] &&
upBuffer[bar_index + 1] >= downBuffer[bar_index + 1]
//
;
//
return result;
}
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
// MARKET ...
//
// Length ...
int mLength;
//
// CALCULATION ...
//
// Method ...
ENUM_MA_METHOD mMethod;
//
// Up Applied To
ENUM_APPLIED_PRICE mUpAppliedTo;
//
// Down Applied To
ENUM_APPLIED_PRICE mDownAppliedTo;
//
string mTag;
//
int mHandler;
//
bool IsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(upBuffer);
result = rCount > bar_index + 1;
//
return result;
}
};
@@ -0,0 +1,469 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XTRND Indicator Provider
// Description: Trend Finder ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XPeaksAndVales Exported Buffers ...
enum ENUM_X_XTRND_BUFFERS
{
//
X_TRND_UP_LINE = 0,
X_TRND_UP_STATE_LINE = 1,
//
X_TRND_DOWN_LINE = 2,
X_TRND_DOWN_STATE_LINE = 3,
};
//
// Trend State at unique Bar ...
enum ENUM_X_XTRND_STATE
{
X_TRND_STATE_RANGE = 0,
X_TRND_STATE_CONSOLIDATION = 1,
X_TRND_STATE_UP = 2,
X_TRND_STATE_DOWN = 3,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXTRNDHelper
{
//
public:
//
// Properties ...
double upBuffer[];
double upStateBuffer[];
double downBuffer[];
double downStateBuffer[];
//
// Constructor ...
void XSCXTRNDHelper()
{
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXTRNDHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// MARKET ...
int cycleLength = 2, // Cycle Length to Check
int numberOfVerifications = 2, // Number of Verifications
//
// CALCULATION ...
ENUM_SERIESMODE hhMode = MODE_HIGH, // Detect Up
ENUM_SERIESMODE llMode = MODE_LOW // Detect Low
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// MARKET ...
mCycleLength = cycleLength;
mNumberOfVerifications = numberOfVerifications;
//
// CALCULATIONS ...
mHHMode = hhMode;
mLLMode = llMode;
//
mTag = "XTRND " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xtrnd",
//
// Inputs ...
//
// MARKET ...
"",
mCycleLength,
mNumberOfVerifications,
//
// CALCULATIONS ...
"",
mHHMode,
mLLMode,
//
// PRESENTATION ...
"",
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
ArraySetAsSeries(upBuffer, true);
ArraySetAsSeries(upStateBuffer, true);
ArraySetAsSeries(downBuffer, true);
ArraySetAsSeries(downStateBuffer, true);
}
//
// DeConstructor ...
void ~XSCXTRNDHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// UP ...
CopyBuffer(
mHandler,
X_TRND_UP_LINE,
0,
mNumberOfItemsReadPerTick,
upBuffer);
//
// UP STATE ...
CopyBuffer(
mHandler,
X_TRND_UP_STATE_LINE,
0,
mNumberOfItemsReadPerTick,
upStateBuffer);
//
// DOWN ...
CopyBuffer(
mHandler,
X_TRND_DOWN_LINE,
0,
mNumberOfItemsReadPerTick,
downBuffer);
//
// DOWN STATE ...
CopyBuffer(
mHandler,
X_TRND_DOWN_STATE_LINE,
0,
mNumberOfItemsReadPerTick,
downStateBuffer);
}
//
// START Tools Functions ...
//
//
// Detect Trend Up ...
bool IsTrendBullish(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result =
//
upStateBuffer[bar_index] == X_TRND_STATE_UP &&
downStateBuffer[bar_index] == X_TRND_STATE_UP
//
;
//
return result;
}
//
// Detect Trend Switched Up ...
bool IsTrendSwitchedBullish(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 1))
{
return result;
}
//
result =
//
IsTrendBullish(bar_index) &&
!IsTrendBullish(bar_index + 1)
//
;
//
return result;
}
//
// Detect Trend Down ...
bool IsTrendBearish(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result =
//
upStateBuffer[bar_index] == X_TRND_STATE_DOWN &&
downStateBuffer[bar_index] == X_TRND_STATE_DOWN
//
;
//
return result;
}
//
// Detect Trend Switched Down ...
bool IsTrendSwitchedBearish(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 1))
{
return result;
}
//
result =
//
IsTrendBearish(bar_index) &&
!IsTrendBearish(bar_index + 1)
//
;
//
return result;
}
//
// Detect Trend Consolidation ...
bool IsTrendConsolidation(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result =
//
(upStateBuffer[bar_index] == X_TRND_STATE_RANGE ||
upStateBuffer[bar_index] == X_TRND_STATE_CONSOLIDATION)
//
&&
//
(downStateBuffer[bar_index] == X_TRND_STATE_RANGE ||
downStateBuffer[bar_index] == X_TRND_STATE_CONSOLIDATION)
//
;
//
return result;
}
//
// Detect Trend Switched Consolidation ...
bool IsTrendSwitchedConsolidation(
int bar_index // Bar Index ...
)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 1))
{
return result;
}
//
result =
//
IsTrendConsolidation(bar_index) &&
!IsTrendConsolidation(bar_index + 1)
//
;
//
return result;
}
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
string mTag;
//
int mHandler;
//
// INPUTS ...
//
// MARKET ...
//
// Cycle Length to Check ...
int mCycleLength;
//
// Number of Verifications ...
int mNumberOfVerifications;
//
// CALCULATIONS ...
//
// Detect Up ...
ENUM_SERIESMODE mHHMode;
//
// Detect Low ...
ENUM_SERIESMODE mLLMode;
//
bool IsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(upBuffer);
result = rCount > bar_index + 1;
//
return result;
}
};
@@ -0,0 +1,367 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XAMA Indicator
// ---------------------------------------------
// Name: XAMA
// Description: Trend Magic 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 XAMA Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XAMA"
//
// XAMA Indicator States ...
enum ENUM_X_XAMA_STATES
{
X_XAMA_BULLISH = 1,
X_XAMA_BEARISH = -1,
X_XAMA_NEUTURAL = 0,
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Makret";
input int length = 52; // Period
input int fastEMA = 2; // Fast EMA Period
input int slowEMA = 30; // Slow EMA Period
input int maShift = 0; // Shift
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
//
input group "Presentation";
input bool showLine = true; // Show Line
//
// END Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 1
//
// maBuffer ...
#define maBufferIndex 0
#define maColorBufferIndex 1
#define stateBufferIndex 2
double maBuffer[];
double maColorBuffer[];
double stateBuffer[];
#property indicator_label1 "XAMA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLime, clrGray, clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
int maHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// Initializing MA Handler ...
maHandler = iAMA(
_Symbol,
_Period,
length,
fastEMA,
slowEMA,
maShift,
appliedTo);
if (maHandler == INVALID_HANDLE)
{
//
string message = "Error Initializing Ma Handler ...";
LogMessage(message);
//
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(maHandler);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(fastEMA, slowEMA);
maxLength = MathMax(maxLength, length);
//
// Check Calculated Bars ...
int maCalculatedBars = BarsCalculated(maHandler);
if (maCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
if (copiedMas <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Do Buffers Calculation ...
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (length >= 2)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
//
string maBufferLabel = "XAMA " + "(" + (string)length + ")";
//
// Ma Buffer ...
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
//
// Ma Color Buffer ...
ArraySetAsSeries(maColorBuffer, true);
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
//
// State Buffer ...
ArraySetAsSeries(stateBuffer, true);
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", "(", length, ")");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(int bar_index)
{
//
// Requirements ...
XOHCL candle = GetCandle(bar_index);
//
double maValue = maBuffer[bar_index];
//
double lineColorIndex =
maValue < candle.low ? 0 : maValue > candle.high ? 2
: 1;
//
// Define State Value ...
// lineColorIndex == 0 => Bullish => 1;
// lineColorIndex == 1 => Neutural => 0;
// lineColorIndex == 2 => Bearish => -1;
double stateValue =
lineColorIndex == 0 ? X_XAMA_BULLISH : lineColorIndex == 2 ? X_XAMA_BEARISH
: X_XAMA_NEUTURAL;
//
// Set Ma Buffer Color Index ...
maColorBuffer[bar_index] = lineColorIndex;
//
// Set State Buffer Value ...
stateBuffer[bar_index] = stateValue;
}
//
// END Functions ...
//
@@ -0,0 +1,765 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_ATRSL ATR Indicator
// ---------------------------------------------------
// Name: X121_ATRSL
// Description: ATR StopLoss Finer
// Market Analysor ...
//
//
// 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_ATRSL Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_ATRSL"
//
// Available Smoothing Methods ...
enum X_XATRSL_SMOOTHING_METHOD
{
X_ATRSL_SMOOTHING_RMA = 0, // RMA
X_ATRSL_SMOOTHING_SMA = 1, // SMA
X_ATRSL_SMOOTHING_EMA = 2, // EMA
X_ATRSL_SMOOTHING_WMA = 3, // WMA
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 14; // Length
input double step = 0.02; // Increment Step
input double maximum = 0.2; // Maximum
input ENUM_APPLIED_PRICE highAppliedTo = PRICE_HIGH; // High Line Applied To
input ENUM_APPLIED_PRICE lowAppliedTo = PRICE_LOW; // Low Line Applied To
//
input group "Presentation";
input bool showHigh = true; // Show High
input bool showLow = true; // Show Low
input bool showSar = true; // Show PSar
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 3
//
// PLOTTED Buffers ...
//
// HIGH ...
#define highBufferIndex 0
double highBuffer[];
//
#property indicator_label1 "X121_ATRSL H"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLightGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// LOW ...
#define lowBufferIndex 1
double lowBuffer[];
//
#property indicator_label2 "X121_ATRSL L"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrLightGray
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// SAR ...
#define sarBufferIndex 2
double sarBuffer[];
//
#property indicator_label3 "X121_ATRSL SAR"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrGold
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// DATA Buffers ...
//
// RMA ...
#define rmaBufferIndex 3
double rmaBuffer[];
//
// WMA ...
#define wmaBufferIndex 4
double wmaBuffer[];
//
// WMA CALCULATIONS ...
//
// MA 1 ...
#define ma1BufferIndex 5
double ma1Buffer[];
//
// MA P ...
#define maPBufferIndex 6
double maPBuffer[];
//
// EMA P ...
#define emaPBufferIndex 7
double emaPBuffer[];
//
// ATR ...
#define atrBufferIndex 8
double atrBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
double smoothFactor;
//
// WMA ...
int ma1Handler = INVALID_HANDLE;
int maPHandler = INVALID_HANDLE;
ENUM_APPLIED_PRICE wmaAppliedTo = PRICE_CLOSE;
//
// EMA ...
int emaPHandler = INVALID_HANDLE;
//
// ATR ...
int atrHandler = INVALID_HANDLE;
//
// SAR ...
int sarHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = 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();
//
// Calculate RMA and WMA Smooth Factoir ...
smoothFactor = 1.0 / length;
//
// Define Index Buffers ...
DefineBuffers();
//
// Initialize Handlers ...
if (!InitialHandlers())
{
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
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(sarHandler);
IndicatorRelease(atrHandler);
IndicatorRelease(ma1Handler);
IndicatorRelease(maPHandler);
IndicatorRelease(emaPHandler);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
int sarCalculatedBars = BarsCalculated(sarHandler);
int atrCalculatedBars = BarsCalculated(atrHandler);
int ma1CalculatedBars = BarsCalculated(ma1Handler);
int maPCalculatedBars = BarsCalculated(maPHandler);
int emaPCalculatedBars = BarsCalculated(emaPHandler);
if (sarCalculatedBars < maxLength ||
atrCalculatedBars < maxLength ||
ma1CalculatedBars < maxLength ||
maPCalculatedBars < maxLength ||
emaPCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
int copiedMa1s = CopyBuffer(ma1Handler, 0, 0, limit, ma1Buffer);
int copiedMaPs = CopyBuffer(maPHandler, 0, 0, limit, maPBuffer);
int copiedEMaPs = CopyBuffer(emaPHandler, 0, 0, limit, emaPBuffer);
if (copiedSars <= 0 ||
copiedAtrs <= 0 ||
copiedMa1s <= 0 ||
copiedMaPs <= 0 ||
copiedEMaPs <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Determines First Calculation ...
bool isFirstBar = ((limit == rates_total) &&
i == rates_total - 1);
//
CalculateBuffers(
i,
isFirstBar,
limit,
rates_total,
prev_calculated,
open,
high,
low,
close
//
);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
// Validate Inputs ...
(length > 2 &&
step > 0 &&
maximum > step)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Max ...
result = MathMax(result, length);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// HIGH ...
ENUM_DRAW_TYPE highDrawType = showHigh ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(highBuffer, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
PlotIndexSetDouble(highBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(highBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(highBufferIndex, PLOT_DRAW_TYPE, highDrawType);
//
// LOW ...
ENUM_DRAW_TYPE lowDrawType = showLow ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(lowBuffer, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
PlotIndexSetDouble(lowBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(lowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(lowBufferIndex, PLOT_DRAW_TYPE, lowDrawType);
//
// SAR ...
ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(sarBuffer, true);
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA);
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType);
//
// DATA Buffers ...
//
// RMA ...
ArraySetAsSeries(rmaBuffer, true);
SetIndexBuffer(rmaBufferIndex, rmaBuffer, INDICATOR_CALCULATIONS);
//
// MA 1 ...
ArraySetAsSeries(ma1Buffer, true);
SetIndexBuffer(ma1BufferIndex, ma1Buffer, INDICATOR_CALCULATIONS);
//
// MA P ...
ArraySetAsSeries(maPBuffer, true);
SetIndexBuffer(maPBufferIndex, maPBuffer, INDICATOR_CALCULATIONS);
//
// WMA ...
ArraySetAsSeries(wmaBuffer, true);
SetIndexBuffer(wmaBufferIndex, wmaBuffer, INDICATOR_DATA);
//
// ATR ...
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
}
//
// Initialize WMA Required Handlers ...
bool InitialHandlers()
{
//
bool result = false;
//
// MA 1 ...
ma1Handler = iMA(
_Symbol,
_Period,
1, // Lenght of MA 1 ...
0,
MODE_SMA,
wmaAppliedTo);
//
// MA P ...
maPHandler = iMA(
_Symbol,
_Period,
length,
0,
MODE_SMA,
wmaAppliedTo);
//
// EMA P ...
emaPHandler = iMA(
_Symbol,
_Period,
length,
0,
MODE_EMA,
wmaAppliedTo);
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
length);
//
// SAR ...
sarHandler = iSAR(
_Symbol,
_Period,
step,
maximum);
//
result =
//
sarHandler != INVALID_HANDLE &&
atrHandler != INVALID_HANDLE &&
ma1Handler != INVALID_HANDLE &&
maPHandler != INVALID_HANDLE &&
emaPHandler != INVALID_HANDLE
//
;
//
// Log Error Message if Initialization Failed ...
if (!result)
{
LogMessage("Error in Initializing Indicator ...");
}
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
bool isFirstBar, // Determines First Bar
const int limit, // Limit Of Calculations
const int ratesTotal, // Total Rates
const int prevCalculated, // Prev Calculated Bars
const double &open[], // Open Price Series
const double &high[], // High Price Series
const double &low[], // Low Price Series
const double &close[] // Close Price Series
)
{
//
// RMA Calculation ...
//
double closeValue = close[bar_index];
double prevRMAValue = isFirstBar
? closeValue
: rmaBuffer[bar_index + 1];
//
double rmaValue = (closeValue * smoothFactor) + prevRMAValue * (1.0 - smoothFactor);
//
rmaBuffer[bar_index] = rmaValue;
//
// WMA Calculations ...
//
double maPValue = maPBuffer[bar_index];
double ma1Value = ma1Buffer[bar_index];
//
double wmaValue;
if (isFirstBar)
{
wmaValue = maPValue;
}
else
{
wmaValue = (ma1Value - wmaBuffer[bar_index + 1]) * smoothFactor + wmaBuffer[bar_index + 1];
}
//
wmaBuffer[bar_index] = wmaValue;
//
// CALCULATE Buffers ...
//
double atrValue = atrBuffer[bar_index];
double highSourcePrice = GetSourcePrice(
bar_index,
highAppliedTo,
open,
high,
low,
close);
double lowSourcePrice = GetSourcePrice(
bar_index,
lowAppliedTo,
open,
high,
low,
close);
//
// Retrieve SMoothing Value ...
// double smoothingValue = GetSmoothedValue(bar_index);
//
double smoothedATR = atrValue;
//
// HIGH ...
double highValue = highSourcePrice + smoothedATR;
highBuffer[bar_index] = highValue;
//
// LOW ...
double lowValue = lowSourcePrice - smoothedATR;
lowBuffer[bar_index] = lowValue;
}
//
// Retrieve Smoothed Value based on User Choice ...
double GetSmoothedValue(
int bar_index // Bar Index
)
{
//
double result = EMPTY_VALUE;
//
// switch (smoothingMethod)
// {
// //
// // RMA ...
// case X_ATRSL_SMOOTHING_RMA:
// result = rmaBuffer[bar_index];
// break;
// //
// // WMA ...
// case X_ATRSL_SMOOTHING_WMA:
// result = wmaBuffer[bar_index];
// break;
// //
// // EMA ...
// case X_ATRSL_SMOOTHING_EMA:
// result = emaPBuffer[bar_index];
// break;
// //
// // SMA ...
// case X_ATRSL_SMOOTHING_SMA:
// result = maPBuffer[bar_index];
// break;
// //
// default:
// result = maPBuffer[bar_index];
// break;
// }
//
return result;
}
//
// Retrive Which Price Selected By User as Source ...
double GetSourcePrice(
int bar_index, // BarIndex
ENUM_APPLIED_PRICE appliedPrice, // Selected Price Source
const double &open[], // Open Price Series
const double &high[], // High Price Series
const double &low[], // Low Price Series
const double &close[] // Close Price Series
)
{
//
double result = EMPTY_VALUE;
//
switch (appliedPrice)
{
//
// OPEN ...
case PRICE_OPEN:
result = open[bar_index];
break;
//
// HIGH ...
case PRICE_HIGH:
result = high[bar_index];
break;
//
// LOW ...
case PRICE_LOW:
result = low[bar_index];
break;
//
// CLOSE ...
default:
case PRICE_CLOSE:
result = close[bar_index];
break;
}
//
return result;
}
//
// END Functions ...
//
@@ -0,0 +1,481 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_CC Candle Styles
// ---------------------------------------------------
// Name: X121_CC
// Description: Candle Styles ...
// Market Analysor ...
//
//
// 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_CC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_CC"
//
// Holds an SnapShot of Charts Configuration ...
struct XChartStyle
{
//
// chart's ID ...
long chartId;
//
// chart's mode ...
ENUM_CHART_MODE mode;
//
// show bid line ...
bool showBidLine;
//
// show ask line ...
bool showAskLine;
//
// show grids on chart ...
bool showGrid;
//
// show volumes ...
bool showVolumes;
//
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
bool showTradeLevels;
//
// chart autoscroll ...
bool autoScroll;
//
// chart quick navigation state ...
bool quickNavigation;
//
// chart's foreground color ...
color foreGroundColor;
//
// chart's background color ...
color backGroundColor;
//
// Up Color ...
color upColor;
//
// Down Color ...
color downColor;
//
// Bullish color ...
color bullishColor;
//
// Bearish color ...
color bearishColor;
//
// grid color ...
color gridColor;
//
// bid line color ...
color bidLineColor;
//
// ask line color ...
color askLineColor;
//
// line mode and doji candlestick color ...
color lineColor;
//
// Color of stop order levels (Stop Loss and Take Profit) ...
color stopColor;
//
// volumes color ...
color volumesColor;
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Chart Style";
input color mUpColor = clrLime; // Up Color
input color mDownColor = clrRed; // Down Color
input color mLineColor = clrLime; // Line mode and Doji candlestick Color
input color mBearishColor = clrRed; // Bullish Color
input color mBullishColor = clrLime; // Bearish Color
input color mVolumesColor = clrGreen; // Volumes Color
//
input group "Presentation";
input bool showCandles = false; // Show Candles
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
XChartStyle chartStyle;
XChartStyle clearStyle;
bool hasChartConfig = false;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
drawPrefix = ShortName;
//
// 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();
//
// Apply Chart Style ...
ApplyCustomChartStyle();
//
// 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
//
RemoveDraws(drawPrefix);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// 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 = true;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
}
//
// Apply Custom Chart Style ...
void ApplyCustomChartStyle()
{
//
// Read Prev Applied Chart Style ans Store it ...
if (!hasChartConfig)
{
//
// Read Current Chart Config and Store it ...
ReadChartStyle();
//
// After Reading Current Chart Style ...
// we have to Save Configs and Change Styles ...
clearStyle = chartStyle;
//
clearStyle.upColor = CLR_NONE;
clearStyle.downColor = CLR_NONE;
clearStyle.lineColor = CLR_NONE;
clearStyle.volumesColor = CLR_NONE;
clearStyle.bullishColor = CLR_NONE;
clearStyle.bearishColor = CLR_NONE;
}
//
// Decide to Show or not Candles based on User Input ...
if (showCandles)
{
SetChartStyle(chartStyle);
}
else
{
SetChartStyle(clearStyle);
}
}
//
// Read Previous Chart Style ...
void ReadChartStyle()
{
//
if (hasChartConfig)
{
return;
}
//
// Retrieve Current Chart ID ...
long chartId = ChartID();
chartStyle.chartId = chartId;
//
// Retrieve Chart Mode ...
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
//
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
//
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
//
chartStyle.upColor = mUpColor;
chartStyle.downColor = mDownColor;
chartStyle.lineColor = mLineColor;
chartStyle.bearishColor = mBearishColor;
chartStyle.bullishColor = mBullishColor;
chartStyle.volumesColor = mVolumesColor;
}
//
// Set Chart Style ...
void SetChartStyle(
XChartStyle &mChartStyle // Chart Style to Apply
)
{
//
ApplyChartStyle(
mChartStyle.chartId,
mChartStyle.mode,
mChartStyle.showBidLine,
mChartStyle.showAskLine,
mChartStyle.showGrid,
mChartStyle.showVolumes,
mChartStyle.showTradeLevels,
mChartStyle.autoScroll,
mChartStyle.quickNavigation,
mChartStyle.foreGroundColor,
mChartStyle.backGroundColor,
mChartStyle.upColor,
mChartStyle.downColor,
mChartStyle.bullishColor,
mChartStyle.bearishColor,
mChartStyle.gridColor,
mChartStyle.bidLineColor,
mChartStyle.askLineColor,
mChartStyle.lineColor,
mChartStyle.stopColor,
mChartStyle.volumesColor);
}
//
// END Functions ...
//
@@ -0,0 +1,629 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCHE Indicator
// ---------------------------------------------
// Name: XCHE
// Description: Hull 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 XHull Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "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 Logging Library ...
#include "../Libraries/x-saherelm.models.lib.mq5"
//
// 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_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_DOT
//
// Short Exit 1 ...
#define shortExit1BufferIndex 1
double shortExit1Buffer[];
//
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color2 clrRed
//
// Long Exit 2 ...
#define longExit2BufferIndex 2
double longExit2Buffer[];
//
#property indicator_type3 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_color3 clrAqua
//
// Short Exit 2 ...
#define shortExit2BufferIndex 3
double shortExit2Buffer[];
//
#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_type5 DRAW_ARROW
#property indicator_color5 clrLime
//
// Short Exit 1 Start ...
#define shortExit1StartBufferIndex 5
double shortExit1StartBuffer[];
//
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrRed
//
// Long Exit 2 Start ...
#define longExit2StartBufferIndex 6
double longExit2StartBuffer[];
//
#property indicator_type7 DRAW_ARROW
#property indicator_color7 clrAqua
//
// Short Exit 2 Start ...
#define shortExit2StartBufferIndex 7
double shortExit2StartBuffer[];
//
#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
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
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,214 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCTimer Indicator
// ---------------------------------------------
// Name: XCTimer
// Description: Trend Magic 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 XCTimer Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XCTimer"
//
// END Constants ...
//
//
// START Inputs ...
//
input color clr = clrYellow;
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER;
//
// END Inputs ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
CreateIndicatorObject();
//
// 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
//
// Delete Object ...
ObjectDelete(0, ShortName);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
ArraySetAsSeries(time, true);
//
int m = int(time[0] + PeriodSeconds() - TimeCurrent());
int s = m % 60;
m = (m - s) / 60;
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp = "", _m = "", _s = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
if (m < 10)
_m = "0";
if (s < 10)
_s = "0";
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in " + _m + IntegerToString(m) + ":" + _s + IntegerToString(s);
//
ObjectSetInteger(0, ShortName, OBJPROP_COLOR, clr);
ObjectSetString(0, ShortName, OBJPROP_TEXT, objText);
ObjectSetInteger(0, ShortName, OBJPROP_FONTSIZE, 10);
ObjectSetString(0, ShortName, OBJPROP_FONT, "Courier");
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
void CreateIndicatorObject()
{
//
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
switch (corner)
{
case CORNER_LEFT_UPPER:
Anchor = ANCHOR_LEFT_UPPER;
break;
case CORNER_RIGHT_UPPER:
Anchor = ANCHOR_RIGHT_UPPER;
break;
case CORNER_LEFT_LOWER:
Anchor = ANCHOR_LEFT_LOWER;
break;
case CORNER_RIGHT_LOWER:
Anchor = ANCHOR_RIGHT_LOWER;
break;
}
//
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
}
//
// END Functions ...
//
@@ -0,0 +1,500 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_HK HikenAshi Candles
// ---------------------------------------------------
// Name: X121_HK
// Description: Hiken Ashi ...
// Market Analysor ...
//
//
// 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_HK Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_HK"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Presentation";
input bool drawCandles = true; // Draw Hiken Ashi Candle
input bool drawCandleLines = false; // Show HikenAshi Lines
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 13
#property indicator_plots 5
//
// PLOTTED Buffers ...
//
// Open ...
#define openBufferIndex 0
double openBuffer[];
//
// High ...
#define highBufferIndex 1
double highBuffer[];
//
// Low ...
#define lowBufferIndex 2
double lowBuffer[];
//
// Close ...
#define closeBufferIndex 3
double closeBuffer[];
//
// Candle Color ...
#define candleColorBufferIndex 4
double candleColorBuffer[];
//
#define candlesBufferIndex 0
//
#property indicator_label1 "X121_HK Open;X121_HK High;X121_HK Low;X121_HK Close"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrAqua, clrMagenta, CLR_NONE
//
#define openHKBufferIndex 5
#define openHKColorBufferIndex 6
double openHKBuffer[];
double openHKColorBuffer[];
//
#define openHKBufferPlotIndex 1
#property indicator_label2 "X121_HK O"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrAqua, clrMagenta, clrLightGray
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
#define highHKBufferIndex 7
#define highHKColorBufferIndex 8
double highHKBuffer[];
double highHKColorBuffer[];
//
#define highHKBufferPlotIndex 2
#property indicator_label3 "X121_HK H"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrAqua, clrMagenta, clrLightGray
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define lowHKBufferIndex 9
#define lowHKColorBufferIndex 10
double lowHKBuffer[];
double lowHKColorBuffer[];
//
#define lowHKBufferPlotIndex 3
#property indicator_label4 "X121_HK L"
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_color4 clrAqua, clrMagenta, clrLightGray
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
#define closeHKBufferIndex 11
#define closeHKColorBufferIndex 12
double closeHKBuffer[];
double closeHKColorBuffer[];
//
#define closeHKBufferPlotIndex 4
#property indicator_label5 "X121_HK C"
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_color5 clrAqua, clrMagenta, clrLightGray
#property indicator_style5 STYLE_DOT
#property indicator_width5 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;
}
//
logTag = 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();
//
// 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
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i, prev_calculated, rates_total, open, high, close, low);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Candles Color ...
ArraySetAsSeries(candleColorBuffer, true);
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
//
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(candleColorBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openBuffer, true);
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, false);
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highBuffer, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
//
// Close ...
ArraySetAsSeries(closeBuffer, true);
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, false);
//
// Low ...
ArraySetAsSeries(lowBuffer, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
//
// Open HK ...
ENUM_DRAW_TYPE openDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(openHKBuffer, true);
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_DRAW_TYPE, openDrawType);
//
ArraySetAsSeries(openHKColorBuffer, true);
SetIndexBuffer(openHKColorBufferIndex, openHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// High HK ...
ENUM_DRAW_TYPE highDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(highHKBuffer, true);
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_DRAW_TYPE, highDrawType);
//
ArraySetAsSeries(highHKColorBuffer, true);
SetIndexBuffer(highHKColorBufferIndex, highHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// Low HK ...
ENUM_DRAW_TYPE lowDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(lowHKBuffer, true);
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_DRAW_TYPE, lowDrawType);
//
ArraySetAsSeries(lowHKColorBuffer, true);
SetIndexBuffer(lowHKColorBufferIndex, lowHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// Close HK ...
ENUM_DRAW_TYPE closeDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(closeHKBuffer, true);
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_DRAW_TYPE, closeDrawType);
//
ArraySetAsSeries(closeHKColorBuffer, true);
SetIndexBuffer(closeHKColorBufferIndex, closeHKColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[])
{
//
double mPrevHKOpenValue;
double mPrevHKCloseValue;
//
if (ArraySize(open) <= bar_index + 1)
{
//
mPrevHKOpenValue = 0;
mPrevHKCloseValue = 0;
}
else
{
//
mPrevHKOpenValue = openBuffer[bar_index + 1];
mPrevHKCloseValue = closeBuffer[bar_index + 1];
}
//
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
//
openBuffer[bar_index] = mHKOpenValue;
highBuffer[bar_index] = mHKHighValue;
lowBuffer[bar_index] = mHKLowValue;
closeBuffer[bar_index] = mHKCloseValue;
//
double candleColorValue =
mHKOpenValue < mHKCloseValue ? 0 : 1;
//
candleColorBuffer[bar_index] = drawCandles ? candleColorValue : 2;
//
openHKBuffer[bar_index] = mHKOpenValue;
openHKColorBuffer[bar_index] = candleColorValue;
//
highHKBuffer[bar_index] = mHKHighValue;
highHKColorBuffer[bar_index] = candleColorValue;
//
lowHKBuffer[bar_index] = mHKLowValue;
lowHKColorBuffer[bar_index] = candleColorValue;
//
closeHKBuffer[bar_index] = mHKCloseValue;
closeHKColorBuffer[bar_index] = candleColorValue;
}
//
// END Functions ...
//
@@ -0,0 +1,587 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XHULL Indicator
// ---------------------------------------------
// Name: XHULL
// Description: Hull 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 XHull Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "XHULL"
//
// END Constants ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.models.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START XSCHULL Class Definition ...
//
//
// a Class For Hull Calculations ...
class XSCHull
{
//
public:
//
// Constructor ...
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
{
//
// These are a way above to assign Private variables at Construct time ...
}
//
// Deconstructor ...
~XSCHull()
{
ArrayFree(mData);
}
//
// Initial Hull ...
bool Init(
int mPeriod,
double mDivisor)
{
//
bool result = false;
//
mFullPeriod = (int)(mPeriod > 1 ? mPeriod : 1);
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (mDivisor > 1 ? mDivisor : 1) : 1);
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
//
mArraySize = -1;
mWeight1 = mWeight2 = mWeight3 = 1;
//
result = true;
//
return result;
}
//
// CalCulate Specific Value ...
double Calculate(
double value,
int i,
int bars)
{
//
double result = 0;
//
if (mArraySize < bars)
{
//
mArraySize = ArrayResize(mData, bars + 500);
if (mArraySize < bars)
return result;
}
//
mData[i].value = value;
if (i > mFullPeriod)
{
//
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
}
else
{
//
mData[i].wsum1 = mData[i].wsum2 =
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
{
//
if (w1 > 0)
{
//
mData[i].wsum1 += mData[i - k].value * w1;
mData[i].lsum1 += mData[i - k].value;
mWeight1 += w1;
}
//
mData[i].wsum2 += mData[i - k].value * w2;
mData[i].lsum2 += mData[i - k].value;
mWeight2 += w2;
}
}
//
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
//
if (i > mSqrtPeriod)
{
//
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
}
else
{
//
mData[i].wsum3 =
mData[i].lsum3 = mWeight3 = 0;
//
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
{
//
mData[i].wsum3 += mData[i - k].value3 * w3;
mData[i].lsum3 += mData[i - k].value3;
mWeight3 += w3;
}
}
//
result = mData[i].wsum3 / mWeight3;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
int mFullPeriod;
int mHalfPeriod;
int mSqrtPeriod;
int mArraySize;
double mWeight1;
double mWeight2;
double mWeight3;
//
XHullData mData[];
};
//
// END XSCHULL Class Definition ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 72; // Length
input double divisor = 2.0; // Divisor (Speed)
//
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 showUpZone = true; // Show Up Zone
input bool showDownZone = true; // Show Down Zone
//
// END Inputs ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 4
#property indicator_plots 4
//
// UP Zone ...
//
#define upZoneBufferIndex 0
#define upZoneColorBufferIndex 1
//
double upZoneBuffer[];
double upZoneColorBuffer[];
//
#property indicator_label1 "XHULL Up"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLightGray, clrAqua, clrMagenta
#property indicator_width1 1
//
// DOWN Zone ...
//
#define downZoneBufferIndex 2
#define downZoneColorBufferIndex 3
//
double downZoneBuffer[];
double downZoneColorBuffer[];
//
#property indicator_label2 "XHULL Down"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrLightGray, clrAqua, clrMagenta
#property indicator_width2 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
XSCHull *mUpZHull;
XSCHull *mDownZHull;
//
// 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();
//
// Make an Instance of Hull Class ...
//
mUpZHull = new XSCHull();
mUpZHull.Init(
length,
divisor);
//
mDownZHull = new XSCHull();
mDownZHull.Init(
length,
divisor);
//
// 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
//
delete mUpZHull;
delete mDownZHull;
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// 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++)
{
//
double upPrice = getPrice(
upAppliedTo,
open, high, low, close, i);
//
double downPrice = getPrice(
downAppliedTo,
open, high, low, close, i);
//
CalculateBuffers(
i,
rates_total,
upPrice,
downPrice);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
result =
length >= 9 &&
divisor >= 0.5;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
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()
{
//
// UP Zone ...
//
// Draw Type ...
ENUM_DRAW_TYPE upZoneDrawType = showUpZone ? DRAW_COLOR_LINE : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(upZoneBufferIndex, upZoneBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upZoneBufferIndex, PLOT_SHOW_DATA, showUpZone);
PlotIndexSetInteger(upZoneBufferIndex, PLOT_DRAW_TYPE, upZoneDrawType);
//
// Color Buffer ...
SetIndexBuffer(upZoneColorBufferIndex, upZoneColorBuffer, INDICATOR_COLOR_INDEX);
//
// DOWN Zone ...
//
// Draw Type ...
ENUM_DRAW_TYPE downZoneDrawType = showDownZone ? DRAW_COLOR_LINE : DRAW_NONE;
//
// Buffer ...
SetIndexBuffer(downZoneBufferIndex, downZoneBuffer, INDICATOR_DATA);
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_SHOW_DATA, showDownZone);
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_DRAW_TYPE, downZoneDrawType);
//
// Color Buffer ...
SetIndexBuffer(downZoneColorBufferIndex, downZoneColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
int ratesTotal, // Total Rates
double upPrice, // Up Price ...
double downPrice // Down Price ...
)
{
//
double upValue = mUpZHull.Calculate(
upPrice,
bar_index,
ratesTotal);
upZoneBuffer[bar_index] = upValue;
double upColorIDX = (bar_index > 0)
? (upZoneBuffer[bar_index] > upZoneBuffer[bar_index - 1])
? 1
: (upZoneBuffer[bar_index] < upZoneBuffer[bar_index - 1])
? 2
: upZoneColorBuffer[bar_index - 1]
: 0;
upZoneColorBuffer[bar_index] = upColorIDX;
//
double downValue = mDownZHull.Calculate(
downPrice,
bar_index,
ratesTotal);
downZoneBuffer[bar_index] = downValue;
double downColorIDX = (bar_index > 0)
? (downZoneBuffer[bar_index] > downZoneBuffer[bar_index - 1])
? 1
: (downZoneBuffer[bar_index] < downZoneBuffer[bar_index - 1])
? 2
: downZoneColorBuffer[bar_index - 1]
: 0;
downZoneColorBuffer[bar_index] = downColorIDX;
}
//
// END Functions ...
//
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,895 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_ICH Ichimoku
// -------------------------------------------------
// Name: X121_ICH
// Description:
// Market Analysor ...
//
//
// 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_ICH Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_ICH"
//
// 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 Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// 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 Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 8
//
// PLOTTED Buffers ...
//
// ICHIMOKU ...
//
// TENKANSEN ...
//
#define tenkanSenBufferIndex 0
double tenkanSenBuffer[];
//
#property indicator_label1 "X121_ICH Tenkan Sen"
#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_ICH Kijun Sen"
#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_ICH Kijun Sen +"
#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_ICH Kijun Sen -"
#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_ICH Chikou Span"
#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_ICH Senkou Span A"
#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_ICH Senkou Span B"
#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_ICH Kumo"
#property indicator_type8 DRAW_FILLING
#property indicator_color8 clrAqua, clrMagenta
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
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;
}
//
logTag = ShortName;
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();
//
// 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
//
RemoveDraws(drawPrefix);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// 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 =
//
// Validate Ichimoku Kinko Hyo ...
(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);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// 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;
//
return;
if (ArraySize(senkouABuffer) > bar_index + kijunSenLength + 1)
{
//
// Detect Koumo Switch ...
bool isKumoSwitchBullish =
//
senkouABuffer[bar_index + kijunSenLength] > senkouBBuffer[bar_index + kijunSenLength] &&
senkouABuffer[bar_index + kijunSenLength + 1] <= senkouBBuffer[bar_index + kijunSenLength + 1]
//
;
//
// Detect Koumo Switch ...
bool isKumoSwitchBearish =
//
senkouABuffer[bar_index + kijunSenLength] < senkouBBuffer[bar_index + kijunSenLength] &&
senkouABuffer[bar_index + kijunSenLength + 1] >= senkouBBuffer[bar_index + kijunSenLength + 1]
//
;
//
datetime time = iTime(
_Symbol,
_Period,
bar_index);
//
long chartID = ChartID();
//
if (isKumoSwitchBullish)
{
//
string vlName = "Kumo_Switch_Bullish_NOW" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrAqua,
STYLE_DASHDOT);
}
//
if (isKumoSwitchBearish)
{
//
string vlName = "Kumo_Switch_Bearish_NOW" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrMagenta,
STYLE_DASHDOT);
}
}
//
return;
if (ArraySize(senkouABuffer) > bar_index + 1)
{
//
// Detect Koumo Switch ...
bool isKumoSwitchBullish =
//
senkouABuffer[bar_index] > senkouBBuffer[bar_index] &&
senkouABuffer[bar_index + 1] <= senkouBBuffer[bar_index + 1]
//
;
//
// Detect Koumo Switch ...
bool isKumoSwitchBearish =
//
senkouABuffer[bar_index] < senkouBBuffer[bar_index] &&
senkouABuffer[bar_index + 1] >= senkouBBuffer[bar_index + 1]
//
;
//
datetime time = iTime(
_Symbol,
_Period,
bar_index);
//
long chartID = ChartID();
//
if (isKumoSwitchBullish)
{
//
string vlName = "Kumo_Switch_Bullish_FUTURE" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrAqua,
STYLE_DASHDOT);
}
//
if (isKumoSwitchBearish)
{
//
string vlName = "Kumo_Switch_Bearish_FUTURE" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
clrMagenta,
STYLE_DASHDOT);
}
}
}
//
// END Functions ...
//
@@ -0,0 +1,469 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_MC MA Cross Indicator
// ---------------------------------------------------
// Name: X121_MC
// Description: Moving Average Crosses
// Market Analysor ...
//
//
// 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_MC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_MC"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Fast";
input int fastMaLength = 9; // Length
input int fastMaShift = 0; // Shift
input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE fastMaAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Slow";
input int slowMaLength = 18; // Length
input int slowMaShift = 0; // Shift
input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE slowMaAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Verifier";
input int verifierMaLength = 50; // Length
input int verifierMaShift = 0; // Shift
input ENUM_MA_METHOD verifierMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE verifierMaAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Presentation";
input bool showFastMa = true; // Show Fast
input bool showSlowMa = true; // Show Slow
input bool showVerifierMa = true; // Show Verifier
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 3
//
// PLOTTED Buffers ...
//
// MA ...
//
// FAST ...
#define fastMaBufferIndex 0
double fastMaBuffer[];
//
#property indicator_label1 "X121_MC MA F"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// SLOW ...
#define slowMaBufferIndex 1
double slowMaBuffer[];
//
#property indicator_label2 "X121_MC MA S"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDarkOrange
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// VERIFIER ...
#define verifierMaBufferIndex 2
double verifierMaBuffer[];
//
#property indicator_label3 "X121_MC MA V"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrDarkBlue
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int fastMaHandler = INVALID_HANDLE;
int slowMaHandler = INVALID_HANDLE;
int verifierMaHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = 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();
//
// MA Initialization ...
//
// FAST ...
fastMaHandler = iMA(
_Symbol,
_Period,
fastMaLength,
fastMaShift,
fastMaMethod,
fastMaAppliedTo);
if (fastMaHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
return INIT_FAILED;
}
//
// SLOW ...
slowMaHandler = iMA(
_Symbol,
_Period,
slowMaLength,
slowMaShift,
slowMaMethod,
slowMaAppliedTo);
if (slowMaHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
return INIT_FAILED;
}
//
// VERIFIER ...
verifierMaHandler = iMA(
_Symbol,
_Period,
verifierMaLength,
verifierMaShift,
verifierMaMethod,
verifierMaAppliedTo);
if (verifierMaHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
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
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(fastMaHandler);
IndicatorRelease(slowMaHandler);
IndicatorRelease(verifierMaHandler);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
int fastMaCalculatedBars = BarsCalculated(fastMaHandler);
int slowMaCalculatedBars = BarsCalculated(slowMaHandler);
int verifierMaCalculatedBars = BarsCalculated(verifierMaHandler);
if (fastMaCalculatedBars < maxLength ||
slowMaCalculatedBars < maxLength ||
verifierMaCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedFastMas = CopyBuffer(fastMaHandler, 0, 0, limit, fastMaBuffer);
int copiedSlowMas = CopyBuffer(slowMaHandler, 0, 0, limit, slowMaBuffer);
int copiedVerifierMas = CopyBuffer(verifierMaHandler, 0, 0, limit, verifierMaBuffer);
if (copiedFastMas <= 0 ||
copiedSlowMas <= 0 ||
copiedVerifierMas <= 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 =
//
// Validate Ma ...
(fastMaLength > 2 &&
slowMaLength > fastMaLength &&
verifierMaLength > slowMaLength)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Ma ...
result = MathMax(result, fastMaLength);
result = MathMax(result, slowMaLength);
result = MathMax(result, verifierMaLength);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// MA ...
//
// FAST ...
ENUM_DRAW_TYPE fastMaDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(fastMaBuffer, true);
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastMaDrawType);
//
// SLOW ...
ENUM_DRAW_TYPE slowMaDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(slowMaBuffer, true);
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowMaDrawType);
//
// VERIFIER ...
ENUM_DRAW_TYPE verifierMaDrawType = showVerifierMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(verifierMaBuffer, true);
SetIndexBuffer(verifierMaBufferIndex, verifierMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_TYPE, verifierMaDrawType);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
}
//
// END Functions ...
//
@@ -0,0 +1,802 @@
/////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_MRB MA Ribbon Indicator
// -----------------------------------------------------
// Name: X121_MRB
// Description: Moving Average Ribbon
// Market Analysor ...
//
//
// 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_MRB Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_MRB"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Ribbon 1";
input int fast1Length = 3; // Fast
input int slow1Length = 5; // Slow
//
input group "Ribbon 2";
input int fast2Length = 8; // Fast
input int slow2Length = 13; // Slow
//
input group "Ribbon 3";
input int fast3Length = 21; // Fast
input int slow3Length = 34; // Slow
//
input group "Ribbon 4";
input int fast4Length = 55; // Fast
input int slow4Length = 89; // Slow
//
input group "Ribbon 5";
input int fast5Length = 144; // Fast
input int slow5Length = 233; // Slow
//
input group "Calculation Mode";
input ENUM_MA_METHOD ribbonMode = MODE_EMA; // Calculation Mode
input ENUM_APPLIED_PRICE ribbonAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Presentation";
input bool showFastMa = true; // Show Fast
input bool showSlowMa = true; // Show Slow
input bool showRibbon = false; // Show Ribbon
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 12
#property indicator_plots 12
//
// PLOTTED Buffers ...
//
// MA ...
//
// FAST ...
#define fastMaBufferIndex 0
double fastMaBuffer[];
//
#property indicator_label1 "X121_MRB F"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// SLOW ...
#define slowMaBufferIndex 1
double slowMaBuffer[];
//
#property indicator_label2 "X121_MRB S"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// DATA Buffers ...
//
// FAST ...
//
#define fast1BufferIndex 2
double fast1Buffer[];
//
#property indicator_label3 "X121_MRB 1 F"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrAquamarine
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#define fast2BufferIndex 3
double fast2Buffer[];
//
#property indicator_label4 "X121_MRB 2 F"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrAquamarine
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
#define fast3BufferIndex 4
double fast3Buffer[];
//
#property indicator_label5 "X121_MRB 3 F"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrAquamarine
#property indicator_style5 STYLE_DOT
#property indicator_width5 1
//
#define fast4BufferIndex 5
double fast4Buffer[];
//
#property indicator_label6 "X121_MRB 4 F"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrAquamarine
#property indicator_style6 STYLE_DOT
#property indicator_width6 1
//
#define fast5BufferIndex 6
double fast5Buffer[];
//
#property indicator_label7 "X121_MRB 5 F"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrAquamarine
#property indicator_style7 STYLE_DOT
#property indicator_width7 1
//
// SLOW ...
//
#define slow1BufferIndex 7
double slow1Buffer[];
//
#property indicator_label8 "X121_MRB 1 S"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrPlum
#property indicator_style8 STYLE_DOT
#property indicator_width8 1
//
#define slow2BufferIndex 8
double slow2Buffer[];
//
#property indicator_label9 "X121_MRB 2 S"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrPlum
#property indicator_style9 STYLE_DOT
#property indicator_width9 1
//
#define slow3BufferIndex 9
double slow3Buffer[];
//
#property indicator_label10 "X121_MRB 3 S"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrPlum
#property indicator_style10 STYLE_DOT
#property indicator_width10 1
//
#define slow4BufferIndex 10
double slow4Buffer[];
//
#property indicator_label11 "X121_MRB 4 S"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrPlum
#property indicator_style11 STYLE_DOT
#property indicator_width11 1
//
#define slow5BufferIndex 11
double slow5Buffer[];
//
#property indicator_label12 "X121_MRB 5 S"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrPlum
#property indicator_style12 STYLE_DOT
#property indicator_width12 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int fast1MaHandler = INVALID_HANDLE;
int fast2MaHandler = INVALID_HANDLE;
int fast3MaHandler = INVALID_HANDLE;
int fast4MaHandler = INVALID_HANDLE;
int fast5MaHandler = INVALID_HANDLE;
//
int slow1MaHandler = INVALID_HANDLE;
int slow2MaHandler = INVALID_HANDLE;
int slow3MaHandler = INVALID_HANDLE;
int slow4MaHandler = INVALID_HANDLE;
int slow5MaHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = 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();
//
// Initialize MAs ...
if (!InitializeMas())
{
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
//
// Here we can handle De Initialization Reasons ...
//
IndicatorRelease(fast1MaHandler);
IndicatorRelease(fast2MaHandler);
IndicatorRelease(fast3MaHandler);
IndicatorRelease(fast4MaHandler);
IndicatorRelease(fast5MaHandler);
//
IndicatorRelease(slow1MaHandler);
IndicatorRelease(slow2MaHandler);
IndicatorRelease(slow3MaHandler);
IndicatorRelease(slow4MaHandler);
IndicatorRelease(slow5MaHandler);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
//
int fast1MaCalculatedBars = BarsCalculated(fast1MaHandler);
int fast2MaCalculatedBars = BarsCalculated(fast2MaHandler);
int fast3MaCalculatedBars = BarsCalculated(fast3MaHandler);
int fast4MaCalculatedBars = BarsCalculated(fast4MaHandler);
int fast5MaCalculatedBars = BarsCalculated(fast5MaHandler);
//
int slow1MaCalculatedBars = BarsCalculated(slow1MaHandler);
int slow2MaCalculatedBars = BarsCalculated(slow2MaHandler);
int slow3MaCalculatedBars = BarsCalculated(slow3MaHandler);
int slow4MaCalculatedBars = BarsCalculated(slow4MaHandler);
int slow5MaCalculatedBars = BarsCalculated(slow5MaHandler);
if (
fast1MaCalculatedBars < maxLength ||
fast2MaCalculatedBars < maxLength ||
fast3MaCalculatedBars < maxLength ||
fast4MaCalculatedBars < maxLength ||
fast5MaCalculatedBars < maxLength ||
slow1MaCalculatedBars < maxLength ||
slow2MaCalculatedBars < maxLength ||
slow3MaCalculatedBars < maxLength ||
slow4MaCalculatedBars < maxLength ||
slow5MaCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
int copiedFast1Mas = CopyBuffer(fast1MaHandler, 0, 0, limit, fast1Buffer);
int copiedFast2Mas = CopyBuffer(fast2MaHandler, 0, 0, limit, fast2Buffer);
int copiedFast3Mas = CopyBuffer(fast3MaHandler, 0, 0, limit, fast3Buffer);
int copiedFast4Mas = CopyBuffer(fast4MaHandler, 0, 0, limit, fast4Buffer);
int copiedFast5Mas = CopyBuffer(fast5MaHandler, 0, 0, limit, fast5Buffer);
//
int copiedSlow1Mas = CopyBuffer(slow1MaHandler, 0, 0, limit, slow1Buffer);
int copiedSlow2Mas = CopyBuffer(slow2MaHandler, 0, 0, limit, slow2Buffer);
int copiedSlow3Mas = CopyBuffer(slow3MaHandler, 0, 0, limit, slow3Buffer);
int copiedSlow4Mas = CopyBuffer(slow4MaHandler, 0, 0, limit, slow4Buffer);
int copiedSlow5Mas = CopyBuffer(slow5MaHandler, 0, 0, limit, slow5Buffer);
if (
copiedFast1Mas <= 0 ||
copiedFast2Mas <= 0 ||
copiedFast3Mas <= 0 ||
copiedFast4Mas <= 0 ||
copiedFast5Mas <= 0 ||
copiedSlow1Mas <= 0 ||
copiedSlow2Mas <= 0 ||
copiedSlow3Mas <= 0 ||
copiedSlow4Mas <= 0 ||
copiedSlow5Mas <= 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 =
//
// Validate Ma ...
(fast1Length > 2 &&
fast2Length > fast1Length &&
fast3Length > fast2Length &&
fast4Length > fast3Length &&
fast5Length > fast4Length &&
slow1Length > fast1Length &&
slow2Length > fast2Length &&
slow3Length > fast3Length &&
slow4Length > fast4Length &&
slow5Length > fast5Length &&
slow2Length > slow1Length &&
slow3Length > slow2Length &&
slow4Length > slow3Length &&
slow5Length > slow4Length
//
)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Ma ...
//
result = MathMax(fast1Length, fast2Length);
result = MathMax(result, fast3Length);
result = MathMax(result, fast4Length);
result = MathMax(result, fast5Length);
//
result = MathMax(result, slow1Length);
result = MathMax(result, slow2Length);
result = MathMax(result, slow3Length);
result = MathMax(result, slow4Length);
result = MathMax(result, slow5Length);
//
return result;
}
//
// Initialize Ma Handlers ...
bool InitializeMas()
{
//
bool result = false;
//
fast1MaHandler = iMA(
_Symbol,
_Period,
fast1Length,
0,
ribbonMode,
ribbonAppliedTo);
fast2MaHandler = iMA(
_Symbol,
_Period,
fast2Length,
0,
ribbonMode,
ribbonAppliedTo);
fast3MaHandler = iMA(
_Symbol,
_Period,
fast3Length,
0,
ribbonMode,
ribbonAppliedTo);
fast4MaHandler = iMA(
_Symbol,
_Period,
fast4Length,
0,
ribbonMode,
ribbonAppliedTo);
fast5MaHandler = iMA(
_Symbol,
_Period,
fast5Length,
0,
ribbonMode,
ribbonAppliedTo);
//
slow1MaHandler = iMA(
_Symbol,
_Period,
slow1Length,
0,
ribbonMode,
ribbonAppliedTo);
slow2MaHandler = iMA(
_Symbol,
_Period,
slow2Length,
0,
ribbonMode,
ribbonAppliedTo);
slow3MaHandler = iMA(
_Symbol,
_Period,
slow3Length,
0,
ribbonMode,
ribbonAppliedTo);
slow4MaHandler = iMA(
_Symbol,
_Period,
slow4Length,
0,
ribbonMode,
ribbonAppliedTo);
slow5MaHandler = iMA(
_Symbol,
_Period,
slow5Length,
0,
ribbonMode,
ribbonAppliedTo);
//
result =
fast1MaHandler != INVALID_HANDLE &&
fast2MaHandler != INVALID_HANDLE &&
fast3MaHandler != INVALID_HANDLE &&
fast4MaHandler != INVALID_HANDLE &&
fast5MaHandler != INVALID_HANDLE &&
slow1MaHandler != INVALID_HANDLE &&
slow2MaHandler != INVALID_HANDLE &&
slow3MaHandler != INVALID_HANDLE &&
slow4MaHandler != INVALID_HANDLE &&
slow5MaHandler != INVALID_HANDLE;
//
if (!result)
{
//
string message = "Error Initializing Handlers ...";
LogMessage(message);
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// FAST ...
ENUM_DRAW_TYPE fastDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(fastMaBuffer, true);
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
//
// SLOW ...
ENUM_DRAW_TYPE slowDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(slowMaBuffer, true);
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
//
// DATA ...
ENUM_DRAW_TYPE ribbonDrawType = showRibbon ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(fast1Buffer, true);
SetIndexBuffer(fast1BufferIndex, fast1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast1BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast2Buffer, true);
SetIndexBuffer(fast2BufferIndex, fast2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast2BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast3Buffer, true);
SetIndexBuffer(fast3BufferIndex, fast3Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast3BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast4Buffer, true);
SetIndexBuffer(fast4BufferIndex, fast4Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast4BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(fast5Buffer, true);
SetIndexBuffer(fast5BufferIndex, fast5Buffer, INDICATOR_DATA);
PlotIndexSetInteger(fast5BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow1Buffer, true);
SetIndexBuffer(slow1BufferIndex, slow1Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow1BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow2Buffer, true);
SetIndexBuffer(slow2BufferIndex, slow2Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow2BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow3Buffer, true);
SetIndexBuffer(slow3BufferIndex, slow3Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow3BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow4Buffer, true);
SetIndexBuffer(slow4BufferIndex, slow4Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow4BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
//
ArraySetAsSeries(slow5Buffer, true);
SetIndexBuffer(slow5BufferIndex, slow5Buffer, INDICATOR_DATA);
PlotIndexSetInteger(slow5BufferIndex, PLOT_SHOW_DATA, showRibbon);
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// Retireve Values ...
//
double fast1Value = fast1Buffer[bar_index];
double fast2Value = fast2Buffer[bar_index];
double fast3Value = fast3Buffer[bar_index];
double fast4Value = fast4Buffer[bar_index];
double fast5Value = fast5Buffer[bar_index];
//
double slow1Value = slow1Buffer[bar_index];
double slow2Value = slow2Buffer[bar_index];
double slow3Value = slow3Buffer[bar_index];
double slow4Value = slow4Buffer[bar_index];
double slow5Value = slow5Buffer[bar_index];
//
double fastValue = (fast1Value + fast2Value + fast3Value + fast4Value + fast5Value) / 5;
fastMaBuffer[bar_index] = fastValue;
//
double slowValue = (slow1Value + slow2Value + slow3Value + slow4Value + slow5Value) / 5;
slowMaBuffer[bar_index] = slowValue;
}
//
// END Functions ...
//
@@ -0,0 +1,453 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_SSLC SSL Channel
// ----------------------------------------------------
// Name: X121_SSLC
// Description: SSL Channel Indicator
// Market Analysor ...
//
//
// 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_SSLC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_SSLC"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Market";
input int length = 30; // Length
//
input group "Calculation";
input ENUM_MA_METHOD method = MODE_SMA; // Method
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Applied To
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Applied To
//
input group "Presentation";
input bool showUp = true; // Show Up
input bool showDown = true; // Show Down
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 5
#property indicator_plots 2
//
// PLOTTED Buffers ...
//
#define upBufferIndex 0
double upBuffer[];
//
#property indicator_label1 "X121_SSLC Up"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#define downBufferIndex 1
double downBuffer[];
//
#property indicator_label2 "X121_SSLC Down"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// DATA Buffers ...
//
#define upMaBufferIndex 2
double upMaBuffer[];
//
#define downMaBufferIndex 3
double downMaBuffer[];
//
#define kpiBufferIndex 4
double kpiBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int upHandler = INVALID_HANDLE;
int downHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = 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();
//
// Initialize Requierd Handlers ...
upHandler = iMA(
_Symbol,
_Period,
length,
0,
method,
upAppliedTo);
downHandler = iMA(
_Symbol,
_Period,
length,
0,
method,
downAppliedTo);
if (upHandler == INVALID_HANDLE || downHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
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
//
// Release Indicators ...
IndicatorRelease(upHandler);
IndicatorRelease(downHandler);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
int upCalculatedBars = BarsCalculated(upHandler);
int downCalculatedBars = BarsCalculated(downHandler);
if (upCalculatedBars < maxLength ||
downCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedUps = CopyBuffer(upHandler, 0, 0, limit, upMaBuffer);
int copiedDowns = CopyBuffer(downHandler, 0, 0, limit, downMaBuffer);
if (copiedUps <= 0 ||
copiedDowns <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i, limit, rates_total, prev_calculated, close);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
// Validate Inputs ...
(length > 2)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(result, length);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// UP ...
//
ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(upBuffer, true);
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType);
//
// DOWN ...
//
ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(downBuffer, true);
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA);
PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_TYPE, downDrawType);
//
// DATA Buffers ...
//
// UP MA ...
ArraySetAsSeries(upMaBuffer, true);
SetIndexBuffer(upMaBufferIndex, upMaBuffer, INDICATOR_CALCULATIONS);
//
// DOWN MA ...
ArraySetAsSeries(downMaBuffer, true);
SetIndexBuffer(downMaBufferIndex, downMaBuffer, INDICATOR_CALCULATIONS);
//
// KPI ...
ArraySetAsSeries(kpiBuffer, true);
SetIndexBuffer(kpiBufferIndex, kpiBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
int limit,
int ratesTotal,
int prevCalculated,
const double &close[])
{
//
double upMaValue = upMaBuffer[bar_index];
double downMaValue = downMaBuffer[bar_index];
//
double closeValue = close[bar_index];
//
double kpiValue;
if (closeValue > upMaValue) {
kpiValue = 1;
} else if (closeValue < downMaValue) {
kpiValue = -1;
} else {
kpiValue = kpiBuffer[bar_index + 1];
}
//
kpiBuffer[bar_index] = kpiValue;
//
double upValue = kpiValue < 0 ? downMaValue : upMaValue;
upBuffer[bar_index] = upValue;
//
double downValue = kpiValue < 0 ? upMaValue : downMaValue;
downBuffer[bar_index] = downValue;
}
//
// END Functions ...
//
@@ -0,0 +1,355 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: X121_XTM
// Description: Trend Magic 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_XTM Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "X121_XTM"
//
// XTM Indicator States ...
enum ENUM_X_XTM_STATES
{
X_XTM_BULLISH = 0,
X_XTM_BEARISH = 2,
X_XTM_NEUTURAL = 1,
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Makret";
input int length = 35; // Length
input int shift = 0; // Shift
//
input group "Calculations";
input ENUM_MA_METHOD method = MODE_SMA; // Method
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
//
input group "Presentation";
input bool showLine = true; // Show Line
//
// END Inputs ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 2
#property indicator_plots 2
//
// maBuffer ...
#define maBufferIndex 0
double maBuffer[];
#define maColorBufferIndex 1
double maColorBuffer[];
//
#property indicator_label1 "X121 XTM"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLime, clrGray, clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int maHandler = 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 MA Handler ...
maHandler = iMA(
_Symbol,
_Period,
length,
shift,
method,
appliedTo);
if (maHandler == INVALID_HANDLE)
{
//
string message = "Error Initializing Ma Handler ...";
Print(message);
//
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(maHandler);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
int maCalculatedBars = BarsCalculated(maHandler);
if (maCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
if (copiedMas <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Do Buffers Calculation ...
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (length >= 2)
{
result = true;
}
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = length;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
//
// Ma Buffer ...
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
//
// Ma Color Buffer ...
ArraySetAsSeries(maColorBuffer, true);
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(int bar_index)
{
//
// Requirements ...
XOHCL candle = GetCandle(bar_index);
//
double maValue = maBuffer[bar_index];
//
double lineColorIndex =
maValue < candle.low ? 0 : maValue > candle.high ? 2
: 1;
//
// Set Ma Buffer Color Index ...
maColorBuffer[bar_index] = lineColorIndex;
}
//
// END Functions ...
//
@@ -0,0 +1,917 @@
////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XTestPRVD Signal Provider Library
// --------------------------------------------------------
// Name: XTestPRVD
// Description: XTestPRVD 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
//
// START Imports/Includes ...
//
//
// Include Common Library ...
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// Include Logger Library ...
#include "../../Libraries/x-saherelm.log.lib.mq5"
//
// Include Alert Library ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
//
// Include Draw Library ...
#include "../../Libraries/x-saherelm.draw.lib.mq5"
//
#include "../../Helpers/Test/x121.xpv.test.helper.mq5"
#include "../../Helpers/Test/x121.xmc.test.helper.mq5"
#include "../../Helpers/Test/x121.xmrb.test.helper.mq5"
#include "../../Helpers/Test/x121.xichi.test.helper.mq5"
#include "../../Helpers/Test/x121.xtrnd.test.helper.mq5"
#include "../../Helpers/Test/x121.xatrsl.test.helper.mq5"
//
// END Imports/Includes ...
//
//
// START Enum/Constant Definitions ...
//
//
// Model Market Sence ...
struct X121MarketCondition
{
//
// XPV ...
//
bool isPVNewPeak;
bool isPVSamePeak;
bool isPVPeakBreakedUp;
bool isPVPeakBreakedDown;
//
bool isPVNewVale;
bool isPVSameVale;
bool isPVValeBreakedUp;
bool isPVValeBreakedDown;
//
// SSL Channel ...
bool isSSLUpOverDown;
bool isSSLUpUnderDown;
bool isSSLUpCrossedOverDown;
bool isSSLUpCrossedUnderDown;
//
// XICHI ...
//
// TNKIJ ...
bool isIchiTenkanSenOverKijunSen;
bool isIchiTenkanSenUnderKijunSen;
bool isIchiTenkanSenCrossedOverKijunSen;
bool isIchiTenkanSenCrossedUnderKijunSen;
//
// KUMO ...
bool isIchiKumoBullish;
bool isIchiKumoBearish;
bool isIchiFutureKumoBullish;
bool isIchiFutureKumoBearish;
bool isIchiKumoSwitchedToBullish;
bool isIchiKumoSwitchedToBearish;
bool isIchiFutureKumoSwitchedToBullish;
bool isIchiFutureKumoSwitchedToBearish;
//
// TNKUMO ...
bool isIchiTenkanSenOverSenkouSpanA;
bool isIchiTenkanSenOverSenkouSpanB;
bool isIchiTenkanSenCrossedOverSenkouSpanA;
bool isIchiTenkanSenCrossedOverSenkouSpanB;
bool isIchiTenkanSenUnderSenkouSpanA;
bool isIchiTenkanSenUnderSenkouSpanB;
bool isIchiTenkanSenCrossedUnderSenkouSpanA;
bool isIchiTenkanSenCrossedUnderSenkouSpanB;
//
// KIJUMO ...
bool isIchiKijunSenOverSenkouSpanA;
bool isIchiKijunSenOverSenkouSpanB;
bool isIchiKijunSenCrossedOverSenkouSpanA;
bool isIchiKijunSenCrossedOverSenkouSpanB;
bool isIchiKijunSenUnderSenkouSpanA;
bool isIchiKijunSenUnderSenkouSpanB;
bool isIchiKijunSenCrossedUnderSenkouSpanA;
bool isIchiKijunSenCrossedUnderSenkouSpanB;
//
// XTRND ...
//
// CURRENT ...
bool isTrendBullish;
bool isTrendBearish;
bool isTrendConsolidation;
bool isTrendSwitchedToBullish;
bool isTrendSwitchedToBearish;
bool isTrendSwitchedToConsolidation;
//
// LEVEL 1 ...
bool isTrendL1Bullish;
bool isTrendL1Bearish;
bool isTrendL1Consolidation;
bool isTrendL1SwitchedToBullish;
bool isTrendL1SwitchedToBearish;
bool isTrendL1SwitchedToConsolidation;
//
// LEVEL 2 ...
bool isTrendL2Bullish;
bool isTrendL2Bearish;
bool isTrendL2Consolidation;
bool isTrendL2SwitchedToBullish;
bool isTrendL2SwitchedToBearish;
bool isTrendL2SwitchedToConsolidation;
//
// LEVEL 3 ...
bool isTrendL3Bullish;
bool isTrendL3Bearish;
bool isTrendL3Consolidation;
bool isTrendL3SwitchedToBullish;
bool isTrendL3SwitchedToBearish;
bool isTrendL3SwitchedToConsolidation;
//
// XMRB ...
//
// MRIBBON ...
bool isRibbonBullish;
bool isRibbonBearish;
bool isRibbonSwitchedToBullish;
bool isRibbonSwitchedToBearish;
//
// RIBOON 1 ...
bool isRibbon1Bullish;
bool isRibbon1Bearish;
bool isRibbon1SwitchedToBullish;
bool isRibbon1SwitchedToBearish;
//
// RIBOON 2 ...
bool isRibbon2Bullish;
bool isRibbon2Bearish;
bool isRibbon2SwitchedToBullish;
bool isRibbon2SwitchedToBearish;
//
// RIBOON 3 ...
bool isRibbon3Bullish;
bool isRibbon3Bearish;
bool isRibbon3SwitchedToBullish;
bool isRibbon3SwitchedToBearish;
//
// RIBOON 4 ...
bool isRibbon4Bullish;
bool isRibbon4Bearish;
bool isRibbon4SwitchedToBullish;
bool isRibbon4SwitchedToBearish;
//
// RIBOON 5 ...
bool isRibbon5Bullish;
bool isRibbon5Bearish;
bool isRibbon5SwitchedToBullish;
bool isRibbon5SwitchedToBearish;
//
// XMC ...
bool isMCFastOverSlow;
bool isMCFastUnderSlow;
bool isMCFastCrossedOverSlow;
bool isMCFastCrossedUnderSlow;
bool isMCFastOverVerifier;
bool isMCFastUnderVerifier;
bool isMCFastCrossedOverVerifier;
bool isMCFastCrossedUnderVerifier;
bool isMCSlowOverVerifier;
bool isMCSlowUnderVerifier;
bool isMCSlowCrossedOverVerifier;
bool isMCSlowCrossedUnderVerifier;
//
// XAMA ...
bool isXAMABullish;
bool isXAMABearish;
bool isXAMANeutural;
bool isXAMAChangedToBullish;
bool isXAMAChangedToBearish;
bool isXAMAChangedToNeutural;
//
// XTM ...
bool isXTMBullish;
bool isXTMBearish;
bool isXTMNeutural;
bool isXTMChangedToBullish;
bool isXTMChangedToBearish;
bool isXTMChangedToNeutural;
}
//
// END Enum/Constant Definitions ...
//
//
// START Variables ...
//
//
int mcclearHandler = INVALID_HANDLE;
//
// END Variables ...
//
//
// START Signal Provider Functions ...
//
//
bool XTestPRVDOnInit()
{
//
bool result = false;
//
result = XATRSLHLPOnInit();
if (!result)
{
return result;
}
//
result = XICHIHLPOnInit();
if (!result)
{
return result;
}
//
result = XMCHLPOnInit();
if (!result)
{
return result;
}
//
result = XMRBHLPOnInit();
if (!result)
{
return result;
}
//
result = XPVHLPOnInit();
if (!result)
{
return result;
}
//
result = XTRNDHLPOnInit();
if (!result)
{
return result;
}
//
// Initial CCLear Handler ...
mcclearHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xcclear",
//
// Inputs ...
//
// CHARTSTYLE ...
"",
//
// Up Color ...
clrLime,
//
// Down Color ...
clrRed,
//
// Line mode and Doji candlestick Color ...
clrLime,
//
// Bullish Color ...
clrRed,
//
// Bearish Color ...
clrLime,
//
// Volumes Color ...
clrGreen,
//
// PRESENTATION ...
"",
true
//
);
result = mcclearHandler != INVALID_HANDLE;
//
return result;
}
//
void XTestPRVDOnDeInit()
{
//
XATRSLHLPOnDeInit();
XICHIHLPOnDeInit();
XMCHLPOnDeInit();
XMRBHLPOnDeInit();
XPVHLPOnDeInit();
XTRNDHLPOnDeInit();
}
//
void XTestPRVDOnTick()
{
XATRSLHLPReadBuffers();
XICHIHLPReadBuffers();
XMCHLPReadBuffers();
XMRBHLPReadBuffers();
XPVHLPReadBuffers();
XTRNDHLPReadBuffers();
}
//
bool XTestPRVDProcessSignals(XSignal &result)
{
//
bool mResult = false;
//
// BUY ...
//
Clean(result);
bool hasLongSignal = XTestPRVDHasLongSignal(result);
if (hasLongSignal)
{
//
mResult = true;
return mResult;
}
//
// SELL ...
//
Clean(result);
bool hasShortignal = XTestPRVDHasShortSignal(result);
if (hasShortignal)
{
//
mResult = true;
return mResult;
}
//
return mResult;
}
//
bool XTestPRVDHasLongSignal(XSignal &result)
{
//
bool mResult = false;
return mResult;
//
XOHCLSupRes supRes = XPVHLPFindCandleSupprtAndResistance(1, 6);
bool hasSupport = ArraySize(supRes.sup) > 0;
bool hasResistance = ArraySize(supRes.res) > 0;
//
double r2r = 1.2;
double riskAmount = 0.005;
double entry = GetEntry(
_Symbol,
POSITION_TYPE_BUY);
double sl = entry -
(hasSupport
? (supRes.sup[ArrayMaximum(supRes.sup)] - supRes.sup[ArrayMinimum(supRes.sup)])
: hasResistance
? (supRes.res[ArrayMaximum(supRes.res)] - supRes.res[ArrayMinimum(supRes.res)])
: PointToPrice(
_Symbol,
10))
//
;
//
bool isXTestHasSignal = XTestPRVDHasLongCondition();
if (isXTestHasSignal)
{
//
Add(
"XTest",
result.providers);
//
result.r2r = 1.5;
//
result.sl = atrslDownBuffer[1];
}
//
bool isXTRNDHasSignal = XTRNDHasLongCondition();
if (isXTRNDHasSignal)
{
//
Add(
"XTRND",
result.providers);
}
//
bool isXICHIHasSignal = XICHIHasLongCondition();
if (isXICHIHasSignal)
{
//
Add(
"XICHI",
result.providers);
}
//
mResult =
//
isXTRNDHasSignal
//
||
//
isXICHIHasSignal
//
;
//
if (mResult)
{
//
result.sl = sl;
result.r2r = r2r;
result.entry = entry;
result.symbol = _Symbol;
result.period = _Period;
result.riskAmount = riskAmount;
result.type = POSITION_TYPE_BUY;
result.supportAndResistance = supRes;
}
//
return mResult;
}
//
bool XTestPRVDHasShortSignal(XSignal &result)
{
//
bool mResult = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
XOHCLSupRes supRes = XPVHLPFindCandleSupprtAndResistance(1, 6);
bool hasSupport = ArraySize(supRes.sup) > 0;
bool hasResistance = ArraySize(supRes.res) > 0;
//
double r2r = 1.2;
double riskAmount = 0.005;
double entry = GetEntry(
_Symbol,
POSITION_TYPE_SELL);
double sl = entry + (supRes.res[ArrayMaximum(supRes.res)] - supRes.res[ArrayMinimum(supRes.res)]);
//
bool isXTRNDHasSignal = XTRNDHasShortCondition();
if (isXTRNDHasSignal)
{
//
Add(
"XTRND",
result.providers);
}
//
bool isICHIHasSignal = XICHIHasShortCondition();
if (isICHIHasSignal)
{
//
Add(
"XICHI",
result.providers);
}
//
mResult =
//
isXTRNDHasSignal
//
// ||
// //
// TODO:
// isICHIHasSignal
//
;
//
if (mResult)
{
//
result.sl = sl;
result.r2r = r2r;
result.entry = entry;
result.symbol = _Symbol;
result.period = _Period;
result.riskAmount = riskAmount;
result.type = POSITION_TYPE_SELL;
result.mode = X_ORDER_MODE_MARKET;
result.supportAndResistance = supRes;
//
if (!hasSupport)
{
//
// When there is no any Provided Support for a Singal ...
// Place Pending Order instead of Market Order and use
// PV's LL Buffers as Supprt area ...
result.mode = X_ORDER_MODE_STOP;
double supportArea = XPVHLPGetMaxLL(1) - GetCandleShadow(c1);
result.entry = supportArea;
}
}
//
return mResult;
}
//
// TODO: Implement it ...
bool XTestPRVDForceCloseAllShorts()
{
//
bool result = false;
// //
// XOHCL c1 = GetCandle(
// _Symbol,
// _Period,
// 1);
// //
// result =
// //
// c1.low < ichiKijunSenBuffer[1] &&
// c1.high > ichiKijunSenBuffer[1]
// //
// ;
//
return result;
}
//
bool XTestPRVDHasLongCondition()
{
//
bool result = false;
//
return result;
}
//
bool XTestPRVDHasShortCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
return result;
}
//
// XTRND ..
//
bool XTRNDForceCloseAllLongs()
{
//
bool result = false;
//
return result;
}
//
bool XTRNDForceCloseAllShorts()
{
//
bool result = false;
//
return result;
}
//
bool XTRNDHasLongCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
XIchiInfo ichi1 = XICHIHLPGetInfo(1);
//
bool isTrendSwitchedToBullish =
//
(
//
XTRNDHLPIsL3TrendSwitchedBullish(1) &&
XTRNDHLPIsTrendBullish(1) &&
XTRNDHLPIsL1TrendBullish(1) &&
XTRNDHLPIsL2TrendBullish(1)
//
)
//
||
//
(
//
XTRNDHLPIsL2TrendSwitchedBullish(1) &&
XTRNDHLPIsTrendBullish(1) &&
XTRNDHLPIsL1TrendBullish(1) &&
XTRNDHLPIsL3TrendBullish(1)
//
)
//
||
//
(
//
XTRNDHLPIsL1TrendSwitchedBullish(1) &&
XTRNDHLPIsTrendBullish(1) &&
XTRNDHLPIsL2TrendBullish(1) &&
XTRNDHLPIsL3TrendBullish(1)
//
)
//
;
//
bool signal1 =
//
isTrendSwitchedToBullish
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
bool XTRNDHasShortCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
bool isTrendSwitchedToBearish =
//
(
//
XTRNDHLPIsL3TrendSwitchedBearish(1) &&
XTRNDHLPIsTrendBearish(1) &&
XTRNDHLPIsL1TrendBearish(1) &&
XTRNDHLPIsL2TrendBearish(1)
//
)
//
||
//
(
//
XTRNDHLPIsL2TrendSwitchedBearish(1) &&
XTRNDHLPIsTrendBearish(1) &&
XTRNDHLPIsL1TrendBearish(1) &&
XTRNDHLPIsL3TrendBearish(1) &&
XTRNDHLPIsTrendBearish(2) &&
XTRNDHLPIsL1TrendBearish(2) &&
XTRNDHLPIsL3TrendBearish(2)
//
)
//
||
//
(
//
XTRNDHLPIsL1TrendSwitchedBearish(1) &&
XTRNDHLPIsTrendBearish(1) &&
XTRNDHLPIsL2TrendBearish(1) &&
XTRNDHLPIsL3TrendBearish(1) &&
XTRNDHLPIsTrendBearish(2) &&
XTRNDHLPIsL2TrendBearish(2) &&
XTRNDHLPIsL3TrendBearish(2) &&
XTRNDHLPIsTrendBearish(3) &&
XTRNDHLPIsL2TrendBearish(3) &&
XTRNDHLPIsL3TrendBearish(3)
//
)
//
;
//
bool signal1 =
//
isTrendSwitchedToBearish
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
// XICHI ...
//
bool XICHIForceCloseAllShorts()
{
//
bool result = false;
//
return result;
}
//
bool XICHIForceCloseAllLongs()
{
//
bool result = false;
//
return result;
}
//
bool XICHIHasLongCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
XIchiInfo info1 = XICHIHLPGetInfo(1);
//
bool isKumoSwitchedToBullish =
//
XICHIHLPIsKumoSwitchedToBullish(1)
//
;
//
bool signal1 =
//
isKumoSwitchedToBullish &&
c1.low > info1.tenkanSen &&
info1.tenkanSen > info1.kijunSen &&
info1.kijunSen > MathMax(info1.senkouSpanA, info1.senkouSpanB)
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
bool XICHIHasShortCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
XIchiInfo info1 = XICHIHLPGetInfo(1);
//
bool isKumoSwitchedToBearish =
//
XICHIHLPIsKumoSwitchedToBearish(1)
//
;
//
bool signal1 =
//
isKumoSwitchedToBearish &&
c1.high < info1.tenkanSen &&
info1.tenkanSen < info1.kijunSen &&
info1.kijunSen < MathMin(info1.senkouSpanA, info1.senkouSpanB)
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
// END Signal Provider Functions ...
//
@@ -0,0 +1,193 @@
///////////////////////////////////////////////////////
//
// 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 Chart Tools Functions ...
//
//
string x121ToolsButtonName = "X121TOOLS";
//
// Calculate Button size ...
bool CalculateButtonSize(
XSize &result, // Holds Result ...
long chartID = 0, // Specified Chart ID ...
int step = 32 // Step Divider ...
)
{
//
bool mResult = false;
//
mResult = GetChartSize(
result,
chartID);
if (!mResult)
{
return mResult;
}
//
// define the step for changing the button size
int x_step = (int)result.width / step;
int y_step = (int)result.height / step;
//
// set the button coordinates and its size
int x = (int)result.width / step;
int y = (int)result.height / step;
//
// int width = (int)result.width * 15 / 32;
// int height = (int)result.height * 15 / 32;
int width = (int)result.width / 32;
int height = (int)result.height / 32;
//
result.x = x;
result.y = y;
result.w = width;
result.h = height;
result.wStep = x_step;
result.hStep = y_step;
//
return mResult;
}
//
// Draw Tools Button On Chart ...
bool DrawToolsButton(
long chartID = 0, // Specified Chart ID ...
int subWindow = 0, // Specified Chart's SubWindow ...
ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER // Specified Corner to Draw Button ...
)
{
//
bool result = false;
//
XSize size;
result = CalculateButtonSize(
size,
chartID);
if (!result)
{
return result;
}
//
result = ButtonCreate(
chartID,
x121ToolsButtonName,
0,
size.x,
size.y,
size.w,
size.y,
corner,
"Press",
"Arial",
10,
clrBlack,
clrLightGray,
CLR_NONE,
false, // Pressed/Released ...
false,
false,
true,
0);
//
return result;
}
//
bool ToggleToolsButtonState(
long chartID = 0, // Specified Chart ID ...
int subWindow = 0 // Specified Chart's SubWindow ...
)
{
//
bool result = false;
//
return result;
}
//
// Prepare Chart Requirements ...
bool DrawTools(
long chartID = 0, // Specified Chart ID ...
int subWindow = 0 // Specified Chart's SubWindow ...
)
{
//
bool result = false;
//
result = DrawToolsButton(
chartID,
subWindow);
//
// redraw the chart
if (result)
{
ChartRedraw();
}
//
return result;
}
//
// Parse Chart Tools Events ...
void HandleToolsChartEvent(
long chartID, // Specified Chart ID ...
const int id, // event ID
const long &lparam, // long type event parameter
const double &dparam, // double type event parameter
const string &sparam // string type event parameter
)
{
//
// OnClick ...
if (id == CHARTEVENT_CLICK)
{
//
// Toolls Btton Clicked ...
if (sparam == x121ToolsButtonName)
{
LogMessage("Tools Button Clicked ...");
}
}
}
//
// END Chart Tools Functions ...
//
@@ -0,0 +1,269 @@
2024.04.01 06:30:00 XEA > Peaks and Vales
2024.04.01 06:30:00 XEA > Supprot and Resistance:
2024.04.01 06:30:00 R1: 1.07873
2024.04.01 06:30:00 R2: 1.07986
2024.04.01 06:30:00
2024.04.01 06:30:00 S1: 1.07819
2024.04.01 06:30:00 S2: 1.07743
2024.04.01 06:30:00
2024.04.01 06:30:00
2024.04.01 06:30:00 XEA >
2024.04.01 06:30:00 XEA > Ichimoku Kinko Hyo
2024.04.01 06:30:00 XEA > Supprot and Resistance:
2024.04.01 06:30:00 R1: 1.0787149999999999
2024.04.01 06:30:00 R2: 1.0788
2024.04.01 06:30:00
2024.04.01 06:30:00 S1: 0.0
2024.04.01 06:30:00 S2: 0.0
2024.04.01 15:30:00 XEA > Peaks and Vales
2024.04.01 15:30:00 XEA > Supprot and Resistance:
2024.04.01 15:30:00 R1: 1.07849
2024.04.01 15:30:00 R2: 1.07903
2024.04.01 15:30:00
2024.04.01 15:30:00 S1: 0.0
2024.04.01 15:30:00 S2: 0.0
2024.04.01 15:30:00
2024.04.01 15:30:00
2024.04.01 15:30:00 XEA >
2024.04.01 15:30:00 XEA > Ichimoku Kinko Hyo
2024.04.01 15:30:00 XEA > Supprot and Resistance:
2024.04.01 15:30:00 R1: 1.0782349999999998
2024.04.01 15:30:00 R2: 1.07844
2024.04.01 15:30:00
2024.04.01 15:30:00 S1: 0.0
2024.04.01 15:30:00 S2: 0.0
2024.04.01 16:20:00 XEA > Peaks and Vales
2024.04.01 16:20:00 XEA > Supprot and Resistance:
2024.04.01 16:20:00 R1: 1.07855
2024.04.01 16:20:00 R2: 1.07903
2024.04.01 16:20:00
2024.04.01 16:20:00 S1: 0.0
2024.04.01 16:20:00 S2: 0.0
2024.04.01 16:20:00
2024.04.01 16:20:00
2024.04.01 16:20:00 XEA >
2024.04.01 16:20:00 XEA > Ichimoku Kinko Hyo
2024.04.01 16:20:00 XEA > Supprot and Resistance:
2024.04.01 16:20:00 R1: 1.078125
2024.04.01 16:20:00 R2: 1.07817
2024.04.01 16:20:00
2024.04.01 16:20:00 S1: 0.0
2024.04.01 16:20:00 S2: 0.0
2024.04.01 17:45:02 XEA > Peaks and Vales
2024.04.01 17:45:02 XEA > Supprot and Resistance:
2024.04.01 17:45:02 R1: 1.0781
2024.04.01 17:45:02 R2: 1.07826
2024.04.01 17:45:02
2024.04.01 17:45:02 S1: 0.0
2024.04.01 17:45:02 S2: 0.0
2024.04.01 17:45:02
2024.04.01 17:45:02
2024.04.01 17:45:02 XEA >
2024.04.01 17:45:02 XEA > Ichimoku Kinko Hyo
2024.04.01 17:45:02 XEA > Supprot and Resistance:
2024.04.01 17:45:02 R1: 1.077985
2024.04.01 17:45:02 R2: 1.078125
2024.04.01 17:45:02
2024.04.01 17:45:02 S1: 0.0
2024.04.01 17:45:02 S2: 0.0
2024.04.01 17:45:02
2024.04.01 17:45:02
2024.04.01 18:15:00 XEA > Peaks and Vales
2024.04.01 18:15:00 XEA > Supprot and Resistance:
2024.04.01 18:15:00 R1: 1.07805
2024.04.01 18:15:00 R2: 1.07853
2024.04.01 18:15:00
2024.04.01 18:15:00 S1: 0.0
2024.04.01 18:15:00 S2: 0.0
2024.04.01 18:15:00
2024.04.01 18:15:00
2024.04.01 18:15:00 XEA >
2024.04.01 18:15:00 XEA > Ichimoku Kinko Hyo
2024.04.01 18:15:00 XEA > Supprot and Resistance:
2024.04.01 18:15:00 R1: 1.07611
2024.04.01 18:15:00 R2: 1.0763449999999999
2024.04.01 18:15:00
2024.04.01 18:15:00 S1: 0.0
2024.04.01 18:15:00 S2: 0.0
2024.04.01 18:15:00
2024.04.01 18:15:00
2024.04.01 18:25:00 XEA > Peaks and Vales
2024.04.01 18:25:00 XEA > Supprot and Resistance:
2024.04.01 18:25:00 R1: 1.07805
2024.04.01 18:25:00 R2: 1.07853
2024.04.01 18:25:00
2024.04.01 18:25:00 S1: 0.0
2024.04.01 18:25:00 S2: 0.0
2024.04.01 18:25:00
2024.04.01 18:25:00
2024.04.01 18:25:00 XEA >
2024.04.01 18:25:00 XEA > Ichimoku Kinko Hyo
2024.04.01 18:25:00 XEA > Supprot and Resistance:
2024.04.01 18:25:00 R1: 1.07611
2024.04.01 18:25:00 R2: 1.0763449999999999
2024.04.01 18:25:00
2024.04.01 18:25:00 S1: 0.0
2024.04.01 18:25:00 S2: 0.0
2024.04.01 18:25:00
2024.04.01 18:25:00
2024.04.02 01:50:02 XEA > Peaks and Vales
2024.04.02 01:50:02 XEA > Supprot and Resistance:
2024.04.02 01:50:02 R1: 1.07849
2024.04.02 01:50:02 R2: 1.07903
2024.04.02 01:50:02
2024.04.02 01:50:02 S1: 1.07363
2024.04.02 01:50:02 S2: 1.07342
2024.04.02 01:50:02
2024.04.02 01:50:02
2024.04.02 01:50:02 XEA >
2024.04.02 01:50:02 XEA > Ichimoku Kinko Hyo
2024.04.02 01:50:02 XEA > Supprot and Resistance:
2024.04.02 01:50:02 R1: 1.074205
2024.04.02 01:50:02 R2: 1.07428
2024.04.02 01:50:02
2024.04.02 01:50:02 S1: 1.0740675
2024.04.02 01:50:02 S2: 1.074025
2024.04.02 01:50:02
2024.04.02 01:50:02
2024.04.02 02:05:00 XEA > Peaks and Vales
2024.04.02 02:05:00 XEA > Supprot and Resistance:
2024.04.02 02:05:00 R1: 1.07416
2024.04.02 02:05:00 R2: 1.0744
2024.04.02 02:05:00
2024.04.02 02:05:00 S1: 1.07366
2024.04.02 02:05:00 S2: 0.0
2024.04.02 02:05:00
2024.04.02 02:05:00
2024.04.02 02:05:00 XEA >
2024.04.02 02:05:00 XEA > Ichimoku Kinko Hyo
2024.04.02 02:05:00 XEA > Supprot and Resistance:
2024.04.02 02:05:00 R1: 1.074025
2024.04.02 02:05:00 R2: 1.0740675
2024.04.02 02:05:00
2024.04.02 02:05:00 S1: 1.073385
2024.04.02 02:05:00 S2: 0.0
2024.04.02 02:05:00
2024.04.02 02:05:00
2024.04.02 03:35:00 XEA > Peaks and Vales
2024.04.02 03:35:00 XEA > Supprot and Resistance:
2024.04.02 03:35:00 R1: 1.07399
2024.04.02 03:35:00 R2: 1.07425
2024.04.02 03:35:00
2024.04.02 03:35:00 S1: 0.0
2024.04.02 03:35:00 S2: 0.0
2024.04.02 03:35:00
2024.04.02 03:35:00
2024.04.02 03:35:00 XEA >
2024.04.02 03:35:00 XEA > Ichimoku Kinko Hyo
2024.04.02 03:35:00 XEA > Supprot and Resistance:
2024.04.02 03:35:00 R1: 1.073385
2024.04.02 03:35:00 R2: 1.073705
2024.04.02 03:35:00
2024.04.02 03:35:00 S1: 0.0
2024.04.02 03:35:00 S2: 0.0
2024.04.02 03:35:00
2024.04.02 03:35:00
2024.04.02 06:25:00 XEA > Peaks and Vales
2024.04.02 06:25:00 XEA > Supprot and Resistance:
2024.04.02 06:25:00 R1: 1.07366
2024.04.02 06:25:00 R2: 1.07512
2024.04.02 06:25:00
2024.04.02 06:25:00 S1: 1.07312
2024.04.02 06:25:00 S2: 0.0
2024.04.02 06:25:00
2024.04.02 06:25:00
2024.04.02 06:25:00 XEA >
2024.04.02 06:25:00 XEA > Ichimoku Kinko Hyo
2024.04.02 06:25:00 XEA > Supprot and Resistance:
2024.04.02 06:25:00 R1: 1.073485
2024.04.02 06:25:00 R2: 1.0736249999999998
2024.04.02 06:25:00
2024.04.02 06:25:00 S1: 0.0
2024.04.02 06:25:00 S2: 0.0
2024.04.02 06:25:00
2024.04.02 06:25:00
2024.04.10 19:00:04 XEA > Peaks and Vales
2024.04.10 19:00:04 XEA > Supprot and Resistance:
2024.04.10 19:00:04 R1: 1.07795
2024.04.10 19:00:04 R2: 1.08617
2024.04.10 19:00:04
2024.04.10 19:00:04 S1: 0.0
2024.04.10 19:00:04 S2: 0.0
2024.04.10 19:00:04
2024.04.10 19:00:04
2024.04.10 19:00:04 XEA >
2024.04.10 19:00:04 XEA > Ichimoku Kinko Hyo
2024.04.10 19:00:04 XEA > Supprot and Resistance:
2024.04.10 19:00:04 R1: 1.073705
2024.04.10 19:00:04 R2: 1.07374
2024.04.10 19:00:04
2024.04.10 19:00:04 S1: 1.073275
2024.04.10 19:00:04 S2: 1.0732050000000002
2024.04.10 19:00:04
2024.04.10 19:00:04
2024.04.10 19:40:00 XEA > Peaks and Vales
2024.04.10 19:40:00 XEA > Supprot and Resistance:
2024.04.10 19:40:00 R1: 1.07742
2024.04.10 19:40:00 R2: 1.08584
2024.04.10 19:40:00
2024.04.10 19:40:00 S1: 0.0
2024.04.10 19:40:00 S2: 0.0
2024.04.10 19:40:00
2024.04.10 19:40:00
2024.04.10 19:40:00 XEA >
2024.04.10 19:40:00 XEA > Ichimoku Kinko Hyo
2024.04.10 19:40:00 XEA > Supprot and Resistance:
2024.04.10 19:40:00 R1: 1.0732050000000002
2024.04.10 19:40:00 R2: 1.073275
2024.04.10 19:40:00
2024.04.10 19:40:00 S1: 1.072805
2024.04.10 19:40:00 S2: 0.0
2024.04.10 19:40:00
2024.04.10 19:40:00
2024.04.11 03:10:00 XEA > Peaks and Vales
2024.04.11 03:10:00 XEA > Supprot and Resistance:
2024.04.11 03:10:00 R1: 1.07425
2024.04.11 03:10:00 R2: 1.07542
2024.04.11 03:10:00
2024.04.11 03:10:00 S1: 0.0
2024.04.11 03:10:00 S2: 0.0
2024.04.11 03:10:00
2024.04.11 03:10:00
2024.04.11 03:10:00 XEA >
2024.04.11 03:10:00 XEA > Ichimoku Kinko Hyo
2024.04.11 03:10:00 XEA > Supprot and Resistance:
2024.04.11 03:10:00 R1: 1.074115
2024.04.11 03:10:00 R2: 1.07416
2024.04.11 03:10:00
2024.04.11 03:10:00 S1: 1.0738750000000001
2024.04.11 03:10:00 S2: 1.0738050000000001
2024.04.11 03:10:00
2024.04.11 03:10:00
+361
View File
@@ -0,0 +1,361 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Candle Indicator
// ---------------------------------------------
// Name: XTM
// Description: Trend Magic 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 XTM Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XTM"
//
// XTM Indicator States ...
enum ENUM_X_XTM_STATES
{
X_XTM_BULLISH = 1,
X_XTM_BEARISH = -1,
X_XTM_NEUTURAL = 0,
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Makret";
input int maPeriod = 35; // Period
input int maShift = 0; // Shift
input ENUM_MA_METHOD maMethod = MODE_SMA; // Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_LOW; // Applied To
input group "Presentation";
input bool showLine = true; // Show Line
//
// END Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 1
//
// maBuffer ...
#define maBufferIndex 0
#define maColorBufferIndex 1
#define stateBufferIndex 2
double maBuffer[];
double maColorBuffer[];
double stateBuffer[];
#property indicator_label1 "XTM"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLime, clrGray, clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
int maHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// Initializing MA Handler ...
maHandler = iMA(
_Symbol,
_Period,
maPeriod,
maShift,
maMethod,
maAppliedTo);
if (maHandler == INVALID_HANDLE)
{
//
string message = "Error Initializing Ma Handler ...";
LogMessage(message);
//
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 ...
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(0, maPeriod);
//
// Check Calculated Bars ...
int maCalculatedBars = BarsCalculated(maHandler);
if (maCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
if (copiedMas <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Do Buffers Calculation ...
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (maPeriod >= 2)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
//
string maBufferLabel = "XTM " + "(" + (string)maPeriod + ")";
//
// Ma Buffer ...
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
//
// Ma Color Buffer ...
ArraySetAsSeries(maColorBuffer, true);
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
//
// State Buffer ...
ArraySetAsSeries(stateBuffer, true);
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", "(", maPeriod, ")");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(int bar_index)
{
//
// Requirements ...
XOHCL candle = GetCandle(bar_index);
//
double maValue = maBuffer[bar_index];
//
double lineColorIndex =
maValue < candle.low ? 0 : maValue > candle.high ? 2
: 1;
//
// Define State Value ...
// lineColorIndex == 0 => Bullish => 1;
// lineColorIndex == 1 => Neutural => 0;
// lineColorIndex == 2 => Bearish => -1;
double stateValue =
lineColorIndex == 0 ? X_XTM_BULLISH : lineColorIndex == 2 ? X_XTM_BEARISH
: X_XTM_NEUTURAL;
//
// Set Ma Buffer Color Index ...
maColorBuffer[bar_index] = lineColorIndex;
//
// Set State Buffer Value ...
stateBuffer[bar_index] = stateValue;
}
//
// END Functions ...
//
@@ -0,0 +1,227 @@
//
// Close All Open Positions when Profit Summary is Reached ...
void HandleGridHedge()
{
//
int openPositionsCount = xEATrade.PositionsCount();
if (openPositionsCount <= 1 ||
xEAMinProfitPerOpenPositionForHedging <= 0)
{
return;
}
//
double requiredProfitForHedging = xEAMinProfitPerOpenPositionForHedging * openPositionsCount;
double accountProfit = xEATrade.GetPositionsProfit();
if (accountProfit > 0 || MathAbs(accountProfit) < requiredProfitForHedging)
{
return;
}
//
string comment = "Close since Grid Hedging ...";
xEATrade.CloseAllPositions(comment);
//
string msg = "Grid Hedging in Loss: " + (string)accountProfit;
LogMessage(msg);
}
//
// Close All Open Positions when Profit Summary is Reached ...
void HandlePyramidHedge()
{
//
int openPositionsCount = xEATrade.PositionsCount();
if (openPositionsCount <= 1 ||
xEAMinProfitPerOpenPositionForHedging <= 0)
{
return;
}
//
double requiredProfitForHedging = xEAMinProfitPerOpenPositionForHedging * openPositionsCount;
double accountProfit = xEATrade.GetPositionsProfit();
if (accountProfit < requiredProfitForHedging)
{
return;
}
//
string comment = "Close since Pyramid Hedging ...";
xEATrade.CloseAllPositions(comment);
//
string msg = "Pyramid Hedging in Profit: " + (string)accountProfit;
LogMessage(msg);
}
//
// Force Close Signals ...
void HandleForceClosing()
{
//
int positionsCount = xEATrade.PositionsCount();
int ordersCount = xEATrade.OrdersCount();
if (positionsCount <= 0 || ordersCount <= 0)
{
return;
}
//
X121ForceClose results[];
xEAProvider.CanForceCloseShortSignals(results);
int resultsCount = ArraySize(results);
if (resultsCount <= 0)
{
return;
}
//
for (int i = 0; i < resultsCount; i++)
{
//
X121ForceClose iForceClose = results[i];
if (!iForceClose.force)
{
continue;
}
//
XPosition iPositions[];
xEATrade.GetPositions(
iPositions,
iForceClose.symbol,
iForceClose.period);
int iPositionsCount = ArraySize(iPositions);
if (iPositionsCount > 0)
{
//
for (int j = 0; j < iPositionsCount; j++)
{
//
XPosition jPosition = iPositions[j];
bool isLong = IsLong(jPosition.type);
if (isLong)
{
continue;
}
//
ENUM_X121_SIGNAL_PROVIDERS jProvider = ExtractProvider(jPosition);
string jProviderStr = ToString(jProvider);
if (jProviderStr != iForceClose.provider)
{
continue;
}
//
string comment = "Force Close Signals ...";
bool isClosed = xEATrade.Close(jPosition.ticket, comment);
if (isClosed)
{
//
string msg = "Position (" + (string)jPosition.ticket + ") Closed Due Force Event ...";
LogMessage(msg);
}
}
}
//
XOrder iOrders[];
xEATrade.GetOrders(
iOrders,
iForceClose.symbol,
iForceClose.period,
ORDER_STATE_PLACED);
int iOrdersCount = ArraySize(iOrders);
if (iOrdersCount > 0)
{
//
bool isCanceled = xEATrade.CancelOrders(iOrders);
if (isCanceled)
{
//
string msg = "(" + (string)ordersCount + ") Canceled due Cycle Change ...";
//
LogMessage(msg);
}
}
}
}
//
// Close a Position and it's Support Due to Profit ...
void HandleHedgeSupports()
{
//
int positionsCount = xEATrade.PositionsCount();
if (positionsCount <= 0)
{
return;
}
//
XPosition positions[];
xEATrade.GetPositions(
positions);
positionsCount = ArraySize(positions);
if (positionsCount <= 0)
{
return;
}
//
for (int i = 0; i < positionsCount; i++)
{
//
XPosition iPosition = positions[i];
//
bool hasSupport = xEATrade.HasSupport(iPosition.ticket);
if (!hasSupport)
{
continue;
}
//
bool isClosed = xEATrade.ClosePositionAndSupports(
iPosition.ticket);
if (isClosed)
{
//
string msg = "Position and Supports Closed ...";
LogMessage(msg);
}
}
}
//
// Delete Specific Order of Support if Exists ...
ulong positionId = deal.positionId;
//
XOrder supports[];
bool hasSupport = xEATrade.GetSupportOrders(
positionId,
supports,
NULL,
NULL,
ORDER_STATE_PLACED);
if (hasSupport)
{
//
bool isCanceled = xEATrade.CancelOrders(supports);
//
if (isCanceled)
{
//
string msg = "Close all Supports of (" + (string)positionId + ") Due to it's TakeProfit Event ...";
LogMessage(msg);
}
}

Some files were not shown because too many files have changed in this diff Show More