last works ...
This commit is contained in:
Vendored
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
},
|
},
|
||||||
"creation_time": "2024-07-28T22:48:10.644Z",
|
"creation_time": "2024-07-28T22:48:10.644Z",
|
||||||
"details": {
|
"details": {
|
||||||
"content": "[] Add Recovery Options when try to Synchronize Positions Using Trade Handler ...\n[] Add Do not Trail Support or Recovery Positions in Trade Handler ...\n[] Add a TP and SL to Recovery Position ...\n[] Made Multi Asset ...\n[] Add Pressure Based Trailling ...\n[] Add Support for Pressures in Recovery ...\n[] Add OB / FVG and Other things Like XPV Signalling ...\n[] Create XCHCHE Insicator and it's Helper class ...\n",
|
"content": "[] Add Recovery Options when try to Synchronize Positions Using Trade Handler ...\n[x] Add Do not Trail Support or Recovery Positions in Trade Handler ...\n[x] Add a TP and SL to Recovery Position ...\n[x] Made Multi Asset ...\n[] Add Pressure Based Trailling ...\n[x] Add Support for Pressures in Recovery ...\n[] Add OB / FVG and Other things Like XPV Signalling ...\n[x] Create XCHCHE Insicator and it's Helper class ...\n[] Create XCHVLM. XCHTD ...\n",
|
||||||
"mime": "text/markdown"
|
"mime": "text/markdown"
|
||||||
},
|
},
|
||||||
"id": "86",
|
"id": "86",
|
||||||
|
|||||||
@@ -5640,21 +5640,60 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
bool FixRecoveredPositionTPSL(XPosition &osition)
|
bool FixRecoveredPositionTPSL(XPosition &position)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Try to Remove SL of Recovery Signals ...
|
result = position.IsValid();
|
||||||
if (osition.sl > 0 || osition.tp > 0)
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double points = GetPoints(position.symbol);
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Try to Remove SL and TP of Recovery Signals ...
|
||||||
|
// if (position.sl > 0 || position.tp > 0)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// string comment = "EQM Recover Remove TP/SL";
|
||||||
|
// result = mTrader.Modify(
|
||||||
|
// position.ticket,
|
||||||
|
// 0,
|
||||||
|
// 0,
|
||||||
|
// comment //
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try to Remove TP of Recovery Signals ...
|
||||||
|
if (position.tp > 0)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
string comment = "EQM Recover Remove TP/SL";
|
double tp = 0;
|
||||||
|
bool isLong = IsLong(position.type);
|
||||||
|
double reward = MathAbs(position.tp - position.entry) / points;
|
||||||
|
if (reward <= mRecoveryTPPoint)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
reward = (mRecoveryTPPoint * 2 * points);
|
||||||
|
tp =
|
||||||
|
isLong
|
||||||
|
? position.entry + reward
|
||||||
|
: position.entry - reward;
|
||||||
|
tp = NormalizePrice(tp, position.symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string comment = "EQM Recover Fix TP/SL";
|
||||||
result = mTrader.Modify(
|
result = mTrader.Modify(
|
||||||
osition.ticket,
|
position.ticket,
|
||||||
0,
|
position.sl,
|
||||||
0,
|
tp,
|
||||||
comment //
|
comment //
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,10 @@ bool eaIgnoreSL = false; // Ignore SL
|
|||||||
double eaR2R = 1.5; // Risk to Reward Ratio
|
double eaR2R = 1.5; // Risk to Reward Ratio
|
||||||
|
|
||||||
//
|
//
|
||||||
bool eaMultiSymbol = false; // Use Multi Symbol
|
bool eaMultiSymbol = true; // Use Multi Symbol
|
||||||
bool eaUseMaxAllowedTradesPerSymbol = true; // Use Max Allowed Trades Per Symbol
|
bool eaUseMaxAllowedTradesPerSymbol = true; // Use Max Allowed Trades Per Symbol
|
||||||
string eaSymbols = "EURUSDb,USDJPYb,USDCHFb,GBPUSDb,XAUUSDb,XAGUSDb"; // Trading Symbols
|
string eaSymbols = "EURUSDb,USDJPYb"; // Trading Symbols
|
||||||
|
// string eaSymbols = "EURUSDb,USDJPYb,USDCHFb,GBPUSDb,XAUUSDb,XAGUSDb"; // Trading Symbols
|
||||||
|
|
||||||
//
|
//
|
||||||
// Variables ...
|
// Variables ...
|
||||||
@@ -82,13 +83,14 @@ XSCBaseStrategy *strategies[];
|
|||||||
// Trader Instance Class ...
|
// Trader Instance Class ...
|
||||||
XSCTrade *eaTrader;
|
XSCTrade *eaTrader;
|
||||||
|
|
||||||
//
|
|
||||||
// XTimeTracker eaTimeTracker;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Alert Class ...
|
// Alert Class ...
|
||||||
XSCAlert *eaAlert;
|
XSCAlert *eaAlert;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Time Tracker ...
|
||||||
|
XTimeTracker eaTimeTracker;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trade Handler Instance Class ...
|
// Trade Handler Instance Class ...
|
||||||
XSCXTradeHandler *eaTradeHandler;
|
XSCXTradeHandler *eaTradeHandler;
|
||||||
@@ -167,6 +169,7 @@ void OnTick()
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
HandleTradeState();
|
HandleTradeState();
|
||||||
|
HandleTimeReport();
|
||||||
HandleStrategiesOnTick();
|
HandleStrategiesOnTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +186,8 @@ void OnTimer()
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// HandleTradeState();
|
// HandleTradeState();
|
||||||
|
// HandleTimeReport();
|
||||||
|
// HandleStrategiesOnTick();
|
||||||
|
|
||||||
// //
|
// //
|
||||||
// if (eaTimeTracker.IsNewDay())
|
// if (eaTimeTracker.IsNewDay())
|
||||||
@@ -269,7 +274,7 @@ bool InitialEA()
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Configure Hedging ...
|
// Configure Hedging ...
|
||||||
eaTradeHandler.AllowHedging(false);
|
eaTradeHandler.AllowHedging(true);
|
||||||
eaTradeHandler.HedgeVolumeFactor(eaVolume);
|
eaTradeHandler.HedgeVolumeFactor(eaVolume);
|
||||||
eaTradeHandler.OnlyHedgeSupportedPositions(false);
|
eaTradeHandler.OnlyHedgeSupportedPositions(false);
|
||||||
eaTradeHandler.HedgeMinProfitPerVolumeFactor(0.3);
|
eaTradeHandler.HedgeMinProfitPerVolumeFactor(0.3);
|
||||||
@@ -444,6 +449,21 @@ void HandleTradeState()
|
|||||||
eaTradeHandler.HandleProtection();
|
eaTradeHandler.HandleProtection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Time Reporting ...
|
||||||
|
void HandleTimeReport()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (eaTimeTracker.IsNewDay())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string msg = "New Day ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
eaAlert.Alert(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// All Signals from Strategies Comming Here for Execution or
|
// All Signals from Strategies Comming Here for Execution or
|
||||||
// Analyzing ...
|
// Analyzing ...
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,898 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
// SaherElm IT Center MQL5 Indicator
|
||||||
|
// -------------------------------------------
|
||||||
|
// Name: XCHTD
|
||||||
|
// Description: XCHTD Cycles ...
|
||||||
|
//
|
||||||
|
// 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 XCHTD Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
#define ShortName "XCHTD"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
enum ENUM_XCHTD_MODE
|
||||||
|
{
|
||||||
|
XCHTD_POWER_MODE = 0, // Using Power
|
||||||
|
XCHTD_PRESSURE_MODE = 1, // Using Pressure
|
||||||
|
XCHTD_TYPE_MODE = 2, // Using Type
|
||||||
|
XCHTD_STRONG_MODE = 3, // Using Power and Pressures
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Market";
|
||||||
|
input int length = 14; // Length
|
||||||
|
input ENUM_XCHTD_MODE mode = XCHTD_POWER_MODE; // Mode
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Cycles";
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Short";
|
||||||
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Medium";
|
||||||
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Long";
|
||||||
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Hind";
|
||||||
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
input group "Presentation";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
input bool showCurrent = true; // Show Current Cycle
|
||||||
|
input bool showShort = true; // Show Short Cycle
|
||||||
|
input bool showMedium = true; // Show Medium Cycle
|
||||||
|
input bool showLong = true; // Show Long Cycle
|
||||||
|
input bool showHind = true; // Show Hind Cycle
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 10
|
||||||
|
#property indicator_plots 10
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cBullBufferIndex 0
|
||||||
|
double cBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label1 "XCHTD C Bull"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrLime
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cBearBufferIndex 1
|
||||||
|
double cBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label2 "XCHTD C Bear"
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_style2 STYLE_SOLID
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sBullBufferIndex 2
|
||||||
|
double sBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label3 "XCHTD S Bull"
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrLime
|
||||||
|
#property indicator_style3 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sBearBufferIndex 3
|
||||||
|
double sBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label4 "XCHTD S Bear"
|
||||||
|
#property indicator_type4 DRAW_LINE
|
||||||
|
#property indicator_style4 STYLE_SOLID
|
||||||
|
#property indicator_color4 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mBullBufferIndex 4
|
||||||
|
double mBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label5 "XCHTD M Bull"
|
||||||
|
#property indicator_type5 DRAW_LINE
|
||||||
|
#property indicator_color5 clrLime
|
||||||
|
#property indicator_style5 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mBearBufferIndex 5
|
||||||
|
double mBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label6 "XCHTD M Bear"
|
||||||
|
#property indicator_type6 DRAW_LINE
|
||||||
|
#property indicator_style6 STYLE_SOLID
|
||||||
|
#property indicator_color6 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lBullBufferIndex 6
|
||||||
|
double lBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label7 "XCHTD L Bull"
|
||||||
|
#property indicator_type7 DRAW_LINE
|
||||||
|
#property indicator_color7 clrLime
|
||||||
|
#property indicator_style7 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lBearBufferIndex 7
|
||||||
|
double lBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label8 "XCHTD L Bear"
|
||||||
|
#property indicator_type8 DRAW_LINE
|
||||||
|
#property indicator_style8 STYLE_SOLID
|
||||||
|
#property indicator_color8 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hBullBufferIndex 8
|
||||||
|
double hBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label9 "XCHTD H Bull"
|
||||||
|
#property indicator_type9 DRAW_LINE
|
||||||
|
#property indicator_color9 clrLime
|
||||||
|
#property indicator_style9 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hBearBufferIndex 9
|
||||||
|
double hBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label10 "XCHTD H Bear"
|
||||||
|
#property indicator_type10 DRAW_LINE
|
||||||
|
#property indicator_style10 STYLE_SOLID
|
||||||
|
#property indicator_color10 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Variables, Properties and etc ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int maxLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
int mCMarketLength = length;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
int mSCycleLength = 0;
|
||||||
|
int mSMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
int mMCycleLength = 0;
|
||||||
|
int mMMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
int mLCycleLength = 0;
|
||||||
|
int mLMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
int mHCycleLength = 0;
|
||||||
|
int mHMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Event Handlers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!InitMarketCycles())
|
||||||
|
{
|
||||||
|
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(
|
||||||
|
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;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 ...
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateBuffers(
|
||||||
|
i,
|
||||||
|
prev_calculated,
|
||||||
|
rates_total,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tick_volume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Functions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
length >= 2 &&
|
||||||
|
//
|
||||||
|
(IsValid(scMethod, scPeriod) &&
|
||||||
|
IsValid(mcMethod, mcPeriod) &&
|
||||||
|
IsValid(lcMethod, lcPeriod) &&
|
||||||
|
IsValid(hcMethod, hcPeriod))
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Market Cycles ...
|
||||||
|
bool InitMarketCycles()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (scMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mSCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_SHORT,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSCPeriod = scPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mSCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||||
|
mSMarketLength = mSCycleLength * mCMarketLength;
|
||||||
|
result = mSCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (mcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mMCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_MEDIUM,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mMCPeriod = mcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mMCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||||
|
mMMarketLength = mMCycleLength * mCMarketLength;
|
||||||
|
result = mMCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (lcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mLCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_LONG,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mLCPeriod = lcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mLCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||||
|
mLMarketLength = mLCycleLength * mCMarketLength;
|
||||||
|
result = mLCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (hcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mHCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_HIND,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mHCPeriod = hcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mHCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||||
|
mHMarketLength = mHCycleLength * mCMarketLength;
|
||||||
|
result = mHCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve all Exists Input Max Length ...
|
||||||
|
// use for Start Of Drawing ...
|
||||||
|
int ExtractMaxLengthOfInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = MathMax(mCMarketLength, mSMarketLength);
|
||||||
|
result = MathMax(result, mMMarketLength);
|
||||||
|
result = MathMax(result, mLMarketLength);
|
||||||
|
result = MathMax(result, mHMarketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(cBullBuffer, true);
|
||||||
|
SetIndexBuffer(cBullBufferIndex, cBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(cBullBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||||
|
PlotIndexSetInteger(cBullBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(cBearBuffer, true);
|
||||||
|
SetIndexBuffer(cBearBufferIndex, cBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(cBearBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||||
|
PlotIndexSetInteger(cBearBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(sBullBuffer, true);
|
||||||
|
SetIndexBuffer(sBullBufferIndex, sBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(sBullBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||||
|
PlotIndexSetInteger(sBullBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(sBearBuffer, true);
|
||||||
|
SetIndexBuffer(sBearBufferIndex, sBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(sBearBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||||
|
PlotIndexSetInteger(sBearBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(mBullBuffer, true);
|
||||||
|
SetIndexBuffer(mBullBufferIndex, mBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(mBullBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||||
|
PlotIndexSetInteger(mBullBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(mBearBuffer, true);
|
||||||
|
SetIndexBuffer(mBearBufferIndex, mBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(mBearBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||||
|
PlotIndexSetInteger(mBearBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(lBullBuffer, true);
|
||||||
|
SetIndexBuffer(lBullBufferIndex, lBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(lBullBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||||
|
PlotIndexSetInteger(lBullBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(lBearBuffer, true);
|
||||||
|
SetIndexBuffer(lBearBufferIndex, lBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(lBearBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||||
|
PlotIndexSetInteger(lBearBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(hBullBuffer, true);
|
||||||
|
SetIndexBuffer(hBullBufferIndex, hBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(hBullBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||||
|
PlotIndexSetInteger(hBullBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(hBearBuffer, true);
|
||||||
|
SetIndexBuffer(hBearBufferIndex, hBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(hBearBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||||
|
PlotIndexSetInteger(hBearBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateCycles(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycles(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// CURRENT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mCMarketLength,
|
||||||
|
showCurrent,
|
||||||
|
cBullBuffer,
|
||||||
|
cBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SHORT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mSMarketLength,
|
||||||
|
showShort,
|
||||||
|
sBullBuffer,
|
||||||
|
sBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// MEDIUM ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mMMarketLength,
|
||||||
|
showMedium,
|
||||||
|
mBullBuffer,
|
||||||
|
mBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// LONG ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mLMarketLength,
|
||||||
|
showLong,
|
||||||
|
lBullBuffer,
|
||||||
|
lBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// HIND ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mHMarketLength,
|
||||||
|
showHind,
|
||||||
|
hBullBuffer,
|
||||||
|
hBearBuffer //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycle(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[],
|
||||||
|
//
|
||||||
|
int _length, // Calculation Length
|
||||||
|
bool _show,
|
||||||
|
double &_bull[],
|
||||||
|
double &_bear[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double bullPower = 0;
|
||||||
|
double bearPower = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
double lowShadow = 0;
|
||||||
|
double highShadow = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
double bullPressure = 0;
|
||||||
|
double bearPressure = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
double bullRange = 0;
|
||||||
|
double bearRange = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = bar_index; i < bar_index + _length; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool isBullish =
|
||||||
|
//
|
||||||
|
close[i] > open[i]
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isBearish =
|
||||||
|
//
|
||||||
|
close[i] < open[i]
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
double iUpper = MathMax(open[i], close[i]);
|
||||||
|
double iLower = MathMin(open[i], close[i]);
|
||||||
|
|
||||||
|
//
|
||||||
|
double iBody = iUpper - iLower;
|
||||||
|
double iRange = high[i] - low[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
double iHighShadow = high[i] - iUpper;
|
||||||
|
double iLowShadow = iLower - low[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isBullish)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bullPower += iBody;
|
||||||
|
bullRange += iRange;
|
||||||
|
bearPressure += iHighShadow;
|
||||||
|
}
|
||||||
|
else if (isBearish)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bearPower += iBody;
|
||||||
|
bearRange += iRange;
|
||||||
|
bullPressure += iLowShadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
lowShadow += iLowShadow;
|
||||||
|
highShadow += iHighShadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (mode == XCHTD_POWER_MODE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullPower;
|
||||||
|
_bear[bar_index] = bearPower;
|
||||||
|
}
|
||||||
|
else if (mode == XCHTD_PRESSURE_MODE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullPressure;
|
||||||
|
_bear[bar_index] = bearPressure;
|
||||||
|
}
|
||||||
|
else if (mode == XCHTD_TYPE_MODE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullRange;
|
||||||
|
_bear[bar_index] = bearRange;
|
||||||
|
} else if (mode == XCHTD_STRONG_MODE) {
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullPower + bullPressure;
|
||||||
|
_bear[bar_index] = bearPower + bearPressure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
@@ -0,0 +1,898 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
// SaherElm IT Center MQL5 Indicator
|
||||||
|
// -------------------------------------------
|
||||||
|
// Name: XCHTD
|
||||||
|
// Description: XCHTD Cycles ...
|
||||||
|
//
|
||||||
|
// 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 XCHTD Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
#define ShortName "XCHTD"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
enum ENUM_XCHTD_MODE
|
||||||
|
{
|
||||||
|
XCHTD_POWER_MODE = 0, // Using Power
|
||||||
|
XCHTD_PRESSURE_MODE = 1, // Using Pressure
|
||||||
|
XCHTD_TYPE_MODE = 2, // Using Type
|
||||||
|
XCHTD_STRONG_MODE = 3, // Using Power and Pressures
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Market";
|
||||||
|
input int length = 14; // Length
|
||||||
|
input ENUM_XCHTD_MODE mode = XCHTD_POWER_MODE; // Mode
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Cycles";
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Short";
|
||||||
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Medium";
|
||||||
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Long";
|
||||||
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Hind";
|
||||||
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
input group "Presentation";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
input bool showCurrent = true; // Show Current Cycle
|
||||||
|
input bool showShort = true; // Show Short Cycle
|
||||||
|
input bool showMedium = true; // Show Medium Cycle
|
||||||
|
input bool showLong = true; // Show Long Cycle
|
||||||
|
input bool showHind = true; // Show Hind Cycle
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 10
|
||||||
|
#property indicator_plots 10
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cBullBufferIndex 0
|
||||||
|
double cBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label1 "XCHTD C Bull"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrLime
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cBearBufferIndex 1
|
||||||
|
double cBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label2 "XCHTD C Bear"
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_style2 STYLE_SOLID
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sBullBufferIndex 2
|
||||||
|
double sBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label3 "XCHTD S Bull"
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrLime
|
||||||
|
#property indicator_style3 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sBearBufferIndex 3
|
||||||
|
double sBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label4 "XCHTD S Bear"
|
||||||
|
#property indicator_type4 DRAW_LINE
|
||||||
|
#property indicator_style4 STYLE_SOLID
|
||||||
|
#property indicator_color4 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mBullBufferIndex 4
|
||||||
|
double mBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label5 "XCHTD M Bull"
|
||||||
|
#property indicator_type5 DRAW_LINE
|
||||||
|
#property indicator_color5 clrLime
|
||||||
|
#property indicator_style5 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mBearBufferIndex 5
|
||||||
|
double mBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label6 "XCHTD M Bear"
|
||||||
|
#property indicator_type6 DRAW_LINE
|
||||||
|
#property indicator_style6 STYLE_SOLID
|
||||||
|
#property indicator_color6 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lBullBufferIndex 6
|
||||||
|
double lBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label7 "XCHTD L Bull"
|
||||||
|
#property indicator_type7 DRAW_LINE
|
||||||
|
#property indicator_color7 clrLime
|
||||||
|
#property indicator_style7 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lBearBufferIndex 7
|
||||||
|
double lBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label8 "XCHTD L Bear"
|
||||||
|
#property indicator_type8 DRAW_LINE
|
||||||
|
#property indicator_style8 STYLE_SOLID
|
||||||
|
#property indicator_color8 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hBullBufferIndex 8
|
||||||
|
double hBullBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label9 "XCHTD H Bull"
|
||||||
|
#property indicator_type9 DRAW_LINE
|
||||||
|
#property indicator_color9 clrLime
|
||||||
|
#property indicator_style9 STYLE_SOLID
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hBearBufferIndex 9
|
||||||
|
double hBearBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label10 "XCHTD H Bear"
|
||||||
|
#property indicator_type10 DRAW_LINE
|
||||||
|
#property indicator_style10 STYLE_SOLID
|
||||||
|
#property indicator_color10 clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Variables, Properties and etc ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int maxLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
int mCMarketLength = length;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
int mSCycleLength = 0;
|
||||||
|
int mSMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
int mMCycleLength = 0;
|
||||||
|
int mMMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
int mLCycleLength = 0;
|
||||||
|
int mLMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
int mHCycleLength = 0;
|
||||||
|
int mHMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Event Handlers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!InitMarketCycles())
|
||||||
|
{
|
||||||
|
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(
|
||||||
|
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;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 ...
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateBuffers(
|
||||||
|
i,
|
||||||
|
prev_calculated,
|
||||||
|
rates_total,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tick_volume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Functions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
length >= 2 &&
|
||||||
|
//
|
||||||
|
(IsValid(scMethod, scPeriod) &&
|
||||||
|
IsValid(mcMethod, mcPeriod) &&
|
||||||
|
IsValid(lcMethod, lcPeriod) &&
|
||||||
|
IsValid(hcMethod, hcPeriod))
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Market Cycles ...
|
||||||
|
bool InitMarketCycles()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (scMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mSCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_SHORT,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSCPeriod = scPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mSCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||||
|
mSMarketLength = mSCycleLength * mCMarketLength;
|
||||||
|
result = mSCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (mcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mMCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_MEDIUM,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mMCPeriod = mcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mMCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||||
|
mMMarketLength = mMCycleLength * mCMarketLength;
|
||||||
|
result = mMCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (lcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mLCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_LONG,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mLCPeriod = lcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mLCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||||
|
mLMarketLength = mLCycleLength * mCMarketLength;
|
||||||
|
result = mLCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (hcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mHCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_HIND,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mHCPeriod = hcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mHCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||||
|
mHMarketLength = mHCycleLength * mCMarketLength;
|
||||||
|
result = mHCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve all Exists Input Max Length ...
|
||||||
|
// use for Start Of Drawing ...
|
||||||
|
int ExtractMaxLengthOfInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = MathMax(mCMarketLength, mSMarketLength);
|
||||||
|
result = MathMax(result, mMMarketLength);
|
||||||
|
result = MathMax(result, mLMarketLength);
|
||||||
|
result = MathMax(result, mHMarketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(cBullBuffer, true);
|
||||||
|
SetIndexBuffer(cBullBufferIndex, cBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(cBullBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||||
|
PlotIndexSetInteger(cBullBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(cBearBuffer, true);
|
||||||
|
SetIndexBuffer(cBearBufferIndex, cBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(cBearBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||||
|
PlotIndexSetInteger(cBearBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(sBullBuffer, true);
|
||||||
|
SetIndexBuffer(sBullBufferIndex, sBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(sBullBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||||
|
PlotIndexSetInteger(sBullBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(sBearBuffer, true);
|
||||||
|
SetIndexBuffer(sBearBufferIndex, sBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(sBearBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||||
|
PlotIndexSetInteger(sBearBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(mBullBuffer, true);
|
||||||
|
SetIndexBuffer(mBullBufferIndex, mBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(mBullBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||||
|
PlotIndexSetInteger(mBullBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(mBearBuffer, true);
|
||||||
|
SetIndexBuffer(mBearBufferIndex, mBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(mBearBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||||
|
PlotIndexSetInteger(mBearBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(lBullBuffer, true);
|
||||||
|
SetIndexBuffer(lBullBufferIndex, lBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(lBullBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||||
|
PlotIndexSetInteger(lBullBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(lBearBuffer, true);
|
||||||
|
SetIndexBuffer(lBearBufferIndex, lBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(lBearBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||||
|
PlotIndexSetInteger(lBearBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_LINE : DRAW_NONE;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(hBullBuffer, true);
|
||||||
|
SetIndexBuffer(hBullBufferIndex, hBullBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(hBullBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||||
|
PlotIndexSetInteger(hBullBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||||
|
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(hBearBuffer, true);
|
||||||
|
SetIndexBuffer(hBearBufferIndex, hBearBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(hBearBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||||
|
PlotIndexSetInteger(hBearBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateCycles(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycles(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// CURRENT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mCMarketLength,
|
||||||
|
showCurrent,
|
||||||
|
cBullBuffer,
|
||||||
|
cBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SHORT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mSMarketLength,
|
||||||
|
showShort,
|
||||||
|
sBullBuffer,
|
||||||
|
sBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// MEDIUM ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mMMarketLength,
|
||||||
|
showMedium,
|
||||||
|
mBullBuffer,
|
||||||
|
mBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// LONG ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mLMarketLength,
|
||||||
|
showLong,
|
||||||
|
lBullBuffer,
|
||||||
|
lBearBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// HIND ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mHMarketLength,
|
||||||
|
showHind,
|
||||||
|
hBullBuffer,
|
||||||
|
hBearBuffer //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycle(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[],
|
||||||
|
//
|
||||||
|
int _length, // Calculation Length
|
||||||
|
bool _show,
|
||||||
|
double &_bull[],
|
||||||
|
double &_bear[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double bullPower = 0;
|
||||||
|
double bearPower = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
double lowShadow = 0;
|
||||||
|
double highShadow = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
double bullPressure = 0;
|
||||||
|
double bearPressure = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
double bullRange = 0;
|
||||||
|
double bearRange = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = bar_index; i < bar_index + _length; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool isBullish =
|
||||||
|
//
|
||||||
|
close[i] > open[i]
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isBearish =
|
||||||
|
//
|
||||||
|
close[i] < open[i]
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
double iUpper = MathMax(open[i], close[i]);
|
||||||
|
double iLower = MathMin(open[i], close[i]);
|
||||||
|
|
||||||
|
//
|
||||||
|
double iBody = iUpper - iLower;
|
||||||
|
double iRange = high[i] - low[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
double iHighShadow = high[i] - iUpper;
|
||||||
|
double iLowShadow = iLower - low[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isBullish)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bullPower += iBody;
|
||||||
|
bullRange += iRange;
|
||||||
|
bearPressure += iHighShadow;
|
||||||
|
}
|
||||||
|
else if (isBearish)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bearPower += iBody;
|
||||||
|
bearRange += iRange;
|
||||||
|
bullPressure += iLowShadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
lowShadow += iLowShadow;
|
||||||
|
highShadow += iHighShadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (mode == XCHTD_POWER_MODE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullPower;
|
||||||
|
_bear[bar_index] = bearPower;
|
||||||
|
}
|
||||||
|
else if (mode == XCHTD_PRESSURE_MODE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullPressure;
|
||||||
|
_bear[bar_index] = bearPressure;
|
||||||
|
}
|
||||||
|
else if (mode == XCHTD_TYPE_MODE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullRange;
|
||||||
|
_bear[bar_index] = bearRange;
|
||||||
|
} else if (mode == XCHTD_STRONG_MODE) {
|
||||||
|
//
|
||||||
|
_bull[bar_index] = bullPower + bullPressure;
|
||||||
|
_bear[bar_index] = bearPower + bearPressure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
@@ -0,0 +1,810 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
// SaherElm IT Center MQL5 Indicator
|
||||||
|
// -------------------------------------------
|
||||||
|
// Name: XCHVLM
|
||||||
|
// Description: XCHVLM Cycles ...
|
||||||
|
//
|
||||||
|
// 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 XCHVLM Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
#define ShortName "XCHVLM"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include <Math/Stat/Normal.mqh>
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Market";
|
||||||
|
input int length = 14; // Length
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Cycles";
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Short";
|
||||||
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Medium";
|
||||||
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Long";
|
||||||
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Hind";
|
||||||
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
input group "Presentation";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
input bool showCurrent = true; // Show Current Cycle
|
||||||
|
input bool showShort = true; // Show Short Cycle
|
||||||
|
input bool showMedium = true; // Show Medium Cycle
|
||||||
|
input bool showLong = true; // Show Long Cycle
|
||||||
|
input bool showHind = true; // Show Hind Cycle
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hideColorIDX 0
|
||||||
|
#define bullishColorIDX 1
|
||||||
|
#define bearishColorIDX 2
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 10
|
||||||
|
#property indicator_plots 10
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cBufferIndex 0
|
||||||
|
double cBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cColorBufferIndex 1
|
||||||
|
double cColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cPlotBufferIndex 0
|
||||||
|
#property indicator_label1 "XCHVLM C"
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color1 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sBufferIndex 2
|
||||||
|
double sBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sColorBufferIndex 3
|
||||||
|
double sColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sPlotBufferIndex 1
|
||||||
|
#property indicator_label2 "XCHVLM S"
|
||||||
|
#property indicator_style2 STYLE_SOLID
|
||||||
|
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color2 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mBufferIndex 4
|
||||||
|
double mBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mColorBufferIndex 5
|
||||||
|
double mColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mPlotBufferIndex 2
|
||||||
|
#property indicator_label3 "XCHVLM M"
|
||||||
|
#property indicator_style3 STYLE_SOLID
|
||||||
|
#property indicator_type3 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color3 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lBufferIndex 6
|
||||||
|
double lBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lColorBufferIndex 7
|
||||||
|
double lColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lPlotBufferIndex 3
|
||||||
|
#property indicator_label4 "XCHVLM L"
|
||||||
|
#property indicator_style4 STYLE_SOLID
|
||||||
|
#property indicator_type4 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color4 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hBufferIndex 8
|
||||||
|
double hBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hColorBufferIndex 9
|
||||||
|
double hColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hPlotBufferIndex 4
|
||||||
|
#property indicator_label5 "XCHVLM H"
|
||||||
|
#property indicator_style5 STYLE_SOLID
|
||||||
|
#property indicator_type5 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color5 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Variables, Properties and etc ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int maxLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
int mCMarketLength = length;
|
||||||
|
double cVolumes[];
|
||||||
|
double cDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
int mSCycleLength = 0;
|
||||||
|
int mSMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||||
|
double sVolumes[];
|
||||||
|
double sDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
int mMCycleLength = 0;
|
||||||
|
int mMMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||||
|
double mVolumes[];
|
||||||
|
double mDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
int mLCycleLength = 0;
|
||||||
|
int mLMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||||
|
double lVolumes[];
|
||||||
|
double lDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
int mHCycleLength = 0;
|
||||||
|
int mHMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||||
|
double hVolumes[];
|
||||||
|
double hDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Event Handlers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!InitMarketCycles())
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
ArrayResize(cVolumes, maxLength, 0);
|
||||||
|
ArrayResize(cDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
ArrayResize(sVolumes, maxLength, 0);
|
||||||
|
ArrayResize(sDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
ArrayResize(mVolumes, maxLength, 0);
|
||||||
|
ArrayResize(mDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
ArrayResize(lVolumes, maxLength, 0);
|
||||||
|
ArrayResize(lDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
ArrayResize(hVolumes, maxLength, 0);
|
||||||
|
ArrayResize(hDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(cVolumes);
|
||||||
|
Clean(cDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(sVolumes);
|
||||||
|
Clean(sDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(mVolumes);
|
||||||
|
Clean(mDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(lVolumes);
|
||||||
|
Clean(lDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(hVolumes);
|
||||||
|
Clean(hDistances);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
static int i = maxLength * 2;
|
||||||
|
for (i; i < rates_total; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateBuffers(
|
||||||
|
i,
|
||||||
|
prev_calculated,
|
||||||
|
rates_total,
|
||||||
|
//
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tick_volume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
i = rates_total - 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Functions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
length >= 2 &&
|
||||||
|
//
|
||||||
|
(IsValid(scMethod, scPeriod) &&
|
||||||
|
IsValid(mcMethod, mcPeriod) &&
|
||||||
|
IsValid(lcMethod, lcPeriod) &&
|
||||||
|
IsValid(hcMethod, hcPeriod))
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Market Cycles ...
|
||||||
|
bool InitMarketCycles()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (scMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mSCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_SHORT,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSCPeriod = scPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mSCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||||
|
mSMarketLength = mSCycleLength * mCMarketLength;
|
||||||
|
result = mSCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (mcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mMCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_MEDIUM,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mMCPeriod = mcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mMCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||||
|
mMMarketLength = mMCycleLength * mCMarketLength;
|
||||||
|
result = mMCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (lcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mLCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_LONG,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mLCPeriod = lcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mLCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||||
|
mLMarketLength = mLCycleLength * mCMarketLength;
|
||||||
|
result = mLCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (hcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mHCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_HIND,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mHCPeriod = hcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mHCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||||
|
mHMarketLength = mHCycleLength * mCMarketLength;
|
||||||
|
result = mHCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve all Exists Input Max Length ...
|
||||||
|
// use for Start Of Drawing ...
|
||||||
|
int ExtractMaxLengthOfInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = MathMax(mCMarketLength, mSMarketLength);
|
||||||
|
result = MathMax(result, mMMarketLength);
|
||||||
|
result = MathMax(result, mLMarketLength);
|
||||||
|
result = MathMax(result, mHMarketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(cPlotBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||||
|
SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(sPlotBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||||
|
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(mPlotBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||||
|
SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(lPlotBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||||
|
SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(hPlotBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||||
|
PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateCycles(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycles(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// CURRENT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mCMarketLength,
|
||||||
|
showCurrent,
|
||||||
|
cVolumes,
|
||||||
|
cDistances,
|
||||||
|
cBuffer,
|
||||||
|
cColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SHORT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mSMarketLength,
|
||||||
|
showShort,
|
||||||
|
sVolumes,
|
||||||
|
sDistances,
|
||||||
|
sBuffer,
|
||||||
|
sColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// MEDIUM ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mMMarketLength,
|
||||||
|
showMedium,
|
||||||
|
mVolumes,
|
||||||
|
mDistances,
|
||||||
|
mBuffer,
|
||||||
|
mColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// LONG ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mLMarketLength,
|
||||||
|
showLong,
|
||||||
|
lVolumes,
|
||||||
|
lDistances,
|
||||||
|
lBuffer,
|
||||||
|
lColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// HIND ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mHMarketLength,
|
||||||
|
showHind,
|
||||||
|
hVolumes,
|
||||||
|
hDistances,
|
||||||
|
hBuffer,
|
||||||
|
hColorBuffer //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycle(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[],
|
||||||
|
//
|
||||||
|
int _length, // Calculation Length
|
||||||
|
bool _show,
|
||||||
|
double &_volumes[],
|
||||||
|
double &_distances[],
|
||||||
|
double &_buffer[],
|
||||||
|
double &_colorBuffer[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
for (int x = 0; x < _length; x++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_volumes[x] = (double)tickVolume[bar_index - x];
|
||||||
|
_distances[x] =
|
||||||
|
(close[bar_index - x] > open[bar_index - x])
|
||||||
|
? high[bar_index - x] - low[bar_index - x]
|
||||||
|
: low[bar_index - x] - high[bar_index - x];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double iValue = MathMean(_volumes) * MathMean(_distances);
|
||||||
|
|
||||||
|
//
|
||||||
|
_buffer[bar_index] = iValue;
|
||||||
|
_colorBuffer[bar_index] = iValue > 0
|
||||||
|
? _show
|
||||||
|
? bullishColorIDX
|
||||||
|
: hideColorIDX
|
||||||
|
: _show
|
||||||
|
? bearishColorIDX
|
||||||
|
: hideColorIDX;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
@@ -0,0 +1,810 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
// SaherElm IT Center MQL5 Indicator
|
||||||
|
// -------------------------------------------
|
||||||
|
// Name: XCHVLM
|
||||||
|
// Description: XCHVLM Cycles ...
|
||||||
|
//
|
||||||
|
// 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 XCHVLM Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
#define ShortName "XCHVLM"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include <Math/Stat/Normal.mqh>
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Market";
|
||||||
|
input int length = 14; // Length
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Cycles";
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Short";
|
||||||
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Medium";
|
||||||
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Long";
|
||||||
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Hind";
|
||||||
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
|
||||||
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
input group "Presentation";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
input bool showCurrent = true; // Show Current Cycle
|
||||||
|
input bool showShort = true; // Show Short Cycle
|
||||||
|
input bool showMedium = true; // Show Medium Cycle
|
||||||
|
input bool showLong = true; // Show Long Cycle
|
||||||
|
input bool showHind = true; // Show Hind Cycle
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hideColorIDX 0
|
||||||
|
#define bullishColorIDX 1
|
||||||
|
#define bearishColorIDX 2
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 10
|
||||||
|
#property indicator_plots 10
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cBufferIndex 0
|
||||||
|
double cBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cColorBufferIndex 1
|
||||||
|
double cColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define cPlotBufferIndex 0
|
||||||
|
#property indicator_label1 "XCHVLM C"
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color1 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sBufferIndex 2
|
||||||
|
double sBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sColorBufferIndex 3
|
||||||
|
double sColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define sPlotBufferIndex 1
|
||||||
|
#property indicator_label2 "XCHVLM S"
|
||||||
|
#property indicator_style2 STYLE_SOLID
|
||||||
|
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color2 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mBufferIndex 4
|
||||||
|
double mBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mColorBufferIndex 5
|
||||||
|
double mColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define mPlotBufferIndex 2
|
||||||
|
#property indicator_label3 "XCHVLM M"
|
||||||
|
#property indicator_style3 STYLE_SOLID
|
||||||
|
#property indicator_type3 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color3 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lBufferIndex 6
|
||||||
|
double lBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lColorBufferIndex 7
|
||||||
|
double lColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define lPlotBufferIndex 3
|
||||||
|
#property indicator_label4 "XCHVLM L"
|
||||||
|
#property indicator_style4 STYLE_SOLID
|
||||||
|
#property indicator_type4 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color4 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hBufferIndex 8
|
||||||
|
double hBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hColorBufferIndex 9
|
||||||
|
double hColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#define hPlotBufferIndex 4
|
||||||
|
#property indicator_label5 "XCHVLM H"
|
||||||
|
#property indicator_style5 STYLE_SOLID
|
||||||
|
#property indicator_type5 DRAW_COLOR_HISTOGRAM
|
||||||
|
#property indicator_color5 CLR_NONE, clrLime, clrRed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Variables, Properties and etc ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int maxLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
int mCMarketLength = length;
|
||||||
|
double cVolumes[];
|
||||||
|
double cDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
int mSCycleLength = 0;
|
||||||
|
int mSMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mSCPeriod = NULL;
|
||||||
|
double sVolumes[];
|
||||||
|
double sDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
int mMCycleLength = 0;
|
||||||
|
int mMMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mMCPeriod = NULL;
|
||||||
|
double mVolumes[];
|
||||||
|
double mDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
int mLCycleLength = 0;
|
||||||
|
int mLMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mLCPeriod = NULL;
|
||||||
|
double lVolumes[];
|
||||||
|
double lDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
int mHCycleLength = 0;
|
||||||
|
int mHMarketLength = 0;
|
||||||
|
ENUM_TIMEFRAMES mHCPeriod = NULL;
|
||||||
|
double hVolumes[];
|
||||||
|
double hDistances[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Event Handlers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!InitMarketCycles())
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
ArrayResize(cVolumes, maxLength, 0);
|
||||||
|
ArrayResize(cDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
ArrayResize(sVolumes, maxLength, 0);
|
||||||
|
ArrayResize(sDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
ArrayResize(mVolumes, maxLength, 0);
|
||||||
|
ArrayResize(mDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
ArrayResize(lVolumes, maxLength, 0);
|
||||||
|
ArrayResize(lDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
ArrayResize(hVolumes, maxLength, 0);
|
||||||
|
ArrayResize(hDistances, maxLength, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(cVolumes);
|
||||||
|
Clean(cDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(sVolumes);
|
||||||
|
Clean(sDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(mVolumes);
|
||||||
|
Clean(mDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(lVolumes);
|
||||||
|
Clean(lDistances);
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(hVolumes);
|
||||||
|
Clean(hDistances);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
static int i = maxLength * 2;
|
||||||
|
for (i; i < rates_total; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateBuffers(
|
||||||
|
i,
|
||||||
|
prev_calculated,
|
||||||
|
rates_total,
|
||||||
|
//
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tick_volume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
i = rates_total - 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Functions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
length >= 2 &&
|
||||||
|
//
|
||||||
|
(IsValid(scMethod, scPeriod) &&
|
||||||
|
IsValid(mcMethod, mcPeriod) &&
|
||||||
|
IsValid(lcMethod, lcPeriod) &&
|
||||||
|
IsValid(hcMethod, hcPeriod))
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Market Cycles ...
|
||||||
|
bool InitMarketCycles()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int cPeriodSeconds = PeriodSeconds(_Period);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (scMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mSCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_SHORT,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSCPeriod = scPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mSCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
|
||||||
|
mSMarketLength = mSCycleLength * mCMarketLength;
|
||||||
|
result = mSCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (mcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mMCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_MEDIUM,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mMCPeriod = mcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mMCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
|
||||||
|
mMMarketLength = mMCycleLength * mCMarketLength;
|
||||||
|
result = mMCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (lcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mLCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_LONG,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mLCPeriod = lcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mLCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
|
||||||
|
mLMarketLength = mLCycleLength * mCMarketLength;
|
||||||
|
result = mLCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind Cycle Initialization ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Cycle Period ...
|
||||||
|
if (hcMethod == X_PERIOD_AUTO)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Select Period ...
|
||||||
|
mHCPeriod = GetCyclePeriod(
|
||||||
|
X_MARKET_CYCLE_HIND,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mHCPeriod = hcPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(mHCPeriod);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
|
||||||
|
mHMarketLength = mHCycleLength * mCMarketLength;
|
||||||
|
result = mHCycleLength > 0;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve all Exists Input Max Length ...
|
||||||
|
// use for Start Of Drawing ...
|
||||||
|
int ExtractMaxLengthOfInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = MathMax(mCMarketLength, mSMarketLength);
|
||||||
|
result = MathMax(result, mMMarketLength);
|
||||||
|
result = MathMax(result, mLMarketLength);
|
||||||
|
result = MathMax(result, mHMarketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(cPlotBufferIndex, PLOT_DRAW_TYPE, cDrawType);
|
||||||
|
SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Short ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(sPlotBufferIndex, PLOT_DRAW_TYPE, sDrawType);
|
||||||
|
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Medium ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(mPlotBufferIndex, PLOT_DRAW_TYPE, mDrawType);
|
||||||
|
SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Long ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
// PlotIndexSetInteger(lPlotBufferIndex, PLOT_DRAW_TYPE, lDrawType);
|
||||||
|
SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hind ...
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||||
|
SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
PlotIndexSetInteger(hPlotBufferIndex, PLOT_DRAW_TYPE, hDrawType);
|
||||||
|
PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateCycles(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycles(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// CURRENT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mCMarketLength,
|
||||||
|
showCurrent,
|
||||||
|
cVolumes,
|
||||||
|
cDistances,
|
||||||
|
cBuffer,
|
||||||
|
cColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SHORT ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mSMarketLength,
|
||||||
|
showShort,
|
||||||
|
sVolumes,
|
||||||
|
sDistances,
|
||||||
|
sBuffer,
|
||||||
|
sColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// MEDIUM ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mMMarketLength,
|
||||||
|
showMedium,
|
||||||
|
mVolumes,
|
||||||
|
mDistances,
|
||||||
|
mBuffer,
|
||||||
|
mColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// LONG ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mLMarketLength,
|
||||||
|
showLong,
|
||||||
|
lVolumes,
|
||||||
|
lDistances,
|
||||||
|
lBuffer,
|
||||||
|
lColorBuffer //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// HIND ...
|
||||||
|
CalculateCycle(
|
||||||
|
bar_index,
|
||||||
|
prevCalculated,
|
||||||
|
ratesTotal,
|
||||||
|
open,
|
||||||
|
high,
|
||||||
|
close,
|
||||||
|
low,
|
||||||
|
tickVolume,
|
||||||
|
//
|
||||||
|
mHMarketLength,
|
||||||
|
showHind,
|
||||||
|
hVolumes,
|
||||||
|
hDistances,
|
||||||
|
hBuffer,
|
||||||
|
hColorBuffer //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void CalculateCycle(
|
||||||
|
int bar_index, // Selected Bar Index
|
||||||
|
const int prevCalculated,
|
||||||
|
const int ratesTotal,
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &close[],
|
||||||
|
const double &low[],
|
||||||
|
const long &tickVolume[],
|
||||||
|
//
|
||||||
|
int _length, // Calculation Length
|
||||||
|
bool _show,
|
||||||
|
double &_volumes[],
|
||||||
|
double &_distances[],
|
||||||
|
double &_buffer[],
|
||||||
|
double &_colorBuffer[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
for (int x = 0; x < _length; x++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
_volumes[x] = (double)tickVolume[bar_index - x];
|
||||||
|
_distances[x] =
|
||||||
|
(close[bar_index - x] > open[bar_index - x])
|
||||||
|
? high[bar_index - x] - low[bar_index - x]
|
||||||
|
: low[bar_index - x] - high[bar_index - x];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double iValue = MathMean(_volumes) * MathMean(_distances);
|
||||||
|
|
||||||
|
//
|
||||||
|
_buffer[bar_index] = iValue;
|
||||||
|
_colorBuffer[bar_index] = iValue > 0
|
||||||
|
? _show
|
||||||
|
? bullishColorIDX
|
||||||
|
: hideColorIDX
|
||||||
|
: _show
|
||||||
|
? bearishColorIDX
|
||||||
|
: hideColorIDX;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
@@ -8909,6 +8909,43 @@ bool Contains(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate a Buffer's Sum ...
|
||||||
|
template <typename T>
|
||||||
|
double GetSum(
|
||||||
|
T &buffer[], // the Buffer which required to search
|
||||||
|
int start = 0, // Start Index
|
||||||
|
int count = 0 // Count for Search
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
T tmp[];
|
||||||
|
int tmpCount = Copy(
|
||||||
|
start,
|
||||||
|
count,
|
||||||
|
buffer,
|
||||||
|
tmp
|
||||||
|
//
|
||||||
|
);
|
||||||
|
if (tmpCount <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Summary ...
|
||||||
|
for (int i = 0; i < tmpCount; i++)
|
||||||
|
{
|
||||||
|
result += buffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Calculate a Buffer's Average ...
|
// Calculate a Buffer's Average ...
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user