last works ...
This commit is contained in:
@@ -90,6 +90,356 @@ enum ENUM_X_CYCLE_EVENTS
|
||||
VALE_PIVOT_ENDED,
|
||||
};
|
||||
|
||||
//
|
||||
// XPV Pivot ...
|
||||
|
||||
//
|
||||
enum ENUM_X_PV_PIVOT
|
||||
{
|
||||
X_PV_NONE, // None
|
||||
X_PV_PEAK, // Peak
|
||||
X_PV_VALE, // Vale
|
||||
};
|
||||
|
||||
//
|
||||
bool IsValid(ENUM_X_PV_PIVOT value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = value != X_PV_NONE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string ToString(ENUM_X_PV_PIVOT value)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = EnumToString(value);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
struct XPVPivot
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
datetime to;
|
||||
double value;
|
||||
double golden;
|
||||
datetime from;
|
||||
string symbol;
|
||||
ENUM_X_PV_PIVOT type;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XPVPivot()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup Model ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
to = NULL;
|
||||
value = 0;
|
||||
from = NULL;
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
type = X_PV_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Model ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
from < to &&
|
||||
value > 0 &&
|
||||
IsValid(to) &&
|
||||
IsValid(type) &&
|
||||
IsValid(from) &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Model Direction ...
|
||||
*
|
||||
* @return ( ENUM_X_DIRECTION )
|
||||
*/
|
||||
ENUM_X_DIRECTION GetDirection()
|
||||
{
|
||||
//
|
||||
ENUM_X_DIRECTION result = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
switch (type)
|
||||
{
|
||||
//
|
||||
case X_PV_PEAK:
|
||||
result = X_DIRECTION_BEARISH;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PV_VALE:
|
||||
result = X_DIRECTION_BULLISH;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Direction is Bullish ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsBullish()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION dir = GetDirection();
|
||||
result = IsBullish(dir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Direction is Bearish ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsBearish()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION dir = GetDirection();
|
||||
result = IsBearish(dir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* To Bar Index ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ToIndex(
|
||||
ENUM_TIMEFRAMES forPeriod = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsValid(forPeriod))
|
||||
{
|
||||
forPeriod = period;
|
||||
}
|
||||
|
||||
//
|
||||
result = GetBarIndex(
|
||||
symbol,
|
||||
forPeriod,
|
||||
to //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* From Bar Index ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int FromIndex(
|
||||
ENUM_TIMEFRAMES forPeriod = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsValid(forPeriod))
|
||||
{
|
||||
forPeriod = period;
|
||||
}
|
||||
|
||||
//
|
||||
result = GetBarIndex(
|
||||
symbol,
|
||||
forPeriod,
|
||||
from //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check two Pivot is Same or Not ...
|
||||
*
|
||||
* @param item: XPVPivot instance Reference ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameAs(XPVPivot &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid() &&
|
||||
item.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
to == item.to &&
|
||||
from == item.from &&
|
||||
type == item.type &&
|
||||
value == item.value &&
|
||||
golden == item.golden &&
|
||||
symbol == item.symbol &&
|
||||
period == item.period
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conerts to XBoxZone ...
|
||||
*
|
||||
* @param box: XBoxZone instance Reference ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AsBox(XBoxZone &box)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
box.to = to;
|
||||
box.from = from;
|
||||
box.symbol = symbol;
|
||||
box.period = period;
|
||||
box.dir = GetDirection();
|
||||
box.type = ToString(type);
|
||||
|
||||
//
|
||||
if (IsBullish())
|
||||
{
|
||||
//
|
||||
box.lower = value;
|
||||
box.upper = golden;
|
||||
}
|
||||
else if (IsBearish())
|
||||
{
|
||||
//
|
||||
box.upper = value;
|
||||
box.lower = golden;
|
||||
}
|
||||
|
||||
//
|
||||
result = box.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
box.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Cycle Helper ...
|
||||
class XC121SMCCycleHelper : public XCBase
|
||||
@@ -478,137 +828,6 @@ class XC121SMCCycleHelper : public XCBase
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
int DetectRejections(
|
||||
XBoxZone &rejections[],
|
||||
@@ -1095,7 +1314,7 @@ class XC121SMCCycleHelper : public XCBase
|
||||
bool mShowBidLine = true; // show bid line
|
||||
bool mShowAskLine = true; // show ask line
|
||||
bool mShowGrid = false; // show grids on chart
|
||||
bool mShowVolumes = false; // show volumes
|
||||
bool mShowVolumes = false; // show volumes
|
||||
bool mShowTradeLevels = true; // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders)
|
||||
bool mAutoScroll = true; // chart autoscroll
|
||||
bool mQuickNavigation = true; // chart quick navigation state
|
||||
|
||||
@@ -35,11 +35,12 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
//
|
||||
// Props ...
|
||||
bool useGuards;
|
||||
double rfRewar;
|
||||
double rfReward;
|
||||
bool isPassedBoxes;
|
||||
XBoxZone mWaitingBoxes[];
|
||||
XBoxZone mBreakedBoxes[];
|
||||
XBoxZone mActivatedBoxes[];
|
||||
bool continuesRFTillTarget;
|
||||
XBoxZone mUnAvailableBoxes[];
|
||||
X121SMCStrategyXINDSignalConditions mConditions;
|
||||
X121SMCStrategyXINDSignalConditions mConditionsCollection[];
|
||||
@@ -78,12 +79,16 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
*/
|
||||
bool DetectSignalSetup(
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
double tpReward = 3,
|
||||
double maxAllowedSLDistanceInPoint = 300 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
tpReward = NormalizeDouble(tpReward, 2);
|
||||
|
||||
//
|
||||
// Validate Cycle Helpers ...
|
||||
result = provider.IsValid();
|
||||
@@ -330,11 +335,11 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
{
|
||||
//
|
||||
iAtr = provider.decisionXConditions.atrBuffer[1];
|
||||
iAtr *= 0.5;
|
||||
iAtr *= 0;
|
||||
|
||||
//
|
||||
// Fix rf Reward ...
|
||||
rfRewar = 2;
|
||||
rfReward = 2;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -368,10 +373,10 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
|
||||
//
|
||||
// Reward to RF ...
|
||||
if (rfRewar > 0)
|
||||
if (rfReward > 0)
|
||||
{
|
||||
//
|
||||
double iRFReward = rfRewar * risk;
|
||||
double iRFReward = rfReward * risk;
|
||||
double iRFTP = isBullish
|
||||
? entry + iRFReward
|
||||
: entry - iRFReward;
|
||||
@@ -381,6 +386,31 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
iRFTP,
|
||||
targets //
|
||||
);
|
||||
|
||||
//
|
||||
if (continuesRFTillTarget &&
|
||||
rfReward < tpReward)
|
||||
{
|
||||
//
|
||||
double iReward = rfReward + 1;
|
||||
while (iReward < tpReward - 1)
|
||||
{
|
||||
//
|
||||
iRFReward = iReward * risk;
|
||||
iRFTP = isBullish
|
||||
? entry + iRFReward
|
||||
: entry - iRFReward;
|
||||
|
||||
//
|
||||
Add(
|
||||
iRFTP,
|
||||
targets //
|
||||
);
|
||||
|
||||
//
|
||||
iReward++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1094,7 +1124,8 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
int UpdateWaitingBoxes(
|
||||
ENUM_X_CYCLES cycle,
|
||||
ENUM_X_CYCLES vCycle,
|
||||
X121SMCStrategySignalProviderData &provider //
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int maxAllowedAge = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1321,6 +1352,31 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
iBox.period //
|
||||
);
|
||||
|
||||
//
|
||||
// Checking Box Age ...
|
||||
int age = iBox.GetAge();
|
||||
bool isAgeBreaked =
|
||||
maxAllowedAge > 0 &&
|
||||
age > maxAllowedAge;
|
||||
if (isAgeBreaked)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
i,
|
||||
mustRemove //
|
||||
);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
iBox,
|
||||
mUnAvailableBoxes //
|
||||
);
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Box Waiting ...
|
||||
if (isValid)
|
||||
@@ -1396,6 +1452,31 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
//
|
||||
XBoxZone iBox = mActivatedBoxes[i];
|
||||
|
||||
//
|
||||
// Checking Box Age ...
|
||||
int age = iBox.GetAge();
|
||||
bool isAgeBreaked =
|
||||
maxAllowedAge > 0 &&
|
||||
age > maxAllowedAge;
|
||||
if (isAgeBreaked)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
i,
|
||||
mustRemove //
|
||||
);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
iBox,
|
||||
mUnAvailableBoxes //
|
||||
);
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Breaked ...
|
||||
bool isBreaked = IsBoxBreaked(
|
||||
@@ -1918,9 +1999,10 @@ class XCX121SMCXINDSignalDetector : public XCBase
|
||||
void Init()
|
||||
{
|
||||
//
|
||||
rfRewar = 2;
|
||||
rfReward = 2;
|
||||
useGuards = false;
|
||||
isPassedBoxes = false;
|
||||
continuesRFTillTarget = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -732,7 +732,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
// XICH Signal ...
|
||||
bool DetectXINDSignal(
|
||||
X121SMCStrategyConditions &conditions,
|
||||
X121SMCStrategyXINDSignalConditions &xICHConditions //
|
||||
X121SMCStrategyXINDSignalConditions &xINDConditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -769,7 +769,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = mXINDSignalDetector.DetectSignalSetup(
|
||||
cycleProvider //
|
||||
cycleProvider,
|
||||
R2R() //
|
||||
);
|
||||
|
||||
//
|
||||
@@ -893,7 +894,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
);
|
||||
|
||||
//
|
||||
xICHConditions = mConditions;
|
||||
xINDConditions = mConditions;
|
||||
|
||||
//
|
||||
mConditions.Clean();
|
||||
@@ -1018,7 +1019,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
//
|
||||
// Presentations ...
|
||||
x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false;
|
||||
x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || true;
|
||||
x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || false;
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
@@ -1051,7 +1052,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
// Presentations ...
|
||||
x121Inputs.xatrInputs.showAtrUpper = showAll || false;
|
||||
x121Inputs.xatrInputs.showAtrLower = showAll || false;
|
||||
x121Inputs.xatrInputs.showRSIChange = showAll || false;
|
||||
x121Inputs.xatrInputs.showRSIChange = showAll || true;
|
||||
x121Inputs.xatrInputs.showPriceChange = showAll || true;
|
||||
x121Inputs.xatrInputs.showSmoothedAtrUpper = showAll || false;
|
||||
x121Inputs.xatrInputs.showSmoothedAtrLower = showAll || false;
|
||||
@@ -1065,13 +1066,17 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
|
||||
// Configurations ...
|
||||
x121Inputs.xstrInputs.strMultiplier = 5;
|
||||
x121Inputs.xstrInputs.strLength = swingLength;
|
||||
x121Inputs.xstrInputs.strBoundaryMode = MODE_SMA;
|
||||
x121Inputs.xstrInputs.strAppliedTo = PRICE_TYPICAL;
|
||||
|
||||
//
|
||||
// Presentations ...
|
||||
x121Inputs.xstrInputs.showStr = showAll || true;
|
||||
x121Inputs.xstrInputs.showStrMid = showAll || false;
|
||||
x121Inputs.xstrInputs.showStrUpper = showAll || false;
|
||||
x121Inputs.xstrInputs.showStrLower = showAll || false;
|
||||
x121Inputs.xstrInputs.showStrSMLow = showAll || false;
|
||||
x121Inputs.xstrInputs.showStrSMHigh = showAll || false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
|
||||
Reference in New Issue
Block a user