add adxtd into indicator for control behaviour ...

This commit is contained in:
2024-06-21 15:59:30 +03:30
parent 9041f22045
commit fdf5442255
9 changed files with 3821 additions and 339 deletions
+3 -4
View File
@@ -3562,11 +3562,10 @@ public:
// //
// XADXTD ... // XADXTD ...
adxtdHelper = new XSCXADXTDHelper( adxtdHelper = new XSCXADXTDHelper();
inputs.symbol,
inputs.period //
);
result = adxtdHelper.Init( result = adxtdHelper.Init(
inputs.symbol,
inputs.period,
inputs.adxtdInputs // inputs.adxtdInputs //
); );
if (!result) if (!result)
+12 -31
View File
@@ -4767,25 +4767,16 @@ private:
{ {
// //
// Check Force State Hedging ... // Check Force State Hedging ...
bool isHedged = DoEQMForceClose(2); // bool isHedged = DoEQMForceClose();
if (isHedged) // if (isHedged)
{ // {
// // //
ForceState(false); // ForceState(false);
return; // return;
} // }
//
isHedged = DoEQMForceClose(1);
if (isHedged)
{
//
ForceState(false);
return;
}
// // // //
// isHedged = DoEQMForceClose(0.5); // isHedged = DoEQMForceClose(5);
// if (isHedged) // if (isHedged)
// { // {
// // // //
@@ -4793,15 +4784,7 @@ private:
// return; // return;
// } // }
// isHedged = DoEQMForceClose(0.3); // //
// if (isHedged)
// {
// //
// ForceState(false);
// return;
// }
//
return; return;
} }
@@ -4839,10 +4822,9 @@ private:
// Now Comparing items for enabling force State ... // Now Comparing items for enabling force State ...
bool isForceState = bool isForceState =
// //
longs > 0 && youngestAge >= 20 &&
shorts > 0 && //
youngestAge >= 20 && // TODO: Make this Configurable ... (longProfits + shortProfits < 0)
longVolumes == shortVolumes
// //
; ;
if (isForceState) if (isForceState)
@@ -4880,7 +4862,6 @@ private:
// Supporting Force States ... // Supporting Force States ...
bool isProtectionForce = bool isProtectionForce =
supportsCount >= 1; supportsCount >= 1;
// supportsCount >= (maxSupports + maxGrids + maxRecoveries);
if (isProtectionForce) if (isProtectionForce)
{ {
// //
@@ -0,0 +1,678 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XADXTD
// Description: provides Indicator implementation
// requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.base.class.mq5"
//
// Indicator Buffers ...
enum ENUM_XADXTD_BUFFERS
{
XADXTD_STRENGTH_LINE = 0, // Strenght Buffer ...
XADXTD_BULL_LINE = 1, // Bull Buffer ...
XADXTD_BEAR_LINE = 2, // Bear Buffer ...
};
//
string GetTitle(ENUM_XADXTD_BUFFERS bufferLine)
{
//
string result = NULL;
//
switch (bufferLine)
{
//
case XADXTD_STRENGTH_LINE:
result = "XStrength";
break;
//
case XADXTD_BULL_LINE:
result = "XBull";
break;
//
case XADXTD_BEAR_LINE:
result = "XBear";
break;
}
//
return result;
}
//
// XADXTD Indicator Inputs ...
struct XADXTDInputs
{
//
// Props ...
string version;
//
// Market ...
//
int length; // Length
//
// Constructor ...
XADXTDInputs()
{
Clean();
}
//
// Tools ...
//
// Initial Inputs ...
bool Init(
int _length = 21 // Length
)
{
//
bool result = false;
//
this.length = _length;
//
result = IsValid();
//
return result;
}
//
// Cleanup ...
void Clean()
{
//
length = 0;
}
//
// Default ...
void Default()
{
//
length = 21;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length > 0
//
;
//
return result;
}
//
// Retrieve Max Length ...
int Max()
{
//
int result = 0;
//
int values[1] = {
length //
};
//
result = GetMax(values);
//
return result;
}
};
//
// Define Conditions ...
struct XADXTDConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
double strength[];
double bullp[];
double bearp[];
//
// Conditions ...
//
bool isStrong;
bool isBullish;
bool isBearish;
bool isSwitchedToBullish;
bool isSwitchedToBearish;
bool isStrongSwitchedToBullish;
bool isStrongSwitchedToBearish;
//
void Clean()
{
//
Clean(strength);
Clean(bullp);
Clean(bearp);
//
ArraySetAsSeries(strength, true);
ArraySetAsSeries(bullp, true);
ArraySetAsSeries(bearp, true);
//
isStrong = false;
isBullish = false;
isBearish = false;
isSwitchedToBullish = false;
isSwitchedToBearish = false;
isStrongSwitchedToBullish = false;
isStrongSwitchedToBearish = false;
}
//
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
if (isBullish)
{
//
bullishScore++;
if (isStrong)
{
bullishScore++;
}
}
if (isBearish)
{
bearishScore++;
if (isStrong)
{
bearishScore++;
}
}
if (isSwitchedToBullish)
{
bullishScore++;
if (isStrong)
{
bullishScore++;
}
}
if (isSwitchedToBearish)
{
bearishScore++;
if (isStrong)
{
bearishScore++;
}
}
if (isStrongSwitchedToBullish)
{
bullishScore++;
}
if (isStrongSwitchedToBearish)
{
bearishScore++;
}
}
//
string GenerateSummary(
bool onlyCommons = false,
bool onlyConditions = false,
bool includeScores = true,
bool ignoreFalseConditions = true,
string separator = "\n" //
)
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
GenerateScore(
bullishScore,
bearishScore //
);
//
string scoresStr =
//
"Scores: " + separator +
"---------------" + separator +
"Bullish: " + ToString(bullishScore) + separator +
"Bearish: " + ToString(bearishScore) + separator +
""
//
;
//
string commonStr = GenerateSpecifiedCommonSummary(
this,
separator,
includeScores //
);
//
string conditionsStr =
//
ToString("isStrong", isStrong, ignoreFalseConditions, separator) +
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
ToString("isStrongSwitchedToBullish", isStrongSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isStrongSwitchedToBearish", isStrongSwitchedToBearish, ignoreFalseConditions, separator) +
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag()
{
return "XADXTD";
}
};
//
// Indicator Class ...
class XSCXADXTDHelper : public XSCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor(s) ...
void XSCXADXTDHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading TimeFrame
)
{
//
mSymbol = symbol;
mPeriod = period;
}
//
// Deconstructor ...
void ~XSCXADXTDHelper() {}
//
// Initialize Indicator ...
bool Init(
XADXTDInputs &inputs // Indicator Properties
)
{
//
bool result = false;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
// Set Inputs ...
this.mInputs = inputs;
//
// Validate Indicator State ...
result = this.IsValid();
if (!result)
{
return result;
}
//
result = DefineBuffers();
if (!result)
{
return result;
}
//
handler = iADX(
mSymbol,
mPeriod,
mInputs.length //
);
result = handler != INVALID_HANDLE;
//
return result;
}
//
XADXTDInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XADXTDInputs &inputs // Indicator Properties
)
{
return Init(inputs);
}
//
// Get Tag ...
string GetTag()
{
//
string result = NULL;
//
result = GetToken();
//
return result;
}
//
// Get Token ...
string GetToken()
{
//
string result = NULL;
//
result = GetSpecificToken(this);
//
return result;
}
//
string GetSymbol()
{
return mSymbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
mInputs.IsValid() &&
IsSpecifiedValid(mPeriod) &&
IsSpecifiedValid(mSymbol)
//
;
//
return result;
}
//
// De Initialize Class ...
void DeInit(int reason)
{
//
IndicatorRelease(handler);
}
//
// Tools ...
int CopyData(
ENUM_XADXTD_BUFFERS line,
double &dest[],
int start = 0,
int count = 1 //
)
{
//
int result = 0;
//
int mLine = -1;
switch (line)
{
//
case XADXTD_STRENGTH_LINE:
mLine = MAIN_LINE;
break;
//
case XADXTD_BULL_LINE:
mLine = PLUSDI_LINE;
break;
//
case XADXTD_BEAR_LINE:
mLine = MINUSDI_LINE;
break;
}
//
if (mLine == -1 || handler == INVALID_HANDLE)
{
return result;
}
//
result = CopyBuffer(
handler,
mLine,
start,
count,
dest //
);
//
return result;
}
//
bool GetConditions(
XADXTDConditions &conditions, //
int barIndex = 0, //
int loopback = 3 //
)
{
//
bool result = true;
//
if (loopback < 3)
{
loopback = 3;
}
//
conditions.Clean();
//
conditions.symbol = mSymbol;
conditions.period = mPeriod;
conditions.time = TimeCurrent();
//
int zIndex = barIndex;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
CopyData(
XADXTD_STRENGTH_LINE,
conditions.strength,
zIndex,
loopback //
);
CopyData(
XADXTD_BULL_LINE,
conditions.bullp,
zIndex,
loopback //
);
CopyData(
XADXTD_BEAR_LINE,
conditions.bearp,
zIndex,
loopback //
);
//
// Calculate Conditions ...
//
bool isStrong = conditions.strength[cIndex] >= 20;
//
bool isBullish = conditions.bullp[cIndex] > conditions.bearp[cIndex];
bool isBearish = conditions.bearp[cIndex] > conditions.bullp[cIndex];
//
bool isBullishPrev = conditions.bullp[pIndex] > conditions.bearp[pIndex];
bool isBearishPrev = conditions.bearp[pIndex] > conditions.bullp[pIndex];
//
bool isSwitchedToBullish = isBullish &&
!isBullishPrev;
bool isSwitchedToBearish = isBearish &&
!isBearishPrev;
//
bool isStrongSwitchedToBullish = isStrong &&
isSwitchedToBullish;
bool isStrongSwitchedToBearish = isStrong &&
isSwitchedToBearish;
//
conditions.isStrong = isStrong;
conditions.isBullish = isBullish;
conditions.isBearish = isBearish;
conditions.isSwitchedToBullish = isSwitchedToBullish;
conditions.isSwitchedToBearish = isSwitchedToBearish;
conditions.isStrongSwitchedToBullish = isStrongSwitchedToBullish;
conditions.isStrongSwitchedToBearish = isStrongSwitchedToBearish;
//
return result;
}
//
// Protected ...
protected:
//
// Props ...
int handler;
//
// Tools ...
bool DefineBuffers()
{
//
bool result = false;
//
result = true;
//
return result;
}
//
// Private ...
private:
//
// Props ...
//
string mSymbol; // Symbol
ENUM_TIMEFRAMES mPeriod; // TimeFrame
//
XADXTDInputs mInputs; // Properties
};
//
+8 -14
View File
@@ -40,13 +40,13 @@ input int x121EASlippage = 10; // Slippgae
// EURUSDb,GBPUSDb,XAUUSDb,USDCHFb,USDJPYb // EURUSDb,GBPUSDb,XAUUSDb,USDCHFb,USDJPYb
input group "Signals"; input group "Signals";
// EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb,XAUUSDb,NZDUSDb,AUDUSDb,USDCADb,BTCUSD,ETHUSD // EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb,XAUUSDb,NZDUSDb,AUDUSDb,USDCADb,BTCUSD,ETHUSD
input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,XAUUSDb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols
input bool x121EAUseAllSymbols = false; // Use All Available Symbols input bool x121EAUseAllSymbols = false; // Use All Available Symbols
input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols
input bool x121EAAllowLong = true; // Allow Long Trades input bool x121EAAllowLong = true; // Allow Long Trades
input bool x121EAAllowShort = true; // Allow Short Trades input bool x121EAAllowShort = true; // Allow Short Trades
input int x121EAReuiredSignalVerifications = 5; // Required Verifications for Signals input int x121EAReuiredSignalVerifications = 5; // Required Verifications for Signals
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
// //
// Risk Management ... // Risk Management ...
@@ -182,7 +182,7 @@ bool InitialEA()
bool result = false; bool result = false;
// //
TesterHideIndicators(true); // TesterHideIndicators(true);
// //
string inputSymbols[]; string inputSymbols[];
@@ -371,12 +371,6 @@ bool InitialEA()
// //
void PreConfigureStyles(X121SetupInputs &inputs) void PreConfigureStyles(X121SetupInputs &inputs)
{ {
//
if (!inputs.IsValid())
{
return;
}
// //
// XPV ... // XPV ...
inputs.pvInputs.showPeaksAndVales = true; inputs.pvInputs.showPeaksAndVales = true;
+251 -228
View File
@@ -22,7 +22,7 @@
// //
// Imports ... // Imports ...
#include "../Classes/x-saherelm.base.class.mq5" #include "../Classes/x-saherelm.xhelper.class.mq5"
// //
// Indicator Buffers ... // Indicator Buffers ...
@@ -33,47 +33,12 @@ enum ENUM_XADXTD_BUFFERS
XADXTD_BEAR_LINE = 2, // Bear Buffer ... XADXTD_BEAR_LINE = 2, // Bear Buffer ...
}; };
//
string GetTitle(ENUM_XADXTD_BUFFERS bufferLine)
{
//
string result = NULL;
//
switch (bufferLine)
{
//
case XADXTD_STRENGTH_LINE:
result = "XStrength";
break;
//
case XADXTD_BULL_LINE:
result = "XBull";
break;
//
case XADXTD_BEAR_LINE:
result = "XBear";
break;
}
//
return result;
}
// //
// XADXTD Indicator Inputs ... // XADXTD Indicator Inputs ...
struct XADXTDInputs struct XADXTDInputs
{ {
// //
// Props ... // Props ...
string version;
//
// Market ...
//
int length; // Length int length; // Length
// //
@@ -86,30 +51,10 @@ struct XADXTDInputs
// //
// Tools ... // Tools ...
//
// Initial Inputs ...
bool Init(
int _length = 21 // Length
)
{
//
bool result = false;
//
this.length = _length;
//
result = IsValid();
//
return result;
}
// //
// Cleanup ... // Cleanup ...
void Clean() void Clean()
{ {
//
length = 0; length = 0;
} }
@@ -117,7 +62,6 @@ struct XADXTDInputs
// Default ... // Default ...
void Default() void Default()
{ {
//
length = 21; length = 21;
} }
@@ -346,9 +290,8 @@ struct XADXTDConditions
}; };
// //
// Indicator Class ... // Class ...
class XSCXADXTDHelper : public XSCBaseHelper
class XSCXADXTDHelper : public XSCBase
{ {
// //
// Public ... // Public ...
@@ -357,30 +300,30 @@ public:
// Props ... // Props ...
// //
// Constructor(s) ... // Constructors ...
void XSCXADXTDHelper( XSCXADXTDHelper() : XSCBaseHelper(_Symbol, _Period)
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading TimeFrame
)
{ {
//
mSymbol = symbol;
mPeriod = period;
} }
// //
// Deconstructor ... // Deconstructor ...
void ~XSCXADXTDHelper() {} ~XSCXADXTDHelper() {}
// //
// Initialize Indicator ... // Tools ...
bool Init( bool Init(
XADXTDInputs &inputs // Indicator Properties string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XADXTDInputs &inputs // Inputs
) )
{ {
// //
bool result = false; bool result = false;
//
mSymbol = symbol;
mPeriod = period;
// //
result = inputs.IsValid(); result = inputs.IsValid();
if (!result) if (!result)
@@ -389,36 +332,36 @@ public:
} }
// //
// Set Inputs ... mInputs = inputs;
this.mInputs = inputs;
// //
// Validate Indicator State ... ArraySetAsSeries(bullpBuffer, true);
result = this.IsValid(); ArraySetAsSeries(bearpBuffer, true);
if (!result) ArraySetAsSeries(strengthBuffer, true);
{
return result;
}
// //
result = DefineBuffers(); mHandler = iCustom(
if (!result)
{
return result;
}
//
handler = iADX(
mSymbol, mSymbol,
mPeriod, mPeriod,
mInputs.length // "x-saherelm.xadxtd",
//
// Inputs ...
mInputs.length // Length
//
); );
result = handler != INVALID_HANDLE; result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
// //
return result; return result;
} }
//
// Inputs ...
// //
XADXTDInputs GetInputs() XADXTDInputs GetInputs()
{ {
@@ -427,129 +370,178 @@ public:
// //
bool SetInputs( bool SetInputs(
XADXTDInputs &inputs // Indicator Properties XADXTDInputs &inputs // Configs
)
{
return Init(inputs);
}
//
// Get Tag ...
string GetTag()
{
//
string result = NULL;
//
result = GetToken();
//
return result;
}
//
// Get Token ...
string GetToken()
{
//
string result = NULL;
//
result = GetSpecificToken(this);
//
return result;
}
//
string GetSymbol()
{
return mSymbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
mInputs.IsValid() &&
IsSpecifiedValid(mPeriod) &&
IsSpecifiedValid(mSymbol)
//
;
//
return result;
}
//
// De Initialize Class ...
void DeInit(int reason)
{
//
IndicatorRelease(handler);
}
//
// Tools ...
int CopyData(
ENUM_XADXTD_BUFFERS line,
double &dest[],
int start = 0,
int count = 1 //
) )
{ {
// //
int result = 0; return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
// Strength ...
//
double GetStrength(
int barIndex // Bar Index
)
{
// //
int mLine = -1; if (barIndex < 0)
switch (line)
{ {
// barIndex = 0;
case XADXTD_STRENGTH_LINE:
mLine = MAIN_LINE;
break;
//
case XADXTD_BULL_LINE:
mLine = PLUSDI_LINE;
break;
//
case XADXTD_BEAR_LINE:
mLine = MINUSDI_LINE;
break;
} }
// //
if (mLine == -1 || handler == INVALID_HANDLE) Calculate();
//
int count = ArraySize(strengthBuffer);
if (barIndex >= count)
{ {
return result; barIndex = count - 1;
} }
// //
result = CopyBuffer( return strengthBuffer[barIndex];
handler, }
mLine,
//
// Copy Required Items ...
int CopyStrength(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start, start,
count, count,
dest // strengthBuffer,
buffer,
forceClean
//
); );
}
//
// BullP ...
//
double GetBullP(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
// //
return result; Calculate();
//
int count = ArraySize(bullpBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return bullpBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyBullP(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
bullpBuffer,
buffer,
forceClean
//
);
}
//
// BearP ...
//
double GetBearP(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(bearpBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return bearpBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyBearP(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
bearpBuffer,
buffer,
forceClean
//
);
} }
// //
@@ -583,23 +575,27 @@ public:
int ppIndex = pIndex + 1; int ppIndex = pIndex + 1;
// //
CopyData( // Buffers ...
XADXTD_STRENGTH_LINE,
conditions.strength, //
CopyStrength(
zIndex, zIndex,
loopback // loopback,
conditions.strength //
); );
CopyData(
XADXTD_BULL_LINE, //
conditions.bullp, CopyBullP(
zIndex, zIndex,
loopback // loopback,
conditions.bullp //
); );
CopyData(
XADXTD_BEAR_LINE, //
conditions.bearp, CopyBearP(
zIndex, zIndex,
loopback // loopback,
conditions.bearp //
); );
// //
@@ -644,35 +640,62 @@ public:
// //
// Protected ... // Protected ...
protected: protected:
//
// Props ...
int handler;
//
// Tools ...
bool DefineBuffers()
{
//
bool result = false;
//
result = true;
//
return result;
}
// //
// Private ... // Private ...
private: private:
// //
// Props ... // Props ...
// XADXTDInputs mInputs; // Inputs ...
string mSymbol; // Symbol
ENUM_TIMEFRAMES mPeriod; // TimeFrame
// //
XADXTDInputs mInputs; // Properties // Buffers ...
double bullpBuffer[];
double bearpBuffer[];
double strengthBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
//
// Strength Buffer ...
CopyBuffer(
mHandler,
XADXTD_STRENGTH_LINE,
0,
totalBars,
strengthBuffer
//
);
//
// BullP Buffer ...
CopyBuffer(
mHandler,
XADXTD_BULL_LINE,
0,
totalBars,
bullpBuffer
//
);
//
// BearP Buffer ...
CopyBuffer(
mHandler,
XADXTD_BEAR_LINE,
0,
totalBars,
bearpBuffer
//
);
}
}; };
// //
+223
View File
@@ -0,0 +1,223 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XADXTD
// Description: ADX TD Channel ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XADXTD Indicator"
#property strict
//
#define ShortName "XADXTD"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
input int length = 21; // Length
//
// BUFFERS ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 0
//
#define strengthBufferIndex 0
double strengthBuffer[];
//
#define bullpBufferIndex 1
double bullpBuffer[];
//
#define bearpBufferIndex 2
double bearpBuffer[];
//
int maxLength = 0;
int mHandler = INVALID_HANDLE;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
mHandler = iADX(
_Symbol,
_Period,
length //
);
if (mHandler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
IndicatorRelease(mHandler);
}
//
// 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 ...
)
{
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
int adxCalculatedBars = BarsCalculated(mHandler);
if (adxCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedADXStrength = CopyBuffer(mHandler, MAIN_LINE, 0, limit, strengthBuffer);
int copiedADXBullp = CopyBuffer(mHandler, PLUSDI_LINE, 0, limit, bullpBuffer);
int copiedADXBearP = CopyBuffer(mHandler, MINUSDI_LINE, 0, limit, bearpBuffer);
if (copiedADXBullp <= 0 ||
copiedADXBearP <= 0 ||
copiedADXStrength <= 0)
{
return prev_calculated;
}
//
return rates_total;
}
//
// Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
(length > 0)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(result, length);
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
ArraySetAsSeries(strengthBuffer, true);
SetIndexBuffer(strengthBufferIndex, strengthBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(bullpBuffer, true);
SetIndexBuffer(bullpBufferIndex, bullpBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(bearpBuffer, true);
SetIndexBuffer(bearpBufferIndex, bearpBuffer, INDICATOR_CALCULATIONS);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+143 -62
View File
@@ -39,21 +39,25 @@ input group "Makret Cycles";
input group "Short"; input group "Short";
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
// input int scLength = 0; // Length
// //
input group "Medium"; input group "Medium";
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
// input int mcLength = 0; // Length
// //
input group "Long"; input group "Long";
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
// input int lcLength = 0; // Length
// //
input group "Hind"; input group "Hind";
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
// input int hcLength = 0; // Length
// //
input group "Fibonacci"; input group "Fibonacci";
@@ -381,24 +385,32 @@ int maxLength;
double mHideColorIDX = 0; double mHideColorIDX = 0;
// //
XMarketCycle sc; // XMarketCycle sc;
int mSCLength = 0;
double mLastSCHH = 0; double mLastSCHH = 0;
double mLastSCLL = 0; double mLastSCLL = 0;
ENUM_TIMEFRAMES mSCPeriod = NULL;
// //
XMarketCycle mc; // XMarketCycle mc;
int mMCLength = 0;
double mLastMCHH = 0; double mLastMCHH = 0;
double mLastMCLL = 0; double mLastMCLL = 0;
ENUM_TIMEFRAMES mMCPeriod = NULL;
// //
XMarketCycle lc; // XMarketCycle lc;
int mLCLength = 0;
double mLastLCHH = 0; double mLastLCHH = 0;
double mLastLCLL = 0; double mLastLCLL = 0;
ENUM_TIMEFRAMES mLCPeriod = NULL;
// //
XMarketCycle hc; // XMarketCycle hc;
int mHCLength = 0;
double mLastHCHH = 0; double mLastHCHH = 0;
double mLastHCLL = 0; double mLastHCLL = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
// //
double lastPeak = 0; double lastPeak = 0;
@@ -516,10 +528,10 @@ bool ValidateInputs()
// //
bool result = bool result =
// //
IsValid(scMethod, scPeriod) && (IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) && IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) && IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod) IsValid(hcMethod, hcPeriod))
// //
; ;
@@ -536,9 +548,9 @@ int ExtractMaxLengthOfInputs()
int result = 0; int result = 0;
// //
result = MathMax(sc.length, mc.length); result = MathMax(mSCLength, mMCLength);
result = MathMax(result, lc.length); result = MathMax(result, mLCLength);
result = MathMax(result, hc.length); result = MathMax(result, mHCLength);
// //
return result; return result;
@@ -834,60 +846,101 @@ bool InitMarketCycles()
bool result = false; bool result = false;
// //
// Short ... int cPeriodSeconds = PeriodSeconds(_Period);
result = sc.Init(
_Symbol, //
_Period, // Find Cycle Period ...
X_MARKET_CYCLE_SHORT, if (scMethod == X_PERIOD_AUTO)
scMethod,
scPeriod
//
);
if (!result)
{ {
return result; //
// Select Period ...
mSCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_SHORT,
_Period //
);
}
else
{
mSCPeriod = scPeriod;
} }
// //
// Medium ... if (IsValid(mSCPeriod))
result = mc.Init(
_Symbol,
_Period,
X_MARKET_CYCLE_MEDIUM,
mcMethod,
mcPeriod
//
);
if (!result)
{ {
return result; mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
} }
// //
// Long ... // Find Cycle Period ...
result = lc.Init( if (mcMethod == X_PERIOD_AUTO)
_Symbol,
_Period,
X_MARKET_CYCLE_LONG,
lcMethod,
lcPeriod
//
);
if (!result)
{ {
return result; //
// Select Period ...
mMCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_MEDIUM,
_Period //
);
}
else
{
mMCPeriod = mcPeriod;
} }
// //
// Hind ... if (IsValid(mMCPeriod))
result = hc.Init( {
_Symbol, mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
_Period, }
X_MARKET_CYCLE_HIND,
hcMethod, //
hcPeriod // Find Cycle Period ...
if (lcMethod == X_PERIOD_AUTO)
{
// //
); // Select Period ...
mLCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_LONG,
_Period //
);
}
else
{
mLCPeriod = lcPeriod;
}
//
if (IsValid(mLCPeriod))
{
mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
}
//
// Find Cycle Period ...
if (hcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mHCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_HIND,
_Period //
);
}
else
{
mHCPeriod = hcPeriod;
}
//
if (IsValid(mHCPeriod))
{
mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
}
//
result = mSCLength > 0 &&
mMCLength > mSCLength &&
mLCLength > mMCLength &&
mHCLength > mLCLength;
// //
return result; return result;
@@ -897,7 +950,7 @@ bool InitMarketCycles()
// Calculate Specified Cycles HH and LL ... // Calculate Specified Cycles HH and LL ...
void CalculateCycle( void CalculateCycle(
int barIndex, int barIndex,
XMarketCycle &cycle, ENUM_X_MARKET_CYCLES cycle,
double &lastHH, double &lastHH,
double &hhBuffer[], double &hhBuffer[],
double &hhColorBuffer[], double &hhColorBuffer[],
@@ -906,9 +959,6 @@ void CalculateCycle(
double &llColorBuffer[] // double &llColorBuffer[] //
) )
{ {
//
cycle.Update(barIndex);
// //
XOHCL bar; XOHCL bar;
bar.Init( bar.Init(
@@ -918,9 +968,40 @@ void CalculateCycle(
// //
); );
//
int mLength = 0;
switch (cycle)
{
//
case X_MARKET_CYCLE_SHORT:
mLength = mSCLength;
break;
//
case X_MARKET_CYCLE_MEDIUM:
mLength = mMCLength;
break;
//
case X_MARKET_CYCLE_LONG:
mLength = mLCLength;
break;
//
case X_MARKET_CYCLE_HIND:
mLength = mHCLength;
break;
}
//
if (mLength <= 0)
{
return;
}
// //
double hhValue = bar.FindHighest( double hhValue = bar.FindHighest(
cycle.length, mLength,
hhMode hhMode
// //
); );
@@ -946,7 +1027,7 @@ void CalculateCycle(
// //
double llValue = bar.FindLowest( double llValue = bar.FindLowest(
cycle.length, mLength,
llMode llMode
// //
); );
@@ -981,7 +1062,7 @@ void CalculateCycles(
// Short ... // Short ...
CalculateCycle( CalculateCycle(
barIndex, barIndex,
sc, X_MARKET_CYCLE_SHORT,
// //
mLastSCHH, mLastSCHH,
scHHBuffer, scHHBuffer,
@@ -997,7 +1078,7 @@ void CalculateCycles(
// Medium ... // Medium ...
CalculateCycle( CalculateCycle(
barIndex, barIndex,
mc, X_MARKET_CYCLE_MEDIUM,
// //
mLastMCHH, mLastMCHH,
mcHHBuffer, mcHHBuffer,
@@ -1013,7 +1094,7 @@ void CalculateCycles(
// Long ... // Long ...
CalculateCycle( CalculateCycle(
barIndex, barIndex,
lc, X_MARKET_CYCLE_LONG,
// //
mLastLCHH, mLastLCHH,
lcHHBuffer, lcHHBuffer,
@@ -1029,7 +1110,7 @@ void CalculateCycles(
// Hind ... // Hind ...
CalculateCycle( CalculateCycle(
barIndex, barIndex,
hc, X_MARKET_CYCLE_HIND,
// //
mLastHCHH, mLastHCHH,
hcHHBuffer, hcHHBuffer,