モメンタムブリック戦略


作成日: 2024-02-19 15:32:17 最終変更日: 2024-02-19 15:32:17
コピー: 1 クリック数: 355
1
フォロー
1234
フォロワー

モメンタムブリック戦略

この戦略は,の形成を模擬して市場の動力の変化を判断し,の方向に応じて空調を多めにします.

戦略原則

この戦略の核心原則は,ATRと閉店価格の関係を計算しての形成を模擬することである.具体的には,2つの変数Brick1とBrick2を定義する.

Brick1の計算方法は,閉店価格がBrick1の昨日値+ATRの値を超えた場合,Brick1はBrick1の昨日値+ATRとなる.閉店価格がBrick1の昨日値-ATRの値を下回った場合,Brick1はBrick1の昨日値-ATRとなる.そうでなければBrick1はBrick1の昨日値を受け継ぐ.

Brick2の計算方法は,Brick1の値がBrick1の昨日値と等しくない場合,Brick2はBrick1の昨日値である.そうでなければBrick2の昨日値を継承する.

このようにしての形成を模倣する.Brick1が上昇すると,ATRが1つを超えると,上向きのが形成され,Brick1が下向きのが形成され,ATRが1つを超えると,下向きのが形成される.Brick2は,の位置を記録する.

Brick1とBrick2が上向きに交差すると,が上向きに拡大し,多頭部と判断される.Brick1とBrick2が下向きに交差すると,が下向きに収縮し,空頭部と判断される.

戦略的優位性

  1. ATRはの形成を判断し,固定サイズのを使うことを避け,市場の変動に動的に適応します.
  2. の交差によって多空方向を判断し,動力の変化を識別する
  3. 市場動向の判断に対する感受性を異なるATRサイクルで調整できます.
  4. 市場動向を直感的に判断する可視化された形成と交差

戦略リスク

  1. ATRの大きさの選択は,戦略の収益率に影響する.ATRが小さすぎると,が多く形成され,無効信号が多く発生する.ATRが大きすぎると,が少なくなり,機会が逃れやすい.
  2. 実際のトレンドはの形に従わないかもしれないし,の交差信号は市場逆転によって拒否されるかもしれない.
  3. 取引コストに非常に敏感である必要があります. そうでなければ,クロスクロスの頻繁な取引は,純利益を大幅に減少させるでしょう.

パラメタルの最適化により最適なATR周期を見つけることができる.無効信号による損失を減らすためにストップ・ストップ・ストラトジーを調整し,コストが利益に影響を減らすために取引品種を適切に拡大する.

戦略の最適化

  1. 量子能指数,振動指数など,他の指標と組み合わせて信号フィルタリングを行うことができる,無効信号を避ける
  2. トレンドフィルターを追加し,トレンドの方向にのみ信号を発信し,反転損失を回避します.
  3. テスト期間中の全サンプルパラメータ最適化方法を使用して,自動的に最適パラメータを探します.

要約する

この戦略は,ダイナミックな模擬の交差によって,市場における短期的な傾向と動力を判断し,形状を直観的に可視化する.戦略の最適化スペースは大きく,パラメータ最適化と信号フィルタリングは,さらに安定性を向上させることができる.

ストラテジーソースコード
/*backtest
start: 2023-02-12 00:00:00
end: 2024-02-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4


///Component Code Start
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)

testStopYear = input(2025, "Backtest Stop Year")
testStopMonth = input(1, "Backtest Stop Month")
testStopDay = input(1, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)



/// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=input.bool, defval=false)
testPeriodBackgroundColor = testPeriodBackground and time >= testPeriodStart and time <= testPeriodStop ? 
   #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() => true
/// Component Code Stop


//Zack_the_Lego (original AUTHOR) made into strategy by mkonsap
strategy("Flex Renko Emulator", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
margin = input(true, title="Margin?")
Margin = margin ? margin : false
res = input(type=input.resolution, defval="D", title="Resolution of ATR")
xATR = atr(14)
//TF = x78tf ? "78" : "39"
BrickSize = security(syminfo.tickerid, res, xATR)

//Brick1 =  close >  nz(Brick1[1]) + BrickSize ? nz(Brick1[1]) + BrickSize : close <
                    //nz(Brick1[1]) - BrickSize ?
                        //nz(Brick1[1]) - BrickSize
                            //: nz(Brick1[1]))


Brick1() =>
    s1 = 0.0
    s1 := close > nz(s1[1]) + BrickSize ? nz(s1[1]) + BrickSize : 
       close < nz(s1[1]) - BrickSize ? nz(s1[1]) - BrickSize : nz(s1[1])
    s1


Brick2() =>
    s2 = 0.0
    Brick1_1 = Brick1()
    s2 := Brick1() != Brick1()[1] ? Brick1_1[1] : nz(s2[1])
    s2

colorer = Brick1() > Brick2() ? color.green : color.red
p1 = plot(Brick1(), color=colorer, linewidth=4, title="Renko")
p2 = plot(Brick2(), color=colorer, linewidth=4, title="Renko")
fill(p1, p2, color=color.purple, transp=50)




mylong = crossover(Brick1(), Brick2())
myshort = crossunder(Brick1(), Brick2())

last_long = float(na)
last_short = float(na)
last_long := mylong ? time : nz(last_long[1])
last_short := myshort ? time : nz(last_short[1])

in_long = last_long > last_short ? 2 : 0
in_short = last_short > last_long ? 2 : 0

mylong2 = crossover(Brick1(), Brick2())
myshort2 = crossunder(Brick1(), Brick2())

last_long2 = float(na)
last_short2 = float(na)
last_long2 := mylong2 ? time : nz(last_long2[1])
last_short2 := myshort2 ? time : nz(last_short2[1])

in_long2 = last_long2 > last_short2 ? 0 : 0
in_short2 = last_short2 > last_long2 ? 0 : 0


condlongx = in_long + in_long2
condlong = crossover(condlongx, 1.9)
condlongclose = crossunder(condlongx, 1.9)

condshortx = in_short + in_short2
condshort = crossover(condshortx, 1.9)
condshortclose = crossunder(condshortx, 1.9)


// === STRATEGY - LONG POSITION EXECUTION WITH CLOSE ORDERS ===
//enterLong() => crossover(condlongx, 1.9) and testPeriod() and strategy.position_size <= 0
//exitLong()  => crossunder(condlongx, 1.9) and testPeriod() and strategy.position_size > 0
//strategy.entry(id = "Long", long = true, when = enterLong())
//strategy.close(id = "Long", when = exitLong())
// === STRATEGY - SHORT POSITION EXECUTION WITH CLOSE ORDER===
//enterShort() => crossover(condshortx, 1.9) and testPeriod() and strategy.position_size >= 0 and Margin
//exitShort() => crossunder(condshortx, 1.9)  and testPeriod() and strategy.position_size < 0
//strategy.entry(id = "Short", long = false, when = enterShort())
//strategy.close(id = "Short", when = exitShort())   
//END


///STRATEGY ONLY LONG AND SHORT/////
if crossover(condlongx, 1.9) and testPeriod() and strategy.position_size <= 0
    strategy.entry("Long", strategy.long, comment="Long")

if crossover(condshortx, 1.9) and testPeriod() and strategy.position_size >= 0
    strategy.close("Long", when=not Margin)

if crossover(condshortx, 1.9) and testPeriod() and strategy.position_size >= 0
    strategy.entry("Short", strategy.short, comment="Short", when=Margin)

/////// END ////