//+------------------------------------------------------------------+
//| DRAW_ARROW.mq5 |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property description "DRAW_ARROW를 시연하기 위한 지표"
#property description "유니코드 문자로 설정된 화살표 차트를 그림"
#property description "화살표의 색상, 크기, 이동 및 심볼 코드가 임의로 변경됩니다"
#property description "모든 N 틱 후"
#property description "코드 매개변수는 기준 값을 설정: code=159 (a circle)"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//--- 화살표를 플롯
#property indicator_label1 "화살표"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrGreen
#property indicator_width1 1
//--- 매개변수 입력
input int N=5; // 변경할 틱의 수
input ushort code=159; // DRAW_ARROW에 그릴 심볼 코드
//--- 플롯에 대한 지표 버퍼
double ArrowsBuffer[];
//--- 색상을 저장할 배열
color colors[]={clrRed,clrBlue,clrGreen};
//+------------------------------------------------------------------+
//| 사용자 지정 지표 초기화 함수 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 지표 버퍼 맵핑
SetIndexBuffer(0,ArrowsBuffer,INDICATOR_DATA);
//--- PLOT_ARROW에서 도면에 대한 심볼 코드 정의
PlotIndexSetInteger(0,PLOT_ARROW,code);
//--- 화살표의 수직 이동 설정(픽셀)
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,5);
//--- 빈 값 0으로 설정
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 사용자 지정 지표 반복 함수 |
//+------------------------------------------------------------------+
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;
//--- 화살표의 색상, 크기, 이동 및 코드를 변경하는 틱 계산
ticks++;
//--- 틱의 임계 수가 누적된 경우
if(ticks>=N)
{
//--- 선 속성 변경
ChangeLineAppearance();
//--- 틱 카운터를 0으로 재설정
ticks=0;
}
//--- 지표 값 계산을 위한 블록
int start=1;
if(prev_calculated>0) start=prev_calculated-1;
//--- 계산 루프
for(int i=1;i<rates_total;i++)
{
//--- 현재 종가가 이전 가격보다 높은 경우 화살표를 그립니다
if(close[i]>close[i-1])
ArrowsBuffer[i]=close[i];
//--- 그렇지 않으면 0값을 지정
else
ArrowsBuffer[i]=0;
}
//--- 다음 호출을 위한 prev_calculated의 반환 값
return(rates_total);
}
//+------------------------------------------------------------------+
//| 지표의 심볼 모양 변경 |
//+------------------------------------------------------------------+
void ChangeLineAppearance()
{
//--- 지표 속성에 대한 정보 형성을 위한 문자열
string comm="";
//--- 화살표 색상을 변경하는 블록
int number=MathRand(); // 임의 숫자 가져오기
//--- 제수는 colors[] 배열의 크기와 같습니다
int size=ArraySize(colors);
//--- 정수 나눗셈의 나머지의 새로운 색상을 선택할 인덱스를 가져오기
int color_index=number%size;
//--- 색상을 PLOT_LINE_COLOR 속성으로 설정
PlotIndexSetInteger(0,PLOT_LINE_COLOR,colors[color_index]);
//--- 선 색상 쓰기
comm=comm+"\r\n"+(string)colors[color_index];
//--- 화살표 크기를 변경할 수 있는 경우
number=MathRand();
//--- 정수 나눗셈의 나머지 너비 가져오기
int width=number%5; // The size is set from 0 to 4
//--- 색상을 PLOT_LINE_WIDTH 속성으로 설정
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,width);
//--- 배열 크기 쓰기
comm=comm+"\r\nWidth="+IntegerToString(width);
//--- 화살표 코드 변경 블록(PLOT_ARROW)
number=MathRand();
//--- 화살표의 새 코드(0 ~ 19)를 계산할 수 있는 정수 분할의 나머지를 가져오기
int code_add=number%20;
//--- code+code_add의 결과로 새 기호 코드를 설정
PlotIndexSetInteger(0,PLOT_ARROW,code+code_add);
//--- 심볼 코드 PLOT_ARROW 쓰기
comm="\r\n"+"PLOT_ARROW="+IntegerToString(code+code_add)+comm;
//--- 화살표의 수직 이동(픽셀)을 변경하기 위한 블록
number=MathRand();
//--- 이동을 정수 나눗셈의 나머지 값으로 가져오기
int shift=20-number%41;
//--- 새 이동을 -20 ~ 20으로 설정
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,shift);
//--- 이동 PLOT_ARROW_SHIFT 쓰기
comm="\r\n"+"PLOT_ARROW_SHIFT="+IntegerToString(shift)+comm;
//--- 설명을 사용하여 차트에 정보 표시
Comment(comm);
}
|