Ja, das ist zum Verrückt-werden. Hier mal ein Update, ich habe an Anlehnung an den funktionierenden ATR mal bei der Initialisierung ein wenig was hinzugefügt. Dann habe ich noch eine zweite Linie für fallende Kerzen gemalt und eine iATR Bedingung hinzugefügt:
#property version "1.00"#property strict#property indicator_separate_window#property indicator_minimum 0#property indicator_maximum 20#property indicator_buffers 2#property indicator_plots 2//--- plot Anzahl steigend#property indicator_label1 "Anzahl steigend"#property indicator_type1 DRAW_LINE#property indicator_color1 clrGreen#property indicator_style1 STYLE_SOLID#property indicator_width1 1//--- plot Anzahl fallend#property indicator_label2 "Anzahl fallend"#property indicator_type2 DRAW_LINE#property indicator_color2 clrRed#property indicator_style2 STYLE_SOLID#property indicator_width2 1//sollen nur Kerzen > ATR beachtet werden?input bool Inp_Respect_ATR = true; //Nur große Kerzen > ATR-Durschschnitt beachteninput int Inp_ATR_Period = 14; //ATR-Periodinput double Inp_ATR_Factor = 1.0; //ATR-Faktor//--- indicator buffersdouble Anz_Up[];double Anz_Down[];//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int OnInit() {//--- indicator buffers mapping IndicatorBuffers(2); IndicatorDigits(0); //--- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(0,Anz_Up); SetIndexBuffer(1,Anz_Down); //--- name for DataWindow and indicator subwindow label string short_name="No. rising / falling candles > "+DoubleToString(Inp_ATR_Factor,1)+" * ATR"; IndicatorShortName(short_name); SetIndexLabel(0,"No. cons. rising"); SetIndexLabel(1,"No. cons. falling"); //--- check for input parameter if((Inp_ATR_Period < 3) || (Inp_ATR_Factor < 0)) { Print("Wrong input parameter: ATR-Period="+IntegerToString(Inp_ATR_Period)+", ATR-Faktor="+DoubleToString(Inp_ATR_Factor)); return(INIT_FAILED); }//--- wenn ATR verwendet wird, dann Linie ab ATR-Period malen if(Inp_Respect_ATR == true) { SetIndexDrawBegin(0,Inp_ATR_Period); SetIndexDrawBegin(1,Inp_ATR_Period); }//--- wenn ATR nicht verwendet wird, dann Linie ab Anfang malen if(Inp_Respect_ATR == false) { SetIndexDrawBegin(0,0); SetIndexDrawBegin(1,0); }//--- 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(Anz_Up,true); ArraySetAsSeries(Anz_Down,true); ArraySetAsSeries(open,true); ArraySetAsSeries(close,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(time,true); int bars = rates_total - 2; if(prev_calculated > 0) bars = rates_total - prev_calculated+1;//erste Kerze mit 0 initialisieren Anz_Up[rates_total-1]=0; Anz_Down[rates_total-1]=0; for(int i = bars; i >= 0; i--) {//wenn Schlusskurs größer als vorheriger Schlusskurs und Kerze > ATR-Faktor, dann Anzahl steigender Kerzen erhöhen und Anzahl fallender zurücksetzen if ((close[i] > close[i+1]) && (iATR(NULL,0,1,0) > (Inp_ATR_Factor * iATR(NULL,0,Inp_ATR_Period,0)))) { Anz_Up[i] = (Anz_Up[i+1]+1); Anz_Down[i] = 0; }//wenn Schlusskurs kleiner als vorheriger Schlusskurs und Kerze > ATR-Faktor, dann Anzahl fallender Kerzen erhöhen und Anzahl steigender zurücksetzen if ((close[i] < close[i+1]) && (iATR(NULL,0,1,0) > (Inp_ATR_Factor * iATR(NULL,0,Inp_ATR_Period,0)))) { Anz_Down[i] = (Anz_Down[i+1]+1); Anz_Up[i] = 0; }//wenn Schlusskurs = vorheriger Schlusskurs, dann Anzahl steigender und fallender Kerzen zurücksetzen if (close[i] == close[i+1]) { Anz_Down[i] = 0; Anz_Up[i] = 0; } }//--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Edited by whipsaw, 23 January 2016 - 07:55 PM.
Code Tag hinzugefügt