Торговый просмотр ATR TP SL - PullRequest
       68

Торговый просмотр ATR TP SL

0 голосов
/ 03 октября 2019

Нужна помощь с моим сценарием,

Я хочу изменить его на текущий выбранный размер свечи.

В настоящее время я должен отредактировать сценарий, чтобы сделать это.

Также было бы неплохо, если бы я мог легко переключаться между отображением Long и Short, спасибо.

// Average true range (ATR) overlay for take profit levels 

[enter image description here][1]

// only taking trades within the qualifier

// stop loss to calculate position size


study(title="Average True Range Overlay", shorttitle="ATR Take Profits", overlay=true)
atrlen = input(14, minval=1)
emalen = input(1, minval=0)
watrband = input(1, minval=0)
emaz=ema(close, 13)
cl=rma(close, emalen)
cx=rma(close,emalen)
atru  =  atr(atrlen)
atrbh  = cx + watrband*atr(atrlen)
atrbl  = cl - watrband*atr(atrlen)
atrbhD = security(tickerid,'1440', atrbh)
atrblD = security(tickerid, '1440', atrbl)
plot(atrbhD, title='Take Profit 1', color=lime, linewidth=2, offset=0)
plot(atrbhD+atru, title='Take Profit 2', color=lime, linewidth=2, offset=0)
plot(atrbhD+atru+atru, title='Take Profit 3', color=lime, linewidth=2, offset=0)
plot(atrblD-atru/1.5, title='Long Stop Loss', color=yellow, linewidth=2, offset=0)
plot(emaz+atru, title='Long Qualifier', color=white, linewidth=2, offset=0)
//
plot(atrblD, title='Take Profit 1', color=red, linewidth=2, offset=0)
plot(atrblD-atru, title='Take Profit 2', color=red, linewidth=2, offset=0)
plot(atrblD-atru-atru, title='Take Profit 3', color=red, linewidth=2, offset=0)
plot(atrbhD+atru/1.5, title='Short Stop Loss', color=yellow, linewidth=2, offset=0)
plot(emaz-atru, color=white, title='Short Qualifier', linewidth=2, offset=0)


//

1 Ответ

1 голос
/ 04 октября 2019

Вы можете выбрать в скрипте Настройки / Входы , хотите ли вы использовать таймфрейм графика (по умолчанию) или более высокий таймфрейм.

//@version=3
// Average true range (ATR) overlay for take profit levels 
// only taking trades within the qualifier
// stop loss to calculate position size
study(title="Average True Range Overlay", shorttitle="ATR Take Profits", overlay=true)
atrlen = input(14, minval=1)
emalen = input(1, minval=0)
watrband = input(1, minval=0)
T00 = "A. None", T01 = "B. 1 minute", T02 = "C. 3 minutes", T03 = "D. 5 minutes", T04 = "E. 15 minutes", T05 = "F. 30 minutes", T06 = "G. 45 minutes", T07 = "H. 1 hour", T08 = "I. 2 hours", T09 = "J. 3 hours", T10 = "K. 4 hours", T11 = "L. 1 day", T12 = "M. 1 week", T13 = "N. 1 month"
usrTf = input( T00, "Use higher time frame?", options=[T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13])
showHighs = input(true, "Show Highs")
showLows = input(true, "Show Lows")

// ————— Function to return period string given input choice.
f_tf(_tf) => 
    // Dependencies: T?? constants.
    _tf   == T01 ? "1"      : 
      _tf == T02 ? "3"      : 
      _tf == T03 ? "5"      : 
      _tf == T04 ? "15"     : 
      _tf == T05 ? "30"     : 
      _tf == T06 ? "45"     : 
      _tf == T07 ? "60"     : 
      _tf == T08 ? "120"    : 
      _tf == T09 ? "180"    : 
      _tf == T10 ? "240"    : 
      _tf == T11 ? "D"      : 
      _tf == T12 ? "W"      : 
      _tf == T13 ? "M"      : period

emaz=ema(close, 13)
cl=rma(close, emalen)
cx=rma(close,emalen)
atru  =  atr(atrlen)
atrbh  = cx + watrband*atr(atrlen)
atrbl  = cl - watrband*atr(atrlen)

// Get TF corresponding to user selection.
tf = f_tf(usrTf)
// Fetch non-repainting higher TF if required.
atrbhD = tf == period ? atrbh : security(tickerid, tf, atrbh[1], lookahead = barmerge.lookahead_on)
atrblD = tf == period ? atrbl : security(tickerid, tf, atrbl[1], lookahead = barmerge.lookahead_on)

plot(showHighs ? atrbhD : na, title='Take Profit 1', color=lime, linewidth=2, offset=0)
plot(showHighs ? atrbhD+atru : na, title='Take Profit 2', color=lime, linewidth=2, offset=0)
plot(showHighs ? atrbhD+atru+atru : na, title='Take Profit 3', color=lime, linewidth=2, offset=0)
plot(showHighs ? atrblD-atru/1.5 : na, title='Long Stop Loss', color=yellow, linewidth=2, offset=0)
plot(showHighs ? emaz+atru : na, title='Long Qualifier', color=white, linewidth=2, offset=0)

plot(showLows ? atrblD : na, title='Take Profit 1', color=red, linewidth=2, offset=0)
plot(showLows ? atrblD-atru : na, title='Take Profit 2', color=red, linewidth=2, offset=0)
plot(showLows ? atrblD-atru-atru : na, title='Take Profit 3', color=red, linewidth=2, offset=0)
plot(showLows ? atrbhD+atru/1.5 : na, title='Short Stop Loss', color=yellow, linewidth=2, offset=0)
plot(showLows ? emaz-atru : na, color=white, title='Short Qualifier', linewidth=2, offset=0)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...