U.S. Dollar / Japanese Yen
Education
Updated

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

1317
前回、表示させた残高は「決済済みだけの残高」でした。
今回は「未決済(取引中)の損益も含めた残高」を表示させます。

(取引会社によって各社の表現が異なるので難しいのですが、、英語だと「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)
=====
Note
strategy.equity
も用意されています

strategy.initial_capital + strategy.netprofit + strategy.openprofit
Note
次の講座
Pine講座㉙ バックテスト|残高とATRで取引量を算出する

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.