666 lines
14 KiB
Plaintext
666 lines
14 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
// SaherElm IT Center MQL5 Indicator
|
|
// -------------------------------------------
|
|
// Name: XCSS
|
|
// Description: XCycle Section Score ...
|
|
//
|
|
// 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 XCSS Indicator"
|
|
#property strict
|
|
|
|
//
|
|
// IMPORT ...
|
|
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
|
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
#include "../Classes/x-saherelm.x121.xmcycle.class.mq5"
|
|
|
|
//
|
|
#define ShortName "XCSS"
|
|
|
|
//
|
|
// INPUTS ...
|
|
|
|
//
|
|
input group "Market";
|
|
|
|
//
|
|
input group "Short";
|
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Period
|
|
|
|
//
|
|
input group "Medium";
|
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Period
|
|
|
|
//
|
|
input group "Long";
|
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Period
|
|
|
|
//
|
|
input group "Hind";
|
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Period
|
|
|
|
//
|
|
// BUFFERS ...
|
|
|
|
//
|
|
#property indicator_separate_window
|
|
|
|
//
|
|
#property indicator_buffers 2
|
|
#property indicator_plots 2
|
|
|
|
//
|
|
#define bullishBufferIndex 0
|
|
double bullishBuffer[];
|
|
|
|
//
|
|
#property indicator_label1 "Bullish"
|
|
#property indicator_type1 DRAW_LINE
|
|
#property indicator_color1 clrLime
|
|
#property indicator_width1 2
|
|
|
|
//
|
|
#define bearishBufferIndex 1
|
|
double bearishBuffer[];
|
|
|
|
//
|
|
#property indicator_label2 "Bearish"
|
|
#property indicator_type2 DRAW_LINE
|
|
#property indicator_color2 clrRed
|
|
#property indicator_width2 2
|
|
|
|
//
|
|
// VARIABLE ...
|
|
|
|
//
|
|
// Indicators ...
|
|
XCCInputs ccInputs;
|
|
XCTInputs ctInputs;
|
|
|
|
//
|
|
XZGInputs zgInputs;
|
|
XPVInputs pvInputs;
|
|
XHKInputs hkInputs;
|
|
XMCInputs mcInputs;
|
|
XTDInputs tdInputs;
|
|
XMRBInputs mrbInputs;
|
|
XICHInputs ichInputs;
|
|
XCHEInputs cheInputs;
|
|
XSTRInputs strInputs;
|
|
XDONInputs donInputs;
|
|
XOSCInputs oscInputs;
|
|
|
|
//
|
|
X121MCycleInputs cMarketInputs; // Curent Market Inputs
|
|
X121MCycleInputs sMarketInputs; // Short Market Inputs
|
|
X121MCycleInputs mMarketInputs; // Medium Market Inputs
|
|
X121MCycleInputs lMarketInputs; // Long Market Inputs
|
|
X121MCycleInputs hMarketInputs; // Hind Market Inputs
|
|
|
|
//
|
|
XSCX121Market *cMarket;
|
|
XSCX121Market *sMarket;
|
|
XSCX121Market *mMarket;
|
|
XSCX121Market *lMarket;
|
|
XSCX121Market *hMarket;
|
|
|
|
//
|
|
// EVENT Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
// Validate Inputs ...
|
|
if (!ValidateInputs())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// Initial Cycles ...
|
|
if (!InitCycles())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// Define Index Buffers ...
|
|
DefineBuffers();
|
|
|
|
//
|
|
// Set Indicator ShortName ...
|
|
SetIndicatorName();
|
|
|
|
//
|
|
// Init Succeed ...
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//
|
|
// DeInitialization ...
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//
|
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
// REASON_REMOVE 1 Program removed from a chart
|
|
// REASON_RECOMPILE 2 Program recompiled
|
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
// REASON_CHARTCLOSE 4 Chart closed
|
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
// REASON_TEMPLATE 7 Another chart template applied
|
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
// REASON_CLOSE 9 Terminal closed
|
|
}
|
|
|
|
//
|
|
// Calculating what we want ...
|
|
int OnCalculate(
|
|
const int rates_total, // Total Bars on Chart ...
|
|
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
const datetime &time[], // History of Open Time ...
|
|
const double &open[], // History of Open Price ...
|
|
const double &high[], // History of High Price ...
|
|
const double &low[], // History of Low Price ...
|
|
const double &close[], // History of Close Price ...
|
|
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
const long &volume[], // History of Trade Volumes ...
|
|
const int &spread[] // History of Spread Price ...
|
|
)
|
|
{
|
|
//
|
|
// 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 = 0; i > limit && !IsStopped(); i++)
|
|
{
|
|
CalculateBuffers(i);
|
|
}
|
|
|
|
//
|
|
return rates_total;
|
|
}
|
|
|
|
//
|
|
// CUSTOM Functions ...
|
|
|
|
//
|
|
// Validate Input Args for Initialization ...
|
|
bool ValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
IsValid(scMethod, scPeriod) &&
|
|
IsValid(mcMethod, mcPeriod) &&
|
|
IsValid(lcMethod, lcPeriod) &&
|
|
IsValid(hcMethod, hcPeriod)
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Define Indexes and Styles ...
|
|
void DefineBuffers()
|
|
{
|
|
//
|
|
// Bullish ...
|
|
ArraySetAsSeries(bullishBuffer, true);
|
|
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(bullishBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
|
|
//
|
|
// Bearish ...
|
|
ArraySetAsSeries(bearishBuffer, true);
|
|
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
|
|
PlotIndexSetDouble(bearishBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
}
|
|
|
|
//
|
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
void SetIndicatorName()
|
|
{
|
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
}
|
|
|
|
//
|
|
void CalculateBuffers(
|
|
int barIndex //
|
|
)
|
|
{
|
|
//
|
|
// int totalBars = iBars(_Symbol, _Period);
|
|
// Print("BarIndex: ", barIndex, ", totalBars: ", totalBars);
|
|
// bool canGo = MathAbs(totalBars - barIndex) > 100;
|
|
// if (!canGo)
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
//
|
|
// Current Market ...
|
|
|
|
//
|
|
double cBullScore = 0;
|
|
double cBearScore = 0;
|
|
|
|
//
|
|
X121MCycleConditions cConditions;
|
|
cMarket.GetMarketConditions(cConditions);
|
|
|
|
//
|
|
cConditions.GenerateScore(
|
|
cBullScore,
|
|
cBearScore //
|
|
);
|
|
|
|
//
|
|
// Short Market ...
|
|
|
|
//
|
|
double sBullScore = 0;
|
|
double sBearScore = 0;
|
|
|
|
//
|
|
X121MCycleConditions sConditions;
|
|
sMarket.GetMarketConditions(sConditions);
|
|
|
|
//
|
|
sConditions.GenerateScore(
|
|
sBullScore,
|
|
sBearScore //
|
|
);
|
|
|
|
//
|
|
// Medium Market ...
|
|
|
|
//
|
|
double mBullScore = 0;
|
|
double mBearScore = 0;
|
|
|
|
//
|
|
X121MCycleConditions mConditions;
|
|
mMarket.GetMarketConditions(mConditions);
|
|
|
|
//
|
|
mConditions.GenerateScore(
|
|
mBullScore,
|
|
mBearScore //
|
|
);
|
|
|
|
//
|
|
// Long Market ...
|
|
|
|
//
|
|
double lBullScore = 0;
|
|
double lBearScore = 0;
|
|
|
|
//
|
|
X121MCycleConditions lConditions;
|
|
lMarket.GetMarketConditions(lConditions);
|
|
|
|
//
|
|
lConditions.GenerateScore(
|
|
lBullScore,
|
|
lBearScore //
|
|
);
|
|
|
|
//
|
|
// Hind Market ...
|
|
|
|
//
|
|
double hBullScore = 0;
|
|
double hBearScore = 0;
|
|
|
|
//
|
|
X121MCycleConditions hConditions;
|
|
hMarket.GetMarketConditions(hConditions);
|
|
|
|
//
|
|
hConditions.GenerateScore(
|
|
hBullScore,
|
|
hBearScore //
|
|
);
|
|
|
|
//
|
|
double bullishScore = cBullScore +
|
|
sBullScore +
|
|
mBullScore +
|
|
lBullScore +
|
|
hBullScore;
|
|
bullishBuffer[barIndex] = bullishScore;
|
|
|
|
//
|
|
double bearishScore = cBearScore +
|
|
sBearScore +
|
|
mBearScore +
|
|
lBearScore +
|
|
hBearScore;
|
|
bearishBuffer[barIndex] = bearishScore;
|
|
}
|
|
|
|
//
|
|
bool InitCycles()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Define an Input Object and Configure it ...
|
|
// then use same Input for Separate Markets ...
|
|
|
|
//
|
|
string symbol = _Symbol;
|
|
ENUM_TIMEFRAMES period = _Period;
|
|
|
|
//
|
|
// Set Inputs to Default ...
|
|
ccInputs.Default();
|
|
ctInputs.Default();
|
|
zgInputs.Default();
|
|
pvInputs.Default();
|
|
hkInputs.Default();
|
|
mcInputs.Default();
|
|
tdInputs.Default();
|
|
mrbInputs.Default();
|
|
ichInputs.Default();
|
|
cheInputs.Default();
|
|
strInputs.Default();
|
|
donInputs.Default();
|
|
oscInputs.Default();
|
|
|
|
//
|
|
cMarketInputs.Default();
|
|
sMarketInputs.Default();
|
|
mMarketInputs.Default();
|
|
lMarketInputs.Default();
|
|
hMarketInputs.Default();
|
|
|
|
//
|
|
// Current Cycle ...
|
|
|
|
//
|
|
ConfigureCurrentCycles();
|
|
|
|
//
|
|
cMarketInputs.cycle.symbol = symbol;
|
|
cMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
cMarketInputs.pvInputs = pvInputs;
|
|
cMarketInputs.zgInputs = zgInputs;
|
|
cMarketInputs.tdInputs = tdInputs;
|
|
cMarketInputs.mcInputs = mcInputs;
|
|
cMarketInputs.hkInputs = hkInputs;
|
|
cMarketInputs.mrbInputs = mrbInputs;
|
|
cMarketInputs.strInputs = strInputs;
|
|
cMarketInputs.oscInputs = oscInputs;
|
|
cMarketInputs.cheInputs = cheInputs;
|
|
cMarketInputs.ichInputs = ichInputs;
|
|
cMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = cMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_SHORT,
|
|
period,
|
|
X_PERIOD_MANUALLY,
|
|
"HOST",
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
cMarket = new XSCX121Market();
|
|
result = cMarket.Init(cMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle ...
|
|
|
|
//
|
|
ConfigureShortCycles();
|
|
|
|
//
|
|
sMarketInputs.cycle.symbol = symbol;
|
|
sMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
sMarketInputs.pvInputs = pvInputs;
|
|
sMarketInputs.zgInputs = zgInputs;
|
|
sMarketInputs.tdInputs = tdInputs;
|
|
sMarketInputs.mcInputs = mcInputs;
|
|
sMarketInputs.hkInputs = hkInputs;
|
|
sMarketInputs.mrbInputs = mrbInputs;
|
|
sMarketInputs.strInputs = strInputs;
|
|
sMarketInputs.oscInputs = oscInputs;
|
|
sMarketInputs.cheInputs = cheInputs;
|
|
sMarketInputs.ichInputs = ichInputs;
|
|
sMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = sMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_SHORT,
|
|
scPeriod,
|
|
scMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
sMarket = new XSCX121Market();
|
|
result = sMarket.Init(sMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Medium Cycle ...
|
|
|
|
//
|
|
ConfigureMediumCycles();
|
|
|
|
//
|
|
mMarketInputs.cycle.symbol = symbol;
|
|
mMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
mMarketInputs.pvInputs = pvInputs;
|
|
mMarketInputs.zgInputs = zgInputs;
|
|
mMarketInputs.tdInputs = tdInputs;
|
|
mMarketInputs.mcInputs = mcInputs;
|
|
mMarketInputs.hkInputs = hkInputs;
|
|
mMarketInputs.mrbInputs = mrbInputs;
|
|
mMarketInputs.strInputs = strInputs;
|
|
mMarketInputs.oscInputs = oscInputs;
|
|
mMarketInputs.cheInputs = cheInputs;
|
|
mMarketInputs.ichInputs = ichInputs;
|
|
mMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = mMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_MEDIUM,
|
|
mcPeriod,
|
|
mcMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mMarket = new XSCX121Market();
|
|
result = mMarket.Init(mMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Long Cycle ...
|
|
|
|
//
|
|
ConfigureLongCycles();
|
|
|
|
//
|
|
lMarketInputs.cycle.symbol = symbol;
|
|
lMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
lMarketInputs.pvInputs = pvInputs;
|
|
lMarketInputs.zgInputs = zgInputs;
|
|
lMarketInputs.tdInputs = tdInputs;
|
|
lMarketInputs.mcInputs = mcInputs;
|
|
lMarketInputs.hkInputs = hkInputs;
|
|
lMarketInputs.mrbInputs = mrbInputs;
|
|
lMarketInputs.strInputs = strInputs;
|
|
lMarketInputs.oscInputs = oscInputs;
|
|
lMarketInputs.cheInputs = cheInputs;
|
|
lMarketInputs.ichInputs = ichInputs;
|
|
lMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = lMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_MEDIUM,
|
|
lcPeriod,
|
|
lcMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
lMarket = new XSCX121Market();
|
|
result = lMarket.Init(lMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Hind Cycle ...
|
|
|
|
//
|
|
ConfigureHindCycles();
|
|
|
|
//
|
|
hMarketInputs.cycle.symbol = symbol;
|
|
hMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
hMarketInputs.pvInputs = pvInputs;
|
|
hMarketInputs.zgInputs = zgInputs;
|
|
hMarketInputs.tdInputs = tdInputs;
|
|
hMarketInputs.mcInputs = mcInputs;
|
|
hMarketInputs.hkInputs = hkInputs;
|
|
hMarketInputs.mrbInputs = mrbInputs;
|
|
hMarketInputs.strInputs = strInputs;
|
|
hMarketInputs.oscInputs = oscInputs;
|
|
hMarketInputs.cheInputs = cheInputs;
|
|
hMarketInputs.ichInputs = ichInputs;
|
|
hMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = hMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_MEDIUM,
|
|
hcPeriod,
|
|
hcMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
hMarket = new XSCX121Market();
|
|
result = hMarket.Init(hMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void ConfigureCurrentCycles() {}
|
|
|
|
//
|
|
void ConfigureShortCycles() {}
|
|
|
|
//
|
|
void ConfigureMediumCycles() {}
|
|
|
|
//
|
|
void ConfigureLongCycles() {}
|
|
|
|
//
|
|
void ConfigureHindCycles() {}
|
|
|
|
// |