ボリュームヒートマップとリアルタイム価格に基づいた売買戦略

EMA VWAP SMA
作成日: 2024-05-24 17:16:58 最終変更日: 2024-05-24 17:16:58
コピー: 2 クリック数: 575
1
フォロー
1621
フォロワー

ボリュームヒートマップとリアルタイム価格に基づいた売買戦略

概要

この戦略は,取引量熱図とリアルタイム価格を組み合わせて,一定期間における価格と取引量分布を分析することによって,買入シグナルを生成する.戦略は,まず,現在の価格と設定された価格範囲のパーセントに基づいて,いくつかの価格レベルを計算する.その後,各価格レベルを過去の一段の期間における買入取引量を統計化し,累積された買入取引量を計算する.累積された買入取引量に基づいて,ラベルの色を決定する.同時に,戦略は,リアルタイム価格曲線を描く.さらに,この戦略は,EMA,VWAPなどの指標を組み合わせて,価格と取引量との関係に基づいて,買入シグナルを生成する.購入条件が満たされ,それ以前にシグナルが生成されなければ,買入シグナルが生成される.

戦略原則

  1. 現在の価格と設定された価格範囲のパーセントに基づいて,いくつかの価格レベルが計算されます.
  2. 各価格レベルの過去期間における取引量を統計し,累積取引量を計算する.
  3. 累積された取引量に基づいて,ラベルの色を決定し,ラベルの表示またはグラフィックを描きます.
  4. リアルタイム価格曲線を描画する.
  5. EMA,VWAPなどの指標を計算する.
  6. 価格とEMA,VWAPなどの指標の関係と取引量条件に基づいて,購入条件が満たされているかどうかを判断する.もし満たされ,以前にシグナルが生じていない場合は,購入シグナルが生じます.
  7. 価格とEMAなどの指標の関係と取引量条件に基づいて,売却条件を満たすかどうかを判断する.満たされ,以前に信号が生じていない場合は,売却信号が生じます.連続した2つの陰線が,以前に信号が生じていない場合でも,売却信号が生じます.
  8. 現在の取引条件の状態を記録し,信号生成の状態を更新します.

優位分析

  1. 取引量ヒートグラフとリアルタイム価格を組み合わせて,価格と取引量分布を直視的に表示し,取引決定に参考を提供する.
  2. EMA,VWAPなどの指標を導入し,戦略の条件判断を豊かにし,戦略の信頼性を高めました.
  3. 価格,指数,取引量などの様々な要素を考慮して,買い物シグナルをより包括的かつ堅牢にします.
  4. 信号生成の制限条件を設定し,連続して重複信号を生成する状況を回避し,誤導的な信号を減らす.

リスク分析

  1. 戦略のパフォーマンスは,価格範囲のパーセント,回帰期などのパラメータ設定によって影響され,状況に応じて調整および最適化が必要である.
  2. EMA,VWAPなどの指標は,それ自体にも遅滞や限界があり,特定の市場環境で有効性が失われる可能性があります.
  3. この戦略は,傾向が強い市場には適用され,波動的な市場では偽信号が多く発生する可能性がある.
  4. 戦略のリスクコントロールは比較的シンプルで,ストップ・ロスやポジション管理などのリスク管理手段は欠けている.

最適化の方向

  1. RSI,MACD,ブリン帯など,より多くの技術指標と市場情緒指標を導入し,戦略的な判断の根拠を豊かにする.
  2. 買い売りシグナルの生成条件を最適化し,シグナルの正確性と信頼性を向上させる.複数の時間枠の分析を導入し,トレンドの方向を確認することを考慮することができる.
  3. リスク管理手段の追加,例えば,ストップ・ロズとポジション管理,合理的なストップ・ロズとポジションの規模を設定し,単一取引のリスクの値を制御する.
  4. 戦略のパラメータ最適化と反テストを行い,最適のパラメータ組み合わせと市場適用範囲を特定する.
  5. この戦略を他の戦略と組み合わせて,異なる戦略の優位性を発揮し,全体的な安定性と収益性を向上させることを検討する.

要約する

この戦略は,取引量熱図,リアルタイム価格および複数の技術指標を組み合わせて,買取信号を生成し,一定の参照価値を有する.戦略の優点は,価格と取引量の分布を直視的に表示することができ,複数の要因を総合的に考慮してシグナルを生成することにある.しかし,戦略には,パラメータ設定の影響,指標の遅れ,トレンド性市場の依存など,いくつかの制限とリスクがある.したがって,実際のアプリケーションでは,より多くの指標,シグナル条件の最適化,リスク制御の強化などの戦略の安定性と収益性の向上のために,さらなる最適化と戦略の完善が必要である.

ストラテジーソースコード
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Buy and Sell Volume Heatmap with Real-Time Price Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Settings for Volume Heatmap
lookbackPeriod = input.int(100, title="Lookback Period")
baseGreenColor = input.color(color.green, title="Buy Volume Color")
baseRedColor = input.color(color.red, title="Sell Volume Color")
priceLevels = input.int(10, title="Number of Price Levels")
priceRangePct = input.float(0.01, title="Price Range Percentage")
labelSize = input.string("small", title="Label Size", options=["tiny", "small", "normal", "large"])
showLabels = input.bool(true, title="Show Volume Labels")

// Initialize arrays to store price levels, buy volumes, and sell volumes
var float[] priceLevelsArr = array.new_float(priceLevels)
var float[] buyVolumes = array.new_float(priceLevels)
var float[] sellVolumes = array.new_float(priceLevels)

// Calculate price levels around the current price
for i = 0 to priceLevels - 1
    priceLevel = close * (1 + (i - priceLevels / 2) * priceRangePct)  // Adjust multiplier for desired spacing
    array.set(priceLevelsArr, i, priceLevel)

// Calculate buy and sell volumes for each price level
for i = 0 to priceLevels - 1
    level = array.get(priceLevelsArr, i)
    buyVol = 0.0
    sellVol = 0.0
    for j = 1 to lookbackPeriod
        if close[j] > open[j]
            if close[j] >= level and low[j] <= level
                buyVol := buyVol + volume[j]
        else
            if close[j] <= level and high[j] >= level
                sellVol := sellVol + volume[j]
    array.set(buyVolumes, i, buyVol)
    array.set(sellVolumes, i, sellVol)

// Determine the maximum volumes for normalization
maxBuyVolume = array.max(buyVolumes)
maxSellVolume = array.max(sellVolumes)

// Initialize cumulative buy and sell volumes for the current bar
cumulativeBuyVol = 0.0
cumulativeSellVol = 0.0

// Calculate colors based on the volumes and accumulate volumes for the current bar
for i = 0 to priceLevels - 1
    buyVol = array.get(buyVolumes, i)
    sellVol = array.get(sellVolumes, i)
    cumulativeBuyVol := cumulativeBuyVol + buyVol
    cumulativeSellVol := cumulativeSellVol + sellVol

// Determine the label color based on which volume is higher
labelColor = cumulativeBuyVol > cumulativeSellVol ? baseGreenColor : baseRedColor

// Initialize variables for plotshape
var float shapePosition = na
var color shapeColor = na

if cumulativeBuyVol > 0 or cumulativeSellVol > 0
    if showLabels
        labelText = "Buy: " + str.tostring(cumulativeBuyVol) + "\nSell: " + str.tostring(cumulativeSellVol)
        label.new(x=bar_index, y=high + (high - low) * 0.02, text=labelText, color=color.new(labelColor, 0), textcolor=color.white, style=label.style_label_down, size=labelSize)
    else
        shapePosition := high + (high - low) * 0.02
        shapeColor := labelColor

// Plot the shape outside the local scope
plotshape(series=showLabels ? na : shapePosition, location=location.absolute, style=shape.circle, size=size.tiny, color=shapeColor)

// Plot the real-time price on the chart
plot(close, title="Real-Time Price", color=color.blue, linewidth=2, style=plot.style_line)

// Mpullback Indicator Settings
a = ta.ema(close, 9)
b = ta.ema(close, 20)
e = ta.vwap(close)
volume_ma = ta.sma(volume, 20)

// Calculate conditions for buy and sell signals
buy_condition = close > a and close > e and volume > volume_ma and close > open and low > a and low > e // Ensure close, low are higher than open, EMA, and VWAP
sell_condition = close < a and close < b and close < e and volume > volume_ma

// Store the previous buy and sell conditions
var bool prev_buy_condition = na
var bool prev_sell_condition = na

// Track if a buy or sell signal has occurred
var bool signal_occurred = false

// Generate buy and sell signals based on conditions
buy_signal = buy_condition and not prev_buy_condition and not signal_occurred
sell_signal = sell_condition and not prev_sell_condition and not signal_occurred

// Determine bearish condition (close lower than the bottom 30% of the candle's range)
bearish = close < low + (high - low) * 0.3

// Add sell signal when there are two consecutive red candles and no signal has occurred
two_consecutive_red_candles = close[1] < open[1] and close < open
sell_signal := sell_signal or (two_consecutive_red_candles and not signal_occurred)

// Remember the current conditions for the next bar
prev_buy_condition := buy_condition
prev_sell_condition := sell_condition

// Update signal occurred status
signal_occurred := buy_signal or sell_signal

// Plot buy and sell signals
plotshape(buy_signal, title="Buy", style=shape.labelup, location=location.belowbar, color=color.green, text="Buy", textcolor=color.white)
plotshape(sell_signal, title="Sell", style=shape.labeldown, location=location.abovebar, color=color.red, text="Sell", textcolor=color.white)

// Strategy entry and exit
if buy_signal
    strategy.entry("Buy", strategy.long)

if sell_signal
    strategy.entry("Sell", strategy.short)