add support for cycles ma in xfima ...

This commit is contained in:
2025-10-28 09:24:32 +03:30
parent 1fd79e5621
commit d86a1b6428
+208 -18
View File
@@ -145,8 +145,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
#property indicator_chart_window
//
#property indicator_buffers 49
#property indicator_plots 18
#property indicator_buffers 57
#property indicator_plots 22
//
// Plot Buffers ...
@@ -424,11 +424,60 @@ double atrBandLowerBuffer[];
#property indicator_color18 clrOrange
#property indicator_width18 2
//
#define scMaBufferIndex 25
double scMaBuffer[];
//
#define scMaBufferPlotIndex 18
#property indicator_label19 "SCMA"
#property indicator_type19 DRAW_LINE
#property indicator_color19 clrChocolate
#property indicator_style19 STYLE_DASHDOT
#property indicator_width19 2
//
#define mcMaBufferIndex 26
double mcMaBuffer[];
//
#define mcMaBufferPlotIndex 19
#property indicator_label20 "MCMA"
#property indicator_type20 DRAW_LINE
#property indicator_color20 clrChocolate
#property indicator_style20 STYLE_DASHDOT
#property indicator_width20 2
//
#define lcMaBufferIndex 27
double lcMaBuffer[];
//
#define lcMaBufferPlotIndex 20
#property indicator_label21 "LCMA"
#property indicator_type21 DRAW_LINE
#property indicator_color21 clrChocolate
#property indicator_style21 STYLE_DASHDOT
#property indicator_width21 2
//
#define hcMaBufferIndex 28
double hcMaBuffer[];
//
#define hcMaBufferPlotIndex 21
#property indicator_label22 "HCMA"
#property indicator_type22 DRAW_LINE
#property indicator_color22 clrChocolate
#property indicator_style22 STYLE_DASHDOT
#property indicator_width22 2
//
// Data Buffers ...
//
#define mLastBufferIndex 24
#define mLastBufferIndex 28
//
// MA ...
@@ -559,32 +608,59 @@ double atrBandRawUpperBuffer[];
#define atrBandRawLowerBufferIndex mLastBufferIndex + 24
double atrBandRawLowerBuffer[];
//
// XCMA Data ...
//
#define scMaStateBufferIndex mLastBufferIndex + 25
double scMaStateBuffer[];
//
#define mcMaStateBufferIndex mLastBufferIndex + 26
double mcMaStateBuffer[];
//
#define lcMaStateBufferIndex mLastBufferIndex + 27
double lcMaStateBuffer[];
//
#define hcMaStateBufferIndex mLastBufferIndex + 28
double hcMaStateBuffer[];
//
// Variables, Properties and etc ...
//
// XMarketCycle sc;
int mSCLength = 0;
int mSCMALength = 0;
ENUM_TIMEFRAMES mSCPeriod = NULL;
//
// XMarketCycle mc;
int mMCLength = 0;
int mMCMALength = 0;
ENUM_TIMEFRAMES mMCPeriod = NULL;
//
// XMarketCycle lc;
int mLCLength = 0;
int mLCMALength = 0;
ENUM_TIMEFRAMES mLCPeriod = NULL;
//
// XMarketCycle hc;
int mHCLength = 0;
int mHCMALength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
//
int sarHandler = INVALID_HANDLE;
int atrHandler = INVALID_HANDLE;
int scMaHandler = INVALID_HANDLE;
int mcMaHandler = INVALID_HANDLE;
int lcMaHandler = INVALID_HANDLE;
int hcMaHandler = INVALID_HANDLE;
int maFastHandler = INVALID_HANDLE;
int maSlowHandler = INVALID_HANDLE;
int maUpperHandler = INVALID_HANDLE;
@@ -599,11 +675,6 @@ int maxLength;
//
int firstBarIndex;
//
// Requirements ...
CArrayObj mObjects;
XCPOIDrawer *mDrawer;
//
double zigzagUppers[];
double zigzagLowers[];
@@ -703,17 +774,14 @@ void OnDeinit(const int reason)
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
delete mDrawer;
ZeroMemory(mDrawer);
//
mObjects.Clear();
//
// De Initialize all Handlers and etc ...
IndicatorRelease(sarHandler);
IndicatorRelease(atrHandler);
IndicatorRelease(scMaHandler);
IndicatorRelease(mcMaHandler);
IndicatorRelease(lcMaHandler);
IndicatorRelease(hcMaHandler);
IndicatorRelease(maFastHandler);
IndicatorRelease(maSlowHandler);
IndicatorRelease(maUpperHandler);
@@ -780,6 +848,12 @@ int OnCalculate(
//
// Validate Calculated Bars ...
//
int scCalculatedBars = BarsCalculated(scMaHandler);
int mcCalculatedBars = BarsCalculated(mcMaHandler);
int lcCalculatedBars = BarsCalculated(lcMaHandler);
int hcCalculatedBars = BarsCalculated(hcMaHandler);
//
// MA ...
int maFastCalculatedBars = BarsCalculated(maFastHandler);
@@ -797,6 +871,12 @@ int OnCalculate(
//
bool isPassedRequiredCalculatedBars =
//
// Cycles MA Handlers ...
scCalculatedBars >= maxLength &&
mcCalculatedBars >= maxLength &&
lcCalculatedBars >= maxLength &&
hcCalculatedBars >= maxLength &&
//
// MA ...
maFastCalculatedBars >= maxLength &&
@@ -808,8 +888,7 @@ int OnCalculate(
sarCalculatedBars >= maxLength &&
//
// ATR ...
atrCalculatedBars >= maxLength
//
atrCalculatedBars >= maxLength //
;
if (!isPassedRequiredCalculatedBars)
{
@@ -824,6 +903,12 @@ int OnCalculate(
//
// Buffers Copy ...
//
int copiedSCs = CopyBuffer(scMaHandler, MAIN_LINE, 0, limit, scMaBuffer);
int copiedMCs = CopyBuffer(mcMaHandler, MAIN_LINE, 0, limit, mcMaBuffer);
int copiedLCs = CopyBuffer(lcMaHandler, MAIN_LINE, 0, limit, lcMaBuffer);
int copiedHCs = CopyBuffer(hcMaHandler, MAIN_LINE, 0, limit, hcMaBuffer);
//
// MA ...
int copiedMAFasts = CopyBuffer(maFastHandler, MAIN_LINE, 0, limit, maFastBuffer);
@@ -842,6 +927,12 @@ int OnCalculate(
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// Cycles MA ...
copiedSCs >= limit &&
copiedMCs >= limit &&
copiedLCs >= limit &&
copiedHCs >= limit &&
//
// MA ...
copiedMAFasts >= limit &&
@@ -1479,6 +1570,21 @@ bool InitCycles()
mMCLength > mSCLength &&
mLCLength > mMCLength &&
mHCLength > mLCLength;
if (result)
{
//
// Initialized Cycles MA Ribons Length ...
mSCMALength = maBandLength * mSCLength;
mMCMALength = maBandLength * mMCLength;
mLCMALength = maBandLength * mLCLength;
mHCMALength = maBandLength * mHCLength;
//
result = mSCMALength > 0 &&
mMCMALength > mSCMALength &&
mLCMALength > mMCMALength &&
mHCMALength > mLCMALength;
}
//
return result;
@@ -1590,7 +1696,71 @@ bool InitRequirements()
}
//
mDrawer = new XCPOIDrawer();
// Cycles MA Handler ...
//
// SC ...
scMaHandler = iMA(
_Symbol,
_Period,
mSCMALength,
0,
maMethod,
maAppliedTo //
);
result = scMaHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// MC ...
mcMaHandler = iMA(
_Symbol,
_Period,
mMCMALength,
0,
maMethod,
maAppliedTo //
);
result = mcMaHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// LC ...
lcMaHandler = iMA(
_Symbol,
_Period,
mLCMALength,
0,
maMethod,
maAppliedTo //
);
result = lcMaHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// HC ...
hcMaHandler = iMA(
_Symbol,
_Period,
mHCMALength,
0,
maMethod,
maAppliedTo //
);
result = hcMaHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
@@ -2577,6 +2747,26 @@ void CalculateATR(
}
}
//
void CalculateCyclesMA(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
}
//
void CalculateCycleRanges(
int barIndex,