yuya_takahashi_

Pine講座㉘ バックテスト|未決済を含めた残高を時系列で表示する

Education
FX:USDJPY   U.S. Dollar / Japanese Yen
前回、表示させた残高は「決済済みだけの残高」でした。
今回は「未決済(取引中)の損益も含めた残高」を表示させます。

(取引会社によって各社の表現が異なるので難しいのですが、、英語だと「account value」とされる項目です)

TradingViewでは、この資金量に応じて取引量を調整するようなロジックを組むこともできます。

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

fastLength = input( 9 )
slowLength = input( 18 )
price = close
balance = strategy.initial_capital + strategy.netprofit

// ここで未決済を含む残高を算出
accountValue = balance + strategy.openprofit

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 )

// 描画する
plot( accountValue ,color=color.red)
=====
Comment:
strategy.equity
も用意されています

strategy.initial_capital + strategy.netprofit + strategy.openprofit
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.