#property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1 //---- ColorLine 플롯 #property indicator_label1 "ColorLine" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrRed,clrGreen,clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 3 //--- 지표 버퍼 double ColorLineBuffer[]; double ColorBuffer[]; int MA_handle; //+------------------------------------------------------------------+ //| 사용자 지정 지표 초기화 함수 | //+------------------------------------------------------------------+ void OnInit() { //--- 지표 버퍼 맵핑 SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA); SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX); //--- MA 핸들 가져오기 MA_handle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE); //--- } //+------------------------------------------------------------------+ //| 색상 인덱스 가져오기 | //+------------------------------------------------------------------+ int getIndexOfColor(int i) { int j=i%300; if(j<100) return(0);// 첫 번째 인덱스 if(j<200) return(1);// 두 번째 인덱스 return(2); // 세 번째 인덱스 } //+------------------------------------------------------------------+ //| 사용자 지정 지표 반복 함수 | //+------------------------------------------------------------------+ 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[]) { //--- static int ticks=0,modified=0; int limit; //--- 첫 번째 계산 또는 막대 수가 변경되었습니다 if(prev_calculated==0) { //--- 지표 버퍼 ColorLineBuffer에 MA 값 복사 int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer); if(copied<=0) return(0);// 복사 실패 - 버리기 //--- 이제 모든 막대의 선 색상을 설정 for(int i=0;i<rates_total;i++) ColorBuffer[i]=getIndexOfColor(i); } else { //--- 지표 버퍼 ColorLineBuffer에 MA 값 복사 int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer); if(copied<=0) return(0); ticks++;// 틱 세기 if(ticks>=5)//이제 색채를 바꿀 때가 되었습니다 { ticks=0; // 카운터를 재설정 modified++; // 색상 변경 카운터 if(modified>=3)modified=0;// 카운터 재설정 ResetLastError(); switch(modified) { case 0:// 첫 번째 색배합 PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrBlue); PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrGreen); Print("색배합 "+modified); break; case 1:// 두 번째 색배합 PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrYellow); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrPink); PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLightSlateGray); Print("색배합 "+modified); break; default:// 세 번째 색배합 PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrLightGoldenrod); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrchid); PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLimeGreen); Print("색배합 "+modified); } } else { //--- 시작 포지션 설정 limit=prev_calculated-1; //--- 이제 모든 막대에 대해 선 색상을 설정 for(int i=limit;i<rates_total;i++) ColorBuffer[i]=getIndexOfColor(i); } } //--- 다음 호출을 위한 prev_calculated의 반환 값 return(rates_total); } //+------------------------------------------------------------------+ |