Binärer Histogramm-Indikator für das Wiedersehen von Preis-Levels

 
#property strict
#property indicator_separate_window  //show "Hit" in separate window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_label1  "Hit"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrMediumBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

#property indicator_chart_window     //show "Today Close" in chart window
#property indicator_label2  "DayClose"
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_style1 4
#property indicator_width1 1

//--- input parameters
double findagainvalue[];
input int Startstunde[]=8;
input double Findagainstarttime=16;
input double Findagainendtime=26;
input int Testperiode=1000;
extern double TimeZoneOfData=0;

datetime Valuetime;
bool ExtParameters=false;
//--- indicator buffers
int Hit[];
double TodayCloseBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Hit);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexLabel(0,"Hit");
   SetIndexEmptyValue(0,0);
//  }
//  {
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,TodayCloseBuffer);
   SetIndexLabel(1,"DayClose");
   SetIndexEmptyValue(1,0.0);
   return(0);
//  }
   
//---
   if(Testperiode<=1)
     {
      Print("Wrong input parameters");
      ExtParameters=false;
      return(INIT_FAILED);
     }
   else
      ExtParameters=true;
//--- initialization done

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| 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 counted_bars=IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars>0) counted_bars--;
   int lastbar=Bars-counted_bars;
   if(counted_bars==0) lastbar-=1+1;

   DailyClose(1,lastbar);
   return (0);
  }
//+------------------------------------------------------------------+
//| DailyClose                                                        |
//+------------------------------------------------------------------+
int DailyClose(int offset,int lastbar)
  {
   int shift;
   int tzdiffsec=TimeZoneOfData*3600;
   bool ShowDailyCloseLevel=True;

   for(shift=lastbar;shift>=offset;shift--)
     {
      TodayCloseBuffer[shift]=0;
      if(ShowDailyCloseLevel)
        {
         if(TimeDay(Time[shift]-tzdiffsec)!=TimeDay(Time[shift-1]-tzdiffsec))
           {      // day change
            TodayCloseBuffer[shift]=Close[shift];                    //Initialisierung Buffer
            TodayCloseBuffer[shift+1]=0;                            //Deinitialisierung verhindert Stufen
            Startstunde[shift]=Time[shift];
            findagainvalue[shift]=Close[shift];    
           }
         else
           {
            TodayCloseBuffer[shift]=TodayCloseBuffer[shift+1];
           }
        }
     }
   return(0);
  }


int countHit(int offset,int lastbar)
  {
   int shift;

   for(shift=lastbar;shift>=offset;shift--)

   {
   Hit[shift]=0;
   
   if (Time[0]>Startstunde[0]+Findagainstarttime*3600 && Time[0]<Startstunde[0]+Findagainendtime*3600)
                      Hit[shift]=1;
                      else Hit[shift]=0;
   
   
   }
   return(Hit);
  }
//+------------------------------------------------------------------+

Hallo zusammen, ich programmiere schon einige Zeit, allerdings nur ea s / bisher keine Indikatoren.... die Logik ist doch etwas anders dort. Ich freue mich daher über eure Hilfe. Bei obigem code bekomme ich noch viele Fehlermeldungen

Ich möchte einen Indikator der mir einfach nur eine 1 ausgibt, wenn ein bestimmter Preis in einem bestimmten Zeitraum wieder erreicht wird, ansonsten eine 0.

Beispiel: Open um 8.00h (oderClose um 8.00h). Hat der Kurs diesen Preis am Nachmittag ab 13Uhr des gleichen Tages bis um 7 Uhr des übernächsten Tages wieder erreicht? ja=1 nein=0 

Und das dann für jedes Open um 8h. Im Histogramm sollte dann unter dem Open die 1 oder die 0 stehen. Für das letzte Open wäre dann natürlich zunächst noch die 0 weil die zeit für das wiedersehen ja noch nicht begonnen/geendet hat. 

Ich hab mich mal an der Programmierung des MACDs und einem anderen Indikator orientiert, komme aber nicht wirklich weiter. Für erfahrene Indikator-Programmierer dürfte das ein Klacks sein, schätze ich.

 

Interessanterweise wird hier versucht einen Indikator sowohl im 'indicator_chart_window', als auch im 'indicator_separate_window' zu definieren.

Das ist leider nicht möglich. Also entweder 'indicator_chart_window', oder 'indicator_separate_window'.

Die statische Definition von Plottbuffern ist im MQL5 sowieso ein Krampf.

Ist zwar schon älter dieser Fred, bin aber erst jetzt 'drübergestolpert'.

Grund der Beschwerde: