//+------------------------------------------------------------------+ //| YY.mq4 | //| | //| | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Orange #property indicator_color2 MediumTurquoise #property indicator_width1 2 #property indicator_width2 2 //---- input parameters extern int Q = 122; // Количество баров в расчетах. Расчет справа налево, от первого или нулевого бара. Если Q = 0, то // в расчетах будут использоваться все бары. extern bool Show_6_Last_Ext = false; // Показать значения последние 6 краткосрочных экстремумов и их индексы в комментариях: // Show_6_Last_Ext_ZigZag >= true. extern int SpacePoints = 3; // Расстояние в пипсах между значком и экстремумом бара double Buffer0[]; double Buffer1[]; double Buffer2[]; double Buffer3[]; double A[192]; double I[192]; int H[192]; int L[192]; double p; datetime time; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers( 2 ); IndicatorDigits( Digits ); SetIndexBuffer( 0, Buffer0 ); SetIndexStyle( 0,DRAW_ARROW ); SetIndexArrow( 0,159 ); SetIndexBuffer( 1, Buffer1 ); SetIndexStyle( 1,DRAW_ARROW ); SetIndexArrow( 1,159 ); //---- name for DataWindow and indicator subwindow label IndicatorShortName( "YY" ); if ( Q > Bars || Q == 0 ) Q = Bars - 34; p = SpacePoints * Point; //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- Comment( " " ); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- if ( time == Time[0] ) return(0); // расчет один раз на открытии нового бара time = Time[0]; int e, f; for ( int i = 2; i < Q; i++ ) { Buffer0[i] = EMPTY_VALUE; // заполняем пустотой Buffer1[i] = EMPTY_VALUE; double high = High[i]; double low = Low[i]; int b1 = 0; int b2 = 0; int c1 = 0; int c2 = 0; //------------------------------------------------- right side for ( int z = 1; z < 33; z++ ) { if ( i - z > 0 ) { if ( high > High[i - z] && low > Low[i - z] && b1 == 0 ) { c1 = 1; break; } else { if ( high <= High[i - z] && c1 == 0 ) { b1 = 1; } } //---- if ( low < Low[i - z] && high < High[i - z] && b2 == 0 ) { c2 = 1; break; } else { if ( low >= Low[i - z] && c2 == 0 ) { b2 = 1; } } } } //------------------------------------------------- left side for ( z = 1; z < 33; z++ ) { if ( high > High[i + z] && low > Low[i + z] && c1 == 1 ) { Buffer0[i] = high + p; f++; H[f] = i; A[f] = high; break; } else { if ( high < High[i + z] && c1 == 1 ) { c1 = 2; } } //---- if ( low < Low[i + z] && high < High[i + z] && c2 == 1 ) { Buffer1[i] = low - p; e++; L[e] = i; I[e] = low; break; } else { if ( low > Low[i + z] && c2 == 1 ) { c2 = 2; } } } } //----------------------------------------------------------------------------------------------------- Comments if ( Show_6_Last_Ext == true ) Comment( " Maxs: ",A[1]," [ "+H[1]+" ] ", A[2]," [ "+H[2]+" ] ", A[3]," [ "+H[3]+" ] ",A[4]," [ "+H[4]+" ] ",A[5]," [ "+H[5]+" ] ",A[6], " [ "+H[6]+" ]", "\n\n Mins: ",I[1]," [ "+L[1]+" ] ", I[2]," [ "+L[2]+" ] ", I[3]," [ "+L[3]+" ] ",I[4]," [ "+L[4]+" ] ",I[5]," [ "+L[5]+" ] ",I[6], " [ "+L[6]+" ] " ); //---- return(0); } //+------------------------------------------------------------------+