This commit is contained in:
2025-02-26 19:19:50 +03:30
parent 959ef1fee4
commit 476bcaece8
5 changed files with 2501 additions and 89 deletions
+316 -22
View File
@@ -22,6 +22,7 @@
//
// Imports ...
#include "../Helpers/x-saherelm.x121.x3ma.helper.mq5"
#include "../Helpers/x-saherelm.x121.xatr.helper.mq5"
#include "../Helpers/x-saherelm.x121.xche.helper.mq5"
#include "../Helpers/x-saherelm.x121.xdon.helper.mq5"
@@ -44,6 +45,7 @@ struct X121Inputs
X121XSTRInputs xstrInputs;
X121XCHEInputs xcheInputs;
X121XDONInputs xdonInputs;
X121X3MAInputs x3maInputs;
X121XVWAPInputs xvwapInputs;
X121XTRENDInputs xtrendInputs;
@@ -197,6 +199,7 @@ struct X121Conditions
double strDownBuffer[];
double vwapMidBuffer[];
double upTrendBuffer[];
double x3maMidBuffer[];
double le1StartBuffer[];
double se1StartBuffer[];
double le2StartBuffer[];
@@ -208,6 +211,8 @@ struct X121Conditions
double vwapFastBuffer[];
double vwapSlowBuffer[];
double xhkSMLowBuffer[];
double x3maFastBuffer[];
double x3maSlowBuffer[];
double downTrendBuffer[];
double vwapPriceBuffer[];
double xhkRawLowBuffer[];
@@ -227,10 +232,13 @@ struct X121Conditions
double donOpenLowerBuffer[];
double donHighUpperBuffer[];
double donHighLowerBuffer[];
double x3maMidStateBuffer[];
double vwapFastStateBuffer[];
double vwapSlowStateBuffer[];
double donCloseUpperBuffer[];
double donCloseLowerBuffer[];
double x3maFastStateBuffer[];
double x3maSlowStateBuffer[];
//
double rsiSlope;
@@ -394,6 +402,31 @@ struct X121Conditions
bool isVWapSwitchedToBullishOrdered;
bool isVWapSwitchedToBearishOrdered;
//
bool isX3MaMidBullish;
bool isX3MaMidBearish;
bool isX3MaFastBullish;
bool isX3MaFastBearish;
bool isX3MaMidNeutural;
bool isX3MaSlowBullish;
bool isX3MaSlowBearish;
bool isX3MaFastOverMid;
bool isX3MaMidOverSlow;
bool isX3MaFastNeutural;
bool isX3MaSlowNeutural;
bool isX3MaFastUnderMid;
bool isX3MaMidUnderSlow;
bool isX3MaBullishState;
bool isX3MaBearishState;
bool isX3MaNeuturalState;
bool isX3MaBullishOrdered;
bool isX3MaBearishOrdered;
bool isX3MaSwitchedToBullishState;
bool isX3MaSwitchedToBearishState;
bool isX3MaSwitchedToNeuturalState;
bool isX3MaSwitchedToBullishOrdered;
bool isX3MaSwitchedToBearishOrdered;
//
bool isSMHKBullish;
bool isRawHKBullish;
@@ -643,6 +676,7 @@ struct X121Conditions
Clean(strDownBuffer);
Clean(vwapMidBuffer);
Clean(upTrendBuffer);
Clean(x3maMidBuffer);
Clean(le1StartBuffer);
Clean(se1StartBuffer);
Clean(le2StartBuffer);
@@ -654,6 +688,8 @@ struct X121Conditions
Clean(vwapFastBuffer);
Clean(vwapSlowBuffer);
Clean(xhkSMLowBuffer);
Clean(x3maFastBuffer);
Clean(x3maSlowBuffer);
Clean(downTrendBuffer);
Clean(vwapPriceBuffer);
Clean(xhkRawLowBuffer);
@@ -673,10 +709,13 @@ struct X121Conditions
Clean(donOpenLowerBuffer);
Clean(donHighUpperBuffer);
Clean(donHighLowerBuffer);
Clean(x3maMidStateBuffer);
Clean(vwapFastStateBuffer);
Clean(vwapSlowStateBuffer);
Clean(donCloseUpperBuffer);
Clean(donCloseLowerBuffer);
Clean(x3maFastStateBuffer);
Clean(x3maSlowStateBuffer);
//
ArraySetAsSeries(maBuffer, true);
@@ -710,6 +749,7 @@ struct X121Conditions
ArraySetAsSeries(strDownBuffer, true);
ArraySetAsSeries(vwapMidBuffer, true);
ArraySetAsSeries(upTrendBuffer, true);
ArraySetAsSeries(x3maMidBuffer, true);
ArraySetAsSeries(le1StartBuffer, true);
ArraySetAsSeries(se1StartBuffer, true);
ArraySetAsSeries(le2StartBuffer, true);
@@ -721,6 +761,8 @@ struct X121Conditions
ArraySetAsSeries(vwapFastBuffer, true);
ArraySetAsSeries(vwapSlowBuffer, true);
ArraySetAsSeries(xhkSMLowBuffer, true);
ArraySetAsSeries(x3maFastBuffer, true);
ArraySetAsSeries(x3maSlowBuffer, true);
ArraySetAsSeries(downTrendBuffer, true);
ArraySetAsSeries(vwapPriceBuffer, true);
ArraySetAsSeries(xhkRawLowBuffer, true);
@@ -740,10 +782,13 @@ struct X121Conditions
ArraySetAsSeries(donOpenLowerBuffer, true);
ArraySetAsSeries(donHighUpperBuffer, true);
ArraySetAsSeries(donHighLowerBuffer, true);
ArraySetAsSeries(x3maMidStateBuffer, true);
ArraySetAsSeries(vwapFastStateBuffer, true);
ArraySetAsSeries(vwapSlowStateBuffer, true);
ArraySetAsSeries(donCloseUpperBuffer, true);
ArraySetAsSeries(donCloseLowerBuffer, true);
ArraySetAsSeries(x3maFastStateBuffer, true);
ArraySetAsSeries(x3maSlowStateBuffer, true);
//
cheMin = 0;
@@ -891,48 +936,56 @@ struct X121Conditions
//
// VWAP ...
//
isVWapFastBullish = false;
isVWapFastBearish = false;
isVWapFastNeutural = false;
//
isVWapMidBullish = false;
isVWapMidBearish = false;
isVWapMidNeutural = false;
//
isVWapSlowBullish = false;
isVWapSlowBearish = false;
isVWapSlowNeutural = false;
//
isVWapFastBullish = false;
isVWapFastBearish = false;
isVWapFastOverMid = false;
isVWapMidOverSlow = false;
//
isVWapFastNeutural = false;
isVWapSlowNeutural = false;
isVWapFastUnderMid = false;
isVWapMidUnderSlow = false;
//
isVWapBullishState = false;
isVWapBearishState = false;
isVWapNeuturalState = false;
//
isVWapBullishOrdered = false;
isVWapBearishOrdered = false;
//
isVWapSwitchedToBullishState = false;
isVWapSwitchedToBearishState = false;
//
isVWapSwitchedToNeuturalState = false;
isVWapSwitchedToBullishOrdered = false;
isVWapSwitchedToBearishOrdered = false;
//
// X3MA ...
isX3MaMidBullish = false;
isX3MaMidBearish = false;
isX3MaFastBullish = false;
isX3MaFastBearish = false;
isX3MaMidNeutural = false;
isX3MaSlowBullish = false;
isX3MaSlowBearish = false;
isX3MaFastOverMid = false;
isX3MaMidOverSlow = false;
isX3MaFastNeutural = false;
isX3MaSlowNeutural = false;
isX3MaFastUnderMid = false;
isX3MaMidUnderSlow = false;
isX3MaBullishState = false;
isX3MaBearishState = false;
isX3MaNeuturalState = false;
isX3MaBullishOrdered = false;
isX3MaBearishOrdered = false;
isX3MaSwitchedToBullishState = false;
isX3MaSwitchedToBearishState = false;
isX3MaSwitchedToNeuturalState = false;
isX3MaSwitchedToBullishOrdered = false;
isX3MaSwitchedToBearishOrdered = false;
//
// CHE ...
@@ -1474,6 +1527,97 @@ struct X121Conditions
}
}
//
// X3MA ...
//
if (isX3MaBullishState)
{
bullishScore += score;
}
if (isX3MaBullishOrdered)
{
bullishScore += score;
}
if (isX3MaSwitchedToBullishState)
{
bullishScore += highScore;
}
if (isX3MaSwitchedToBullishOrdered)
{
bullishScore += highScore;
}
if (!isX3MaBullishState &&
!isX3MaSwitchedToBullishState)
{
//
if (isX3MaFastBullish)
{
bullishScore += minScore;
}
if (isX3MaSlowBullish)
{
bullishScore += minScore;
}
}
if (!isX3MaBullishOrdered &&
!isX3MaSwitchedToBullishOrdered)
{
//
if (isX3MaFastOverMid)
{
bullishScore += minScore;
}
if (isX3MaMidOverSlow)
{
bullishScore += minScore;
}
}
//
if (isX3MaBearishState)
{
bearishScore += score;
}
if (isX3MaBearishOrdered)
{
bearishScore += score;
}
if (isX3MaSwitchedToBearishState)
{
bearishScore += highScore;
}
if (isX3MaSwitchedToBearishOrdered)
{
bearishScore += highScore;
}
if (!isX3MaBearishState &&
!isX3MaSwitchedToBearishState)
{
//
if (isX3MaFastBearish)
{
bearishScore += minScore;
}
if (isX3MaSlowBearish)
{
bearishScore += minScore;
}
}
if (!isX3MaBearishOrdered &&
!isX3MaSwitchedToBearishOrdered)
{
//
if (isX3MaFastUnderMid)
{
bearishScore += minScore;
}
if (isX3MaMidUnderSlow)
{
bearishScore += minScore;
}
}
//
// XSMHK ...
@@ -1705,6 +1849,33 @@ struct X121Conditions
ToString("isVWapSwitchedToNeuturalState", isVWapSwitchedToNeuturalState, ignoreFalseConditions, separator) +
//
"-----------------------" + separator +
"X3MA ..." + separator +
"-----------------------" + separator +
ToString("isX3MaMidBullish", isX3MaMidBullish, ignoreFalseConditions, separator) +
ToString("isX3MaMidBearish", isX3MaMidBearish, ignoreFalseConditions, separator) +
ToString("isX3MaFastBullish", isX3MaFastBullish, ignoreFalseConditions, separator) +
ToString("isX3MaFastBearish", isX3MaFastBearish, ignoreFalseConditions, separator) +
ToString("isX3MaMidNeutural", isX3MaMidNeutural, ignoreFalseConditions, separator) +
ToString("isX3MaSlowBullish", isX3MaSlowBullish, ignoreFalseConditions, separator) +
ToString("isX3MaSlowBearish", isX3MaSlowBearish, ignoreFalseConditions, separator) +
ToString("isX3MaFastOverMid", isX3MaFastOverMid, ignoreFalseConditions, separator) +
ToString("isX3MaMidOverSlow", isX3MaMidOverSlow, ignoreFalseConditions, separator) +
ToString("isX3MaFastNeutural", isX3MaFastNeutural, ignoreFalseConditions, separator) +
ToString("isX3MaSlowNeutural", isX3MaSlowNeutural, ignoreFalseConditions, separator) +
ToString("isX3MaFastUnderMid", isX3MaFastUnderMid, ignoreFalseConditions, separator) +
ToString("isX3MaMidUnderSlow", isX3MaMidUnderSlow, ignoreFalseConditions, separator) +
ToString("isX3MaBullishState", isX3MaBullishState, ignoreFalseConditions, separator) +
ToString("isX3MaBearishState", isX3MaBearishState, ignoreFalseConditions, separator) +
ToString("isX3MaNeuturalState", isX3MaNeuturalState, ignoreFalseConditions, separator) +
ToString("isX3MaBullishOrdered", isX3MaBullishOrdered, ignoreFalseConditions, separator) +
ToString("isX3MaBearishOrdered", isX3MaBearishOrdered, ignoreFalseConditions, separator) +
ToString("isX3MaSwitchedToBullishState", isX3MaSwitchedToBullishState, ignoreFalseConditions, separator) +
ToString("isX3MaSwitchedToBearishState", isX3MaSwitchedToBearishState, ignoreFalseConditions, separator) +
ToString("isX3MaSwitchedToNeuturalState", isX3MaSwitchedToNeuturalState, ignoreFalseConditions, separator) +
ToString("isX3MaSwitchedToBullishOrdered", isX3MaSwitchedToBullishOrdered, ignoreFalseConditions, separator) +
ToString("isX3MaSwitchedToBearishOrdered", isX3MaSwitchedToBearishOrdered, ignoreFalseConditions, separator) +
//
"-----------------------" + separator +
"CHE ..." + separator +
"-----------------------" + separator +
ToString("isChe1Bullish", isChe1Bullish, ignoreFalseConditions, separator) +
@@ -1913,6 +2084,7 @@ class XCX121Helper : public XCBase
XCX121XSTRHelper *xstrHelper;
XCX121XCHEHelper *xcheHelper;
XCX121XDONHelper *xdonHelper;
XCX121X3MAHelper *x3maHelper;
XCX121XVWAPHelper *xvwapHelper;
XCX121XTRENDHelper *xtrendHelper;
@@ -1933,6 +2105,7 @@ class XCX121Helper : public XCBase
delete xstrHelper;
delete xcheHelper;
delete xdonHelper;
delete x3maHelper;
delete xvwapHelper;
delete xtrendHelper;
@@ -1943,6 +2116,7 @@ class XCX121Helper : public XCBase
ZeroMemory(xstrHelper);
ZeroMemory(xcheHelper);
ZeroMemory(xdonHelper);
ZeroMemory(x3maHelper);
ZeroMemory(xvwapHelper);
ZeroMemory(xtrendHelper);
}
@@ -2005,6 +2179,7 @@ class XCX121Helper : public XCBase
xstrInputs = inputs.xstrInputs;
xcheInputs = inputs.xcheInputs;
xdonInputs = inputs.xdonInputs;
x3maInputs = inputs.x3maInputs;
xvwapInputs = inputs.xvwapInputs;
xtrendInputs = inputs.xtrendInputs;
@@ -2089,6 +2264,19 @@ class XCX121Helper : public XCBase
return result;
}
//
// X3MA ...
x3maHelper = new XCX121X3MAHelper();
result = x3maHelper.Init(
symbol,
period,
x3maInputs //
);
if (!result)
{
return result;
}
//
// XVWAP ...
xvwapHelper = new XCX121XVWAPHelper();
@@ -2273,6 +2461,28 @@ class XCX121Helper : public XCBase
return result;
}
//
// X3MA ...
bool Get3MAConditions(
X121X3MAConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = false;
//
result = x3maHelper.GetConditions(
conditions,
barIndex,
loopback //
);
//
return result;
}
//
// XVWAP ...
bool GetVWAPConditions(
@@ -2475,6 +2685,19 @@ class XCX121Helper : public XCBase
return result;
}
//
// X3MA ...
X121X3MAConditions x3maConditions;
result = Get3MAConditions(
x3maConditions,
barIndex,
loopback //
);
if (!result)
{
return result;
}
//
// XVWAP ...
X121XVWAPConditions xvwapConditions;
@@ -3031,6 +3254,76 @@ class XCX121Helper : public XCBase
conditions.isRejectedDonCloseUpper = xdonConditions.isRejectedDonCloseUpper;
conditions.isRejectedDonCloseLower = xdonConditions.isRejectedDonCloseLower;
//
// X3MA ...
//
// Buffers ...
//
Copy(
x3maConditions.x3maFastBuffer,
conditions.x3maFastBuffer //
);
//
Copy(
x3maConditions.x3maMidBuffer,
conditions.x3maMidBuffer //
);
//
Copy(
x3maConditions.x3maSlowBuffer,
conditions.x3maSlowBuffer //
);
//
Copy(
x3maConditions.x3maFastStateBuffer,
conditions.x3maFastStateBuffer //
);
//
Copy(
x3maConditions.x3maMidStateBuffer,
conditions.x3maMidStateBuffer //
);
//
Copy(
x3maConditions.x3maSlowStateBuffer,
conditions.x3maSlowStateBuffer //
);
//
// Conditions ...
//
conditions.isX3MaMidBullish = x3maConditions.isX3MaMidBullish;
conditions.isX3MaMidBearish = x3maConditions.isX3MaMidBearish;
conditions.isX3MaFastBullish = x3maConditions.isX3MaFastBullish;
conditions.isX3MaFastBearish = x3maConditions.isX3MaFastBearish;
conditions.isX3MaMidNeutural = x3maConditions.isX3MaMidNeutural;
conditions.isX3MaSlowBullish = x3maConditions.isX3MaSlowBullish;
conditions.isX3MaSlowBearish = x3maConditions.isX3MaSlowBearish;
conditions.isX3MaFastOverMid = x3maConditions.isX3MaFastOverMid;
conditions.isX3MaMidOverSlow = x3maConditions.isX3MaMidOverSlow;
conditions.isX3MaFastNeutural = x3maConditions.isX3MaFastNeutural;
conditions.isX3MaSlowNeutural = x3maConditions.isX3MaSlowNeutural;
conditions.isX3MaFastUnderMid = x3maConditions.isX3MaFastUnderMid;
conditions.isX3MaMidUnderSlow = x3maConditions.isX3MaMidUnderSlow;
conditions.isX3MaBullishState = x3maConditions.isX3MaBullishState;
conditions.isX3MaBearishState = x3maConditions.isX3MaBearishState;
conditions.isX3MaNeuturalState = x3maConditions.isX3MaNeuturalState;
conditions.isX3MaBullishOrdered = x3maConditions.isX3MaBullishOrdered;
conditions.isX3MaBearishOrdered = x3maConditions.isX3MaBearishOrdered;
conditions.isX3MaSwitchedToBullishState = x3maConditions.isX3MaSwitchedToBullishState;
conditions.isX3MaSwitchedToBearishState = x3maConditions.isX3MaSwitchedToBearishState;
conditions.isX3MaSwitchedToNeuturalState = x3maConditions.isX3MaSwitchedToNeuturalState;
conditions.isX3MaSwitchedToBullishOrdered = x3maConditions.isX3MaSwitchedToBullishOrdered;
conditions.isX3MaSwitchedToBearishOrdered = x3maConditions.isX3MaSwitchedToBearishOrdered;
//
// XVWAP ...
@@ -3740,6 +4033,7 @@ class XCX121Helper : public XCBase
X121XDONInputs xdonInputs;
X121XSTRInputs xstrInputs;
X121XCHEInputs xcheInputs;
X121X3MAInputs x3maInputs;
X121XVWAPInputs xvwapInputs;
X121XTRENDInputs xtrendInputs;
File diff suppressed because it is too large Load Diff
+658
View File
@@ -0,0 +1,658 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XWZ
// Description: XWZ ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121 XWZ Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121_X3MA"
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int fastMALength = 20; // Fast MA Length
input int midMALength = 50; // Mid MA Length
input int slowMALength = 200; // Slow MA Length
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input bool showMaFast = true; // Show Fast MA
input bool showMaMid = true; // Show Mid MA
input bool showMaSlow = true; // Show Slow MA
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 3
//
// Plot Buffers ...
//
// FAST ...
#define maFastBufferIndex 0
double maFastBuffer[];
#define maFastColorBufferIndex 1
double maFastColorBuffer[];
//
#define maFastPlotBufferIndex 0
#property indicator_label1 "X121 MAF"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// MID ...
#define maMidBufferIndex 2
double maMidBuffer[];
#define maMidColorBufferIndex 3
double maMidColorBuffer[];
//
#define maMidPlotBufferIndex 1
#property indicator_label2 "X121 MAM"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
// SLOW ...
#define maSlowBufferIndex 4
double maSlowBuffer[];
#define maSlowColorBufferIndex 5
double maSlowColorBuffer[];
//
#define maSlowPlotBufferIndex 2
#property indicator_label3 "X121 MAS"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// Data Buffers ...
//
int mLastBufferIndex = 5;
//
// Fast State ...
#define maFastStateBufferIndex mLastBufferIndex + 1
double maFastStateBuffer[];
//
// Mid State ...
#define maMidStateBufferIndex mLastBufferIndex + 2
double maMidStateBuffer[];
//
// Slow State ...
#define maSlowStateBufferIndex mLastBufferIndex + 3
double maSlowStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
int maFastHandler = INVALID_HANDLE;
int maMidHandler = INVALID_HANDLE;
int maSlowHandler = INVALID_HANDLE;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// Fast MA ...
maFastHandler = iMA(
_Symbol,
_Period,
fastMALength,
0,
maMethod,
maAppliedTo //
);
bool isInited = maFastHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Mid MA ...
maMidHandler = iMA(
_Symbol,
_Period,
midMALength,
0,
maMethod,
maAppliedTo //
);
isInited = maMidHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// Slow MA ...
maSlowHandler = iMA(
_Symbol,
_Period,
slowMALength,
0,
maMethod,
maAppliedTo //
);
isInited = maSlowHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
IndicatorSetInteger(INDICATOR_DIGITS, 2);
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
IndicatorRelease(maFastHandler);
IndicatorRelease(maMidHandler);
IndicatorRelease(maSlowHandler);
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
int OnCalculate(
const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[] //
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// Validate Calculated Bars ...
//
// Fast MA ...
int maFastCalculatedBars = BarsCalculated(maFastHandler);
//
// Mid MA ...
int maMidCalculatedBars = BarsCalculated(maMidHandler);
//
// Slow MA ...
int maSlowCalculatedBars = BarsCalculated(maSlowHandler);
//
bool isPassedRequiredCalculatedBars =
//
// Fast MA ...
maFastCalculatedBars >= maxLength &&
//
// Slow MA ...
maMidCalculatedBars >= maxLength &&
//
// Slow MA ...
maSlowCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// Fast MA ...
int copiedFastMas = CopyBuffer(maFastHandler, 0, 0, limit, maFastBuffer);
//
// Mid MA ...
int copiedMidMas = CopyBuffer(maMidHandler, 0, 0, limit, maMidBuffer);
//
// Slow MA ...
int copiedSlowMas = CopyBuffer(maSlowHandler, 0, 0, limit, maSlowBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// Fast MA ...
copiedFastMas > 0 &&
//
// Mid MA ...
copiedMidMas > 0 &&
//
// Slow MA ...
copiedSlowMas > 0
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(
//
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result = fastMALength > 0 &&
midMALength > 0 &&
slowMALength > 0 &&
midMALength > fastMALength &&
slowMALength > midMALength;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(fastMALength, midMALength);
result = MathMax(result, slowMALength);
//
return result;
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Fast ...
ArraySetAsSeries(maFastBuffer, true);
ArraySetAsSeries(maFastColorBuffer, true);
SetIndexBuffer(maFastBufferIndex, maFastBuffer, INDICATOR_DATA);
SetIndexBuffer(maFastColorBufferIndex, maFastColorBuffer, INDICATOR_COLOR_INDEX);
//
// Mid ...
ArraySetAsSeries(maMidBuffer, true);
ArraySetAsSeries(maMidColorBuffer, true);
SetIndexBuffer(maMidBufferIndex, maMidBuffer, INDICATOR_DATA);
SetIndexBuffer(maMidColorBufferIndex, maMidColorBuffer, INDICATOR_COLOR_INDEX);
//
// Slow ...
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(maSlowColorBuffer, true);
SetIndexBuffer(maSlowBufferIndex, maSlowBuffer, INDICATOR_DATA);
SetIndexBuffer(maSlowColorBufferIndex, maSlowColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// Fast State ...
ArraySetAsSeries(maFastStateBuffer, true);
SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS);
//
// Mid State ...
ArraySetAsSeries(maMidStateBuffer, true);
SetIndexBuffer(maMidStateBufferIndex, maMidStateBuffer, INDICATOR_CALCULATIONS);
//
// Slow State ...
ArraySetAsSeries(maSlowStateBuffer, true);
SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateValues(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
maMidBuffer[barIndex] = 0;
maFastBuffer[barIndex] = 0;
maSlowBuffer[barIndex] = 0;
//
maFastColorBuffer[barIndex] = hideColorIDX;
maMidColorBuffer[barIndex] = hideColorIDX;
maSlowColorBuffer[barIndex] = hideColorIDX;
maFastStateBuffer[barIndex] = hideColorIDX;
maMidStateBuffer[barIndex] = hideColorIDX;
maSlowStateBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate Vales ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateValues(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Implement Colorify Mechanism ...
//
// Calculate Applied Price ...
double iPrice = GetAppliedPrice(
maAppliedTo,
open,
high,
low,
close,
bar_index //
);
//
double iFast = maFastBuffer[bar_index];
double iMid = maMidBuffer[bar_index];
double iSlow = maSlowBuffer[bar_index];
//
double iFastState = iPrice > iFast
? bullishColorIDX
: iPrice < iFast
? bearishColorIDX
: neuturalColorIDX;
double iMidState = iPrice > iMid
? bullishColorIDX
: iPrice < iMid
? bearishColorIDX
: neuturalColorIDX;
double iSlowState = iPrice > iSlow
? bullishColorIDX
: iPrice < iSlow
? bearishColorIDX
: neuturalColorIDX;
//
maFastColorBuffer[bar_index] =
showMaFast
? iFastState
: hideColorIDX;
maFastStateBuffer[bar_index] = iFastState;
//
maMidColorBuffer[bar_index] =
showMaMid
? iMidState
: hideColorIDX;
maMidStateBuffer[bar_index] = iMidState;
//
maSlowColorBuffer[bar_index] =
showMaSlow
? iSlowState
: hideColorIDX;
maSlowStateBuffer[bar_index] = iSlowState;
}
//
@@ -361,6 +361,14 @@ class XCX121SMCXWZSignalDetector : public XCBase
Print("Has Inside Zones");
}
//
bool hasBreakedZones = hasWorkingZone &&
workingZone.HasBreakedZones();
if (hasBreakedZones)
{
Print("Has Breaked Zones");
}
//
UpdateTo(cTime);
+180 -67
View File
@@ -75,6 +75,7 @@ struct X121SMCStrategyXWZWorkingZone
//
XOBFVG insideZones[];
XOBFVG breakedZones[];
XOBFVG waitingZones[];
//
@@ -109,6 +110,7 @@ struct X121SMCStrategyXWZWorkingZone
//
Clean(insideZones);
Clean(waitingZones);
Clean(breakedZones);
//
Clean(supportZones);
@@ -432,70 +434,72 @@ struct X121SMCStrategyXWZWorkingZone
return;
}
// //
// // Supply Zones ...
// count = mtfState.FilterSupplyZones(
// supplyZones,
// NULL,
// XZONE_STATE_PASSED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_IGNORED,
// false //
// );
// //
// // Demand Zones ...
// count = mtfState.FilterDemandZones(
// demandZones,
// NULL,
// XZONE_STATE_PASSED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_IGNORED,
// false //
// );
// //
// // Support Zones ...
// count = stfState.FilterSupportZones(
// supportZones,
// period,
// XZONE_STATE_PASSED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_IGNORED,
// false //
// );
// //
// // Resistance Zones ...
// count = stfState.FilterResistanceZones(
// resistanceZones,
// period,
// XZONE_STATE_PASSED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_FAILED,
// false,
// XZONE_STATE_IGNORED,
// false //
// );
//
// Supply Zones ...
count = mtfState.FilterSupplyZones(
supplyZones,
NULL,
XZONE_STATE_PASSED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_IGNORED,
false //
);
//
// Detect price Inside Zones ...
// Demand Zones ...
count = mtfState.FilterDemandZones(
demandZones,
NULL,
XZONE_STATE_PASSED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_IGNORED,
false //
);
//
// Support Zones ...
count = stfState.FilterSupportZones(
supportZones,
period,
XZONE_STATE_PASSED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_IGNORED,
false //
);
//
// Resistance Zones ...
count = stfState.FilterResistanceZones(
resistanceZones,
period,
XZONE_STATE_PASSED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_FAILED,
false,
XZONE_STATE_IGNORED,
false //
);
//
//
//
//
// Detect Price Inside Zones ...
has = HasWaitingZones();
if (has)
{
@@ -520,16 +524,25 @@ struct X121SMCStrategyXWZWorkingZone
if (isInside)
{
//
Add(
i,
mustRemove //
);
//
AddRef(
idx = FindIndex(
iOBFVG,
insideZones //
);
has = IsValidSize(idx);
if (!has)
{
//
Add(
i,
mustRemove //
);
//
AddRef(
iOBFVG,
insideZones //
);
}
}
}
@@ -549,9 +562,97 @@ struct X121SMCStrategyXWZWorkingZone
);
}
}
//
Clean(mustRemove);
}
//
// Detect Inside Zones ...
has = HasInsideZones();
if (has)
{
//
int mustRemove[];
count = CountInsideZones();
for (int i = 0; i < count; i++)
{
//
XOBFVG iOBFVG = insideZones[i];
ENUM_X_DIRECTION iDir = iOBFVG.GetDirection();
bool isBullish = IsBullish(iDir);
//
bool isBullishBreaked =
//
zBar.high < iOBFVG.ob.Lower() &&
cBar.high < iOBFVG.ob.Lower()
//
;
//
bool isBearishBreaked =
//
zBar.low > iOBFVG.ob.Upper() &&
cBar.low > iOBFVG.ob.Upper()
//
;
//
bool isBreaked =
isBullish
? isBullishBreaked
: isBearishBreaked;
//
if (isBreaked)
{
//
idx = FindIndex(
iOBFVG,
breakedZones //
);
has = IsValidIndex(idx);
if (!has)
{
//
Add(
i,
mustRemove //
);
//
AddRef(
iOBFVG,
breakedZones //
);
}
}
}
//
has = HasChild(mustRemove);
if (has)
{
//
count = ArraySize(mustRemove);
for (int i = 0; i < count; i++)
{
//
ArrayRemove(
insideZones,
mustRemove[i],
1 //
);
}
}
//
Clean(mustRemove);
}
//
// Adding New OBFVG to Waiting Zones if not Exists ...
XOBFVG tmpWaitingZones[];
count = ExtractOBFVGs(
tmpWaitingZones,
@@ -682,6 +783,18 @@ struct X121SMCStrategyXWZWorkingZone
return ArraySize(insideZones);
}
//
bool HasBreakedZones()
{
return HasChild(breakedZones);
}
//
int CountBreakedZones()
{
return ArraySize(breakedZones);
}
//
//
//