MT4 MT5 + ダイナミック変数へのTradingViewアラート

作者: リン・ハーンチャオチャン開催日:2022年5月24日 16:59
タグ:SMAMT4MT5

偶然にも,私はオープンソースの収益性の高い外為戦略を共有しています.偶然にも,これは純粋に教育的な素材を目的としたからです. 数日前,TradingViewはPineScriptから動的値の非常に強力な機能をリリースしました. 現在,アラートで渡すことができます. そして,TradingConnectorのおかげで,彼らは瞬時に実行することができます MT4 またはMT5 プラットフォーム 世界の任意のブローカーです. そうです - TradingConnectorはインデックスと商品にも動作します.

このEURUSD 6h戦略の論理は非常にシンプルで,ストーカスティッククロスオーバーをベースに,ストップロスは最新のピボットポイントの下で設定されている.ストップロスは,アラートにダイナミックな値が許容されているため,手術的な精度で設定することが可能である.TradingConnectorは,これらのダイナミックな値を利用するためにアップグレードされ,現在,事前に計算されたストップロース,テイク・プロフィート,ストップ&リーミットオーダーで取引を実行することができます.

トレーディングコネクタのもう一つの新しい機能は,ブローカーが許可する限り,部分的なポジションのみを閉鎖することです.ポジションは,部分的な閉鎖のさらなるアラートで参照される入力時に trade_id を指定する必要があります.アラート構文と機能の詳細な仕様は,トレディングコネクタのウェブサイトで見つけることができます.アラートメッセージに動的変数をどのように含めるかは,アラートコンディション ( alertcondition)) の呼び出しのスクリプトの終わりに見ることができます.

戦略には,手数料も考慮されています.

スリッパージは意図的に0に残されます.TradingConnectorの配達時間が1秒未満であるため,スリッパージは事実上存在しない.特にあなたがブローカーのサーバーと同じデータセンターにホストされているVPSサーバーを使用している場合,これは達成できます.私はそのようなセットアップを使用しています.それは実行可能です.小さなスリッパージとスプレッドはすでに佣金値に含まれています.

この戦略は NON-REPAINTINGであり,TradingViewバックテストで欠陥があることが知られている NO TRAILING-STOPまたは他の機能を使用しています.この戦略を弾丸に耐えて100%成功保証ですか?いやいや!バックテストの第1のルールを忘れないでください - スクリプトがどれほど利益があり,見栄えが良いかに関わらず,それは過去についてのみ話します.同じ戦略が将来にも同様の結果を得る保証はゼロです.

2つのことをしてください. 警告を出すことができます.

  1. コメント 戦略 開始線とアンコメント 研究
  2. 54-59のコメント行と 62-65のコメント行は スクリプトをチャートに追加して アラームを設定します

この脚本は教育目的のみで作られました.

もちろんこれは金融アドバイスではありません.このスクリプトやその一部を何らかの形で使用する人は,取引に関連する高いリスクに気づかなければなりません.

コード修正の為の @LucF と @a.tesla2018 さん ありがとうございました:)

バックテスト

img


/*backtest
start: 2022-04-23 00:00:00
end: 2022-05-22 23:59:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Peter_O

//@version=5
strategy(title='TradingView Alerts to MT4 MT5 Strategy example', commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=false, default_qty_value=100000, initial_capital=1000)
//study(title="TradingView Alerts to MT4 MT5 Strategy example")  //uncomment this line and comment previous one to make it a study producing alerts
//
// This script was created for educational purposes only.
// It is showing how to use dynamic variables in TradingView alerts.
// And how to execute them in Forex, indices and commodities markets

TakeProfitDistance = input(400)
TakePartialProfitDistance = input(150)

// **** Entries logic **** {
periodK = input.int(13, title='K', minval=1)
periodD = input.int(3, title='D', minval=1)
smoothK = input.int(4, title='Smooth', minval=1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
plot(k, title='%K', color=color.new(color.blue, 0))
plot(d, title='%D', color=color.new(color.orange, 0))
h0 = hline(80)
h1 = hline(20)
fill(h0, h1, color=color.new(color.purple, 75))

GoLong = ta.crossover(k, d) and k < 80
GoShort = ta.crossunder(k, d) and k > 20
// } End of entries logic

// **** Pivot-points and stop-loss logic **** {
piv_high = ta.pivothigh(high, 1, 1)
piv_low = ta.pivotlow(low, 1, 1)
var float stoploss_long = low
var float stoploss_short = high

pl = ta.valuewhen(piv_low, piv_low, 0)
ph = ta.valuewhen(piv_high, piv_high, 0)

if GoLong
    stoploss_long := low < pl ? low : pl
    stoploss_long
if GoShort
    stoploss_short := high > ph ? high : ph
    stoploss_short
// } End of Pivot-points and stop-loss logic

strategy.entry('Long', strategy.long, when=GoLong)
strategy.exit('XPartLong', from_entry='Long', qty_percent=50, profit=TakePartialProfitDistance)
strategy.exit('XLong', from_entry='Long', stop=stoploss_long, profit=TakeProfitDistance)
strategy.entry('Short', strategy.short, when=GoShort)
strategy.exit('XPartShort', from_entry='Short', qty_percent=50, profit=TakePartialProfitDistance)
strategy.exit('XShort', from_entry='Short', stop=stoploss_short, profit=TakeProfitDistance)

if GoLong
    alertsyntax_golong = 'long slprice=' + str.tostring(stoploss_long) + ' tp1=' + str.tostring(TakePartialProfitDistance) + ' part1=0.5 tp=' + str.tostring(TakeProfitDistance)
    alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)
if GoShort
    alertsyntax_goshort = 'short slprice=' + str.tostring(stoploss_short) + ' tp1=' + str.tostring(TakePartialProfitDistance) + ' part1=0.5 tp=' + str.tostring(TakeProfitDistance)
    alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)


if GoLong
    strategy.entry("Enter Long", strategy.long)
else if GoShort
    strategy.entry("Enter Short", strategy.short)

関連性

もっと