complete rms tools ea ...
This commit is contained in:
@@ -1441,7 +1441,15 @@ struct X121SMCStrategySignalProviderData
|
||||
}
|
||||
|
||||
//
|
||||
if (cycle == X_CYCLE_DECISION)
|
||||
if (cycle == X_CYCLE_TRIGGER)
|
||||
{
|
||||
//
|
||||
cState = triggerState;
|
||||
cHelper = triggerCycleHelper;
|
||||
cConditions = triggerConditions;
|
||||
cXConditions = triggerXConditions;
|
||||
}
|
||||
else if (cycle == X_CYCLE_DECISION)
|
||||
{
|
||||
//
|
||||
cState = decisionState;
|
||||
@@ -1457,6 +1465,14 @@ struct X121SMCStrategySignalProviderData
|
||||
cConditions = analyseConditions;
|
||||
cXConditions = analyseXConditions;
|
||||
}
|
||||
else if (cycle == X_CYCLE_VERIFICATION)
|
||||
{
|
||||
//
|
||||
cState = verificationState;
|
||||
cHelper = verificationCycleHelper;
|
||||
cConditions = verificationConditions;
|
||||
cXConditions = verificationXConditions;
|
||||
}
|
||||
else if (cycle == X_CYCLE_CONSOLIDATION)
|
||||
{
|
||||
//
|
||||
@@ -2577,6 +2593,586 @@ struct X121SMCStrategyConditionParser
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// Detecting Signal Conditions ...
|
||||
|
||||
//
|
||||
// Bullish Conditions ...
|
||||
isBullish =
|
||||
//
|
||||
// Base Condition ...
|
||||
cXConditions.isSMHKSwitchedToBullish &&
|
||||
(
|
||||
//
|
||||
// Validate CBar ...
|
||||
cBar.IsBullish() &&
|
||||
cBar.open >= cSMHKBar.open &&
|
||||
//
|
||||
cXConditions.isSarBullish
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Bearish Conditions ...
|
||||
isBearish =
|
||||
//
|
||||
// Base Condition ...
|
||||
cXConditions.isSMHKSwitchedToBearish &&
|
||||
(
|
||||
//
|
||||
// Validate CBar ...
|
||||
cBar.IsBearish() &&
|
||||
cBar.open <= cSMHKBar.open &&
|
||||
//
|
||||
cXConditions.isSarBearish
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = cXConditions.symbol;
|
||||
box.period = cXConditions.period;
|
||||
|
||||
//
|
||||
int fromIDX = -1;
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
double vale = cXConditions.valesBuffer[cIDX];
|
||||
box.lower = vale;
|
||||
box.upper = cXConditions.valesGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
int lowerValeIDX = -1;
|
||||
double lowerVale = cHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerVale(
|
||||
lowerValeIDX,
|
||||
vale,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
int higherValeIDX = -1;
|
||||
double higherVale = cHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherVale(
|
||||
higherValeIDX,
|
||||
vale,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidIndex(lowerValeIDX) &&
|
||||
IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX =
|
||||
lowerValeIDX < higherValeIDX
|
||||
? lowerValeIDX
|
||||
: higherValeIDX;
|
||||
}
|
||||
else if (IsValidIndex(lowerValeIDX) &&
|
||||
!IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = lowerValeIDX;
|
||||
}
|
||||
else if (!IsValidIndex(lowerValeIDX) &&
|
||||
IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = higherValeIDX;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double peak = cXConditions.peaksBuffer[cIDX];
|
||||
box.upper = peak;
|
||||
|
||||
//
|
||||
box.lower = cXConditions.peaksGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
int lowerPeakIDX = -1;
|
||||
double lowerPeak = cHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerPeak(
|
||||
lowerPeakIDX,
|
||||
peak,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
int higherPeakIDX = -1;
|
||||
double higherPeak = cHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherPeak(
|
||||
higherPeakIDX,
|
||||
peak,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidIndex(lowerPeakIDX) &&
|
||||
IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX =
|
||||
lowerPeakIDX < higherPeakIDX
|
||||
? lowerPeakIDX
|
||||
: higherPeakIDX;
|
||||
}
|
||||
else if (IsValidIndex(lowerPeakIDX) &&
|
||||
!IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = lowerPeakIDX;
|
||||
}
|
||||
else if (!IsValidIndex(lowerPeakIDX) &&
|
||||
IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = higherPeakIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValidIndex(fromIDX))
|
||||
{
|
||||
//
|
||||
box.from = iTime(
|
||||
zBar.symbol,
|
||||
zBar.period,
|
||||
fromIDX //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
box.from = pBar.time;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Holder Box ...
|
||||
XBoxZone tmpBoxes[];
|
||||
if (chState.IsValid())
|
||||
{
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
// Demand Zones ...
|
||||
XBoxZone tmp[];
|
||||
ToBox(
|
||||
chState.demandZones,
|
||||
tmp //
|
||||
);
|
||||
Copy(
|
||||
tmp,
|
||||
tmpBoxes,
|
||||
false //
|
||||
);
|
||||
Clean(tmp);
|
||||
|
||||
//
|
||||
// Bullish Order Blocks ...
|
||||
ToBox(
|
||||
chState.bullishOrderBlocks,
|
||||
tmp //
|
||||
);
|
||||
Copy(
|
||||
tmp,
|
||||
tmpBoxes,
|
||||
false //
|
||||
);
|
||||
Clean(tmp);
|
||||
|
||||
//
|
||||
// Bullish Fair Value Gaps ...
|
||||
ToBox(
|
||||
chState.bullishFairValueGaps,
|
||||
tmp //
|
||||
);
|
||||
Copy(
|
||||
tmp,
|
||||
tmpBoxes,
|
||||
false //
|
||||
);
|
||||
Clean(tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Supply Zones ...
|
||||
XBoxZone tmp[];
|
||||
ToBox(
|
||||
chState.supplyZones,
|
||||
tmp //
|
||||
);
|
||||
Copy(
|
||||
tmp,
|
||||
tmpBoxes,
|
||||
false //
|
||||
);
|
||||
Clean(tmp);
|
||||
|
||||
//
|
||||
// Bearish Order Blocks ...
|
||||
ToBox(
|
||||
chState.bearishOrderBlocks,
|
||||
tmp //
|
||||
);
|
||||
Copy(
|
||||
tmp,
|
||||
tmpBoxes,
|
||||
false //
|
||||
);
|
||||
Clean(tmp);
|
||||
|
||||
//
|
||||
// Bearish Fair Value Gaps ...
|
||||
ToBox(
|
||||
chState.bearishFairValueGaps,
|
||||
tmp //
|
||||
);
|
||||
Copy(
|
||||
tmp,
|
||||
tmpBoxes,
|
||||
false //
|
||||
);
|
||||
Clean(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = HasChild(tmpBoxes);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
while (HasChild(tmpBoxes))
|
||||
{
|
||||
//
|
||||
idx = GetOldest(tmpBoxes);
|
||||
has = IsValidIndex(idx);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone iBox = tmpBoxes[idx];
|
||||
ArrayRemove(
|
||||
tmpBoxes,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
has = IsBoxInside(
|
||||
box,
|
||||
iBox //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
holderBox = iBox;
|
||||
holderBox.to = TimeCurrent();
|
||||
iBox.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpBoxes);
|
||||
|
||||
//
|
||||
// Fix Box Upper and Lower based on Strategy ...
|
||||
|
||||
//
|
||||
double points = GetPoints(box.symbol);
|
||||
double minPointsDiff = points * 20;
|
||||
|
||||
// //
|
||||
// double prefferSL = 0;
|
||||
|
||||
// //
|
||||
// // First Check Based on Prev Bar ...
|
||||
// // double prevDiff =
|
||||
// // isBullish
|
||||
// // ? cBar.low < zBar.open
|
||||
// // ? zBar.open - cBar.low
|
||||
// // : 0
|
||||
// // : isBearish
|
||||
// // ? cBar.high > zBar.open
|
||||
// // ? cBar.high - zBar.open
|
||||
// // : 0
|
||||
// // : 0;
|
||||
// // if (prevDiff >= minPointsDiff)
|
||||
// // {
|
||||
// // //
|
||||
// // prefferSL =
|
||||
// // isBullish
|
||||
// // ? cBar.low
|
||||
// // : cBar.high;
|
||||
// // }
|
||||
|
||||
// //
|
||||
// // Other SL Conditions ...
|
||||
// if (prefferSL <= 0)
|
||||
// {
|
||||
// //
|
||||
// if (isBullish)
|
||||
// {
|
||||
// //
|
||||
// if (zBar.open < cXConditions.valesGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.valesBuffer[cIDX];
|
||||
// }
|
||||
// else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.valesGoldenBuffer[cIDX];
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //
|
||||
// if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.peaksBuffer[cIDX];
|
||||
// }
|
||||
// else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX])
|
||||
// {
|
||||
// prefferSL = cXConditions.peaksGoldenBuffer[cIDX];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (prefferSL > 0)
|
||||
// {
|
||||
// //
|
||||
// prefferSL =
|
||||
// prefferSL <= minPointsDiff
|
||||
// ? minPointsDiff
|
||||
// : prefferSL;
|
||||
|
||||
// //
|
||||
// box.upper =
|
||||
// isBullish
|
||||
// ? zBar.open
|
||||
// : prefferSL;
|
||||
|
||||
// //
|
||||
// box.lower =
|
||||
// isBullish
|
||||
// ? prefferSL
|
||||
// : zBar.open;
|
||||
// }
|
||||
|
||||
//
|
||||
// Validate Conditions to Force Has Holder Box ...
|
||||
result =
|
||||
result &&
|
||||
holderBox.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
chState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
ZeroMemory(chHelper);
|
||||
chConditions.Clean();
|
||||
chXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool HasSenario4Conditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
XBoxZone &box,
|
||||
XBoxZone &holderBox,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
ENUM_X_CYCLES holderCycle = X_CYCLE_NONE,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Parse(cXConditions);
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState chState;
|
||||
X121Conditions chXConditions;
|
||||
XC121SMCCycleHelper *chHelper;
|
||||
X121SMCCycleConditions chConditions;
|
||||
if (holderCycle != X_CYCLE_NONE)
|
||||
{
|
||||
//
|
||||
result = provider.SelectCycle(
|
||||
holderCycle,
|
||||
chState,
|
||||
chXConditions,
|
||||
chHelper,
|
||||
chConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
chState.Clean();
|
||||
ZeroMemory(chHelper);
|
||||
chConditions.Clean();
|
||||
chXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Parse(chXConditions);
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
holderBox.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
cState.symbol,
|
||||
cState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
chState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
ZeroMemory(chHelper);
|
||||
chConditions.Clean();
|
||||
chXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detecting Signal Conditions ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user