ストラテジー

input #

Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function automatically detects the type of the argument used for ‘defval’ and uses the corresponding input widget.

input(defval, title, tooltip, inline, group)  input bool
input(defval, title, tooltip, inline, group)  input color
input(defval, title, tooltip, inline, group)  input int
input(defval, title, tooltip, inline, group)  input float
input(defval, title, tooltip, inline, group)  input string
input(defval, title, inline, group, tooltip)  series float
戻り値 #

input変数の値。

引数 #
defval (const int/float/bool/string/color or source-type built-ins)Determines the default value of the input variable proposed in the script’s “Settings/Inputs” tab, from where script users can change it. Source-type built-ins are built-in series float variables that specify the source of the calculation: close, hlc3, etc.
title (const string)入力項目のタイトルです。指定されていない場合には、変数名が入力のタイトルとして使用されます。タイトルが指定されている場合でもそれが空の場合には、名前は空の文字列になります。
tooltip (const string)ツールチップアイコンにカーソルを合わせた時にユーザーに表示される文字列です。
inline (const string)同じ引数を使ったすべてのinputの呼び出しを1行にまとめます。引数として使われる文字列は表示されません。これは、同じ行に属する入力項目を識別するためにのみ使用されます。
group (const string)同じグループ引数の文字列を使用するすべての入力項目の上にヘッダーを作成します。この文字列は、ヘッダーのテキストとしても使用されます。
#
i_switch = input(true, "On/Off")
plot(i_switch ? open : na)

i_len = input(7, "Length")
i_src = input(close, "Source")
plot(ta.sma(i_src, i_len))

i_border = input(142.50, "Price Border")
hline(i_border)
bgcolor(close > i_border ? color.green : color.red)

i_col = input(color.red, "Plot Color")
plot(close, color=i_col)

i_text = input("Hello!", "Message")
l = label.new(bar_index, high, text=i_text)
label.delete(l[1])
備考 #

input 関数の戻りは、常に変数に割り当てられる必要があります。上記の例をご覧ください。

関連 #

input.bool, input.color, input.int, input.float, input.string, input.symbol, input.timeframe, input.session, input.source, input.time

strategy #

この関数はいくつかのストラテジーのプロパティを設定します。

strategy(title, shorttitle, overlay, format, precision, scale, pyramiding, calc_on_order_fills, calc_on_every_tick, max_bars_back, backtest_fill_limits_assumption, default_qty_type, default_qty_value, initial_capital, currency, slippage, commission_type, commission_value, process_orders_on_close, close_entries_rule, margin_long, margin_short, explicit_plot_zorder, max_lines_count, max_labels_count, max_boxes_count)  void
引数 #
title (const string)indicator title that would be seen in Indicators/Strategies widget. Argument IS REQUIRED.
shorttitle (const string)indicator short title that would be seen in the chart legend. Argument is optional.
overlay (const bool)if true the indicator will be added as an overlay for the main series. If false - it would be added on a separate chart pane. Default is false.
format (const string)type of formatting indicator values on the price axis. Possible values are: format.inherit, format.price, format.volume. Default is format.inherit.
precision (const int)number of digits after the floating point for indicator values on the price axis. Must be a non negative integer and not greater than 16. If omitted, using formatting from parent series. If format is format.inherit and this argument is set, then format becomes format.price.
scale (scale_type)インジケーターが割り当てられる価格スケール。可能な値は scale.right, scale.left, scale.none です。値 scale.none は、‘overlay = true’ の設定との組み合わせでのみ適用できます。省略された場合は、メインスケールが使用されます。
pyramiding (const int)同じ方向に許可されるエントリーの最大数。値が0の場合、同じ方向のエントリーオーダーを1つだけ開くことができ、以降のエントリー注文は拒否されます。デフォルト値は0です。
calc_on_order_fills (const bool)バー内での注文の計算を1回追加します。このパラメータが ‘true’ に設定されている場合、ストラテジーは注文が約定した後に(バーの終値でだけでなく)バー内でもう一度再計算されます。デフォルト値は ‘false’ です。
calc_on_every_tick (const bool)イントラバー(バー内)のストラテジーの追加計算。パラメータが ‘true’ の場合、ストラテジーは、バーの終値ではなく、リアルタイムで毎ティック計算を行います。このパラメータは、ヒストリカルデータでのストラテジーの計算には影響を与えません。デフォルト値は ‘false’ です。
max_bars_back (const int)strategyで履歴参照に利用可能なバーの最大数。スクリプトのコードで変数の過去データへの参照(‘[]’演算子を使用)がある場合には、このパラメーターはスクリプト内のすべてのビルトインまたはユーザー変数に適用されます。Pineスクリプトの可変バッファサイズは一般的に自動検出されます。しかし特定のケースでは自動検出を行うことができない為、ユーザーはこの値の下限を手動で設定することができます。注記: このパラメーターの代わりに、ひとつの変数にのみ適用される max_bars_back 関数の使用が最適です。
backtest_fill_limits_assumption (const int)指値注文実行の想定。指値注文は、市場価格が指値注文の水準を指定されたティック数だけ超える場合にのみイントラバーで約定されます。
default_qty_type (const string)‘qty’ = ‘NaN’の場合は、契約数/株数/ロット数/ユニット数を決定するパラメーター。利用できる値は、strategy.fixed (デフォルトでは固定数量)、strategy.cash (シンボルの通貨で指定し、その金額を数量に変換)、strategy.percent_of_equity (現在利用可能な資金の%) です。
default_qty_value (const int/float)Number of contracts/shares/lots/units if ‘default_qty_type’ = strategy.fixed が使用されている場合は、契約数/株数/ロット数/ユニット数、‘default_qty_type’ = strategy.cash が使用されている場合は、シンボルの通貨での金額、‘default_qty_type’ = strategy.percent_of_equity が使用されている場合は、現在利用可能な資金のパーセンテージです。
currency (const string)このストラテジーの口座通貨です。オプション引数です。デフォルトは、チャート上のシンボルが取引される通貨です。設定可能な値は currency.NONE, currency.USD, currency.EUR, currency.AUD, currency.GBP, currency.NZD, currency.CAD, currency.CHF, currency.HKD, currency.JPY, currency.NOK, currency.SEK, currency.SGD, currency.TRY, currency.ZAR です。
slippage (const int)市場の売買価格やストップ注文の約定価格に加算/減算されるティック単位のスリッページです。mintick=0.01 で slippage=5 の場合、スリッページの合計は、5*0.01=0.05 になります。
commission_type (const string)注文の手数料タイプ。利用できる値は以下の3つです: strategy.commission.percent (注文金額のパーセンテージ)、strategy.commission.cash_per_contract (取引毎に口座通貨の一定額)、strategy.commission.cash_per_order (注文毎に口座通貨の一定額)
commission_value (const int/float)注文の手数料値。選択されたタイプ(commission_type)に応じてパーセントまたは金額が含まれる。
process_orders_on_close (const bool)true に設定すると、バーがクローズしてストラテジーの計算が完了した後に、追加で注文の試行が行われます。注文が成行注文の場合には、ブローカエミュレーターは次のバーの始値の前にその注文を実行します。注文が価格条件付きの場合には、注文は価格条件が合致する場合のみ約定されます。このオプションは現在のバーでポジションを閉じたい場合に便利です。デフォルト値は ‘false’ です。
close_entries_rule (const string)注文がクローズされる順序を決定します。許可される値は: ‘FIFO’ または ‘ANY’ です。FIFO (First-In, First-Out) では、複数のトレードがオープンしている時には最も早いトレードが最初に閉じられます。このルールは、株式、先物、米国のFX (NFAコンプライアンスルール 2-43b) に適用されます。‘ANY’ はトレードが任意の順序で閉じられる可能性を意味します(これは米国以外のFXで許可されています)。デフォルト値は ‘FIFO’ です。
max_lines_count (const int)表示される直近のライン描画の数。デフォルト値は50で、許可される最大値は500です。
max_labels_count (const int)表示される直近のラベル描画の数。デフォルト値は50で、許可される最大値は500です。
max_boxes_count (const int)表示する直近のボックス描画の数。デフォルト値は50で、最大許容値は500です。
margin_long (const int/float)Margin long is the percentage of the purchase price of a security that must be covered by cash or collateral for long positions. Must be a non-negative number. Optional. The default is 100.
margin_short (const int/float)Margin short is the percentage of the purchase price of a security that must be covered by cash or collateral for short positions. Must be a non-negative number. Optional. The default is 100.
explicit_plot_zorder (const bool)インジケーターのプロット、塗りつぶし、水平線のレンダリング順を指定します。trueの場合、プロットはインジケータのコード上の順序に基づいて描画され、新しいプロットは前のプロットの上に描画されます。これは plot*() 関数、fill、hline にのみ適用されます。オプション引数。デフォルトは faLse です。
initial_capital (const int/float)ストラテジーの取引に利用可能な currency で定義された通貨での初期資金です。オプション引数で、デフォルトは 100000 です。
#
strategy(title='MyStrategy')
strategy(title="MyStrategy", shorttitle="MS", pyramiding = 10)
備考 #

全てのストラテジースクリプト毎に strategy を呼び出す必要があります。
引数 calc_on_every_tick = true を使用するPineScriptコードは、ヒストリカルデータとリアルタイムデータで計算方法が異なります。
標準外のチャートタイプを戦略のベースに使用した場合は、成績が変わってしまいます。注文がそのチャートの価格で実行されるからです。(例えば、平均足のチャートでは平均足の価格(平均価格)で実行され、実際のマーケット価格では実行されません。) 従い、戦略を作成する場合は標準のチャートを使用することを強くお勧めします。

© - 2021 - TradingViewの教科書