BinaryOptionテストテンプレート
はじめに
バイオプと通常のFXとは全く異なるため、通常TradingViewではバイオプロジックの検証ができません。
ですが、指定した期間で強制決済した結果を集計することで、バイオプとしてのロジックを検証することができます。
今回は、テンプレートを見つけましたので確認していきます。
https://jp.tradingview.com/script/pvnR5RYJ-Binary-Options-Strategy-Template/
解説
以下は終値が単純移動平均より上ならBUY、下ならSELLという単純なロジックだけでバイオプをした場合の検証です。
これを実際のロジックに置き換えて作る必要があります。
その前提で、このスクリプトを見ていきましょう。
//@version=4
strategy("Binary Options Strategy Template", overlay=true)
// In this code we track the bar where a position was opened and close the position
// aftera specified number of bars. The objective of this script is testing long/short signals
// for knowing the amount of times it would turn a profit or not.
// User input for amount of bars till close
barsTillClose = input(5, minval=2, title="Amount of Bars Till Close Position")
// SIMPLE ENTRY LOGIC (insert long/short signal here)
sma = sma(close, 14)
strategy.entry("Long", strategy.long, when=close > sma)
strategy.entry("Short", strategy.long, when=close < sma)
// Track the Entry Bar
entryTime = float(na)
timeClose = bool(na)
entryTime := timeClose[1] ? na : strategy.position_size[0] > strategy.position_size[1] ? bar_index : entryTime[1]
// See if we need to close
timeClose := bar_index >= entryTime+(barsTillClose-2)
strategy.close("Long", when=timeClose)
strategy.close("Short", when=timeClose)
plot(sma)
エントリーロジック
単純な終値が単純移動平均線を超えるかどうかだけのロジックでエントリーを決めている。
// SIMPLE ENTRY LOGIC (insert long/short signal here)
sma = sma(close, 14)
strategy.entry("Long", strategy.long, when=close > sma)
strategy.entry("Short", strategy.long, when=close < sma)
sma: 単純移動平均線- strategy.entry
:
- 構文:
strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when, alert_message) → void id(series[string]): 注文の識別子。識別子を指定する事で注文の変更やキャンセルが可能long (bool): 市場ポジションの方向:strategy.longはロング。strategy.shortはショートwhen (bool): 注文の条件。条件がtrueの場合注文が発注される。条件がfalseの場合には何も起こらない
以前発注された同じIDの注文はキャンセルされない。
デフォルト値はtrue。
- 構文:
トラッキング
// Track the Entry Bar
entryTime = float(na)
timeClose = bool(na)
entryTime := timeClose[1] ? na : strategy.position_size[0] > strategy.position_size[1] ? bar_index : entryTime[1]
// See if we need to close
timeClose := bar_index >= entryTime+(barsTillClose-2)
- strategy.position_size
:
- 現在の市場ポジションの方向とサイズ。値が0より大きい場合、市場ポジションは買い。値が0より少ない場合、市場ポジションは売り。
entryTime := timeClose[1] ? na : strategy.position_size[0] > strategy.position_size[1] ? bar_index : entryTime[1]- 1つ過去のバーでクローズしていれば
na - エントリーした場合は
bar_index - それ以外は過去の値を継続
- 1つ過去のバーでクローズしていれば
timeClose := bar_index >= entryTime+(barsTillClose-2)- 現在の
bar_indexがエントリーした時のbar_indexにbarsTillCloseを足して2で引いた値以上の場合に決済
- 現在の
決済ロジック
バイオプの指定期間以上になったら決済する。
strategy.close("Long", when=timeClose)
strategy.close("Short", when=timeClose)
- bar_index
:
- type: series[integer]
- 現在のバーのインデックス。ナンバリングは0から始まり、最初のバーのインデックスは0
- strategy.close
:
- 構文:
strategy.close(id, when, comment, qty, qty_percent, alert_message) → void
- 構文:
BinaryOption用インジケーター
はじめに TradingViewでBinaryOption用のインジケーターを研究中です。 今回は以下のインジケーターを見てみます。 https://jp.tradingview.com/script/s48QJlfi-Vdub-Binary-Options-SniperVX-v1/ PineScript //@version=4 study("Vdub Binary Options SniperVX v1", overlay=true, shorttitle="Vdub_SniperBX_v1") // //====================channel====================== len = input(8, minval=1) src = input(close, title="Source") out = sma(src, len) last8h = highest(close, 13) lastl8 = lowest(close, 13) bearish = cross(close,out) == 1 and close[1] > close bullish = cross(close,out) == 1 and close[1] < close channel2=input(false, title="Bar Channel On/Off") ul2=plot(channel2?last8h:last8h==nz(last8h[1])?last8h:na, color=color.black, linewidth=1, style=plot.style_linebr, title="Candle body resistance level top", offset=0) ll2=plot(channel2?lastl8:lastl8==nz(lastl8[1])?lastl8:na, color=color.black, linewidth=1, style=plot....
自動売買方法
はじめに TradingViewはトレードする場合かなり便利です。 様々なチャートとインジケータをweb上で閲覧可能。 Oandaと接続して、裁量トレードはできる。 ここまでは良いのですが、TradingViewだけで 自動売買 が現在未対応らしい。 残念すぎるだろ… あきらめない 自動売買の選択肢で有力なのが、MT4・MT5を使用する方法です。 ですが、これには問題があり、基本的にはWindowsでこれらのソフトを稼働させ続ける環境を用意する必要があります。 Windows稼働の環境作りも面倒で、もっさりした環境でMT4・MT5を使いたくないですよね… そこで、TradingViewを使ってFXをする方法を調査しました。 PineScript(TradingViewで使用されるインジケータ作成用の言語)でAlert発火 ↓ WebHookでGASにAlertのメッセージを飛ばす ↓ GASでメッセージを解析してOandaのAPIで取引を実行する トレード用のAPI トレード用に使用できるAPIの選択肢は少なく、有力なのはOandaです。 ただ、これも問題がありOandaのGold会員である必要があります。 Gold会員の維持は毎月$50万のトレードを行っている必要があり、比較的ハードルが高いです。 最後に 日本国内では、未だにMT4が主流のようで、なかなか自動売買が楽にできる選択肢が増えないのが現状のようです。 TradingViewに頑張ってもらって、無料でTradingViewから自動売買ができるようになれば最高ですよね? 近いうちにその日が来ることを望んでいます。...