Harigami
ログイン
pk-hangjing タイトルなし
No License Python
コピー
//@version=4
study("自動平行チャネル", "短期中期", true, format.inherit)
period     = input(     300, "中期チャネル期間"       , input.integer, minval=3)
period2     = input(     100, "短期チャネル期間"       , input.integer, minval=3)
deviations = input(    2.0, "中期チャネル幅調整" , input.float  , minval=0.1, step=0.1)
deviations2 = input(    2.0, "短期チャネル幅調整" , input.float  , minval=0.1, step=0.1)
extendType = input("ON", "中期チャネル延長", input.string , options=["ON","OFF"])=="ON" ? extend.right : extend.none
extendType2 = input("ON", "短期チャネル延長", input.string , options=["ON","OFF"])=="ON" ? extend.right : extend.none
periodMinusOne = period-1
periodMinusOne2 = period2-1
///中期
Ex = 0.0, Ey = 0.0, Ex2 = 0.0, Exy = 0.0, for i=0 to periodMinusOne
    closeI = nz(close[i]), Ex := Ex + i, Ey := Ey + closeI, Ex2 := Ex2 + (i * i), Exy := Exy + (closeI * i)
ExEx = Ex * Ex, slope = Ex2==ExEx ? 0.0 : (period * Exy - Ex * Ey) / (period * Ex2 - ExEx)
linearRegression = (Ey - slope * Ex) / period
intercept = linearRegression + bar_index * slope
deviation = 0.0, for i=0 to periodMinusOne
    deviation := deviation + pow(nz(close[i]) - (intercept - slope * (bar_index[i])), 2.0)
deviation := deviations * sqrt(deviation / periodMinusOne)
startingPointY = linearRegression + slope * periodMinusOne
var line upperChannelLine = na  , var line medianChannelLine = na  , var line lowerChannelLine = na
line.delete(upperChannelLine[1]), line.delete(medianChannelLine[1]), line.delete(lowerChannelLine[1])
///短期
Ex3 = 0.0, Ey3 = 0.0, Ex4 = 0.0, Exy3 = 0.0, for i3=0 to periodMinusOne2
    closeI3 = nz(close[i3]), Ex3 := Ex3 + i3, Ey3 := Ey3 + closeI3, Ex4 := Ex4 + (i3 * i3), Exy3 := Exy3 + (closeI3 * i3)
ExEx3 = Ex3 * Ex3, slope3 = Ex4==ExEx3 ? 0.0 : (period2 * Exy3 - Ex3 * Ey3) / (period2 * Ex4 - ExEx3)
linearRegression3 = (Ey3 - slope3 * Ex3) / period2
intercept3 = linearRegression3 + bar_index * slope3
deviation3 = 0.0, for i3=0 to periodMinusOne2
    deviation3 := deviation3 + pow(nz(close[i3]) - (intercept3 - slope3 * (bar_index[i3])), 2.0)
deviation3 := deviations2 * sqrt(deviation3 / periodMinusOne2)
startingPointY3 = linearRegression3 + slope3 * periodMinusOne2
var line upperChannelLine3 = na  , var line medianChannelLine3 = na  , var line lowerChannelLine3 = na
line.delete(upperChannelLine3[1]), line.delete(medianChannelLine3[1]), line.delete(lowerChannelLine3[1])
///カラー
upperChannelLine  := line.new(bar_index - period + 1, startingPointY + deviation, bar_index, linearRegression + deviation, xloc.bar_index, extendType, color.lime, line.style_solid , 2)
medianChannelLine := line.new(bar_index - period + 1, startingPointY            , bar_index, linearRegression            , xloc.bar_index, extendType, color.lime, line.style_solid , 1)
lowerChannelLine  := line.new(bar_index - period + 1, startingPointY - deviation, bar_index, linearRegression - deviation, xloc.bar_index, extendType, color.lime, line.style_solid , 2)

upperChannelLine3  := line.new(bar_index - period2 + 1, startingPointY3 + deviation3, bar_index, linearRegression3 + deviation3, xloc.bar_index, extendType2, color.red, line.style_solid , 2)
lowerChannelLine3  := line.new(bar_index - period2 + 1, startingPointY3 - deviation3, bar_index, linearRegression3 - deviation3, xloc.bar_index, extendType2, color.red, line.style_solid , 2)
//@version=4
study("自動平行チャネル", "短期中期", true, format.inherit)
period     = input(     300, "中期チャネル期間"       , input.integer, minval=3)
period2     = input(     100, "短期チャネル期間"       , input.integer, minval=3)
deviations = input(    2.0, "中期チャネル幅調整" , input.float  , minval=0.1, step=0.1)
deviations2 = input(    2.0, "短期チャネル幅調整" , input.float  , minval=0.1, step=0.1)
extendType = input("ON", "中期チャネル延長", input.string , options=["ON","OFF"])=="ON" ? extend.right : extend.none
extendType2 = input("ON", "短期チャネル延長", input.string , options=["ON","OFF"])=="ON" ? extend.right : extend.none
periodMinusOne = period-1
periodMinusOne2 = period2-1
///中期
Ex = 0.0, Ey = 0.0, Ex2 = 0.0, Exy = 0.0, for i=0 to periodMinusOne
    closeI = nz(close[i]), Ex := Ex + i, Ey := Ey + closeI, Ex2 := Ex2 + (i * i), Exy := Exy + (closeI * i)
ExEx = Ex * Ex, slope = Ex2==ExEx ? 0.0 : (period * Exy - Ex * Ey) / (period * Ex2 - ExEx)
linearRegression = (Ey - slope * Ex) / period
intercept = linearRegression + bar_index * slope
deviation = 0.0, for i=0 to periodMinusOne
    deviation := deviation + pow(nz(close[i]) - (intercept - slope * (bar_index[i])), 2.0)
deviation := deviations * sqrt(deviation / periodMinusOne)
startingPointY = linearRegression + slope * periodMinusOne
var line upperChannelLine = na  , var line medianChannelLine = na  , var line lowerChannelLine = na
line.delete(upperChannelLine[1]), line.delete(medianChannelLine[1]), line.delete(lowerChannelLine[1])
///短期
Ex3 = 0.0, Ey3 = 0.0, Ex4 = 0.0, Exy3 = 0.0, for i3=0 to periodMinusOne2
    closeI3 = nz(close[i3]), Ex3 := Ex3 + i3, Ey3 := Ey3 + closeI3, Ex4 := Ex4 + (i3 * i3), Exy3 := Exy3 + (closeI3 * i3)
ExEx3 = Ex3 * Ex3, slope3 = Ex4==ExEx3 ? 0.0 : (period2 * Exy3 - Ex3 * Ey3) / (period2 * Ex4 - ExEx3)
linearRegression3 = (Ey3 - slope3 * Ex3) / period2
intercept3 = linearRegression3 + bar_index * slope3
deviation3 = 0.0, for i3=0 to periodMinusOne2
    deviation3 := deviation3 + pow(nz(close[i3]) - (intercept3 - slope3 * (bar_index[i3])), 2.0)
deviation3 := deviations2 * sqrt(deviation3 / periodMinusOne2)
startingPointY3 = linearRegression3 + slope3 * periodMinusOne2
var line upperChannelLine3 = na  , var line medianChannelLine3 = na  , var line lowerChannelLine3 = na
line.delete(upperChannelLine3[1]), line.delete(medianChannelLine3[1]), line.delete(lowerChannelLine3[1])
///カラー
upperChannelLine  := line.new(bar_index - period + 1, startingPointY + deviation, bar_index, linearRegression + deviation, xloc.bar_index, extendType, color.lime, line.style_solid , 2)
medianChannelLine := line.new(bar_index - period + 1, startingPointY            , bar_index, linearRegression            , xloc.bar_index, extendType, color.lime, line.style_solid , 1)
lowerChannelLine  := line.new(bar_index - period + 1, startingPointY - deviation, bar_index, linearRegression - deviation, xloc.bar_index, extendType, color.lime, line.style_solid , 2)

upperChannelLine3  := line.new(bar_index - period2 + 1, startingPointY3 + deviation3, bar_index, linearRegression3 + deviation3, xloc.bar_index, extendType2, color.red, line.style_solid , 2)
lowerChannelLine3  := line.new(bar_index - period2 + 1, startingPointY3 - deviation3, bar_index, linearRegression3 - deviation3, xloc.bar_index, extendType2, color.red, line.style_solid , 2)
コンソール
現在、コメントはありません。
最初のコメンターになりませんか?