MT4 MT5 + 동적 변수 NOT-REPAINT

저자:차오장, 날짜: 2022-05-24 16:59:00
태그:SMAMT4MT5

우연히, 나는 오픈 소스 수익성 있는 외환 전략을 공유하고 있습니다. 우연히, 이것은 순수 교육 자료를 목표로 했기 때문입니다. 며칠 전에 트레이딩뷰는 파인 스크립트에서 동적 값의 매우 강력한 기능을 발표 이제 알림에 전달 될 수 있습니다. 그리고 트레이딩 커넥터 덕분에, 그들은 즉시 실행 될 수 있습니다 MT4 또는 MT5 세계 어느 브로커의 플랫폼. 그래서 예 - 트레이딩 커넥터 지수와 상품과도 작동합니다.

이 EURUSD 6h 전략의 논리는 매우 간단합니다. 그것은 가장 최근의 피워트 포인트 아래로 설정된 스톡라스틱 크로스오버를 기반으로합니다. 경고에 동적 값을 허용함으로써 수술적 정확도로 스톱 로스를 설정하는 것이 가능합니다. 트레이딩 커넥터는 또한 이러한 동적 값을 활용하기 위해 업그레이드되었으며 이제 사전 계산된 스톱 로스, 영리, 그리고 스톱 및 리미트 오더로 거래를 실행할 수 있습니다.

트레이딩 커넥터의 또 다른 새로운 특징은 브로커가 허용하는 경우에만 부분적으로 포지션을 닫는 것입니다. 포지션은 입시에 trade_id를 지정해야하며, 부분적인 폐쇄와 함께 추가 알림에 참조됩니다. 알림 문법과 기능에 대한 자세한 스펙은 트레이딩 커넥터 웹 사이트에서 찾을 수 있습니다. 알림 메시지에 동적 변수를 포함하는 방법은 알림 조건 ()) 호출에서 스크립트의 끝에서 볼 수 있습니다.

이 전략은 또한 수수료를 고려합니다.

슬리핑은 의도적으로 0으로 남겨집니다. 트레이딩 커넥터의 1 초 배달 시간이 짧기 때문에 슬리핑은 사실상 존재하지 않습니다. 특히 브로커의 서버와 같은 데이터 센터에 호스팅 된 VPS 서버를 사용하는 경우 달성 할 수 있습니다. 나는 그러한 설정을 사용하고 있습니다. 작은 슬리핑과 스프레드는 이미 수수료 가치에 포함되어 있습니다.

이 전략은 NO-REPAINTING이며 TRAILING-STOP 또는 TradingView 백테스터에서 결함이 있는 것으로 알려진 다른 기능이 없습니다. 이 전략이 방탄 방지 및 100% 성공 보장되는가? 지옥은 아닙니다! 백테스팅의 1번 규칙을 기억하십시오 - 스크립트가 얼마나 수익성 있고 잘 보이더라도 과거에 대해만 이야기합니다. 동일한 전략이 미래에 유사한 결과를 얻을 것이라는 것은 제로 보장됩니다.

이 스크립트를 연구로 바꾸어 경고를 생성할 수 있도록 2가지 작업을 수행합니다.

  1. 댓글 전략 라인 시작 및 논평 연구 라인
  2. 54-59번 논문 줄과 62-65번 논평 줄은 그래프에 스크립트를 추가하고 경고를 구성합니다.

이 스크립트는 교육적인 목적으로만 만들어졌습니다.

물론 이것은 금융 조언이 아닙니다. 이 스크립트나 그 어떤 부분을 어떤 방식으로든 사용하는 사람은 거래와 관련된 높은 위험을 알아야 합니다.

코드 수정에 도움이 되어 주셔서 감사합니다.

백테스트

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)

관련

더 많은