apply all chanes on xatr indicator, remains Helper ...

This commit is contained in:
2025-03-30 06:29:33 +03:30
parent eaddb8aa72
commit 7619129c26
4 changed files with 429 additions and 81 deletions
+6 -4
View File
@@ -34,10 +34,12 @@ enum ENUM_X121_XATR_BUFFERS
//
X121_ATR_UPPER_LINE = 0,
X121_ATR_LOWER_LINE = 1,
X121_ATR_LINE = 2,
X121_ATR_UPPER_RAW_LINE = 3,
X121_ATR_LOWER_RAW_LINE = 4,
X121_RSI_LINE = 5,
X121_PRICE_CHANGE_LINE = 2,
X121_PRICE_CHANGE_MA_LINE = 3,
X121_ATR_LINE = 4,
X121_ATR_UPPER_RAW_LINE = 5,
X121_ATR_LOWER_RAW_LINE = 6,
X121_RSI_LINE = 7,
};
//
+307 -75
View File
@@ -38,16 +38,23 @@ input group "Market";
//
input group "RSI Detection";
input int rsiLength = 14; // Length
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
input int rsiLength = 14; // Length
input ENUM_X_PRICE rsiPriceType = X_PRICE_CLOSE; // Applied To
input ENUM_X_MA_METHOD rsiSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method;
//
input group "ATR Detection";
input int atrLength = 14; // Length
input double atrMultiplier = 1; // Multiplier
input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To
input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
input int atrLength = 14; // Length
input double atrMultiplier = 1; // Multiplier
input ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // Upper Zone Applied To
input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // Lower Zone Applied To
input ENUM_X_MA_METHOD atrSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method
//
input group "Price Change";
input int priceChangeSmoothingLength = 14; // Length
input ENUM_X_PRICE priceChangeType = X_PRICE_CLOSE; // Price Type
input ENUM_X_MA_METHOD priceChangeSmoothingMethod = X_MA_MODE_SMA; // Moving Average Moethod
//
input group "Presentation";
@@ -56,8 +63,14 @@ input group "Presentation";
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showAtrUpper = true; // Show Upper Zone
input bool showAtrLower = true; // Show Lower Zone
input bool showAtrUpper = true; // Show Upper Zone
input bool showAtrLower = true; // Show Lower Zone
input bool showSmoothedAtrUpper = true; // Show Smoothed Upper Zone
input bool showSmoothedAtrLower = true; // Show Smoothed Lower Zone
input bool showRSIChange = true; // Show RSI Change
input bool showSmoothedRSIChange = true; // ShowSmoothed RSI Change
input bool showPriceChange = true; // Show Price Change
input bool showSmoothedPriceChange = true; // ShowSmoothed Price Change
//
// Buffers ...
@@ -72,8 +85,8 @@ input bool showAtrLower = true; // Show Lower Zone
#property indicator_chart_window
//
#property indicator_buffers 6
#property indicator_plots 2
#property indicator_buffers 10
#property indicator_plots 8
//
// ATR ...
@@ -89,7 +102,7 @@ double atrUpperBuffer[];
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_width1 1
//
// Lower ...
@@ -102,13 +115,94 @@ double atrLowerBuffer[];
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrYellow
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
#property indicator_width2 1
//
// ATR Smoothed ...
//
// Upper ...
//
#define atrSmoothedUpperBufferIndex 2
double atrSmoothedUpperBuffer[];
#property indicator_label3 "X121 ATRUSM"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_DASH
#property indicator_width3 1
//
// Lower ...
//
#define atrSmoothedLowerBufferIndex 3
double atrSmoothedLowerBuffer[];
#property indicator_label4 "X121 ATRLSM"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrYellow
#property indicator_style4 STYLE_DASH
#property indicator_width4 1
//
// Price Change ...
//
#define priceChangeBufferIndex 4
double priceChangeBuffer[];
#property indicator_label5 "X121 PCH"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrOrchid
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//
// Price Change Smoothed ...
//
#define priceChangeSmoothedBufferIndex 5
double priceChangeSmoothedBuffer[];
#property indicator_label6 "X121 PCHSM"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrOrchid
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//
// RSI Change ...
//
#define rsiChangeBufferIndex 6
double rsiChangeBuffer[];
#property indicator_label7 "X121 RSICH"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrCornflowerBlue
#property indicator_style7 STYLE_SOLID
#property indicator_width7 1
//
// RSI Change Smoothed ...
//
#define rsiChangeSmoothedBufferIndex 7
double rsiChangeSmoothedBuffer[];
#property indicator_label8 "X121 RSICHSM"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrCornflowerBlue
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//
// Data Buffers ...
//
int mLastBufferIndex = 1;
int mLastBufferIndex = 7;
//
// ATR ...
@@ -116,15 +210,9 @@ int mLastBufferIndex = 1;
#define atrBufferIndex mLastBufferIndex + 1
double atrBuffer[];
#define atrUpperRawBufferIndex mLastBufferIndex + 2
double atrUpperRawBuffer[];
#define atrLowerRawBufferIndex mLastBufferIndex + 3
double atrLowerRawBuffer[];
//
// RSI ...
#define rsiBufferIndex mLastBufferIndex + 4
#define rsiBufferIndex mLastBufferIndex + 2
double rsiBuffer[];
//
@@ -146,9 +234,7 @@ int rsiHandler = INVALID_HANDLE;
int atrHandler = INVALID_HANDLE;
//
bool isStrTrendChanged;
bool isStrStartBearishTrend;
bool isStrStartBullishTrend;
ENUM_APPLIED_PRICE rsiAppliedTo = ToAppliedPrice(rsiPriceType);
//
// Event Handlers ...
@@ -386,7 +472,14 @@ bool ValidateInputs()
//
// ATR ...
atrLength > 0 &&
atrMultiplier > 0
atrMultiplier > 0 &&
//
priceChangeSmoothingLength > 0 &&
//
IsValid(rsiPriceType) &&
IsValid(priceChangeType) &&
IsValid(atrUpperPriceType) &&
IsValid(atrLowerPriceType)
//
;
@@ -406,6 +499,7 @@ int ExtractMaxLengthOfInputs()
//
result = MathMax(rsiLength, atrLength);
result = MathMax(result, priceChangeSmoothingLength);
//
return result;
@@ -421,46 +515,89 @@ void DefineBuffers()
//
// UPPER ...
bool canShowAtrUpper = showAtrUpper;
ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE atrUpperDrawType = showAtrUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrUpperBuffer, true);
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, showAtrUpper);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
//
// LOWER ...
bool canShowAtrLower = showAtrLower;
ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE atrLowerDrawType = showAtrLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrLowerBuffer, true);
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, showAtrLower);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
//
// ATR Smoothed ...
//
// UPPER ...
ENUM_DRAW_TYPE atrSmoothedUpperDrawType = showSmoothedAtrUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrSmoothedUpperBuffer, true);
SetIndexBuffer(atrSmoothedUpperBufferIndex, atrSmoothedUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrSmoothedUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrUpper);
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_DRAW_TYPE, atrSmoothedUpperDrawType);
//
// LOWER ...
ENUM_DRAW_TYPE atrSmoothedLowerDrawType = showSmoothedAtrLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrSmoothedLowerBuffer, true);
SetIndexBuffer(atrSmoothedLowerBufferIndex, atrSmoothedLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrSmoothedLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrLower);
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_DRAW_TYPE, atrSmoothedLowerDrawType);
//
// PriceChange ...
ENUM_DRAW_TYPE priceChangeDrawType = showPriceChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(priceChangeBuffer, true);
SetIndexBuffer(priceChangeBufferIndex, priceChangeBuffer, INDICATOR_DATA);
PlotIndexSetDouble(priceChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_SHOW_DATA, showPriceChange);
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_DRAW_TYPE, priceChangeDrawType);
//
// PriceChange Smoothed ...
ENUM_DRAW_TYPE priceChangeSmoothedaDrawType = showSmoothedPriceChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(priceChangeSmoothedBuffer, true);
SetIndexBuffer(priceChangeSmoothedBufferIndex, priceChangeSmoothedBuffer, INDICATOR_DATA);
PlotIndexSetDouble(priceChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedPriceChange);
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, priceChangeSmoothedaDrawType);
//
// RSIChange ...
ENUM_DRAW_TYPE rsiChangeDrawType = showRSIChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(rsiChangeBuffer, true);
SetIndexBuffer(rsiChangeBufferIndex, rsiChangeBuffer, INDICATOR_DATA);
PlotIndexSetDouble(rsiChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_SHOW_DATA, showRSIChange);
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_DRAW_TYPE, rsiChangeDrawType);
//
// RSIChangeMa ...
ENUM_DRAW_TYPE rsiChangeMaDrawType = showSmoothedRSIChange ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(rsiChangeSmoothedBuffer, true);
SetIndexBuffer(rsiChangeSmoothedBufferIndex, rsiChangeSmoothedBuffer, INDICATOR_DATA);
PlotIndexSetDouble(rsiChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedRSIChange);
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, rsiChangeMaDrawType);
//
// Data Buffers ...
//
// ATR ...
//
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrUpperRawBuffer, true);
SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrLowerRawBuffer, true);
SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS);
//
// RSI ...
//
ArraySetAsSeries(rsiBuffer, true);
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
}
@@ -470,7 +607,9 @@ void DefineBuffers()
*/
void SetIndicatorName()
{
//
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
IndicatorSetInteger(INDICATOR_DIGITS, 2);
}
/**
@@ -535,16 +674,16 @@ void CalculateBuffers(
void FillBuffersZero(int barIndex)
{
//
// RSIS ...
rsiBuffer[barIndex] = 0;
//
// ATRS ...
atrBuffer[barIndex] = 0;
atrUpperBuffer[barIndex] = 0;
atrUpperRawBuffer[barIndex] = 0;
atrUpperBuffer[barIndex] = 0;
atrLowerRawBuffer[barIndex] = 0;
atrLowerBuffer[barIndex] = 0;
rsiChangeBuffer[barIndex] = 0;
priceChangeBuffer[barIndex] = 0;
atrSmoothedUpperBuffer[barIndex] = 0;
atrSmoothedLowerBuffer[barIndex] = 0;
rsiChangeSmoothedBuffer[barIndex] = 0;
priceChangeSmoothedBuffer[barIndex] = 0;
}
/**
@@ -569,15 +708,17 @@ void CalculateAtrZones(
)
{
//
// Select ATr Value ...
double atrValue = atrBuffer[bar_index];
double appliedAtrMultiplierValue = atrValue * atrMultiplier;
double points = GetPoints(_Symbol);
//
// ATR Calculations ...
double iAtr = atrBuffer[bar_index];
double iMultiPliedAtr = iAtr * atrMultiplier;
//
// Select Upper Price ...
ENUM_X_PRICE mUpperType = ToXPrice(atrUpperAppliedTo);
double upperPrice = GetAppliedPrice(
mUpperType,
double iUpperPrice = GetAppliedPrice(
atrUpperPriceType,
open,
high,
low,
@@ -587,9 +728,8 @@ void CalculateAtrZones(
//
// Select Lower Price ...
ENUM_X_PRICE mLowerType = ToXPrice(atrLowerAppliedTo);
double lowerPrice = GetAppliedPrice(
mLowerType,
double iLowerPrice = GetAppliedPrice(
atrLowerPriceType,
open,
high,
low,
@@ -598,21 +738,19 @@ void CalculateAtrZones(
);
//
// Calculate Raw Atrs ...
// Calculate Atrs ...
//
// Upper ...
double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue;
atrUpperRawBuffer[bar_index] = atrUpperRawValue;
double iAtrUpper = iUpperPrice + iMultiPliedAtr;
double iAtrLower = iLowerPrice - iMultiPliedAtr;
//
// Lower ...
double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue;
atrLowerRawBuffer[bar_index] = atrLowerRawValue;
atrUpperBuffer[bar_index] = iAtrUpper;
atrLowerBuffer[bar_index] = iAtrLower;
//
bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE;
if (canSmooth)
bool canSmoothAtr = atrSmoothingMethod != X_MA_MODE_NONE;
if (canSmoothAtr)
{
//
// Upper ...
@@ -621,9 +759,9 @@ void CalculateAtrZones(
prevCalculated,
bar_index,
atrLength,
atrUpperRawBuffer,
atrUpperBuffer,
atrSmoothingMode //
atrSmoothedUpperBuffer,
atrSmoothingMethod //
);
//
@@ -633,17 +771,111 @@ void CalculateAtrZones(
prevCalculated,
bar_index,
atrLength,
atrLowerRawBuffer,
atrLowerBuffer,
atrSmoothingMode //
atrSmoothedLowerBuffer,
atrSmoothingMethod //
);
}
else
{
//
// Use Raw Values ...
atrUpperBuffer[bar_index] = atrUpperRawValue;
atrLowerBuffer[bar_index] = atrLowerRawValue;
atrSmoothedUpperBuffer[bar_index] = iAtrUpper;
atrSmoothedLowerBuffer[bar_index] = iAtrLower;
}
//
// RSI Change Calculations ...
//
double iRsi = rsiBuffer[bar_index];
double iRsiP = rsiBuffer[bar_index + 1];
double iRsiPrice = GetAppliedPrice(
rsiPriceType,
open,
high,
low,
close,
bar_index //
);
//
double iRsiChanged = iRsi - iRsiP;
double iRsiPointsChanged = iRsiChanged / points;
//
double iRChange = iRsiPrice + (iRsiChanged * points);
rsiChangeBuffer[bar_index] = iRChange;
//
bool canSmoothRsi = rsiSmoothingMethod != X_MA_MODE_NONE;
if (canSmoothRsi)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
rsiChangeBuffer,
rsiChangeSmoothedBuffer,
rsiSmoothingMethod //
);
}
else
{
rsiChangeSmoothedBuffer[bar_index] = iRChange;
}
//
// PRICE Change Calculation ...
//
double iPChangePrice = GetAppliedPrice(
priceChangeType,
open,
high,
low,
close,
bar_index //
);
double iPPChangePrice = GetAppliedPrice(
priceChangeType,
open,
high,
low,
close,
bar_index + 1 //
);
//
double iPriceChange = iPChangePrice - iPPChangePrice;
double iPricePointsChanged = iPriceChange / points;
double iVolatilityChange = iPriceChange / iAtr;
//
double iPChange = iPChangePrice + (iPricePointsChanged * points);
priceChangeBuffer[bar_index] = iPChange;
//
bool canSmoothPriceChange = priceChangeSmoothingMethod != X_MA_MODE_NONE;
if (canSmoothPriceChange)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
priceChangeBuffer,
priceChangeSmoothedBuffer,
priceChangeSmoothingMethod //
);
}
else
{
priceChangeSmoothedBuffer[bar_index] = iPChange;
}
}
@@ -4788,6 +4788,105 @@ struct X121SMCStrategyConditionParser
(cXConditions.isStrBearish ||
cXConditions.isStrSwitchedToBearish);
//
// Detecting Str Box ...
XBoxZone strBox;
bool hasStrBox = false;
if (!hasStrBox)
{
//
hasStrBox =
cXConditions.isStrBullish ||
cXConditions.isStrBearish;
if (hasStrBox)
{
//
ENUM_X_DIRECTION strDir =
cXConditions.isStrBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
XOHCL lastBar;
ENUM_X_DIRECTION lastDir;
bool hasLast =
cHelper
.DetectNearestStrSwitched(
lastBar,
lastDir,
zIDX //
);
//
XOHCL prevBar;
ENUM_X_DIRECTION prevDir;
bool hasPrev =
hasLast &&
cHelper
.DetectNearestStrSwitched(
prevBar,
prevDir,
lastBar.Index() + 1 //
);
//
hasStrBox =
hasLast &&
hasPrev;
if (hasStrBox)
{
//
int fromIDX = MathMax(
lastBar.Index(),
prevBar.Index() //
);
//
string symbol = cBar.symbol;
ENUM_TIMEFRAMES period = cBar.period;
//
datetime from = GetBarTime(
symbol,
period,
fromIDX //
);
//
int length = fromIDX - barIndex;
//
double upper = zBar.FindHighest(
length,
MODE_HIGH //
);
//
double lower = zBar.FindLowest(
length,
MODE_LOW //
);
//
strBox.from = from;
strBox.dir = strDir;
strBox.lower = lower;
strBox.upper = upper;
strBox.symbol = symbol;
strBox.period = period;
strBox.type = "XSTRBox";
strBox.to = TimeCurrent();
//
hasStrBox =strBox.IsValid();
}
//
lastBar.Clean();
prevBar.Clean();
}
}
//
// XFastMa ...
@@ -4820,6 +4919,7 @@ struct X121SMCStrategyConditionParser
isBullish =
//
// false
hasStrBox &&
isStrIsBullish &&
isFastMaOverStr &&
// isDeltaIsBullish &&
@@ -4833,6 +4933,7 @@ struct X121SMCStrategyConditionParser
isBearish =
//
// false
hasStrBox &&
isStrIsBearish &&
isFastMaUnderStr &&
// isDeltaIsBearish &&
@@ -4848,6 +4949,18 @@ struct X121SMCStrategyConditionParser
isBearish;
if (result)
{
//
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
XCBoxObject *iObj;
bool isCreated = drawer.DrawBox(
strBox,
iObj //
);
if (isCreated) {
//
Print("STRBox");
}
//
dir =
isBullish
@@ -4865,7 +4978,7 @@ struct X121SMCStrategyConditionParser
double points = GetPoints(box.symbol);
//
double pivot = cXConditions.strBuffer[cIDX];
double pivot = cXConditions.strBuffer[cIDX];
// isBullish
// ? cBar.low - (points * 5)
// : cBar.high + (points * 5);
@@ -4911,6 +5024,7 @@ struct X121SMCStrategyConditionParser
pBar.Clean();
pPBar.Clean();
cState.Clean();
strBox.Clean();
cConditions.Clean();
cConditions.Clean();
ZeroMemory(cHelper);
@@ -39,7 +39,7 @@ enum ENUM_X121SMC_XIND_PROVIDERS
// Definitions ...
//
// XICH Signal Conditions ...
// XIND Signal Conditions ...
struct X121SMCStrategyXINDSignalConditions
{
//