지표: iGDR_프랙탈_레벨

 

iGDR_프랙탈_레벨:

iGDR_프랙탈 레벨 표시기는 프랙탈의 레벨을 표시하지만 모든 프랙탈이 아니라 특정 기간 동안의 평균값만 표시합니다.

iGDR_프랙탈_레벨

Author: Nikolay Kositsin

 
왜 200바 제한만 있나요?
 
좋은 지표... Good Job...
 
Automated-Trading:

iGDR_프랙탈_레벨:

저자: 니콜라이 코시친

표시기가 작동하지 않습니다.
 
안타깝게도 그렇습니다. 작동하지 않습니다. 4개의 컴파일 오류가 발생했고, 그것도 어리석은 오류였습니다. 하지만 지표는 흥미롭습니다.
 

컴파일하는 동안 오류가 발생했습니다.

해결 방법

 
오류로 인해 컴파일할 수 없습니다.
 
Benkele Goitsemodimo # 오류로 인해 컴파일할 수 없음

수정되었습니다.

 

//표시자 관심 표시. 수정된 코드

      //+------------------------------------------------------------------+
//|iGDR_프랙탈_레벨.mq5 |
//| 저작권 © 2008-2009, GreenDog, 러시아 |
//|krot@inbox.ru |
//+------------------------------------------------------------------+
//---- 지표 작성자
#property copyright "저작권 © 2008-2009, GreenDog."
//---- 저자 웹사이트 링크
#property link      "krot@inbox.ru"
//---- 표시기 버전 번호
#property version   "1.00"
//---- 메인 창의 그리기 표시기
#property indicator_chart_window 
#property indicator_buffers  1
#property indicator_plots    1
//+----------------------------------------------+
//|| 열거형 선언하기 |||
//+----------------------------------------------+
enum FRACTAL_MODE
  {
   MODE_HIGH_LOW=0, // 극한별
   MODE_LOW,        // 버텍스별
   MODE_HIGH        // 트로프별
  };
//+----------------------------------------------+
//|| 열거형 선언하기 |||
//+----------------------------------------------+
enum FRACTAL_TYPE
  {
   TYPE1=0, // strict
   TYPE2    // 비엄격
  };
//+----------------------------------------------+
//|| 표시기 입력 매개변수 |
//+----------------------------------------------+
input uint frNum_=2;                      // 프랙탈의 막대 수, 2=5 막대 프랙탈, 3=7 막대 프랙탈 등입니다.
input FRACTAL_TYPE frType= TYPE2;         // 프랙탈 정의 유형 0=엄격, 1=비엄격
input FRACTAL_MODE frMode =MODE_HIGH_LOW; // 모드 
input double dlt_=0.24;                   // 평균 막대 높이에서 오차
input uint sBars_=200;                    // 막대 개수(최대 200개)
//----
input color  BG1_Color = PaleGreen;  // 첫 번째 레벨의 배경색
input color  TL1Color  = Green;      // 첫 번째 레벨 라인의 색상
input color  BG2_Color = Yellow;     // 두 번째 레벨의 배경색
input color  TL2Color  = DarkOrange; // 두 번째 레벨의 선 색상
input color  BG3_Color = Pink;       // 세 번째 레벨의 배경색
input color  TL3Color  = Red;        // 세 번째 레벨 선의 색상
//+----------------------------------------------+
uint lastBars=0;
uint frNum,sBars;
datetime lastTime=0;
color BGColor[3],TLColor[3];
double aData[240][2],aRes[3][2];
//+------------------------------------------------------------------+
//| 사용자 지정 표시기 초기화 기능 |
//+------------------------------------------------------------------+ 
void OnInit()
  {
//---- 상수 초기화
   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;
//----
  }
//+------------------------------------------------------------------+
//| 텍스트 레이블 만들기|
//+------------------------------------------------------------------+
void CreateTextLabel(long     chart_id,   // 차트 식별자
                     string   name,       // 개체 이름
                     int      nwin,       // 창 색인
                     datetime time1,      // 가격 레벨 1의 시간
                     double   price1,     // 1 가격 수준
                     color    Color,      // 선 색상
                     string   text,       // 텍스트
                     string   font,       // font 
                     int      fontsize)   // 글꼴 크기
  {
//----
   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);
//----
  }
//+------------------------------------------------------------------+
//|| 텍스트 레이블 재설정하기|
//+------------------------------------------------------------------+
void SetTextLabel(long     chart_id,    // 차트 식별자
                  string   name,        // 개체 이름
                  int      nwin,        // 창 색인
                  datetime time1,       // 가격 레벨 1의 시간
                  double   price1,      // 1 가격 수준
                  color    Color,       // 선 색상
                  int      style,       // 라인 스타일
                  int      width,       // 선 두께
                  string   text,        // 텍스트
                  string   font,        // font
                  int      fontsize)    // 글꼴 크기
  {
//----
   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);
     }
//----
  }
//+------------------------------------------------------------------+
//| 채널 만들기|
//+------------------------------------------------------------------+
void CreateChannel(long     chart_id,      // 차트 식별자
                   string   name,          // 개체 이름
                   int      nwin,          // 창 색인
                   datetime time1,         // 가격 레벨 1의 시간
                   double   price1,        // 1 가격 수준
                   datetime time2,         // 가격 수준 2의 시간
                   double   price2,        // 2 가격 수준
                   datetime time3,         // 가격 레벨 3의 시간
                   double   price3,        // 3 가격 수준
                   color    Color,         // 선 색상
                   int      style,         // 라인 스타일
                   int      width,         // 선 두께
                   string   text)          // 텍스트
  {
//----
   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);
//----
  }
//+------------------------------------------------------------------+
//|| 채널 다시 설치하기|
//+------------------------------------------------------------------+
void SetChannel(long     chart_id,    // 차트 식별자
                string   name,        // 개체 이름
                int      nwin,        // 창 색인
                datetime time1,       // 가격 레벨 1의 시간
                double   price1,      // 1 가격 수준
                datetime time2,       // 가격 수준 2의 시간
                double   price2,      // 2 가격 수준
                datetime time3,       // 가격 레벨 3의 시간
                double   price3,      // 3 가격 수준
                color    Color,       // 선 색상
                int      style,       // 라인 스타일
                int      width,       // 선 두께
                string   text)        // 텍스트
  {
//----
   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);
     }
//----
  }
//+------------------------------------------------------------------+
//| 추세선 만들기|
//+------------------------------------------------------------------+
void CreateTline(long     chart_id,    // 차트 식별자
                 string   name,        // 개체 이름
                 int      nwin,        // 창 색인
                 datetime time1,       // 가격 레벨 1의 시간
                 double   price1,      // 1 가격 수준
                 datetime time2,       // 가격 수준 2의 시간
                 double   price2,      // 2 가격 수준
                 color    Color,       // 선 색상
                 int      style,       // 라인 스타일
                 int      width,       // 선 두께
                 string   text)        // 텍스트
  {
//----
   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);
//----
  }
//+------------------------------------------------------------------+
//|| 추세선 재설정하기|
//+------------------------------------------------------------------+
void SetTline(long     chart_id,    // 차트 식별자
              string   name,        // 개체 이름
              int      nwin,        // 창 색인
              datetime time1,       // 가격 레벨 1의 시간
              double   price1,      // 1 가격 수준
              datetime time2,       // 가격 수준 2의 시간
              double   price2,      // 2 가격 수준
              color    Color,       // 선 색상
              int      style,       // 라인 스타일
              int      width,       // 선 두께
              string   text)        // 텍스트
  {
//----
   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);
     }
//----
  }
//+------------------------------------------------------------------+
//| 최상위 프랙탈 찾기|
//+------------------------------------------------------------------+ 
bool upFrac(int cnt,const double &High[])
  {
//----
   for(int i=1; i<=int(frNum); i++)
     {
      if(frType==TYPE1)
        {
        //---- 엄격한 조건과 포스트 또는 프리 바가 이웃과 동일한 경우 - 프랙탈 없음
         if(High[cnt+i]>=High[cnt+i-1] || High[cnt-i]>=High[cnt-i+1]) return(false);
        }
      else
        { 
        //---- 조건이 엄격하지 않고 포스트 또는 프리 바가 중앙 위에 있는 경우 - 프랙탈 없음
         if(High[cnt+i]>High[cnt] || High[cnt-i]>High[cnt]) return(false);
        }
     }
//----
   return(true);
  }
//+------------------------------------------------------------------+
//| 하단 프랙탈 찾기|
//+------------------------------------------------------------------+ 
bool dwFrac(int cnt,const double &Low[])
  {
//----
   for(int i=1; i<=int(frNum); i++)
     {
      if(frType==TYPE1)
        { 
         //---- 엄격한 조건과 포스트 또는 프리 바가 이웃보다 낮은 경우 - 프랙탈 없음
         if(Low[cnt+i]<=Low[cnt+i-1] || Low[cnt-i]<=Low[cnt-i+1]) return(false);
        }
      else
        { 
         //---- 조건이 엄격하지 않고 포스트 또는 프리 바가 중앙 아래에 있는 경우 - 프랙탈 없음
         if(Low[cnt+i]<Low[cnt] || Low[cnt-i]<Low[cnt]) return(false);
        }
     }
//----
   return(true);
  }
//+------------------------------------------------------------------+
//| 사용자 지정 표시기 초기화 기능 ||
//+------------------------------------------------------------------+ 
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");
     }
//----
  }
//+------------------------------------------------------------------+
//| 사용자 지정 표시기 반복 함수 |
//+------------------------------------------------------------------+
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[])
  {
//---- 계산을 위한 충분한 막대 수 확인
   if(rates_total<int(sBars)) return(0);

//---- 시계열에서와 같이 배열의 요소 색인화 
   ArraySetAsSeries(time,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);

   lastBars=rates_total;

//---- 프랙탈을 검색하여 배열에 넣되 허용된 프랙탈 개수를 넘지 않도록 합니다.
   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))
        { 
         //---- 버텍스 추가 [트로프 모드 제외]
         //---- 엄격하지 않은 조건에서 중복된 인접 버텍스 건너뛰기
         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))
        { 
         //---- 우울증 추가 [버텍스 모드 제외]
         //---- 엄격하지 않은 조건에서 중복된 이웃 트로프 건너뛰기
         if(!frType!=TYPE1 && lastExt>0 && lastExt==low[i])
           {
            aData[sh][0]=low[i];
            lastExt=low[i];
            sh++;
           }
        }
      if(sh>=240) break;
     }

//---- 평균 캔들 스프레드와 해당 허용 오차를 결정합니다.
   double dlt,sHL=0;
   for(int i=1; i<=int(sBars); i++) sHL+=(high[i]-low[i]);
   sHL/=sBars;
   dlt=sHL*dlt_;

//---- 각 레벨에 대한 등급을 정의합니다.
   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;
           }

//---- 가장 강력한 세 가지 레벨 식별
   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])
        { 
         //---- 등급이 1등급보다 큰 경우 1등급이 현재 등급이 됩니다.
         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];
        }

      //---- 등급이 2위보다 높지만 1위에 속하지 않는 경우 2위를 대체합니다.
      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];
        }
      //---- 등급이 3위보다 높지만 1, 2위에 속하지 않는 경우 3위로 대체합니다.
      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);
     }

//---- 출력 댓글
   string rem1="",rem2="";
   if(frType==TYPE2) rem1=rem1+"클래식 ";
   else rem1=rem1+"엄격하게 ";

   rem1=rem1+string(frNum*2+1)+"-바 프랙탈.";
  // if(frMode==MODE_LOW) rem1=rem1+", troughs";
 if(frMode==FRACTAL_MODE::MODE_LOW) rem1=rem1+", 바닥.";
   //else if(frMode==MODE_HIGH) rem1=rem1+", vertex";
else if(frMode==FRACTAL_MODE::MODE_HIGH) rem1=rem1+", 어퍼.";
   rem1=rem1+"\n 찾았습니다."+string(sh)+" 프랙탈 \n 가장 강한 레벨 ";

   StringConcatenate(rem2,aRes[0][0],"[",aRes[0][1],"], ",
                     aRes[1][0],"[",aRes[1][1],"], ",aRes[2][0],"[",aRes[2][1],
                     "], 오류 ±",NormalizeDouble(dlt/_Point,1)," 단락");
   Comment(rem1+rem2);

//----
   ChartRedraw(0);
//---- 
   return(rates_total);
  }
//+------------------------------------------------------------------+