Last ...
This commit is contained in:
@@ -773,13 +773,18 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
|
||||
iObj.SLColor(clrRed);
|
||||
iObj.SLWidth(STYLE_DOT);
|
||||
|
||||
//
|
||||
iObj.TargetWidth(1);
|
||||
iObj.TargetColor(clrLightBlue);
|
||||
iObj.TargetWidth(STYLE_DOT);
|
||||
|
||||
//
|
||||
iObj.EntryWidth(1);
|
||||
iObj.EntryColor(clrYellow);
|
||||
iObj.EntryWidth(STYLE_DOT);
|
||||
|
||||
//
|
||||
mDrawnObjects.Add(iObj);
|
||||
// mDrawnObjects.Add(iObj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -622,6 +622,605 @@ class XC121SMCCycleHelper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Specified Pivot's State ...
|
||||
*
|
||||
* @param pivot: XPVPivot instance Reference ...
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void ValidatePivotState(
|
||||
XPVPivot &pivot,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
if (!pivot.IsValid() ||
|
||||
!pivot.state.IsValid() ||
|
||||
!pivot.state.HasChild())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double upperr = pivot.upper;
|
||||
double lower = pivot.lower;
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
bool isInited = cBar.Init(
|
||||
pivot.symbol,
|
||||
pivot.period,
|
||||
barIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int count = 0;
|
||||
|
||||
//
|
||||
double ask = GetAsk(pivot.symbol);
|
||||
double bid = GetBid(pivot.symbol);
|
||||
|
||||
//
|
||||
double pivotMid = pivot.CalculateMid();
|
||||
|
||||
//
|
||||
// Try to Validate States ...
|
||||
|
||||
//
|
||||
bool isPriceInPremium =
|
||||
//
|
||||
ask > pivotMid &&
|
||||
bid > pivotMid &&
|
||||
cBar.low > pivotMid
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPriceInDiscount =
|
||||
//
|
||||
ask < pivotMid &&
|
||||
bid < pivotMid &&
|
||||
cBar.high < pivotMid
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Swings ...
|
||||
XCSwing *tmpSwings[];
|
||||
|
||||
//
|
||||
// Swing Highs ...
|
||||
Clean(tmpSwings);
|
||||
count = pivot.state.CountSwingHighs();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInPremium)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCSwing *iSwing = pivot.state.swingHighs[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iSwing.GetTime() >= pivot.from &&
|
||||
iSwing.GetTime() <= pivot.to &&
|
||||
iSwing.GetValue() > pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iSwing,
|
||||
tmpSwings //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpSwings,
|
||||
pivot.state.swingHighs //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Lows ...
|
||||
Clean(tmpSwings);
|
||||
count = pivot.state.CountSwingLows();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInDiscount)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCSwing *iSwing = pivot.state.swingLows[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iSwing.GetTime() >= pivot.from &&
|
||||
iSwing.GetTime() <= pivot.to &&
|
||||
iSwing.GetValue() < pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iSwing,
|
||||
tmpSwings //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpSwings,
|
||||
pivot.state.swingLows //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpSwings);
|
||||
|
||||
//
|
||||
// Rejection Bars ...
|
||||
XCRejectionBar *tmpRejections[];
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
Clean(tmpRejections);
|
||||
count = pivot.state.CountBullishRejectionBars();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInDiscount)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCRejectionBar *iRejection = pivot.state.bullishRejectionBars[i];
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
bool isFilled = iRejection.FillBar(iBar);
|
||||
if (!isFilled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iRejection.BarTime() >= pivot.from &&
|
||||
iBar.high < pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iRejection,
|
||||
tmpRejections //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpRejections,
|
||||
pivot.state.bullishRejectionBars //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
Clean(tmpRejections);
|
||||
count = pivot.state.CountBearishRejectionBars();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInPremium)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCRejectionBar *iRejection = pivot.state.bearishRejectionBars[i];
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
bool isFilled = iRejection.FillBar(iBar);
|
||||
if (!isFilled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iRejection.BarTime() >= pivot.from &&
|
||||
iBar.low > pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iRejection,
|
||||
tmpRejections //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpRejections,
|
||||
pivot.state.bearishRejectionBars //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpRejections);
|
||||
|
||||
//
|
||||
// Support Zone ...
|
||||
XCSupportZone *tmpSupports[];
|
||||
count = pivot.state.CountSupportZones();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInDiscount)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCSupportZone *iZone = pivot.state.supportZones[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Upper() < pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpSupports //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpSupports,
|
||||
pivot.state.supportZones //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpSupports);
|
||||
|
||||
//
|
||||
// Resistance Zone ...
|
||||
XCResistanceZone *tmpResistances[];
|
||||
count = pivot.state.CountResistanceZones();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInPremium)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCResistanceZone *iZone = pivot.state.resistanceZones[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Lower() > pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpResistances //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpResistances,
|
||||
pivot.state.resistanceZones //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpResistances);
|
||||
|
||||
//
|
||||
// Supply Zones ...
|
||||
XCSupplyZone *tmpSupplies[];
|
||||
count = pivot.state.CountSupplyZones();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInPremium)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCSupplyZone *iZone = pivot.state.supplyZones[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Lower() > pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpSupplies //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpSupplies,
|
||||
pivot.state.supplyZones //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpSupplies);
|
||||
|
||||
//
|
||||
// Demand Zones ...
|
||||
XCDemandZone *tmpDemands[];
|
||||
count = pivot.state.CountDemandZones();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInDiscount)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCDemandZone *iZone = pivot.state.demandZones[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Upper() < pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpDemands //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpDemands,
|
||||
pivot.state.demandZones //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpDemands);
|
||||
|
||||
//
|
||||
// Order Blocks ...
|
||||
XCOrderBlock *tmpOrderBlocks[];
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
Clean(tmpOrderBlocks);
|
||||
count = pivot.state.CountBullishOrderBlocks();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInDiscount)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *iZone = pivot.state.bullishOrderBlocks[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Upper() < pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpOrderBlocks //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpOrderBlocks,
|
||||
pivot.state.bullishOrderBlocks //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
Clean(tmpOrderBlocks);
|
||||
count = pivot.state.CountBearishOrderBlocks();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInPremium)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *iZone = pivot.state.bearishOrderBlocks[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Lower() > pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpOrderBlocks //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpOrderBlocks,
|
||||
pivot.state.bearishOrderBlocks //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpOrderBlocks);
|
||||
|
||||
//
|
||||
// Fair Value Gaps ...
|
||||
XCFVG *tmpFVGs[];
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
Clean(tmpFVGs);
|
||||
count = pivot.state.CountBullishFairValueGaps();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInDiscount)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCFVG *iZone = pivot.state.bullishFairValueGaps[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Upper() < pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpFVGs //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpFVGs,
|
||||
pivot.state.bullishFairValueGaps //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
Clean(tmpFVGs);
|
||||
count = pivot.state.CountBearishFairValueGaps();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
if (isPriceInPremium)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCFVG *iZone = pivot.state.bearishFairValueGaps[i];
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
//
|
||||
iZone.Lower() > pivotMid
|
||||
//
|
||||
;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iZone,
|
||||
tmpFVGs //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Copy(
|
||||
tmpFVGs,
|
||||
pivot.state.bearishFairValueGaps //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmpFVGs);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Cycle Trend Based On Pivots ...
|
||||
*
|
||||
@@ -1173,7 +1772,7 @@ class XC121SMCCycleHelper : public XCBase
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int FillPivotPointss(XPVPivotPoint &pivots[])
|
||||
int FillPivotPoints(XPVPivotPoint &pivots[])
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
@@ -2020,6 +2619,14 @@ class XC121SMCCycleHelper : public XCBase
|
||||
//
|
||||
mActivePeakPivot.repetition++;
|
||||
mActivePeakPivot.to = changeBar.time;
|
||||
|
||||
//
|
||||
if (mActivePeakPivot.IsValid())
|
||||
{
|
||||
//
|
||||
FillPivotState(mActivePeakPivot);
|
||||
ValidatePivotState(mActivePeakPivot, barIndex);
|
||||
}
|
||||
}
|
||||
else if (mActivePeakPivot.upper > 0 && mActivePeakPivot.upper != peak)
|
||||
{
|
||||
@@ -2083,6 +2690,14 @@ class XC121SMCCycleHelper : public XCBase
|
||||
//
|
||||
mActiveValePivot.repetition++;
|
||||
mActiveValePivot.to = changeBar.time;
|
||||
|
||||
//
|
||||
if (mActiveValePivot.IsValid())
|
||||
{
|
||||
//
|
||||
FillPivotState(mActiveValePivot);
|
||||
ValidatePivotState(mActiveValePivot, barIndex);
|
||||
}
|
||||
}
|
||||
else if (mActiveValePivot.lower > 0 && mActiveValePivot.lower != vale)
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ struct X121SMCTradeData
|
||||
double commission; // Commission
|
||||
string conditions; // Signal Conditions
|
||||
double maxDrawdown; // Max Position Drawdown
|
||||
bool isTargeted; // Check Targetted Before Or Not
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
@@ -110,6 +111,9 @@ struct X121SMCTradeData
|
||||
startTime = NULL;
|
||||
conditions = NULL;
|
||||
|
||||
//
|
||||
isTargeted = false;
|
||||
|
||||
//
|
||||
signal.Clean();
|
||||
}
|
||||
@@ -2901,7 +2905,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
mTrader.GetPositions(
|
||||
longs,
|
||||
shorts,
|
||||
signal.symbol,
|
||||
signal.symbol,
|
||||
signal.provider //
|
||||
);
|
||||
}
|
||||
@@ -3099,6 +3103,13 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
AlertSignalExecutionFailed(
|
||||
signal,
|
||||
state //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -3141,17 +3152,11 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
|
||||
//
|
||||
// Alert Signal Execution Failed ...
|
||||
string msg = "Failed To Execute " +
|
||||
(signal.type == POSITION_TYPE_BUY ? "Long" : "Short") +
|
||||
" Signal Provided by: " + signal.provider +
|
||||
(signal.pushers > 1 ? " Pushers: " + ToString(signal.pushers) : "") +
|
||||
" on: " + signal.symbol +
|
||||
" in: " + ToString(signal.period) +
|
||||
" due Reason: " + ToString(state) + " ...";
|
||||
Alert(msg);
|
||||
AlertSignalExecutionFailed(
|
||||
signal,
|
||||
state //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -3411,13 +3416,20 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
//
|
||||
// Handle RF On Target ...
|
||||
double target = iData.Target();
|
||||
double targetDelta = isLong
|
||||
? target + (15 * points)
|
||||
: target - (15 * points);
|
||||
bool canRF =
|
||||
target > 0 &&
|
||||
target > entry &&
|
||||
!iData.isTargeted &&
|
||||
(isLong ? target > entry
|
||||
: target < entry) &&
|
||||
(isLong
|
||||
? iPosition.sl < target
|
||||
: iPosition.sl > target) &&
|
||||
iPosition.price > target + (10 * points);
|
||||
(isLong
|
||||
? iPosition.price > targetDelta
|
||||
: iPosition.price < targetDelta);
|
||||
if (canRF)
|
||||
{
|
||||
//
|
||||
@@ -3432,6 +3444,9 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
);
|
||||
if (isModified)
|
||||
{
|
||||
//
|
||||
mData[i].isTargeted = true;
|
||||
|
||||
//
|
||||
string message = ToString(iData.Type()) +
|
||||
" Position: " +
|
||||
@@ -3529,7 +3544,22 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
XSymbolLastPosition mLastExecutedSignals[]; // Last Executed Signals
|
||||
|
||||
//
|
||||
// Hedge Related Functions ...
|
||||
void AlertSignalExecutionFailed(
|
||||
XSignal &signal,
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Alert Signal Execution Failed ...
|
||||
string msg = "Failed To Execute " +
|
||||
(signal.type == POSITION_TYPE_BUY ? "Long" : "Short") +
|
||||
" Signal Provided by: " + signal.provider +
|
||||
(signal.pushers > 1 ? " Pushers: " + ToString(signal.pushers) : "") +
|
||||
" on: " + signal.symbol +
|
||||
" in: " + ToString(signal.period) +
|
||||
" due Reason: " + ToString(state) + " ...";
|
||||
Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
|
||||
@@ -49,16 +49,8 @@ struct X121SMCStrategyXTWPVSignalConditions
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
int peakRepeat;
|
||||
double farPeak;
|
||||
double middlePeak;
|
||||
double nearPeak;
|
||||
|
||||
//
|
||||
int valeRepeat;
|
||||
double farVale;
|
||||
double middleVale;
|
||||
double nearVale;
|
||||
double point;
|
||||
XPVPivot pivot;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
@@ -175,16 +167,13 @@ struct X121SMCStrategyXTWPVSignalConditions
|
||||
void ExtensionClean()
|
||||
{
|
||||
//
|
||||
peakRepeat = 0;
|
||||
farPeak = 0;
|
||||
middlePeak = 0;
|
||||
nearPeak = 0;
|
||||
point = 0;
|
||||
pivot.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
valeRepeat = 0;
|
||||
farVale = 0;
|
||||
middleVale = 0;
|
||||
nearVale = 0;
|
||||
bool HasPivot()
|
||||
{
|
||||
return pivot.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -409,7 +398,200 @@ bool DetectX121SMCXTWPVSiganlSetup(
|
||||
// }
|
||||
|
||||
//
|
||||
// Check Exists Valid Peaks or Vales ...
|
||||
// Retrieve Active Pivots ...
|
||||
|
||||
//
|
||||
// Select Source Cycle Helper ...
|
||||
XC121SMCCycleHelper *helper = analyseCycleHelper;
|
||||
X121SMCCycleConditions helperConditions = analyseConditions;
|
||||
XPOIState helperState = analyseState;
|
||||
XOHCL helperCBar;
|
||||
result = helper.GetBar(
|
||||
cBar,
|
||||
helperCBar //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPVPivot peakPivot;
|
||||
bool hasPeakPivot = helper
|
||||
.GetActivePeakPivot(peakPivot);
|
||||
|
||||
//
|
||||
XPVPivot valePivot;
|
||||
bool hasValePivot = helper
|
||||
.GetActiveValePivot(valePivot);
|
||||
|
||||
//
|
||||
// Check Pivot ...
|
||||
bool hasPivot = conditions.HasPivot();
|
||||
if (!hasPivot)
|
||||
{
|
||||
//
|
||||
if (hasPeakPivot && !hasValePivot)
|
||||
{
|
||||
conditions.pivot = peakPivot;
|
||||
}
|
||||
else if (hasValePivot && !hasPeakPivot)
|
||||
{
|
||||
conditions.pivot = valePivot;
|
||||
}
|
||||
else if (hasPeakPivot && hasValePivot)
|
||||
{
|
||||
//
|
||||
if (peakPivot.from > valePivot.from)
|
||||
{
|
||||
conditions.pivot = peakPivot;
|
||||
}
|
||||
else if (valePivot.from > peakPivot.from)
|
||||
{
|
||||
conditions.pivot = valePivot;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
hasPivot = conditions.HasPivot();
|
||||
result = hasPivot;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Update Pivot States ...
|
||||
if (hasPivot)
|
||||
{
|
||||
//
|
||||
conditions.pivot.to = cTime;
|
||||
helper.FillPivotState(conditions.pivot);
|
||||
|
||||
//
|
||||
bool hasNewPivot =
|
||||
//
|
||||
(hasPeakPivot &&
|
||||
peakPivot.from > conditions.pivot.from) ||
|
||||
(hasValePivot &&
|
||||
valePivot.from > conditions.pivot.from)
|
||||
//
|
||||
;
|
||||
result = !hasNewPivot;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
conditions.pivot.Clean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Waits for new Peaks or Vales ...
|
||||
|
||||
//
|
||||
double peak = helperConditions.x121Conditions.peaksBuffer[1];
|
||||
bool isNewPeak = helperConditions.x121Conditions.isNewPeak;
|
||||
bool isNewPeakOverLast = helperConditions.x121Conditions.isNewPeakOverLast;
|
||||
bool isNewPeakUnderLast = helperConditions.x121Conditions.isNewPeakUnderLast;
|
||||
|
||||
//
|
||||
double vale = helperConditions.x121Conditions.valesBuffer[1];
|
||||
bool isNewVale = helperConditions.x121Conditions.isNewVale;
|
||||
bool isNewValeOverLast = helperConditions.x121Conditions.isNewValeOverLast;
|
||||
bool isNewValeUnderLast = helperConditions.x121Conditions.isNewValeUnderLast;
|
||||
|
||||
//
|
||||
result = isNewPeak ||
|
||||
isNewVale;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
|
||||
//
|
||||
double bullishFib = GetFibonacciLevel(
|
||||
helperCBar.high,
|
||||
helperCBar.low,
|
||||
GetFiboLevelValue(X_FIBO_LEVEL_382),
|
||||
-1 //
|
||||
);
|
||||
|
||||
//
|
||||
double bearishFib = GetFibonacciLevel(
|
||||
helperCBar.high,
|
||||
helperCBar.low,
|
||||
GetFiboLevelValue(X_FIBO_LEVEL_382),
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
bool isBearishFiboPassed = bullishFib <= conditions.pivot.lower;
|
||||
|
||||
//
|
||||
// Bearish Conditions 1 ...
|
||||
bool bearishConditions1 =
|
||||
//
|
||||
isNewValeUnderLast &&
|
||||
isBearishFiboPassed &&
|
||||
helperCBar.IsBearish() &&
|
||||
conditions.pivot.lower > vale &&
|
||||
conditions.pivot.lower < helperCBar.GetUp() &&
|
||||
conditions.pivot.lower > helperCBar.GetDown()
|
||||
//
|
||||
;
|
||||
if (bearishConditions1)
|
||||
{
|
||||
conditions.point = conditions.pivot.lower;
|
||||
}
|
||||
|
||||
//
|
||||
double donCloseUpper = helperConditions.x121Conditions.donCloseUpperBuffer[1];
|
||||
double donCloseLower = helperConditions.x121Conditions.donCloseLowerBuffer[1];
|
||||
|
||||
//
|
||||
double donOpenUpper = helperConditions.x121Conditions.donOpenUpperBuffer[1];
|
||||
double donOpenLower = helperConditions.x121Conditions.donOpenLowerBuffer[1];
|
||||
|
||||
//
|
||||
bool bearishConditions2 =
|
||||
//
|
||||
isNewPeakUnderLast &&
|
||||
donCloseUpper > peak
|
||||
//
|
||||
;
|
||||
if (bearishConditions2)
|
||||
{
|
||||
conditions.point = peak;
|
||||
}
|
||||
|
||||
//
|
||||
// Summary Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
bearishConditions1 ||
|
||||
bearishConditions2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
@@ -465,8 +647,8 @@ bool DetectX121SMCXTWPVSiganlTrigger(
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
bool isBullish = IsBullish(setupDir);
|
||||
bool isBearish = IsBearish(setupDir);
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
@@ -639,56 +821,15 @@ bool DetectX121SMCXTWPVSiganlTrigger(
|
||||
//
|
||||
// Trigger Conditions ...
|
||||
|
||||
//
|
||||
// Check VWap State ...
|
||||
// //
|
||||
// isBullish =
|
||||
// isBullish &&
|
||||
// false;
|
||||
|
||||
//
|
||||
bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState;
|
||||
bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState;
|
||||
|
||||
//
|
||||
isBullish =
|
||||
IsBullish(setupDir) &&
|
||||
isVWapBullishState;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
IsBearish(setupDir) &&
|
||||
isVWapBearishState;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Waitings For Sar Switched to Direction ...
|
||||
|
||||
//
|
||||
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
isBullish &&
|
||||
isSarSwitchedToBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
isBearish &&
|
||||
isSarSwitchedToBearish
|
||||
//
|
||||
;
|
||||
// //
|
||||
// isBearish =
|
||||
// isBearish &&
|
||||
// false;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
@@ -710,32 +851,181 @@ bool DetectX121SMCXTWPVSiganlTrigger(
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Nearest FVG or Supply Zone For Traget ...
|
||||
// Detect Consolidation ...
|
||||
XConsolidationZone consolidationZone;
|
||||
bool hasConsolidationZone = triggerCycleHelper
|
||||
.GetLastConsolidationZone(consolidationZone);
|
||||
if (hasConsolidationZone)
|
||||
{
|
||||
//
|
||||
hasConsolidationZone =
|
||||
isBullish
|
||||
? consolidationZone.upper <= conditions.point
|
||||
: consolidationZone.lower >= conditions.point;
|
||||
|
||||
//
|
||||
if (!hasConsolidationZone)
|
||||
{
|
||||
consolidationZone.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Select Source State ...
|
||||
XPOIState state = triggerState;
|
||||
// Detect Nearest Pivot Point ...
|
||||
XPVPivotPoint pivotPoints[];
|
||||
XPVPivotPoint nearestPivotPoint;
|
||||
bool hasNearestPivotPoint = false;
|
||||
int pivotPointsCount = triggerCycleHelper
|
||||
.FillPivotPoints(pivotPoints);
|
||||
if (IsValidSize(pivotPointsCount))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < pivotPointsCount; i++)
|
||||
{
|
||||
//
|
||||
XPVPivotPoint iPoint = pivotPoints[i];
|
||||
|
||||
//
|
||||
bool canSet =
|
||||
(isBullish
|
||||
? iPoint.value < conditions.point
|
||||
: iPoint.value > conditions.point)
|
||||
//
|
||||
&&
|
||||
//
|
||||
(!nearestPivotPoint.IsValid()
|
||||
? true
|
||||
: isBullish
|
||||
? nearestPivotPoint.value > iPoint.value
|
||||
: nearestPivotPoint.value < iPoint.value);
|
||||
if (canSet)
|
||||
{
|
||||
nearestPivotPoint = iPoint;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
hasNearestPivotPoint = nearestPivotPoint.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Target ...
|
||||
double target = CalculateTarget(
|
||||
cBar,
|
||||
state,
|
||||
analyseState,
|
||||
setupDir //
|
||||
);
|
||||
if (target == 0)
|
||||
{
|
||||
//
|
||||
target = CalculateTarget(
|
||||
cBar,
|
||||
verificationState,
|
||||
setupDir //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double oppositTarget = CalculateTarget(
|
||||
cBar,
|
||||
analyseState,
|
||||
Opposit(setupDir) //
|
||||
);
|
||||
|
||||
//
|
||||
double points = GetPoints(conditions.symbol);
|
||||
|
||||
//
|
||||
double entry = GetEntry(
|
||||
conditions.symbol,
|
||||
setupDir //
|
||||
);
|
||||
|
||||
//
|
||||
result = target > 0;
|
||||
if (!result)
|
||||
// Filling SL Candidates ...
|
||||
double sls[];
|
||||
if (hasConsolidationZone)
|
||||
{
|
||||
return result;
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
Add(
|
||||
consolidationZone.lower,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(
|
||||
consolidationZone.upper,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
}
|
||||
if (hasNearestPivotPoint)
|
||||
{
|
||||
Add(
|
||||
nearestPivotPoint.value,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
if (ArraySize(sls) == 0)
|
||||
{
|
||||
//
|
||||
double pointsDiff = (10 * points);
|
||||
double pointsPlus = conditions.point + pointsDiff;
|
||||
double pointsMinus = conditions.point - pointsDiff;
|
||||
|
||||
//
|
||||
// Force SL ...
|
||||
Add(
|
||||
conditions.point,
|
||||
sls //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
pointsPlus,
|
||||
sls //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
pointsMinus,
|
||||
sls //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
oppositTarget,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double slsMin = GetMin(sls);
|
||||
double slsMax = GetMax(sls);
|
||||
|
||||
//
|
||||
double sl = isBullish
|
||||
? slsMin
|
||||
: slsMax;
|
||||
double risk = MathAbs(entry - sl);
|
||||
double targetDelta = 2 * (risk / 3);
|
||||
if (target == 0)
|
||||
{
|
||||
//
|
||||
// Force Target On Half Risk ...
|
||||
target =
|
||||
isBullish
|
||||
? entry + targetDelta
|
||||
: entry - targetDelta;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.sl = sl;
|
||||
conditions.target = target;
|
||||
conditions.triggerTime = cTime;
|
||||
conditions.sl = isBullish
|
||||
? sar
|
||||
: sar;
|
||||
conditions.type = isBullish
|
||||
? X_POSITION_TYPE_LONG
|
||||
: X_POSITION_TYPE_SHORT;
|
||||
|
||||
@@ -326,6 +326,18 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
signal.time = TimeCurrent();
|
||||
signal.target = conditions.target;
|
||||
|
||||
//
|
||||
bool canReplaceTarget =
|
||||
hasLong
|
||||
? signal.target > signal.tp
|
||||
: signal.target < signal.tp;
|
||||
if (canReplaceTarget)
|
||||
{
|
||||
//
|
||||
signal.tp = conditions.target;
|
||||
signal.target = tp;
|
||||
}
|
||||
|
||||
//
|
||||
// Configure Signal Protecting ...
|
||||
// if (hasXPVOBSignal ||
|
||||
@@ -1180,6 +1192,38 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
//
|
||||
setupDir = mXTWPVConditions.dir;
|
||||
setupTime = mXTWPVConditions.setupTime;
|
||||
|
||||
// //
|
||||
// if (!isSetuped)
|
||||
// {
|
||||
// //
|
||||
// bool hasParent = mXTWPVConditions.HasParentPivot();
|
||||
// if (hasParent)
|
||||
// {
|
||||
// //
|
||||
// XCBaseObject *objs[];
|
||||
// mPOIDrawer.DrawPivot(
|
||||
// mXTWPVConditions.parentPivot,
|
||||
// objs,
|
||||
// true, // Drawing State ...
|
||||
// true // Drawing Ticks Zone ...
|
||||
// );
|
||||
// AddObjectsIfNotExists(objs);
|
||||
// }
|
||||
|
||||
// //
|
||||
// bool hasChild = mXTWPVConditions.HasChildPivot();
|
||||
// if (hasChild)
|
||||
// {
|
||||
// //
|
||||
// XCBaseObject *objs[];
|
||||
// mPOIDrawer.DrawPivot(
|
||||
// mXTWPVConditions.childPivot,
|
||||
// objs //
|
||||
// );
|
||||
// AddObjectsIfNotExists(objs);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
@@ -1581,9 +1625,22 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
|
||||
//
|
||||
x121Inputs.showFibo2Levels = false;
|
||||
x121Inputs.showFibo3Levels = true;
|
||||
x121Inputs.showFibo3Levels = false;
|
||||
x121Inputs.showFibo4Levels = false;
|
||||
|
||||
//
|
||||
x121Inputs.showSar = false;
|
||||
x121Inputs.showPeaks = true;
|
||||
x121Inputs.showVales = true;
|
||||
x121Inputs.showVWap = false;
|
||||
x121Inputs.showDonchain = true;
|
||||
|
||||
//
|
||||
x121Inputs.showOpen = true;
|
||||
x121Inputs.showHigh = true;
|
||||
x121Inputs.showClose = true;
|
||||
x121Inputs.showLow = true;
|
||||
|
||||
//
|
||||
// Initialize Cycle Helpers ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user