//+------------------------------------------------------------------+ //| OpenAI.mqh | //| OpenAI API Integration Module | //+------------------------------------------------------------------+ #property copyright "QuarterTheory x VIZION" #property strict #include "GlobalVariables.mqh" #include "InputParams.mqh" #include "Utilities.mqh" #include "Tradeexecution.mqh" #include "Openai.mqh" //================ FORWARD DECLARATIONS ==================// //bool IsAIEnabled(); //================ OPENAI GLOBALS ==================// string OpenAI_API_Key_Internal = "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"; // Internal storage string OpenAI_Model = "gpt-4o-mini"; // or "gpt-4o-mini" for faster/cheaper string OpenAI_Endpoint = "https://api.openai.com/v1/chat/completions"; // Response cache to avoid duplicate API calls struct OpenAI_Cache { string last_question; string last_response; datetime last_time; }; OpenAI_Cache AI_Cache; //+------------------------------------------------------------------+ //| Initialize OpenAI API | //+------------------------------------------------------------------+ bool InitializeOpenAI(string api_key) { if(StringLen(api_key) < 20) { Print("❌ OpenAI API key invalid or too short"); return false; } OpenAI_API_Key_Internal = api_key; // Store internally AI_Cache.last_question = ""; AI_Cache.last_response = ""; AI_Cache.last_time = 0; Print("✅ OpenAI API initialized with model: ", OpenAI_Model); return true; } //+------------------------------------------------------------------+ //| Build market context for AI analysis | //+------------------------------------------------------------------+ string BuildMarketContext() { string context = "Current Market Context:\n"; context += "=======================\n\n"; // Market Mode context += "MARKET MODE:\n"; context += "- Family: " + FamilyToText(Current_Family) + "\n"; context += "- Bias: " + BiasToText(Current_Bias) + "\n"; context += "- Strength: " + StrengthToText(Current_Strength) + "\n"; context += "- State: " + StateToText(Current_State) + "\n"; context += "- MFIB Bias: " + BiasToText(MFIB_Bias) + "\n\n"; // Technical Indicators context += "INDICATORS:\n"; context += "- ADX: " + DoubleToString(Current_ADX, 1) + "\n"; context += "- ATR: " + DoubleToString(Current_ATR, 5) + "\n"; context += "- Stoch K: " + DoubleToString(Stoch_K_Current, 1) + "\n"; context += "- Stoch D: " + DoubleToString(Stoch_D_Current, 1) + "\n\n"; // MA Positions context += "MOVING AVERAGES:\n"; context += "- MA7: " + DoubleToString(MA_Current[0], 5) + "\n"; context += "- MA14: " + DoubleToString(MA_Current[1], 5) + "\n"; context += "- MA21: " + DoubleToString(MA_Current[2], 5) + "\n"; context += "- MA50: " + DoubleToString(MA_Current[3], 5) + "\n"; context += "- MA140: " + DoubleToString(MA_Current[4], 5) + "\n\n"; // Price Levels double current = MidPrice(); context += "PRICE LEVELS:\n"; context += "- Current: " + DoubleToString(current, 5) + "\n"; context += "- MFIB .382: " + DoubleToString(MFIB_Level_382, 5) + "\n"; context += "- MFIB .618: " + DoubleToString(MFIB_Level_618, 5) + "\n\n"; // Signals context += "SIGNALS:\n"; context += "- Praise Count: " + IntegerToString(Praise_Count) + "/8\n"; context += "- Warning Count: " + IntegerToString(Warning_Confluence_Count) + "\n"; if(Praise_Count > 0) { context += "- Active Praise: "; if(Praise_Triple_Magnet) context += "TripleMagnet "; if(Praise_Power_Couple) context += "PowerCouple "; if(Praise_MFIB_Staircase) context += "MFIB-Staircase "; if(Praise_MFIB_Express) context += "MFIB-Express "; if(Praise_MFIB_Breakout) context += "MFIB-Breakout "; if(Praise_MA_Stack) context += "MA-Stack "; if(Praise_Clean_Reclaim) context += "CleanReclaim "; if(Praise_Multi_Breakout) context += "MultiBreakout "; context += "\n"; } if(Warning_Confluence_Count > 0) { context += "- Active Warnings: "; if(MA7_Cross_14_Warning) context += "MA7x14 "; if(MA7_Cross_21_Warning) context += "MA7x21 "; if(Stoch_Extreme_Warning) context += "StochExtreme "; if(MFIB_Reject_Warning) context += "MFIB-Reject "; if(Band_Snap_Warning) context += "BandSnap "; context += "\n"; } context += "\n"; // Open Positions int total_positions = ArraySize(OpenPositions); context += "POSITIONS:\n"; context += "- Total Open: " + IntegerToString(total_positions) + "\n"; int buy_count = 0, sell_count = 0; double total_profit = 0; for(int i=0; i= 20); }