last works on create X121Setup ...
This commit is contained in:
@@ -46,4 +46,34 @@ protected:
|
||||
private:
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
template <typename T>
|
||||
string GenerateSpecifiedCommonSummary(
|
||||
T &mItem,
|
||||
string separator = "\n",
|
||||
bool includeScores = true,
|
||||
bool setLabel = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(!setLabel
|
||||
? ""
|
||||
: "Commons:" + separator) +
|
||||
"---------------" + separator +
|
||||
"Symbol: " + mItem.symbol + separator +
|
||||
"Period: " + ToString(mItem.period) + separator +
|
||||
"Time: " + ToString(mItem.time) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -249,6 +249,243 @@ struct XBuffer
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
class XSCBaseBufferClass : public XSCBaseAlert
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Virtual ...
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
virtual bool IsValid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
virtual void Calculate() {}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Indicators Buffers ...
|
||||
XBuffer mBuffers[];
|
||||
|
||||
//
|
||||
// Buffer Management ...
|
||||
|
||||
//
|
||||
// Count Registered Buffers ...
|
||||
int CountBuffers()
|
||||
{
|
||||
return ArraySize(mBuffers);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Specified Buffer Index ...
|
||||
int GetBufferIndex(
|
||||
string title // Specified Buffer Title
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsSpecifiedValid(title))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int buffersCount = CountBuffers();
|
||||
if (!IsValidSize(buffersCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < buffersCount; i++)
|
||||
{
|
||||
//
|
||||
XBuffer iBuffer = mBuffers[i];
|
||||
|
||||
//
|
||||
bool isOwn = iBuffer.IsOwn(title);
|
||||
if (isOwn)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Contains Specific Buffer or not ...
|
||||
bool HasBuffer(
|
||||
string title // Specified Buffer Title
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int bufferIndex = GetBufferIndex(title);
|
||||
result = bufferIndex >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Specified Buffer ...
|
||||
bool GetBuffer(
|
||||
string title, // Specified Buffer Title
|
||||
XBuffer &buffer // Hold Result
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int idx = GetBufferIndex(title);
|
||||
result = idx >= 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
buffer = mBuffers[idx];
|
||||
|
||||
//
|
||||
result = buffer.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Register Specified Buffer ...
|
||||
bool SetBuffer(
|
||||
XBuffer &buffer // Specified Buffer for Registration
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate buffer ...
|
||||
result = buffer.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Buffer Doesn't Exists before ...
|
||||
int idx = GetBufferIndex(buffer.title);
|
||||
result = idx == -1;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
buffer,
|
||||
mBuffers //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double GetBufferValue(
|
||||
string mTitle, // Required Buffer Title
|
||||
int index // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
// Validate State ...
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int bufferIDX = GetBufferIndex(mTitle);
|
||||
if (bufferIDX < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
result = mBuffers[bufferIDX].Get(index);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int CopyBufferValue(
|
||||
string mTitle,
|
||||
double &buffer[],
|
||||
int start,
|
||||
int count //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int sourceIDX = GetBufferIndex(mTitle);
|
||||
if (sourceIDX < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
result = ArrayCopy(
|
||||
buffer,
|
||||
mBuffers[sourceIDX].values,
|
||||
start,
|
||||
start,
|
||||
count //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Base Indicator Class ...
|
||||
class XSCBaseInd : public XSCBaseAlert
|
||||
@@ -650,3 +887,5 @@ private:
|
||||
//
|
||||
// Props ...
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,136 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Trend.mqh |
|
||||
//| Copyright 2000-2024, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include "Indicator.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CiADX. |
|
||||
//| Purpose: Class of the "Average Directional Index" indicator. |
|
||||
//| Derives from class CIndicator. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CiADX : public CIndicator
|
||||
{
|
||||
protected:
|
||||
int m_ma_period;
|
||||
|
||||
public:
|
||||
CiADX(void);
|
||||
~CiADX(void);
|
||||
//--- methods of access to protected data
|
||||
int MaPeriod(void) const { return (m_ma_period); }
|
||||
//--- method of creation
|
||||
bool Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period);
|
||||
//--- methods of access to indicator data
|
||||
double Main(const int index) const;
|
||||
double Plus(const int index) const;
|
||||
double Minus(const int index) const;
|
||||
//--- method of identifying
|
||||
virtual int Type(void) const { return (IND_ADX); }
|
||||
|
||||
protected:
|
||||
//--- methods of tuning
|
||||
virtual bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[]);
|
||||
bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiADX::CiADX(void) : m_ma_period(-1)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiADX::~CiADX(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Average Directional Index" indicator |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiADX::Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period)
|
||||
{
|
||||
//--- check history
|
||||
if (!SetSymbolPeriod(symbol, period))
|
||||
return (false);
|
||||
//--- create
|
||||
m_handle = iADX(symbol, period, ma_period);
|
||||
//--- check result
|
||||
if (m_handle == INVALID_HANDLE)
|
||||
return (false);
|
||||
//--- indicator successfully created
|
||||
if (!Initialize(symbol, period, ma_period))
|
||||
{
|
||||
//--- initialization failed
|
||||
IndicatorRelease(m_handle);
|
||||
m_handle = INVALID_HANDLE;
|
||||
return (false);
|
||||
}
|
||||
//--- ok
|
||||
return (true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize the indicator with universal parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[])
|
||||
{
|
||||
return (Initialize(symbol, period, (int)params[0].integer_value));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize indicator with the special parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period)
|
||||
{
|
||||
if (CreateBuffers(symbol, period, 3))
|
||||
{
|
||||
//--- string of status of drawing
|
||||
m_name = "ADX";
|
||||
m_status = "(" + symbol + "," + PeriodDescription() + "," + IntegerToString(ma_period) + ") H=" + IntegerToString(m_handle);
|
||||
//--- save settings
|
||||
m_ma_period = ma_period;
|
||||
//--- create buffers
|
||||
((CIndicatorBuffer *)At(0)).Name("MAIN_LINE");
|
||||
((CIndicatorBuffer *)At(1)).Name("PLUS_LINE");
|
||||
((CIndicatorBuffer *)At(2)).Name("MINUS_LINE");
|
||||
//--- ok
|
||||
return (true);
|
||||
}
|
||||
//--- error
|
||||
return (false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to Main buffer of "Average Directional Index" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiADX::Main(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(0);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to Plus buffer of "Average Directional Index" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiADX::Plus(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(1);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to Minus buffer of "Average Directional Index" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiADX::Minus(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(2);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
};
|
||||
|
||||
//
|
||||
@@ -122,6 +122,143 @@ struct XASCTInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XASCTConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double longSignal[];
|
||||
double shortSignal[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isLongSignal;
|
||||
bool isShortSignal;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(longSignal);
|
||||
Clean(shortSignal);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(longSignal, true);
|
||||
ArraySetAsSeries(shortSignal, true);
|
||||
|
||||
//
|
||||
isLongSignal = false;
|
||||
isShortSignal = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isLongSignal)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isShortSignal)
|
||||
{
|
||||
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("isLongSignal", isLongSignal, ignoreFalseConditions, separator) +
|
||||
ToString("isShortSignal", isShortSignal, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XASCT";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXASCTHelper : public XSCBaseHelper
|
||||
@@ -325,6 +462,66 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XASCTConditions &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;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyLong(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.longSignal //
|
||||
);
|
||||
CopyShort(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.shortSignal //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isLongSignal = NotEmptyZero(conditions.longSignal[cIndex]);
|
||||
bool isShortSignal = NotEmptyZero(conditions.shortSignal[cIndex]);
|
||||
|
||||
//
|
||||
conditions.isLongSignal = isLongSignal;
|
||||
conditions.isShortSignal = isShortSignal;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -150,6 +150,191 @@ struct XCHEInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XCHEConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double long1[];
|
||||
double long2[];
|
||||
double short1[];
|
||||
double short2[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isStrongBullish;
|
||||
bool isStrongBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
bool isStrongSwitchedToBullish;
|
||||
bool isStrongSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(long1);
|
||||
Clean(long2);
|
||||
Clean(short1);
|
||||
Clean(short2);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(long1, true);
|
||||
ArraySetAsSeries(long2, true);
|
||||
ArraySetAsSeries(short1, true);
|
||||
ArraySetAsSeries(short2, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isStrongBullish = false;
|
||||
isStrongBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
isStrongSwitchedToBullish = false;
|
||||
isStrongSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isStrongBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isStrongSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isStrongBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
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("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongBullish", isStrongBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongBearish", isStrongBearish, 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 "XCHE";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXCHEHelper : public XSCBaseHelper
|
||||
@@ -435,6 +620,110 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XCHEConditions &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;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyLongExit1(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.long1 //
|
||||
);
|
||||
CopyLongExit2(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.long2 //
|
||||
);
|
||||
CopyShortExit1(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.short1 //
|
||||
);
|
||||
CopyShortExit2(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.short2 //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = NotEmptyZero(conditions.long1[cIndex]);
|
||||
bool isBearish = NotEmptyZero(conditions.short1[cIndex]);
|
||||
|
||||
//
|
||||
bool isBullishPrev = NotEmptyZero(conditions.long1[pIndex]);
|
||||
bool isBearishPrev = NotEmptyZero(conditions.short1[pIndex]);
|
||||
|
||||
//
|
||||
bool isStrongBullish = isBullish &&
|
||||
NotEmptyZero(conditions.long2[cIndex]);
|
||||
bool isStrongBearish = isBearish &&
|
||||
NotEmptyZero(conditions.short2[cIndex]);
|
||||
|
||||
//
|
||||
bool isStrongBullishPrev = isBullishPrev &&
|
||||
NotEmptyZero(conditions.long2[pIndex]);
|
||||
bool isStrongBearishPrev = isBearishPrev &&
|
||||
NotEmptyZero(conditions.short2[pIndex]);
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
bool isStrongSwitchedToBullish = isStrongBullish &&
|
||||
!isStrongBullishPrev;
|
||||
bool isStrongSwitchedToBearish = isStrongBearish &&
|
||||
!isStrongBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isStrongBullish = isStrongBullish;
|
||||
conditions.isStrongBearish = isStrongBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
conditions.isStrongSwitchedToBullish = isStrongSwitchedToBullish;
|
||||
conditions.isStrongSwitchedToBearish = isStrongSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -129,6 +129,194 @@ struct XHKInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XHKConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
XOHCL hkBar[];
|
||||
XOHCL smHKBar[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isHKBullish;
|
||||
bool isHKBearish;
|
||||
bool isHKSwitchedToBullish;
|
||||
bool isHKSwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isSMHKBullish;
|
||||
bool isSMHKBearish;
|
||||
bool isSMHKSwitchedToBullish;
|
||||
bool isSMHKSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(hkBar);
|
||||
Clean(smHKBar);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hkBar, true);
|
||||
ArraySetAsSeries(smHKBar, true);
|
||||
|
||||
//
|
||||
isHKBullish = false;
|
||||
isHKBearish = false;
|
||||
isHKSwitchedToBullish = false;
|
||||
isHKSwitchedToBearish = false;
|
||||
|
||||
//
|
||||
isSMHKBullish = false;
|
||||
isSMHKBearish = false;
|
||||
isSMHKSwitchedToBullish = false;
|
||||
isSMHKSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isHKBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isHKSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isHKBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isHKSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isSMHKBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSMHKSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isSMHKBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSMHKSwitchedToBearish)
|
||||
{
|
||||
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("isHKBullish", isHKBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isHKSwitchedToBullish", isHKSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isHKBearish", isHKBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isHKSwitchedToBearish", isHKSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
//
|
||||
ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSMHKSwitchedToBearish", isSMHKSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XHK";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXHKHelper : public XSCBaseHelper
|
||||
@@ -886,6 +1074,97 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XHKConditions &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;
|
||||
|
||||
//
|
||||
CopyAsOHCL(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.hkBar //
|
||||
);
|
||||
CopySMAsOHCL(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.smHKBar //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isHKBullish = conditions.hkBar[cIndex].IsBullish();
|
||||
bool isHKBullishPrev = conditions.hkBar[pIndex].IsBullish();
|
||||
|
||||
//
|
||||
bool isHKSwitchedToBullish = isHKBullish &&
|
||||
!isHKBullishPrev;
|
||||
|
||||
//
|
||||
bool isHKBearish = conditions.hkBar[cIndex].IsBearish();
|
||||
bool isHKBearishPrev = conditions.hkBar[pIndex].IsBearish();
|
||||
|
||||
//
|
||||
bool isHKSwitchedToBearish = isHKBearish &&
|
||||
!isHKBearishPrev;
|
||||
|
||||
//
|
||||
bool isSMHKBullish = conditions.smHKBar[cIndex].IsBullish();
|
||||
bool isSMHKBullishPrev = conditions.smHKBar[pIndex].IsBullish();
|
||||
|
||||
//
|
||||
bool isSMHKSwitchedToBullish = isSMHKBullish &&
|
||||
!isSMHKBullishPrev;
|
||||
|
||||
//
|
||||
bool isSMHKBearish = conditions.smHKBar[cIndex].IsBearish();
|
||||
bool isSMHKBearishPrev = conditions.smHKBar[pIndex].IsBearish();
|
||||
|
||||
//
|
||||
bool isSMHKSwitchedToBearish = isSMHKBearish &&
|
||||
!isSMHKBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isHKBullish = isHKBullish;
|
||||
conditions.isHKSwitchedToBullish = isHKSwitchedToBullish;
|
||||
conditions.isHKBearish = isHKBearish;
|
||||
conditions.isHKSwitchedToBearish = isHKSwitchedToBearish;
|
||||
conditions.isSMHKBullish = isSMHKBullish;
|
||||
conditions.isSMHKSwitchedToBullish = isSMHKSwitchedToBullish;
|
||||
conditions.isSMHKBearish = isSMHKBearish;
|
||||
conditions.isSMHKSwitchedToBearish = isSMHKSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -140,6 +140,185 @@ struct XHULLInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XHULLConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double up[];
|
||||
double down[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isUpBullish;
|
||||
bool isUpBearish;
|
||||
bool isDownBullish;
|
||||
bool isDownBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(up);
|
||||
Clean(down);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(up, true);
|
||||
ArraySetAsSeries(down, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isUpBullish = false;
|
||||
isUpBearish = false;
|
||||
isDownBullish = false;
|
||||
isDownBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isUpBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isDownBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isUpBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isDownBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
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("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isUpBullish", isUpBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isUpBearish", isUpBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isDownBullish", isDownBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isDownBearish", isDownBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XHULL";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXHULLHelper : public XSCBaseHelper
|
||||
@@ -165,7 +344,7 @@ public:
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XHULLInputs &inputs // Inputs
|
||||
XHULLInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -346,6 +525,99 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XHULLConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 4 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 4)
|
||||
{
|
||||
loopback = 4;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
CopyUp(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.up //
|
||||
);
|
||||
CopyDown(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.down //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isUpBullish = conditions.up[cIndex] > conditions.up[pIndex];
|
||||
bool isUpBearish = conditions.up[cIndex] < conditions.up[pIndex];
|
||||
|
||||
//
|
||||
bool isUpBullishPrev = conditions.up[pIndex] > conditions.up[ppIndex];
|
||||
bool isUpBearishPrev = conditions.up[pIndex] < conditions.up[ppIndex];
|
||||
|
||||
//
|
||||
bool isDownBullish = conditions.down[cIndex] > conditions.down[pIndex];
|
||||
bool isDownBearish = conditions.down[cIndex] < conditions.down[pIndex];
|
||||
|
||||
//
|
||||
bool isDownBullishPrev = conditions.down[pIndex] > conditions.down[ppIndex];
|
||||
bool isDownBearishPrev = conditions.down[pIndex] < conditions.down[ppIndex];
|
||||
|
||||
//
|
||||
bool isBullish = isUpBullish &&
|
||||
isDownBullish;
|
||||
bool isBearish = isUpBearish &&
|
||||
isDownBearish;
|
||||
|
||||
//
|
||||
bool isBullishPrev = isUpBullishPrev &&
|
||||
isDownBullishPrev;
|
||||
bool isBearishPrev = isUpBearishPrev &&
|
||||
isDownBearishPrev;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isUpBullish = isUpBullish;
|
||||
conditions.isUpBearish = isUpBearish;
|
||||
conditions.isDownBullish = isDownBullish;
|
||||
conditions.isDownBearish = isDownBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -190,6 +190,568 @@ struct XICHInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XICHConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double tenkanSen[];
|
||||
double kijunSen[];
|
||||
double chikouSpan[];
|
||||
double senkouSpanA[];
|
||||
double senkouSpanB[];
|
||||
double futureSenkouSpanA[];
|
||||
double futureSenkouSpanB[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isClosedOverKijunSen;
|
||||
bool isClosedUnderKijunSen;
|
||||
bool isTenkanSenOverKijunSen;
|
||||
bool isTenkanSenUnderKijunSen;
|
||||
bool isTenkanSenCrossedOverKijunSen;
|
||||
bool isTenkanSenCrossedUnderKijunSen;
|
||||
|
||||
//
|
||||
bool isSenkouSpanAOverB;
|
||||
bool isSenkouSpanAUnderB;
|
||||
bool isSenkouSpanAOverLast;
|
||||
bool isSenkouSpanAUnderLast;
|
||||
bool isFutureSenkouSpanAOverB;
|
||||
bool isFutureSenkouSpanAUnderB;
|
||||
bool isFutureSenkouSpanAOverLast;
|
||||
bool isFutureSenkouSpanAUnderLast;
|
||||
|
||||
//
|
||||
bool isSenkouSpanACrossedOverB;
|
||||
bool isSenkouSpanACrossedUnderB;
|
||||
bool isSenkouSpanACrossedOverLast;
|
||||
bool isSenkouSpanACrossedUnderLast;
|
||||
bool isFutureSenkouSpanACrossedOverB;
|
||||
bool isFutureSenkouSpanACrossedUnderB;
|
||||
bool isFutureSenkouSpanACrossedOverLast;
|
||||
bool isFutureSenkouSpanACrossedUnderLast;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(tenkanSen);
|
||||
Clean(kijunSen);
|
||||
Clean(chikouSpan);
|
||||
Clean(senkouSpanA);
|
||||
Clean(senkouSpanB);
|
||||
Clean(futureSenkouSpanA);
|
||||
Clean(futureSenkouSpanB);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(tenkanSen, true);
|
||||
ArraySetAsSeries(kijunSen, true);
|
||||
ArraySetAsSeries(chikouSpan, true);
|
||||
ArraySetAsSeries(senkouSpanA, true);
|
||||
ArraySetAsSeries(senkouSpanB, true);
|
||||
ArraySetAsSeries(futureSenkouSpanA, true);
|
||||
ArraySetAsSeries(futureSenkouSpanB, true);
|
||||
|
||||
//
|
||||
isClosedOverKijunSen = false;
|
||||
isClosedUnderKijunSen = false;
|
||||
isTenkanSenOverKijunSen = false;
|
||||
isTenkanSenUnderKijunSen = false;
|
||||
isTenkanSenCrossedOverKijunSen = false;
|
||||
isTenkanSenCrossedUnderKijunSen = false;
|
||||
|
||||
//
|
||||
isSenkouSpanAOverB = false;
|
||||
isSenkouSpanAUnderB = false;
|
||||
isSenkouSpanAOverLast = false;
|
||||
isSenkouSpanAUnderLast = false;
|
||||
isFutureSenkouSpanAOverB = false;
|
||||
isFutureSenkouSpanAUnderB = false;
|
||||
isFutureSenkouSpanAOverLast = false;
|
||||
isFutureSenkouSpanAUnderLast = false;
|
||||
|
||||
//
|
||||
isSenkouSpanACrossedOverB = false;
|
||||
isSenkouSpanACrossedUnderB = false;
|
||||
isSenkouSpanACrossedOverLast = false;
|
||||
isSenkouSpanACrossedUnderLast = false;
|
||||
isFutureSenkouSpanACrossedOverB = false;
|
||||
isFutureSenkouSpanACrossedUnderB = false;
|
||||
isFutureSenkouSpanACrossedOverLast = false;
|
||||
isFutureSenkouSpanACrossedUnderLast = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isClosedOverKijunSen)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isTenkanSenOverKijunSen)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isTenkanSenCrossedOverKijunSen)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSenkouSpanAOverB)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSenkouSpanAOverLast)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanAOverB)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanAOverLast)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSenkouSpanACrossedOverB)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSenkouSpanACrossedOverLast)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanACrossedOverB)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanACrossedOverLast)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isClosedUnderKijunSen)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isTenkanSenUnderKijunSen)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isTenkanSenCrossedUnderKijunSen)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSenkouSpanAUnderB)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSenkouSpanAUnderLast)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanAUnderB)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanAUnderLast)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSenkouSpanACrossedUnderB)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSenkouSpanACrossedUnderLast)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanACrossedUnderB)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isFutureSenkouSpanACrossedUnderLast)
|
||||
{
|
||||
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("isClosedOverKijunSen", isClosedOverKijunSen, ignoreFalseConditions, separator) +
|
||||
ToString("isClosedUnderKijunSen", isClosedUnderKijunSen, ignoreFalseConditions, separator) +
|
||||
ToString("isTenkanSenOverKijunSen", isTenkanSenOverKijunSen, ignoreFalseConditions, separator) +
|
||||
ToString("isTenkanSenUnderKijunSen", isTenkanSenUnderKijunSen, ignoreFalseConditions, separator) +
|
||||
ToString("isTenkanSenCrossedOverKijunSen", isTenkanSenCrossedOverKijunSen, ignoreFalseConditions, separator) +
|
||||
ToString("isTenkanSenCrossedUnderKijunSen", isTenkanSenCrossedUnderKijunSen, ignoreFalseConditions, separator) +
|
||||
//
|
||||
ToString("isSenkouSpanAOverB", isSenkouSpanAOverB, ignoreFalseConditions, separator) +
|
||||
ToString("isSenkouSpanAUnderB", isSenkouSpanAUnderB, ignoreFalseConditions, separator) +
|
||||
ToString("isSenkouSpanAOverLast", isSenkouSpanAOverLast, ignoreFalseConditions, separator) +
|
||||
ToString("isSenkouSpanAUnderLast", isSenkouSpanAUnderLast, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanAOverB", isFutureSenkouSpanAOverB, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanAUnderB", isFutureSenkouSpanAUnderB, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanAOverLast", isFutureSenkouSpanAOverLast, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanAUnderLast", isFutureSenkouSpanAUnderLast, ignoreFalseConditions, separator) +
|
||||
//
|
||||
ToString("isSenkouSpanACrossedOverB", isSenkouSpanACrossedOverB, ignoreFalseConditions, separator) +
|
||||
ToString("isSenkouSpanACrossedUnderB", isSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) +
|
||||
ToString("isSenkouSpanACrossedOverLast", isSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) +
|
||||
ToString("isSenkouSpanACrossedUnderLast", isSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanACrossedOverB", isFutureSenkouSpanACrossedOverB, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanACrossedUnderB", isFutureSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanACrossedOverLast", isFutureSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) +
|
||||
ToString("isFutureSenkouSpanACrossedUnderLast", isFutureSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XICH";
|
||||
}
|
||||
|
||||
//
|
||||
bool HasLongConditions()
|
||||
{
|
||||
//
|
||||
bool result;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isCloseOverSenkouSpanA = cBar.close > senkouSpanA[cIndex];
|
||||
|
||||
//
|
||||
bool isBaseBullish = isCloseOverSenkouSpanA &&
|
||||
isSenkouSpanAOverB &&
|
||||
isSenkouSpanAOverLast;
|
||||
|
||||
//
|
||||
bool isKijunSenOverSenkouSpanA = kijunSen[cIndex] > senkouSpanA[cIndex];
|
||||
|
||||
//
|
||||
bool isCloseOverTenkanSen = cBar.close > tenkanSen[cIndex];
|
||||
|
||||
//
|
||||
bool isPriceCloseCrossedUpTenkanSen = pBar.close <= tenkanSen[pIndex] &&
|
||||
cBar.close > tenkanSen[cIndex];
|
||||
|
||||
//
|
||||
double cKumoUpper = MathMax(senkouSpanA[cIndex], senkouSpanB[cIndex]);
|
||||
double pKumoUpper = MathMax(senkouSpanA[pIndex], senkouSpanB[pIndex]);
|
||||
|
||||
//
|
||||
double cKumoLower = MathMin(senkouSpanA[cIndex], senkouSpanB[cIndex]);
|
||||
double pKumoLower = MathMin(senkouSpanA[pIndex], senkouSpanB[pIndex]);
|
||||
|
||||
//
|
||||
bool isTenkanSenOverKumo = tenkanSen[cIndex] > cKumoUpper;
|
||||
bool isTenkanSenOverKumoPrev = tenkanSen[pIndex] > pKumoUpper;
|
||||
|
||||
//
|
||||
bool isTenkanSenUnderKumo = tenkanSen[cIndex] < cKumoLower;
|
||||
bool isTenkanSenUnderKumoPrev = tenkanSen[pIndex] < pKumoLower;
|
||||
|
||||
//
|
||||
bool isTenkanSenCrossedOverKumo = isTenkanSenOverKumo &&
|
||||
!isTenkanSenOverKumoPrev;
|
||||
|
||||
//
|
||||
bool isTenkanSenCrossedUnderKumo = isTenkanSenUnderKumo &&
|
||||
!isTenkanSenUnderKumoPrev;
|
||||
|
||||
//
|
||||
bool condition1 =
|
||||
isBaseBullish &&
|
||||
isCloseOverTenkanSen &&
|
||||
isKijunSenOverSenkouSpanA &&
|
||||
isTenkanSenCrossedOverKijunSen;
|
||||
|
||||
//
|
||||
bool condition2 =
|
||||
isBaseBullish &&
|
||||
isCloseOverTenkanSen &&
|
||||
isKijunSenOverSenkouSpanA &&
|
||||
isTenkanSenOverKijunSen &&
|
||||
isSenkouSpanACrossedOverB;
|
||||
|
||||
//
|
||||
bool condition3 =
|
||||
isBaseBullish &&
|
||||
isKijunSenOverSenkouSpanA &&
|
||||
isPriceCloseCrossedUpTenkanSen &&
|
||||
isTenkanSenOverKijunSen;
|
||||
|
||||
//
|
||||
bool condition4 =
|
||||
isCloseOverTenkanSen &&
|
||||
isTenkanSenCrossedOverKumo &&
|
||||
isTenkanSenOverKijunSen &&
|
||||
isFutureSenkouSpanAOverB &&
|
||||
isFutureSenkouSpanAOverLast;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
condition1
|
||||
//
|
||||
||
|
||||
//
|
||||
condition2
|
||||
//
|
||||
||
|
||||
//
|
||||
condition3
|
||||
//
|
||||
||
|
||||
//
|
||||
condition4
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool HasShortConditions()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isCloseUnderSenkouSpanB = cBar.close < senkouSpanB[cIndex];
|
||||
|
||||
//
|
||||
bool isBaseBearish = isCloseUnderSenkouSpanB &&
|
||||
isSenkouSpanAUnderB &&
|
||||
isSenkouSpanAUnderLast;
|
||||
|
||||
//
|
||||
bool isKijunSenUnderSenkouSpanB = kijunSen[cIndex] < senkouSpanB[cIndex];
|
||||
|
||||
//
|
||||
bool isCloseUnderTenkanSen = cBar.close < tenkanSen[cIndex];
|
||||
|
||||
//
|
||||
bool isPriceCloseCrossedDownTenkanSen = pBar.close >= tenkanSen[pIndex] &&
|
||||
cBar.close < tenkanSen[cIndex];
|
||||
|
||||
//
|
||||
double cKumoUpper = MathMax(senkouSpanA[cIndex], senkouSpanB[cIndex]);
|
||||
double pKumoUpper = MathMax(senkouSpanA[pIndex], senkouSpanB[pIndex]);
|
||||
|
||||
//
|
||||
double cKumoLower = MathMin(senkouSpanA[cIndex], senkouSpanB[cIndex]);
|
||||
double pKumoLower = MathMin(senkouSpanA[pIndex], senkouSpanB[pIndex]);
|
||||
|
||||
//
|
||||
bool isTenkanSenOverKumo = tenkanSen[cIndex] > cKumoUpper;
|
||||
bool isTenkanSenOverKumoPrev = tenkanSen[pIndex] > pKumoUpper;
|
||||
|
||||
//
|
||||
bool isTenkanSenUnderKumo = tenkanSen[cIndex] < cKumoLower;
|
||||
bool isTenkanSenUnderKumoPrev = tenkanSen[pIndex] < pKumoLower;
|
||||
|
||||
//
|
||||
bool isTenkanSenCrossedOverKumo = isTenkanSenOverKumo &&
|
||||
!isTenkanSenOverKumoPrev;
|
||||
|
||||
//
|
||||
bool isTenkanSenCrossedUnderKumo = isTenkanSenUnderKumo &&
|
||||
!isTenkanSenUnderKumoPrev;
|
||||
|
||||
//
|
||||
bool condition1 =
|
||||
isBaseBearish &&
|
||||
isCloseUnderTenkanSen &&
|
||||
isKijunSenUnderSenkouSpanB &&
|
||||
isTenkanSenCrossedUnderKijunSen;
|
||||
|
||||
//
|
||||
bool condition2 =
|
||||
isBaseBearish &&
|
||||
isCloseUnderTenkanSen &&
|
||||
isKijunSenUnderSenkouSpanB &&
|
||||
isTenkanSenUnderKijunSen &&
|
||||
isSenkouSpanACrossedUnderB;
|
||||
|
||||
//
|
||||
bool condition3 =
|
||||
isBaseBearish &&
|
||||
isKijunSenUnderSenkouSpanB &&
|
||||
isPriceCloseCrossedDownTenkanSen &&
|
||||
isTenkanSenUnderKijunSen;
|
||||
|
||||
//
|
||||
bool condition4 =
|
||||
isCloseUnderTenkanSen &&
|
||||
isTenkanSenCrossedUnderKumo &&
|
||||
isTenkanSenUnderKijunSen &&
|
||||
isFutureSenkouSpanAUnderB &&
|
||||
isFutureSenkouSpanAUnderLast;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
condition1
|
||||
|
||||
||
|
||||
//
|
||||
condition2
|
||||
//
|
||||
||
|
||||
//
|
||||
condition3
|
||||
//
|
||||
||
|
||||
//
|
||||
condition4
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXICHHelper : public XSCBaseHelper
|
||||
@@ -703,6 +1265,190 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XICHConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 4 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 4)
|
||||
{
|
||||
loopback = 4;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
CopyTenkanSen(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.tenkanSen //
|
||||
);
|
||||
CopyKijunSen(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.kijunSen //
|
||||
);
|
||||
CopyChikouSpan(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.chikouSpan //
|
||||
);
|
||||
CopySenkouSpanA(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.senkouSpanA //
|
||||
);
|
||||
CopySenkouSpanB(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.senkouSpanB //
|
||||
);
|
||||
CopyFutureSenkouSpanA(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.futureSenkouSpanA //
|
||||
);
|
||||
CopyFutureSenkouSpanB(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.futureSenkouSpanB //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isClosedOverKijunSen = cBar.close > conditions.kijunSen[cIndex];
|
||||
bool isClosedUnderKijunSen = cBar.close < conditions.kijunSen[cIndex];
|
||||
|
||||
//
|
||||
bool isTenkanSenOverKijunSen = conditions.tenkanSen[cIndex] > conditions.kijunSen[cIndex];
|
||||
bool isTenkanSenUnderKijunSen = conditions.tenkanSen[cIndex] < conditions.kijunSen[cIndex];
|
||||
|
||||
//
|
||||
bool isTenkanSenOverKijunSenPrev = conditions.tenkanSen[pIndex] > conditions.kijunSen[pIndex];
|
||||
bool isTenkanSenUnderKijunSenPrev = conditions.tenkanSen[pIndex] < conditions.kijunSen[pIndex];
|
||||
|
||||
//
|
||||
bool isTenkanSenCrossedOverKijunSen = isTenkanSenOverKijunSen &&
|
||||
!isTenkanSenOverKijunSenPrev;
|
||||
bool isTenkanSenCrossedUnderKijunSen = isTenkanSenUnderKijunSen &&
|
||||
!isTenkanSenUnderKijunSenPrev;
|
||||
|
||||
//
|
||||
bool isSenkouSpanAOverB = conditions.senkouSpanA[cIndex] > conditions.senkouSpanB[cIndex];
|
||||
bool isSenkouSpanAUnderB = conditions.senkouSpanA[cIndex] < conditions.senkouSpanB[cIndex];
|
||||
|
||||
//
|
||||
bool isSenkouSpanAOverBPrev = conditions.senkouSpanA[pIndex] > conditions.senkouSpanB[pIndex];
|
||||
bool isSenkouSpanAUnderBPrev = conditions.senkouSpanA[pIndex] < conditions.senkouSpanB[pIndex];
|
||||
|
||||
//
|
||||
bool isSenkouSpanAOverLast = conditions.senkouSpanA[cIndex] > conditions.senkouSpanA[pIndex];
|
||||
bool isSenkouSpanAUnderLast = conditions.senkouSpanA[cIndex] < conditions.senkouSpanA[pIndex];
|
||||
|
||||
//
|
||||
bool isSenkouSpanAOverLastPrev = conditions.senkouSpanA[pIndex] > conditions.senkouSpanA[ppIndex];
|
||||
bool isSenkouSpanAUnderLastPrev = conditions.senkouSpanA[pIndex] < conditions.senkouSpanA[ppIndex];
|
||||
|
||||
//
|
||||
bool isFutureSenkouSpanAOverB = conditions.futureSenkouSpanA[cIndex] > conditions.futureSenkouSpanB[cIndex];
|
||||
bool isFutureSenkouSpanAUnderB = conditions.futureSenkouSpanA[cIndex] < conditions.futureSenkouSpanB[cIndex];
|
||||
|
||||
//
|
||||
bool isFutureSenkouSpanAOverBPrev = conditions.futureSenkouSpanA[pIndex] > conditions.futureSenkouSpanB[pIndex];
|
||||
bool isFutureSenkouSpanAUnderBPrev = conditions.futureSenkouSpanA[pIndex] < conditions.futureSenkouSpanB[pIndex];
|
||||
|
||||
//
|
||||
bool isFutureSenkouSpanAOverLast = conditions.futureSenkouSpanA[cIndex] > conditions.futureSenkouSpanA[pIndex];
|
||||
bool isFutureSenkouSpanAUnderLast = conditions.futureSenkouSpanA[cIndex] < conditions.futureSenkouSpanA[pIndex];
|
||||
|
||||
//
|
||||
bool isFutureSenkouSpanAOverLastPrev = conditions.futureSenkouSpanA[pIndex] > conditions.futureSenkouSpanA[ppIndex];
|
||||
bool isFutureSenkouSpanAUnderLastPrev = conditions.futureSenkouSpanA[pIndex] < conditions.futureSenkouSpanA[ppIndex];
|
||||
|
||||
//
|
||||
bool isSenkouSpanACrossedOverB = isSenkouSpanAOverB &&
|
||||
!isSenkouSpanAOverBPrev;
|
||||
bool isSenkouSpanACrossedUnderB = isSenkouSpanAUnderB &&
|
||||
!isSenkouSpanAUnderBPrev;
|
||||
|
||||
//
|
||||
bool isSenkouSpanACrossedOverLast = isSenkouSpanAOverLast &
|
||||
!isSenkouSpanAOverLastPrev;
|
||||
bool isSenkouSpanACrossedUnderLast = isSenkouSpanAUnderLast &&
|
||||
!isSenkouSpanAUnderLastPrev;
|
||||
|
||||
//
|
||||
bool isFutureSenkouSpanACrossedOverB = isFutureSenkouSpanAOverB &&
|
||||
!isFutureSenkouSpanAOverBPrev;
|
||||
bool isFutureSenkouSpanACrossedUnderB = isFutureSenkouSpanAUnderB &&
|
||||
!isFutureSenkouSpanAUnderBPrev;
|
||||
|
||||
//
|
||||
bool isFutureSenkouSpanACrossedOverLast = isFutureSenkouSpanAOverLast &&
|
||||
!isFutureSenkouSpanAOverLastPrev;
|
||||
bool isFutureSenkouSpanACrossedUnderLast = isFutureSenkouSpanAUnderLast &&
|
||||
!isFutureSenkouSpanAUnderLastPrev;
|
||||
|
||||
//
|
||||
conditions.isClosedOverKijunSen = isClosedOverKijunSen;
|
||||
conditions.isClosedUnderKijunSen = isClosedUnderKijunSen;
|
||||
conditions.isTenkanSenOverKijunSen = isTenkanSenOverKijunSen;
|
||||
conditions.isTenkanSenUnderKijunSen = isTenkanSenUnderKijunSen;
|
||||
conditions.isTenkanSenCrossedOverKijunSen = isTenkanSenCrossedOverKijunSen;
|
||||
conditions.isTenkanSenCrossedUnderKijunSen = isTenkanSenCrossedUnderKijunSen;
|
||||
conditions.isSenkouSpanAOverB = isSenkouSpanAOverB;
|
||||
conditions.isSenkouSpanAUnderB = isSenkouSpanAUnderB;
|
||||
conditions.isSenkouSpanAOverLast = isSenkouSpanAOverLast;
|
||||
conditions.isSenkouSpanAUnderLast = isSenkouSpanAUnderLast;
|
||||
conditions.isFutureSenkouSpanAOverB = isFutureSenkouSpanAOverB;
|
||||
conditions.isFutureSenkouSpanAUnderB = isFutureSenkouSpanAUnderB;
|
||||
conditions.isFutureSenkouSpanAOverLast = isFutureSenkouSpanAOverLast;
|
||||
conditions.isFutureSenkouSpanAUnderLast = isFutureSenkouSpanAUnderLast;
|
||||
conditions.isSenkouSpanACrossedOverB = isSenkouSpanACrossedOverB;
|
||||
conditions.isSenkouSpanACrossedUnderB = isSenkouSpanACrossedUnderB;
|
||||
conditions.isSenkouSpanACrossedOverLast = isSenkouSpanACrossedOverLast;
|
||||
conditions.isSenkouSpanACrossedUnderLast = isSenkouSpanACrossedUnderLast;
|
||||
conditions.isFutureSenkouSpanACrossedOverB = isFutureSenkouSpanACrossedOverB;
|
||||
conditions.isFutureSenkouSpanACrossedUnderB = isFutureSenkouSpanACrossedUnderB;
|
||||
conditions.isFutureSenkouSpanACrossedOverLast = isFutureSenkouSpanACrossedOverLast;
|
||||
conditions.isFutureSenkouSpanACrossedUnderLast = isFutureSenkouSpanACrossedUnderLast;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -284,6 +284,159 @@ struct XMRBInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XMRBConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double fast[];
|
||||
double slow[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isFastOverSlow;
|
||||
bool isFastUnderSlow;
|
||||
bool isFastCrossedOverSlow;
|
||||
bool isFastCrossedUnderSlow;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(fast);
|
||||
Clean(slow);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast, true);
|
||||
ArraySetAsSeries(slow, true);
|
||||
|
||||
//
|
||||
isFastOverSlow = false;
|
||||
isFastUnderSlow = false;
|
||||
isFastCrossedOverSlow = false;
|
||||
isFastCrossedUnderSlow = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isFastOverSlow)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isFastCrossedOverSlow)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isFastUnderSlow)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isFastCrossedUnderSlow)
|
||||
{
|
||||
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("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) +
|
||||
ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) +
|
||||
ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) +
|
||||
ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XMRB";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXMRBHelper : public XSCBaseHelper
|
||||
@@ -1196,6 +1349,74 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XMRBConditions &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;
|
||||
|
||||
//
|
||||
CopyFast(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.fast //
|
||||
);
|
||||
CopySlow(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.slow //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex];
|
||||
bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex];
|
||||
|
||||
//
|
||||
bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex];
|
||||
bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex];
|
||||
|
||||
//
|
||||
bool isFastCrossedOverSlow = isFastOverSlow &&
|
||||
!isFastOverSlowPrev;
|
||||
bool isFastCrossedUnderSlow = isFastUnderSlow &&
|
||||
!isFastUnderSlowPrev;
|
||||
|
||||
//
|
||||
conditions.isFastOverSlow = isFastOverSlow;
|
||||
conditions.isFastUnderSlow = isFastUnderSlow;
|
||||
conditions.isFastCrossedOverSlow = isFastCrossedOverSlow;
|
||||
conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow;
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -140,6 +140,157 @@ struct XSSLCInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XSSLCConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double up[];
|
||||
double down[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(up);
|
||||
Clean(down);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(up, true);
|
||||
ArraySetAsSeries(down, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
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("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XSSLC";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXSSLCHelper : public XSCBaseHelper
|
||||
@@ -355,6 +506,75 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XSSLCConditions &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;
|
||||
|
||||
//
|
||||
CopyUp(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.up //
|
||||
);
|
||||
CopyDown(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.down //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = conditions.up[cIndex] > conditions.down[cIndex];
|
||||
bool isBearish = conditions.up[cIndex] < conditions.down[cIndex];
|
||||
|
||||
//
|
||||
bool isBullishPrev = conditions.up[pIndex] > conditions.down[pIndex];
|
||||
bool isBearishPrev = conditions.up[pIndex] < conditions.down[pIndex];
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -129,6 +129,157 @@ struct XSTRInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XSTRConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double trend[];
|
||||
double state[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isTrendBullish;
|
||||
bool isTrendBearish;
|
||||
bool isTrendSwitchedToBullish;
|
||||
bool isTrendSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(trend);
|
||||
Clean(state);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trend, true);
|
||||
ArraySetAsSeries(state, true);
|
||||
|
||||
//
|
||||
isTrendBullish = false;
|
||||
isTrendBearish = false;
|
||||
isTrendSwitchedToBullish = false;
|
||||
isTrendSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isTrendBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isTrendSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isTrendBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isTrendSwitchedToBearish)
|
||||
{
|
||||
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("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isTrendSwitchedToBullish", isTrendSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isTrendSwitchedToBearish", isTrendSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XSTR";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXSTRHelper : public XSCBaseHelper
|
||||
@@ -154,7 +305,7 @@ public:
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XSTRInputs &inputs // Inputs
|
||||
XSTRInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -367,6 +518,75 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XSTRConditions &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;
|
||||
|
||||
//
|
||||
CopyTrend(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.trend //
|
||||
);
|
||||
CopyState(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.state //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isTrendBullish = IsBullish(conditions.state[cIndex]);
|
||||
bool isTrendBearish = IsBearish(conditions.state[cIndex]);
|
||||
|
||||
//
|
||||
bool isTrendBullishPrev = IsBullish(conditions.state[pIndex]);
|
||||
bool isTrendBearishPrev = IsBearish(conditions.state[pIndex]);
|
||||
|
||||
//
|
||||
bool isTrendSwitchedToBullish = isTrendBullish &&
|
||||
!isTrendBullishPrev;
|
||||
bool isTrendSwitchedToBearish = isTrendBearish &&
|
||||
!isTrendBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isTrendBullish = isTrendBullish;
|
||||
conditions.isTrendBearish = isTrendBearish;
|
||||
conditions.isTrendSwitchedToBullish = isTrendSwitchedToBullish;
|
||||
conditions.isTrendSwitchedToBearish = isTrendSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -137,6 +137,157 @@ struct XTDInputs
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XTDConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double bullish[];
|
||||
double bearish[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(bullish);
|
||||
Clean(bearish);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullish, true);
|
||||
ArraySetAsSeries(bearish, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
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("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XTD";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXTDHelper : public XSCBaseHelper
|
||||
@@ -162,7 +313,7 @@ public:
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XTDInputs &inputs // Inputs
|
||||
XTDInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -393,6 +544,75 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XTDConditions &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;
|
||||
|
||||
//
|
||||
CopyBullish(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bullish //
|
||||
);
|
||||
CopyBearish(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bearish //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = conditions.bullish[cIndex] > conditions.bearish[cIndex];
|
||||
bool isBearish = conditions.bullish[cIndex] < conditions.bearish[cIndex];
|
||||
|
||||
//
|
||||
bool isBullishPrev = conditions.bullish[pIndex] > conditions.bearish[pIndex];
|
||||
bool isBearishPrev = conditions.bullish[pIndex] < conditions.bearish[pIndex];
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -2405,6 +2405,9 @@ struct XBarTracker
|
||||
//
|
||||
int lastTrackedBar; // Last Tracked Bar ...
|
||||
|
||||
//
|
||||
bool waitsUntilNext; // Waits Until Next Bar ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XBarTracker()
|
||||
@@ -2473,6 +2476,37 @@ struct XBarTracker
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool CanProcessBar()
|
||||
{
|
||||
//
|
||||
bool isInTestMode = IsRunningOnTestMode();
|
||||
|
||||
//
|
||||
bool isNewBar = IsNewBar();
|
||||
|
||||
//
|
||||
bool result =
|
||||
isInTestMode
|
||||
? isNewBar
|
||||
: !waitsUntilNext
|
||||
? true
|
||||
: isNewBar;
|
||||
if (result && waitsUntilNext)
|
||||
{
|
||||
waitsUntilNext = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void Waits()
|
||||
{
|
||||
this.waitsUntilNext = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
void Clean()
|
||||
@@ -4516,6 +4550,29 @@ void CalculateTPSL(
|
||||
//
|
||||
return;
|
||||
}
|
||||
else if (canCalculateBasedOnSL && canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
bool canSetTPPrice = isLong
|
||||
? tpPrice > mEntry
|
||||
: tpPrice < mEntry;
|
||||
if (canSetTPPrice)
|
||||
{
|
||||
mTP = tpPrice;
|
||||
}
|
||||
|
||||
//
|
||||
bool canSetSLPrice = isLong
|
||||
? slPrice < mEntry
|
||||
: slPrice > mEntry;
|
||||
if (canSetSLPrice)
|
||||
{
|
||||
mSL = slPrice;
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
mTP = isLong
|
||||
@@ -4528,6 +4585,100 @@ void CalculateTPSL(
|
||||
: mEntry + risk;
|
||||
}
|
||||
|
||||
//
|
||||
bool CalculateTPSLByPoint(
|
||||
double &mSL, // Hold SL
|
||||
double &mTP, // Hold TP
|
||||
ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell)
|
||||
double mEntry, // Entry Price
|
||||
double mPointValue, // Point Value
|
||||
double mR2R = 1, // Provided Risk To Reward Ratio
|
||||
double slPoint = 0, // Provided SL Point
|
||||
double tpPoint = 0 // Provided TP Point
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSL = 0;
|
||||
mTP = 0;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(mType);
|
||||
|
||||
//
|
||||
// Set Default R2R ...
|
||||
if (mR2R < 1)
|
||||
{
|
||||
mR2R = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (mEntry <= 0 ||
|
||||
mPointValue <= 0 ||
|
||||
(slPoint <= 0 && tpPoint <= 0))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double risk = 0;
|
||||
double reward = 0;
|
||||
|
||||
//
|
||||
bool canCalculateBasedOnSL = slPoint > 0;
|
||||
|
||||
//
|
||||
bool canCalculateBasedOnTP = tpPoint > 0;
|
||||
|
||||
//
|
||||
if (!canCalculateBasedOnSL && !canCalculateBasedOnTP)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (canCalculateBasedOnSL && canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
reward = tpPoint * mPointValue;
|
||||
risk = slPoint * mPointValue;
|
||||
}
|
||||
else if (!canCalculateBasedOnSL && canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
reward = tpPoint * mPointValue;
|
||||
risk = reward / mR2R;
|
||||
}
|
||||
else if (canCalculateBasedOnSL && !canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
risk = slPoint * mPointValue;
|
||||
reward = risk * mR2R;
|
||||
}
|
||||
|
||||
//
|
||||
result = risk > 0 && reward > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mTP = isLong
|
||||
? mEntry + reward
|
||||
: mEntry - reward;
|
||||
|
||||
//
|
||||
mSL = isLong
|
||||
? mEntry - risk
|
||||
: mEntry + risk;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetTick(
|
||||
string mSymbol,
|
||||
@@ -6161,14 +6312,14 @@ double GetAverage(
|
||||
//
|
||||
// Get Max of Specific Loopback of a Buffer ...
|
||||
template <typename T>
|
||||
double GetMax(
|
||||
T GetMax(
|
||||
T &buffer[], // the Buffer which required to search
|
||||
int start = 0, // Start Index
|
||||
int count = 0 // Count for Search
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
T result = 0;
|
||||
|
||||
//
|
||||
if (count <= 0)
|
||||
@@ -6195,7 +6346,7 @@ double GetMax(
|
||||
for (int i = 0; i < tmpCount; i++)
|
||||
{
|
||||
//
|
||||
double iValue = tmp[i];
|
||||
T iValue = tmp[i];
|
||||
|
||||
//
|
||||
result =
|
||||
@@ -6216,14 +6367,14 @@ double GetMax(
|
||||
//
|
||||
// Get Min of Specific Loopback of a Buffer ...
|
||||
template <typename T>
|
||||
double GetMin(
|
||||
T GetMin(
|
||||
T &buffer[], // the Buffer which required to search
|
||||
int start = 0, // Start Index
|
||||
int count = 0 // Count for Search
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
T result = 0;
|
||||
|
||||
//
|
||||
if (count <= 0)
|
||||
@@ -6250,7 +6401,7 @@ double GetMin(
|
||||
for (int i = 0; i < tmpCount; i++)
|
||||
{
|
||||
//
|
||||
double iValue = tmp[i];
|
||||
T iValue = tmp[i];
|
||||
|
||||
//
|
||||
result =
|
||||
|
||||
Reference in New Issue
Block a user