//+------------------------------------------------------------------+ //| LearnCAppDialog.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Perco" #property link "https://www.mql5.com" #property version "1.00" #include #include #include #include // ← AJOUT: Include pour checkbox #include // ← RETOUR: Include pour label dans le dialog CAppDialog AppWindow; CButton m_button1; // the button object CButton m_button2; // the button object CButton m_button3; // the button object CButton m_button4; // the button object CButton m_button_locker; // the button object CCheckBox m_checkbox_sound; // ← AJOUT: checkbox pour alerte sonore CLabel m_label_rsi; // ← RETOUR: label pour valeur RSI dans le dialog //--- Variables RSI int rsi_handle; // ← NOUVEAU: handle pour RSI double rsi_buffer[]; // ← NOUVEAU: buffer pour RSI //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Créer le handle RSI rsi_handle = iRSI(_Symbol, _Period, 14, PRICE_CLOSE); if(rsi_handle == INVALID_HANDLE) { Print("Erreur lors de la création du handle RSI"); return(INIT_FAILED); } ArraySetAsSeries(rsi_buffer, true); //--- create application dialog if(!AppWindow.Create(0,"RSI Alert",0,5,82,200,300)) return(INIT_FAILED); //--- create dependent controls if(!CreateButton1()) return(INIT_FAILED); if(!CreateButton2()) return(INIT_FAILED); if(!CreateButton3()) return(INIT_FAILED); if(!CreateButton4()) return(INIT_FAILED); if(!CreateButton_locker()) return(INIT_FAILED); if(!CreateCheckBoxSound()) // ← AJOUT: Créer la checkbox return(INIT_FAILED); if(!CreateLabelRSI()) // ← NOUVEAU: Créer le label RSI return(INIT_FAILED); //--- run application AppWindow.Run(); //--- succeed return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Libérer le handle RSI if(rsi_handle != INVALID_HANDLE) IndicatorRelease(rsi_handle); //--- destroy dialog AppWindow.Destroy(reason); } //+------------------------------------------------------------------+ //| Expert chart event function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, // event ID const long& lparam, // event parameter of the long type const double& dparam, // event parameter of the double type const string& sparam) // event parameter of the string type { AppWindow.ChartEvent(id,lparam,dparam,sparam); } //+------------------------------------------------------------------+ //| Expert tick function - NOUVEAU | //+------------------------------------------------------------------+ void OnTick() { //--- Mettre à jour la valeur RSI UpdateRSIDisplay(); } //+------------------------------------------------------------------+ //| defines | //+------------------------------------------------------------------+ //--- indents and gaps #define INDENT_LEFT (11) // indent from left (with allowance for border width) #define INDENT_TOP (11) // indent from top (with allowance for border width) #define CONTROLS_GAP_X (5) // gap by X coordinate //--- for buttons #define BUTTON_WIDTH (20) // size by X coordinate #define BUTTON_HEIGHT (20) // size by Y coordinate //+------------------------------------------------------------------+ //| Create the "Button1" button | //+------------------------------------------------------------------+ bool CreateButton1(void) { //--- coordinates int x1=INDENT_LEFT; // x1 = 11 pixels int y1=INDENT_TOP + 25; // y1 = 11 pixels int x2=x1+BUTTON_WIDTH; // x2 = 11 + 100 = 111 pixels int y2=y1+BUTTON_HEIGHT; // y2 = 11 + 20 = 32 pixels //--- create if(!m_button1.Create(0,"Button1",0,x1,y1,x2,y2)) return(false); if(!m_button1.Text("+")) return(false); if(!AppWindow.Add(m_button1)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create Button2 | //+------------------------------------------------------------------+ bool CreateButton2(void) { //--- coordinates int x1 = INDENT_LEFT+ 25; int y1 = INDENT_TOP + 25 ; // Position sous le premier bouton int x2 = x1 + BUTTON_WIDTH; int y2 = y1 + BUTTON_HEIGHT; //--- create if(!m_button2.Create(0,"Button2",0,x1,y1,x2,y2)) return(false); if(!m_button2.Text("-")) return(false); if(!AppWindow.Add(m_button2)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create the "Button3" button | //+------------------------------------------------------------------+ bool CreateButton3(void) { //--- coordinates int x1=INDENT_LEFT; // x1 = 11 pixels int y1=INDENT_TOP + 55; // y1 = 11 pixels int x2=x1+BUTTON_WIDTH; // x2 = 11 + 100 = 111 pixels int y2=y1+BUTTON_HEIGHT; // y2 = 11 + 20 = 32 pixels //--- create if(!m_button3.Create(0,"Button3",0,x1,y1,x2,y2)) return(false); if(!m_button3.Text("+")) return(false); if(!AppWindow.Add(m_button3)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create Button4 | //+------------------------------------------------------------------+ bool CreateButton4(void) { //--- coordinates int x1 = INDENT_LEFT+ 25; int y1 = INDENT_TOP + 55; // Position sous le premier bouton int x2 = x1 + BUTTON_WIDTH; int y2 = y1 + BUTTON_HEIGHT; //--- create if(!m_button4.Create(0,"Button4",0,x1,y1,x2,y2)) return(false); if(!m_button4.Text("-")) return(false); if(!AppWindow.Add(m_button4)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create Button_locker | //+------------------------------------------------------------------+ bool CreateButton_locker(void) { //--- coordinates int x1 = INDENT_LEFT+ 150; int y1 = INDENT_TOP + 150; // Position sous le premier bouton int x2 = x1 + BUTTON_WIDTH; int y2 = y1 + BUTTON_HEIGHT; //--- create if(!m_button_locker.Create(0,"Button_locker ",0,x1,y1,x2,y2)) return(false); if(!m_button_locker.Text("🔒")) return(false); if(!AppWindow.Add(m_button_locker)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create CheckBox pour alerte sonore | //+------------------------------------------------------------------+ bool CreateCheckBoxSound(void) { //--- coordinates int x1 = INDENT_LEFT ; int y1 = INDENT_TOP + 85; // Position sous les autres boutons int x2 = x1 + 120; // Largeur pour le texte "Alerte sonore" int y2 = y1 + 20; // Hauteur standard //--- create if(!m_checkbox_sound.Create(0,"CheckBoxSound",0,x1,y1,x2,y2)) return(false); if(!m_checkbox_sound.Text("Alerte sonore")) return(false); m_checkbox_sound.Checked(true); // ← CORRECTION: Utiliser Checked() au lieu de Check() //--- add to dialog if(!AppWindow.Add(m_checkbox_sound)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create Label pour valeur RSI - DANS LE DIALOG | //+------------------------------------------------------------------+ bool CreateLabelRSI(void) { //--- coordinates dans le dialog - Position plus visible int x1 = INDENT_LEFT + 10; // Plus à droite pour être visible int y1 = 0; // Légèrement plus bas int x2 = x1 + 120; // Largeur suffisante int y2 = y1 + 20; // Hauteur standard //--- create le CLabel if(!m_label_rsi.Create(0,"LabelRSI",0,x1,y1,x2,y2)) { Print("Erreur création label RSI"); return(false); } //--- Texte et couleur initiaux if(!m_label_rsi.Text("RSI: ---.--")) { Print("Erreur texte label RSI"); return(false); } if(!m_label_rsi.FontSize(25)) { Print("Erreur taille police label RSI"); return(false); } if(!m_label_rsi.Color(C'50,205,50')) { Print("Erreur couleur label RSI"); return(false); } //--- CRUCIAL: Ajouter au dialog if(!AppWindow.Add(m_label_rsi)) { Print("Erreur ajout label RSI au dialog"); return(false); } Print("Label RSI créé avec succès dans le dialog"); return(true); } //+------------------------------------------------------------------+ //| Mettre à jour l'affichage RSI - DANS LE DIALOG avec DEBUG | //+------------------------------------------------------------------+ void UpdateRSIDisplay() { //--- Copier les données RSI if(CopyBuffer(rsi_handle, 0, 0, 1, rsi_buffer) <= 0) { Print("Erreur CopyBuffer RSI"); return; } //--- Obtenir la valeur actuelle double current_rsi = rsi_buffer[0]; Print("RSI actuel: ", current_rsi); // DEBUG //--- Créer le texte avec couleur selon niveau string rsi_text = "RSI: " + DoubleToString(current_rsi, 2); //--- Changer la couleur selon les niveaux color rsi_color = C'0,165,20'; // Vert lime personnalisé (R=50, G=205, B=50) if(current_rsi >= 55.0) { rsi_color = C'220,20,60'; // Rouge crimson (R=220, G=20, B=60) Print("RSI SURACHAT: ", current_rsi); } else if(current_rsi <= 45.0) { rsi_color = C'30,144,255'; // Bleu dodger (R=30, G=144, B=255) Print("RSI SURVENTE: ", current_rsi); } //--- Mettre à jour le CLabel dans le dialog if(!m_label_rsi.Text(rsi_text)) { Print("Erreur mise à jour texte RSI"); return; } if(!m_label_rsi.Color(rsi_color)) { Print("Erreur mise à jour couleur RSI"); return; } Print("RSI mis à jour: ", rsi_text); // DEBUG }