refacto fenetre

This commit is contained in:
Cédric TOMAZ
2025-09-24 09:21:18 +02:00
parent d8c84fdf7e
commit 03b6a2f05b
+250 -77
View File
@@ -9,21 +9,31 @@
#include <Controls\Dialog.mqh> #include <Controls\Dialog.mqh>
#include <Controls\Button.mqh> #include <Controls\Button.mqh>
#include <Controls\CheckGroup.mqh> #include <Controls\CheckGroup.mqh>
#include <Controls\CheckBox.mqh> // ← AJOUT: Include pour checkbox #include <Controls\CheckBox.mqh>
#include <Controls\Label.mqh> // ← RETOUR: Include pour label dans le dialog #include <Controls\Label.mqh>
CAppDialog AppWindow; CAppDialog AppWindow;
CButton m_button1; // the button object CButton m_button1; // Bouton + pour surachat
CButton m_button2; // the button object CButton m_button2; // Bouton - pour surachat
CButton m_button3; // the button object CButton m_button3; // Bouton + pour survente
CButton m_button4; // the button object CButton m_button4; // Bouton - pour survente
CButton m_button_locker; // the button object CButton m_button_locker; // Bouton de verrouillage
CCheckBox m_checkbox_sound; // ← AJOUT: checkbox pour alerte sonore CCheckBox m_checkbox_sound; // Checkbox pour alerte sonore
CLabel m_label_rsi; // ← RETOUR: label pour valeur RSI dans le dialog CLabel m_label_rsi; // Label pour valeur RSI actuelle
CLabel m_label_surachat; // ← NOUVEAU: Label pour valeur surachat
CLabel m_label_survente; // ← NOUVEAU: Label pour valeur survente
//--- Variables RSI //--- Variables RSI
int rsi_handle; // ← NOUVEAU: handle pour RSI int rsi_handle; // Handle pour RSI
double rsi_buffer[]; // ← NOUVEAU: buffer pour RSI double rsi_buffer[]; // Buffer pour RSI
//--- Variables pour les seuils RSI
double surachat_value = 79.0; // ← NOUVEAU: Valeur seuil surachat
double survente_value = 21.0; // ← NOUVEAU: Valeur seuil survente
bool surachat_alerted = false; // Drapeau pour l'alerte de surachat
bool survente_alerted = false; // Drapeau pour l'alerte de survente
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Expert initialization function | //| Expert initialization function |
@@ -40,7 +50,7 @@ int OnInit()
ArraySetAsSeries(rsi_buffer, true); ArraySetAsSeries(rsi_buffer, true);
//--- create application dialog //--- create application dialog
if(!AppWindow.Create(0,"RSI Alert",0,5,82,200,300)) if(!AppWindow.Create(0,"RSI Alert",0,5,82,160,230))
return(INIT_FAILED); return(INIT_FAILED);
//--- create dependent controls //--- create dependent controls
if(!CreateButton1()) if(!CreateButton1())
@@ -53,9 +63,13 @@ int OnInit()
return(INIT_FAILED); return(INIT_FAILED);
if(!CreateButton_locker()) if(!CreateButton_locker())
return(INIT_FAILED); return(INIT_FAILED);
if(!CreateCheckBoxSound()) // ← AJOUT: Créer la checkbox if(!CreateCheckBoxSound())
return(INIT_FAILED); return(INIT_FAILED);
if(!CreateLabelRSI()) // ← NOUVEAU: Créer le label RSI if(!CreateLabelRSI())
return(INIT_FAILED);
if(!CreateLabelSurachat()) // ← NOUVEAU: Créer le label surachat
return(INIT_FAILED);
if(!CreateLabelSurvente()) // ← NOUVEAU: Créer le label survente
return(INIT_FAILED); return(INIT_FAILED);
//--- run application //--- run application
AppWindow.Run(); AppWindow.Run();
@@ -83,11 +97,51 @@ void OnChartEvent(const int id, // event ID
const double& dparam, // event parameter of the double type const double& dparam, // event parameter of the double type
const string& sparam) // event parameter of the string type const string& sparam) // event parameter of the string type
{ {
//--- Gérer les événements des boutons
if(id == CHARTEVENT_OBJECT_CLICK)
{
if(sparam == "Button1") // Bouton + surachat
{
surachat_value += 1.0;
if(surachat_value > 100.0) surachat_value = 100.0;
UpdateSuraChatDisplay();
Print("Surachat +1: ", surachat_value);
}
else if(sparam == "Button2") // Bouton - surachat
{
surachat_value -= 1.0;
if(surachat_value < 50.0) surachat_value = 50.0; // Minimum logique
UpdateSuraChatDisplay();
Print("Surachat -1: ", surachat_value);
}
else if(sparam == "Button3") // Bouton + survente
{
survente_value += 1.0;
if(survente_value > 50.0) survente_value = 50.0; // Maximum logique
UpdateSurventeDisplay();
Print("Survente +1: ", survente_value);
}
else if(sparam == "Button4") // Bouton - survente
{
survente_value -= 1.0;
if(survente_value < 0.0) survente_value = 0.0;
UpdateSurventeDisplay();
Print("Survente -1: ", survente_value);
}
else if(sparam == "Button_locker") // Bouton de réinitialisation
{
surachat_alerted = false; // Réinitialiser l'alerte surachat
survente_alerted = false; // Réinitialiser l'alerte survente
m_button_locker.Text("🔓"); // Indiquer visuellement le déverrouillage
Print("Alertes réinitialisées");
}
}
AppWindow.ChartEvent(id,lparam,dparam,sparam); AppWindow.ChartEvent(id,lparam,dparam,sparam);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Expert tick function - NOUVEAU | //| Expert tick function |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
void OnTick() void OnTick()
{ {
@@ -107,15 +161,15 @@ void OnTick()
#define BUTTON_HEIGHT (20) // size by Y coordinate #define BUTTON_HEIGHT (20) // size by Y coordinate
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Create the "Button1" button | //| Create the "Button1" button (+ pour surachat) |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
bool CreateButton1(void) bool CreateButton1(void)
{ {
//--- coordinates //--- coordinates
int x1=INDENT_LEFT; // x1 = 11 pixels int x1=INDENT_LEFT;
int y1=INDENT_TOP + 25; // y1 = 11 pixels int y1=INDENT_TOP + 25;
int x2=x1+BUTTON_WIDTH; // x2 = 11 + 100 = 111 pixels int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT; // y2 = 11 + 20 = 32 pixels int y2=y1+BUTTON_HEIGHT;
//--- create //--- create
if(!m_button1.Create(0,"Button1",0,x1,y1,x2,y2)) if(!m_button1.Create(0,"Button1",0,x1,y1,x2,y2))
return(false); return(false);
@@ -125,15 +179,16 @@ bool CreateButton1(void)
return(false); return(false);
//--- succeed //--- succeed
return(true); return(true);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Create Button2 | //| Create Button2 (- pour surachat) |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
bool CreateButton2(void) bool CreateButton2(void)
{ {
//--- coordinates //--- coordinates
int x1 = INDENT_LEFT+ 25; int x1 = INDENT_LEFT + 25;
int y1 = INDENT_TOP + 25 ; // Position sous le premier bouton int y1 = INDENT_TOP + 25;
int x2 = x1 + BUTTON_WIDTH; int x2 = x1 + BUTTON_WIDTH;
int y2 = y1 + BUTTON_HEIGHT; int y2 = y1 + BUTTON_HEIGHT;
//--- create //--- create
@@ -145,17 +200,18 @@ bool CreateButton2(void)
return(false); return(false);
//--- succeed //--- succeed
return(true); return(true);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Create the "Button3" button | //| Create the "Button3" button (+ pour survente) |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
bool CreateButton3(void) bool CreateButton3(void)
{ {
//--- coordinates //--- coordinates
int x1=INDENT_LEFT; // x1 = 11 pixels int x1=INDENT_LEFT;
int y1=INDENT_TOP + 55; // y1 = 11 pixels int y1=INDENT_TOP + 55;
int x2=x1+BUTTON_WIDTH; // x2 = 11 + 100 = 111 pixels int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT; // y2 = 11 + 20 = 32 pixels int y2=y1+BUTTON_HEIGHT;
//--- create //--- create
if(!m_button3.Create(0,"Button3",0,x1,y1,x2,y2)) if(!m_button3.Create(0,"Button3",0,x1,y1,x2,y2))
return(false); return(false);
@@ -165,15 +221,16 @@ bool CreateButton3(void)
return(false); return(false);
//--- succeed //--- succeed
return(true); return(true);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Create Button4 | //| Create Button4 (- pour survente) |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
bool CreateButton4(void) bool CreateButton4(void)
{ {
//--- coordinates //--- coordinates
int x1 = INDENT_LEFT+ 25; int x1 = INDENT_LEFT + 25;
int y1 = INDENT_TOP + 55; // Position sous le premier bouton int y1 = INDENT_TOP + 55;
int x2 = x1 + BUTTON_WIDTH; int x2 = x1 + BUTTON_WIDTH;
int y2 = y1 + BUTTON_HEIGHT; int y2 = y1 + BUTTON_HEIGHT;
//--- create //--- create
@@ -185,27 +242,28 @@ bool CreateButton4(void)
return(false); return(false);
//--- succeed //--- succeed
return(true); return(true);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Create Button_locker | //| Create Button_locker |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
bool CreateButton_locker(void) bool CreateButton_locker(void)
{ {
//--- coordinates //--- coordinates
int x1 = INDENT_LEFT+ 150; int x1 = INDENT_LEFT + 110;
int y1 = INDENT_TOP + 150; // Position sous le premier bouton int y1 = INDENT_TOP + 85;
int x2 = x1 + BUTTON_WIDTH; int x2 = x1 + BUTTON_WIDTH;
int y2 = y1 + BUTTON_HEIGHT; int y2 = y1 + BUTTON_HEIGHT;
//--- create //--- create
if(!m_button_locker.Create(0,"Button_locker ",0,x1,y1,x2,y2)) if(!m_button_locker.Create(0,"Button_locker",0,x1,y1,x2,y2))
return(false); return(false);
if(!m_button_locker.Text("🔒")) if(!m_button_locker.Text("🔒")) // Initialement verrouillé
return(false); return(false);
if(!AppWindow.Add(m_button_locker)) if(!AppWindow.Add(m_button_locker))
return(false); return(false);
//--- succeed //--- succeed
return(true); return(true);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Create CheckBox pour alerte sonore | //| Create CheckBox pour alerte sonore |
@@ -213,16 +271,16 @@ bool CreateButton_locker(void)
bool CreateCheckBoxSound(void) bool CreateCheckBoxSound(void)
{ {
//--- coordinates //--- coordinates
int x1 = INDENT_LEFT ; int x1 = INDENT_LEFT;
int y1 = INDENT_TOP + 85; // Position sous les autres boutons int y1 = INDENT_TOP + 85;
int x2 = x1 + 120; // Largeur pour le texte "Alerte sonore" int x2 = x1 + 105;
int y2 = y1 + 20; // Hauteur standard int y2 = y1 + 20;
//--- create //--- create
if(!m_checkbox_sound.Create(0,"CheckBoxSound",0,x1,y1,x2,y2)) if(!m_checkbox_sound.Create(0,"CheckBoxSound",0,x1,y1,x2,y2))
return(false); return(false);
if(!m_checkbox_sound.Text("Alerte sonore")) if(!m_checkbox_sound.Text("Alerte sonore"))
return(false); return(false);
m_checkbox_sound.Checked(true); // ← CORRECTION: Utiliser Checked() au lieu de Check() m_checkbox_sound.Checked(true);
//--- add to dialog //--- add to dialog
if(!AppWindow.Add(m_checkbox_sound)) if(!AppWindow.Add(m_checkbox_sound))
return(false); return(false);
@@ -231,15 +289,15 @@ bool CreateCheckBoxSound(void)
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Create Label pour valeur RSI - DANS LE DIALOG | //| Create Label pour valeur RSI |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
bool CreateLabelRSI(void) bool CreateLabelRSI(void)
{ {
//--- coordinates dans le dialog - Position plus visible //--- coordinates dans le dialog
int x1 = INDENT_LEFT + 10; // Plus à droite pour être visible int x1 = INDENT_LEFT + 2;
int y1 = 0; // Légèrement plus bas int y1 = 0;
int x2 = x1 + 120; // Largeur suffisante int x2 = x1 + 120;
int y2 = y1 + 20; // Hauteur standard int y2 = y1 + 20;
//--- create le CLabel //--- create le CLabel
if(!m_label_rsi.Create(0,"LabelRSI",0,x1,y1,x2,y2)) if(!m_label_rsi.Create(0,"LabelRSI",0,x1,y1,x2,y2))
@@ -254,7 +312,7 @@ bool CreateLabelRSI(void)
Print("Erreur texte label RSI"); Print("Erreur texte label RSI");
return(false); return(false);
} }
if(!m_label_rsi.FontSize(25)) if(!m_label_rsi.FontSize(20))
{ {
Print("Erreur taille police label RSI"); Print("Erreur taille police label RSI");
return(false); return(false);
@@ -265,51 +323,144 @@ bool CreateLabelRSI(void)
return(false); return(false);
} }
//--- CRUCIAL: Ajouter au dialog //--- Ajouter au dialog
if(!AppWindow.Add(m_label_rsi)) if(!AppWindow.Add(m_label_rsi))
{ {
Print("Erreur ajout label RSI au dialog"); Print("Erreur ajout label RSI au dialog");
return(false); return(false);
} }
Print("Label RSI créé avec succès dans le dialog"); Print("Label RSI créé avec succès");
return(true); return(true);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Mettre à jour l'affichage RSI - DANS LE DIALOG avec DEBUG | //| Create Label pour valeur SURACHAT - NOUVEAU |
//+------------------------------------------------------------------+
bool CreateLabelSurachat(void)
{
//--- coordinates à côté des boutons 1 et 2
int x1 = INDENT_LEFT + 55; // À droite des boutons + et -
int y1 = INDENT_TOP + 25; // Même ligne que boutons 1 et 2
int x2 = x1 + 80; // Largeur pour "Surachat: 70"
int y2 = y1 + 20;
//--- create
if(!m_label_surachat.Create(0,"LabelSurachat",0,x1,y1,x2,y2))
{
Print("Erreur création label surachat");
return(false);
}
//--- Texte initial avec valeur par défaut
string text_surachat = "Surachat: " + DoubleToString(surachat_value, 0);
if(!m_label_surachat.Text(text_surachat))
return(false);
if(!m_label_surachat.FontSize(10))
return(false);
if(!m_label_surachat.Color(C'220,20,60')) // Rouge pour surachat
return(false);
//--- Ajouter au dialog
if(!AppWindow.Add(m_label_surachat))
{
Print("Erreur ajout label surachat au dialog");
return(false);
}
Print("Label Surachat créé avec succès");
return(true);
}
//+------------------------------------------------------------------+
//| Create Label pour valeur SURVENTE - NOUVEAU |
//+------------------------------------------------------------------+
bool CreateLabelSurvente(void)
{
//--- coordinates à côté des boutons 3 et 4
int x1 = INDENT_LEFT + 55; // À droite des boutons + et -
int y1 = INDENT_TOP + 55; // Même ligne que boutons 3 et 4
int x2 = x1 + 80; // Largeur pour "Survente: 30"
int y2 = y1 + 20;
//--- create
if(!m_label_survente.Create(0,"LabelSurvente",0,x1,y1,x2,y2))
{
Print("Erreur création label survente");
return(false);
}
//--- Texte initial avec valeur par défaut
string text_survente = "Survente: " + DoubleToString(survente_value, 0);
if(!m_label_survente.Text(text_survente))
return(false);
if(!m_label_survente.FontSize(10))
return(false);
if(!m_label_survente.Color(C'30,144,255')) // Bleu pour survente
return(false);
//--- Ajouter au dialog
if(!AppWindow.Add(m_label_survente))
{
Print("Erreur ajout label survente au dialog");
return(false);
}
Print("Label Survente créé avec succès");
return(true);
}
//+------------------------------------------------------------------+
//| Mettre à jour l'affichage RSI |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
void UpdateRSIDisplay() void UpdateRSIDisplay()
{ {
//--- Copier les données RSI //--- Copier les données RSI
if(CopyBuffer(rsi_handle, 0, 0, 1, rsi_buffer) <= 0) if(CopyBuffer(rsi_handle, 0, 0, 1, rsi_buffer) <= 0)
{ {
Print("Erreur CopyBuffer RSI"); Print("Erreur CopyBuffer RSI");
return; return;
} }
//--- Obtenir la valeur actuelle //--- Obtenir la valeur actuelle
double current_rsi = rsi_buffer[0]; double current_rsi = rsi_buffer[0];
Print("RSI actuel: ", current_rsi); // DEBUG
//--- Créer le texte avec couleur selon niveau //--- Créer le texte
string rsi_text = "RSI: " + DoubleToString(current_rsi, 2); string rsi_text = "RSI: " + DoubleToString(current_rsi, 2);
//--- Changer la couleur selon les niveaux //--- Changer la couleur selon les seuils personnalisables
color rsi_color = C'0,165,20'; // Vert lime personnalisé (R=50, G=205, B=50) color rsi_color = C'0,165,20'; // Vert par défaut
if(current_rsi >= 55.0) if(current_rsi >= surachat_value && !surachat_alerted) // Surachat et pas encore alerté
{ {
rsi_color = C'220,20,60'; // Rouge crimson (R=220, G=20, B=60) rsi_color = C'220,20,60'; // Rouge surachat
Print("RSI SURACHAT: ", current_rsi);
// Alerte sonore si activée
if(m_checkbox_sound.Checked())
{
Alert("RSI SURACHAT: ", current_rsi, " >= ", surachat_value);
surachat_alerted = true; // Marquer l'alerte comme déclenchée
} }
else if(current_rsi <= 45.0) }
else if(current_rsi <= survente_value && !survente_alerted) // Survente et pas encore alerté
{ {
rsi_color = C'30,144,255'; // Bleu dodger (R=30, G=144, B=255) rsi_color = C'30,144,255'; // Bleu survente
Print("RSI SURVENTE: ", current_rsi);
// Alerte sonore si activée
if(m_checkbox_sound.Checked())
{
Alert("RSI SURVENTE: ", current_rsi, " <= ", survente_value);
survente_alerted = true; // Marquer l'alerte comme déclenchée
}
}
else if(current_rsi < surachat_value && current_rsi > survente_value)
{
// Réinitialiser les drapeaux si RSI revient dans la zone neutre
surachat_alerted = false;
survente_alerted = false;
} }
//--- Mettre à jour le CLabel dans le dialog //--- Mettre à jour le label RSI
if(!m_label_rsi.Text(rsi_text)) if(!m_label_rsi.Text(rsi_text))
{ {
Print("Erreur mise à jour texte RSI"); Print("Erreur mise à jour texte RSI");
@@ -321,6 +472,28 @@ void UpdateRSIDisplay()
Print("Erreur mise à jour couleur RSI"); Print("Erreur mise à jour couleur RSI");
return; return;
} }
}
Print("RSI mis à jour: ", rsi_text); // DEBUG //+------------------------------------------------------------------+
//| Mettre à jour l'affichage SURACHAT - NOUVEAU |
//+------------------------------------------------------------------+
void UpdateSuraChatDisplay()
{
string text_surachat = "Surachat: " + DoubleToString(surachat_value, 0);
if(!m_label_surachat.Text(text_surachat))
{
Print("Erreur mise à jour texte surachat");
}
}
//+------------------------------------------------------------------+
//| Mettre à jour l'affichage SURVENTE - NOUVEAU |
//+------------------------------------------------------------------+
void UpdateSurventeDisplay()
{
string text_survente = "Survente: " + DoubleToString(survente_value, 0);
if(!m_label_survente.Text(text_survente))
{
Print("Erreur mise à jour texte survente");
}
} }