같은 지표에서 추세와 확인처럼 들립니다. 흥미 롭습니다!
안녕하세요 인디케이터 코드를 공유해 주셔서 감사합니다. 트레이딩 뷰에서 스퀴즈 모멘텀 인디케이터를 변환하려고했는데 여기에 제가 가진 코드가 있습니다... 약간 다릅니다... 이에 대한 의견을 듣고 싶습니다! 고마워요.
//+------------------------------------------------------------------------+ //|스퀴즈 모멘텀 인디케이터.mq5 | //|LazyBear의 파인 스크립트에서 변환 | //|| //+------------------------------------------------------------------------+ #property copyright "Converted from Pine Script by LazyBear" #property link "" #property version "1.02" #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 2 #property indicator_type1 DRAW_COLOR_HISTOGRAM #property indicator_color1 clrLime, clrGreen, clrRed, clrMaroon #property indicator_style1 STYLE_SOLID #property indicator_width1 4 #property indicator_label1 "Squeeze Momentum" #property indicator_type2 DRAW_COLOR_LINE #property indicator_color2 clrBlue, clrBlack, clrGray #property indicator_style2 STYLE_SOLID #property indicator_width2 2 #property indicator_label2 "Squeeze" //--- 입력 매개변수 input int LengthBB = 20; // BB 길이 input double MultBB = 2.0; // BB 멀티팩터 input int LengthKC = 20; // KC 길이 input double MultKC = 1.5; // KC 멀티팩터 input bool UseTrueRange = true; // 트루레인지 사용(KC) //--- 표시기 버퍼 double MomentumBuffer[]; // 모멘텀 값 double MomentumColorBuffer[]; // 모멘텀 색상 double SqueezeBuffer[]; // 스퀴즈 값 double SqueezeColorBuffer[]; // 스퀴즈 색상 //+------------------------------------------------------------------+ //| 사용자 지정 표시기 초기화 기능| //+------------------------------------------------------------------+ int OnInit() { //--- 표시기 버퍼 매핑 SetIndexBuffer(0, MomentumBuffer, INDICATOR_DATA); SetIndexBuffer(1, MomentumColorBuffer, INDICATOR_COLOR_INDEX); SetIndexBuffer(2, SqueezeBuffer, INDICATOR_DATA); SetIndexBuffer(3, SqueezeColorBuffer, INDICATOR_COLOR_INDEX); //--- 색상 색인 설정 PlotIndexSetInteger(0, PLOT_COLOR_INDEXES, 4); // 히스토그램의 4가지 색상 PlotIndexSetInteger(1, PLOT_COLOR_INDEXES, 3); // 라인의 3가지 색상 //--- 표시기 이름 설정 IndicatorSetString(INDICATOR_SHORTNAME, "SQZMOM_LB [LazyBear]"); //--- 정밀도 설정 IndicatorSetInteger(INDICATOR_DIGITS, 5); //--- 배열을 시리즈로 설정 ArraySetAsSeries(MomentumBuffer, true); ArraySetAsSeries(MomentumColorBuffer, true); ArraySetAsSeries(SqueezeBuffer, true); ArraySetAsSeries(SqueezeColorBuffer, true); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 단순 이동 평균| //+------------------------------------------------------------------+ double SimpleMA(const double &price[], int period, int shift) { double sum = 0.0; for(int i = 0; i < period; i++) { sum += price[shift + i]; } return sum / period; } //+------------------------------------------------------------------+ //| 표준 편차| //+------------------------------------------------------------------+ double StdDev(const double &price[], int period, int shift) { double avg = SimpleMA(price, period, shift); double sum = 0.0; for(int i = 0; i < period; i++) { sum += MathPow(price[shift + i] - avg, 2); } return MathSqrt(sum / period); } //+------------------------------------------------------------------+ //| 선형 회귀| //+------------------------------------------------------------------+ double LinReg(const double &price[], int period, int shift) { double sum_x = 0.0; double sum_y = 0.0; double sum_xy = 0.0; double sum_x2 = 0.0; for(int i = 0; i < period; i++) { sum_x += i; sum_y += price[shift + i]; sum_xy += i * price[shift + i]; sum_x2 += i * i; } double m = period; double slope = (m * sum_xy - sum_x * sum_y) / (m * sum_x2 - sum_x * sum_x); double intercept = (sum_y - slope * sum_x) / m; return intercept; } //+------------------------------------------------------------------+ //| 사용자 지정 인디케이터 반복 함수| //+------------------------------------------------------------------+ 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[]) { // 최소 데이터 확인 int min_bars = MathMax(LengthBB, LengthKC) + 1; if(rates_total < min_bars) return(0); // 적절한 인덱싱을 위해 배열을 직렬로 설정합니다. ArraySetAsSeries(high, true); ArraySetAsSeries(low, true); ArraySetAsSeries(close, true); // 시작점 계산 int limit; if(prev_calculated == 0) limit = rates_total - min_bars; else limit = rates_total - prev_calculated; limit = MathMin(limit, rates_total - min_bars); // 소스 계산을 위한 배열 준비 double source[]; ArrayResize(source, rates_total); ArraySetAsSeries(source, true); // 주 계산 루프 for(int i = limit; i >= 0; i--) { // 볼린저 밴드 계산 double basis = 0.0; for(int j = 0; j < LengthBB; j++) basis += close[i+j]; basis /= LengthBB; double dev = 0.0; for(int j = 0; j < LengthBB; j++) dev += MathPow(close[i+j] - basis, 2); dev = MultBB * MathSqrt(dev / LengthBB); double upperBB = basis + dev; double lowerBB = basis - dev; // 켈트너 채널 계산 double ma = 0.0; for(int j = 0; j < LengthKC; j++) ma += close[i+j]; ma /= LengthKC; double range_sum = 0.0; for(int j = 0; j < LengthKC; j++) { double tr; if(UseTrueRange && i+j+1 < rates_total) tr = MathMax(high[i+j] - low[i+j], MathMax(MathAbs(high[i+j] - close[i+j+1]), MathAbs(low[i+j] - close[i+j+1]))); else tr = high[i+j] - low[i+j]; range_sum += tr; } double range_ma = range_sum / LengthKC; double upperKC = ma + MultKC * range_ma; double lowerKC = ma - MultKC * range_ma; // 스퀴즈 조건 계산 bool sqzOn = (lowerBB > lowerKC) && (upperBB < upperKC); bool sqzOff = (lowerBB < lowerKC) && (upperBB > upperKC); bool noSqz = !sqzOn && !sqzOff; // KC 기간의 최고 최고점과 최저점 찾기 double highest = high[i]; double lowest = low[i]; for(int j = 1; j < LengthKC; j++) { if(i+j >= rates_total) break; if(high[i+j] > highest) highest = high[i+j]; if(low[i+j] < lowest) lowest = low[i+j]; } // linreg의 소스 계산 double avg_hl = (highest + lowest) / 2; double avg_val = (avg_hl + ma) / 2; for(int j = 0; j < LengthKC; j++) { if(i+j >= rates_total) break; source[i+j] = close[i+j] - avg_val; } // 선형 회귀로 운동량 계산하기 MomentumBuffer[i] = LinReg(source, LengthKC, i); // 스퀴즈 라인 값 설정(항상 0) SqueezeBuffer[i] = 0; // 파인 스크립트에서와 똑같이 조건에 따라 색상을 설정합니다. // bcolor = iff(val > 0, iff(val > nz(val[1]), 라임, 그린), iff(val < nz(val[1], 레드, 마룬))) if(i < rates_total - 1) { if(MomentumBuffer[i] > 0) { if(MomentumBuffer[i] > MomentumBuffer[i+1]) MomentumColorBuffer[i] = 0; // 라임 else MomentumColorBuffer[i] = 1; // 녹색 } else { if(MomentumBuffer[i] < MomentumBuffer[i+1]) MomentumColorBuffer[i] = 2; // 빨간색 else MomentumColorBuffer[i] = 3; // maroon } } else { // 첫 번째 막대의 경우 MomentumColorBuffer[i] = (MomentumBuffer[i] > 0) ? 0 : 2; // 라임 또는 레드 } // scolor = noSqz ? blue : sqzOn ? black : gray if(noSqz) SqueezeColorBuffer[i] = 0; // blue else if(sqzOn) SqueezeColorBuffer[i] = 1; // 검정 else SqueezeColorBuffer[i] = 2; // 회색 } return(rates_total); } //+------------------------------------------------------------------+
파일:
Squeze_Momentum.mq5
9 kb
Bollinger Squeeze Basic MT5:
볼린저 스퀴즈 기본 메타 트레이더 지표 - 모멘텀, 볼린저 밴드 및 켈트너 채널을 기반으로 한 복합 지표입니다. 이 지표는 현재 볼린저 밴드와 켈트너 채널 값 사이의 관계를 보여줄 때 차트의 별도 창에 모멘텀 히스토그램과 점 범위로 그려집니다. 이 지표는 MT4 및 MT5 버전의 거래 플랫폼에서 모두 사용할 수 있습니다.
Author: Tuan Nguyen Van