ボリンジャー・バンド + EMA 9

作者: リン・ハーンチャオチャン開催日:2023年9月8日16時29分
タグ:

このコードは,TradingViewプラットフォーム上のチャートをカスタマイズするために使用されるPine Scriptで書かれています. ボリンジャーバンドと9期 EMA (指数関数移動平均線) を使用したスカルピング戦略を定義しているようです. いくつかの重要な部分をご説明します.

  1. EMAの計算とプロット:

    ema9 = ta.ema(close, 9) plot(ema9)

9日間の EMA の線形グラフが表示されます.

  1. ボリンジャー・バンドの計算と戦略の定義

strategy("Bollinger Bands + EMA 9", overlay=true) length = input.int(20, minval=1) src = input(close, title="Source") mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev") basis = ta.sma(src, length) dev = mult * ta.stdev(src, length) upper = basis + dev lower = basis - dev offset = input.int(0, "Offset", minval = -500, maxval = 500) p1 = plot(upper, "Upper", color=#2962FF, offset = offset) p2 = plot(lower, "Lower", color=#2962FF, offset = offset) fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

上下ボリンジャー帯を計算し グラフを描き その間を埋めます

  1. ロング・トレードに入手・退場するタイミングを定義します.

    Exit = close >= ema9 Long = (close[1] <lower) strategy.entry("Long",strategy.long, 1000, when =Long) strategy.close("Long", when=add)

このパートは,閉じる価格が下の帯を突破するとLONGポジションに入手し,閉じる価格が9日間のEMAに等しいかそれ以上になると終了します.

このスクリプトは,個人的なリスク耐性や好みに応じて調整する必要があることに注意してください.また,ライブ取引環境でのパフォーマンスも異なる場合があります.実際の取引に進む前に,常に取引戦略をバックテストしてください.


/*backtest
start: 2022-09-01 00:00:00
end: 2023-09-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © D499

//@version=5
//EMA
ema9 = ta.ema(close, 9)
plot(ema9)
//BB
strategy("Bollinger Bands + EMA 9", overlay=true)
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

Exit = close >= ema9
Long = (close[1] < lower)
strategy.entry("Long",strategy.long, 1, when = Long)
strategy.close("Long", when = Exit)

もっと