Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Rechtecke Zeichnen bei einer Bedingung (http://www.expert-advisor.com/forum/showthread.php?t=6098)

T.P. 22.04.18 19:36

Rechtecke Zeichnen bei einer Bedingung
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo Leute..

Der Indikator soll eigentlich bei jeder zutreffenden Bedingung nicht nur einen Pfeil zeichnen sondern auch ein farbiges Rechteck um die beiden Kerzen.

Das High und Low der Signalkerze gibt die Höhe des Rechteckes an.
Start und Endpunkt des Rechtecks sind jeweils 2 Kerzen.


Warum macht der Indikator jetzt nur einmalig ein rechteck und nicht wie die Pfeile überall eins?
Könnte mir jemand bitte den Code richtig umstellen und es erklären?

Code:

#property copyright "Tommy"
#property link      "https://www.mql5.com"
#property version  "1.00"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue

double Buytrigger[];
double Selltrigger[];
double Signal[];

extern int  Feldfarbe = PaleGreen;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                        |
//+------------------------------------------------------------------+
int init()
{

//---- indicators

  SetIndexStyle(0, DRAW_ARROW, EMPTY);
  SetIndexArrow(0, 234);
  SetIndexBuffer(0, Signal);
  SetIndexBuffer(1, Buytrigger);
  SetIndexBuffer(2, Selltrigger);
 
//----
  SetIndexLabel(0,"Signal");
  SetIndexLabel(1,"Buytrigger");
  SetIndexLabel(2,"Selltrigger");
 
  return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                      |
//+------------------------------------------------------------------+
int deinit()
{
  return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  int limit;
  int counted_bars=IndicatorCounted();
  if(counted_bars<0) return(-1);
  limit=Bars-counted_bars;


//---
  for(int i=1; i<limit; i++)
    {       
       
      double EH = iHigh(NULL,0,i+1); 
      double EL = iLow(NULL,0,i+1); 
      double ZH = iHigh(NULL,0,i); 
      double ZL = iLow(NULL,0,i);
      double atr = iATR(_Symbol, 0, 100, i)*0.5;
     
         
      if ((ZH > EH || ZH == EH) && (ZL < EL || ZL == EL)) 
     
      { 
      Buytrigger[i]  = High[i];
      Selltrigger[i] = Low[i];
      Signal[i] = High[i] + atr; 
      ObjectCreate("Rechteck", OBJ_RECTANGLE, 0, Time[i], High[i], Time[i+1], Low[i]);
      ObjectSetInteger(0,"Rechteck",OBJPROP_COLOR,Feldfarbe);
      }   

}
 
  return(0);
}


AVT 22.04.18 22:43

Du hast eine Schleife, in der Du ObjectCreate() benutzt. Jedes neu geschaffene Objekt braucht aber einen einzigartigen Namen. Das mit ObjectCreate("Rechteck",...) funktioniert also nur einmal, weil der Name eben "Rechteck" ist und nicht - wenn es mehrere sind - "Rechteck-1", "Rechteck-2", "Rechteck-3" ...

Ich hoffe, das hilft schon. AVT

T.P. 23.04.18 15:15

DANKE AVT!!!!!!

Man den ganzen Sonntag verzweifelt!!!

Habe es jetzt so gelöst das ich statt dem Namen den Wert des Triggers angebe. Der ist nämlich immer anders. Danke nochmal vielmals. :):):):)

Code:

#property copyright "Tommy"
#property link      "https://www.mql5.com"
#property version  "1.00"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue

double Buytrigger[];
double Selltrigger[];
double Signal[];

extern int  Feldfarbe = PaleGreen;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                        |
//+------------------------------------------------------------------+
int init()
{

//---- indicators

  SetIndexStyle(0, DRAW_ARROW, EMPTY);
  SetIndexArrow(0, 234);
  SetIndexBuffer(0, Signal);
  SetIndexBuffer(1, Buytrigger);
  SetIndexBuffer(2, Selltrigger);
 
//----
  SetIndexLabel(0,"Signal");
  SetIndexLabel(1,"Buytrigger");
  SetIndexLabel(2,"Selltrigger");
 
  return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                      |
//+------------------------------------------------------------------+
int deinit()
{
  return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  int limit;
  int counted_bars=IndicatorCounted();
  if(counted_bars<0) return(-1);
  limit=Bars-counted_bars;


//---
  for(int i=1; i<limit; i++)
    {       
       
      double EH = iHigh(NULL,0,i+1); 
      double EL = iLow(NULL,0,i+1); 
      double ZH = iHigh(NULL,0,i); 
      double ZL = iLow(NULL,0,i);
      double atr = iATR(_Symbol, 0, 100, i)*0.5;
     
         
      if ((ZH > EH || ZH == EH) && (ZL < EL || ZL == EL)) 
     
      { 
      Buytrigger[i]  = High[i];
      Selltrigger[i] = Low[i];
      Signal[i] = High[i] + atr; 
      ObjectCreate(" Buy Trigger " +Buytrigger[i]+"", OBJ_RECTANGLE, 0, Time[i], High[i], Time[i+1], Low[i]);
      ObjectSetInteger(0," Buy Trigger " +Buytrigger[i]+"",OBJPROP_COLOR,Feldfarbe);
      }   

}
 
  return(0);
}



Alle Zeitangaben in WEZ +2. Es ist jetzt 11:05 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum