커뮤니티

변환부탁드립니다.

프로필 이미지
코샘매쓰
2021-09-27 21:15:32
1710
글번호 152500
답변완료
감사합니다. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // &#169; BobRivera990 //@version=4 study(title = "Trend Type Indicator by BobRivera990", overlay = false) //==========================================================================[Inputs]========================================================================== useAtr = input(true, title = "Use ATR to detect Sideways Movements") // Use Average True Range (ATR) to detect Sideways Movements atrLen = input(14, minval = 1, title = "ATR Length") // length of the Average True Range (ATR) used to detect Sideways Movements atrMaType = input("SMA", options = ["SMA", "EMA"], title = "ATR Moving Average Type") // Type of the moving average of the ATR used to detect Sideways Movements atrMaLen = input(20, minval = 1, title = "ATR MA Length") // length of the moving average of the ATR used to detect Sideways Movements useAdx = input(true, title = "Use ADX to detect Sideways Movements") // Use Average Directional Index (ADX) to detect Sideways Movements adxLen = input(14, minval = 1, maxval = 50, title = "ADX Smoothing") // length of the Average Directional Index (ADX) used to detect Sideways Movements diLen = input(14, minval = 1, title = "DI Length") // length of the Plus and Minus Directional Indicators (+DI & -DI) used to determine the direction of the trend adxLim = input(25, minval = 1, title = "ADX Limit") // A level of ADX used as the boundary between Trend Market and Sideways Market smooth = input(3, minval = 1, maxval = 5, title = "Smoothing Factor") // Factor used for smoothing the oscillator lag = input(8, minval = 0, maxval = 15, title = "Lag") // lag used to match indicator and chart //============================================================================================================================================================ //===================================================================[Initial Calculations]=================================================================== atr = atr(atrLen) // Calculate the Average True Range (ATR) atrMa = atrMaType == "EMA" ? ema(atr, atrMaLen) : sma(atr, atrMaLen) // Calculate the moving average of the ATR up = change(high) // Calculate parameter related to ADX, +DI and -DI down = -change(low) // Calculate parameter related to ADX, +DI and -DI plusDM = na(up) ? na : (up > down and up > 0 ? up : 0) // Calculate parameter related to ADX, +DI and -DI minusDM = na(down) ? na : (down > up and down > 0 ? down : 0) // Calculate parameter related to ADX, +DI and -DI trur = rma(tr, diLen) // Calculate parameter related to ADX, +DI and -DI plus = fixnan(100 * rma(plusDM, diLen) / trur) // Calculate Plus Directional Indicator (+DI) minus = fixnan(100 * rma(minusDM, diLen) / trur) // Calculate Minus Directional Indicator (-DI) sum = plus + minus // Calculate parameter related to ADX adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxLen) // Calculate Average Directional Index (ADX) //============================================================================================================================================================ //========================================================================[Conditions]======================================================================== cndNa = na(atr) or na(adx) or na(plus) or na(minus) or na(atrMaLen) // Conditions for lack of sufficient data for calculations cndSidwayss1 = useAtr and atr <= atrMa // Sideways Movement condition (based on ATR) cndSidwayss2 = useAdx and adx <= adxLim // Sideways Movement condition (based on ADX) cndSidways = cndSidwayss1 or cndSidwayss2 // General Sideways Movement condition cndUp = plus > minus // uptrend condition cndDown = minus >= plus // downtrend condition trendType = cndNa ? na : cndSidways ? 0 : cndUp ? 2 : -2 // Determine the type of trend smoothType = na(trendType) ? na : round(sma(trendType, smooth) / 2) * 2 // Calculate the smoothed trend type oscillator //============================================================================================================================================================ //=========================================================================[Drawing]========================================================================== colGreen30 = color.new(color.green, 30) // Define the color used in the drawings colGreen90 = color.new(color.green, 90) // Define the color used in the drawings colGray = color.new(color.gray, 20) // Define the color used in the drawings colWhite90 = color.new(color.white, 90) // Define the color used in the drawings colRed30 = color.new(color.red, 30) // Define the color used in the drawings colRed90 = color.new(color.red, 90) // Define the color used in the drawings band3 = plot(+3, title = "Band_3", color=color.black) // Draw the upper limit of the uptrend area band2 = plot(+1, title = "Band_2", color=color.black) // Draw the boundary between Sideways and Uptrend areas band1 = plot(-1, title = "Band_1", color=color.black) // Draw the boundary between Sideways and Downtrend areas band0 = plot(-3, title = "Band_0", color=color.black) // Draw the lower limit of the downtrend area fill(band2, band3, title = "Uptrend area", color = colGreen90) // Highlight the Uptrend area fill(band1, band2, title = "Sideways area", color = colWhite90) // Highlight the Sideways area fill(band0, band1, title = "Downtrend area", color = colRed90) // Highlight the Downtrend area var label lblUp = na label.delete(lblUp) lblUp := label.new(x = time, y = 2, text = "UP", color = color.new(color.green, 100), textcolor = color.black, style = label.style_label_left, xloc = xloc.bar_time, yloc = yloc.price, size=size.normal, textalign = text.align_left) // Show Uptrend area label var label lblSideways = na label.delete(lblSideways) lblSideways := label.new(x = time, y = 0, text = "SIDEWAYS", color = color.new(color.green, 100), textcolor = color.black, style = label.style_label_left, xloc = xloc.bar_time, yloc = yloc.price, size = size.normal, textalign = text.align_left) // Show Sideways area label var label lblDown = na label.delete(lblDown) lblDown := label.new(x = time, y = -2, text = "DOWN", color = color.new(color.green, 100), textcolor = color.black, style = label.style_label_left, xloc = xloc.bar_time, yloc = yloc.price, size = size.normal, textalign = text.align_left) // Show Downtrend area label var label lblCurrentType = na label.delete(lblCurrentType) lblCurrentType := label.new(x = time, y = smoothType, color = color.new(color.blue, 30), style = label.style_label_right, xloc = xloc.bar_time, yloc = yloc.price, size = size.small) // Show the latest status label trendCol = smoothType == 2 ? colGreen30 : smoothType == 0 ? colGray : colRed30 // Determine the color of the oscillator in different conditions plot(smoothType, title = "Trend Type Oscillator", color = trendCol, linewidth = 3, offset = -lag, style = plot.style_stepline) // Draw the trend type oscillator
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2021-09-28 16:41:20

안녕하세요 예스스탁입니다. input : useAtr(true),atrLen(14),atrMaType("SMA"),atrMaLen(20),useAdx(true),adxLen(14),diLen(14),adxLim(25), smooth(3),lag(8); var : ATrv(0),atrMa(0),upv(0),dnv(0),plusDM(0),minusDM(0),trur(0),adxv(0); var : plus(0),minus(0),sum(0),rma1(0),rma2(0),rma3(0),rma4(0); var : cndNa(False),cndSidwayss1(False),cndSidwayss2(False),cndSidways(False); var : cndUp(False),cndDown(False),trendType(0),smoothType(0); var : tx1(0),tx2(0),tx3(0); atrv = atr(atrLen); if atrMaType == "EMA" Then atrMa = ema(atrv, atrMaLen); Else atrMa = ma(atrv, atrMaLen); upv = h-H[1]; dnv = -(L-L[1]); plusDM = iff(IsNan(upv) , Nan , IFf(upv > dnv and upv > 0 , upv , 0)); minusDM = iff(IsNan(dnv) , Nan , IFf(dnv > upv and dnv > 0 , dnv , 0)); var1 = 1/15; rma1 = iff(IsNan(rma1) , ma(c, 15) , var1 * C + (1 - var1) * trur); trur = rma1; var2 = 1/diLen; rma2 = iff(IsNan(rma2) , ma(plusDM, 15) , var2 * plusDM + (1 - var2) * rma2); rma3 = iff(IsNan(rma3) , ma(minusDM, 15) , var2 * minusDM + (1 - var2) * rma3); plus = 100 * rma2/ trur; minus = 100 * rma3 / trur; sum = plus + minus; Var4 = 1/adxlen; value4 = abs(plus - minus) / IFf(sum == 0 , 1 , sum); rma4 = iff(IsNan(rma4) , ma(value4, 15) , var4 * value4 + (1 - var4) * rma4); adxv = 100 * rma4; cndNa = IsNan(atrv) or IsNan(adxv) or IsNan(plus) or IsNan(minus) or IsNan(atrMaLen); cndSidwayss1 = useAtr and atrv <= atrMa; cndSidwayss2 = useAdx and adxv <= adxLim; cndSidways = cndSidwayss1 or cndSidwayss2; cndUp = plus > minus; cndDown = minus >= plus; trendType = iff(cndNa , Nan , iff(cndSidways , 0 , iff(cndUp , 2 , -2))); smoothType = iff(IsNan(trendType) , Nan , round(ma(trendType, smooth) / 2,0) * 2); plot1(3,"Band_3",black); plot2(1,"Band_2",black); plot3(-1,"Band_1",black); plot4(-3,"Band_0",black); plot5(smoothType,"Trend Type Oscillator"); Text_Delete(tx1); Text_Delete(tx2); Text_Delete(tx3); tx1 = Text_New_Self(NextBarSdate,NextBarStime,2,"UP"); tx2 = Text_New_Self(NextBarSdate,NextBarStime,0,"SIDEWAYS"); tx3 = Text_New_Self(NextBarSdate,NextBarStime,-2,"DOWN"); 즐거운 하루되세요 > 코샘매쓰 님이 쓴 글입니다. > 제목 : 변환부탁드립니다. > 감사합니다. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // &#169; BobRivera990 //@version=4 study(title = "Trend Type Indicator by BobRivera990", overlay = false) //==========================================================================[Inputs]========================================================================== useAtr = input(true, title = "Use ATR to detect Sideways Movements") // Use Average True Range (ATR) to detect Sideways Movements atrLen = input(14, minval = 1, title = "ATR Length") // length of the Average True Range (ATR) used to detect Sideways Movements atrMaType = input("SMA", options = ["SMA", "EMA"], title = "ATR Moving Average Type") // Type of the moving average of the ATR used to detect Sideways Movements atrMaLen = input(20, minval = 1, title = "ATR MA Length") // length of the moving average of the ATR used to detect Sideways Movements useAdx = input(true, title = "Use ADX to detect Sideways Movements") // Use Average Directional Index (ADX) to detect Sideways Movements adxLen = input(14, minval = 1, maxval = 50, title = "ADX Smoothing") // length of the Average Directional Index (ADX) used to detect Sideways Movements diLen = input(14, minval = 1, title = "DI Length") // length of the Plus and Minus Directional Indicators (+DI & -DI) used to determine the direction of the trend adxLim = input(25, minval = 1, title = "ADX Limit") // A level of ADX used as the boundary between Trend Market and Sideways Market smooth = input(3, minval = 1, maxval = 5, title = "Smoothing Factor") // Factor used for smoothing the oscillator lag = input(8, minval = 0, maxval = 15, title = "Lag") // lag used to match indicator and chart //============================================================================================================================================================ //===================================================================[Initial Calculations]=================================================================== atr = atr(atrLen) // Calculate the Average True Range (ATR) atrMa = atrMaType == "EMA" ? ema(atr, atrMaLen) : sma(atr, atrMaLen) // Calculate the moving average of the ATR up = change(high) // Calculate parameter related to ADX, +DI and -DI down = -change(low) // Calculate parameter related to ADX, +DI and -DI plusDM = na(up) ? na : (up > down and up > 0 ? up : 0) // Calculate parameter related to ADX, +DI and -DI minusDM = na(down) ? na : (down > up and down > 0 ? down : 0) // Calculate parameter related to ADX, +DI and -DI trur = rma(tr, diLen) // Calculate parameter related to ADX, +DI and -DI plus = fixnan(100 * rma(plusDM, diLen) / trur) // Calculate Plus Directional Indicator (+DI) minus = fixnan(100 * rma(minusDM, diLen) / trur) // Calculate Minus Directional Indicator (-DI) sum = plus + minus // Calculate parameter related to ADX adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxLen) // Calculate Average Directional Index (ADX) //============================================================================================================================================================ //========================================================================[Conditions]======================================================================== cndNa = na(atr) or na(adx) or na(plus) or na(minus) or na(atrMaLen) // Conditions for lack of sufficient data for calculations cndSidwayss1 = useAtr and atr <= atrMa // Sideways Movement condition (based on ATR) cndSidwayss2 = useAdx and adx <= adxLim // Sideways Movement condition (based on ADX) cndSidways = cndSidwayss1 or cndSidwayss2 // General Sideways Movement condition cndUp = plus > minus // uptrend condition cndDown = minus >= plus // downtrend condition trendType = cndNa ? na : cndSidways ? 0 : cndUp ? 2 : -2 // Determine the type of trend smoothType = na(trendType) ? na : round(sma(trendType, smooth) / 2) * 2 // Calculate the smoothed trend type oscillator //============================================================================================================================================================ //=========================================================================[Drawing]========================================================================== colGreen30 = color.new(color.green, 30) // Define the color used in the drawings colGreen90 = color.new(color.green, 90) // Define the color used in the drawings colGray = color.new(color.gray, 20) // Define the color used in the drawings colWhite90 = color.new(color.white, 90) // Define the color used in the drawings colRed30 = color.new(color.red, 30) // Define the color used in the drawings colRed90 = color.new(color.red, 90) // Define the color used in the drawings band3 = plot(+3, title = "Band_3", color=color.black) // Draw the upper limit of the uptrend area band2 = plot(+1, title = "Band_2", color=color.black) // Draw the boundary between Sideways and Uptrend areas band1 = plot(-1, title = "Band_1", color=color.black) // Draw the boundary between Sideways and Downtrend areas band0 = plot(-3, title = "Band_0", color=color.black) // Draw the lower limit of the downtrend area fill(band2, band3, title = "Uptrend area", color = colGreen90) // Highlight the Uptrend area fill(band1, band2, title = "Sideways area", color = colWhite90) // Highlight the Sideways area fill(band0, band1, title = "Downtrend area", color = colRed90) // Highlight the Downtrend area var label lblUp = na label.delete(lblUp) lblUp := label.new(x = time, y = 2, text = "UP", color = color.new(color.green, 100), textcolor = color.black, style = label.style_label_left, xloc = xloc.bar_time, yloc = yloc.price, size=size.normal, textalign = text.align_left) // Show Uptrend area label var label lblSideways = na label.delete(lblSideways) lblSideways := label.new(x = time, y = 0, text = "SIDEWAYS", color = color.new(color.green, 100), textcolor = color.black, style = label.style_label_left, xloc = xloc.bar_time, yloc = yloc.price, size = size.normal, textalign = text.align_left) // Show Sideways area label var label lblDown = na label.delete(lblDown) lblDown := label.new(x = time, y = -2, text = "DOWN", color = color.new(color.green, 100), textcolor = color.black, style = label.style_label_left, xloc = xloc.bar_time, yloc = yloc.price, size = size.normal, textalign = text.align_left) // Show Downtrend area label var label lblCurrentType = na label.delete(lblCurrentType) lblCurrentType := label.new(x = time, y = smoothType, color = color.new(color.blue, 30), style = label.style_label_right, xloc = xloc.bar_time, yloc = yloc.price, size = size.small) // Show the latest status label trendCol = smoothType == 2 ? colGreen30 : smoothType == 0 ? colGray : colRed30 // Determine the color of the oscillator in different conditions plot(smoothType, title = "Trend Type Oscillator", color = trendCol, linewidth = 3, offset = -lag, style = plot.style_stepline) // Draw the trend type oscillator