
この戦略は,高速と遅い動きの均線の金叉死叉原理に基づいて設計されている. 速い均線が,下から遅い均線を穿越するとき,多行し,速い均線が,上から下から遅い均線を穿越するとき,空行する. この戦略は,中長線取引に適用され,市場のトレンドの逆転を捉えることができる.
この戦略は,指数関数移動平均 ((EMA) を用いて快速平均線を計算する.快速平均線の長さは10周期で,慢速平均線の長さは30周期である.戦略は,まず,快速EMAと慢速EMAを計算し,それから平均線を描画し,異なる色の背景を表示し,平均線のトレンド方向を示す.
今日の閉盘価格が急速平均線より高く,そして急速平均線が遅い平均線より高いときは,緑の背景が表示され,上昇傾向にあることを示します.今日の閉盘価格が急速平均線より低く,そして急速平均線が遅い平均線より低いときは,赤の背景が表示され,下降傾向にあることを示します.
上昇傾向では,赤K線が現れれば (閉盘価格が開盤価格より低い),そして昨日も赤K線であった場合,多額入場する. ストップ・ロスを300点設定し,ストップ・ストップを平仓に空にする.
ダウントレンドでは,緑のK線 (閉盘価格が開盘価格より高) が現れ,昨日も緑のK線であった場合,空白入場を行う. ストップ・ローズを300点設定し,ストップ・ストップを平仓に多めに行う.
各取引方向にポジションを開設した後,1008000000ミリ秒を超えるポジションを保有した場合,強制的に平仓を設け,死を防止する.
この戦略は,全体的に比較的に均衡しており,双EMAのトレンド識別を使用し,K線実体配合の追加ルールと組み合わせて取引を行うことで,偽信号を効果的にフィルターできます.しかし,EMAシステムとパラメータの設定は依然として最適化する必要があり,止損ストップメカニズムも市場に応じて調整する必要があり,全体的に信頼性の高いトレンド取引戦略です.
/*backtest
start: 2023-10-10 00:00:00
end: 2023-11-09 00:00:00
period: 1h
basePeriod: 15m
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/
// © yeainshukla
//@version=5
strategy('BuyRedSellGreen4H', overlay = true)
greenCandle = close > open
redCandle = open > close
start = timestamp(2023,9,18,0,00)
end = timestamp(2023,12,31,0,00)
fastLength = input.int(10, title="Fast Average Length")
slowLength = input.int(30, title="Slow Average Length")
averageData = input.source(close, title="Average Data Source")
// Calculate exponential moving averages
fastAverage = ta.ema(averageData, fastLength)
slowAverage = ta.ema(averageData, slowLength)
// Plot averages
plot(fastAverage, color=color.navy, title="Fast EMA")
plot(slowAverage, color=color.fuchsia, linewidth=2, title="Slow EMA")
// Show the moving average trend with a coloured background
backgroundColor = if close > fastAverage and fastAverage > slowAverage
color.new(color.green, 85)
else if close < fastAverage and fastAverage < slowAverage
color.new(color.red, 85)
else
color.new(color.orange, 90)
bgcolor(backgroundColor, title="EMA Background")
if time >= start and time < end
if(close < open)
if(close[1] < open[1])
strategy.entry("Enter Long", strategy.long)
strategy.exit("Exit Long", from_entry="Enter Long")
strategy.close("Enter Short")
else
if(close[1] > open[1])
strategy.entry("Enter Short", strategy.short)
strategy.exit("Exit Short", from_entry="Enter Short")
strategy.close("Enter Long")
if strategy.position_size < 0 or strategy.position_size > 0// short and long is opened.
if((time - strategy.opentrades.entry_time(strategy.opentrades - 1)) > 1008000000)
strategy.close("Enter Short")
strategy.close("Enter Long")