1
votes

Im writing this to get a variable from 1W timeframe to use in a lower timeframe.

I draw a line with 2 points in history, and then I get the value of line at the current bar.

I draw the line on timeframe 1W, it connects 2 points from the bar_index[2] to the bar_index[1] and so I can get the value of that line at the current bar_index (all 3 bar_index are on 1W timeframe).

//@version=4

msma = sma(close, 14)
var msma_line = line.new(bar_index[1], high[1], bar_index, low, extend = extend.right)
line.set_xy1(msma_line, bar_index[2], msma[2])
line.set_xy2(msma_line, bar_index[1], msma[1])
msma_point = line.get_price(msma_line,bar_index)

W_1 =  security(syminfo.tickerid, "1W", msma_point, barmerge.gaps_off, barmerge.lookahead_on)

Now I get that value (V) at the current week, I go to the timeframe 4H, and I want to see that (V) value, store it in a variable, so I can compare it with the current close.

if (close > W_1)
  // here is what to do with the comparaison

But I have got the error

'expression' argument of security function should have no side effects

What does that mean?

How I can use the W_1 variable at lower timeframe ?

2
Please specify, do you want to draw a line on the higher timeframe? What value do you want to get from the higher timeframe? - AnyDozer
I edited my question to explain what I need - CandyG80

2 Answers

0
votes

The problem is that msma is being generated on the lower timeframe, using this should solve the problem

msma = security(syminfo.tickerid,"1w",sma(close, 14))
var msma_line = line.new(bar_index[1], high[1], bar_index, low, extend = extend.right)
line.set_xy1(msma_line, bar_index[2], msma[2])
line.set_xy2(msma_line, bar_index[1], msma[1])
msma_point = line.get_price(msma_line,bar_index)
0
votes

OK, after many tries and failed, I found a way to get the same value of 1W line point on any lower timeframe:

msma = sma(close, 14)

[Wmsma, Wmsma_1, Wmsma_2] =  security(syminfo.tickerid, "1W", [msma, msma[1], msma[2]], barmerge.gaps_off, barmerge.lookahead_on)

anynumber = 42 // any number >= 42 will work, but because Im on the 4H chart, so I set it == 42, because there are 42 bars of 4H per week
anynumber2 = anynumber + anynumber

var msma_line = line.new(bar_index[1], high[1], bar_index, low, extend = extend.right)
line.set_xy1(msma_line, bar_index[anynumber2], Wmsma_2)
line.set_xy2(msma_line, bar_index[anynumber], Wmsma_1)
msma_point = line.get_price(msma_line,bar_index)