感情に基づくXBT先物取引戦略

作者: リン・ハーンチャオチャン, 日付: 2023-12-22 14:48:44
タグ:

img

概要

この戦略は,長期または短期間のXBTUSD先物契約の多サイクルセンチメント分析のアプローチを採用している.異なるサイクルにおける価格変動範囲と最高値と最低値を包括的に考慮し,一連の重量調整を通じて全体的な市場センチメントを計算する. センチメント価値の変化パターンに基づいて購入および販売信号が生成される.

戦略の論理

  1. 最低価格,最高価格,平均価格,価格変動範囲,および a から j (1 から 89 バール) までのサイクルにおける他の指標を計算する.

  2. 価格範囲 (場所変数) の内での閉値の標準化された位置を定義する.異なるサイクルに対するセンチメント値を得るために,各サイクルの価格変動範囲と組み合わせる.

  3. センチメント値は,全体的なセンチメント値 (センチメント) を得るため,一連の重量 (w変数) 調整を経る.センチメントは現在の全体的な市場情勢を反映する.

  4. 感情の変動を分析する. 感情がポジティブからネガティブに変わるとセールシグナルが生成される. 感情がネガティブからポジティブに変わると購入シグナルが生成される.

  5. 入力勢力を決定し,センチメントの変動 (デルタ変数) の絶対値に基づいて利益とストップロスの条件を設定する.

利点

  1. より包括的な市場動向判断をするために,異なるサイクルにおける感情を考慮します.

  2. 重量調整メカニズムは 戦略を安定させる.

  3. センチメント値と変動を組み合わせることで より正確なエントリータイミングです

  4. 最低価格でリスクを管理し 利益を得てストップロスをします

リスク

  1. パラメータの設定が正しくない場合,取引が頻繁すぎたり,機会が逃れることもあります.

  2. ブラック・スワン事件は 戦略の論理を無効化させるかもしれない

  3. 契約の調整やルール変更は戦略の業績に影響を与える可能性があります.

  4. 市場情勢の計算は,歴史的なデータに基づいています.市場体制が変わると再評価が必要です.

リスクは,変動する市場状況に合わせて重量,取引サイクル,利益率などを調整することによって管理できます.一方,ポジションサイズと全体的な露出を厳格に制御することによって資本管理を最適化します.

オプティマイゼーションの方向性

  1. 分析サイクルを拡大して 感情判断の基盤を 強化する

  2. 組み合わせのアプローチのために より多くの技術指標を組み込む.

  3. 機械学習法で感情の特徴を抽出します

  4. 体重を動的に調整する

  5. 利得とストップロスの戦略を最適化します

結論

この戦略は,センチメント分析の取引哲学に基づいている.複数のサイクルを考慮して現在の全体的な市場情勢を決定する.継続的なセンチメントの変化は,タイミングエントリーのための価格変動によって助けられる,取引信号を生成するための基礎として機能する. 市場動向を判断するこのユニークなアプローチは,サイクルの範囲でうまく機能する. 分析期間をさらに拡大し,より多くの指標を追加し,最適化することで,センチメント取引戦略をより成熟し,より複雑な市場環境に適応するために安定することができます.


/*backtest
start: 2022-12-15 00:00:00
end: 2023-12-21 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/
// © Jomy

//@version=4

//2h chart BITMEX:XBTUSD
//use on low leverage 1-2x only

strategy("expected range STRATEGY",overlay=false,initial_capital=1000,precision=2)
leverage=input(1,"leverage",step=.5)
tp=input(53,"take profit %",step=1)
sl=input(7,"stoploss %",step=1)
stoploss=1-(sl/100)
plot(stoploss)
level=input(.70,"level to initiate trade",step=.02)
closelevel=input(0.0,"level to close trade",step=.02)
levelshort=input(.68,"level to initiate trade",step=.02)
closelevelshort=input(0.0,"level to close trade",step=.02)

wa=input(1.158,"weight a",step=.2)
wb=input(1.119,"weight b",step=.2)
wc=input(1.153,"weight c",step=.2)
wd=input(1.272,"weight d",step=.2)
we=input(1.295,"weight e",step=.2)
wf=input(1.523,"weight f",step=.2)
wg=input(1.588,"weight g",step=.2)
wh=input(2.100,"weight h",step=.2)
wi=input(1.816,"weight i",step=.2)
wj=input(2.832,"weight j",step=.2)
a=1
b=2
c=3
d=5
e=8
f=13
g=21
h=34
i=55
j=89

n=0
n:=if volume > -1
    nz(n[1])+1



ra=highest(high,a)-lowest(low,a)
aa=sma(ohlc4,a)
ha=aa[1]+ra[1]/2
la=aa[1]-ra[1]/2

rb=highest(high,b)-lowest(low,b)
ab=sma(ohlc4,b)
hb=ab[1]+rb[1]/2
lb=ab[1]-rb[1]/2

rc=highest(high,c)-lowest(low,c)
ac=sma(ohlc4,c)
hc=ac[1]+rc[1]/2
lc=ac[1]-rc[1]/2

rd=highest(high,d)-lowest(low,d)
ad=sma(ohlc4,d)
hd=ad[1]+rd[1]/2
ld=ad[1]-rd[1]/2

re=highest(high,e)-lowest(low,e)
ae=sma(ohlc4,e)
he=ae[1]+re[1]/2
le=ae[1]-re[1]/2

rf=highest(high,f)-lowest(low,f)
af=sma(ohlc4,f)
hf=af[1]+rf[1]/2
lf=af[1]-rf[1]/2

rg=highest(high,g)-lowest(low,g)
ag=sma(ohlc4,g)
hg=ag[1]+rg[1]/2
lg=ag[1]-rg[1]/2

rh=highest(high,h)-lowest(low,h)
ah=sma(ohlc4,h)
hh=ah[1]+rh[1]/2
lh=ah[1]-rh[1]/2

ri=highest(high,i)-lowest(low,i)
ai=sma(ohlc4,i)
hi=ai[1]+ri[1]/2
li=ai[1]-ri[1]/2

rj=highest(high,j)-lowest(low,j)
aj=sma(ohlc4,j)
hj=aj[1]+rj[1]/2
lj=aj[1]-rj[1]/2

placea=((close-la)/(ha-la)-.5)*-100
placeb=((close-lb)/(hb-lb)-.5)*-100
placec=((close-lc)/(hc-lc)-.5)*-100
placed=((close-ld)/(hd-ld)-.5)*-100
placee=((close-le)/(he-le)-.5)*-100
placef=((close-lf)/(hf-lf)-.5)*-100
placeg=((close-lg)/(hg-lg)-.5)*-100
placeh=((close-lh)/(hh-lh)-.5)*-100
placei=((close-li)/(hi-li)-.5)*-100
placej=((close-lj)/(hj-lj)-.5)*-100

sentiment=((placea/j)*ra*wa+(placeb/i)*rb*wb+(placec/h)*rc*wc+(placed/g)*rd*wd+(placee/f)*re*we+(placef/e)*rf*wf+(placeg/d)*rg*wg+(placeh/c)*rh*wh+(placei/b)*ri*wi+(placej/a)*rj*wj)/(wa+wb+wc+wd+we+wf+wg+wh+wi+wj)

deltalong=0.0
deltalong:=if sentiment>0
    nz(deltalong[1])+sentiment-sentiment[1]
else
    0
deltashort=0.0   
deltashort:=if sentiment<0
    nz(deltashort[1])+((sentiment-sentiment[1])*-1)
else
    0

//plot(sentiment*-1,color=color.blue)    
//plot(deltalong,color=color.red)
//plot(deltashort,color=color.lime)

peakfindlong=highest(deltalong,j)*level


peakfindshort=highest(deltashort,j)*levelshort


contracts=(strategy.equity/close)*leverage


//reason for o is this strategy makes dumb trades before the sentiment line crosses the 0 point the first time
o=0
o:=if cross(0,sentiment) and n>j
    1
else
    nz(o[1])

long=deltashort>peakfindlong and o==1

short=deltalong>peakfindshort and o==1


longstart=0.0
longstart:=if strategy.position_size>0 and strategy.position_size[1]<=0
    close
else
    nz(longstart[1])

shortstart=0.0
shortstart:=if strategy.position_size<0 and strategy.position_size[1]>=0 
    close
else
    nz(shortstart[1])    

highsincelong = 0.0
highsincelong := if strategy.position_size>0
    max(max(highsincelong[1],high),high[1])
else
    0

lowsinceshort = 1000000.0
lowsinceshort := if strategy.position_size<0
    min(min(lowsinceshort[1],low),low[1])
else
    10000000 

closelong=strategy.position_size > 0 and ((highsincelong/longstart-1)*100) > tp
closeshort=strategy.position_size < 0 and ((shortstart/lowsinceshort-1)*100) > tp

stoptrade=0
stoptrade:= if closelong
    1
else
    nz(stoptrade[1])

stoptrade:= if short and stoptrade[1]==1
    0
else
    stoptrade 

stoptrade:= if closeshort 
    -1
else
    stoptrade 
    
stoptrade:= if long and stoptrade[1]==-1
    0
else
    stoptrade     

if(closelong)
    strategy.close("Long1")   

pnllong = ((close - strategy.position_avg_price) / strategy.position_avg_price)*100
pnlshort = ((strategy.position_avg_price-close) / strategy.position_avg_price) *100
plot (strategy.position_size > 0 ?(highsincelong/longstart-1)*100 : 0.0,color=color.lime,linewidth=2)
plot (strategy.position_size < 0 ?(shortstart/lowsinceshort-1)*100 : 0.0,color=color.red,linewidth=2)  
plot( strategy.position_size > 0 ? pnllong:0, color=strategy.position_size > 0 ?color.yellow:color.black,linewidth=2 )
plot( strategy.position_size < 0 ? pnlshort:0, color=strategy.position_size < 0 ?color.orange:color.black,linewidth=2)
longuntilshort=0
longuntilshort:=if long
    1
else
    if short
        -1
    else
        nz(longuntilshort[1]) 
bgcolor(stoptrade!=0?color.black:longuntilshort==1?color.lime:longuntilshort==-1?color.red:na,transp=70)   

if(long and stoptrade==0)
    strategy.entry("Long1",strategy.long,qty=max(1,min(contracts,1000000000)))

if(closelong)
    strategy.close("Long1")
    
strategy.exit("Long1",stop=longstart * stoploss,when = strategy.position_size>0)

if(short and stoptrade==0)    
    strategy.entry("Short1",strategy.short,max(1,min(contracts,1000000000)))

if(closeshort)
    strategy.close("Short1")

strategy.exit("Long1",stop=shortstart / stoploss,when = strategy.position_size<0)

もっと