update workspace ...
This commit is contained in:
@@ -0,0 +1,385 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCHttp
|
||||
// Description: provides all HTTP 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XSCHttp
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCHttp()
|
||||
{
|
||||
XSCHttp("", 10000);
|
||||
}
|
||||
void XSCHttp(
|
||||
string path, // Base Folder to Store Data
|
||||
int timeout // base timeout for Requests
|
||||
)
|
||||
{
|
||||
//
|
||||
Path(path);
|
||||
Timeout(timeout);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCHttp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Getter(s)/Setter(s) ...
|
||||
//
|
||||
|
||||
//
|
||||
// Path ...
|
||||
void Path(string value)
|
||||
{
|
||||
mPath = value;
|
||||
}
|
||||
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
// Timeout ...
|
||||
void Timeout(int value)
|
||||
{
|
||||
mTimeout = value;
|
||||
}
|
||||
|
||||
//
|
||||
int Timeout()
|
||||
{
|
||||
return mTimeout;
|
||||
}
|
||||
|
||||
//
|
||||
// Error ...
|
||||
int Error()
|
||||
{
|
||||
return mError;
|
||||
}
|
||||
|
||||
//
|
||||
// Response ...
|
||||
string Response()
|
||||
{
|
||||
return mResponse;
|
||||
}
|
||||
|
||||
//
|
||||
// END Getter(s)/Setter(s) ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset State ...
|
||||
ResetState();
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders);
|
||||
|
||||
//
|
||||
if (result < 0)
|
||||
{
|
||||
mError = GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResponse = CharArrayToString(response);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Download Specific URL Content to Specific Path and File Name ...
|
||||
bool Download(
|
||||
string url, // the URL address which going to download
|
||||
string fileName // Specify Destination file name to Store Response
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string filePath = GetFilePath(fileName);
|
||||
string cookie = NULL;
|
||||
string referer = NULL;
|
||||
int timeout = Timeout();
|
||||
|
||||
//
|
||||
char payload[];
|
||||
string headers;
|
||||
char response[];
|
||||
string responseHeaders;
|
||||
|
||||
//
|
||||
// Send Request ...
|
||||
int requestResult = GetRequest(
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
// Define File Handler ...
|
||||
int mFileHandler = FileOpen(
|
||||
filePath,
|
||||
FILE_WRITE | FILE_BIN);
|
||||
if (mFileHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
mError = GetLastError();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Write Response to File ...
|
||||
uint writed = FileWriteArray(
|
||||
mFileHandler,
|
||||
response,
|
||||
0,
|
||||
ArraySize(response));
|
||||
FileFlush(mFileHandler);
|
||||
FileClose(mFileHandler);
|
||||
|
||||
//
|
||||
result = writed > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Destintion Folder Path ...
|
||||
string mPath;
|
||||
|
||||
//
|
||||
// WEB Request Timeout Value ...
|
||||
int mTimeout;
|
||||
|
||||
//
|
||||
// WEB Request's Response ...
|
||||
string mResponse;
|
||||
|
||||
//
|
||||
// Error Value ...
|
||||
int mError;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Reset Errors State ...
|
||||
void ResetState()
|
||||
{
|
||||
//
|
||||
// Reset Errors ...
|
||||
mError = -1;
|
||||
mResponse = "";
|
||||
ResetLastError();
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Full File Path ...
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
Path() + "\\" + fileName
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,443 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121EA
|
||||
// Description: an Expert Class which
|
||||
// used X121 Setup ...
|
||||
//
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.xea.class.mq5"
|
||||
#include "../Libraries/x-saherelm.x121.draw.lib.mq5"
|
||||
#include "../Classes/x-saherelm.x121.provider.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// an Expert Advisor Class by X121Provider ...
|
||||
class XSCX121EA : public XSCBaseEA
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
XSCX121Provider *mProvider;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCX121EA(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Time Frame
|
||||
ulong magic, // Magic Number
|
||||
int slippage, // Slippgae
|
||||
OnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
|
||||
OnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
|
||||
OnDealsChanged onDealsChangedHandler = NULL, // On Deals Changed Event Handler
|
||||
OnOrdersChanged onOrdersChangedHandler = NULL, // On Orders Changed Event Handler
|
||||
OnPositionsChanged onPositionsChangedHandler = NULL, // On Positions Changed Event Handler
|
||||
OnTradeStateChanged onTradeStateChangedHandler = NULL, // On Trade State Changed Event Handler
|
||||
TOnSignalConditions onSignalConditions = NULL // On SignalConditions Event Handler
|
||||
) : XSCBaseEA(symbol,
|
||||
period,
|
||||
magic,
|
||||
slippage,
|
||||
onStopLossTriggered,
|
||||
onTakeProfitTriggered,
|
||||
onDealsChangedHandler,
|
||||
onOrdersChangedHandler,
|
||||
onPositionsChangedHandler,
|
||||
onTradeStateChangedHandler)
|
||||
{
|
||||
//
|
||||
mOnSignalConditions = onSignalConditions;
|
||||
|
||||
//
|
||||
InitProvider();
|
||||
}
|
||||
|
||||
//
|
||||
// DeConstructor ...
|
||||
void ~XSCX121EA()
|
||||
{
|
||||
delete mProvider;
|
||||
}
|
||||
|
||||
//
|
||||
// START Inheritance Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
void PrepareTag()
|
||||
{
|
||||
mTag = "X121EA:" + mSymbol + "," + ToString(mPeriod) + (string)mMagic;
|
||||
}
|
||||
|
||||
//
|
||||
bool CheckGuard(XGuard &guards[])
|
||||
{
|
||||
return mProvider.GuardCheck(guards);
|
||||
}
|
||||
|
||||
//
|
||||
bool SignalCheck(XSignal &signals[])
|
||||
{
|
||||
//
|
||||
// Detect Pivot Points ...
|
||||
int foundedPivots = mProvider.CountPivots();
|
||||
int reuiredPivots = mProvider.GetMinPivots();
|
||||
if (foundedPivots < reuiredPivots)
|
||||
{
|
||||
//
|
||||
mProvider.ProccessPivotPoints();
|
||||
|
||||
//
|
||||
LogMessage("Founding Pivots: " + ToString(foundedPivots) + "/" + ToString(reuiredPivots));
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
X121MarketConditions conditions;
|
||||
bool result = mProvider.ProcessTick(conditions);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// TODO: Here we Do all Signal Preparations such as TP/SL Calculations
|
||||
// or Support and Resistance usage or Volume Calculations ...
|
||||
// then pass prepared Signal to Execution ...
|
||||
|
||||
//
|
||||
ulong mTicket = MathRand() * 100000;
|
||||
|
||||
//
|
||||
DrawSignal(
|
||||
mTicket,
|
||||
conditions.signal);
|
||||
|
||||
//
|
||||
DrawSupportResistance(
|
||||
0,
|
||||
conditions.supportResistances,
|
||||
conditions.signal.providers[0]);
|
||||
|
||||
//
|
||||
// IGNORE SIGNAL EXECUTTION ...
|
||||
return false;
|
||||
|
||||
//
|
||||
Add(
|
||||
conditions.signal,
|
||||
signals);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Inheritance Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Actions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Provided Actions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121ProviderInputs mProviderConfig;
|
||||
TOnSignalConditions mOnSignalConditions;
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
//
|
||||
// Prepare Default Configurations for X121Provider Setup ...
|
||||
void PrepareProviderConfig()
|
||||
{
|
||||
//
|
||||
// XCT ...
|
||||
// Candle Timing ...
|
||||
mProviderConfig.xctConfig.clr = clrBlueViolet;
|
||||
mProviderConfig.xctConfig.corner = CORNER_RIGHT_UPPER;
|
||||
mProviderConfig.xctConfig.showCandleTime = true;
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
// Candle Styling ...
|
||||
mProviderConfig.xccConfig.upColor = clrLime;
|
||||
mProviderConfig.xccConfig.downColor = clrRed;
|
||||
mProviderConfig.xccConfig.lineColor = clrLime;
|
||||
mProviderConfig.xccConfig.bearishColor = clrRed;
|
||||
mProviderConfig.xccConfig.bullishColor = clrLime;
|
||||
mProviderConfig.xccConfig.volumesColor = clrGreen;
|
||||
mProviderConfig.xccConfig.showCandles = true;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
// HikenAshi Candle Representing ...
|
||||
mProviderConfig.xhkConfig.drawCandleLines = false;
|
||||
|
||||
//
|
||||
// XTM ...
|
||||
// Trend Magic ...
|
||||
mProviderConfig.xtmConfig.length = 35;
|
||||
mProviderConfig.xtmConfig.shift = 0;
|
||||
mProviderConfig.xtmConfig.method = MODE_SMA;
|
||||
mProviderConfig.xtmConfig.appliedTo = PRICE_LOW;
|
||||
mProviderConfig.xtmConfig.showLine = false;
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
// Peaks And Vales ...
|
||||
mProviderConfig.xpvConfig.shortLength = 9;
|
||||
mProviderConfig.xpvConfig.mediumLength = 17;
|
||||
mProviderConfig.xpvConfig.longLength = 26;
|
||||
mProviderConfig.xpvConfig.hindLength = 35;
|
||||
mProviderConfig.xpvConfig.fiboLevel1 = 0.382;
|
||||
mProviderConfig.xpvConfig.fiboLevel2 = 0.5;
|
||||
mProviderConfig.xpvConfig.fiboLevel3 = 0.618;
|
||||
mProviderConfig.xpvConfig.hhMode = MODE_HIGH;
|
||||
mProviderConfig.xpvConfig.llMode = MODE_LOW;
|
||||
mProviderConfig.xpvConfig.showPeaksAndVales = false;
|
||||
mProviderConfig.xpvConfig.showLevels = false;
|
||||
mProviderConfig.xpvConfig.showFibo1Levels = false;
|
||||
mProviderConfig.xpvConfig.showFibo2Levels = false;
|
||||
mProviderConfig.xpvConfig.showFibo3Levels = false;
|
||||
|
||||
//
|
||||
// XAMA ...
|
||||
// Adaptive Moving Average ...
|
||||
mProviderConfig.xamaConfig.length = 52;
|
||||
mProviderConfig.xamaConfig.fastEMA = 2;
|
||||
mProviderConfig.xamaConfig.slowEMA = 30;
|
||||
mProviderConfig.xamaConfig.maShift = 0;
|
||||
mProviderConfig.xamaConfig.appliedTo = PRICE_LOW;
|
||||
mProviderConfig.xamaConfig.showLine = false;
|
||||
|
||||
//
|
||||
// XMRB ...
|
||||
// Moving Average Ribbon ...
|
||||
mProviderConfig.xmrbConfig.fast1Length = 3;
|
||||
mProviderConfig.xmrbConfig.slow1Length = 5;
|
||||
mProviderConfig.xmrbConfig.fast2Length = 8;
|
||||
mProviderConfig.xmrbConfig.slow2Length = 13;
|
||||
mProviderConfig.xmrbConfig.fast3Length = 21;
|
||||
mProviderConfig.xmrbConfig.slow3Length = 34;
|
||||
mProviderConfig.xmrbConfig.fast4Length = 55;
|
||||
mProviderConfig.xmrbConfig.slow4Length = 89;
|
||||
mProviderConfig.xmrbConfig.fast5Length = 144;
|
||||
mProviderConfig.xmrbConfig.slow5Length = 233;
|
||||
mProviderConfig.xmrbConfig.ribbonMode = MODE_EMA;
|
||||
mProviderConfig.xmrbConfig.ribbonAppliedTo = PRICE_CLOSE;
|
||||
mProviderConfig.xmrbConfig.showFastMa = false;
|
||||
mProviderConfig.xmrbConfig.showSlowMa = false;
|
||||
mProviderConfig.xmrbConfig.showRibbon = false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
// Chandelier Exit Points ...
|
||||
mProviderConfig.xcheConfig.length = 35;
|
||||
mProviderConfig.xcheConfig.loopback = 26;
|
||||
mProviderConfig.xcheConfig.multiplier1 = 3;
|
||||
mProviderConfig.xcheConfig.multiplier2 = 3.5;
|
||||
mProviderConfig.xcheConfig.upAppliedTo = PRICE_HIGH;
|
||||
mProviderConfig.xcheConfig.downAppliedTo = PRICE_LOW;
|
||||
mProviderConfig.xcheConfig.showLongExit1Line = false;
|
||||
mProviderConfig.xcheConfig.showShortExit1Line = false;
|
||||
mProviderConfig.xcheConfig.showLongExit2Line = false;
|
||||
mProviderConfig.xcheConfig.showShortExit2Line = false;
|
||||
|
||||
//
|
||||
// XICH ...
|
||||
// Ichimopku Kinko Hyo ...
|
||||
mProviderConfig.xichConfig.tenkanSenLength = 9;
|
||||
mProviderConfig.xichConfig.tenkanSenMode = X_XICH_HH_LL_MODE;
|
||||
mProviderConfig.xichConfig.kijunSenLength = 26;
|
||||
mProviderConfig.xichConfig.kijunSenMode = X_XICH_HH_LL_MODE;
|
||||
mProviderConfig.xichConfig.senkouSpanBLength = 52;
|
||||
mProviderConfig.xichConfig.senkouSpanBMode = X_XICH_HH_LL_MODE;
|
||||
mProviderConfig.xichConfig.chikuoSpanAppliedTo = PRICE_CLOSE;
|
||||
mProviderConfig.xichConfig.showTenkanSen = false;
|
||||
mProviderConfig.xichConfig.showKijunSen = false;
|
||||
mProviderConfig.xichConfig.showKijunSenPlus = false;
|
||||
mProviderConfig.xichConfig.showKijunSenNegative = false;
|
||||
mProviderConfig.xichConfig.showChikouSpan = false;
|
||||
mProviderConfig.xichConfig.showSenkouSpanA = false;
|
||||
mProviderConfig.xichConfig.showSenkouSpanB = false;
|
||||
mProviderConfig.xichConfig.showKumo = false;
|
||||
mProviderConfig.xichConfig.shiftKumo = true;
|
||||
|
||||
//
|
||||
// XTRND ...
|
||||
// Trend Detector ...
|
||||
mProviderConfig.xtrndConfig.cycleLength = 2;
|
||||
mProviderConfig.xtrndConfig.numberOfVerifications = 2;
|
||||
mProviderConfig.xtrndConfig.hhMode = MODE_HIGH;
|
||||
mProviderConfig.xtrndConfig.llMode = MODE_LOW;
|
||||
mProviderConfig.xtrndConfig.l1Method = X_PERIOD_AUTO;
|
||||
mProviderConfig.xtrndConfig.l1Period = NULL;
|
||||
mProviderConfig.xtrndConfig.l2Method = X_PERIOD_AUTO;
|
||||
mProviderConfig.xtrndConfig.l2Period = NULL;
|
||||
mProviderConfig.xtrndConfig.l3Method = X_PERIOD_AUTO;
|
||||
mProviderConfig.xtrndConfig.l3Period = NULL;
|
||||
mProviderConfig.xtrndConfig.showConsolidations = false;
|
||||
mProviderConfig.xtrndConfig.showTrend = false;
|
||||
mProviderConfig.xtrndConfig.showL1Trend = false;
|
||||
mProviderConfig.xtrndConfig.showL2Trend = false;
|
||||
mProviderConfig.xtrndConfig.showL3Trend = false;
|
||||
|
||||
//
|
||||
// XSSLC ...
|
||||
// SSL Channel ...
|
||||
mProviderConfig.xsslcConfig.length = 36;
|
||||
mProviderConfig.xsslcConfig.method = MODE_SMA;
|
||||
mProviderConfig.xsslcConfig.upAppliedTo = PRICE_HIGH;
|
||||
mProviderConfig.xsslcConfig.downAppliedTo = PRICE_LOW;
|
||||
mProviderConfig.xsslcConfig.showUp = false;
|
||||
mProviderConfig.xsslcConfig.showDown = false;
|
||||
|
||||
//
|
||||
// XHULL ...
|
||||
// Hull Trend Detection Channel ...
|
||||
mProviderConfig.xhullConfig.length = 72;
|
||||
mProviderConfig.xhullConfig.divisor = 2;
|
||||
mProviderConfig.xhullConfig.upAppliedTo = PRICE_HIGH;
|
||||
mProviderConfig.xhullConfig.downAppliedTo = PRICE_LOW;
|
||||
mProviderConfig.xhullConfig.showUpZone = false;
|
||||
mProviderConfig.xhullConfig.showDownZone = false;
|
||||
|
||||
//
|
||||
// Default Configs For Different States ...
|
||||
bool showPV = true;
|
||||
bool showHK = true;
|
||||
bool showCHE = true;
|
||||
bool showTRND = true;
|
||||
bool simpleIchi = true;
|
||||
|
||||
//
|
||||
if (showHK)
|
||||
{
|
||||
//
|
||||
// Hiken Ashi ...
|
||||
mProviderConfig.xccConfig.showCandles = false;
|
||||
mProviderConfig.xhkConfig.drawCandles = true;
|
||||
}
|
||||
if (showPV)
|
||||
{
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
mProviderConfig.xpvConfig.showFibo1Levels = true;
|
||||
mProviderConfig.xpvConfig.showFibo2Levels = true;
|
||||
mProviderConfig.xpvConfig.showFibo3Levels = true;
|
||||
mProviderConfig.xpvConfig.showPeaksAndVales = true;
|
||||
}
|
||||
if (simpleIchi)
|
||||
{
|
||||
//
|
||||
// Simple Ichimoku Kinko Hyo ...
|
||||
mProviderConfig.xichConfig.showKijunSen = true;
|
||||
mProviderConfig.xichConfig.showTenkanSen = true;
|
||||
mProviderConfig.xichConfig.showSenkouSpanA = true;
|
||||
mProviderConfig.xichConfig.showSenkouSpanB = true;
|
||||
}
|
||||
if (showCHE)
|
||||
{
|
||||
//
|
||||
// Chandelier Exit ...
|
||||
mProviderConfig.xcheConfig.showLongExit1Line = true;
|
||||
mProviderConfig.xcheConfig.showLongExit2Line = true;
|
||||
mProviderConfig.xcheConfig.showShortExit1Line = true;
|
||||
mProviderConfig.xcheConfig.showShortExit2Line = true;
|
||||
}
|
||||
if (showTRND)
|
||||
{
|
||||
//
|
||||
// Show Trend ...
|
||||
mProviderConfig.xtrndConfig.showL1Trend = true;
|
||||
mProviderConfig.xtrndConfig.showL2Trend = true;
|
||||
mProviderConfig.xtrndConfig.showL3Trend = true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize X121Provider ...
|
||||
void InitProvider()
|
||||
{
|
||||
//
|
||||
PrepareProviderConfig();
|
||||
|
||||
//
|
||||
mProvider = new XSCX121Provider(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
|
||||
//
|
||||
if (mOnSignalConditions != NULL)
|
||||
{
|
||||
//
|
||||
// Attach Event Handlers ...
|
||||
mProvider.AddOnSignalConditionEventHandler(mOnSignalConditions);
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Provider ...
|
||||
mProvider.SetConfig(mProviderConfig);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,398 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCAccount
|
||||
// Description: provides all Account 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include <Trade/AccountInfo.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XSCAccount
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCAccount()
|
||||
{
|
||||
//
|
||||
mAccountInfo = new CAccountInfo();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCAccount()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// User Account ...
|
||||
long GetUserAccount()
|
||||
{
|
||||
return mAccountInfo.Login();
|
||||
}
|
||||
|
||||
//
|
||||
// Account Leverage ...
|
||||
long GetLeverage()
|
||||
{
|
||||
return mAccountInfo.Leverage();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Trade Expert State ...
|
||||
bool CanExpertTrade()
|
||||
{
|
||||
return mAccountInfo.TradeExpert();
|
||||
}
|
||||
|
||||
//
|
||||
// User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ...
|
||||
// --------------------------
|
||||
// ACCOUNT_TRADE_MODE_DEMO
|
||||
// ACCOUNT_TRADE_MODE_CONTEST
|
||||
// ACCOUNT_TRADE_MODE_REAL
|
||||
ENUM_ACCOUNT_TRADE_MODE GetTradeMode()
|
||||
{
|
||||
return mAccountInfo.TradeMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Account Balance ...
|
||||
double GetBalance()
|
||||
{
|
||||
return mAccountInfo.Balance();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of give Credit ...
|
||||
double GetCredit()
|
||||
{
|
||||
return mAccountInfo.Credit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Profit on account ...
|
||||
double GetProfit()
|
||||
{
|
||||
return mAccountInfo.Profit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Equity on account ...
|
||||
double GetEquity()
|
||||
{
|
||||
return mAccountInfo.Equity();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of reserved Margin ...
|
||||
double GetMargin()
|
||||
{
|
||||
return mAccountInfo.Margin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of free Margin ...
|
||||
double GetFreeMargin()
|
||||
{
|
||||
return mAccountInfo.FreeMargin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin ...
|
||||
double GetMarginLevel()
|
||||
{
|
||||
return mAccountInfo.MarginLevel();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level Of Margin for a Deposit ...
|
||||
double GetMarginCall()
|
||||
{
|
||||
return mAccountInfo.MarginCall();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin for Stop out ...
|
||||
double GetMarginStopOut()
|
||||
{
|
||||
return mAccountInfo.MarginStopOut();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Client Name ...
|
||||
string GetName()
|
||||
{
|
||||
return mAccountInfo.Name();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Trade Server Name ...
|
||||
string GetServerName()
|
||||
{
|
||||
return mAccountInfo.Server();
|
||||
}
|
||||
|
||||
//
|
||||
// Get deposit Currency Name ...
|
||||
string GetCurrency()
|
||||
{
|
||||
return mAccountInfo.Currency();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Company Name that serves an Account ...
|
||||
string GetCompany()
|
||||
{
|
||||
return mAccountInfo.Company();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Profits for the current account based on passed parameters ...
|
||||
double CalculateTradeProfit(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry, // open price
|
||||
double exit // close price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.OrderProfitCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry,
|
||||
exit);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of margin which required for trade operation ...
|
||||
double CalculateMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of free margin left after trade operation ...
|
||||
double CalculateFreeMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.FreeMarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate the Maximum possible volume of trade operation ...
|
||||
double CalculateMaxVolume(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double entry, // open price
|
||||
double percent = 100 // percent of available margin
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MaxLotCheck(
|
||||
symbol,
|
||||
type,
|
||||
entry,
|
||||
percent);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Point Value for Given Symbol based on Account ...
|
||||
double GetPointValue(
|
||||
string symbol // trading symbol
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
|
||||
double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
|
||||
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
|
||||
|
||||
//
|
||||
double ticksPerPoint = tickSize / point;
|
||||
|
||||
//
|
||||
result = tickValue / ticksPerPoint;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Amount based on account Currency by Providing:
|
||||
// Points and Volume ...
|
||||
double CalculateRiskAmount(
|
||||
string symbol, // trading symbol
|
||||
double points, // amount of Risk Points
|
||||
double volume // position Volume
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = pointValue * volume * points;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Points based on account Currency by Providing:
|
||||
// Volume and Amount ...
|
||||
double CalculateRiskPoints(
|
||||
string symbol, // trading symbol
|
||||
double volume, // position Volume
|
||||
double amount // amount of Risk based on Account Currency
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * volume);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Volume based on account Currency by Providing:
|
||||
// Amount and Risk Points ...
|
||||
double CalculateVolume(
|
||||
string symbol, // trading symbol
|
||||
double amount, // amount of Risk based on Account Currency
|
||||
double points // amount of Risk Points
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
points =
|
||||
points <= 0
|
||||
? 10
|
||||
: points;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * points);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Account Info ...
|
||||
CAccountInfo mAccountInfo;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,814 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCBaseEA
|
||||
// Description: provides all Base EA 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.alert.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Classes/x-saherelm.xaccount.class.mq5"
|
||||
#include "../Classes/x-saherelm.xprovider.class.mq5"
|
||||
#include "../Libraries/x-saherelm.seriallizer.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCBaseEA
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
XSCTrade *mTrader;
|
||||
XSCAccount *mAccount;
|
||||
|
||||
//
|
||||
bool isNewHour;
|
||||
bool isNewDay;
|
||||
bool isNewWeek;
|
||||
bool isNewMonth;
|
||||
bool isNewCandle;
|
||||
|
||||
//
|
||||
bool isInTestMode;
|
||||
|
||||
//
|
||||
bool mWaitsUntilNewCandle;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCBaseEA(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Time Frame
|
||||
ulong magic, // Magic Number
|
||||
int slippage, // Slippgae
|
||||
OnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
|
||||
OnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
|
||||
OnDealsChanged onDealsChangedHandler = NULL, // On Deals Changed Event Handler
|
||||
OnOrdersChanged onOrdersChangedHandler = NULL, // On Orders Changed Event Handler
|
||||
OnPositionsChanged onPositionsChangedHandler = NULL, // On Positions Changed Event Handler
|
||||
OnTradeStateChanged onTradeStateChangedHandler = NULL // On Trade State Changed Event Handler
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mMagic = magic;
|
||||
mSlippage = slippage;
|
||||
|
||||
//
|
||||
mOnStopLossTriggered = onStopLossTriggered;
|
||||
mOnTakeProfitTriggered = onTakeProfitTriggered;
|
||||
mOnDealsChangedHandler = onDealsChangedHandler;
|
||||
mOnOrdersChangedHandler = onOrdersChangedHandler;
|
||||
mOnPositionsChangedHandler = onPositionsChangedHandler;
|
||||
mOnTradeStateChangedHandler = onTradeStateChangedHandler;
|
||||
|
||||
//
|
||||
// Reset Timings ...
|
||||
ResetTiming();
|
||||
|
||||
//
|
||||
InitRequirements();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCBaseEA()
|
||||
{
|
||||
//
|
||||
delete mTrader;
|
||||
delete mAccount;
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Tag ...
|
||||
string GetTag()
|
||||
{
|
||||
return mTag;
|
||||
}
|
||||
|
||||
//
|
||||
ulong GetMagic()
|
||||
{
|
||||
return mMagic;
|
||||
}
|
||||
|
||||
//
|
||||
int GetSlippage()
|
||||
{
|
||||
return mSlippage;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XEA" + mSymbol + "," + ToString(mPeriod) + (string)mMagic;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Chart Events ...
|
||||
virtual void OnChartEvent(
|
||||
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
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Check any Registered Providers Signalling ...
|
||||
virtual bool SignalCheck(XSignal &signals[]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for any Custom Guard Actions Guard Actions ...
|
||||
virtual bool CheckGuard(XGuard &guards[]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// NOTE: you have to call these Functions on Static Classes to Handle Works ...
|
||||
|
||||
//
|
||||
// Handle StopLoss Event ...
|
||||
virtual void OnStopLossTriggered(const XDeal &deal) {}
|
||||
|
||||
//
|
||||
// Handle TakeProfit Event ...
|
||||
virtual void OnTakeProfitTriggered(const XDeal &deal) {}
|
||||
|
||||
//
|
||||
// Handle Deals Changed Event ...
|
||||
virtual void OnDealsChangedHandler(int count) {}
|
||||
|
||||
//
|
||||
// Handle Order Changed Event ...
|
||||
virtual void OnOrdersChangedHandler(int count) {}
|
||||
|
||||
//
|
||||
// Handle Position Changed Event ...
|
||||
virtual void OnPositionsChangedHandler(int count) {}
|
||||
|
||||
//
|
||||
// Handle Trade State Changed ...
|
||||
virtual void OnTradeStateChangedHandler(const XOnTradeHandlerState &state) {}
|
||||
|
||||
//
|
||||
// Implemented Actions ...
|
||||
|
||||
//
|
||||
// OnTick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// First Check Guards ....
|
||||
XGuard guards[];
|
||||
bool hasGuard = CheckGuard(guards);
|
||||
if (hasGuard) {
|
||||
DoGuards(guards);
|
||||
}
|
||||
|
||||
//
|
||||
XSignal signals[];
|
||||
bool hasSignal = SignalCheck(signals);
|
||||
if (hasSignal) {
|
||||
mTrader.ExecuteSignals(signals);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade ...
|
||||
void OnTrade()
|
||||
{
|
||||
//
|
||||
XOnTradeHandlerState state = mTrader.HandleOnTrade();
|
||||
|
||||
//
|
||||
if (
|
||||
!state.hasNewDeal &&
|
||||
!state.hasNewOrder &&
|
||||
!state.hasNewPosition &&
|
||||
!state.hasNewHistoryOrder)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// STATE ...
|
||||
|
||||
//
|
||||
// Notfy Trade State Changed Event ...
|
||||
OnTradeStateChangedHandler(state);
|
||||
|
||||
//
|
||||
// DEALS ...
|
||||
if (state.hasNewDeal)
|
||||
{
|
||||
//
|
||||
// Notfy Deals Changed Event ...
|
||||
OnDealsChangedHandler(state.newDeals);
|
||||
|
||||
//
|
||||
// Retrieve Last Deal ...
|
||||
XDeal deals[];
|
||||
mTrader.GetDeals(deals);
|
||||
int dealsCount = ArraySize(deals);
|
||||
if (dealsCount > 0)
|
||||
{
|
||||
//
|
||||
XDeal lastDeal = deals[0];
|
||||
|
||||
//
|
||||
if (lastDeal.reason == DEAL_REASON_TP)
|
||||
{
|
||||
OnTakeProfitTriggered(lastDeal);
|
||||
}
|
||||
else if (lastDeal.reason == DEAL_REASON_SL)
|
||||
{
|
||||
OnStopLossTriggered(lastDeal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ORDERS ...
|
||||
if (state.hasNewOrder || state.hasNewHistoryOrder)
|
||||
{
|
||||
//
|
||||
// Notfy Orders Changed Event ...
|
||||
OnOrdersChangedHandler(state.newOrders + state.newHistoryOrders);
|
||||
}
|
||||
|
||||
//
|
||||
// POSITIONS ...
|
||||
if (state.hasNewPosition)
|
||||
{
|
||||
//
|
||||
// Notfy Positions Changed Event ...
|
||||
OnPositionsChangedHandler(state.newPositions);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Dept Of Market ...
|
||||
void OnBookEvent(const string &symbol)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// TOOLS ...
|
||||
//
|
||||
void GetPositions(
|
||||
XPosition &result[], // Hold Result ...
|
||||
string symbol = NULL, // Trading Symbol ...
|
||||
ENUM_POSITION_TYPE type = NULL, // Trading Type ...
|
||||
ENUM_TIMEFRAMES period = NULL // Trading Period ...
|
||||
)
|
||||
{
|
||||
//
|
||||
Clean(result);
|
||||
|
||||
//
|
||||
int positionsCount = mTrader.PositionsCount();
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
mTrader.GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
period);
|
||||
positionsCount = ArraySize(positions);
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (type == NULL)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
result,
|
||||
ArraySize(positions));
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
positions[i],
|
||||
result);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
if (type == NULL || iPosition.type == type)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iPosition,
|
||||
result);
|
||||
}
|
||||
}
|
||||
}
|
||||
void GetPositions(
|
||||
XPosition &result[], // Hold Result ...
|
||||
string symbol = NULL, // Trading Symbol ...
|
||||
ENUM_POSITION_TYPE type = NULL, // Trading Type ...
|
||||
ENUM_TIMEFRAMES period = NULL, // Trading Period ...
|
||||
string provider = NULL // Signal Provider ...
|
||||
)
|
||||
{
|
||||
//
|
||||
Clean(result);
|
||||
|
||||
//
|
||||
bool hasSymbol = !(symbol == NULL || StringLen(symbol) == 0);
|
||||
bool hasProvider = !(provider == NULL || StringLen(provider) == 0);
|
||||
|
||||
//
|
||||
int positionsCount = mTrader.PositionsCount();
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
mTrader.GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
period);
|
||||
positionsCount = ArraySize(positions);
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (!hasProvider && type == NULL)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
result,
|
||||
ArraySize(positions));
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
positions[i],
|
||||
result);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (type == NULL)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
result,
|
||||
ArraySize(positions));
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
positions[i],
|
||||
result);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
string iProvider = ExtractProvider(iPosition.comment);
|
||||
if (hasProvider && iProvider != provider)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
if (type == NULL || iPosition.type == type)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iPosition,
|
||||
result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// GUARD Handlers ...
|
||||
|
||||
//
|
||||
// Parse Recievd Guards and Do them ...
|
||||
void DoGuards(XGuard &guards[])
|
||||
{
|
||||
int guardsCount = ArraySize(guards);
|
||||
if (guardsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < guardsCount; i++)
|
||||
{
|
||||
//
|
||||
XGuard iGuard = guards[i];
|
||||
|
||||
//
|
||||
switch (iGuard.action)
|
||||
{
|
||||
//
|
||||
// Hedge In Profit Specified Positions ...
|
||||
case X_GUARD_ACTION_HEDGE:
|
||||
HandleGuardHedgeAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
|
||||
//
|
||||
// Trail Stop Loss in Specified Positions ...
|
||||
case X_GUARD_ACTION_TRAIL_STOP:
|
||||
HandleGuardTrailingStopAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period,
|
||||
iGuard.dblPayLoad);
|
||||
break;
|
||||
|
||||
//
|
||||
// Force Close Specified Positions ...
|
||||
case X_GUARD_ACTION_FORCE_CLOSE:
|
||||
HandleGuardForceCloseAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
|
||||
//
|
||||
// Generate and Place Support Signals ...
|
||||
case X_GUARD_ACTION_ADD_SUPPORT_SIGNAL:
|
||||
HandleGuardAddSupportPositionAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
|
||||
//
|
||||
// Delete All Placed Pending Orders ...
|
||||
case X_GUARD_ACTION_CANCEL_PENDING_ORDERS:
|
||||
HandleGuardCancelPendingOrdersAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Close All Specified Provider's Positions in Profit Summary ...
|
||||
void HandleGuardHedgeAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period, // Specified Time Frame
|
||||
double minProfitForHedging = 1 // Specified Profit for Hedge ...
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Force Close Specified Set Of Position ...
|
||||
void HandleGuardForceCloseAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period, // Specified Time Frame
|
||||
ulong ticket = 0 // Specific Ticket
|
||||
)
|
||||
{
|
||||
//
|
||||
string comment = "";
|
||||
|
||||
//
|
||||
// Close All Positions ...
|
||||
if (ticket == 0)
|
||||
{
|
||||
//
|
||||
XPosition positions[];
|
||||
GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
type,
|
||||
period,
|
||||
provider);
|
||||
if (ArraySize(positions) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
comment = provider + " Force Close Guard ...";
|
||||
|
||||
//
|
||||
mTrader.ClosePositions(
|
||||
positions,
|
||||
comment);
|
||||
}
|
||||
//
|
||||
// Close Specific Position ...
|
||||
else
|
||||
{
|
||||
//
|
||||
XPosition position;
|
||||
bool hasPosition = mTrader.GetPosition(
|
||||
position,
|
||||
ticket);
|
||||
|
||||
//
|
||||
if (hasPosition)
|
||||
{
|
||||
//
|
||||
comment = provider + "(" + ToString(ticket) + ")" + " Force Close Guard ...";
|
||||
|
||||
//
|
||||
mTrader.Close(
|
||||
ticket,
|
||||
comment);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (StringLen(comment) > 0)
|
||||
{
|
||||
LogMessage(comment);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Trailing Specified Set Of Positions Stop Losses ...
|
||||
void HandleGuardTrailingStopAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period, // Specified Time Frame
|
||||
double sl // Desired SL Value ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// Add Support Signal for Specified Positions ...
|
||||
void HandleGuardAddSupportPositionAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period // Specified Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// Cancel all Placed Orders ...
|
||||
void HandleGuardCancelPendingOrdersAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period // Specified Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string GetTagPrefix()
|
||||
{
|
||||
//
|
||||
string result = "(" + mSymbol + ")(" + ToString(mPeriod) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// ExpertAdviser MAgic Number ...
|
||||
ulong mMagic;
|
||||
|
||||
//
|
||||
// Slipppage ...
|
||||
int mSlippage;
|
||||
|
||||
//
|
||||
// Tag Identifier ...
|
||||
string mTag;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Define Requirements ...
|
||||
|
||||
//
|
||||
// XSCTrade Event Handlers ...
|
||||
OnStopLoss mOnStopLossTriggered;
|
||||
OnTakeProfit mOnTakeProfitTriggered;
|
||||
OnDealsChanged mOnDealsChangedHandler;
|
||||
OnOrdersChanged mOnOrdersChangedHandler;
|
||||
OnPositionsChanged mOnPositionsChangedHandler;
|
||||
OnTradeStateChanged mOnTradeStateChangedHandler;
|
||||
|
||||
//
|
||||
// Initi Requirements ...
|
||||
void InitRequirements()
|
||||
{
|
||||
//
|
||||
// Account Manager ...
|
||||
mAccount = new XSCAccount();
|
||||
|
||||
//
|
||||
// Trader ...
|
||||
mTrader = new XSCTrade(
|
||||
mSlippage,
|
||||
mMagic);
|
||||
|
||||
//
|
||||
// Attach Event Handlers ...
|
||||
|
||||
//
|
||||
if (mOnStopLossTriggered != NULL)
|
||||
{
|
||||
mTrader.AddOnStopLossEventHandler(mOnStopLossTriggered);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnTakeProfitTriggered != NULL)
|
||||
{
|
||||
mTrader.AddOnTakeProfitEventHandler(mOnTakeProfitTriggered);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnDealsChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnDealsChangedEventHandler(mOnDealsChangedHandler);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnOrdersChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnOrdersChangedEventHandler(mOnOrdersChangedHandler);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnPositionsChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnPositionsChangedEventHandler(mOnPositionsChangedHandler);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnTradeStateChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnTradeStateChangedEventHandler(mOnTradeStateChangedHandler);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,209 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCBaseHelper
|
||||
// Description: provides all Base 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCBaseHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
LoopBack(52);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCBaseHelper()
|
||||
{
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Loopback Bars ...
|
||||
void LoopBack(int value)
|
||||
{
|
||||
mLoopbackBars = value;
|
||||
}
|
||||
|
||||
int Loopback()
|
||||
{
|
||||
return mLoopbackBars;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Tag ...
|
||||
string GetTag()
|
||||
{
|
||||
return mTag;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Bars ...
|
||||
int GetBars()
|
||||
{
|
||||
//
|
||||
int result =
|
||||
Bars(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int GetCalculatedBars()
|
||||
{
|
||||
return BarsCalculated(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag() {}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve MAx Required Length for Calculations ...
|
||||
virtual int GetMaxLength();
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string GetTagPrefix()
|
||||
{
|
||||
//
|
||||
string result = "(" + mSymbol + ")(" + ToString(mPeriod) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// Indicator Handler ...
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
// Number Of Items Read Per Tick ...
|
||||
int mLoopbackBars;
|
||||
|
||||
//
|
||||
// Tag Identifier ...
|
||||
string mTag;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,295 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCNotifier
|
||||
// Description: provides all Base Notification 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Notification Model ...
|
||||
typedef void (*OnMessage)(
|
||||
string, // action ...
|
||||
string // payload ...
|
||||
);
|
||||
|
||||
//
|
||||
struct XNotifierEventListener
|
||||
{
|
||||
string action;
|
||||
OnMessage listeners[];
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#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 Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCNotifier
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCNotifier()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCNotifier()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
bool AddEventListener(
|
||||
string action, // Specific Action ...
|
||||
OnMessage listener // Specific Listener ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int aIndex = FindActionIndex(action);
|
||||
if (aIndex < 0)
|
||||
{
|
||||
//
|
||||
// Create a New Structure ...
|
||||
XNotifierEventListener model;
|
||||
|
||||
//
|
||||
model.action = action;
|
||||
|
||||
//
|
||||
Add(
|
||||
listener,
|
||||
model.listeners);
|
||||
|
||||
//
|
||||
Add(
|
||||
model,
|
||||
mEventListeners);
|
||||
|
||||
//
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Just Add Listener to Exists model ...
|
||||
Add(
|
||||
listener,
|
||||
mEventListeners[aIndex].listeners);
|
||||
|
||||
//
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool NotifyEvent(
|
||||
string action, // action ...
|
||||
string payload // payload ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int actionIndex = FindActionIndex(action);
|
||||
result = actionIndex >= 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int aListenersCount = ArraySize(mEventListeners[actionIndex].listeners);
|
||||
result = aListenersCount > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < aListenersCount; i++)
|
||||
{
|
||||
//
|
||||
OnMessage iListener = mEventListeners[actionIndex].listeners[i];
|
||||
|
||||
//
|
||||
// Call Listener ...
|
||||
iListener(
|
||||
action,
|
||||
payload);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
XNotifierEventListener mEventListeners[];
|
||||
|
||||
//
|
||||
// Find Specific Actions Index in Registered Event Listeners ...
|
||||
int FindActionIndex(string action)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int listenersCount = ArraySize(mEventListeners);
|
||||
if (listenersCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < listenersCount; i++)
|
||||
{
|
||||
//
|
||||
XNotifierEventListener iModel = mEventListeners[i];
|
||||
|
||||
//
|
||||
if (iModel.action == action)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
void Clean(
|
||||
OnMessage &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
0);
|
||||
}
|
||||
void Clean(
|
||||
XNotifierEventListener &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
0);
|
||||
}
|
||||
|
||||
//
|
||||
void Add(
|
||||
OnMessage item, // Item ...
|
||||
OnMessage &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
void Add(
|
||||
XNotifierEventListener &item, // Item ...
|
||||
XNotifierEventListener &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,304 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCEABaseProvider
|
||||
// Description: provides base requirements for
|
||||
// Specific Sgnal 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 Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Notified a Signal was Appears ...
|
||||
typedef void (*OnSignal)(
|
||||
XSignal &signal);
|
||||
|
||||
//
|
||||
// Notified a Guard Appears ...
|
||||
typedef void (*OnGuard)(XGuard &guard);
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Base Class for All of our EA's ...
|
||||
class XSCEABaseProvider
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCEABaseProvider()
|
||||
{
|
||||
mSymbol = _Symbol;
|
||||
mPeriod = _Period;
|
||||
}
|
||||
void XSCEABaseProvider(
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mTag = mSymbol + "," + ToString(mPeriod);
|
||||
|
||||
//
|
||||
mIsInTestMode = IsRunningOnTestMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCEABaseProvider()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
bool CanIgnoreTick() {
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
bool result = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare State ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
mCanIgnoreTick = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
ProcessBuffers();
|
||||
|
||||
//
|
||||
if (mCanIgnoreTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
mWaitUntilNewCandle = false;
|
||||
|
||||
//
|
||||
ProcessTick();
|
||||
}
|
||||
|
||||
//
|
||||
virtual void PrepareTag();
|
||||
|
||||
//
|
||||
// Initialize Indicators and Requirements ...
|
||||
virtual bool Init();
|
||||
|
||||
//
|
||||
virtual int GetMaxLength();
|
||||
|
||||
//
|
||||
virtual int GetCalculatedBars();
|
||||
|
||||
//
|
||||
// Handle Update Buffers ...
|
||||
virtual void ProcessBuffers()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Tick Event ...
|
||||
virtual void ProcessTick()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Guards ...
|
||||
virtual bool GuardCheck(XGuard &guards[]);
|
||||
|
||||
//
|
||||
// Add Specific On Signal Event Handler ...
|
||||
int AddOnSignalEventHandler(OnSignal handler)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
mSignalEventHandlers,
|
||||
ArraySize(mSignalEventHandlers) + 1);
|
||||
|
||||
//
|
||||
int result = ArraySize(mSignalEventHandlers) - 1;
|
||||
mSignalEventHandlers[result] = handler;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove All On Signal Event Handler ...
|
||||
void ReoveOnSignalEventHandlers()
|
||||
{
|
||||
//
|
||||
ArrayFree(mSignalEventHandlers);
|
||||
}
|
||||
|
||||
//
|
||||
// Notify a Signal Found on all Event Listeners ...
|
||||
void NotifyOnSignalEvent(XSignal &info)
|
||||
{
|
||||
//
|
||||
int listenerCount = ArraySize(mSignalEventHandlers);
|
||||
if (listenerCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Listeners ...
|
||||
for (int i = 0; i < listenerCount; i++)
|
||||
{
|
||||
//
|
||||
OnSignal listener = mSignalEventHandlers[i];
|
||||
|
||||
//
|
||||
listener(info);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
string mTag;
|
||||
|
||||
//
|
||||
bool mIsNewCandle;
|
||||
bool mIsInTestMode;
|
||||
bool mCanIgnoreTick;
|
||||
bool mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Signal Event Handlers ...
|
||||
OnSignal mSignalEventHandlers[];
|
||||
};
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Model Signal Providers Definitions ...
|
||||
struct XBaseSignalProvider
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
};
|
||||
|
||||
//
|
||||
struct XLastSignal
|
||||
{
|
||||
datetime at;
|
||||
string provider;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Add Specific Provider to List ...
|
||||
void Add(
|
||||
XBaseSignalProvider &item, // item want to add
|
||||
XBaseSignalProvider &buffer[] // Destination buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,262 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: X121EA
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
//
|
||||
// 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 X121EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Common Library ...
|
||||
#include "../Classes/x-saherelm.x121.xea.class.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "X121EA"
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// EA ...
|
||||
input group "Common";
|
||||
input bool xEAEnable = true; // Enable EA
|
||||
input int xEASlippage = 10; // Slippgae
|
||||
input ulong xEAMagicNumber = 1604056; // Magic Number
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
input group "Signals";
|
||||
input bool xEAEnableLongs = true; // Enable Long Trades
|
||||
input bool xEAEnableShorts = true; // Enable Short Trades
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input int xEAMaxOpenPositions = 15; // Max Allowed Open Positions
|
||||
input double xEAMaxAllowedDrawDownFactor = 0.15; // Max Allowed Drawdown Factor
|
||||
|
||||
//
|
||||
// Alerts ...
|
||||
input group "Alerts";
|
||||
input bool xEAEnableAlerts = true; // Enable Events Alert
|
||||
input bool xEAEnableHourlyAlerts = false; // Send Alert on each new Hour
|
||||
input bool xEAEnableDailyAlerts = false; // Send Alert on each new Day
|
||||
input bool xEAEnableWeeklyAlerts = false; // Send Alert on each new Week
|
||||
input bool xEAEnableMonthlyAlerts = false; // Send Alert on each new Month
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logger Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// END Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
XSCX121EA *mX121EA;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = logTag;
|
||||
alertPrefix = logTag;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
InitEAInstance();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// De Initialize XEA Providers ...
|
||||
delete mX121EA;
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEAEnable)
|
||||
{
|
||||
mX121EA.OnTick();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade Events ...
|
||||
void OnTrade()
|
||||
{
|
||||
mX121EA.OnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Signal Event ...
|
||||
void OnSignalConditionsRecieved(X121MarketConditions &info)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle StopLoss Event ...
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle TakeProfit Event ...
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Deals Changed Event ...
|
||||
void OnDealsChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Order Changed Event ...
|
||||
void OnOrdersChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Position Changed Event ...
|
||||
void OnPositionsChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade State Changed ...
|
||||
void OnTradeStateChangedHandler(const XOnTradeHandlerState &state)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
xEASlippage > 0 &&
|
||||
xEAMagicNumber > 0
|
||||
//
|
||||
// TODO: add new validations here ...
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Logging State ...
|
||||
string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize X121EA Class Instances ...
|
||||
void InitEAInstance()
|
||||
{
|
||||
//
|
||||
mX121EA = new XSCX121EA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xEAMagicNumber,
|
||||
xEASlippage,
|
||||
OnStopLossTriggered,
|
||||
OnTakeProfitTriggered,
|
||||
OnDealsChangedHandler,
|
||||
OnOrdersChangedHandler,
|
||||
OnPositionsChangedHandler,
|
||||
OnTradeStateChangedHandler,
|
||||
OnSignalConditionsRecieved);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,438 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXAMAHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XAMA" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
virtual 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;
|
||||
}
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,293 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
) {}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = 2;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,594 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = MathMax(mLength, mLoopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
virtual 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;
|
||||
}
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,248 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCTHelper
|
||||
// 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 XCTInputs
|
||||
{
|
||||
//
|
||||
color clr;
|
||||
ENUM_BASE_CORNER corner;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandleTime; // Show Candle Time
|
||||
};
|
||||
|
||||
//
|
||||
// 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 XSCXCTHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXCTHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXCTHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Candles ...
|
||||
bool ShowCandleTime(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowCandleTime == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowCandleTime = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XCT" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = 1;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xct",
|
||||
//
|
||||
// Inputs ...
|
||||
mClr,
|
||||
mCorner,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mShowCandleTime
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XCTInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XCTInputs result;
|
||||
|
||||
//
|
||||
result.clr = mClr;
|
||||
result.corner = mCorner;
|
||||
result.showCandleTime = mShowCandleTime;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XCTInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mClr = config.clr;
|
||||
mCorner = config.corner;
|
||||
mShowCandleTime = config.showCandleTime;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
|
||||
//
|
||||
// Text Color ...
|
||||
color mClr;
|
||||
//
|
||||
// Text Position ...
|
||||
ENUM_BASE_CORNER mCorner;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Candles ...
|
||||
bool mShowCandleTime;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,427 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Draw Hiken Ashi Candle ...
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = 2;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
virtual 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;
|
||||
}
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,530 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
virtual 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);
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,965 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXICHHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
// 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
|
||||
};
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XICHInputs
|
||||
{
|
||||
//
|
||||
// TENKANSEN ...
|
||||
// Tenkan Sen ...
|
||||
int tenkanSenLength; // Length
|
||||
ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode; // Calculation Mode
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
// Kijun Sen ...
|
||||
int kijunSenLength; // Length
|
||||
ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode; // Calculation Mode
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
// Senkou Span B ...
|
||||
int senkouSpanBLength; // Length
|
||||
ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode; // Calculation Mode
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
// Chikou Span ...
|
||||
ENUM_APPLIED_PRICE chikuoSpanAppliedTo; // Price Type
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showTenkanSen; // Show Tenkan Sen
|
||||
bool showKijunSen; // Show Kijun Sen
|
||||
bool showKijunSenPlus; // Show Kijun Sen +
|
||||
bool showKijunSenNegative; // Show Kijun Sen -
|
||||
bool showChikouSpan; // Show Chikou Span
|
||||
bool showSenkouSpanA; // Show Senkou Span A
|
||||
bool showSenkouSpanB; // Show Senkou Span B
|
||||
bool showKumo; // Show Kumo
|
||||
bool shiftKumo; // Shift Kumo to Future
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XICH_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XICH_TEANKANSEN_LINE = 0,
|
||||
XICH_KIJUNSEN_LINE = 1,
|
||||
XICH_CHIKOUSPAN_LINE = 4,
|
||||
XICH_SENKOUSPANA_LINE = 5,
|
||||
XICH_SENKOUSPANB_LINE = 6,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XICHInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double tenkanSen;
|
||||
double kijunSen;
|
||||
double chikouSpan;
|
||||
double senkouSpanA;
|
||||
double senkouSpanB;
|
||||
double senkouSpanAFuture;
|
||||
double senkouSpanBFuture;
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isTenkanSenOverKijunSen;
|
||||
bool isTenkanSenUnderKijunSen;
|
||||
bool isTenkanSenCrossedOverKijunSen;
|
||||
bool isTenkanSenCrossedUnderKijunSen;
|
||||
|
||||
//
|
||||
bool isKumoBullish;
|
||||
bool isKumoBearish;
|
||||
bool isFutureKumoBullish;
|
||||
bool isFutureKumoBearish;
|
||||
bool isKumoSwitchedToBullish;
|
||||
bool isKumoSwitchedToBearish;
|
||||
bool isFutureKumoSwitchedToBullish;
|
||||
bool isFutureKumoSwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isTenkanSenOverSenkouSpanA;
|
||||
bool isTenkanSenUnderSenkouSpanA;
|
||||
bool isTenkanSenOverFutureSenkouSpanA;
|
||||
bool isTenkanSenUnderFutureSenkouSpanA;
|
||||
bool isTenkanSenCrossedOverSenkouSpanA;
|
||||
bool isTenkanSenCrossedUnderSenkouSpanA;
|
||||
bool isTenkanSenCrossedOverFutureSenkouSpanA;
|
||||
bool isTenkanSenCrossedUnderFutureSenkouSpanA;
|
||||
|
||||
//
|
||||
bool isTenkanSenOverSenkouSpanB;
|
||||
bool isTenkanSenUnderSenkouSpanB;
|
||||
bool isTenkanSenOverFutureSenkouSpanB;
|
||||
bool isTenkanSenUnderFutureSenkouSpanB;
|
||||
bool isTenkanSenCrossedOverSenkouSpanB;
|
||||
bool isTenkanSenCrossedUnderSenkouSpanB;
|
||||
bool isTenkanSenCrossedOverFutureSenkouSpanB;
|
||||
bool isTenkanSenCrossedUnderFutureSenkouSpanB;
|
||||
|
||||
//
|
||||
bool isKijunSenOverSenkouSpanA;
|
||||
bool isKijunSenUnderSenkouSpanA;
|
||||
bool isKijunSenOverFutureSenkouSpanA;
|
||||
bool isKijunSenUnderFutureSenkouSpanA;
|
||||
bool isKijunSenCrossedOverSenkouSpanA;
|
||||
bool isKijunSenCrossedUnderSenkouSpanA;
|
||||
bool isKijunSenCrossedOverFutureSenkouSpanA;
|
||||
bool isKijunSenCrossedUnderFutureSenkouSpanA;
|
||||
|
||||
//
|
||||
bool isKijunSenOverSenkouSpanB;
|
||||
bool isKijunSenUnderSenkouSpanB;
|
||||
bool isKijunSenOverFutureSenkouSpanB;
|
||||
bool isKijunSenUnderFutureSenkouSpanB;
|
||||
bool isKijunSenCrossedOverSenkouSpanB;
|
||||
bool isKijunSenCrossedUnderSenkouSpanB;
|
||||
bool isKijunSenCrossedOverFutureSenkouSpanB;
|
||||
bool isKijunSenCrossedUnderFutureSenkouSpanB;
|
||||
};
|
||||
|
||||
//
|
||||
// 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 XSCXICHHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double tenkanSenBuffer[];
|
||||
double kijunSenBuffer[];
|
||||
double chikouSpanBuffer[];
|
||||
double senkouSpanABuffer[];
|
||||
double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXICHHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXICHHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Tenkan Sen ...
|
||||
bool ShowTenkanSen(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowTenkanSen == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowTenkanSen = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Kijun Sen ...
|
||||
bool ShowKijunSen(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowKijunSen == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowKijunSen = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Chikou Span ...
|
||||
bool ShowChikouSpan(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowChikouSpan == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowChikouSpan = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Senkou Span A ...
|
||||
bool ShowSenkouSpanA(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowSenkouSpanA == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowSenkouSpanA = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Senkou Span B ...
|
||||
bool ShowSenkouSpanB(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowSenkouSpanB == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowSenkouSpanB = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Kumo ...
|
||||
bool ShowKumo(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowKumo == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowKumo = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XICH" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
//
|
||||
result = MathMax(result, mTenkanSenLength);
|
||||
result = MathMax(result, mKijunSenLength);
|
||||
result = MathMax(result, mSenkouSpanBLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
//
|
||||
result =
|
||||
(mTenkanSenLength > 2 &&
|
||||
mKijunSenLength > mTenkanSenLength &&
|
||||
mSenkouSpanBLength > mKijunSenLength);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xich",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// TENKANSEN ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mTenkanSenLength,
|
||||
//
|
||||
// Calculation Mode ...
|
||||
mTenkanSenMode,
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mKijunSenLength,
|
||||
//
|
||||
// Calculation Mode ...
|
||||
mKijunSenMode,
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mSenkouSpanBLength,
|
||||
//
|
||||
// Calculation Mode ...
|
||||
mSenkouSpanBMode,
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
"",
|
||||
//
|
||||
// Price Type ...
|
||||
mChikuoSpanAppliedTo,
|
||||
//
|
||||
// PRESENTATION ...
|
||||
"",
|
||||
//
|
||||
// Show Tenkan Sen ...
|
||||
mShowTenkanSen,
|
||||
//
|
||||
// Show Kijun Sen ...
|
||||
mShowKijunSen,
|
||||
//
|
||||
// Show Kijun Sen + ...
|
||||
mShowKijunSenPlus,
|
||||
//
|
||||
// Show Kijun Sen - ...
|
||||
mShowKijunSenNegative,
|
||||
//
|
||||
// Show Chikou Span ...
|
||||
mShowChikouSpan,
|
||||
//
|
||||
// Show Senkou Span A ...
|
||||
mShowSenkouSpanA,
|
||||
//
|
||||
// Show Senkou Span B ...
|
||||
mShowSenkouSpanB,
|
||||
//
|
||||
// Show Kumo ...
|
||||
mShowKumo,
|
||||
//
|
||||
// Shift Kumo to Future ...
|
||||
mShiftKumo
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XICHInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XICHInputs result;
|
||||
|
||||
//
|
||||
result.tenkanSenLength = mTenkanSenLength;
|
||||
result.tenkanSenMode = mTenkanSenMode;
|
||||
result.kijunSenLength = mKijunSenLength;
|
||||
result.kijunSenMode = mKijunSenMode;
|
||||
result.senkouSpanBLength = mSenkouSpanBLength;
|
||||
result.senkouSpanBMode = mSenkouSpanBMode;
|
||||
result.chikuoSpanAppliedTo = mChikuoSpanAppliedTo;
|
||||
result.showTenkanSen = mShowTenkanSen;
|
||||
result.showKijunSen = mShowKijunSen;
|
||||
result.showKijunSenPlus = mShowKijunSenPlus;
|
||||
result.showKijunSenNegative = mShowKijunSenNegative;
|
||||
result.showChikouSpan = mShowChikouSpan;
|
||||
result.showSenkouSpanA = mShowSenkouSpanA;
|
||||
result.showSenkouSpanB = mShowSenkouSpanB;
|
||||
result.showKumo = mShowKumo;
|
||||
result.shiftKumo = mShiftKumo;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XICHInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mTenkanSenLength = config.tenkanSenLength;
|
||||
mTenkanSenMode = config.tenkanSenMode;
|
||||
mKijunSenLength = config.kijunSenLength;
|
||||
mKijunSenMode = config.kijunSenMode;
|
||||
mSenkouSpanBLength = config.senkouSpanBLength;
|
||||
mSenkouSpanBMode = config.senkouSpanBMode;
|
||||
mChikuoSpanAppliedTo = config.chikuoSpanAppliedTo;
|
||||
mShowTenkanSen = config.showTenkanSen;
|
||||
mShowKijunSen = config.showKijunSen;
|
||||
mShowKijunSenPlus = config.showKijunSenPlus;
|
||||
mShowKijunSenNegative = config.showKijunSenNegative;
|
||||
mShowChikouSpan = config.showChikouSpan;
|
||||
mShowSenkouSpanA = config.showSenkouSpanA;
|
||||
mShowSenkouSpanB = config.showSenkouSpanB;
|
||||
mShowKumo = config.showKumo;
|
||||
mShiftKumo = config.shiftKumo;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Since Ichimoku Has Some Issues ...
|
||||
mLoopbackBars = 52;
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
ArraySetAsSeries(tenkanSenBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XICH_TEANKANSEN_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
tenkanSenBuffer);
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
ArraySetAsSeries(kijunSenBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XICH_KIJUNSEN_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
kijunSenBuffer);
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
ArraySetAsSeries(chikouSpanBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XICH_CHIKOUSPAN_LINE,
|
||||
barIndex + mKijunSenLength + 1,
|
||||
mLoopbackBars,
|
||||
chikouSpanBuffer);
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
ArraySetAsSeries(senkouSpanABuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XICH_SENKOUSPANA_LINE,
|
||||
-1 * (barIndex + mKijunSenLength),
|
||||
mLoopbackBars,
|
||||
senkouSpanABuffer);
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
ArraySetAsSeries(senkouSpanBBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XICH_SENKOUSPANB_LINE,
|
||||
-1 * (barIndex + mKijunSenLength),
|
||||
mLoopbackBars,
|
||||
senkouSpanBBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XICHInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XICHInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 tenkanSen = tenkanSenBuffer[barIndex];
|
||||
double tenkanSenPrev = tenkanSenBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
double kijunSen = kijunSenBuffer[barIndex];
|
||||
double kijunSenPrev = kijunSenBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
double chikouSpan = chikouSpanBuffer[barIndex + mKijunSenLength];
|
||||
double chikouSpanPrev = chikouSpanBuffer[barIndex + mKijunSenLength + 1];
|
||||
|
||||
//
|
||||
double senkouSpanA = senkouSpanABuffer[barIndex + mKijunSenLength];
|
||||
double senkouSpanAPrev = senkouSpanABuffer[barIndex + mKijunSenLength + 1];
|
||||
|
||||
//
|
||||
double senkouSpanB = senkouSpanBBuffer[barIndex + mKijunSenLength];
|
||||
double senkouSpanBPrev = senkouSpanBBuffer[barIndex + mKijunSenLength + 1];
|
||||
|
||||
//
|
||||
double senkouSpanAFuture = senkouSpanABuffer[barIndex];
|
||||
double senkouSpanAFuturePrev = senkouSpanABuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
double senkouSpanBFuture = senkouSpanBBuffer[barIndex];
|
||||
double senkouSpanBFuturePrev = senkouSpanBBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isTenkanSenOverKijunSen =
|
||||
tenkanSen > kijunSen;
|
||||
bool isTenkanSenUnderKijunSen =
|
||||
tenkanSen < kijunSen;
|
||||
bool isTenkanSenCrossedOverKijunSen =
|
||||
tenkanSen > kijunSen &&
|
||||
tenkanSenPrev <= kijunSenPrev;
|
||||
bool isTenkanSenCrossedUnderKijunSen =
|
||||
tenkanSen < kijunSen &&
|
||||
tenkanSenPrev >= kijunSenPrev;
|
||||
|
||||
//
|
||||
bool isKumoBullish =
|
||||
senkouSpanA > senkouSpanB;
|
||||
bool isKumoBearish =
|
||||
senkouSpanA < senkouSpanB;
|
||||
bool isFutureKumoBullish =
|
||||
senkouSpanAFuture > senkouSpanBFuture;
|
||||
bool isFutureKumoBearish =
|
||||
senkouSpanAFuture < senkouSpanBFuture;
|
||||
bool isKumoSwitchedToBullish =
|
||||
senkouSpanA > senkouSpanB &&
|
||||
senkouSpanAPrev <= senkouSpanBPrev;
|
||||
bool isKumoSwitchedToBearish =
|
||||
senkouSpanA < senkouSpanB &&
|
||||
senkouSpanAPrev >= senkouSpanBPrev;
|
||||
bool isFutureKumoSwitchedToBullish =
|
||||
senkouSpanAFuture > senkouSpanBFuture &&
|
||||
senkouSpanAFuturePrev <= senkouSpanBFuturePrev;
|
||||
bool isFutureKumoSwitchedToBearish =
|
||||
senkouSpanAFuture < senkouSpanBFuture &&
|
||||
senkouSpanAFuturePrev >= senkouSpanBFuturePrev;
|
||||
|
||||
//
|
||||
bool isTenkanSenOverSenkouSpanA =
|
||||
tenkanSen > senkouSpanA;
|
||||
bool isTenkanSenUnderSenkouSpanA =
|
||||
tenkanSen < senkouSpanA;
|
||||
bool isTenkanSenOverFutureSenkouSpanA =
|
||||
tenkanSen > senkouSpanAFuture;
|
||||
bool isTenkanSenUnderFutureSenkouSpanA =
|
||||
tenkanSen < senkouSpanAFuture;
|
||||
bool isTenkanSenCrossedOverSenkouSpanA =
|
||||
tenkanSen > senkouSpanA &&
|
||||
tenkanSenPrev <= senkouSpanAPrev;
|
||||
bool isTenkanSenCrossedUnderSenkouSpanA =
|
||||
tenkanSen < senkouSpanA &&
|
||||
tenkanSenPrev >= senkouSpanAPrev;
|
||||
bool isTenkanSenCrossedOverFutureSenkouSpanA =
|
||||
tenkanSen > senkouSpanAFuture &&
|
||||
tenkanSenPrev <= senkouSpanAFuturePrev;
|
||||
bool isTenkanSenCrossedUnderFutureSenkouSpanA =
|
||||
tenkanSen < senkouSpanAFuture &&
|
||||
tenkanSenPrev >= senkouSpanAFuturePrev;
|
||||
|
||||
//
|
||||
bool isTenkanSenOverSenkouSpanB =
|
||||
tenkanSen > senkouSpanB;
|
||||
bool isTenkanSenUnderSenkouSpanB =
|
||||
tenkanSen < senkouSpanB;
|
||||
bool isTenkanSenOverFutureSenkouSpanB =
|
||||
tenkanSen > senkouSpanBFuture;
|
||||
bool isTenkanSenUnderFutureSenkouSpanB =
|
||||
tenkanSen < senkouSpanBFuture;
|
||||
bool isTenkanSenCrossedOverSenkouSpanB =
|
||||
tenkanSen > senkouSpanB &&
|
||||
tenkanSenPrev <= senkouSpanBPrev;
|
||||
bool isTenkanSenCrossedUnderSenkouSpanB =
|
||||
tenkanSen < senkouSpanB &&
|
||||
tenkanSenPrev >= senkouSpanBPrev;
|
||||
bool isTenkanSenCrossedOverFutureSenkouSpanB =
|
||||
tenkanSen > senkouSpanBFuture &&
|
||||
tenkanSenPrev <= senkouSpanBFuturePrev;
|
||||
bool isTenkanSenCrossedUnderFutureSenkouSpanB =
|
||||
tenkanSen < senkouSpanBFuture &&
|
||||
tenkanSenPrev >= senkouSpanBFuturePrev;
|
||||
|
||||
//
|
||||
bool isKijunSenOverSenkouSpanA =
|
||||
kijunSen > senkouSpanA;
|
||||
bool isKijunSenUnderSenkouSpanA =
|
||||
kijunSen < senkouSpanA;
|
||||
bool isKijunSenOverFutureSenkouSpanA =
|
||||
kijunSen > senkouSpanAFuture;
|
||||
bool isKijunSenUnderFutureSenkouSpanA =
|
||||
kijunSen < senkouSpanAFuture;
|
||||
bool isKijunSenCrossedOverSenkouSpanA =
|
||||
kijunSen > senkouSpanA &&
|
||||
kijunSenPrev <= senkouSpanAPrev;
|
||||
bool isKijunSenCrossedUnderSenkouSpanA =
|
||||
kijunSen < senkouSpanA &&
|
||||
kijunSenPrev >= senkouSpanAPrev;
|
||||
bool isKijunSenCrossedOverFutureSenkouSpanA =
|
||||
kijunSen > senkouSpanAFuture &&
|
||||
kijunSenPrev <= senkouSpanAFuturePrev;
|
||||
bool isKijunSenCrossedUnderFutureSenkouSpanA =
|
||||
kijunSen < senkouSpanAFuture &&
|
||||
kijunSenPrev >= senkouSpanAFuturePrev;
|
||||
|
||||
//
|
||||
bool isKijunSenOverSenkouSpanB =
|
||||
kijunSen > senkouSpanB;
|
||||
bool isKijunSenUnderSenkouSpanB =
|
||||
kijunSen < senkouSpanB;
|
||||
bool isKijunSenOverFutureSenkouSpanB =
|
||||
kijunSen > senkouSpanBFuture;
|
||||
bool isKijunSenUnderFutureSenkouSpanB =
|
||||
kijunSen < senkouSpanBFuture;
|
||||
bool isKijunSenCrossedOverSenkouSpanB =
|
||||
kijunSen > senkouSpanB &&
|
||||
kijunSenPrev <= senkouSpanB;
|
||||
bool isKijunSenCrossedUnderSenkouSpanB =
|
||||
kijunSen < senkouSpanB &&
|
||||
kijunSenPrev >= senkouSpanB;
|
||||
bool isKijunSenCrossedOverFutureSenkouSpanB =
|
||||
kijunSen > senkouSpanBFuture &&
|
||||
kijunSenPrev <= senkouSpanBFuturePrev;
|
||||
bool isKijunSenCrossedUnderFutureSenkouSpanB =
|
||||
kijunSen < senkouSpanBFuture &&
|
||||
kijunSenPrev >= senkouSpanBFuturePrev;
|
||||
|
||||
//
|
||||
result.tenkanSen = tenkanSen;
|
||||
result.kijunSen = kijunSen;
|
||||
result.chikouSpan = chikouSpan;
|
||||
result.senkouSpanA = senkouSpanA;
|
||||
result.senkouSpanB = senkouSpanB;
|
||||
result.senkouSpanAFuture = senkouSpanAFuture;
|
||||
result.senkouSpanBFuture = senkouSpanBFuture;
|
||||
|
||||
//
|
||||
result.isTenkanSenOverKijunSen = isTenkanSenOverKijunSen;
|
||||
result.isTenkanSenUnderKijunSen = isTenkanSenUnderKijunSen;
|
||||
result.isTenkanSenCrossedOverKijunSen = isTenkanSenCrossedOverKijunSen;
|
||||
result.isTenkanSenCrossedUnderKijunSen = isTenkanSenCrossedUnderKijunSen;
|
||||
|
||||
//
|
||||
result.isKumoBullish = isKumoBullish;
|
||||
result.isKumoBearish = isKumoBearish;
|
||||
result.isFutureKumoBullish = isFutureKumoBullish;
|
||||
result.isFutureKumoBearish = isFutureKumoBearish;
|
||||
result.isKumoSwitchedToBullish = isKumoSwitchedToBullish;
|
||||
result.isKumoSwitchedToBearish = isKumoSwitchedToBearish;
|
||||
result.isFutureKumoSwitchedToBullish = isFutureKumoSwitchedToBullish;
|
||||
result.isFutureKumoSwitchedToBearish = isFutureKumoSwitchedToBearish;
|
||||
|
||||
//
|
||||
result.isTenkanSenOverSenkouSpanA = isTenkanSenOverSenkouSpanA;
|
||||
result.isTenkanSenUnderSenkouSpanA = isTenkanSenUnderSenkouSpanA;
|
||||
result.isTenkanSenOverFutureSenkouSpanA = isTenkanSenOverFutureSenkouSpanA;
|
||||
result.isTenkanSenUnderFutureSenkouSpanA = isTenkanSenUnderFutureSenkouSpanA;
|
||||
result.isTenkanSenCrossedOverSenkouSpanA = isTenkanSenCrossedOverSenkouSpanA;
|
||||
result.isTenkanSenCrossedUnderSenkouSpanA = isTenkanSenCrossedUnderSenkouSpanA;
|
||||
result.isTenkanSenCrossedOverFutureSenkouSpanA = isTenkanSenCrossedOverFutureSenkouSpanA;
|
||||
result.isTenkanSenCrossedUnderFutureSenkouSpanA = isTenkanSenCrossedUnderFutureSenkouSpanA;
|
||||
|
||||
//
|
||||
result.isTenkanSenOverSenkouSpanB = isTenkanSenOverSenkouSpanB;
|
||||
result.isTenkanSenUnderSenkouSpanB = isTenkanSenUnderSenkouSpanB;
|
||||
result.isTenkanSenOverFutureSenkouSpanB = isTenkanSenOverFutureSenkouSpanB;
|
||||
result.isTenkanSenUnderFutureSenkouSpanB = isTenkanSenUnderFutureSenkouSpanB;
|
||||
result.isTenkanSenCrossedOverSenkouSpanB = isTenkanSenCrossedOverSenkouSpanB;
|
||||
result.isTenkanSenCrossedUnderSenkouSpanB = isTenkanSenCrossedUnderSenkouSpanB;
|
||||
result.isTenkanSenCrossedOverFutureSenkouSpanB = isTenkanSenCrossedOverFutureSenkouSpanB;
|
||||
result.isTenkanSenCrossedUnderFutureSenkouSpanB = isTenkanSenCrossedUnderFutureSenkouSpanB;
|
||||
|
||||
//
|
||||
result.isKijunSenOverSenkouSpanA = isKijunSenOverSenkouSpanA;
|
||||
result.isKijunSenUnderSenkouSpanA = isKijunSenUnderSenkouSpanA;
|
||||
result.isKijunSenOverFutureSenkouSpanA = isKijunSenOverFutureSenkouSpanA;
|
||||
result.isKijunSenUnderFutureSenkouSpanA = isKijunSenUnderFutureSenkouSpanA;
|
||||
result.isKijunSenCrossedOverSenkouSpanA = isKijunSenCrossedOverSenkouSpanA;
|
||||
result.isKijunSenCrossedUnderSenkouSpanA = isKijunSenCrossedUnderSenkouSpanA;
|
||||
result.isKijunSenCrossedOverFutureSenkouSpanA = isKijunSenCrossedOverFutureSenkouSpanA;
|
||||
result.isKijunSenCrossedUnderFutureSenkouSpanA = isKijunSenCrossedUnderFutureSenkouSpanA;
|
||||
|
||||
//
|
||||
result.isKijunSenOverSenkouSpanB = isKijunSenOverSenkouSpanB;
|
||||
result.isKijunSenUnderSenkouSpanB = isKijunSenUnderSenkouSpanB;
|
||||
result.isKijunSenOverFutureSenkouSpanB = isKijunSenOverFutureSenkouSpanB;
|
||||
result.isKijunSenUnderFutureSenkouSpanB = isKijunSenUnderFutureSenkouSpanB;
|
||||
result.isKijunSenCrossedOverSenkouSpanB = isKijunSenCrossedOverSenkouSpanB;
|
||||
result.isKijunSenCrossedUnderSenkouSpanB = isKijunSenCrossedUnderSenkouSpanB;
|
||||
result.isKijunSenCrossedOverFutureSenkouSpanB = isKijunSenCrossedOverFutureSenkouSpanB;
|
||||
result.isKijunSenCrossedUnderFutureSenkouSpanB = isKijunSenCrossedUnderFutureSenkouSpanB;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// TENKANSEN ...
|
||||
//
|
||||
// Length ...
|
||||
int mTenkanSenLength;
|
||||
//
|
||||
// Calculation Mode ...
|
||||
ENUM_X_ICHIMOKU_CALCULATION_MODE mTenkanSenMode;
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
//
|
||||
// Length ...
|
||||
int mKijunSenLength;
|
||||
//
|
||||
// Calculation Mode ...
|
||||
ENUM_X_ICHIMOKU_CALCULATION_MODE mKijunSenMode;
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
//
|
||||
// Length ...
|
||||
int mSenkouSpanBLength;
|
||||
//
|
||||
// Calculation Mode ...
|
||||
ENUM_X_ICHIMOKU_CALCULATION_MODE mSenkouSpanBMode;
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
//
|
||||
// Price Type ...
|
||||
ENUM_APPLIED_PRICE mChikuoSpanAppliedTo;
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Tenkan Sen ...
|
||||
bool mShowTenkanSen;
|
||||
//
|
||||
// Show Kijun Sen ...
|
||||
bool mShowKijunSen;
|
||||
//
|
||||
// Show Kijun Sen + ...
|
||||
bool mShowKijunSenPlus;
|
||||
//
|
||||
// Show Kijun Sen - ...
|
||||
bool mShowKijunSenNegative;
|
||||
//
|
||||
// Show Chikou Span ...
|
||||
bool mShowChikouSpan;
|
||||
//
|
||||
// Show Senkou Span A ...
|
||||
bool mShowSenkouSpanA;
|
||||
//
|
||||
// Show Senkou Span B ...
|
||||
bool mShowSenkouSpanB;
|
||||
//
|
||||
// Show Kumo ...
|
||||
bool mShowKumo;
|
||||
//
|
||||
// Shift Kumo to Future ...
|
||||
bool mShiftKumo;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,849 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = MathMax(mFast1Length, mFast2Length);
|
||||
result = MathMax(result, mFast3Length);
|
||||
result = MathMax(result, mFast4Length);
|
||||
result = MathMax(result, mFast5Length);
|
||||
|
||||
//
|
||||
result = MathMax(result, mSlow1Length);
|
||||
result = MathMax(result, mSlow2Length);
|
||||
result = MathMax(result, mSlow3Length);
|
||||
result = MathMax(result, mSlow4Length);
|
||||
result = MathMax(result, mSlow5Length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 &&
|
||||
mSlow3Length > mFast3Length &&
|
||||
mSlow4Length > mFast4Length &&
|
||||
mSlow5Length > mFast5Length &&
|
||||
mSlow2Length > mSlow1Length &&
|
||||
mSlow3Length > mSlow2Length &&
|
||||
mSlow4Length > mSlow3Length &&
|
||||
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 ...
|
||||
virtual 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);
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,644 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
double fiboLevel1; // Fibio 1st Level
|
||||
double fiboLevel2; // Fibio 2st Level
|
||||
double fiboLevel3; // Fibio 3rd Level
|
||||
|
||||
//
|
||||
// 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
|
||||
bool showFibo1Levels; // Show Fibo 1st Level
|
||||
bool showFibo2Levels; // Show Fibo 2nd Level
|
||||
bool showFibo3Levels; // Show Fibo 3rd Level
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XPV_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XPV_PEAKS_LINE = 0,
|
||||
XPV_VALES_LINE = 1,
|
||||
XPV_FL1_LINE = 6,
|
||||
XPV_FL2_LINE = 8,
|
||||
XPV_FL3_LINE = 10,
|
||||
};
|
||||
|
||||
//
|
||||
// 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;
|
||||
double fl1;
|
||||
double fl2;
|
||||
double fl3;
|
||||
|
||||
//
|
||||
// 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[];
|
||||
double fl1Buffer[];
|
||||
double fl2Buffer[];
|
||||
double fl3Buffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXPVHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Fibo 1st Level ...
|
||||
bool ShowFibo1Levels(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowFibo1Levels == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowFibo1Levels = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Fibo 2nd Level ...
|
||||
bool ShowFibo2Levels(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowFibo2Levels == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowFibo2Levels = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Fibo 3rd Level ...
|
||||
bool ShowFibo3Levels(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowFibo3Levels == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowFibo3Levels = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XPV" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = MathMax(mShortLength, mMediumLength);
|
||||
result = MathMax(result, mLongLength);
|
||||
result = MathMax(result, mHindLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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,
|
||||
//
|
||||
// Fibio 1st Level ...
|
||||
mFiboLevel1,
|
||||
//
|
||||
// Fibio 2st Level ...
|
||||
mFiboLevel2,
|
||||
//
|
||||
// Fibio 3rd Level ...
|
||||
mFiboLevel3,
|
||||
//
|
||||
// Detection Mode ...
|
||||
"",
|
||||
//
|
||||
// Highest High Calculation Method ...
|
||||
mHHMode,
|
||||
//
|
||||
// Lowest Low Calculation Method ...
|
||||
mLLMode,
|
||||
//
|
||||
// Presentations ...
|
||||
"",
|
||||
//
|
||||
// Show Peaks and Vales ...
|
||||
mShowPeaksAndVales,
|
||||
//
|
||||
// Show Levels ...
|
||||
mShowLevels,
|
||||
//
|
||||
// Show Fibo 1st Level ...
|
||||
mShowFibo1Levels,
|
||||
//
|
||||
// Show Fibo 2nd Level ...
|
||||
mShowFibo2Levels,
|
||||
//
|
||||
// Show Fibo 3rd Level ...
|
||||
mShowFibo3Levels
|
||||
//
|
||||
);
|
||||
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.fiboLevel1 = mFiboLevel1;
|
||||
result.fiboLevel2 = mFiboLevel2;
|
||||
result.fiboLevel3 = mFiboLevel3;
|
||||
result.hhMode = mHHMode;
|
||||
result.llMode = mLLMode;
|
||||
result.showPeaksAndVales = mShowPeaksAndVales;
|
||||
result.showLevels = mShowLevels;
|
||||
result.showFibo1Levels = mShowFibo1Levels;
|
||||
result.showFibo2Levels = mShowFibo2Levels;
|
||||
result.showFibo3Levels = mShowFibo3Levels;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XPVInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mShortLength = config.shortLength;
|
||||
mMediumLength = config.mediumLength;
|
||||
mLongLength = config.longLength;
|
||||
mHindLength = config.hindLength;
|
||||
mFiboLevel1 = config.fiboLevel1;
|
||||
mFiboLevel2 = config.fiboLevel2;
|
||||
mFiboLevel3 = config.fiboLevel3;
|
||||
mHHMode = config.hhMode;
|
||||
mLLMode = config.llMode;
|
||||
mShowPeaksAndVales = config.showPeaksAndVales;
|
||||
mShowLevels = config.showLevels;
|
||||
mShowFibo1Levels = config.showFibo1Levels;
|
||||
mShowFibo2Levels = config.showFibo2Levels;
|
||||
mShowFibo3Levels = config.showFibo3Levels;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual 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);
|
||||
|
||||
//
|
||||
// FIBBO LEVELS ...
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
ArraySetAsSeries(fl1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_FL1_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fl1Buffer);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
ArraySetAsSeries(fl2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_FL2_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fl2Buffer);
|
||||
|
||||
//
|
||||
// LEVEL 3 ...
|
||||
ArraySetAsSeries(fl3Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_FL3_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fl3Buffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XPVInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XPVInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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.fl1 = fl1Buffer[barIndex];
|
||||
result.fl2 = fl2Buffer[barIndex];
|
||||
result.fl3 = fl3Buffer[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;
|
||||
//
|
||||
// Fibio 1st Level ...
|
||||
double mFiboLevel1;
|
||||
//
|
||||
// Fibio 2st Level ...
|
||||
double mFiboLevel2;
|
||||
//
|
||||
// Fibio 3rd Level ...
|
||||
double mFiboLevel3;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// Show Fibo 1st Level ...
|
||||
bool mShowFibo1Levels;
|
||||
//
|
||||
// Show Fibo 2nd Level ...
|
||||
bool mShowFibo2Levels;
|
||||
//
|
||||
// Show Fibo 3rd Level ...
|
||||
bool mShowFibo3Levels;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,473 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
virtual 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;
|
||||
}
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,439 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXTMHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XTM" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
virtual 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;
|
||||
}
|
||||
|
||||
//
|
||||
barIndex--;
|
||||
if (barIndex < 0) {
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
+1074
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,350 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_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 X121_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "X121_XAMA"
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 0,
|
||||
X_XAMA_BEARISH = 2,
|
||||
X_XAMA_NEUTURAL = 1,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret";
|
||||
input int length = 52; // Length
|
||||
input int fastEMA = 2; // Fast EMA Length
|
||||
input int slowEMA = 30; // Slow EMA Length
|
||||
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 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
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
|
||||
#property indicator_label1 "X121_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 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 = iAMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
fastEMA,
|
||||
slowEMA,
|
||||
maShift,
|
||||
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);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,454 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Styles
|
||||
// ---------------------------------------------------
|
||||
// Name: X121_CC
|
||||
// Description: Candle Styles ...
|
||||
//
|
||||
//
|
||||
// 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 upColor = clrLime; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrLime; // Line mode and Doji candlestick Color
|
||||
input color bearishColor = clrRed; // Bullish Color
|
||||
input color bullishColor = clrLime; // Bearish Color
|
||||
input color volumesColor = clrGreen; // Volumes Color
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandles = true; // Show Candles
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Custom Chart Style ...
|
||||
void ApplyCustomChartStyle()
|
||||
{
|
||||
//
|
||||
// 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.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()
|
||||
{
|
||||
//
|
||||
// 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 = upColor;
|
||||
chartStyle.downColor = downColor;
|
||||
chartStyle.lineColor = lineColor;
|
||||
chartStyle.bearishColor = bearishColor;
|
||||
chartStyle.bullishColor = bullishColor;
|
||||
chartStyle.volumesColor = volumesColor;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,631 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCHE
|
||||
// Description: Chandelier Exit Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XCHE Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCHE"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 35; // Length
|
||||
input int loopback = 26; // Loopback
|
||||
input double multiplier1 = 3.0; // 1st Multiplier
|
||||
input double multiplier2 = 3.5; // 2nd Multiplier
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLongExit1Line = true; // Show 1st Long Exit
|
||||
input bool showShortExit1Line = true; // Show 1st Short Exit
|
||||
input bool showLongExit2Line = true; // Show 2st Long Exit
|
||||
input bool showShortExit2Line = true; // Show 2st Short Exit
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
#define longExit1BufferIndex 0
|
||||
double longExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XCHE LE 1"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
#define shortExit1BufferIndex 1
|
||||
double shortExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XCHE SE 1"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color2 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
#define longExit2BufferIndex 2
|
||||
double longExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XCHE LE 2"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color3 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
#define shortExit2BufferIndex 3
|
||||
double shortExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XCHE SE 2"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color4 clrMagenta
|
||||
|
||||
//
|
||||
// START Arrows ...
|
||||
|
||||
//
|
||||
// Long Exit 1 Start ...
|
||||
#define longExit1StartBufferIndex 4
|
||||
double longExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XCHE LES 1"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrLime
|
||||
|
||||
//
|
||||
// Short Exit 1 Start ...
|
||||
#define shortExit1StartBufferIndex 5
|
||||
double shortExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XCHE SES 1"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 Start ...
|
||||
#define longExit2StartBufferIndex 6
|
||||
double longExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XCHE LES 2"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 Start ...
|
||||
#define shortExit2StartBufferIndex 7
|
||||
double shortExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XCHE SES 2"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrMagenta
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Working Array ...
|
||||
double work[][6];
|
||||
#define hi1Idx 0
|
||||
#define lo1Idx 1
|
||||
#define hi2Idx 2
|
||||
#define lo2Idx 3
|
||||
#define trend1Idx 4
|
||||
#define trend2Idx 5
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
if (Bars(_Symbol, _Period) < rates_total)
|
||||
{
|
||||
return (prev_calculated);
|
||||
}
|
||||
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
ArrayResize(work, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
length >= 9 &&
|
||||
loopback >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(length, loopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
uint arrowCode = 159;
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit1DrawType = showLongExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit1StartDrawType = showLongExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit1BufferIndex, longExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_SHOW_DATA, showLongExit1Line);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_DRAW_TYPE, longExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit1StartBufferIndex, longExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_DRAW_TYPE, longExit1StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit1DrawType = showShortExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit1StartDrawType = showShortExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit1BufferIndex, shortExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_SHOW_DATA, showShortExit1Line);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_DRAW_TYPE, shortExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit1StartBufferIndex, shortExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_DRAW_TYPE, shortExit1StartDrawType);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit2DrawType = showLongExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit2StartDrawType = showLongExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit2BufferIndex, longExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_SHOW_DATA, showLongExit2Line);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_DRAW_TYPE, longExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit2StartBufferIndex, longExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_DRAW_TYPE, longExit2StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit2DrawType = showShortExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit2StartDrawType = showShortExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit2BufferIndex, shortExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_SHOW_DATA, showShortExit2Line);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_DRAW_TYPE, shortExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit2StartBufferIndex, shortExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_DRAW_TYPE, shortExit2StartDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
int prevCalculated, // Previous Calculated
|
||||
int ratesTotal, // Total Rates
|
||||
const double &open[], // Rates Open ...
|
||||
const double &high[], // Rates High ...
|
||||
const double &low[], // Rates Low ...
|
||||
const double &close[] // Rates Close ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Cleanup Buffers ...
|
||||
longExit1Buffer[bar_index] = longExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index] = shortExit1StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
longExit2Buffer[bar_index] = longExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index] = shortExit2StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
int start = MathMax(bar_index - loopback, 0);
|
||||
|
||||
//
|
||||
// Calculate ATR Value ...
|
||||
double atrValue = 0;
|
||||
for (int k = 1; k <= length && (bar_index - k - 1) >= 0; k++)
|
||||
{
|
||||
//
|
||||
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
|
||||
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
|
||||
}
|
||||
atrValue /= (double)length;
|
||||
|
||||
//
|
||||
// Retrieve Highest High and Lowest Lows ...
|
||||
double loopbackMax = high[ArrayMaximum(high, start, loopback)];
|
||||
double loopbackMin = low[ArrayMinimum(low, start, loopback)];
|
||||
|
||||
//
|
||||
// Fill Multi Dimesional Working Array ...
|
||||
work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue;
|
||||
work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue;
|
||||
work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue;
|
||||
work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue;
|
||||
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
|
||||
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
|
||||
|
||||
//
|
||||
if (bar_index > 0)
|
||||
{
|
||||
//
|
||||
// Calculate Trends ...
|
||||
if (close[bar_index] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Exit Values ...
|
||||
|
||||
//
|
||||
// Exit 1 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
longExit1Buffer[bar_index] = work[bar_index][hi1Idx];
|
||||
|
||||
//
|
||||
if (longExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit1StartBuffer[bar_index] = longExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit1Buffer[bar_index] = work[bar_index][lo1Idx];
|
||||
|
||||
//
|
||||
if (shortExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1)
|
||||
{
|
||||
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
longExit2Buffer[bar_index] = work[bar_index][hi2Idx];
|
||||
|
||||
//
|
||||
if (longExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit2StartBuffer[bar_index] = longExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit2Buffer[bar_index] = work[bar_index][lo2Idx];
|
||||
|
||||
//
|
||||
if (shortExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,264 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCT
|
||||
// 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_XCT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCT"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandleTime = true; // Show Candle Time
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
if (showCandleTime)
|
||||
{
|
||||
CreateIndicatorObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjectDelete(0, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
XCandleRemains remainTime;
|
||||
GetCandleRemainsTime(
|
||||
remainTime,
|
||||
_Symbol,
|
||||
_Period,
|
||||
0);
|
||||
|
||||
//
|
||||
string msg = ToString(
|
||||
remainTime,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
":",
|
||||
true);
|
||||
|
||||
//
|
||||
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
|
||||
|
||||
//
|
||||
string _sp = "";
|
||||
if (mSpread < 10)
|
||||
_sp = "..";
|
||||
else if (mSpread < 100)
|
||||
_sp = ".";
|
||||
|
||||
//
|
||||
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in: " + msg;
|
||||
|
||||
//
|
||||
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()
|
||||
{
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,486 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------------
|
||||
// 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_XHK Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XHK"
|
||||
|
||||
//
|
||||
// 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 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_XHK Open;X121_XHK High;X121_XHK Low;X121_XHK 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_XHK 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_XHK 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_XHK 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_XHK 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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,602 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_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 X121_XHULL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XHULL"
|
||||
|
||||
//
|
||||
struct XHullData
|
||||
{
|
||||
//
|
||||
double value;
|
||||
double value3;
|
||||
|
||||
//
|
||||
double wsum1;
|
||||
double wsum2;
|
||||
double wsum3;
|
||||
|
||||
//
|
||||
double lsum1;
|
||||
double lsum2;
|
||||
double lsum3;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// 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 "X121_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 "X121_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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 Function ...
|
||||
|
||||
template <typename T>
|
||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
||||
{
|
||||
switch (tprice)
|
||||
{
|
||||
case PRICE_CLOSE:
|
||||
return (close[i]);
|
||||
case PRICE_OPEN:
|
||||
return (open[i]);
|
||||
case PRICE_HIGH:
|
||||
return (high[i]);
|
||||
case PRICE_LOW:
|
||||
return (low[i]);
|
||||
case PRICE_MEDIAN:
|
||||
return ((high[i] + low[i]) / 2.0);
|
||||
case PRICE_TYPICAL:
|
||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
||||
case PRICE_WEIGHTED:
|
||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,743 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121_XICH
|
||||
// Description: Ichimoku Kinko Hyo ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XICH Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XICH"
|
||||
|
||||
//
|
||||
// Ichimoku Golden Numbers ...
|
||||
enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS
|
||||
{
|
||||
X_ICH_BASE = 9,
|
||||
X_ICH_GOLDEN = 17,
|
||||
X_ICH_CYCLE = 26,
|
||||
X_ICH_PERIOD = 35,
|
||||
X_ICH_STAR = 45,
|
||||
X_ICH_MED = 52,
|
||||
X_ICH_LONG = 63,
|
||||
X_ICH_FULL = 72
|
||||
};
|
||||
|
||||
//
|
||||
// Ichimoku Lines Calculator Mode ...
|
||||
enum ENUM_X_ICHIMOKU_CALCULATION_MODE
|
||||
{
|
||||
//
|
||||
X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low
|
||||
X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// ICHIMOKU Kinko Hyo ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
input group "Tenkan Sen";
|
||||
input int tenkanSenLength = 9; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
input group "Kijun Sen";
|
||||
input int kijunSenLength = 26; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
input group "Senkou Span B";
|
||||
input int senkouSpanBLength = 52; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
input group "Chikou Span";
|
||||
input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTenkanSen = true; // Show Tenkan Sen
|
||||
input bool showKijunSen = true; // Show Kijun Sen
|
||||
input bool showKijunSenPlus = false; // Show Kijun Sen +
|
||||
input bool showKijunSenNegative = false; // Show Kijun Sen -
|
||||
input bool showChikouSpan = true; // Show Chikou Span
|
||||
input bool showSenkouSpanA = true; // Show Senkou Span A
|
||||
input bool showSenkouSpanB = true; // Show Senkou Span B
|
||||
input bool showKumo = true; // Show Kumo
|
||||
input bool shiftKumo = true; // Shift Kumo to Future
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
#define tenkanSenBufferIndex 0
|
||||
double tenkanSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XICH TK"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
#define kijunSenBufferIndex 1
|
||||
double kijunSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XICH KJ"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDodgerBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define kijunSenPlusBufferIndex 2
|
||||
double kijunSenPlusBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XICH KJ+"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMediumTurquoise
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define kijunSenNegativeBufferIndex 3
|
||||
double kijunSenNegativeBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XICH KJ-"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrDarkSeaGreen
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
|
||||
//
|
||||
#define chikouSpanBufferIndex 4
|
||||
double chikouSpanBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XICH CS"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrDarkGreen
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define senkouABufferIndex 5
|
||||
double senkouABuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XICH SSA"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrLightGray
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define senkouBBufferIndex 6
|
||||
double senkouBBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XICH SSB"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrLightGray
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
|
||||
//
|
||||
#define senkouSpanABufferIndex 7
|
||||
double senkouSpanABuffer[];
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
#define senkouSpanBBufferIndex 8
|
||||
double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
// KUMOCLOUD ...
|
||||
|
||||
//
|
||||
#define kumoBufferIndex 7
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XICH Kumo"
|
||||
#property indicator_type8 DRAW_FILLING
|
||||
#property indicator_color8 clrAqua, clrMagenta
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(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()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
double topValue;
|
||||
double bottomValue;
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
// Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (tenkanSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_HIGH;
|
||||
mTenkanSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_OPEN;
|
||||
mTenkanSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mTenkanSenTopMode,
|
||||
tenkanSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mTenkanSenBottomMode,
|
||||
tenkanSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double tenkanSenValue = (topValue + bottomValue) / 2;
|
||||
tenkanSenBuffer[bar_index] = tenkanSenValue;
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
// Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (kijunSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_HIGH;
|
||||
mKijunSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_OPEN;
|
||||
mKijunSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mKijunSenTopMode,
|
||||
kijunSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mKijunSenBottomMode,
|
||||
kijunSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double kijunSenValue = (topValue + bottomValue) / 2;
|
||||
kijunSenBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
kijunSenPlusBuffer[bar_index] = kijunSenValue;
|
||||
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
double chikouSpanValue = GetAppliedPrice(
|
||||
bar_index,
|
||||
chikuoSpanAppliedTo);
|
||||
chikouSpanBuffer[bar_index] = chikouSpanValue;
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2;
|
||||
senkouABuffer[bar_index] = senkouSpanAValue;
|
||||
senkouSpanABuffer[bar_index] = senkouSpanAValue;
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
// Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (senkouSpanBMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_HIGH;
|
||||
mSenkouSpanBBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_OPEN;
|
||||
mSenkouSpanBBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mSenkouSpanBTopMode,
|
||||
senkouSpanBLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mSenkouSpanBBottomMode,
|
||||
senkouSpanBLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double senkouSpanBValue = (topValue + bottomValue) / 2;
|
||||
senkouBBuffer[bar_index] = senkouSpanBValue;
|
||||
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,786 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------
|
||||
// Name: X121_XMRB
|
||||
// Description: Moving Average Ribbon
|
||||
//
|
||||
//
|
||||
// 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_XMRB Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XMRB"
|
||||
|
||||
//
|
||||
// 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";
|
||||
input ENUM_MA_METHOD ribbonMode = MODE_EMA; // 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 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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_XMRB 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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(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 ...";
|
||||
Print(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()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,992 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: X121_XPV
|
||||
// Description: Market Peaks and Vales
|
||||
//
|
||||
//
|
||||
// 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_XPV Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XPV"
|
||||
|
||||
//
|
||||
// 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 int hindLength = 35; // Hind Length
|
||||
input double fiboLevel1 = 0.382; // Fibio 1st Level
|
||||
input double fiboLevel2 = 0.5; // Fibio 2st Level
|
||||
input double fiboLevel3 = 0.618; // Fibio 3rd Level
|
||||
|
||||
//
|
||||
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
|
||||
input bool showLevels = false; // Show Levels
|
||||
input bool showFibo1Levels = true; // Show Fibo 1st Level
|
||||
input bool showFibo2Levels = true; // Show Fibo 2nd Level
|
||||
input bool showFibo3Levels = true; // Show Fibo 3rd Level
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 26
|
||||
#property indicator_plots 18
|
||||
|
||||
//
|
||||
// PEKSANDVALES ...
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
|
||||
//
|
||||
#define peaksBufferIndex 0
|
||||
double peaksBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XPV PEAKS"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
|
||||
//
|
||||
#define valesBufferIndex 1
|
||||
double valesBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XPV VALES"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define rBufferIndex 2
|
||||
double rBuffer[];
|
||||
|
||||
//
|
||||
#define rColorBufferIndex 3
|
||||
double rColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XPV R"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrAqua, CLR_NONE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define sBufferIndex 4
|
||||
#define sBufferPlotIndex 3
|
||||
double sBuffer[];
|
||||
|
||||
//
|
||||
#define sColorBufferIndex 5
|
||||
double sColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XPV S"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 clrMagenta, CLR_NONE
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// FIBBO Level 1 ...
|
||||
|
||||
//
|
||||
#define fl1BufferIndex 6
|
||||
#define fl1BufferPlotIndex 4
|
||||
double fl1Buffer[];
|
||||
|
||||
//
|
||||
#define fl1ColorBufferIndex 7
|
||||
double fl1ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XPV FL1"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 CLR_NONE, clrGold
|
||||
#property indicator_style5 STYLE_DASHDOTDOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// FIBBO Level 2 ...
|
||||
|
||||
//
|
||||
#define fl2BufferIndex 8
|
||||
#define fl2BufferPlotIndex 5
|
||||
double fl2Buffer[];
|
||||
|
||||
//
|
||||
#define fl2ColorBufferIndex 9
|
||||
double fl2ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XPV FL2"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrGold
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// FIBBO Level 3 ...
|
||||
|
||||
//
|
||||
#define fl3BufferIndex 10
|
||||
#define fl3BufferPlotIndex 6
|
||||
double fl3Buffer[];
|
||||
|
||||
//
|
||||
#define fl3ColorBufferIndex 11
|
||||
double fl3ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XPV FL3"
|
||||
#property indicator_type7 DRAW_COLOR_LINE
|
||||
#property indicator_color7 CLR_NONE, clrGold
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// LEVELS ...
|
||||
|
||||
//
|
||||
#define sHHBufferIndex 12
|
||||
#define sHHBufferPlotIndex 7
|
||||
double sHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XPV SHH"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrLightGray
|
||||
#property indicator_style8 STYLE_DOT
|
||||
#property indicator_width8 1
|
||||
|
||||
#define sLLBufferIndex 13
|
||||
#define sLLBufferPlotIndex 8
|
||||
double sLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "X121_XPV SLL"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrLightGray
|
||||
#property indicator_style9 STYLE_DOT
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
#define mHHBufferIndex 14
|
||||
#define mHHBufferPlotIndex 9
|
||||
double mHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121_XPV MHH"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrLightGray
|
||||
#property indicator_style10 STYLE_DOT
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
#define mLLBufferIndex 15
|
||||
#define mLLBufferPlotIndex 10
|
||||
double mLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "X121_XPV MLL"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrLightGray
|
||||
#property indicator_style11 STYLE_DOT
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
#define lHHBufferIndex 16
|
||||
#define lHHBufferPlotIndex 11
|
||||
double lHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "X121_XPV LHH"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrLightGray
|
||||
#property indicator_style12 STYLE_DOT
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
#define lLLBufferIndex 17
|
||||
#define lLLBufferPlotIndex 12
|
||||
double lLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label13 "X121_XPV LLL"
|
||||
#property indicator_type13 DRAW_LINE
|
||||
#property indicator_color13 clrLightGray
|
||||
#property indicator_style13 STYLE_DOT
|
||||
#property indicator_width13 1
|
||||
|
||||
//
|
||||
#define hHHBufferIndex 18
|
||||
#define hHHBufferPlotIndex 13
|
||||
double hHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label14 "X121_XPV HHH"
|
||||
#property indicator_type14 DRAW_LINE
|
||||
#property indicator_color14 clrLightGray
|
||||
#property indicator_style14 STYLE_DOT
|
||||
#property indicator_width14 1
|
||||
|
||||
//
|
||||
#define hLLBufferIndex 19
|
||||
#define hLLBufferPlotIndex 14
|
||||
double hLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label15 "X121_XPV HLL"
|
||||
#property indicator_type15 DRAW_LINE
|
||||
#property indicator_color15 clrLightGray
|
||||
#property indicator_style15 STYLE_DOT
|
||||
#property indicator_width15 1
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(shortLength > 2 &&
|
||||
mediumLength > shortLength &&
|
||||
longLength > mediumLength &&
|
||||
hindLength > longLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
result = MathMax(shortLength, mediumLength);
|
||||
result = MathMax(result, longLength);
|
||||
result = MathMax(result, hindLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// 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, showPeaksAndVales);
|
||||
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, showPeaksAndVales);
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
|
||||
|
||||
//
|
||||
// SUPPORT and RESISTANCE ...
|
||||
//
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
ArraySetAsSeries(rBuffer, true);
|
||||
SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// RESISTANCE Color ...
|
||||
ArraySetAsSeries(rColorBuffer, true);
|
||||
SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
ArraySetAsSeries(sBuffer, true);
|
||||
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// SUPPORT Color ...
|
||||
ArraySetAsSeries(sColorBuffer, true);
|
||||
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// FIBBO Levels ...
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl1Buffer, true);
|
||||
SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl1BufferIndex, PLOT_SHOW_DATA, showFibo1Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl1ColorBuffer, true);
|
||||
SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl2Buffer, true);
|
||||
SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl2BufferIndex, PLOT_SHOW_DATA, showFibo2Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl2ColorBuffer, true);
|
||||
SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// LEVEL 3 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl3Buffer, true);
|
||||
SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl3BufferIndex, PLOT_SHOW_DATA, showFibo3Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl3ColorBuffer, true);
|
||||
SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE zoneDrawType = showLevels ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// SHORT Buffers ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// MEDIUM Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LONG Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// HIND Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate ...
|
||||
|
||||
//
|
||||
double rColorIDX = 1;
|
||||
double sColorIDX = 1;
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int sHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sHHValue = GetAppliedPrice(
|
||||
sHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
sHHBuffer[bar_index] = sHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int sLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sLLValue = GetAppliedPrice(
|
||||
sLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
sLLBuffer[bar_index] = sLLValue;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int mHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mHHValue = GetAppliedPrice(
|
||||
mHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
mHHBuffer[bar_index] = mHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int mLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mLLValue = GetAppliedPrice(
|
||||
mLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
mLLBuffer[bar_index] = mLLValue;
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int lHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lHHValue = GetAppliedPrice(
|
||||
lHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
lHHBuffer[bar_index] = lHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int lLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lLLValue = GetAppliedPrice(
|
||||
lLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
lLLBuffer[bar_index] = lLLValue;
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int hHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hHHValue = GetAppliedPrice(
|
||||
hHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
hHHBuffer[bar_index] = hHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int hLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hLLValue = GetAppliedPrice(
|
||||
hLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
hLLBuffer[bar_index] = hLLValue;
|
||||
|
||||
//
|
||||
// RESISTANCE SUPPORT ...
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
double rValue = (sHHValue + mHHValue + lHHValue + hHHValue) / 4;
|
||||
rBuffer[bar_index] = rValue;
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
double sValue = (sLLValue + mLLValue + lLLValue + hLLValue) / 4;
|
||||
sBuffer[bar_index] = sValue;
|
||||
|
||||
//
|
||||
// PEAKS and VALES ...
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
bool isPeak = rValue == hHHValue &&
|
||||
hHHValue == lHHValue &&
|
||||
lHHValue == mHHValue &&
|
||||
mHHValue == sHHValue;
|
||||
//
|
||||
if (isPeak && lastPeak != rValue)
|
||||
{
|
||||
//
|
||||
if (showPeaksAndVales)
|
||||
{
|
||||
rColorIDX = 0;
|
||||
}
|
||||
|
||||
//
|
||||
lastPeak = rValue;
|
||||
peaksBuffer[bar_index] = lastPeak;
|
||||
}
|
||||
else
|
||||
{
|
||||
peaksBuffer[bar_index] = lastPeak;
|
||||
}
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
bool isVale = sValue == hLLValue &&
|
||||
hLLValue == lLLValue &&
|
||||
lLLValue == mLLValue &&
|
||||
mLLValue == sLLValue;
|
||||
|
||||
//
|
||||
if (isVale && lastVale != sValue)
|
||||
{
|
||||
//
|
||||
if (showPeaksAndVales)
|
||||
{
|
||||
sColorIDX = 0;
|
||||
}
|
||||
|
||||
//
|
||||
lastVale = sValue;
|
||||
valesBuffer[bar_index] = lastVale;
|
||||
}
|
||||
else
|
||||
{
|
||||
valesBuffer[bar_index] = lastVale;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Default Colors ...
|
||||
|
||||
//
|
||||
rColorBuffer[bar_index] = rColorIDX;
|
||||
sColorBuffer[bar_index] = sColorIDX;
|
||||
|
||||
//
|
||||
// Calculate Fibonacci ...
|
||||
double upPrice = peaksBuffer[bar_index];
|
||||
double downPrice = valesBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Level 1 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel1BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel1,
|
||||
1);
|
||||
fl1Buffer[bar_index] = fibLevel1BullishValue;
|
||||
double fl1BullColorIdx = showFibo1Levels ? 1 : 0;
|
||||
fl1ColorBuffer[bar_index] = fl1BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel1BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel1,
|
||||
// 0);
|
||||
// fl1BearBuffer[bar_index] = fibLevel1BearishValue;
|
||||
// double fl1BearColorIdx = showFibo1Levels ? 1 : 0;
|
||||
// fl1BearColorBuffer[bar_index] = fl1BearColorIdx;
|
||||
|
||||
//
|
||||
// Level 2 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel2BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel2,
|
||||
1);
|
||||
fl2Buffer[bar_index] = fibLevel2BullishValue;
|
||||
double fl2BullColorIdx = showFibo2Levels ? 1 : 0;
|
||||
fl2ColorBuffer[bar_index] = fl2BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel2BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel2,
|
||||
// 0);
|
||||
// fl2BearBuffer[bar_index] = fibLevel2BearishValue;
|
||||
// double fl2BearColorIdx = showFibo2Levels ? 1 : 0;
|
||||
// fl2BearColorBuffer[bar_index] = fl2BearColorIdx;
|
||||
|
||||
//
|
||||
// Level 3 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel3BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel3,
|
||||
1);
|
||||
fl3Buffer[bar_index] = fibLevel3BullishValue;
|
||||
double fl3BullColorIdx = showFibo3Levels ? 1 : 0;
|
||||
fl3ColorBuffer[bar_index] = fl3BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel3BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel3,
|
||||
// 0);
|
||||
// fl3BearBuffer[bar_index] = fibLevel3BearishValue;
|
||||
// double fl3BearColorIdx = showFibo3Levels ? 1 : 0;
|
||||
// fl3BearColorBuffer[bar_index] = fl3BearColorIdx;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,437 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ----------------------------------------------------
|
||||
// Name: X121_XSSLC
|
||||
// Description: SSL Channel Indicator
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XSSLC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XSSLC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 36; // 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 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_XSSLC 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_XSSLC 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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...";
|
||||
Print(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);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(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, showDown);
|
||||
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()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,354 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,775 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCHNL
|
||||
// Description: XCHL Channel Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XCHNL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCHNL"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// END XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret Cycles";
|
||||
input int shortLength = 9; // Short Length
|
||||
input int mediumLength = 17; // Medium Length
|
||||
input int longLength = 26; // Long Length
|
||||
input int hindLength = 35; // Hind Length
|
||||
|
||||
//
|
||||
input group "Trend";
|
||||
input int numOfShoulder = 10; // Number of Shoulders for Swings
|
||||
|
||||
//
|
||||
input group "Detection Modes";
|
||||
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTrend = false; // Show Trend
|
||||
input bool showSRs = false; // Show Support and Resistance
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// PEKSANDVALES ...
|
||||
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 0
|
||||
|
||||
#define sHHBufferIndex 0
|
||||
#define sLLBufferIndex 1
|
||||
#define mHHBufferIndex 2
|
||||
#define mLLBufferIndex 3
|
||||
#define lHHBufferIndex 4
|
||||
#define lLLBufferIndex 5
|
||||
#define hHHBufferIndex 6
|
||||
#define hLLBufferIndex 7
|
||||
|
||||
double sHHBuffer[];
|
||||
double sLLBuffer[];
|
||||
double mHHBuffer[];
|
||||
double mLLBuffer[];
|
||||
double lHHBuffer[];
|
||||
double lLLBuffer[];
|
||||
double hHHBuffer[];
|
||||
double hLLBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Make an Instance of Hull Class ...
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
RemoveDraws(drawPrefix);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Validate Peaks and Vales ...
|
||||
(shortLength > 2 &&
|
||||
mediumLength > shortLength &&
|
||||
longLength > mediumLength &&
|
||||
hindLength > longLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
result = MathMax(shortLength, mediumLength);
|
||||
result = MathMax(result, longLength);
|
||||
result = MathMax(result, hindLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate ...
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int sHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sHHValue = GetAppliedPrice(
|
||||
sHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
sHHBuffer[bar_index] = sHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int sLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sLLValue = GetAppliedPrice(
|
||||
sLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
sLLBuffer[bar_index] = sLLValue;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int mHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mHHValue = GetAppliedPrice(
|
||||
mHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
mHHBuffer[bar_index] = mHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int mLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mLLValue = GetAppliedPrice(
|
||||
mLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
mLLBuffer[bar_index] = mLLValue;
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int lHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lHHValue = GetAppliedPrice(
|
||||
lHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
lHHBuffer[bar_index] = lHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int lLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lLLValue = GetAppliedPrice(
|
||||
lLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
lLLBuffer[bar_index] = lLLValue;
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int hHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hHHValue = GetAppliedPrice(
|
||||
hHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
hHHBuffer[bar_index] = hHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int hLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hLLValue = GetAppliedPrice(
|
||||
hLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
hLLBuffer[bar_index] = hLLValue;
|
||||
|
||||
//
|
||||
// Find Swings ...
|
||||
|
||||
//
|
||||
// High ...
|
||||
int hSwing1 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
bar_index + 1);
|
||||
|
||||
int hSwing2 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
hSwing1 + 1);
|
||||
|
||||
//
|
||||
// High ...
|
||||
int hSwing3 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
hSwing2 + 1);
|
||||
|
||||
// int hSwing4 = FindSwing(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// MODE_HIGH,
|
||||
// numOfShoulder,
|
||||
// hSwing3 + 1);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
int lSwing1 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
bar_index + 1);
|
||||
|
||||
int lSwing2 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
lSwing1 + 1);
|
||||
|
||||
int lSwing3 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
lSwing2 + 1);
|
||||
|
||||
// int lSwing4 = FindSwing(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// MODE_LOW,
|
||||
// numOfShoulder,
|
||||
// lSwing3 + 1);
|
||||
|
||||
//
|
||||
if (bar_index < 50)
|
||||
{
|
||||
|
||||
//
|
||||
bool isStrongResistance =
|
||||
//
|
||||
hHHBuffer[bar_index + 1] == hHHBuffer[bar_index + 2] &&
|
||||
hHHBuffer[bar_index + 2] == hHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
lHHBuffer[bar_index + 1] == lHHBuffer[bar_index + 2] &&
|
||||
lHHBuffer[bar_index + 2] == lHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
mHHBuffer[bar_index + 1] == mHHBuffer[bar_index + 2] &&
|
||||
mHHBuffer[bar_index + 2] == mHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
sHHBuffer[bar_index + 1] == sHHBuffer[bar_index + 2] &&
|
||||
sHHBuffer[bar_index + 2] == sHHBuffer[bar_index + 3]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isStrongSupport =
|
||||
//
|
||||
hLLBuffer[bar_index + 1] == hLLBuffer[bar_index + 2] &&
|
||||
hLLBuffer[bar_index + 2] == hLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
lLLBuffer[bar_index + 1] == lLLBuffer[bar_index + 2] &&
|
||||
lLLBuffer[bar_index + 2] == lLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
mLLBuffer[bar_index + 1] == mLLBuffer[bar_index + 2] &&
|
||||
mLLBuffer[bar_index + 2] == mLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
sLLBuffer[bar_index + 1] == sLLBuffer[bar_index + 2] &&
|
||||
sLLBuffer[bar_index + 2] == sLLBuffer[bar_index + 3]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isStrongResistance && showSRs)
|
||||
{
|
||||
//
|
||||
DrawSupportResistance(
|
||||
"R",
|
||||
clrRed,
|
||||
sHHBuffer[bar_index + 3],
|
||||
bar_index + 3);
|
||||
}
|
||||
|
||||
//
|
||||
if (isStrongSupport && showSRs)
|
||||
{
|
||||
//
|
||||
DrawSupportResistance(
|
||||
"S",
|
||||
clrGreen,
|
||||
sLLBuffer[bar_index + 3],
|
||||
bar_index + 3);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (showTrend && bar_index < 20)
|
||||
{
|
||||
//
|
||||
DrawSwing(
|
||||
"High1",
|
||||
MODE_HIGH,
|
||||
clrAqua,
|
||||
hSwing1,
|
||||
hSwing2);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"Low1",
|
||||
MODE_LOW,
|
||||
clrAqua,
|
||||
lSwing1,
|
||||
lSwing2);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"High2",
|
||||
MODE_HIGH,
|
||||
clrMagenta,
|
||||
hSwing2,
|
||||
hSwing3);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"Low2",
|
||||
MODE_LOW,
|
||||
clrMagenta,
|
||||
lSwing2,
|
||||
lSwing3);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void DrawSwing(
|
||||
string prefix, // Prefix ...
|
||||
ENUM_SERIESMODE mode, // Swing Mode ...
|
||||
color swingColor, // Color ...
|
||||
int index1, // Index 1 ...
|
||||
int index2 // Index 2 ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (mode != MODE_HIGH && mode != MODE_LOW)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL c1 = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index1);
|
||||
|
||||
//
|
||||
datetime time1 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index1);
|
||||
|
||||
//
|
||||
XOHCL c2 = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index2);
|
||||
|
||||
//
|
||||
datetime time2 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index2);
|
||||
|
||||
//
|
||||
double value1 = -1;
|
||||
double value2 = -1;
|
||||
|
||||
//
|
||||
switch (mode)
|
||||
{
|
||||
//
|
||||
case MODE_HIGH:
|
||||
value1 = c1.high;
|
||||
value2 = c2.high;
|
||||
break;
|
||||
|
||||
//
|
||||
case MODE_LOW:
|
||||
value1 = c1.low;
|
||||
value2 = c2.low;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
if (value1 == -1 || value2 == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
long chartId = ChartID();
|
||||
string tlName = prefix + "_" + "TrendLine";
|
||||
|
||||
// //
|
||||
// if (IsDrawExists(tlName)) {
|
||||
// RemoveDraw(tlName);
|
||||
// }
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartId,
|
||||
tlName,
|
||||
0,
|
||||
time2,
|
||||
value2,
|
||||
time1,
|
||||
value1,
|
||||
swingColor,
|
||||
STYLE_DOT,
|
||||
3,
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Support and Resistance ...
|
||||
void DrawSupportResistance(
|
||||
string prefix, // Prefix ...
|
||||
color lColor, // Color ...
|
||||
double price, // Support or Resistance price ...
|
||||
int bar_index // Start Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
datetime time1 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
datetime time2 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index - 1);
|
||||
|
||||
//
|
||||
long chartId = ChartID();
|
||||
string tlName = prefix + "_" + "TL" + "_" + (string)(NormalizePrice(price, _Symbol));
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartId,
|
||||
tlName,
|
||||
0,
|
||||
time1,
|
||||
price,
|
||||
time2,
|
||||
price,
|
||||
lColor,
|
||||
STYLE_DOT,
|
||||
3,
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,187 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Alert Library
|
||||
// --------------------------------------
|
||||
// Name: XAlert
|
||||
// Description: provides Alerts abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Alerts";
|
||||
input bool enableAlerts = true; // Enable Alerts
|
||||
input bool logAlerts = true; // Log Alerts
|
||||
input bool terminalAlerts = false; // Terminal Alerts
|
||||
input bool mailAlerts = false; // Mail Alerts
|
||||
input bool pushAlerts = false; // Push Alerts
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
#include "x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string alertPrefix = "X-Alert";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitAlertLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitAlertLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Attach Alert Prefix to Message ...
|
||||
string PrepareAlertMessage(string message)
|
||||
{
|
||||
//
|
||||
StringReplace(message, "\n", " | ");
|
||||
|
||||
//
|
||||
StringConcatenate(message, alertPrefix, " > ", message);
|
||||
|
||||
//
|
||||
return message;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Alert ...
|
||||
void LogAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !logAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
LogMessage(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal Alert ...
|
||||
void TerminalAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !terminalAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
// Send Terminal Alert ...
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail Alert ...
|
||||
void MailAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !mailAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Mail Alert ...
|
||||
SendMail(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send Push Notification ...
|
||||
void PushAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !pushAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
//
|
||||
// Send Push Notification Alert ...
|
||||
SendNotification(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Sending ...
|
||||
void SendAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
if (logAlerts)
|
||||
{
|
||||
LogAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal ...
|
||||
if (terminalAlerts)
|
||||
{
|
||||
TerminalAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail ...
|
||||
if (mailAlerts)
|
||||
{
|
||||
MailAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Push ...
|
||||
if (pushAlerts)
|
||||
{
|
||||
PushAlert(message);
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,177 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Http Library
|
||||
// ------------------------------------------
|
||||
// Name: XHttp
|
||||
// Description: provide http communication
|
||||
// abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Model Definition ...
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
//
|
||||
// END Model Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitHttpLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitHttpLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,117 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Logger Library
|
||||
// ---------------------------------------
|
||||
// Name: XLogger
|
||||
// Description: provides Logging abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Logging";
|
||||
input bool enableLogging = true; // Enable Logging
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Including Models ...
|
||||
#include "x-saherelm.models.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string logTag = "X-Logger"; // LogTag
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Logging a Message ...
|
||||
void LogMessage(string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, " > ", message);
|
||||
}
|
||||
void LogMessage(string tag, string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(tag, " > ", message);
|
||||
}
|
||||
|
||||
//
|
||||
void LogEmptyLine()
|
||||
{
|
||||
LogMessage(" ");
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Array ...
|
||||
void LogArray(int &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(double &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(string &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,238 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Models Library
|
||||
// ---------------------------------------
|
||||
// Name: XModels
|
||||
// Description: provides all required models ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// How To Calculate Static Volume ...
|
||||
enum ENUM_STATIC_VOLUME_METHODS
|
||||
{
|
||||
//
|
||||
// Based On Deposit ...
|
||||
X_STATIC_VOLUME_BASED_ON_DEPOSIT,
|
||||
//
|
||||
// Based On Balance ...
|
||||
X_STATIC_VOLUME_BASED_ON_BALANCE,
|
||||
};
|
||||
|
||||
//
|
||||
// START Model Definitions ...
|
||||
//
|
||||
//
|
||||
// OHCL Candel Model ...
|
||||
enum ENUM_X_PRICE
|
||||
{
|
||||
X_PRICE_HIGH,
|
||||
X_PRICE_OPEN,
|
||||
X_PRICE_CLOSE,
|
||||
X_PRICE_LOW
|
||||
};
|
||||
|
||||
//
|
||||
// Swing Types Enum ...
|
||||
enum ENUM_X_SWING_TYPE
|
||||
{
|
||||
X_NO_SWING = 0,
|
||||
X_SWING_HIGH = 1,
|
||||
X_SWING_LOW = -1,
|
||||
};
|
||||
|
||||
//
|
||||
// Available Guard Action ...
|
||||
enum ENUM_X_GUARD_ACTIONS
|
||||
{
|
||||
X_GUARD_ACTION_HEDGE,
|
||||
X_GUARD_PARTIAL_CLOSE,
|
||||
X_GUARD_ACTION_TRAIL_STOP,
|
||||
X_GUARD_ACTION_FORCE_CLOSE,
|
||||
X_GUARD_ACTION_ADD_SUPPORT_SIGNAL,
|
||||
X_GUARD_ACTION_CANCEL_PENDING_ORDERS,
|
||||
};
|
||||
|
||||
//
|
||||
// Model Guard Info ...
|
||||
struct XGuard
|
||||
{
|
||||
string symbol;
|
||||
string provider;
|
||||
ENUM_TIMEFRAMES period;
|
||||
ENUM_POSITION_TYPE type;
|
||||
ENUM_X_GUARD_ACTIONS action;
|
||||
|
||||
//
|
||||
double dblPayLoad;
|
||||
string strPayload;
|
||||
};
|
||||
|
||||
//
|
||||
// Describe an Specific Candle ...
|
||||
struct XOHCL
|
||||
{
|
||||
double high;
|
||||
double open;
|
||||
double close;
|
||||
double low;
|
||||
};
|
||||
|
||||
//
|
||||
// Model Support and Resistance
|
||||
// for Specific Bar ...
|
||||
struct XOHCLSupRes
|
||||
{
|
||||
//
|
||||
double res[];
|
||||
|
||||
//
|
||||
double sup[];
|
||||
};
|
||||
|
||||
//
|
||||
// Available Order Modes ...
|
||||
enum ENUM_X_ORDER_MODES
|
||||
{
|
||||
X_ORDER_MODE_MARKET = 0, // Market Order
|
||||
X_ORDER_MODE_STOP = 1, // Pending Stop Order
|
||||
X_ORDER_MODE_LIMIT = 2, // Pending Limit Order
|
||||
X_ORDER_MODE_STOP_LIMIT = 3, // Pending Stop Limit Order
|
||||
};
|
||||
|
||||
//
|
||||
// Model a Signal ...
|
||||
struct XSignal
|
||||
{
|
||||
//
|
||||
string providers[];
|
||||
|
||||
//
|
||||
string symbol;
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
ENUM_POSITION_TYPE type;
|
||||
|
||||
//
|
||||
ENUM_X_ORDER_MODES mode;
|
||||
|
||||
//
|
||||
double entry;
|
||||
|
||||
//
|
||||
double riskAmount;
|
||||
|
||||
//
|
||||
double tp;
|
||||
|
||||
//
|
||||
double sl;
|
||||
|
||||
//
|
||||
double r2r;
|
||||
|
||||
//
|
||||
double volume;
|
||||
|
||||
//
|
||||
bool calculateTP;
|
||||
|
||||
//
|
||||
bool useSupportAndResistance;
|
||||
|
||||
//
|
||||
bool useRiskAmountAsVolume;
|
||||
};
|
||||
//
|
||||
// EXTENSION Methods ...
|
||||
|
||||
//
|
||||
void Add(
|
||||
XSignal &item,
|
||||
XSignal &buffer[])
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// Clear an Specific Signal Item ...
|
||||
void Clean(XSignal &item)
|
||||
{
|
||||
//
|
||||
ArrayFree(item.providers);
|
||||
ArrayResize(item.providers, 0);
|
||||
|
||||
//
|
||||
item.symbol = "";
|
||||
item.type = NULL;
|
||||
item.mode = NULL;
|
||||
item.period = NULL;
|
||||
|
||||
//
|
||||
item.tp = 0;
|
||||
item.sl = 0;
|
||||
item.r2r = 0;
|
||||
item.entry = 0;
|
||||
item.volume = 0;
|
||||
item.riskAmount = 0;
|
||||
}
|
||||
|
||||
//
|
||||
void Clean(XSignal &buffer[])
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
ArrayResize(buffer, 0);
|
||||
}
|
||||
|
||||
//
|
||||
void Clean(XGuard &buffer[])
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
ArrayResize(buffer, 0);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,85 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Seriallize Library
|
||||
// ---------------------------------------
|
||||
// Name: XSeriallizer
|
||||
// Description: provides Seriallizing EA abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
|
||||
//
|
||||
string XProviderToken = "PRV";
|
||||
string XSupportToken = "SP";
|
||||
|
||||
//
|
||||
string GenerateSupportSignalComment(
|
||||
ulong ticket // Position/Order Ticket
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result = XSupportToken + "(" + (string)ticket + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string ExtractParentTicketOfSupport(string comment)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ExtractString(
|
||||
comment,
|
||||
XSupportToken + "(",
|
||||
")");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract a Provider name if exists from a Comment ...
|
||||
string ExtractProvider(string comment)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ExtractString(
|
||||
comment,
|
||||
XProviderToken + "(",
|
||||
")");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,241 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X12 Draw Library
|
||||
// ------------------------------------------
|
||||
// Name: X121Draw
|
||||
// Description: provides Draw Requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
|
||||
//
|
||||
// START Draw Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Draw Signal ...
|
||||
void DrawSignal(const ulong ticket, XSignal &signal)
|
||||
{
|
||||
//
|
||||
bool isLong = IsLong(signal.type);
|
||||
|
||||
//
|
||||
string prefix = (string)ticket + "_" + ToString(signal.period);
|
||||
|
||||
//
|
||||
// Retrieve Time ...
|
||||
datetime time = iTime(
|
||||
signal.symbol,
|
||||
signal.period,
|
||||
0);
|
||||
|
||||
//
|
||||
// Retrieve 3 Time ...
|
||||
datetime time3 = iTime(
|
||||
signal.symbol,
|
||||
signal.period,
|
||||
3);
|
||||
|
||||
//
|
||||
color posColor = isLong
|
||||
? clrSpringGreen
|
||||
: clrTomato;
|
||||
color tpColor = clrSpringGreen;
|
||||
color slColor = clrTomato;
|
||||
color entryColor = clrGold;
|
||||
|
||||
//
|
||||
ENUM_LINE_STYLE vLineStyle = STYLE_DOT;
|
||||
ENUM_LINE_STYLE tpLineStyle = STYLE_SOLID;
|
||||
ENUM_LINE_STYLE slLineStyle = STYLE_SOLID;
|
||||
ENUM_LINE_STYLE entryLineStyle = STYLE_SOLID;
|
||||
|
||||
//
|
||||
int lineWidth = 2;
|
||||
|
||||
//
|
||||
long chartID = ChartID();
|
||||
|
||||
//
|
||||
// Vertical Line ...
|
||||
string vlName = prefix + "_" + (string)time;
|
||||
|
||||
//
|
||||
DrawVerticalLine(
|
||||
chartID,
|
||||
vlName,
|
||||
0,
|
||||
time,
|
||||
posColor,
|
||||
vLineStyle,
|
||||
lineWidth);
|
||||
|
||||
//
|
||||
// TP ...
|
||||
double profit = (MathAbs(signal.tp - signal.entry)) * signal.volume;
|
||||
string tpName = prefix + "_TP_" + (string)profit;
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartID,
|
||||
tpName,
|
||||
0,
|
||||
time3,
|
||||
signal.tp,
|
||||
time,
|
||||
signal.tp,
|
||||
tpColor,
|
||||
tpLineStyle,
|
||||
lineWidth);
|
||||
|
||||
//
|
||||
// SL ...
|
||||
double lost = (MathAbs(signal.sl - signal.entry)) * signal.volume;
|
||||
string slName = prefix + "_SL_" + (string)lost;
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartID,
|
||||
slName,
|
||||
0,
|
||||
time3,
|
||||
signal.sl,
|
||||
time,
|
||||
signal.sl,
|
||||
slColor,
|
||||
slLineStyle,
|
||||
lineWidth);
|
||||
|
||||
//
|
||||
// ENTRY ...
|
||||
string entryName = prefix + "_ENTRY_" + (string)lost;
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartID,
|
||||
entryName,
|
||||
0,
|
||||
time3,
|
||||
signal.entry,
|
||||
time,
|
||||
signal.entry,
|
||||
entryColor,
|
||||
entryLineStyle,
|
||||
lineWidth);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Support and Resistance ...
|
||||
void DrawSupportResistance(
|
||||
int bar_index,
|
||||
XOHCLSupRes &data,
|
||||
string prefix = "",
|
||||
color supportColor = clrOrange,
|
||||
color resistanceColor = clrOrange)
|
||||
{
|
||||
//
|
||||
datetime barTime = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
datetime prevBarTime = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index + 5);
|
||||
|
||||
//
|
||||
long chID = ChartID();
|
||||
int subWindiw = 0;
|
||||
int lineWidth = 1;
|
||||
|
||||
//
|
||||
string mPrefix = prefix + "_" + (string)barTime + "_";
|
||||
|
||||
//
|
||||
// SUPPORTS ...
|
||||
|
||||
//
|
||||
int supCount = ArraySize(data.sup);
|
||||
if (supCount > 0)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < supCount; i++)
|
||||
{
|
||||
//
|
||||
double iSup = data.sup[i];
|
||||
|
||||
//
|
||||
string supTlName = mPrefix + "SUP[" + (string)(i + 1) + "]_(" + (string)iSup + ")";
|
||||
|
||||
//
|
||||
// Draw Support ...
|
||||
DrawTrendLine(
|
||||
chID,
|
||||
supTlName,
|
||||
subWindiw,
|
||||
prevBarTime,
|
||||
iSup,
|
||||
barTime,
|
||||
iSup,
|
||||
supportColor,
|
||||
STYLE_DOT,
|
||||
lineWidth,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// RESISTANCES ...
|
||||
|
||||
//
|
||||
int resCount = ArraySize(data.res);
|
||||
if (resCount > 0)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < resCount; i++)
|
||||
{
|
||||
//
|
||||
double iRes = data.res[i];
|
||||
|
||||
//
|
||||
string resTlName = mPrefix + "RES[" + (string)(i + 1) + "]_(" + (string)iRes + ")";
|
||||
|
||||
//
|
||||
// Draw Support ...
|
||||
DrawTrendLine(
|
||||
chID,
|
||||
resTlName,
|
||||
subWindiw,
|
||||
prevBarTime,
|
||||
iRes,
|
||||
barTime,
|
||||
iRes,
|
||||
resistanceColor,
|
||||
STYLE_DOT,
|
||||
lineWidth,
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Draw Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user