EA subwindow panel

 

Hi,

gibt es eine Möglichkeit, einen EA mit Subwindow-Panel zu erstellen?

So wie das Beispiel Panel unter

[Datenordner]\MQL5\Indikatoren\Beispiele\Panels\SimplePanel\SimplePanel.mq5


Nur eben von einem EA aus.

Das Panel lässt sich zwar von einem EA aus erstellen, wird beim Enternen des EAs aber nicht gelöscht.

Anbei mein sehr einfacher Beispielcode. Gibt es dafür eine Lösung, bzw. was mache ich falsch?


Wäre für jeden Tipp dankbar ;)

Dateien:
EAPanel.zip  104 kb
 

Ich vermute mal, es wurden ein ganzer Haufen an Objekten erzeugt, die in DeInit() gelöschte werden müssten: https://www.mql5.com/en/docs/objects/objectdeleteall

Vielleicht auch mit einem Comment("") dort und einen Neuzeichnen des Chart.

Documentation on MQL5: Object Functions / ObjectsDeleteAll
Documentation on MQL5: Object Functions / ObjectsDeleteAll
  • www.mql5.com
ObjectsDeleteAll - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

ja das kann man machen, du baust dir einen leeren Indikator, fügst den mir resources im Ea ein, rufst ihn über icustom auf und dann hast du ihn.

Da kannst du sogar das indicator window immer richtig auswählen.

hab ich bei einem panel auch so gemacht. 

Du musst aber trotzdem alle Objekte richtig auslöschen, jedoch kannst du dich da auf das subwindow konzentrieren und dort die Objekte löschen bevor der ea sich dann verabschiedet.

 

Danke für die Antworten ;)

Jedoch passiert bei dem Versuch alle Objekte und den Indikator in OnDeinit zu löschen nichts.

EA:

#include "MyClass.mqh"
int myhandle;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(){

    myhandle = iCustom(_Symbol,PERIOD_CURRENT,"MyIndicator.ex5");
    ChartIndicatorAdd(NULL,1,myhandle);

    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
    
    ObjectsDeleteAll(NULL,1,);
    IndicatorRelease(myhandle);
    ChartIndicatorDelete(NULL,1,"Indicator window 1");
    ChartRedraw();
}

Class:

#include <Controls\Defines.mqh>
#include <Controls\Dialog.mqh>

class CMyClass : public CAppDialog
{
    public:
        void  CMyClass();
        virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
        virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); 
};

//+------------------------------------------------------------------+
//| Event Handling                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CMyClass)
EVENT_MAP_END(CAppDialog)

void CMyClass::CMyClass(){}

//+------------------------------------------------------------------+
//| Create                                                           |
//+------------------------------------------------------------------+
bool CMyClass::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
{
   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
      return(false);

   return(true);
}


Indikator:

#property indicator_separate_window 
#property indicator_plots               0

#include "MyClass.mqh"
CMyClass panel;

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  if(!panel.Create(0,"Panel Indicator",0,0,0,0,300))
    return(INIT_FAILED);

  if(!panel.Run())
    return(INIT_FAILED);
  
  return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
   panel.Destroy(reason);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
   return(rates_total);
}

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   panel.ChartEvent(id,lparam,dparam,sparam);
}


Sollte das Panel nicht auch ohne

ChartIndicatorAdd(NULL,1,myhandle);
erscheinen?
 
Tobias Christian Witzigmann #:

Danke für die Antworten ;)

Jedoch passiert bei dem Versuch alle Objekte und den Indikator in OnDeinit zu löschen nichts.

EA:

Class:


Indikator:


Sollte das Panel nicht auch ohne

erscheinen?

Ja, du verwendest die auch falsch

schau dir mal die doku an, ObjectsDeleteAll

du suchst im subwindow, das panal ist aber mal ganz sicher im hauptwindow, weil das lässt sich nicht in ein subwindow legen. Das hatte ich zuerst auch probiert drum bin ich auf die indicator variante gegangen

 
amando #:

Ja, du verwendest die auch falsch

schau dir mal die doku an, ObjectsDeleteAll

du suchst im subwindow, das panal ist aber mal ganz sicher im hauptwindow, weil das lässt sich nicht in ein subwindow legen. Das hatte ich zuerst auch probiert drum bin ich auf die indicator variante gegangen

Aber das Panel wird doch vom Indikator im subwindow 1 erstellt.


 
Tobias Christian Witzigmann #:

Aber das Panel wird doch vom Indikator im subwindow 1 erstellt.


nur in der Theorie, das sollte so funktionieren, tut es aber nicht, ich hab das damals 3 Tage versucht und dann kapituliert.

da kommen immer nur komische Ereignisse.

 
Tobias Christian Witzigmann #:

Aber das Panel wird doch vom Indikator im subwindow 1 erstellt.


Schau Dir an, wie zB, der MQ-MACD (..\MQL5\Indicators\Examples\MACD.mq5) sein Subwindow konstruiert:

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   2
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_type2   DRAW_LINE
#property indicator_color1  Silver
#property indicator_color2  Red
#property indicator_width1  2
#property indicator_width2  1
#property indicator_label1  "MACD"
#property indicator_label2  "Signal"

Es wird nur festgelegt, dass.., aber nicht welches.. Subwindow verwendet werden soll!

Die Identifizierung erfolgt in OnInit über:

//--- name for indicator subwindow label
   string short_name=StringFormat("MACD(%d,%d,%d)",InpFastEMA,InpSlowEMA,InpSignalSMA);
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

Hier sind alle Chartfunktionen inkl. ChartIndicatorGet: https://www.mql5.com/en/docs/chart_operations/chartindicatorget

Documentation on MQL5: Chart Operations / ChartIndicatorGet
Documentation on MQL5: Chart Operations / ChartIndicatorGet
  • www.mql5.com
ChartIndicatorGet - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Ok ich denke ich habe eine Lösung gefunden.

Das Problem liegt am Name des Indicators. Werde noch etwas testen und dann meine Lösung hier posten.

Nochmals danke für eure Beiträge :)

 
Tobias Christian Witzigmann:

Hi,

gibt es eine Möglichkeit, einen EA mit Subwindow-Panel zu erstellen?

So wie das Beispiel Panel unter

[Datenordner]\MQL5\Indikatoren\Beispiele\Panels\SimplePanel\SimplePanel.mq5


Nur eben von einem EA aus.

Das Panel lässt sich zwar von einem EA aus erstellen, wird beim Enternen des EAs aber nicht gelöscht.

Anbei mein sehr einfacher Beispielcode. Gibt es dafür eine Lösung, bzw. was mache ich falsch?


Wäre für jeden Tipp dankbar ;)

Hallo,

habe einen Code irgendwo im Forum gefunden, aber weiß nicht mehr wo. 

Ich denke, weil dieses Panel auf Basis von Indikator erstellt wurde, könnte es funktionieren. (getestet mit Panel habe ich noch nicht!)

Hier ist der Code.

//+------------------------------------------------------------------+
//|                                             Indicator Delete.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ActionsOnTheChart(1);
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool ActionsOnTheChart(const long chart_id) {
   int sub_windows_total =-1;
   int indicators_total  =0;
//---
   if(!ChartWindowsTotal(chart_id,sub_windows_total)) {
      return(false);
   }
//---
   for(int i=sub_windows_total-1; i>=0; i--) {
      indicators_total=ChartIndicatorsTotal(chart_id,i);
      //---
      if(indicators_total>0) {
         ChIndicatorsDelete(chart_id,i,indicators_total);
      }
   }
//---
   return(true);
}
//+------------------------------------------------------------------+
bool ChartWindowsTotal(const long chart_ID,int &sub_windows_total) {
   long value=-1;
//---
   if(!ChartGetInteger(chart_ID,CHART_WINDOWS_TOTAL,0,value)) {
      Print(__FUNCTION__," Error = ",GetLastError());
      return(false);
   }
//---
   sub_windows_total=(int)value;
//---
   return(true);
}
//+------------------------------------------------------------------+
void ChIndicatorsDelete(const long  chart_id,
                        const int   sub_window,
                        const int   indicators_total) {
   for(int i=indicators_total-1; i>=0; i--) {
      string indicator_name=ChartIndicatorName(chart_id,sub_window,i);
      //---
      ChIndicatorDelete(indicator_name,chart_id,sub_window);
   }
//---
   return;
}
//+------------------------------------------------------------------+
bool ChIndicatorDelete(const string short_name,
                       const long   chart_id=0,
                       const int    sub_window=0) {
   bool res=ChartIndicatorDelete(chart_id,sub_window,short_name);
//---
   if(!res) {
      Print("Failed to delete indicator:\"",short_name,"\". Error: ",GetLastError());
      //---
      return(false);
   }
//---
   return(true);
}

Gruß Igor

Grund der Beschwerde: