0

I am trying to build a script which compares the value of an indicator with previous value of the same indicator but in different time frames and then create a signal based on the comparison.

For example I want to get the value of EMA for 1Day, 4Hours, 1Hour & 30Minutes and then compare these values with the previous values of same time frame.

So for 1D current value is A and 1D-1 value is B
       4H current value is C and 4H-1 value is D
       1H current value is E and 1H-1 value is F
      30M current value is G and 30M-1 value is H

A>B or A<B
C>D or C<D
E>F or E<F
G>H or G<H

Then create a signal based on when all the comparisons align on the same side of trend.

AShar
  • 1

1 Answers1

0

You need to use the security() function to request data from other timeframes.

Example:

//@version=4
study(title="High Time Frame MA", overlay=true)
src = close, len = 9
out = sma(src, len)
out1 = security(syminfo.tickerid, 'D', out)
plot(out1)
vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • I have been able to use security as follows request.security(syminfo.tickerid, "1D", value) for current values but not able to get the previous day/4H/1H/30M values for comparison. Is there a parameter I can use for last value of each of these timeframes. – AShar Jul 30 '23 at 07:03
  • Getting the error as follows: Invalid value of the 'resolution' argument ('D-1') in the 'security' function. – AShar Jul 30 '23 at 07:40
  • If you want to access the previous values, you should use the [history referencing operator](https://www.tradingview.com/pine-script-docs/en/v5/language/Operators.html#history-referencing-operator). – vitruvius Jul 30 '23 at 08:16