From 007155cb015e78ac7fea78c611a6000a177ca255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20TOMAZ?= <57752243+percolouco@users.noreply.github.com> Date: Tue, 23 Sep 2025 15:53:14 +0200 Subject: [PATCH] WIP RSI Alert --- RSI_alert.mq5 | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 RSI_alert.mq5 diff --git a/RSI_alert.mq5 b/RSI_alert.mq5 new file mode 100644 index 0000000..68e9391 --- /dev/null +++ b/RSI_alert.mq5 @@ -0,0 +1,284 @@ +//+------------------------------------------------------------------+ +//| 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 // ← NOUVEAU: Include pour label + +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; // ← NOUVEAU: label pour valeur RSI + +//--- 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 | +//+------------------------------------------------------------------+ +bool CreateLabelRSI(void) +{ +//--- coordinates + int x1 = INDENT_LEFT + 25; + int y1 = INDENT_TOP; // Position sous la checkbox + int x2 = x1 + 150; // Largeur pour "RSI: 00.00" + int y2 = y1 + 25; // Hauteur un peu plus grande +//--- create + if(!m_label_rsi.Create(0,"LabelRSI",0,x1,y1,x2,y2)) + return(false); + if(!m_label_rsi.Text("RSI: ---.--")) // Texte initial + return(false); + if(!m_label_rsi.Color(clrLime)) // Couleur verte + return(false); +//--- add to dialog + if(!AppWindow.Add(m_label_rsi)) + return(false); +//--- succeed + return(true); +} + +//+------------------------------------------------------------------+ +//| Mettre à jour l'affichage RSI | +//+------------------------------------------------------------------+ +void UpdateRSIDisplay() +{ +//--- Copier les données RSI + if(CopyBuffer(rsi_handle, 0, 0, 1, rsi_buffer) <= 0) + return; + +//--- Obtenir la valeur actuelle + double current_rsi = rsi_buffer[0]; + +//--- 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 = clrLime; // Neutre (vert) + + if(current_rsi >= 70.0) + rsi_color = clrRed; // Surachat (rouge) + else if(current_rsi <= 30.0) + rsi_color = clrCyan; // Survente (cyan) + +//--- Mettre à jour le label + m_label_rsi.Text(rsi_text); + m_label_rsi.Color(rsi_color); + // Refresh() supprimé - pas nécessaire avec CLabel +} \ No newline at end of file