ゴゴジャン限定公開 TradingViewで反発額を計算するスクリプト
FX
Pine Script(TradingViewのスクリプト言語)で、トレンド形成時の反発額を計算するスクリプトを作成するには、特定の条件に基づいて高値と安値を検出し、その差を計算する必要があります。以下はその例です。このスクリプトは、価格が高値や安値を形成し、そこから反発した際の値幅を計算します。
pinescript//@version=5 indicator("Trend Reversal Amount", overlay=true) // パラメータ設定 length = input.int(14, title="Length") threshold = input.float(1.0, title="Reversal Threshold (%)") // 高値と安値の取得 highestHigh = ta.highest(high, length) lowestLow = ta.lowest(low, length) // トレンド反転の条件を定義 isUpTrend = close > ta.lowest(close, length) and close > ta.lowest(close[1], length) isDownTrend = close < ta.highest(close, length) and close < ta.highest(close[1], length) // 反発額を計算 reboundAmount = 0.0 if (isUpTrend) reboundAmount := close - lowestLow if (isDownTrend) reboundAmount := highestHigh - close // 反発額が閾値を超えた場合にアラートを表示 if (isUpTrend and reboundAmount > (lowestLow * threshold / 100)) label.new(x=bar_index, y=low, text="Up Rebound\n" + str.tostring(reboundAmount, format.mintick), color=color.green, style=label.style_label_down, textcolor=color.white, size=size.small) if (isDownTrend and reboundAmount > (highestHigh * threshold / 100)) label.new(x=bar_index, y=high, text="Down Rebound\n" + str.tostring(reboundAmount, format.mintick), color=color.red, style=label.style_label_up, textcolor=color.white, size=size.small) // チャートに反発額をプロット plot(isUpTrend ? reboundAmount : na, color=color.green, title="Up Rebound Amount") plot(isDownTrend ? reboundAmount : na, color=color.red, title="Down Rebound Amount")
説明
- バージョン宣言:
//@version=5は、Pine Scriptのバージョン5を使用することを示します。 - インジケータの宣言:
indicator("Trend Reversal Amount", overlay=true)は、インジケータをチャートの上に表示する設定です。 - パラメータ設定:
lengthは、トレンドを検出するための期間の長さです。thresholdは、反発と見なすための最低パーセンテージ変動です。
- 高値と安値の取得: 指定された期間の最高値と最安値を計算します。
- トレンド反転の条件:
- 上昇トレンド (
isUpTrend) は、価格が指定された期間の最安値を上回るときです。 - 下降トレンド (
isDownTrend) は、価格が指定された期間の最高値を下回るときです。
- 上昇トレンド (
- 反発額の計算:
- 上昇トレンドの場合、現在の価格と期間内の最安値の差を計算します。
- 下降トレンドの場合、期間内の最高値と現在の価格の差を計算します。
- アラート表示:
- 反発額が閾値を超えた場合、ラベルをチャートに表示します。
- 反発額のプロット:
- 上昇トレンドの反発額を緑色で、下降トレンドの反発額を赤色でプロットします。
このスクリプトをTradingViewのチャートに適用すると、トレンド形成時の反発額が計算され、閾値を超えた場合にアラートが表示されます。
×![]()
Is it OK?