Kod ini ditulis dalam Pine Script, yang digunakan untuk menyesuaikan carta di platform TradingView. Ia seolah-olah menentukan strategi scalping menggunakan Bollinger Bands dan 9 tempoh EMA (Exponential Moving Average).
Pengiraan dan perancangan EMA:
ema9 = ta.ema(close, 9) plot(ema9)
Ini menghasilkan carta garis EMA 9 hari.
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))
Ia mengira Bollinger Bands atas dan bawah, merangka mereka dan mengisi kawasan di antara.
Menentukan bila untuk memasuki dan keluar perdagangan panjang:
Exit = close >= ema9 Long = (close[1] <lower) strategy.entry("Long",strategy.long, 1000, when =Long) strategy.close("Long", when=add)
Bahagian ini memasuki kedudukan LONG apabila harga penutupan melanggar jalur bawah dan keluar apabila harga penutupan sama atau melebihi EMA 9 hari.
Sila ambil perhatian bahawa anda perlu menyesuaikan skrip ini mengikut toleransi risiko dan pilihan peribadi anda. Juga, prestasi dalam persekitaran perdagangan langsung mungkin berbeza. Sentiasa backtest mana-mana strategi perdagangan sebelum anda meneruskan perdagangan sebenar.
/*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)