¿Por qué sólo hay un límite de 200 bares?
Buen Indicador... Buen Trabajo...
Indicador no funciona
Desgraciadamente, sí. No funciona. 4 errores de compilación, y estúpidos. Pero el indicador es interesante.
no se puede compilar debido a errores
//Indicador interesante. Código corregido
//+------------------------------------------------------------------+ //|iGDR_Fractal_Levels.mq5 //| Copyright © 2008-2009, GreenDog, Rusia | //|krot@inbox.ru | //+------------------------------------------------------------------+ //---- autoría del indicador #property copyright "Copyright © 2008-2009, GreenDog". //---- enlace a la página web del autor #property link "krot@inbox.ru" //---- número de versión del indicador #property version "1.00" //---- dibujar indicador en la ventana principal #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //+----------------------------------------------+ //|| Declarar una enumeración || //+----------------------------------------------+ enum FRACTAL_MODE { MODE_HIGH_LOW=0, // por extrema MODE_LOW, // por vértice MODE_HIGH // por comederos }; //+----------------------------------------------+ //|| Declarar una enumeración || //+----------------------------------------------+ enum FRACTAL_TYPE { TYPE1=0, // estricto TYPE2 // no estricto }; //+----------------------------------------------+ //|| Parámetros de entrada del indicador //+----------------------------------------------+ input uint frNum_=2; // Número de barras del fractal, 2=fractal de 5 barras, 3=fractal de 7 barras, etc. input FRACTAL_TYPE frType= TYPE2; // Tipo de definición del fractal 0=estricto, 1=no estricto input FRACTAL_MODE frMode =MODE_HIGH_LOW; // Modo input double dlt_=0.24; // Error de la altura media de la barra input uint sBars_=200; // Número de barras (máx. 200) //---- input color BG1_Color = PaleGreen; // Color de fondo de los primeros niveles input color TL1Color = Green; // Color de las líneas de primer nivel input color BG2_Color = Yellow; // Color de fondo de los segundos niveles input color TL2Color = DarkOrange; // Color de las líneas de los segundos niveles input color BG3_Color = Pink; // Color de fondo de los terceros niveles input color TL3Color = Red; // Color de las líneas de tercer nivel //+----------------------------------------------+ uint lastBars=0; uint frNum,sBars; datetime lastTime=0; color BGColor[3],TLColor[3]; double aData[240][2],aRes[3][2]; //+------------------------------------------------------------------+ //| Función de inicialización del indicador personalizada | //+------------------------------------------------------------------+ void OnInit() { //---- inicialización de constantes frNum=frNum_; if(frNum_<2) frNum=2; sBars=sBars_; if(sBars_>200) sBars=200; if(sBars_<10) sBars=10; BGColor[0]=BG1_Color; BGColor[1]=BG2_Color; BGColor[2]=BG3_Color; TLColor[0]=TL1Color; TLColor[1]=TL2Color; TLColor[2]=TL3Color; //---- } //+------------------------------------------------------------------+ //| Creación de una etiqueta de texto| //+------------------------------------------------------------------+ void CreateTextLabel(long chart_id, // identificador del gráfico string name, // nombre del objeto int nwin, // índice de la ventana datetime time1, // tiempo de 1 nivel de precios double price1, // 1 nivel de precios color Color, // color de la línea string text, // texto string font, // fuente int fontsize) // tamaño de letra { //---- ObjectCreate(chart_id,name,OBJ_TEXT,nwin,time1,price1); ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color); ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true); ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true); ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true); ObjectSetString(chart_id,name,OBJPROP_FONT,font); ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,fontsize); //---- } //+------------------------------------------------------------------+ //|| Restablecer la etiqueta de texto| //+------------------------------------------------------------------+ void SetTextLabel(long chart_id, // identificador del gráfico string name, // nombre del objeto int nwin, // índice de la ventana datetime time1, // tiempo de 1 nivel de precios double price1, // 1 nivel de precios color Color, // color de la línea int style, // estilo de línea int width, // grosor de la línea string text, // texto string font, // fuente int fontsize) // tamaño de letra { //---- if(ObjectFind(chart_id,name)==-1) { CreateTextLabel(chart_id,name,nwin,time1,price1,Color,text,font,fontsize); } else { ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectMove(chart_id,name,0,time1,price1); ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color); } //---- } //+------------------------------------------------------------------+ //| Creación de un canal| //+------------------------------------------------------------------+ void CreateChannel(long chart_id, // identificador del gráfico string name, // nombre del objeto int nwin, // índice de la ventana datetime time1, // tiempo de 1 nivel de precios double price1, // 1 nivel de precios datetime time2, // momento del nivel de precios 2 double price2, // 2 nivel de precios datetime time3, // momento del nivel de precios 3 double price3, // 3 nivel de precios color Color, // color de la línea int style, // estilo de línea int width, // grosor de la línea string text) // texto { //---- ObjectCreate(chart_id,name,OBJ_CHANNEL,nwin,time1,price1,time2,price2); ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color); ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style); ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width); ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectSetInteger(chart_id,name,OBJPROP_FILL,true); ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,true); ObjectSetInteger(chart_id,name,OBJPROP_RAY,true); ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true); ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true); ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true); //---- } //+------------------------------------------------------------------+ //|| Reinstalación del canal| //+------------------------------------------------------------------+ void SetChannel(long chart_id, // identificador del gráfico string name, // nombre del objeto int nwin, // índice de la ventana datetime time1, // tiempo de 1 nivel de precios double price1, // 1 nivel de precios datetime time2, // momento del nivel de precios 2 double price2, // 2 nivel de precios datetime time3, // momento del nivel de precios 3 double price3, // 3 nivel de precios color Color, // color de la línea int style, // estilo de línea int width, // grosor de la línea string text) // texto { //---- if(ObjectFind(chart_id,name)==-1) { CreateChannel(chart_id,name,nwin,time1,price1,time2,price2,time3,price3,Color,style,width,text); } else { ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectMove(chart_id,name,0,time1,price1); ObjectMove(chart_id,name,1,time2,price2); ObjectMove(chart_id,name,2,time3,price3); ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color); } //---- } //+------------------------------------------------------------------+ //| Creación de una línea de tendencia| //+------------------------------------------------------------------+ void CreateTline(long chart_id, // identificador del gráfico string name, // nombre del objeto int nwin, // índice de la ventana datetime time1, // tiempo de 1 nivel de precios double price1, // 1 nivel de precios datetime time2, // momento del nivel de precios 2 double price2, // 2 nivel de precios color Color, // color de la línea int style, // estilo de línea int width, // grosor de la línea string text) // texto { //---- ObjectCreate(chart_id,name,OBJ_TREND,nwin,time1,price1,time2,price2); ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color); ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style); ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width); ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectSetInteger(chart_id,name,OBJPROP_BACK,false); ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,true); ObjectSetInteger(chart_id,name,OBJPROP_RAY,true); ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true); ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true); ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true); //---- } //+------------------------------------------------------------------+ //|| Restablecer la línea de tendencia| //+------------------------------------------------------------------+ void SetTline(long chart_id, // identificador del gráfico string name, // nombre del objeto int nwin, // índice de la ventana datetime time1, // tiempo de 1 nivel de precios double price1, // 1 nivel de precios datetime time2, // momento del nivel de precios 2 double price2, // 2 nivel de precios color Color, // color de la línea int style, // estilo de línea int width, // grosor de la línea string text) // texto { //---- if(ObjectFind(chart_id,name)==-1) { CreateTline(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,text); } else { ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectMove(chart_id,name,0,time1,price1); ObjectMove(chart_id,name,1,time2,price2); ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color); } //---- } //+------------------------------------------------------------------+ //| Encontrar el fractal superior| //+------------------------------------------------------------------+ bool upFrac(int cnt,const double &High[]) { //---- for(int i=1; i<=int(frNum); i++) { if(frType==TYPE1) { //---- si la condición estricta y las barras post o pre son superiores a la vecina - sin fractal if(High[cnt+i]>=High[cnt+i-1] || High[cnt-i]>=High[cnt-i+1]) return(false); } else { //---- si la condición no es estricta y las barras posteriores o anteriores están por encima del centro - no hay fractal if(High[cnt+i]>High[cnt] || High[cnt-i]>High[cnt]) return(false); } } //---- return(true); } //+------------------------------------------------------------------+ //| Encontrar el fractal inferior| //+------------------------------------------------------------------+ bool dwFrac(int cnt,const double &Low[]) { //---- for(int i=1; i<=int(frNum); i++) { if(frType==TYPE1) { //---- si la condición estricta y las barras post o pre son inferiores a la vecina - no fractal if(Low[cnt+i]<=Low[cnt+i-1] || Low[cnt-i]<=Low[cnt-i+1]) return(false); } else { //---- si la condición no es estricta y las barras posteriores o anteriores están por debajo del centro - no hay fractal if(Low[cnt+i]<Low[cnt] || Low[cnt-i]<Low[cnt]) return(false); } } //---- return(true); } //+------------------------------------------------------------------+ //| Función personalizada de desinicialización del indicador || //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //---- Comment(""); for(int i=0; i<3; i++) { string name="IPGDR_Lv"+string(i); ObjectDelete(0,name); ObjectDelete(0,name+"Up"); ObjectDelete(0,name+"Dw"); ObjectDelete(0,name+"Tx"); } //---- } //+------------------------------------------------------------------+ //| Función de iteración del indicador personalizada | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // cantidad de historia en barras en el tick actual const int prev_calculated,// cantidad de historia en barras en el tick anterior const datetime &time[], const double &open[], const double& high[], // matriz de precios máximos para el cálculo del indicador const double& low[], // matriz de precios mínimos para el cálculo del indicador const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---- comprobar si el número de barras es suficiente para el cálculo if(rates_total<int(sBars)) return(0); //---- indexación de elementos en matrices, como en las series temporales ArraySetAsSeries(time,true); ArraySetAsSeries(close,true); ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); lastBars=rates_total; //---- buscar fractales, ponerlos en la matriz, pero no más del número permitido de fractales. int sh=0; ArrayInitialize(aData,0); double lastExt=0; int total=int(sBars-2*frNum); int start=int(frNum+1); for(int i=start; i<total; i++) { // if(frMode!=MODE_LOW && upFrac(i,high)) if(frMode!=FRACTAL_MODE::MODE_LOW && upFrac(i,high)) { //---- añadir vértices [excepto modo artesa] //---- omitir vértices vecinos duplicados en condiciones no estrictas if(!(frType!=TYPE1 && lastExt>0 && lastExt==high[i])) { aData[sh][0]=high[i]; lastExt=high[i]; sh++; } } if(sh>=240) break; // if(frMode!=MODE_HIGH && dwFrac(i,low)) if(frMode!=FRACTAL_MODE::MODE_HIGH && dwFrac(i,low)) { //---- añadir depresiones [excepto modo vértice] //---- omitir los comederos vecinos duplicados en condiciones no estrictas if(!frType!=TYPE1 && lastExt>0 && lastExt==low[i]) { aData[sh][0]=low[i]; lastExt=low[i]; sh++; } } if(sh>=240) break; } //---- determinar la dispersión media de las velas y la tolerancia correspondiente double dlt,sHL=0; for(int i=1; i<=int(sBars); i++) sHL+=(high[i]-low[i]); sHL/=sBars; dlt=sHL*dlt_; //---- definir clasificaciones para cada nivel for(int i=0; i<sh; i++) for(int j=i+1; j<sh; j++) if(aData[j][0]>aData[i][0]-dlt && aData[j][0]<aData[i][0]+dlt) { aData[i][1]+=1; aData[j][1]+=1; } //---- identificar los tres niveles más fuertes double cur[2],tmp[2]; aRes[0][0]=aData[0][0]; aRes[0][1]=aData[0][1]; for(int i=1; i<sh; i++) { cur[0]=aData[i][0]; cur[1]=aData[i][1]; if(cur[1]>aRes[0][1]) { //---- si la clasificación es mayor que el rango 1, entonces el rango 1 se convierte en el actual tmp[0]=aRes[0][0]; tmp[1]=aRes[0][1]; aRes[0][0]=cur[0]; aRes[0][1]=cur[1]; cur[0]=tmp[0]; cur[1]=tmp[1]; } //---- si la calificación es superior al 2º puesto y, sin embargo, no pertenece al 1º puesto, sustituye al 2º puesto. if(cur[1]>aRes[1][1] && (cur[0]<aRes[0][0]-dlt || cur[0]>aRes[0][0]+dlt)) { tmp[0]=aRes[1][0]; tmp[1]=aRes[1][1]; aRes[1][0]=cur[0]; aRes[1][1]=cur[1]; cur[0]=tmp[0]; cur[1]=tmp[1]; } //---- si la calificación es superior al 3er puesto y sin embargo no pertenece al 1er y 2º puesto, sustituir el 3er puesto. if(cur[1]>aRes[2][1] && (cur[0]<aRes[0][0]-dlt || cur[0]>aRes[0][0]+dlt) && (cur[0]<aRes[1][0]-dlt || cur[0]>aRes[1][0]+dlt)) { aRes[2][0]=cur[0]; aRes[2][1]=cur[1]; } } for(int i=0; i<3; i++) { double dwL=aRes[i][0]-dlt,upL=aRes[i][0]+dlt; string name="IPGDR_Lv"+string(i); SetChannel(0,name,0,time[24],upL,time[1],upL,time[24],dwL,BGColor[i],STYLE_SOLID,1,name); SetTline(0,name+"Up",0,time[24],upL,time[1],upL,TLColor[i],STYLE_SOLID,1,name+"Up"); SetTline(0,name+"Dw",0,time[24],dwL,time[1],dwL,TLColor[i],STYLE_SOLID,1,name+"Dw"); SetTextLabel(0,name+"Tx",0,time[32],upL+2*_Point,TLColor[i],STYLE_SOLID,1,DoubleToString(aRes[i][0],_Digits),"tahoma",14); } //---- comentarios de salida string rem1="",rem2=""; if(frType==TYPE2) rem1=rem1+"Clásico"; else rem1=rem1+"Estrictamente"; rem1=rem1+string(frNum*2+1)+"fractales de barra".; // if(frMode==MODE_LOW) rem1=rem1+", troughs"; if(frMode==FRACTAL_MODE::MODE_LOW) rem1=rem1+", fondos."; //else if(frMode==MODE_HIGH) rem1=rem1+", vertex"; else if(frMode==FRACTAL_MODE::MODE_HIGH) rem1=rem1+... "uppers".; rem1=rem1+"\N - Encontrado".+string(sh)+" fractal(es) \n Niveles más fuertes "; StringConcatenate(rem2,aRes[0][0],"[",aRes[0][1],"], ", aRes[1][0],"[",aRes[1][1],"], ",aRes[2][0],"[",aRes[2][1], "], error ±",NormalizeDouble(dlt/_Point,1)," párrafo(s)"); Comment(rem1+rem2); //---- ChartRedraw(0); //---- return(rates_total); } //+------------------------------------------------------------------+
Está perdiendo oportunidades comerciales:
- Aplicaciones de trading gratuitas
- 8 000+ señales para copiar
- Noticias económicas para analizar los mercados financieros
Registro
Entrada
Usted acepta la política del sitio web y las condiciones de uso
Si no tiene cuenta de usuario, regístrese
iGDR_Fractal_Levels:
iGDR_Fractal_Levels muestra los valores medios de fractales durante un cierto periodo de tiempo.
Autor: Nikolay Kositsin