
この戦略は,単純移動平均 ((SMA)) に基づくBankNifty期貨取引戦略である.戦略の主な構想は,SMAをトレンド指標として利用し,価格がSMAを突破するときに多し,価格がSMAを突破するときに空しである.同時に,この戦略は,リスクを制御し,利益をロックするために,停止と停止条件を設定している.
この戦略の核心は,SMAをトレンド指標として使用することである.具体的には,戦略は,まず指定された周期のSMAを計算し,その後,価格とSMAの相対的な位置に基づいてトレンドの方向を判断する.価格がSMAを突破すると,上昇傾向が形成されていると考え,この時点で多;価格がSMAを突破すると,下降傾向が形成されていると考え,この時点で空する.さらに,この戦略は,リスクを制御し,利益をロックするために,ストップ・ロスト・条件を設定する.ストップ・ロスト条件は,価格がSMAの一定範囲を突破する (“Stop Loss Buffer”パラメータで設定する),価格がポジション開設価格の一定範囲を突破する (“Stop Loss”パラメータで設定する),および取引時間が15:00に達する (“Target Price”パラメータで設定する).
この戦略は,SMAベースのシンプルな取引戦略で,BankNifty期貨に適用されます.その優点は,原理がシンプルで,適応力が強く,リスク管理策が設けられていることです.しかし,実際のアプリケーションでは,パラメータ最適化,震動市場,トレンド逆転およびポケット内の波動などの潜在的なリスクにも注意する必要があります.将来的には,パラメータ最適化,他の指標,ダイナミックストップ損失および取引制限時間などの面で戦略の最適化および改善を検討することができます.
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Bhasker_S
//@version=5
strategy("Strategy BankNifty SMA", overlay=true, margin_long=100, margin_short=100)
src = input(close, title="Source")
timeFrame = input.timeframe(defval='5', title = "Select Chart Timeframe")
typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
len = input.int(200, minval=1, title="Length", step = 10)
alertPrecision = input.float(0, "Alert Precision", minval = 0, maxval = 50, step=1)
slTimeFrame = input.timeframe(defval='1', title = "Select Stoploss Candle Timeframe")
slBuffer = input.float(0, "Stop Loss Buffer", minval = 0, maxval = 50, step = 1)
targetSlab = input.float(150, "Target Price", minval = 1, maxval = 2000, step = 10)
Stoploss = input.float(20, "Stop Loss", minval = 1, maxval = 2000, step = 5)
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
//out = ta.sma(src, len)
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
tfSource = request.security(syminfo.tickerid, timeFrame, src, barmerge.gaps_on, barmerge.lookahead_off)
mySMA = ma(tfSource, len, typeMA)
plot(mySMA, color=color.rgb(243, 33, 89), title="MA", offset=offset, linewidth = 2)
slClose = request.security(syminfo.tickerid, slTimeFrame, src, barmerge.gaps_on, barmerge.lookahead_off)
highTravel = low > mySMA
lowTravel = high < mySMA
touchabove = (((high[1] + alertPrecision) > mySMA[1]) and (low[1] < mySMA[1])) //and (high[2] < mySMA[2])
touchbelow = (((low[1] - alertPrecision) < mySMA[1]) and (high[1] > mySMA[1])) //and (low[2] > mySMA[2])
crossabove = math.min(open, close) > mySMA
crossbelow = math.max(open, close) < mySMA
upalert = (touchabove or touchbelow) and crossabove
downalert = (touchabove or touchbelow) and crossbelow
h=hour(time('1'),"Asia/Kolkata")
m=minute(time('1'),"Asia/Kolkata")
startTime=h*100+m
if upalert and strategy.position_size == 0
strategy.entry("buy", strategy.long, 15)
if downalert and strategy.position_size == 0
strategy.entry("sell", strategy.short, 15)
longexit = (slClose < (mySMA - slBuffer)) or (slClose < (strategy.opentrades.entry_price(strategy.opentrades - 1) - Stoploss)) or (slClose > (strategy.opentrades.entry_price(strategy.opentrades - 1) + targetSlab)) or (hour(time) == 15)
shortexit = (slClose > (mySMA + slBuffer)) or (slClose > (strategy.opentrades.entry_price(strategy.opentrades - 1) + Stoploss)) or (slClose < (strategy.opentrades.entry_price(strategy.opentrades - 1) - targetSlab)) or (hour(time) == 15)
if longexit
strategy.close("buy")
if shortexit
strategy.close("sell")