리소스 로딩... 로딩...

계절적 역전 시간 간 거래 전략

저자:차오장
태그:

img

전반적인 설명

전략 원칙

이점 분석

위험 분석

최적화 방향

요약


/*backtest
start: 2023-01-24 00:00:00
end: 2024-01-24 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/
// © EmpiricalFX

//@version=4
strategy("Seasonality Benchmark ","Season",overlay=false,default_qty_type=strategy.percent_of_equity,
     default_qty_value=25,initial_capital=100000,currency="USD",
     commission_type=strategy.commission.percent,commission_value=0.5)
input_entry_direction = input("Long","Position Type",options=["Long","Short"])
input_entry_month = input("Oct","Entry Month",options=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"])
input_exit_month = input("Jan","Entry Month",options=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"])

//Convert three character month string to integer
month_str_to_int(m)=>
    ret = m == "Jan" ? 1 :
          m == "Feb" ? 2 :
          m == "Mar" ? 3 :
          m == "Apr" ? 4 :
          m == "May" ? 5 :
          m == "Jun" ? 6 :
          m == "Jul" ? 7 :
          m == "Aug" ? 8 :
          m == "Sep" ? 9 :
          m == "Oct" ? 10 :
          m == "Nov" ? 11 :
          m == "Dec" ? 12 : -1
          
is_long = input_entry_direction == "Long" ? true : false
entry = month_str_to_int(input_entry_month)
exit = month_str_to_int(input_exit_month)
var balance = strategy.equity

//Entering a position is conditional on:
    //1. No currently active trades
    //2. Input entry month matches current month
if(strategy.opentrades == 0 and entry == month)
    strategy.entry("Swing",is_long)

//Exiting a position is conditional on:
    //1. Must have open trade
    //2. Input exit month matches current month
if(strategy.opentrades > 0 and exit == month)
    strategy.close("Swing")
    
//Update the balance every time a trade is exited
if(change(strategy.closedtrades)>0)
    balance := strategy.equity
    
plot(strategy.equity,"Equity",color.orange)
plot(balance,"Balance",color.red)

    

더 많은