
これは,2つの異なる時間周期の指数移動平均を交差した空白の自動取引戦略である.これは簡単な技術指標を使用し,初心者学習と実践に適しています.
この策略は,2つの指数移動平均を用いており,一つは大時間周期の平均値であり,もう一つは現在の周期の平均値である.現在の周期の平均値が大周期の平均値を通過するときは,多行し,現在の周期の平均値が大周期の平均値を通過するときは,空行する.
具体的には,戦略はまず2つの平均線参数を定義します.
そして2つのEMAをそれぞれ計算します.
取引の論理について:
異なる時間周期の均線の交差によってトレンドの方向を判断し,自動取引を行う.
この戦略の利点は以下の通りです.
この戦略にはいくつかのリスクがあります.
リスクは,ストップ・ロスを設定し,パラメータの組み合わせを最適化したり,他の指標を加えたりすることによって軽減できます.
この戦略は以下の点で最適化できます.
この指数移動平均交差戦略は,シンプルな指標捕捉のトレンドを適用し,初心者の学習の実践に適しています.最適化スペースは広く,より多くの技術指標とモデルを導入して改善し,より強力な効果を持つ量化取引戦略を開発することができます.
/*backtest
start: 2023-09-16 00:00:00
end: 2023-10-16 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("Noro's Singapore Strategy", shorttitle = "Singapore str", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot")
tf = input("D", title = "Big Timeframe")
len = input(3, minval = 1, title = "MA length")
src = input(close, title = "MA Source")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
//MAs
ma1 = request.security(syminfo.tickerid, tf, sma(src, len))
ma2 = sma(src, len)
plot(ma1, linewidth = 2, color = blue, title = "Big TF MA")
plot(ma2, linewidth = 2, color = red, title = "MA")
//Trading
size = strategy.position_size
lot = 0.0
lot := size != size[1] ? strategy.equity / close * capital / 100 : lot[1]
if ma2 > ma1
strategy.entry("L", strategy.long, needlong ? lot : 0, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if ma2 < ma1
strategy.entry("S", strategy.short, needshort ? lot : 0, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if time > timestamp(toyear, tomonth, today, 23, 59)
strategy.close_all()