Zum Inhalt springen
View in the app

A better way to browse. Learn more.

#T/N/X/T

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Indikator auf Tagesbasis in kleineren Zeiteinheiten verwenden

Geschrieben

Hallo liebe Community,

 

ich habe mir einen Trendindikator auf Tagesbasis geschrieben (einfache if-Abfragen auf zwei unterschiedliche SMAs der PERIOD_D1). Für jeden Tag wird der Indikator berechnet, in dem ich die iMA-Funktionen mit einem Zähler füttere.

 

Jetzt möchte ich diesen Indikator auf Charts zB auf Stunden-/15min-Basis anzeigen, aber dann wird der Indikator natürlich falsch angezeigt, da der eingehende Zähler sich ja jetzt auf die Balken der geringeren Zeiteinheit bezieht, der iMA aber auf PERIOD_D1 berechnet. Was ich mir wünsche ist, dass die Werte des o.g. Indikators über alle Balken der geringeren Zeiteinheit während eines Tages konstant blieben.

 

Hat jemand eine Idee, wie man das umsetzen könnte? Bei Bedarf poste ich auch Code. Viel mehr als ne Schleife die pro Zähler eine Bedingung auf iMA(NULL,PERIOD_D1,MA_Periode,0,0,0,Zähler) prüft und bei erfüllter Bedingung den Indikator[Zähler] = 1, sonst Indikator[Zähler] = 0 setzt, steht da aber nicht drin.

 

Danke Euch schon jetzt für Eure Hilfe.


Gruß HechTrader.

Featured Replies

Geschrieben
  • Autor

Danke für die schnelle Antwort. Leider komme ich nicht so richtig weiter mit der Funktion bzw. weiß nicht, wo und wie ich sie einbauen soll. Wenn das hier mein aktueller Code ist:

 

...
#property strict
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Uptrend
#property indicator_label1  "Uptrend"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDarkGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2



//--- input parameters
input int      SMA_lang=200;
input int      SMA_kurz=20;
//--- indicator buffers
double   Uptrend[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Uptrend);  
   SetIndexDrawBegin(0,SMA_lang);  
   
//---
   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[])
  {
//---
for(int i=300;i>=0;i--)
{
   if iMA(NULL,PERIOD_D1,SMA_lang,0,0,0,i) > iMA(NULL,PERIOD_D1,SMA_lang,0,0,0,(i+3))

                        {
                            Uptrend[i]=1;
                        }
                                      
   else                     Uptrend[i]=0;
                         
}       
                                   
//--- return value of prev_calculated for next call
   return(rates_total);
  }

wo müsste ich dann die ArrayCopySeries() einbauen und mit welchen Werten füllen?

 

Hab die Funktion noch nicht durchblickt. Danke und Gruß

Geschrieben
  • Autor

Habe gerade weitergeforscht, und ich glaube, dass ich mit der Funktion iBarShift weiterkomme. Am Wochenende teste ich mal.

 

Thx so far :-)

Geschrieben

Habe gerade weitergeforscht, und ich glaube, dass ich mit der Funktion iBarShift weiterkomme. Am Wochenende teste ich mal.

 

iBarShift wird Dir da nicht helfen, da Du ja Daten aus einem anderen Timeframe berechnen willst.

 

Hier mal ein Beispiel zu ArrayCopySeries (musst mal testen):

extern int     TimeFrame    =  1440;  
int limit;
 
if (TimeFrame != Period())
   {
      datetime TimeArray[];
         limit = MathMax(limit,TimeFrame/Period());
         ArrayCopySeries(TimeArray, MODE_TIME, NULL,TimeFrame);
                         
         for(i=0,int y=0; i<limit; i++)
         {
            if(Time[i]<TimeArray[y]) y++;

         GD[i] = iMA(NULL,TimeFrame,SMA_lang,0,0,0,y);
         }
   
         
      return(0);         
   }
Geschrieben
  • Autor

Hi conglom-o,

 

fantastisch, Du hast mir wirklich sehr weitergeholfen an einer Stelle, wo ich als relativer Anfänger nicht mehr weitergekommen bin! 10points.gif Jetzt kann ich erstmal weitermachen.

 

Um zu testen, und um mal hier für ggf. weitere Newbies mit derselben Frage ein bisschen Code reinzustellen, habe ich mir einfach in nem separaten Indikatorfenster den MA des zugehörigen Tages darstellen lassen, egal auf welcher ZE <= D1 ich mich befinde (Achtung, Code ziemlich unformatiert ;-)).

 

#property strict
#property indicator_separate_window

#property indicator_buffers 1
#property indicator_plots   1
//--- plot Uptrend
#property indicator_label1  "GD"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDarkGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- input parameters
input int      TimeFrame=1440;
input int      SMA_lang=200;
int limit, i, y;
double GD[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,GD);  
   
//---
   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();
  //---- 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;
 
if (TimeFrame != Period())
   {
      datetime TimeArray[];
         limit = MathMax(limit,TimeFrame/Period());
         
         //für jeden Balken im Array "TimeArray" die Eröffnungszeit des zugehörigen Balken der höheren Zeiteinheit "TimeFrame" (=Tag=1440) speichern
         ArrayCopySeries(TimeArray, MODE_TIME, NULL,TimeFrame);
                         
         for(i=0,y=0; i<limit; i++)
         {
            //wenn Eröffnungszeit des Balkens "jünger" als zugehörige Eröffnugnszeit der höheren Zeiteinheit, dann GD der Vorperiode (Shift y=1) nehmen
            if(Time[i]<TimeArray[y]) y++;

         GD[i] = iMA(NULL,TimeFrame,SMA_lang,0,0,0,y);
         }
   

               
  
   }

//wenn aktuelle Chartperiode = höhere Zeiteinheit, dann "normale" iMA-Berechnung
if (TimeFrame == Period())
   {
      for(i=0;i<limit;i++)
         {   
            GD[i] = iMA(NULL,PERIOD_D1,SMA_lang,0,0,0,i);
         }
   }         
      return(0);         
}

Dein Kommentar

Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.

Gast
Auf dieses Thema antworten...

Account

Navigation

Suche

Suche

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.