#property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 2 //--- 입력 매개변수 input int RSIperiod=14; // RSI 계산 기간 input int Smooth=8; // 평활 기간 RSI input ENUM_MA_METHOD meth=MODE_SMMA; // 평활법 //---- RSI 플롯 #property indicator_label1 "RSI" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //---- RSI_Smoothed 플롯 #property indicator_label2 "RSI_Smoothed" #property indicator_type2 DRAW_LINE #property indicator_color2 clrNavy #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- 지표 버퍼 double RSIBuffer[]; // 여기에 RSI 값을 저장합니다 double RSI_SmoothedBuffer[]; // 다음은 RSI의 평활값입니다 int RSIhandle; // RSI 지표에 핸들 연결 //+------------------------------------------------------------------+ //| 사용자 지정 지표 초기화 함수 | //+------------------------------------------------------------------+ void OnInit() { //--- 지표 버퍼 매핑 SetIndexBuffer(0,RSIBuffer,INDICATOR_DATA); SetIndexBuffer(1,RSI_SmoothedBuffer,INDICATOR_DATA); IndicatorSetString(INDICATOR_SHORTNAME,"iRSI"); IndicatorSetInteger(INDICATOR_DIGITS,2); //--- RSIhandle=iRSI(NULL,0,RSIperiod,PRICE_CLOSE); //--- } //+------------------------------------------------------------------+ //| 사용자 지정 지표 반복 함수 | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[] ) { //--- 마지막 오류 값 재설정 ResetLastError(); //--- RSIBuffer []에서 RSI 지표 데이터 가져오기 int copied=CopyBuffer(RSIhandle,0,0,rates_total,RSIBuffer); if(copied<=0) { Print("지표 RSI 값을 복사할 수 없습니다. Error = ", GetLastError(),", copied =",copied); return(0); } //--- RSI 값을 사용하여 평균값 지표 생성 int RSI_MA_handle=iMA(NULL,0,Smooth,0,meth,RSIhandle); copied=CopyBuffer(RSI_MA_handle,0,0,rates_total,RSI_SmoothedBuffer); if(copied<=0) { Print("RSI의 평활 지표를 복사할 수 없습니다. Error = ", GetLastError(),", copied =",copied); return(0); } //--- 다음 번 호출에 대해 prev_calculated 값을 반환 return(rates_total); } |