Search
Products
Community
Markets
News
Brokers
More
IN
Get started
U.S. Dollar / Japanese Yen
Education
Updated
Aug 1, 2019
Pine講座㉙ バックテスト|残高とATRで取引量を算出する
2
5
Grab this chart
Grab this chart
2
2
Jul 24, 2019
前回までに取得した「残高」から
取引量を算出するコードです。
残高とATRをもとに取引量を調整していきます。
小次郎講師やタートルズの資金管理ですね。
次回は、この取引量をもとに売買します。
追加した箇所を解説してます。
=====
//
version
=4
//initial_capitalで元金を指定
strategy( "MovingAvg2Line Cross" ,initial_capital=100000 )
fastLength = input( 9 )
slowLength = input( 18 )
price = close
balance = strategy.initial_capital + strategy.netprofit
//投資金の0.5%をトレードに充てる
amount_rate = 0.005
//ATRを算出
atr = ema( tr ,20 )
//ATRと残高をもとに取引量を算出
amount = ( balance * 0.005 ) / atr
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" )
//1000通貨単位に丸めて描画
plot( round( amount / 1000 ) * 1000 )
=====
Aug 1, 2019
Note
次の講座
yuya_takahashi_
Follow
小次郎講師公式インジケーターのお申込
bit.ly/2vdSV4Q
小次郎講師のLINE@
bit.ly/2VZQFu3
小次郎講師のチャート情報局
bit.ly/2GvLAEp
Also on:
Beyond Technical Analysis
pinescript
yuya_takahashi_
Follow
小次郎講師公式インジケーターのお申込
bit.ly/2vdSV4Q
小次郎講師のLINE@
bit.ly/2VZQFu3
小次郎講師のチャート情報局
bit.ly/2GvLAEp
Also on:
Related publications
Pine講座⑲ 2行でlabelを表示する
by yuya_takahashi_
Pine講座⑳ labelでインフォパネルを表示する
by yuya_takahashi_
Pine講座㉑ ラインを表示する
by yuya_takahashi_
Pine講座㉒ ラインとラベルを組み合わせる
by yuya_takahashi_
Pine講座㉓ 終値から ±2-ATR にラインを描画する
by yuya_takahashi_
Pine講座㉔ 取引量を算出してインフォパネルに表示する
by yuya_takahashi_
Pine講座㉕ TradingViewでバックテストをする
by yuya_takahashi_
Pine講座㉖ バックテスト|2本のSMAで途転
by yuya_takahashi_
Pine講座㉗ バックテスト|残高の推移を時系列で表示する
by yuya_takahashi_
Pine講座㉘ バックテスト|未決済を含めた残高を時系列で表示する
by yuya_takahashi_
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
.