Last active
October 16, 2019 03:31
-
-
Save bongkook/2701f95ea2de8753f0a4b93d843258d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------ | |
// | |
// バックテスト用ストラテジーファイル | |
// | |
//------------------------------------ | |
//【説明】バックテスト用のPineスクリプトです。 | |
//------------------------------------ | |
//@version=3 | |
//バックテスト時の初期資金などの設定は投資戦略テスターのタブの歯車アイコンから設定することができます。 | |
//パラメーターはヘルプを参照してください。 | |
//バックテストの期間を増やしても終了したトレード数が増えないときはinitial_capital=が十分にあるかを確認してみてください。 | |
//バックテストの結果に出るトレード数は上限が決まっているようで一定数以上のトレードがシュミレーションされない場合があるようです。 | |
//初期資金はinitial_capital=で指定しています。単位は『デフォルト』が通貨ぺアの(建て)の方になります。BitMEXの場合はドルです。 | |
//ETH/BTCのような場合は初期資金の単位はBTCとなります。1注文で資金の100%を投資するような設定です。 | |
//commission_value=0.05で手数料の指定を行っています。お忘れなく! | |
strategy(title = "バックテストストラテジー", initial_capital=10000, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.05, overlay=true) | |
//初期値として2018.2.1 00:01~2018.3.29 00:01がテスト期間に設定されています。 | |
//投資戦略テスターのタブの歯車アイコンから変更することもできます。 | |
SYear = input(2018, "開始: 年") | |
SMonth = input(2, " 月") | |
SDay = input(1, " 日") | |
SHour = input(0, " 時") | |
SMinute = input(1, " 分") | |
StartDATE = timestamp("GMT+9",SYear,SMonth,SDay,SHour,SMinute) | |
EYear = input(2018, "終了: 年") | |
EMonth = input(3, " 月") | |
EDay = input(29, " 日") | |
EHour = input(0, " 時") | |
EMinute = input(1, " 分") | |
EndDATE = timestamp("GMT+9",EYear,EMonth,EDay,EHour,EMinute) | |
BGColor = (time >= StartDATE) and (time <= EndDATE) ? #333333 : na | |
bgcolor(BGColor, transp=96) | |
BackTest() => | |
time >= StartDATE and time <= EndDATE ? true : false | |
//------------------------------------ | |
// | |
//テストしたいストラテジーの宣言文や代入などを下に張り付けていきます。 | |
// | |
//------------------------------------ | |
longCondition = crossover(sma(close, 14), sma(close, 28)) | |
shortCondition = crossunder(sma(close, 14), sma(close, 28)) | |
//------------------------------------ | |
// | |
//注文処理をif BackTest()のifブロックに入れます。 | |
// | |
//------------------------------------ | |
if BackTest() | |
if (longCondition) | |
strategy.entry("My Long Entry Id", strategy.long) | |
if (shortCondition) | |
strategy.entry("My Short Entry Id", strategy.short) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment