yuya_takahashi_

Pine講座㉚ バックテスト|算出した取引量で売買する

Education
FX:USDJPY   U.S. Dollar / Japanese Yen
前回までに算出した取引量で売買していきます。

といっても、
予め用意された引数に「計算した取引量」
渡してあげるだけなので、何にも難しいことはありません。

更新した箇所のみ、解説を入れます。

=====
//@version=4
strategy( "MovingAvg2Line Cross" ,initial_capital=100000 )

fastLength = input( 9 )
slowLength = input( 18 )

price = close
balance = strategy.initial_capital + strategy.netprofit
accountValue = balance + strategy.openprofit

amount_rate = 0.005
atr = ema( tr ,20 )

//取引量を算出
//今回はここで1000通貨に丸める
amount = round( ( ( balance * 0.005 ) / atr ) / 1000 ) * 1000

mafast = sma( price ,fastLength )
maslow = sma( price ,slowLength )

if ( crossover( mafast ,maslow ) )
//取引量を追加
strategy.entry( "MA2CrossLE" ,strategy.long ,amount ,comment="MA2CrossLE" )

if ( crossunder( mafast, maslow ) )
//取引量を追加
strategy.entry( "MA2CrossSE" ,strategy.short ,amount ,comment="MA2CrossSE" )

plot( balance )
=====


チャート上の売買の箇所に「+9000」「-12000」などの
数字がありますが、これが取引量を表しています。

前回までのバックテストと、取引量が違うことが分かると思います。
(前回までは、一括して「資金量の関係ない取引量」が指定されている)
Comment:
かなり複雑になるので割愛しますが、

time などと組み合わせると、
一定期間ごとの福利(一定期間内は単利)等の検証も出来ます。

次回以降は、他の手法のバックテストに移っていきます!!
Comment:
次の講座

小次郎講師公式インジケーターのお申込
bit.ly/2vdSV4Q

小次郎講師のLINE@
bit.ly/2VZQFu3

小次郎講師のチャート情報局
bit.ly/2GvLAEp
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.