Einzelnen Beitrag anzeigen
  #6 (permalink)  
Alt 12.06.17
Traderole Traderole ist offline
Neues Mitglied
 
Registriert seit: Sep 2014
Beiträge: 18
Traderole befindet sich auf einem aufstrebenden Ast
Standard

Vielen Danke erstmal für die Idee mit dem object counter. das hat funktioniert. Nun bin ich auf ein anderes Problem gestossen. Und zwar rechnet der Indikator alle im Chart vorhandenen Bars. D.h. man bekommt hunderte linen. Wie könnte man das abändern, das er vielleicht nur die letzen 500 bars einbezieht um Highs and Lows zu bestimmen?

PHP-Code:
#property version   "1.00"
#property strict
#property indicator_chart_window

extern int periode_to_next_extremum 20;
int bars_to_check 40;
double ResLevel[], SupLevel[];
datetime ResTime[],SupTime[];
int objectcounter 1;
string NameRES "line";
string TextRES "RES";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   
ArrayResize(ResLevel,1);
   
ArrayResize(ResTime,2);
//--- indicator buffers mapping

//---
   
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 limit;
   
int counted_bars IndicatorCounted();
//---- check for possible errors 
   
if(counted_bars<0) return(-1);
   
limit=Bars counted_bars;

   
//---- main loop 
   
for(int i 1limiti++)
      {
      
//Resistance

      
if(iHighest(NULL,0,MODE_HIGH,bars_to_check,i) == +  periode_to_next_extremum)
         {
         
ResLevel[0] = High[periode_to_next_extremum];
         
ResTime[0] = Time[periode_to_next_extremum];
         
ResTime[1] = Time[periode_to_next_extremum] + 9999999;
         
objectcounter++;
         if(!
ObjectCreate(NameRES + (string)objectcounter,OBJ_TREND,0,ResTime[0],ResLevel[0],ResTime[1],ResLevel[0]))
            {
            Print(
"There must be sth wrong Trend: "GetLastError());      
            }
            else Print(
"Trend has been drawn: ",NameRES + (string)objectcounter);
         if(!
ObjectCreate(TextRES + (string)objectcounter,OBJ_TEXT,0,ResTime[0],ResLevel[0]))
            {
            Print(
"There must be sth wrong Text: "GetLastError());
            }
         if(!
ObjectSetText(TextRES + (string)objectcounter,TextRES + (string)objectcounter,10,"Times New Roman"Red))
            {
            Print(
"There must be sth wrong Change Text: "GetLastError());
            }            
         }
      
//Support

      
}
      
//--- return value of prev_calculated for next call
   
return(rates_total);
  }
//+------------------------------------------------------------------+

void OnDeinit(const int reason)
   {
   
int number_of_objects_deleted ObjectsDeleteAll(0,"",0,-1);
   Print(
"number_of_objects-deleted = "number_of_objects_deleted);
   }