Last Works ...

This commit is contained in:
2024-11-15 20:03:39 +03:30
parent e0b2164515
commit eae679f78d
4 changed files with 418 additions and 71 deletions
+15 -5
View File
@@ -35,6 +35,8 @@ struct XCTInputs
// Props ... // Props ...
// //
string font; // Font
int fontSize; // Font Size;
color clr; // Text Color color clr; // Text Color
ENUM_BASE_CORNER corner; // Text Position ENUM_BASE_CORNER corner; // Text Position
@@ -46,7 +48,6 @@ struct XCTInputs
// Constructor(s) ... // Constructor(s) ...
XCTInputs() XCTInputs()
{ {
//
Clean(); Clean();
} }
@@ -58,6 +59,8 @@ struct XCTInputs
void Clean() void Clean()
{ {
// //
font = NULL;
fontSize = 15;
clr = CLR_NONE; clr = CLR_NONE;
corner = CORNER_RIGHT_LOWER; corner = CORNER_RIGHT_LOWER;
@@ -71,6 +74,8 @@ struct XCTInputs
void Default() void Default()
{ {
// //
font = "Arial";
fontSize = 15;
clr = clrYellow; clr = clrYellow;
corner = CORNER_RIGHT_LOWER; corner = CORNER_RIGHT_LOWER;
@@ -124,13 +129,16 @@ public:
// //
// Constructors ... // Constructors ...
XCXCTHelper() : XCBaseHelper(_Symbol, _Period) XCXCTHelper()
: XCBaseHelper(_Symbol, _Period)
{ {
} }
// //
// Deconstructor ... // Deconstructor ...
~XCXCTHelper() {} ~XCXCTHelper()
{
}
// //
// Tools ... // Tools ...
@@ -164,8 +172,10 @@ public:
"x-saherelm.xct", "x-saherelm.xct",
// //
// Inputs ... // Inputs ...
mInputs.clr, // Text Color mInputs.fontSize, // Font Size ...
mInputs.corner, // Text Position mInputs.font, // Font ...
mInputs.clr, // Text Color ...
mInputs.corner, // Text Position ...
// //
// Presentation ... // Presentation ...
"", "",
+28 -18
View File
@@ -36,6 +36,8 @@
// //
// //
input int fontSize = 15; // Font Size
input string font = "Arial"; // Font
input color clr = clrYellow; // Text Color input color clr = clrYellow; // Text Color
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
@@ -65,7 +67,7 @@ input bool showCandleTime = true; // Show Candle Time
// //
// START Global Definitions: Variables, Properties and etc ... // START Global Definitions: Variables, Properties and etc ...
// //
string tag;
// //
// END Global Definitions: Variables, Properties and etc ... // END Global Definitions: Variables, Properties and etc ...
// //
@@ -80,13 +82,18 @@ int OnInit()
{ {
// //
// Validate Inputs ... // Validate Inputs ...
//
tag = ShortName + _Symbol + ToString(_Period);
//
if (showCandleTime) if (showCandleTime)
{ {
CreateIndicatorObject(); CreateIndicatorObject();
} }
else else
{ {
ObjectDelete(0, ShortName); ObjectDelete(0, tag);
} }
// //
@@ -114,16 +121,9 @@ void OnDeinit(const int reason)
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed // REASON_CLOSE 9 Terminal closed
//
ulong chID = FindChartID(
_Symbol,
_Period
//
);
// //
// Delete Object ... // Delete Object ...
ObjectDelete(chID, ShortName); ObjectDelete(0, tag);
// //
Comment(""); Comment("");
@@ -204,10 +204,7 @@ int OnCalculate(
string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg; string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg;
// //
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr); ObjectSetString(0, tag, OBJPROP_TEXT, objText);
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier");
// //
return rates_total; return rates_total;
@@ -238,9 +235,9 @@ void CreateIndicatorObject()
} }
// //
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0); ObjectCreate(0, tag, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner); ObjectSetInteger(0, tag, OBJPROP_CORNER, corner);
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10); ObjectSetInteger(0, tag, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2); ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
// //
@@ -262,7 +259,20 @@ void CreateIndicatorObject()
} }
// //
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor); int mFontSize = fontSize > 0
? fontSize
: 10;
//
string mFont = IsValid(font)
? font
: "Arial";
//
ObjectSetString(0, tag, OBJPROP_FONT, mFont);
ObjectSetInteger(0, tag, OBJPROP_COLOR, clr);
ObjectSetInteger(0, tag, OBJPROP_ANCHOR, Anchor);
ObjectSetInteger(0, tag, OBJPROP_FONTSIZE, mFontSize);
} }
// //
+191
View File
@@ -38,6 +38,55 @@ struct X121SMCStrategyConditions
ENUM_TIMEFRAMES period; ENUM_TIMEFRAMES period;
datetime time; datetime time;
//
// D1 ...
XPOIState d1State;
ENUM_X_DIRECTION d1MarketDirection;
XCSupportZone *d1SupportZones[];
XCResistanceZone *d1ResistanceZones[];
//
// H4 ...
XPOIState h4State;
ENUM_X_DIRECTION h4MarketDirection;
XCSupportZone *h4SupportZones[];
XCResistanceZone *h4ResistanceZones[];
//
// H2 ...
XPOIState h2State;
ENUM_X_DIRECTION h2MarketDirection;
XCSupportZone *h2SupportZones[];
XCResistanceZone *h2ResistanceZones[];
//
// H1 ...
XPOIState h1State;
ENUM_X_DIRECTION h1MarketDirection;
XCSupportZone *h1SupportZones[];
XCResistanceZone *h1ResistanceZones[];
//
// M15 ...
XPOIState m15State;
ENUM_X_DIRECTION m15MarketDirection;
XCSupportZone *m15SupportZones[];
XCResistanceZone *m15ResistanceZones[];
//
// M5 ...
XPOIState m5State;
ENUM_X_DIRECTION m5MarketDirection;
XCSupportZone *m5SupportZones[];
XCResistanceZone *m5ResistanceZones[];
//
// M1 ...
XPOIState m1State;
ENUM_X_DIRECTION m1MarketDirection;
XCSupportZone *m1SupportZones[];
XCResistanceZone *m1ResistanceZones[];
// //
void X121SMCStrategyConditions() void X121SMCStrategyConditions()
{ {
@@ -56,6 +105,55 @@ struct X121SMCStrategyConditions
symbol = NULL; symbol = NULL;
period = NULL; period = NULL;
time = NULL; time = NULL;
//
// D1 ...
d1State.Clean();
d1MarketDirection = X_DIRECTION_NONE;
Clean(d1SupportZones);
Clean(d1ResistanceZones);
//
// H4 ...
h4State.Clean();
h4MarketDirection = X_DIRECTION_NONE;
Clean(h4SupportZones);
Clean(h4ResistanceZones);
//
// H2 ...
h2State.Clean();
h2MarketDirection = X_DIRECTION_NONE;
Clean(h2SupportZones);
Clean(h2ResistanceZones);
//
// H1 ...
h1State.Clean();
h1MarketDirection = X_DIRECTION_NONE;
Clean(h1SupportZones);
Clean(h1ResistanceZones);
//
// M15 ...
m15State.Clean();
m15MarketDirection = X_DIRECTION_NONE;
Clean(m15SupportZones);
Clean(m15ResistanceZones);
//
// M5 ...
m5State.Clean();
m5MarketDirection = X_DIRECTION_NONE;
Clean(m5SupportZones);
Clean(m5ResistanceZones);
//
// M1 ...
m1State.Clean();
m1MarketDirection = X_DIRECTION_NONE;
Clean(m1SupportZones);
Clean(m1ResistanceZones);
} }
/** /**
@@ -77,6 +175,99 @@ struct X121SMCStrategyConditions
return result; return result;
} }
//
// Custom Tools ...
/**
* Check Conditions for Detect Market Structure ...
*
* @param structure: ENUM_X_DIRECTION member, Market Structure Direction reference ...
*
* @return ( bool )
*/
bool HasMarketStructure(
ENUM_X_DIRECTION &structure //
)
{
//
bool result = false;
//
structure = X_DIRECTION_NONE;
//
result = IsValid();
if (!result)
{
return result;
}
//
bool is1DBullish = IsBullish(d1MarketDirection);
bool is1DBearish = IsBearish(d1MarketDirection);
//
bool is4HBullish = IsBullish(h4MarketDirection);
bool is4HBearish = IsBearish(h4MarketDirection);
//
bool is2HBullish = IsBullish(h2MarketDirection);
bool is2HBearish = IsBearish(h2MarketDirection);
//
bool is1HBullish = IsBullish(h1MarketDirection);
bool is1HBearish = IsBearish(h1MarketDirection);
//
bool is15MBullish = IsBullish(m15MarketDirection);
bool is15MBearish = IsBearish(m15MarketDirection);
//
bool is5MBullish = IsBullish(m5MarketDirection);
bool is5MBearish = IsBearish(m5MarketDirection);
//
bool is1MBullish = IsBullish(m1MarketDirection);
bool is1MBearish = IsBearish(m1MarketDirection);
//
bool isStructuresBullish =
//
is1HBullish &&
is15MBullish &&
is5MBullish
//
;
//
bool isStructuresBearish =
//
is1HBearish &&
is15MBearish &&
is5MBearish
//
;
//
bool hasMarketStructure =
isStructuresBullish ||
isStructuresBearish;
result = hasMarketStructure;
if (!result)
{
return result;
}
//
structure =
isStructuresBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
return result;
}
/** /**
* Generate Provided Scores ... * Generate Provided Scores ...
* *
@@ -331,18 +331,132 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
dir = X_DIRECTION_NONE; dir = X_DIRECTION_NONE;
// //
// TODO: Implement ... // Detect Market Structures ...
ENUM_X_DIRECTION marketStructureDir;
result = DetectMarketStructure(
marketStructureDir,
_5MState //
);
// //
// 1D ...
mConditions.d1State = _1DState;
result = DetectMarketStructure(
mConditions.d1MarketDirection,
_1DState //
);
if (!result) if (!result)
{ {
//
mConditions.Clean(); mConditions.Clean();
return result;
} }
bool is1DBullish = IsBullish(mConditions.d1MarketDirection);
bool is1DBearish = IsBearish(mConditions.d1MarketDirection);
//
// 4H ...
mConditions.h4State = _4HState;
result = DetectMarketStructure(
mConditions.h4MarketDirection,
_4HState //
);
if (!result)
{
//
mConditions.Clean();
return result;
}
bool is4HBullish = IsBullish(mConditions.h4MarketDirection);
bool is4HBearish = IsBearish(mConditions.h4MarketDirection);
//
// 2H ...
mConditions.h2State = _2HState;
result = DetectMarketStructure(
mConditions.h2MarketDirection,
_2HState //
);
if (!result)
{
//
mConditions.Clean();
return result;
}
bool is2HBullish = IsBullish(mConditions.h2MarketDirection);
bool is2HBearish = IsBearish(mConditions.h2MarketDirection);
//
// 1H ...
mConditions.h1State = _1HState;
result = DetectMarketStructure(
mConditions.h1MarketDirection,
_1HState //
);
if (!result)
{
//
mConditions.Clean();
return result;
}
bool is1HBullish = IsBullish(mConditions.h1MarketDirection);
bool is1HBearish = IsBearish(mConditions.h1MarketDirection);
//
// 15M ...
mConditions.m15State = _15MState;
result = DetectMarketStructure(
mConditions.m15MarketDirection,
_15MState //
);
if (!result)
{
//
mConditions.Clean();
return result;
}
bool is15MBullish = IsBullish(mConditions.m15MarketDirection);
bool is15MBearish = IsBearish(mConditions.m15MarketDirection);
//
// 5M ...
mConditions.m5State = _5MState;
result = DetectMarketStructure(
mConditions.m5MarketDirection,
_5MState //
);
if (!result)
{
//
mConditions.Clean();
return result;
}
bool is5MBullish = IsBullish(mConditions.m5MarketDirection);
bool is5MBearish = IsBearish(mConditions.m5MarketDirection);
//
// 1M ...
mConditions.m1State = _1MState;
result = DetectMarketStructure(
mConditions.m1MarketDirection,
_1MState //
);
if (!result)
{
//
mConditions.Clean();
return result;
}
bool is1MBullish = IsBullish(mConditions.m1MarketDirection);
bool is1MBearish = IsBearish(mConditions.m1MarketDirection);
//
ENUM_X_DIRECTION marketStructure = X_DIRECTION_NONE;
result = mConditions.HasMarketStructure(marketStructure);
if (!result)
{
//
mConditions.Clean();
return result;
}
//
DrawState(_5MState);
// //
return result; return result;
@@ -364,17 +478,12 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
// //
bool result = false; bool result = false;
//
// DrawState(state);
//
// Print("Salam");
// //
int count = 0; int count = 0;
// //
// Filter Untouched Supports ... // Filter Untouched Supports ...
int untouchedSupportsCount = 0;
XCSupportZone *untouchedSupportZones[]; XCSupportZone *untouchedSupportZones[];
count = ArraySize(state.supportZones); count = ArraySize(state.supportZones);
if (IsValidSize(count)) if (IsValidSize(count))
@@ -436,31 +545,33 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
} }
// //
int untouchedSupportsCount = ArraySize(untouchedSupportZones); untouchedSupportsCount = ArraySize(untouchedSupportZones);
if (IsValidSize(untouchedSupportsCount)) if (IsValidSize(untouchedSupportsCount))
{ {
// //
for (int i = 0; i < untouchedSupportsCount; i++) // Draw ...
{ // for (int i = 0; i < untouchedSupportsCount; i++)
// // {
XCSupportZone *item = untouchedSupportZones[i]; // //
// XCSupportZone *item = untouchedSupportZones[i];
// // //
XCSupportZoneObject *iObj; // XCSupportZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateSupportZone( // bool isCreated = mPOIDrawer.CreateSupportZone(
item, // item,
iObj // // iObj //
); // );
if (isCreated) // if (isCreated)
{ // {
AddObjectIfNotExists(iObj); // AddObjectIfNotExists(iObj);
} // }
} // }
} }
} }
// //
// Filter Untouched Resistances ... // Filter Untouched Resistances ...
int untouchedResistancesCount = 0;
XCResistanceZone *untouchedResistanceZones[]; XCResistanceZone *untouchedResistanceZones[];
count = ArraySize(state.resistanceZones); count = ArraySize(state.resistanceZones);
if (IsValidSize(count)) if (IsValidSize(count))
@@ -522,27 +633,52 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
} }
// //
int untouchedResistancesCount = ArraySize(untouchedResistanceZones); untouchedResistancesCount = ArraySize(untouchedResistanceZones);
if (IsValidSize(untouchedResistancesCount)) if (IsValidSize(untouchedResistancesCount))
{ {
// //
for (int i = 0; i < untouchedResistancesCount; i++) // Draw ...
{ // for (int i = 0; i < untouchedResistancesCount; i++)
// // {
XCResistanceZone *item = untouchedResistanceZones[i]; // //
// XCResistanceZone *item = untouchedResistanceZones[i];
// //
// XCResistanceZoneObject *iObj;
// bool isCreated = mPOIDrawer.CreateResistanceZone(
// item,
// iObj //
// );
// if (isCreated)
// {
// AddObjectIfNotExists(iObj);
// }
// }
}
}
// //
XCResistanceZoneObject *iObj; bool hasBullishStructure =
bool isCreated = mPOIDrawer.CreateResistanceZone( IsValidSize(untouchedSupportsCount) &&
item, untouchedSupportsCount > untouchedResistancesCount;
iObj // bool hasBearishStructure =
); IsValidSize(untouchedResistancesCount) &&
if (isCreated) untouchedResistancesCount > untouchedSupportsCount;
//
result = (hasBullishStructure &&
!hasBearishStructure) ||
(hasBearishStructure &&
!hasBullishStructure);
//
if (result)
{ {
AddObjectIfNotExists(iObj); //
} dir =
} hasBullishStructure
} ? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
} }
// //