Skip to content

Instantly share code, notes, and snippets.

@igotit-anything
Created March 24, 2025 07:36
Show Gist options
  • Save igotit-anything/7e6a0f2ec314d5d55b09c07712cf09e4 to your computer and use it in GitHub Desktop.
Save igotit-anything/7e6a0f2ec314d5d55b09c07712cf09e4 to your computer and use it in GitHub Desktop.
#property indicator_chart_window // 지표표현 방식 : indicator_separate_window = 캔들챠트에 표현, indicator_chart_window = 별도창.
#property indicator_buffers 1 // 지표 버퍼수
//#property indicator_plots 1// 설정하지 않는 경우 상기 indicator_buffers 와 동일 수량 자동 할당됨.
#property indicator_color1 Yellow
// 지표 버퍼
double indi_buf_1[];
int OnInit()
{
IndicatorSetString(INDICATOR_SHORTNAME,"CyMA"); // 지표 이름 설정
// 지표 인덱스별 사용하는 메모리 지정.
SetIndexBuffer(0, indi_buf_1);// 지표 인덱스 0 에 해당하는 버퍼 지정.
// plot 인덱스별 스타일 지정 . 필수 . 이것 하지 않으면 그래프 안보임.
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE); // plot 인덱스 0 스타일 지정.
return INIT_SUCCEEDED;
}
void OnDeinit(const int reason)
{
}
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[])
{
//OnCalculate(,,) 첫 실행 시, 모든 캔들(현재 진행중인 미완성 캔들도 포함)데이터 활용.
if(prev_calculated == 0){
for (int i = 0; i < rates_total; i++)
{
indi_buf_1[i] = close[i]; // 종가 데이터를 지표 버퍼에 저장
}
}
else if(prev_calculated > 0){ // 첫 실행 이후 실행 지점. 1 신규 완성 캔들 2.현재진행중 캔들의 틱 변경시
if(rates_total > prev_calculated){ //신규 캔들완성 시점. 항상 1차이 나지만(예: rates_total=100, prev_calculated = 99) 혹시 더 큰 차이 발생 대비하여 루프로 처리함.(rates_total=100, prev_calculated = 90)
for (int i = prev_calculated; i < rates_total; i++)
{
indi_buf_1[i] = close[i];
}
}
else{ // 틱 가격 변동시 이것 실행됨.
indi_buf_1[ rates_total-1] = close[ rates_total-1];// 실시간 Tick 갱신됨.
}
}
//Comment(__FUNCTION__, " OnCalc rates_toal = ", rates_total, " buf size = " , ArraySize(indi_buf_1), " prev_calculated = ", prev_calculated);
return rates_total; // 필수. prev_calculated 는 직전 호출시 반환된 rates_total 임.
}
@igotit-anything
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment