Beschriftung im 2. Sub-Fenster - Seite 2

 
Dom130568:

Hallo Carl,


danke für den Hinweis, aber die Beschreibung kann ich mittlerweile singen. Meine Screenshots  anscheinend nicht mit übertragen daher der Anhang.


der Codeausschnitt:

  1. Also die ChartID (long) ist nicht der WindowIndex(int)!
  2. Soweit ich mich erinnere ist 0 nur eine Leerstelle für das aktuelle - daher schreibst Du immer ins selbe Fenster, dem aktuellen!
  3. Hier sind die Funktionen für den Chart: https://docs.mql4.com/chart_operations/chartid
  4. Hier die für Objects: https://docs.mql4.com/objects
ChartID - Chart Operations - MQL4 Reference
ChartID - Chart Operations - MQL4 Reference
  • docs.mql4.com
ChartID - Chart Operations - MQL4 Reference
 
Carl Schreiber:
  1. Also die ChartID (long) ist nicht der WindowIndex(int)!
  2. Soweit ich mich erinnere ist 0 nur eine Leerstelle für das aktuelle - daher schreibst Du immer ins selbe Fenster, dem aktuellen!
  3. Hier sind die Funktionen für den Chart: https://docs.mql4.com/chart_operations/chartid
  4. Hier die für Objects: https://docs.mql4.com/objects

Hallo Carl,

ChartID hatte ich aufgrund der Suggestion von amando hinzugefügt. Hatte aber keinen Einfluß. Wieder entfernt.

Im Grunde will ich in das Indikator-Fenster Momentum die grüne 2 hineinbekommen. Und der WindowIndex ist mit Wert 2 ja auch korrekt. Erstaunlich finde ich, daß der WindowIndex Wert in ObjectCreate völlig ignoriert wird. Ob ich da 0,1 oder 2 reinschreibe, es landet immer im ersten Sub-Fenster. 

Vielleicht nochmal mein Wunsch zusammengefasst: 

Ich möchte im Indikator Momentum ein Label platzieren. Dieses Fenster ist nun (zufällig) das 2. Subfenster. Kann ja auch mal das erste oder dritte sein. Daher soll ja der WindowIndex ausgelesen und zugewiesen werden. 

Ein Beispiel wäre toll wo jemand ein Label in einen Indikator platziert und das man dieses Indikatorfenster in beliebiger Reihenfolge später platzieren kann.

Hier nochmal der komplette Code für den individuellen Momentum Indikator. Ich habe dem Label nur testhalber den WindowIndex zugewiesen damit ich sehen kann, das es tatsächlich 2 ist. Später soll der Momentumwert (gut lesbar) angezeigt werden. Aber bitte auch im Momentum Fenster.

//+------------------------------------------------------------------+
//|                                                        Test1.mq4 |
//|                                                          Dominik |
//|                                       dominikus.evers@icloud.com |
//+------------------------------------------------------------------+
#property copyright "Dominik"
#property link      "dominikus.evers@icloud.com"
#property version   "1.00"
#property strict


#property indicator_separate_window
#property indicator_buffers 3


//#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  5

//#property indicator_label2  "Label2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  5

//#property indicator_label3  "Label3"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrWhite
#property indicator_style3  STYLE_SOLID
#property indicator_width3  3

//--- input parameters
input int      barsToProcess=100;
//--- indicator buffers
double         Label1_Buffer[];
double         Label2_Buffer[];
double         Label3_Buffer[];
  
 
  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   
   IndicatorShortName("Momentum");
   int windowIndex=WindowFind("Momentum");
                 
  ObjectCreate(0,"Label", OBJ_LABEL,windowIndex,0,0);
  ObjectSet("Label", OBJPROP_CORNER,1);
  ObjectSet("Label", OBJPROP_XDISTANCE,40);
  ObjectSet("Label", OBJPROP_YDISTANCE,12);
  ObjectSetText("Label",windowIndex,25,"Tahoma",Lime);     
  
  
    
  // IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,Label1_Buffer);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,Label2_Buffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Label3_Buffer);
   
    
   
 //  MathSrand(TimeLocal());
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

     int limit;
     int counted_bars=IndicatorCounted();
  //---- check for possible errors
     if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
  //---- main loop
  
     int i;
     for(i=0; i<limit; i++)
  {
    
   // Umschalten Histogramm Farbe:
    if (((iMomentum(NULL,0,14,0,i)-100)*100) < 0)
      {
      Label2_Buffer[i]=(iMomentum(NULL,0,14,0,i)-100)*90;
      Label1_Buffer[i]=0;
      }
      else
      {
      Label2_Buffer[i]=0;
      Label1_Buffer[i]=(iMomentum(NULL,0,14,0,i)-100)*90;
      }
      
      // die durchgezogene Linie:
      Label3_Buffer[i]=(iMomentum(NULL,0,14,0,i)-100)*100; 
      double wert=(iMomentum(NULL,0,14,0,0)-100)*100; 
        
    //  ObjectSetText("Label",DoubleToStr(wert,2),25,"Tahoma",White); 
    }   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
  
//+------------------------------------------------------------------+
 

Hallo zusammen,

das "Problem" ist gelöst. Ich habe lediglich die Indikatorfenster gelöscht und neu aus dem Navigator eingefügt. Jetzt funktioniert alles wie gewünscht. Es funktionierte nur nicht während der Programmierung.

Sorry für die Umstände.

Allen einen guten Rutsch und ein erfolgreiches 2019.


Grüße, Dominik

Grund der Beschwerde: