yuya_takahashi_

Pine講座㉗ バックテスト|残高の推移を時系列で表示する

Education
FX:USDJPY   U.S. Dollar / Japanese Yen
「ストラテジーテスター>概要」のグラフの横軸は、「取引回数」がデフォルトです。

概要を把握するにはまったく問題ありませんが、ときにチャートと照らし合わせて時系列で確認したいケースがあります。

今回の方法を使うと、オシレーターの窓に「残高の推移」を表示することができますので、
・どの売買で
・どれくらいの資金の増減
みたいなことが、
簡単に確認できるようになります。

前回のコードに追記しているので、
追記部分のみ解説を加えたいと思います。

=====
//@version=4
strategy( "MovingAvg2Line Cross" )

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

// 残高の計算(スタート時の資金 + 累計損益)
// strategy.initial_capital → スタート時の資金
// strategy.netprofit → 累計損益
balance = strategy.initial_capital + strategy.netprofit

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

if ( crossover( mafast ,maslow ) )
strategy.entry( "MA2CrossLE" ,strategy.long ,comment="MA2CrossLE" )

if ( crossunder( mafast, maslow ) )
strategy.entry( "MA2CrossSE" ,strategy.short ,comment="MA2CrossSE" )

// スタート時の資金を描画
plot( strategy.initial_capital )

// 残高の描画
plot( balance )
=====
Comment:
次の講座

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

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

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

Related Ideas

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.