ビットコインとイーサリアムの強気トレンド戦略


作成日: 2023-10-07 10:16:09 最終変更日: 2023-10-07 10:16:09
コピー: 5 クリック数: 704
1
フォロー
1617
フォロワー

概要

この戦略は,ビットコインやイーサリアムなどの暗号通貨に適用される,技術指標に基づく単純な自動多頭トレンド戦略であり,主要な上昇傾向を捕捉し,頻繁に取引がもたらす手数料の損失を減らすことを目的としています.

戦略原則

  1. MACDでトレンドの方向を判断し,MACDは上向きに交差する時に見えます.

  2. 20周期EMA,100周期SMAと200周期SMAを計算し,EMAとSMAは上位に上昇すると見積もります.

  3. EMAがSMAより高いときは買多し,SMAがSMAの慢線より高いときは買多し;

  4. ストップラインを設定し,価格がストップラインを下回るとストップアウトする.

  5. 価格が下がるとEMAを下回ってSMAを突破すると平仓退出.

この戦略は,トレンドと入場タイミングを判断する複数の指標を統合し,主要な上昇傾向を追跡して利益を得ます.

戦略的優位性

  1. 複数の指標の組み合わせで判断し,偽突破などの誤った信号を効果的にフィルターします.

  2. 取引の頻度や必要のない取引を減らすため,トレンドが明確である時にのみ入場する.

  3. ストップ・ロスの戦略は,単一取引の最大損失を効果的に制御します.

  4. また,BTCとEthereumでよりよい収益が得られることを示しています.

  5. 戦略の論理はシンプルでわかりやすく,理解しやすい実装で,初心者向けに適しています.

  6. 拡張性があり,より多くの指標を導入して最適化できます.

戦略リスク

  1. 市場動向がランダムで,誤判の危険が大きい.

  2. システム上のリスクは,単一のポジションで回避できない.

  3. ストップポイントの不適切な設定は,過剰なストップに繋がる可能性があります.

  4. 測量データは実態を反映するものではなく,実態が検証される必要がある.

  5. 取引費用の影響を考慮しない限り,実効は異なる可能性があります.

  6. 種別特性を考慮せずに,調整・最適化が必要である.

戦略最適化の方向性

  1. 異なるパラメータの組み合わせをテストし,指標パラメータを最適化します.

  2. KDJのような指標の入場信号のフィルタリングを追加する.

  3. ストップ・ローズ戦略の最適化,ダイナミック・ストップ・ローズ導入

  4. 口座の資金管理を考慮し,ポジションの大きさを調整する.

  5. 品種の特徴を区分し,パラメータを調整する.

  6. タイムサイクルの指数で判断する.

  7. 異なる品種の効果をテストし,最適な品種を特定する.

要約する

この戦略の全体的な考え方は明確で分かりやすく,多指標判断を使用して誤信号を効果的にフィルタリングできます。しかし,パラメータ,リスク管理などをさらに最適化する必要があり,その後,実盤検証を組み合わせて,実用的に適用できます。さらに最適化を拡張すれば,非常に実用的な暗号通貨トレンド追跡戦略になることができます。

ストラテジーソースコード
/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(title="BTC Long strategy", overlay=true, max_bars_back=3000, initial_capital=1000, commission_value=0.075)

//////////// !!!!!!!!!!!!!!!! WORK BEST IN 2 HOURS for BTC, ETH and ETHXBT !!!!!!!!!!!!!!!!!!! /////////////////////


[macdLine, macdSignalLine, macdHist] = macd(close, 12, 26, 7)  

//_rsi_len = input(14, title="RSI length")
_rsi_len = 14 
 
NewValue = 0
PreviousValue = 0
leverage = 1

smaPercentageIncrease = 0.0
SMA_PERCENT_INCREASE = 0.0
float atrValue = 0
bool bPositionOpened = false
float stockPositionSize = 0 
float volatilityPercentage = 0.0
bool bDisplayArrow = false 
bool bEMAIsRising = false
bool bSMAIsRising = false
bool bSMASlowIsRising = false
bool bMACDIsRising = false
bool bMACDHistIsRising = false
bool bMACDSignalIsRising = false

float stopLoss = input (1.5, "StopLoss in %", type=input.float) //StopLoss associated with the order 
//positionSize = input (1000, "in $")
float positionSize = 1000
float currentPrice = close 
float stopLossPrice = 0
float entryPrice = 0



//-----------------------------------------------------------



// === INPUT BACKTEST RANGE ONE YEAR 
//FromDay   = input(defval = 01, title = "From Day", minval = 1, maxval = 31)
//FromMonth = input(defval = 01, title = "From Month", minval = 1, maxval = 12)
//FromYear  = input(defval = 2020, title = "From Year", minval = 2017)
FromDay   = 01
FromMonth = 01
FromYear  = 2019


//ToDay     = input(defval = 01, title = "To Day", minval = 1, maxval = 31)
//ToMonth   = input(defval = 01, title = "To Month", minval = 1, maxval = 12)
//ToYear    = input(defval = 2023, title = "To Year", minval = 2017)
ToDay     = 31
ToMonth   = 12
ToYear    = 2099

// === FUNCTION EXAMPLE ===
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => true // create function "within window of time"



//emaLength = input(20, "EMA Length")
//smaLength = input(100, "SMA Length")
//smaSlowLength = input(200, "SMA Length") 
emaLength = 20
smaLength = 100
smaSlowLength = 200
 
ema = ema(close, emaLength) 
sma = sma(close, smaLength)
smaSlow = sma(close, smaSlowLength)

plot(sma, color=color.green)
plot(smaSlow, color=color.orange)
plot(ema, color=color.yellow)

//reload previous values
stopLossPrice := na(stopLossPrice[1]) ? 0.0 : stopLossPrice[1]
entryPrice := na(entryPrice[1]) ? 0.0 : entryPrice[1]
bPositionOpened := na(bPositionOpened[1]) ? false : bPositionOpened[1]
positionSize := na(positionSize[1]) ? 50000 : positionSize[1]
stockPositionSize := na(stockPositionSize[1]) ? 0 : stockPositionSize[1]
//leverage := na(leverage[1]) ? 1 : leverage[1]
 
//ReEvaluate the direction of indicators
bEMAIsRising := rising(ema, 2) 
bSMAIsRising := rising(sma, 3)
bMACDIsRising := rising(macdLine, 3)
bMACDHistIsRising := rising(macdHist, 1)
bSMASlowIsRising := rising(smaSlow, 10)
bMACDSignalIsRising := rising(macdSignalLine, 3)

atrValue := atr(14)
volatilityPercentage := (atrValue/currentPrice)*100 //calcute the volatility. Percentage of the actual price


//There is too many signal in tranding market, to avoid this we need to make sure that the smaSlow has a mininal increase
//THIS DOES NOT WORK AT ALL!!!!!
//if bSMASlowIsRising == true
//    //calculate the percentegage difference over the last 10 bars
//    smaPercentageIncrease := ((smaSlow[0]/sma[10])-1)*100
//    if smaPercentageIncrease < SMA_PERCENT_INCREASE
//        //Not enough increase we reset the flag 
//        bSMASlowIsRising := false 
        
 
if (window()) 
    //Check if we can open a LONG
//sma > smaSlow and
    if ( volatilityPercentage < 2 and bPositionOpened == false and bSMASlowIsRising == true and bMACDIsRising == true and bEMAIsRising == true and bSMAIsRising == true and ema[0] > sma[0] and sma[0] < currentPrice)
    // add comparaison between macd and macd signal line
    //if (bPositionOpened == false and macdSignalLine < macdLine and bMACDIsRising == true and bMACDHistIsRising == true and bEMAIsRising == true and bSMAIsRising == true and ema[1] > sma[1] and sma[1] < currentPrice)
   
        //Enter in short position 
        stockPositionSize := (positionSize*leverage)/currentPrice //Calculate the position size based on the actual price and the position Size (in $) configured.
        
        //calculate exit values
        stopLossPrice := currentPrice*(1-stopLoss/100) 
        strategy.entry("myPosition", strategy.long, qty=stockPositionSize, comment="BUY at " + tostring(currentPrice))
        entryPrice := currentPrice //store the entry price
        bPositionOpened := true  
        bDisplayArrow := true 
        
    
    //if (bPositionOpened == true and (currentPrice <= stopLossPrice or crossunder(ema[1], sma[1]) or currentPrice < sma[1]))  
    if (bPositionOpened == true and (currentPrice <= stopLossPrice or crossunder(ema[1], sma[1])))
        strategy.close("myPosition", comment="" + tostring(currentPrice) ) //Stop
        //uncomment the below line to make the bot investing the full portfolio amount to test compounding effect.
        //positionSize := positionSize + ((stockPositionSize * currentPrice) - (positionSize*leverage)) 
        //reset some flags 
        bPositionOpened := false 
        bDisplayArrow := true 
        entryPrice := 0.0