last works ...
This commit is contained in:
@@ -931,6 +931,883 @@ if (has)
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
bool GeneratePVBox(
|
||||
XBoxZone &box,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
box.symbol = GetSymbol();
|
||||
box.period = GetPeriod();
|
||||
|
||||
//
|
||||
int index = barIndex;
|
||||
|
||||
//
|
||||
// Peak ...
|
||||
datetime peaksSameFrom = NULL;
|
||||
double peak = mX121Helper.xpvHelper.GetPeak(index);
|
||||
double prevPeak = mX121Helper.xpvHelper.GetPeak(index + 1);
|
||||
bool startsByPeak = peak == prevPeak;
|
||||
|
||||
//
|
||||
// Vale ...
|
||||
datetime valesSameFrom = NULL;
|
||||
double vale = mX121Helper.xpvHelper.GetVale(index);
|
||||
double prevVale = mX121Helper.xpvHelper.GetVale(index + 1);
|
||||
bool startsByVale =
|
||||
!startsByPeak &&
|
||||
vale == prevVale;
|
||||
|
||||
//
|
||||
bool canBreak = false;
|
||||
while (!canBreak)
|
||||
{
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
datetime cTime = iTime(
|
||||
box.symbol,
|
||||
box.period,
|
||||
index //
|
||||
);
|
||||
|
||||
//
|
||||
// Peak ...
|
||||
double iPeak = mX121Helper.xpvHelper.GetPeak(index);
|
||||
|
||||
//
|
||||
// Vale ...
|
||||
double iVale = mX121Helper.xpvHelper.GetVale(index);
|
||||
|
||||
//
|
||||
// Start By Peak or Value ...
|
||||
bool isSame = false;
|
||||
if (startsByPeak)
|
||||
{
|
||||
//
|
||||
isSame = iPeak == peak;
|
||||
bool canSetVale = vale == 0
|
||||
? true
|
||||
: iVale > vale;
|
||||
if (canSetVale)
|
||||
{
|
||||
vale = iVale;
|
||||
}
|
||||
}
|
||||
else if (startsByVale)
|
||||
{
|
||||
//
|
||||
isSame = iVale == vale;
|
||||
bool canSetPeak = peak == 0
|
||||
? true
|
||||
: iPeak < peak;
|
||||
if (canSetPeak)
|
||||
{
|
||||
peak = iPeak;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (isSame)
|
||||
{
|
||||
//
|
||||
box.from = cTime;
|
||||
box.upper = peak;
|
||||
box.lower = vale;
|
||||
}
|
||||
else if (IsValid(box.from))
|
||||
{
|
||||
//
|
||||
// Complete Box ...
|
||||
box.to = iTime(
|
||||
box.symbol,
|
||||
box.period,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
box.type = "XPVBox";
|
||||
box.dir = startsByPeak
|
||||
? X_DIRECTION_BEARISH
|
||||
: startsByVale
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_NONE;
|
||||
}
|
||||
|
||||
//
|
||||
canBreak = !isSame;
|
||||
}
|
||||
|
||||
//
|
||||
result = box.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
box.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void DetectPVPivots(
|
||||
int barIndex = 0,
|
||||
int validation = 50,
|
||||
int loopback = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
loopback = NormalizeInt(loopback, 10);
|
||||
validation = NormalizeInt(validation, 5);
|
||||
|
||||
//
|
||||
int iPeakVerified = 0;
|
||||
int iValeVerified = 0;
|
||||
datetime iPeakTo = GetBarTime(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
barIndex //
|
||||
);
|
||||
datetime iValeTo = GetBarTime(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
barIndex //
|
||||
);
|
||||
double iPeak = mX121Helper.xpvHelper.GetPeak(barIndex);
|
||||
double iVale = mX121Helper.xpvHelper.GetVale(barIndex);
|
||||
double iPeakGolden = mX121Helper.xpvHelper.GetPeakGoldenZone(barIndex);
|
||||
double iValeGolden = mX121Helper.xpvHelper.GetValeGoldenZone(barIndex);
|
||||
for (int i = barIndex + 1; i < barIndex + 1 + loopback; i++)
|
||||
{
|
||||
//
|
||||
double iiPeak = mX121Helper.xpvHelper.GetPeak(i);
|
||||
double iiVale = mX121Helper.xpvHelper.GetVale(i);
|
||||
double iiPeakGolden = mX121Helper.xpvHelper.GetPeakGoldenZone(i);
|
||||
double iiValeGolden = mX121Helper.xpvHelper.GetValeGoldenZone(i);
|
||||
|
||||
//
|
||||
if (iiPeak == iPeak)
|
||||
{
|
||||
//
|
||||
iPeakVerified++;
|
||||
iPeakGolden = iPeakGolden < iiPeakGolden
|
||||
? iiPeakGolden
|
||||
: iPeakGolden;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (iPeakVerified > 0 &&
|
||||
iPeakVerified < validation)
|
||||
{
|
||||
//
|
||||
// Reset ...
|
||||
iPeak = iiPeak;
|
||||
iPeakVerified = 0;
|
||||
iPeakGolden = iiPeakGolden;
|
||||
iPeakTo = GetBarTime(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
i //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (iiVale == iVale)
|
||||
{
|
||||
//
|
||||
iValeVerified++;
|
||||
iValeGolden = iValeGolden > iiValeGolden
|
||||
? iiValeGolden
|
||||
: iValeGolden;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (iValeVerified > 0 &&
|
||||
iValeVerified < validation)
|
||||
{
|
||||
//
|
||||
// Reset ...
|
||||
iVale = iiVale;
|
||||
iValeVerified = 0;
|
||||
iValeGolden = iiValeGolden;
|
||||
iValeTo = GetBarTime(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
i //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (iPeakVerified >= validation &&
|
||||
iValeVerified >= validation)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Checking PV Pivots ...
|
||||
|
||||
//
|
||||
if (iPeakVerified >= validation)
|
||||
{
|
||||
//
|
||||
XPVPivot iPivot;
|
||||
|
||||
//
|
||||
iPivot.to = iPeakTo;
|
||||
iPivot.value = iPeak;
|
||||
iPivot.type = X_PV_PEAK;
|
||||
iPivot.golden = iPeakGolden;
|
||||
iPivot.symbol = GetSymbol();
|
||||
iPivot.period = GetPeriod();
|
||||
iPivot.from = ((datetime)iPeakTo - (PeriodSeconds(GetPeriod()) * iPeakVerified));
|
||||
|
||||
//
|
||||
if (iPivot.IsValid())
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iPivot,
|
||||
mPVPivots //
|
||||
);
|
||||
|
||||
//
|
||||
XBoxZone iBox;
|
||||
XCBoxObject *iObj;
|
||||
bool iHas = iPivot.AsBox(iBox);
|
||||
if (iHas)
|
||||
{
|
||||
//
|
||||
iHas = mPOIDrawer.DrawBox(
|
||||
iBox,
|
||||
iObj //
|
||||
);
|
||||
if (iHas)
|
||||
{
|
||||
Print("Peak Pivot ...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iPivot.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (iValeVerified >= validation)
|
||||
{
|
||||
//
|
||||
XPVPivot iPivot;
|
||||
|
||||
//
|
||||
iPivot.to = iValeTo;
|
||||
iPivot.value = iVale;
|
||||
iPivot.type = X_PV_VALE;
|
||||
iPivot.symbol = GetSymbol();
|
||||
iPivot.period = GetPeriod();
|
||||
iPivot.golden = iValeGolden;
|
||||
iPivot.from = ((datetime)iValeTo - (PeriodSeconds(GetPeriod()) * iValeVerified));
|
||||
|
||||
//
|
||||
if (iPivot.IsValid())
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iPivot,
|
||||
mPVPivots //
|
||||
);
|
||||
|
||||
//
|
||||
XBoxZone iBox;
|
||||
XCBoxObject *iObj;
|
||||
bool iHas = iPivot.AsBox(iBox);
|
||||
if (iHas)
|
||||
{
|
||||
//
|
||||
iHas = mPOIDrawer.DrawBox(
|
||||
iBox,
|
||||
iObj //
|
||||
);
|
||||
if (iHas)
|
||||
{
|
||||
Print("Vale Pivot ...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iPivot.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
DetectPVPivots(barIndex);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// Detect Support and Resistances ...
|
||||
XBoxZone tmpBoxes[];
|
||||
XBoxZone selectedSupRes[];
|
||||
count = provider.triggerState.SupportResistancesAsBox(tmpBoxes);
|
||||
has = IsValidSize(count);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XBoxZone iBox = tmpBoxes[i];
|
||||
|
||||
//
|
||||
// Validate Box ...
|
||||
bool isDirPassed = iBox.dir == selectedBox.dir;
|
||||
bool isPlacePassed = IsBoxInsideOr(iBox, selectedBox, true);
|
||||
has = isDirPassed &&
|
||||
isPlacePassed;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iBox,
|
||||
selectedSupRes //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpBoxes);
|
||||
}
|
||||
has = HasChild(selectedSupRes);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
count = ArraySize(selectedSupRes);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
selectedSupRes[i].to = TimeCurrent();
|
||||
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
has = drawer.DrawBox(
|
||||
selectedSupRes[i],
|
||||
iObj //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// double strSupport = 0;
|
||||
// datetime strIn = NULL;
|
||||
// datetime strOut = NULL;
|
||||
// bool isStrInBox = false;
|
||||
// double strResistance = 0;
|
||||
// bool isStrOutBox = false;
|
||||
// Checking STR Variables ...
|
||||
// CheckBoxStr(
|
||||
// cHelper,
|
||||
// selectedBox,
|
||||
// isStrInBox,
|
||||
// strIn,
|
||||
// isStrOutBox,
|
||||
// strOut,
|
||||
// strSupport,
|
||||
// strResistance //
|
||||
// );
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
bool IsFVGBoxValid(
|
||||
XBoxZone &box,
|
||||
ENUM_X_CYCLES cycle,
|
||||
X121SMCStrategySignalProviderData &provider //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = box.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XPOIStateEvents cStateEvents;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cStateEvents,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBoxBullish = box.IsBullish();
|
||||
|
||||
//
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
XBoxZone tmpBoxes[];
|
||||
count = cState.FairValueGapsAsBox(tmpBoxes);
|
||||
has = IsValidSize(count);
|
||||
|
||||
//
|
||||
// Check Must Contains Inner Cycle FVG ...
|
||||
XBoxZone selectedBox;
|
||||
bool hasSelectedBox = false;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XBoxZone iBox = tmpBoxes[i];
|
||||
|
||||
//
|
||||
// Regular Validation of Boxes ...
|
||||
bool isValid = IsBoxValid(
|
||||
iBox,
|
||||
0,
|
||||
iBox.period //
|
||||
);
|
||||
bool isTypePassed = iBox.dir == box.dir;
|
||||
bool isFromPssed = iBox.from >= box.from;
|
||||
bool isPlacePassed =
|
||||
IsBoxInsideOr(
|
||||
iBox,
|
||||
box //
|
||||
) &&
|
||||
(isBoxBullish
|
||||
? iBox.lower >= box.lower
|
||||
: iBox.upper <= box.upper);
|
||||
has =
|
||||
isValid &&
|
||||
isFromPssed &&
|
||||
isTypePassed &&
|
||||
isPlacePassed;
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
iBox.Clean();
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
has =
|
||||
!hasSelectedBox
|
||||
? true
|
||||
: isBoxBullish
|
||||
? selectedBox.upper > iBox.upper
|
||||
: selectedBox.lower < iBox.lower;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
selectedBox = iBox;
|
||||
hasSelectedBox = selectedBox.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = hasSelectedBox;
|
||||
|
||||
//
|
||||
// IGNORE Box Validations ...
|
||||
// if (result)
|
||||
// {
|
||||
// // //
|
||||
// // // From Index ...
|
||||
// // int fromIndex = GetBarIndex(
|
||||
// // selectedBox.symbol,
|
||||
// // selectedBox.period,
|
||||
// // selectedBox.from //
|
||||
// // ) +
|
||||
// // 1;
|
||||
// // result = IsValidIndex(fromIndex);
|
||||
|
||||
// // //
|
||||
// // // To Index ...
|
||||
// // int toIndex = GetBarIndex(
|
||||
// // selectedBox.symbol,
|
||||
// // selectedBox.period,
|
||||
// // selectedBox.to //
|
||||
// // );
|
||||
// // if (toIndex < 1)
|
||||
// // {
|
||||
// // toIndex = 1;
|
||||
// // }
|
||||
// // result = IsValidIndex(toIndex);
|
||||
|
||||
// // //
|
||||
// // // Now we Have Retrieve X121Conditions between from and to Indexes ...
|
||||
// // // for Check States ...
|
||||
|
||||
// // //
|
||||
// // bool hasNewValeUnderLast = false;
|
||||
// // bool isStrSwitchedToBullish = false;
|
||||
// // bool isSarSwitchedToBullish = false;
|
||||
// // bool hasValueGoldenZoneBreak = false;
|
||||
// // bool isSMHKSwitchedToBullish = false;
|
||||
// // bool isVWapSwitchedToBullishState = false;
|
||||
// // bool isX3MaSwitchedToBullishState = false;
|
||||
// // bool isVWapSwitchedToBullishOrdered = false;
|
||||
// // bool isX3MaSwitchedToBullishOrdered = false;
|
||||
|
||||
// // //
|
||||
// // bool hasNewPeakOverLast = false;
|
||||
// // bool isStrSwitchedToBearish = false;
|
||||
// // bool isSarSwitchedToBearish = false;
|
||||
// // bool hasPeakGoldenZoneBreak = false;
|
||||
// // bool isSMHKSwitchedToBearish = false;
|
||||
// // bool isVWapSwitchedToBearishState = false;
|
||||
// // bool isX3MaSwitchedToBearishState = false;
|
||||
// // bool isVWapSwitchedToBearishOrdered = false;
|
||||
// // bool isX3MaSwitchedToBearishOrdered = false;
|
||||
|
||||
// // //
|
||||
// // for (int i = fromIndex; i >= toIndex; i--)
|
||||
// // {
|
||||
// // //
|
||||
// // XOHCL iBar;
|
||||
// // has = iBar.Init(
|
||||
// // cState.symbol,
|
||||
// // cState.period,
|
||||
// // i //
|
||||
// // );
|
||||
// // X121Conditions iConditions;
|
||||
// // has = has &&
|
||||
// // cHelper.mX121Helper.GetConditions(
|
||||
// // iConditions,
|
||||
// // i //
|
||||
// // );
|
||||
// // if (!has)
|
||||
// // {
|
||||
// // continue;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // // Bullish ...
|
||||
|
||||
// // //
|
||||
// // if (!hasNewValeUnderLast)
|
||||
// // {
|
||||
// // hasNewValeUnderLast = iConditions.isNewValeUnderLast;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isStrSwitchedToBullish)
|
||||
// // {
|
||||
// // isStrSwitchedToBullish = iConditions.isStrSwitchedToBullish;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isSarSwitchedToBullish)
|
||||
// // {
|
||||
// // isSarSwitchedToBullish = iConditions.isSarSwitchedToBullish;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!hasValueGoldenZoneBreak)
|
||||
// // {
|
||||
// // //
|
||||
// // hasValueGoldenZoneBreak =
|
||||
// // iBar.IsBullish() &&
|
||||
// // iBar.GetUp() > iConditions.valesGoldenBuffer[1] &&
|
||||
// // iBar.GetDown() < iConditions.valesGoldenBuffer[1];
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isSMHKSwitchedToBullish)
|
||||
// // {
|
||||
// // isSMHKSwitchedToBullish = iConditions.isSMHKSwitchedToBullish;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isVWapSwitchedToBullishState)
|
||||
// // {
|
||||
// // isVWapSwitchedToBullishState = iConditions.isVWapSwitchedToBullishState;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isX3MaSwitchedToBullishState)
|
||||
// // {
|
||||
// // isX3MaSwitchedToBullishState = iConditions.isX3MaSwitchedToBullishState;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isVWapSwitchedToBullishOrdered)
|
||||
// // {
|
||||
// // isVWapSwitchedToBullishOrdered = iConditions.isVWapSwitchedToBullishOrdered;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isX3MaSwitchedToBullishOrdered)
|
||||
// // {
|
||||
// // isX3MaSwitchedToBullishOrdered = iConditions.isX3MaSwitchedToBullishOrdered;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // // Bearish ...
|
||||
|
||||
// // //
|
||||
// // if (!hasNewPeakOverLast)
|
||||
// // {
|
||||
// // hasNewPeakOverLast = iConditions.isNewPeakOverLast;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isStrSwitchedToBearish)
|
||||
// // {
|
||||
// // isStrSwitchedToBearish = iConditions.isStrSwitchedToBearish;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isSarSwitchedToBearish)
|
||||
// // {
|
||||
// // isSarSwitchedToBearish = iConditions.isSarSwitchedToBearish;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!hasPeakGoldenZoneBreak)
|
||||
// // {
|
||||
// // //
|
||||
// // hasPeakGoldenZoneBreak =
|
||||
// // iBar.IsBearish() &&
|
||||
// // iBar.GetUp() > iConditions.peaksGoldenBuffer[1] &&
|
||||
// // iBar.GetDown() < iConditions.peaksGoldenBuffer[1];
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isSMHKSwitchedToBearish)
|
||||
// // {
|
||||
// // isSMHKSwitchedToBearish = iConditions.isSMHKSwitchedToBearish;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isVWapSwitchedToBearishState)
|
||||
// // {
|
||||
// // isVWapSwitchedToBearishState = iConditions.isVWapSwitchedToBearishState;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isX3MaSwitchedToBearishState)
|
||||
// // {
|
||||
// // isX3MaSwitchedToBearishState = iConditions.isX3MaSwitchedToBearishState;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isVWapSwitchedToBearishOrdered)
|
||||
// // {
|
||||
// // isVWapSwitchedToBearishOrdered = iConditions.isVWapSwitchedToBearishOrdered;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // if (!isX3MaSwitchedToBearishOrdered)
|
||||
// // {
|
||||
// // isX3MaSwitchedToBearishOrdered = iConditions.isX3MaSwitchedToBearishOrdered;
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // iConditions.Clean();
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // // Bullish Conditions Summary ...
|
||||
|
||||
// // //
|
||||
// // bool hasBullishOrConditions =
|
||||
// // hasNewValeUnderLast ||
|
||||
// // isStrSwitchedToBullish ||
|
||||
// // isSarSwitchedToBullish ||
|
||||
// // hasValueGoldenZoneBreak ||
|
||||
// // isSMHKSwitchedToBullish ||
|
||||
// // isVWapSwitchedToBullishState ||
|
||||
// // isX3MaSwitchedToBullishState ||
|
||||
// // isVWapSwitchedToBullishOrdered ||
|
||||
// // isX3MaSwitchedToBullishOrdered;
|
||||
|
||||
// // //
|
||||
// // bool hasBullishAndConditions =
|
||||
// // hasNewValeUnderLast &&
|
||||
// // hasValueGoldenZoneBreak &&
|
||||
// // (isStrSwitchedToBullish ||
|
||||
// // isSarSwitchedToBullish ||
|
||||
// // isSMHKSwitchedToBullish ||
|
||||
// // isVWapSwitchedToBullishState ||
|
||||
// // isX3MaSwitchedToBullishState ||
|
||||
// // isVWapSwitchedToBullishOrdered ||
|
||||
// // isX3MaSwitchedToBullishOrdered);
|
||||
|
||||
// // //
|
||||
// // // Bearish Conditions Summary ...
|
||||
|
||||
// // //
|
||||
// // bool hasBearishOrConditions =
|
||||
// // hasNewPeakOverLast ||
|
||||
// // isStrSwitchedToBearish ||
|
||||
// // isSarSwitchedToBearish ||
|
||||
// // hasPeakGoldenZoneBreak ||
|
||||
// // isSMHKSwitchedToBearish ||
|
||||
// // isVWapSwitchedToBearishState ||
|
||||
// // isX3MaSwitchedToBearishState ||
|
||||
// // isVWapSwitchedToBearishOrdered ||
|
||||
// // isX3MaSwitchedToBearishOrdered;
|
||||
|
||||
// // //
|
||||
// // bool hasBearishAndConditions =
|
||||
// // hasNewPeakOverLast &&
|
||||
// // hasPeakGoldenZoneBreak &&
|
||||
// // (isStrSwitchedToBearish ||
|
||||
// // isSarSwitchedToBearish ||
|
||||
// // isSMHKSwitchedToBearish ||
|
||||
// // isVWapSwitchedToBearishState ||
|
||||
// // isX3MaSwitchedToBearishState ||
|
||||
// // isVWapSwitchedToBearishOrdered ||
|
||||
// // isX3MaSwitchedToBearishOrdered);
|
||||
|
||||
// //
|
||||
// bool isBullish =
|
||||
// isBoxBullish
|
||||
// // &&
|
||||
// // !hasBearishOrConditions &&
|
||||
// // hasBullishOrConditions
|
||||
// ;
|
||||
|
||||
// //
|
||||
// bool isBearish =
|
||||
// !isBoxBullish
|
||||
// // &&
|
||||
// // !hasBullishOrConditions &&
|
||||
// // hasBearishOrConditions
|
||||
// ;
|
||||
|
||||
// //
|
||||
// result = isBullish ||
|
||||
// isBearish;
|
||||
|
||||
// //
|
||||
// // if (result)
|
||||
// // {
|
||||
// // //
|
||||
// // XCBoxObject *iBoxObj;
|
||||
// // XCBoxObject *iInBoxObj;
|
||||
|
||||
// // //
|
||||
// // has = provider
|
||||
// // .verificationCycleHelper
|
||||
// // .mPOIDrawer
|
||||
// // .DrawBox(
|
||||
// // box,
|
||||
// // iBoxObj //
|
||||
// // );
|
||||
// // if (has)
|
||||
// // {
|
||||
// // //
|
||||
// // iBoxObj.BoxWidth(2);
|
||||
// // iBoxObj.BoxStyle(STYLE_SOLID);
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // has = provider
|
||||
// // .verificationCycleHelper
|
||||
// // .mPOIDrawer
|
||||
// // .DrawBox(
|
||||
// // selectedBox,
|
||||
// // iInBoxObj //
|
||||
// // );
|
||||
// // if (has)
|
||||
// // {
|
||||
// // //
|
||||
// // iInBoxObj.BoxWidth(2);
|
||||
// // iInBoxObj.BoxStyle(STYLE_DASH);
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // Print("Inside Selected Box ...");
|
||||
// // }
|
||||
// }
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
cState.Clean();
|
||||
Clean(tmpBoxes);
|
||||
selectedBox.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,637 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XSTR
|
||||
// Description: XSTR ...
|
||||
//
|
||||
//
|
||||
// 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 XSTR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XSTR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int strLength = 14; // Length
|
||||
input double strMultiplier = 3; // Multiplier
|
||||
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input bool showStr = true; // Show Str
|
||||
input bool showStrUpper = true; // Show Str Upper
|
||||
input bool showStrLower = true; // Show Str Lower
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// STR ...
|
||||
#define strBufferIndex 0
|
||||
double strBuffer[];
|
||||
|
||||
#define strColorBufferIndex 1
|
||||
double strColorBuffer[];
|
||||
|
||||
//
|
||||
#define strPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 STR"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Up ...
|
||||
#define strUpBufferIndex 2
|
||||
double strUpBuffer[];
|
||||
|
||||
//
|
||||
#define strUpPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 STR U"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 C'255,106,0'
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Down ...
|
||||
#define strDownBufferIndex 3
|
||||
double strDownBuffer[];
|
||||
|
||||
//
|
||||
#define strDownPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 STR D"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 C'255,106,0'
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 3;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
// Atr ...
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define strPriceBufferIndex mLastBufferIndex + 2
|
||||
double strPriceBuffer[];
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define strStateBufferIndex mLastBufferIndex + 3
|
||||
double strStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength //
|
||||
);
|
||||
bool isInited = atrHandler != 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();
|
||||
|
||||
//
|
||||
// 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(atrHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ...
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? maxLength
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, rates_total, atrBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !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 =
|
||||
//
|
||||
// STR ...
|
||||
strLength > 0 &&
|
||||
strMultiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(1, strLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateStr(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
strBuffer[barIndex] = 0;
|
||||
strUpBuffer[barIndex] = 0;
|
||||
strDownBuffer[barIndex] = 0;
|
||||
strPriceBuffer[barIndex] = 0;
|
||||
strColorBuffer[barIndex] = hideColorIDX;
|
||||
strStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate STR ...
|
||||
*
|
||||
* @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 ...
|
||||
*/
|
||||
void CalculateStr(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
ENUM_X_PRICE mPTYpe = ToXPrice(strAppliedTo);
|
||||
double price = GetAppliedPrice(
|
||||
mPTYpe,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
strPriceBuffer[bar_index] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
strUpBuffer[bar_index] = price + (strMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
strDownBuffer[bar_index] = price - (strMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = hideColorIDX;
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strDownBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bullishColorIDX;
|
||||
}
|
||||
else if (strStateBuffer[bar_index] == -1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strUpBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bearishColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showStr)
|
||||
{
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,793 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XSTR
|
||||
// Description: XSTR ...
|
||||
//
|
||||
//
|
||||
// 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 XSTR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XSTR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int strLength = 14; // Length
|
||||
input double strMultiplier = 3; // Multiplier
|
||||
input ENUM_MA_METHOD strBoundaryMode = MODE_SMA; // Boundary Mode
|
||||
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showStr = true; // Show Str
|
||||
input bool showStrMid = true; // Show Str Mid
|
||||
input bool showStrUpper = true; // Show Str Upper
|
||||
input bool showStrLower = true; // Show Str Lower
|
||||
input bool showStrLowMa = true; // Show Low Smoothed Buffer
|
||||
input bool showStrHighMa = true; // Show High Smoothed Buffer
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 11
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// STR ...
|
||||
#define strBufferIndex 0
|
||||
double strBuffer[];
|
||||
|
||||
#define strColorBufferIndex 1
|
||||
double strColorBuffer[];
|
||||
|
||||
//
|
||||
#define strPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 STR"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Up ...
|
||||
#define strUpBufferIndex 2
|
||||
double strUpBuffer[];
|
||||
|
||||
//
|
||||
#define strUpPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 STR U"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrBlueViolet
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Down ...
|
||||
#define strDownBufferIndex 3
|
||||
double strDownBuffer[];
|
||||
|
||||
//
|
||||
#define strDownPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 STR D"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrBlueViolet
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// High MA ...
|
||||
#define strHighMaBufferIndex 4
|
||||
double strHighMaBuffer[];
|
||||
|
||||
//
|
||||
#define strHighMaPlotBufferIndex 3
|
||||
#property indicator_label4 "X121 STR HSM"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAqua
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
#define strLowMaBufferIndex 5
|
||||
double strLowMaBuffer[];
|
||||
|
||||
//
|
||||
#define strLowMaPlotBufferIndex 4
|
||||
#property indicator_label5 "X121 STR LSM"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrMagenta
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// STR Mmid ...
|
||||
#define strMidBufferIndex 6
|
||||
double strMidBuffer[];
|
||||
|
||||
#define strMidColorBufferIndex 7
|
||||
double strMidColorBuffer[];
|
||||
|
||||
//
|
||||
#define strMidPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 STR Mid"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
// Atr ...
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define strPriceBufferIndex mLastBufferIndex + 2
|
||||
double strPriceBuffer[];
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define strStateBufferIndex mLastBufferIndex + 3
|
||||
double strStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// MA Handler ...
|
||||
int lowMaHandler = INVALID_HANDLE;
|
||||
int highMaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength //
|
||||
);
|
||||
bool isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_LOW //
|
||||
);
|
||||
isInited = lowMaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
highMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_HIGH //
|
||||
);
|
||||
isInited = highMaHandler != 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();
|
||||
|
||||
//
|
||||
// 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(atrHandler);
|
||||
IndicatorRelease(lowMaHandler);
|
||||
IndicatorRelease(highMaHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ...
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int lowMaCalculatedBars = BarsCalculated(lowMaHandler);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int highMaCalculatedBars = BarsCalculated(highMaHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaCalculatedBars >= 0 &&
|
||||
//
|
||||
// High Ma ...
|
||||
highMaCalculatedBars >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? maxLength
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, rates_total, atrBuffer);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int copiedLowMas = CopyBuffer(lowMaHandler, 0, 0, rates_total, strLowMaBuffer);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int copiedHighMas = CopyBuffer(highMaHandler, 0, 0, rates_total, strHighMaBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
copiedLowMas >= 0 &&
|
||||
//
|
||||
// Hig Ma ...
|
||||
copiedHighMas >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !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 =
|
||||
//
|
||||
// STR ...
|
||||
strLength > 0 &&
|
||||
strMultiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(1, strLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strLowMaDrawType = showStrLowMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strLowMaBufferIndex, strLowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strLowMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_SHOW_DATA, showStrLowMa);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_DRAW_TYPE, strLowMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strHighMaDrawType = showStrHighMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strHighMaBufferIndex, strHighMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strHighMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_SHOW_DATA, showStrHighMa);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_DRAW_TYPE, strHighMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strMidDrawType = showStrMid ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strMidBufferIndex, strMidBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strMidColorBufferIndex, strMidColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
PlotIndexSetDouble(strMidPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strMidPlotBufferIndex, PLOT_SHOW_DATA, showStrMid);
|
||||
PlotIndexSetInteger(strMidPlotBufferIndex, PLOT_DRAW_TYPE, strMidDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateStr(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
strBuffer[barIndex] = emptyValue;
|
||||
strUpBuffer[barIndex] = emptyValue;
|
||||
strMidBuffer[barIndex] = emptyValue;
|
||||
strMidBuffer[barIndex] = emptyValue;
|
||||
strDownBuffer[barIndex] = emptyValue;
|
||||
strPriceBuffer[barIndex] = emptyValue;
|
||||
strLowMaBuffer[barIndex] = emptyValue;
|
||||
strHighMaBuffer[barIndex] = emptyValue;
|
||||
|
||||
//
|
||||
strColorBuffer[barIndex] = hideColorIDX;
|
||||
strStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate STR ...
|
||||
*
|
||||
* @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 ...
|
||||
*/
|
||||
void CalculateStr(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
ENUM_X_PRICE mPType = ToXPrice(strAppliedTo);
|
||||
double price = GetAppliedPrice(
|
||||
mPType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
strPriceBuffer[bar_index] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
strUpBuffer[bar_index] = price + (strMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
strDownBuffer[bar_index] = price - (strMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = hideColorIDX;
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strDownBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bullishColorIDX;
|
||||
}
|
||||
else if (strStateBuffer[bar_index] == -1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strUpBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bearishColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showStr)
|
||||
{
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// Str Mid ...
|
||||
|
||||
//
|
||||
double iStrMid = strDownBuffer[bar_index] + ((strUpBuffer[bar_index] - strDownBuffer[bar_index]) / 2);
|
||||
strMidBuffer[bar_index] = iStrMid;
|
||||
|
||||
//
|
||||
double iStrColor = close[bar_index] > strMidBuffer[bar_index]
|
||||
? bullishColorIDX
|
||||
: close[bar_index] < strMidBuffer[bar_index]
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
strMidColorBuffer[bar_index] = iStrColor;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user