Multitimeframe Indikator

 

Hallo, ich versuche einen Indikator zu entwickeln, der auf Basis von mehreren Timeframes rechnet. Wenn ich auf dem M30 Chart bin, gibt er aber nur 2 von 4 Buffern aus. Weis jemand, woran das liegen könnte?

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                        Copyright 2019, Arthur S. |
//|                    https://www.mql5.com/en/users/michael12345678 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Arthur S."
#property link      "https://www.mql5.com/en/users/michael12345678"
#property version   "1.00"

#property indicator_chart_window
#property indicator_buffers 12
#property indicator_plots 6

#property indicator_label1 "Up_Period30"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrBlue

#property indicator_label2 "Down_Period30"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed

#property indicator_label3 "Up_Period60"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrBlueViolet

#property indicator_label4 "Down_Period60"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrDarkCyan

#property indicator_label5 "Up_Period15"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrDarkGreen

#property indicator_label6 "Down_Period15"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrDeepPink

int MovingAverage12_Period30;
int MovingAverage22_Period30;
int MovingAverage12_Period60;
int MovingAverage22_Period60;
int MovingAverage12_Period15;
int MovingAverage22_Period15;

double MovingAverageBuffer12_Period30[];
double MovingAverageBuffer22_Period30[];
double MovingAverageBuffer12_Period60[];
double MovingAverageBuffer22_Period60[];
double MovingAverageBuffer12_Period15[];
double MovingAverageBuffer22_Period15[];

double UpBuffer_Period30[];
double DownBuffer_Period30[];
double UpBuffer_Period60[];
double DownBuffer_Period60[];
double UpBuffer_Period15[];
double DownBuffer_Period15[];

bool Up_Period30=false;
bool Down_Period30=false;
bool Up_Period60=false;
bool Down_Period60=false;
bool Up_Period15=false;
bool Down_Period15=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0,UpBuffer_Period30,INDICATOR_DATA);
   SetIndexBuffer(1,DownBuffer_Period30,INDICATOR_DATA);
   SetIndexBuffer(2,UpBuffer_Period60,INDICATOR_DATA);
   SetIndexBuffer(3,DownBuffer_Period60,INDICATOR_DATA);
   SetIndexBuffer(4,UpBuffer_Period15,INDICATOR_DATA);
   SetIndexBuffer(5,DownBuffer_Period15,INDICATOR_DATA);
   SetIndexBuffer(6,MovingAverageBuffer12_Period30,INDICATOR_CALCULATIONS);
   SetIndexBuffer(7,MovingAverageBuffer22_Period30,INDICATOR_CALCULATIONS);
   SetIndexBuffer(8,MovingAverageBuffer12_Period60,INDICATOR_CALCULATIONS);
   SetIndexBuffer(9,MovingAverageBuffer22_Period60,INDICATOR_CALCULATIONS);
   SetIndexBuffer(10,MovingAverageBuffer12_Period15,INDICATOR_CALCULATIONS);
   SetIndexBuffer(11,MovingAverageBuffer22_Period15,INDICATOR_CALCULATIONS);
   
   MovingAverage12_Period30=iMA(_Symbol,PERIOD_M30,12,0,MODE_EMA,PRICE_OPEN);
   if(MovingAverage12_Period30==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   MovingAverage22_Period30=iMA(_Symbol,PERIOD_M30,22,0,MODE_EMA,PRICE_OPEN);
   if(MovingAverage22_Period30==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   MovingAverage12_Period60=iMA(_Symbol,PERIOD_H1,12,0,MODE_EMA,PRICE_OPEN);
   if(MovingAverage12_Period60==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   MovingAverage22_Period60=iMA(_Symbol,PERIOD_H1,22,0,MODE_EMA,PRICE_OPEN);
   if(MovingAverage22_Period60==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   MovingAverage12_Period15=iMA(_Symbol,PERIOD_M15,12,0,MODE_EMA,PRICE_OPEN);
   if(MovingAverage12_Period15==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   MovingAverage22_Period15=iMA(_Symbol,PERIOD_M15,22,0,MODE_EMA,PRICE_OPEN);
   if(MovingAverage22_Period15==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   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[])
{
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(UpBuffer_Period30,true);
   ArraySetAsSeries(DownBuffer_Period30,true);
   ArraySetAsSeries(MovingAverageBuffer12_Period30,true);
   ArraySetAsSeries(MovingAverageBuffer22_Period30,true);
   ArraySetAsSeries(UpBuffer_Period60,true);
   ArraySetAsSeries(DownBuffer_Period60,true);
   ArraySetAsSeries(MovingAverageBuffer12_Period60,true);
   ArraySetAsSeries(MovingAverageBuffer22_Period60,true);
   ArraySetAsSeries(UpBuffer_Period15,true);
   ArraySetAsSeries(DownBuffer_Period15,true);
   ArraySetAsSeries(MovingAverageBuffer12_Period15,true);
   ArraySetAsSeries(MovingAverageBuffer22_Period15,true);
   
   int limit=MathMin(rates_total-1,rates_total-prev_calculated);
   
   int copied12_Period30=CopyBuffer(MovingAverage12_Period30,0,0,limit,MovingAverageBuffer12_Period30);
   int copied22_Period30=CopyBuffer(MovingAverage22_Period30,0,0,limit,MovingAverageBuffer22_Period30);
   int copied12_Period60=CopyBuffer(MovingAverage12_Period60,0,0,limit,MovingAverageBuffer12_Period60);
   int copied22_Period60=CopyBuffer(MovingAverage22_Period60,0,0,limit,MovingAverageBuffer22_Period60);
   int copied12_Period15=CopyBuffer(MovingAverage12_Period15,0,0,limit,MovingAverageBuffer12_Period15);
   int copied22_Period15=CopyBuffer(MovingAverage22_Period15,0,0,limit,MovingAverageBuffer22_Period15);
   
   for(int i=0;i<limit;i++)
   {
      UpBuffer_Period30[i]=EMPTY_VALUE;
      DownBuffer_Period30[i]=EMPTY_VALUE;
      UpBuffer_Period60[i]=EMPTY_VALUE;
      DownBuffer_Period60[i]=EMPTY_VALUE;
      UpBuffer_Period15[i]=EMPTY_VALUE;
      DownBuffer_Period15[i]=EMPTY_VALUE;
      
      if(_Period==PERIOD_M30)
      {
         if(MovingAverageBuffer12_Period30[i]>MovingAverageBuffer22_Period30[i] && MovingAverageBuffer12_Period30[i+1]<MovingAverageBuffer22_Period30[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M30,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            UpBuffer_Period30[Bar]=low[Bar]-0.00030;
            
            Up_Period30=true;
         }
         else if(MovingAverageBuffer12_Period30[i]<MovingAverageBuffer22_Period30[i] && MovingAverageBuffer12_Period30[i+1]>MovingAverageBuffer22_Period30[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M30,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            DownBuffer_Period30[Bar]=high[Bar]+0.00030;
            
            Down_Period30=true;
         }
         
         if(MovingAverageBuffer12_Period15[i]>MovingAverageBuffer22_Period15[i] && MovingAverageBuffer12_Period15[i+1]<MovingAverageBuffer22_Period15[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M15,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            UpBuffer_Period15[Bar]=low[Bar]-0.00090;
            
            Up_Period15=true;
         }
         else if(MovingAverageBuffer12_Period15[i]<MovingAverageBuffer22_Period15[i] && MovingAverageBuffer12_Period15[i+1]>MovingAverageBuffer22_Period15[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M15,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            DownBuffer_Period15[Bar]=high[Bar]+0.00090;
            
            Down_Period15=true;
         }
      }
      else if(_Period==PERIOD_H1)
      {
         if(MovingAverageBuffer12_Period30[i]>MovingAverageBuffer22_Period30[i] && MovingAverageBuffer12_Period30[i+1]<MovingAverageBuffer22_Period30[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M30,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            UpBuffer_Period30[Bar]=low[Bar]-0.00030;
            
            Up_Period30=true;
         }
         else if(MovingAverageBuffer12_Period30[i]<MovingAverageBuffer22_Period30[i] && MovingAverageBuffer12_Period30[i+1]>MovingAverageBuffer22_Period30[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M30,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            DownBuffer_Period30[Bar]=high[Bar]+0.00030;
            
            Down_Period30=true;
         }
         
         if(MovingAverageBuffer12_Period60[i]>MovingAverageBuffer22_Period60[i] && MovingAverageBuffer12_Period60[i+1]<MovingAverageBuffer22_Period60[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_H1,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            UpBuffer_Period60[Bar]=low[Bar]-0.00060;
            
            Up_Period60=true;
         }
         else if(MovingAverageBuffer12_Period60[i]<MovingAverageBuffer22_Period60[i] && MovingAverageBuffer12_Period60[i+1]>MovingAverageBuffer22_Period60[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_H1,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            DownBuffer_Period60[Bar]=high[Bar]+0.00060;
            
            Down_Period60=true;
         }
         
         if(MovingAverageBuffer12_Period15[i]>MovingAverageBuffer22_Period15[i] && MovingAverageBuffer12_Period15[i+1]<MovingAverageBuffer22_Period15[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M15,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            UpBuffer_Period15[Bar]=low[Bar]-0.00090;
            
            Up_Period15=true;
         }
         else if(MovingAverageBuffer12_Period15[i]<MovingAverageBuffer22_Period15[i] && MovingAverageBuffer12_Period15[i+1]>MovingAverageBuffer22_Period15[i+1])
         {
            datetime CandleTime=iTime(_Symbol,PERIOD_M15,i);
            
            int Bar=iBarShift(_Symbol,_Period,CandleTime,true);
            
            DownBuffer_Period15[Bar]=high[Bar]+0.00090;
            
            Down_Period15=true;
         }
      }
   }
   
   Comment("Up_Period15: ",Up_Period15,
           "\nDown_Period15: ",Down_Period15,
           "\nUp_Period30: ",Up_Period30,
           "\nDown_Period30: ",Down_Period30,
           "\nUp_Period60: ",Up_Period60,
           "\nDown_Period60: ",Down_Period60);
   
   return(rates_total);
}
//+------------------------------------------------------------------+
 

Die zweiten 6 Buffer sind deklariert, dass sie nur berechnet, aber nirgends angezeigt werden.

Mach das bei denen so, wie bei den ersten 6 nur gibt an beim Zeichnen:

#property indicator_type11 DRAW_NONE
...
SetIndexBuffer(10,UpBuffer_Period30,INDICATOR_DATA);

Ich glaube so geht's.

 
Das verstehe ich nicht so ganz, UpBuffer_Period30 ist doch INDICATOR_DATA
 

Stell alle(!) 12 so ein, dass sie gezeichnet werden würden und dann sag denen Indis, die Du nicht auf dem Chart sehen willst: DRAW_NONE.

Sonst sind das, wie bei Dir nur intern verwendbare Puffer, die aber weder im Chart noch im Datenfenster angezeigt werden - ist ein Geschwindikeitsvorteil!

Ausprobieren..
 
Up_Period15 und Down_Period15 werden nicht ausgegeben.
 
UpBuffer_Period60[Bar] usw wird kein Wert zugewiesen bei PERIOD_M30

Gruß Uwe
 
Uwe Goetzke:

Das brauche ich nicht ;-)

 
Arthur Singer:
Up_Period15 und Down_Period15 werden nicht ausgegeben.

??

Was heißt jetzt nicht ausgegeben?

Die anderen jetzt schon?

Irgendetwas im log?

 
 
Und was soll ich da jetzt sehen bzw. nicht sehen?
 
Das nur Period30=true ist und Period15=false, also Period15 wird nicht angezeigt.