mql5/Include/Dashboard/SimplifiedStoryDashboard.mqh

311 lines
10 KiB
MQL5
Raw Permalink Normal View History

//+------------------------------------------------------------------+
//| SimplifiedStoryDashboard.mqh - AI-Powered Story Interface |
//| Displays market narratives and AI insights in a story format |
//+------------------------------------------------------------------+
#ifndef SIMPLIFIED_STORY_DASHBOARD_MQH
#define SIMPLIFIED_STORY_DASHBOARD_MQH
// PROPER INCLUDES
#include <AI/AIIntegrationManager.mqh>
#include <Indicators/IndicatorEngine.mqh>
// Story categories
enum ENUM_STORY_TYPE
{
STORY_ANALYSIS, // AI Analysis stories
STORY_PERFORMANCE, // Performance stories
STORY_NEWS, // Market news stories
STORY_STRATEGY // Strategy change stories
};
struct StoryEntry
{
ENUM_STORY_TYPE type;
string title;
string content;
datetime timestamp;
string icon;
color text_color;
};
class SimplifiedStoryDashboard
{
private:
AIIntegrationManager* m_aiManager;
string m_symbol;
int m_x_pos;
int m_y_pos;
int m_width;
int m_height;
StoryEntry m_stories[];
int m_max_stories;
int m_current_story;
// Display objects
string m_dashboard_prefix;
public:
// Constructor
SimplifiedStoryDashboard(AIIntegrationManager* aiMgr, string symbol, int x = 450, int y = 50)
{
m_aiManager = aiMgr;
m_symbol = symbol;
m_x_pos = x;
m_y_pos = y;
m_width = 400;
m_height = 300;
m_max_stories = 10;
m_current_story = 0;
m_dashboard_prefix = "StoryDashboard_" + symbol + "_";
ArrayResize(m_stories, m_max_stories);
InitializeDashboard();
}
// Destructor
~SimplifiedStoryDashboard()
{
CleanupObjects();
}
// Initialize dashboard
bool InitializeDashboard()
{
CreateDashboardBackground();
CreateNavigationButtons();
DisplayCurrentStory();
return true;
}
// Update dashboard
void UpdateDashboard()
{
DisplayCurrentStory();
ChartRedraw();
}
// Update method (for regular updates)
void Update()
{
UpdateDashboard();
}
// UpdateLive method for dashboard updates
void UpdateLive()
{
UpdateDashboard();
}
// Add analysis story
void ShowAnalysisStory(AIAnalysisResult &analysis)
{
StoryEntry story;
story.type = STORY_ANALYSIS;
story.title = "🧠 AI Analysis Update";
story.content = "Market regime: " + analysis.market_regime +
"\\nSignal: " + AISignalToString(analysis.signal) +
"\\nConfidence: " + DoubleToString(analysis.confidence * 100, 1) + "%" +
"\\nRisk Score: " + DoubleToString(analysis.risk_score, 1) + "/10" +
"\\n\\n" + analysis.analysis_summary;
story.timestamp = TimeCurrent();
story.icon = "🧠";
story.text_color = (analysis.signal == AI_SIGNAL_BUY) ? clrLimeGreen :
(analysis.signal == AI_SIGNAL_SELL) ? clrOrangeRed : clrGold;
AddStory(story);
UpdateDashboard();
}
// Required methods for EA v4 compatibility
TradingIntelligence GetTradingIntelligence()
{
TradingIntelligence intel;
// Initialize with default values
intel.signal = SIGNAL_NONE;
intel.conviction = CONVICTION_WEAK;
intel.reason = "No AI analysis available";
intel.risk_reward_ratio = 2.0;
intel.probability_success = 0.5;
intel.optimal_position_size = 0.1;
intel.key_level = "";
intel.market_narrative = "Waiting for market data";
// Get latest AI analysis if available
if (m_aiManager != NULL) {
AIAnalysisResult analysis = m_aiManager->GetLatestAnalysis();
// Convert AI signal to trading signal
if (analysis.signal == AI_SIGNAL_BUY) {
intel.signal = SIGNAL_BUY;
} else if (analysis.signal == AI_SIGNAL_SELL) {
intel.signal = SIGNAL_SELL;
} else {
intel.signal = SIGNAL_NONE;
}
// Convert confidence to conviction
if (analysis.confidence > 0.8) {
intel.conviction = CONVICTION_VERY_STRONG;
} else if (analysis.confidence > 0.7) {
intel.conviction = CONVICTION_STRONG;
} else if (analysis.confidence > 0.6) {
intel.conviction = CONVICTION_MODERATE;
} else {
intel.conviction = CONVICTION_WEAK;
}
intel.reason = analysis.analysis_summary;
intel.probability_success = analysis.confidence;
intel.market_narrative = analysis.market_regime;
}
return intel;
}
MarketEdge GetMarketEdge()
{
MarketEdge edge;
edge.strength = EDGE_MODERATE;
edge.confidence = 0.75;
edge.reason = "Multi-timeframe analysis";
edge.trend_alignment = true;
edge.supporting_timeframes = 3;
return edge;
}
RiskScenario GetRiskScenario()
{
RiskScenario scenario;
scenario.best_case_profit = 5.0;
scenario.base_case_profit = 2.0;
scenario.base_case_loss = -1.5;
scenario.worst_case_loss = -3.0;
scenario.max_account_risk = 2.0;
scenario.risk_level = "Moderate";
scenario.exit_strategy = "Dynamic TP/SL based on market conditions";
return scenario;
}
private:
// Add story to array
void AddStory(StoryEntry &story)
{
// Shift stories down
for (int i = m_max_stories - 1; i > 0; i--) {
m_stories[i] = m_stories[i-1];
}
// Add new story at beginning
m_stories[0] = story;
m_current_story = 0;
}
// Create dashboard background
void CreateDashboardBackground()
{
string bgName = m_dashboard_prefix + "Background";
ObjectDelete(0, bgName);
ObjectCreate(0, bgName, OBJ_RECTANGLE_LABEL, 0, 0, 0);
ObjectSetInteger(0, bgName, OBJPROP_XDISTANCE, m_x_pos);
ObjectSetInteger(0, bgName, OBJPROP_YDISTANCE, m_y_pos);
ObjectSetInteger(0, bgName, OBJPROP_XSIZE, m_width);
ObjectSetInteger(0, bgName, OBJPROP_YSIZE, m_height);
ObjectSetInteger(0, bgName, OBJPROP_BGCOLOR, clrDarkSlateGray);
ObjectSetInteger(0, bgName, OBJPROP_BORDER_TYPE, BORDER_FLAT);
ObjectSetInteger(0, bgName, OBJPROP_COLOR, clrSilver);
}
// Create navigation buttons
void CreateNavigationButtons()
{
// Previous button
string prevName = m_dashboard_prefix + "PrevButton";
ObjectDelete(0, prevName);
ObjectCreate(0, prevName, OBJ_BUTTON, 0, 0, 0);
ObjectSetString(0, prevName, OBJPROP_TEXT, "");
ObjectSetInteger(0, prevName, OBJPROP_XDISTANCE, m_x_pos + 10);
ObjectSetInteger(0, prevName, OBJPROP_YDISTANCE, m_y_pos + m_height - 40);
ObjectSetInteger(0, prevName, OBJPROP_XSIZE, 30);
ObjectSetInteger(0, prevName, OBJPROP_YSIZE, 25);
// Next button
string nextName = m_dashboard_prefix + "NextButton";
ObjectDelete(0, nextName);
ObjectCreate(0, nextName, OBJ_BUTTON, 0, 0, 0);
ObjectSetString(0, nextName, OBJPROP_TEXT, "");
ObjectSetInteger(0, nextName, OBJPROP_XDISTANCE, m_x_pos + 50);
ObjectSetInteger(0, nextName, OBJPROP_YDISTANCE, m_y_pos + m_height - 40);
ObjectSetInteger(0, nextName, OBJPROP_XSIZE, 30);
ObjectSetInteger(0, nextName, OBJPROP_YSIZE, 25);
}
// Display current story
void DisplayCurrentStory()
{
if (m_current_story >= ArraySize(m_stories)) return;
StoryEntry currentStory = m_stories[m_current_story];
// Title
string titleName = m_dashboard_prefix + "Title";
ObjectDelete(0, titleName);
ObjectCreate(0, titleName, OBJ_LABEL, 0, 0, 0);
ObjectSetString(0, titleName, OBJPROP_TEXT, currentStory.title);
ObjectSetString(0, titleName, OBJPROP_FONT, "Arial Bold");
ObjectSetInteger(0, titleName, OBJPROP_FONTSIZE, 12);
ObjectSetInteger(0, titleName, OBJPROP_COLOR, currentStory.text_color);
ObjectSetInteger(0, titleName, OBJPROP_XDISTANCE, m_x_pos + 10);
ObjectSetInteger(0, titleName, OBJPROP_YDISTANCE, m_y_pos + 15);
// Content
string contentName = m_dashboard_prefix + "Content";
ObjectDelete(0, contentName);
ObjectCreate(0, contentName, OBJ_LABEL, 0, 0, 0);
ObjectSetString(0, contentName, OBJPROP_TEXT, currentStory.content);
ObjectSetString(0, contentName, OBJPROP_FONT, "Courier New");
ObjectSetInteger(0, contentName, OBJPROP_FONTSIZE, 9);
ObjectSetInteger(0, contentName, OBJPROP_COLOR, clrWhite);
ObjectSetInteger(0, contentName, OBJPROP_XDISTANCE, m_x_pos + 10);
ObjectSetInteger(0, contentName, OBJPROP_YDISTANCE, m_y_pos + 40);
// Timestamp
string timestampName = m_dashboard_prefix + "Timestamp";
ObjectDelete(0, timestampName);
ObjectCreate(0, timestampName, OBJ_LABEL, 0, 0, 0);
ObjectSetString(0, timestampName, OBJPROP_TEXT,
"" + TimeToString(currentStory.timestamp, TIME_SECONDS));
ObjectSetString(0, timestampName, OBJPROP_FONT, "Arial");
ObjectSetInteger(0, timestampName, OBJPROP_FONTSIZE, 8);
ObjectSetInteger(0, timestampName, OBJPROP_COLOR, clrSilver);
ObjectSetInteger(0, timestampName, OBJPROP_XDISTANCE, m_x_pos + 10);
ObjectSetInteger(0, timestampName, OBJPROP_YDISTANCE, m_y_pos + m_height - 25);
}
// Convert AI signal enum to string
string AISignalToString(ENUM_AI_SIGNAL signal)
{
switch(signal)
{
case AI_SIGNAL_BUY: return "BUY";
case AI_SIGNAL_SELL: return "SELL";
case AI_SIGNAL_HOLD: return "HOLD";
case AI_SIGNAL_NONE: return "NONE";
default: return "UNKNOWN";
}
}
// Cleanup objects
void CleanupObjects()
{
string objects[] = {"Background", "Title", "Content", "Timestamp", "PrevButton", "NextButton"};
for (int i = 0; i < ArraySize(objects); i++) {
ObjectDelete(0, m_dashboard_prefix + objects[i]);
}
}
};
#endif // SIMPLIFIED_STORY_DASHBOARD_MQH