EA_SMC_Mql5/Include/SMC_DataStructures.mqh
2025-07-03 23:37:16 +07:00

188 lines
No EOL
13 KiB
MQL5

//+------------------------------------------------------------------+
//| SMC_DataStructures.mqh |
//| Central definitions for all shared data structure classes. |
//+------------------------------------------------------------------+
#ifndef SMCDATASTRUCTURES_MQH
#define SMCDATASTRUCTURES_MQH
#include <Object.mqh>
#include <CEnumSharing.mqh>
// --- Raw Material: Fair Value Gap ---
class S_FairValueGap : public CObject {
public:
datetime time;
double top;
double bottom;
bool is_valid;
string direction;
S_FairValueGap(datetime p_time, double p_top, double p_bottom, string p_dir) {
time=p_time; top=p_top; bottom=p_bottom; direction=p_dir; is_valid=true;
}
};
// --- Raw Material: Order Block ---
class S_OrderBlock : public CObject {
public:
datetime time;
double top;
double bottom;
bool is_valid;
string direction;
S_OrderBlock(datetime p_time, double p_top, double p_bottom, string p_dir) {
time=p_time; top=p_top; bottom=p_bottom; direction=p_dir; is_valid=true;
}
};
// --- Final Product: A complete tradeable setup ---
// --- UPGRADED with State Management ---
class S_OrderBlockInfo : public CObject {
public:
// --- Core Setup Data ---
double top, bottom; string ob_type; datetime start_time; string object_name;
bool has_fvg; double fvg_top; double fvg_bottom; datetime fvg_start_time;
// --- Storyline Point Memory ---
datetime p1_time; double p1_price;
datetime p2_time; double p2_price;
datetime retest_time; double retest_price;
datetime confirmation_time; double confirmation_price;
// --- NEW: Advanced State Management ---
ENUM_ZONE_STATE state; // สถานะปัจจุบันของโซน (มาแทนที่ is_valid)
int mitigation_count; // นับจำนวนครั้งที่ราคาเข้ามา "แตะ" โซน
// --- Constructor (ปรับปรุงใหม่) ---
S_OrderBlockInfo(double p_top, double p_bottom, string p_type, datetime p_time,
bool p_has_fvg, double p_fvg_top, double p_fvg_bottom, datetime p_fvg_start_time,
datetime p_p1_time, double p_p1_price, datetime p_p2_time, double p_p2_price) {
// Core Data
top=p_top; bottom=p_bottom; ob_type=p_type; start_time=p_time; object_name="OB_"+p_type+"_"+(string)p_time;
has_fvg=p_has_fvg; fvg_top=p_fvg_top; fvg_bottom=p_fvg_bottom; fvg_start_time=p_fvg_start_time;
// Storyline
p1_time = p_p1_time; p1_price = p_p1_price; p2_time = p_p2_time; p2_price = p_p2_price;
retest_time = 0; retest_price = 0; confirmation_time = 0; confirmation_price = 0;
// Initialize new state variables
state = STATE_FRESH;
mitigation_count = 0;
}
};
// --- The definitive SwingPoint Class ---
class SwingPoint : public CObject {
public:
int bar_index;
datetime time;
double price;
ENUM_SWING_TYPE type; // SWING_HIGH or SWING_LOW
ENUM_SWING_STATUS status; // UNCONFIRMED, MINOR, MAJOR, INDUCEMENT
int linked_major_index;
int taken_out_by;
datetime bos_confirmation_time;
int bos_confirmed_at;
int mitigation_count;
SwingPoint() {
bar_index = -1; price = 0.0; time = 0;
type = SWING_TYPE_NONE;
status = STATUS_UNCONFIRMED;
linked_major_index = -1; taken_out_by = -1; bos_confirmation_time = 0; bos_confirmed_at = -1;
}
SwingPoint(const SwingPoint &other) {
bar_index = other.bar_index; price = other.price; time = other.time;
type = other.type; status = other.status;
linked_major_index = other.linked_major_index; taken_out_by = other.taken_out_by; bos_confirmation_time = other.bos_confirmation_time;
bos_confirmed_at = other.bos_confirmed_at;
mitigation_count = 0;
}
};
// --- The definitive CSignalZone Class ---
class CSignalZone : public CObject {
public:
long zone_id;
string object_name;
double top, bottom;
datetime time;
ENUM_ZONE_TYPE zone_type;
ENUM_DIRECTION direction;
ENUM_ZONE_STATE state;
int trades_taken_count;
int mitigation_count;
SwingPoint* origin_swing_ptr;
bool is_significant;
bool has_displacement;
bool has_structure_confirmation;
datetime trigger_level_time;
CSignalZone(long magic_number) {
zone_id = (magic_number == 0) ? 0 : TimeCurrent() + (long)MathRand();
object_name = "EASMC_" + (string)magic_number + "_Zone_" + (string)zone_id;
state = STATE_FRESH;
mitigation_count = 0;
origin_swing_ptr = NULL;
is_significant = false;
trigger_level_time = 0;
trades_taken_count = 0;
has_displacement = false; // +++ ADD
has_structure_confirmation = false; // +++ ADD
}
};
class CDataContext
{
public:
MqlRates rates[];
double atr_buffer[];
double rsi_buffer[];
double volume_buffer[];
double sto_main_buffer[];
double sto_signal_buffer[];
int bars_to_load;
CDataContext(int size) {
bars_to_load = size;
ArrayResize(rates, size);
ArrayResize(atr_buffer, size);
ArrayResize(rsi_buffer, size);
ArrayResize(volume_buffer, size);
ArrayResize(sto_main_buffer, size);
ArrayResize(sto_signal_buffer, size);
}
};
class CTradedLevel : public CObject {
public:
datetime level_time;
int trade_count;
CTradedLevel(datetime p_time) { level_time = p_time; trade_count = 1; }
};
class CManagedTrade : public CObject {
public:
ulong ticket;
datetime entry_time;
double target_sl_price;
double target_tp_price;
datetime trigger_level_time;
bool is_sl_tp_set;
bool is_partial_tp_taken;
bool is_structural_exit_trade;
CManagedTrade(ulong t, double sl, double tp, datetime trigger_time, bool is_structural) {
ticket = t;
entry_time = TimeCurrent();
target_sl_price = sl;
target_tp_price = tp;
trigger_level_time = trigger_time;
is_sl_tp_set = false;
is_partial_tp_taken = false;
is_structural_exit_trade = is_structural;
}
};
#endif // SMCDATASTRUCTURES_MQH