499 lines
16 KiB
Plaintext
499 lines
16 KiB
Plaintext
//+------------------------------------------------------------------+
|
|
//| 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 <Controls\Dialog.mqh>
|
|
#include <Controls\Button.mqh>
|
|
#include <Controls\CheckGroup.mqh>
|
|
#include <Controls\CheckBox.mqh>
|
|
#include <Controls\Label.mqh>
|
|
|
|
CAppDialog AppWindow;
|
|
CButton m_button1; // Bouton + pour surachat
|
|
CButton m_button2; // Bouton - pour surachat
|
|
CButton m_button3; // Bouton + pour survente
|
|
CButton m_button4; // Bouton - pour survente
|
|
CButton m_button_locker; // Bouton de verrouillage
|
|
CCheckBox m_checkbox_sound; // Checkbox pour alerte sonore
|
|
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
|
|
int rsi_handle; // Handle 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 |
|
|
//+------------------------------------------------------------------+
|
|
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,160,230))
|
|
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())
|
|
return(INIT_FAILED);
|
|
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);
|
|
//--- 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
|
|
{
|
|
//--- 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);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
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 (+ pour surachat) |
|
|
//+------------------------------------------------------------------+
|
|
bool CreateButton1(void)
|
|
{
|
|
//--- coordinates
|
|
int x1=INDENT_LEFT;
|
|
int y1=INDENT_TOP + 25;
|
|
int x2=x1+BUTTON_WIDTH;
|
|
int y2=y1+BUTTON_HEIGHT;
|
|
//--- 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 (- pour surachat) |
|
|
//+------------------------------------------------------------------+
|
|
bool CreateButton2(void)
|
|
{
|
|
//--- coordinates
|
|
int x1 = INDENT_LEFT + 25;
|
|
int y1 = INDENT_TOP + 25;
|
|
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 (+ pour survente) |
|
|
//+------------------------------------------------------------------+
|
|
bool CreateButton3(void)
|
|
{
|
|
//--- coordinates
|
|
int x1=INDENT_LEFT;
|
|
int y1=INDENT_TOP + 55;
|
|
int x2=x1+BUTTON_WIDTH;
|
|
int y2=y1+BUTTON_HEIGHT;
|
|
//--- 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 (- pour survente) |
|
|
//+------------------------------------------------------------------+
|
|
bool CreateButton4(void)
|
|
{
|
|
//--- coordinates
|
|
int x1 = INDENT_LEFT + 25;
|
|
int y1 = INDENT_TOP + 55;
|
|
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 + 110;
|
|
int y1 = INDENT_TOP + 85;
|
|
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("🔒")) // Initialement verrouillé
|
|
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;
|
|
int x2 = x1 + 105;
|
|
int y2 = y1 + 20;
|
|
//--- 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);
|
|
//--- add to dialog
|
|
if(!AppWindow.Add(m_checkbox_sound))
|
|
return(false);
|
|
//--- succeed
|
|
return(true);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Create Label pour valeur RSI |
|
|
//+------------------------------------------------------------------+
|
|
bool CreateLabelRSI(void)
|
|
{
|
|
//--- coordinates dans le dialog
|
|
int x1 = INDENT_LEFT + 2;
|
|
int y1 = 0;
|
|
int x2 = x1 + 120;
|
|
int y2 = y1 + 20;
|
|
|
|
//--- 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(20))
|
|
{
|
|
Print("Erreur taille police label RSI");
|
|
return(false);
|
|
}
|
|
if(!m_label_rsi.Color(C'50,205,50'))
|
|
{
|
|
Print("Erreur couleur label RSI");
|
|
return(false);
|
|
}
|
|
|
|
//--- 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");
|
|
return(true);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| 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()
|
|
{
|
|
//--- 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];
|
|
|
|
//--- Créer le texte
|
|
string rsi_text = "RSI: " + DoubleToString(current_rsi, 2);
|
|
|
|
//--- Changer la couleur selon les seuils personnalisables
|
|
color rsi_color = C'0,165,20'; // Vert par défaut
|
|
|
|
if(current_rsi >= surachat_value && !surachat_alerted) // Surachat et pas encore alerté
|
|
{
|
|
rsi_color = C'220,20,60'; // Rouge surachat
|
|
|
|
// 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 <= survente_value && !survente_alerted) // Survente et pas encore alerté
|
|
{
|
|
rsi_color = C'30,144,255'; // Bleu survente
|
|
|
|
// 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 label RSI
|
|
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;
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| 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");
|
|
}
|
|
} |