Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

pine script - Renko function updating when it shouldn't be

EDIT: For anyone interested, I ended up writing my own version of a Renko that keeps track manually rather than calling the security function. I noticed that the Renko chart in TV calculates block size from ATR at the time that you open the chart. The Renko function seems to do the same. This means that calling it multiple times will change the resulting block size, and create non-deterministic behavior. I would not consider using the Renko function if you are using ATR to determine block size.

Disclaimer: I am not using the Renko chart or trying to use the Renko chart for strategies.

I am trying to develop a simple alert system for live trading stocks I want to buy or short. The premise is simply that the Renko close crosses a moving average of the Renko.

My understanding is that using a Renko function within a security function will not return data until the bar is fully formed. Meaning that if the last bar was at level 300, every bar in my current timeframe will return 300 for that function until the next bar is fully formed.

However, in my script I witnessed some movement of the Renko lines, and for the same conditions have had false alerts, and shapes plotted for the conditions with no alerts.

I thought this could be an issue where I need to use f_secureSecurity, but being that the renko function is not supposed to return unformed data I don't see why I should have to.

If anyone could confirm, I'm suspecting that I'm meeting the conditions and plotting a shape without triggering an alert because perhaps the condition is technically being met BEFORE the current bar. I know how to fix that if it's the case, but am still unsure of the false triggers.

study(title="Renko Indicator 4", shorttitle="Renko Indicator 4", overlay=true)

f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)

text_mode = input(title="Trade Mode", options=["Long", "Short", "Long and Short"], defval="Long")

var int mode = 0
if text_mode == "Short"
    mode := 1
else if text_mode == "Long and Short"
    mode := 2

plotchar(mode,"Mode",'')

atr_len = input(14,"ATR Length")

average_period = input(10, "Moving Average Period")

renko_t = renko(syminfo.tickerid, "ATR", atr_len)

// renko_average = f_secureSecurity(renko_t,timeframe.period, sma(close,average_period))
// renko_close = f_secureSecurity(renko_t, timeframe.period, close)

renko_average = security(renko_t,timeframe.period, sma(close,average_period))
renko_close = security(renko_t, timeframe.period, close)

plot(renko_average)
plot(renko_close)

var bool mode_long = na

if crossover(renko_close, renko_average) and (not mode_long or na(mode_long))
    mode_long := true
if crossunder(renko_close, renko_average) and (mode_long or na(mode_long))
    mode_long := false
long = mode_long and not mode_long[1]
short = not mode_long and mode_long[1]


alertcondition(short, 'TRADE SHORT', 'Renko SHORT {{ticker}} {{plot("Mode")}}')
alertcondition(long, 'TRADE LONG', 'Renko LONG {{ticker}} {{plot("Mode")}}')

plotshape(short, style=shape.square, size=size.small, color=color.red)
plotshape(long, style=shape.square, size=size.small, color=color.green)
question from:https://stackoverflow.com/questions/65847030/renko-function-updating-when-it-shouldnt-be

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...