Reputation: 11
This is my sample script which is causing repainting once I refresh the chart. Not sure what's wrong with it.
** //@version=5 strategy('MyTrendStrategy', overlay=true)
//f_security(_sym, _res, _src, _rep) => request.security(_sym, _res, _src)
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src, lookahead = barmerge.lookahead_on) out1 = f_secureSecurity(syminfo.tickerid, "15", open) out2 = f_secureSecurity(syminfo.tickerid, "15", close)
plot(out1, color=color.new(color.red, 0)) plot(out2, color=color.new(color.green, 0))
longCondition = ta.crossover(out2, out1) if longCondition strategy.entry('long', strategy.long, alert_message="GO LONG") shortCondition = ta.crossunder(out2, out1) if shortCondition strategy.entry('short', strategy.short, alert_message="GO SHORT") **
Upvotes: 1
Views: 1025
Reputation: 1
hi i put this but my alert not being triggered res5 = input("D", type=input.resolution)
o = security(syminfo.tickerid, res5, open, barmerge.gaps_off, barmerge.lookahead_on)
c =security(syminfo.tickerid, res5, close[1], barmerge.gaps_off, barmerge.lookahead_on)
hz = security(syminfo.tickerid, res5, high, barmerge.gaps_off, barmerge.lookahead_on)
l = security(syminfo.tickerid, res5, low, barmerge.gaps_off,barmerge.lookahead_on)
Upvotes: 0
Reputation: 2310
this will sort you out. When using lookahead we need to use last bar info using the historical operator []. Otherwise it leaks future data on the historical set before it would have been possible in real world conditions.
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
For more info please see this link and this link
Cheers and best of luck with your coding and trading
Upvotes: 3