Valuewhen()

Hi, I want to know the RSI value at the Swing end by using VALUEWHEN() function. I expect the current RSI value is 52.19 but somehow it is not as attached. Just want to know which part of the script goes wrong:

https://learn.optuma.com/course/advanced-scripting/?course_type=content&course_page=1&lecture=11
https://help.optuma.com/kb/faq.php?id=1048

//Gann Swings
//Current Swing
S0 = SWINGEND(GANNSWING(SWINGCOUNT=2, DEFAULT=SwingList, METHOD=Use Next Bar));

//Corresponding RSI value of the Swings
R0 = VALUEWHEN(RSI(BARS=14),S0);

R0

Hi May,

Have a look at this article on using swing charts in scripting https://www.optuma.com/swing-scripting-1/

The issue is that SwingEnd() returns a swing list which does not line up with day by day bars. What you want to use is the following:

g1 = GANNSWING(SWINGCOUNT=2, DEFAULT=SwingList, METHOD=Use Next Bar);
S0 = G1.SwingEnd;

R0 = VALUEWHEN(RSI(BARS=14),S0);

Hope that helps

Mathew

Thanks Mathew! It works fine on current swing.

As I want to compare the corresponding RSI values at previous swing ends, I used the scripts below but did not work out (As attached, value of R1 in lower panel is the same as R0 in upper one somehow).

I believe I should use the dot notation as recommended in the article for both current scanning and backtesting purposes.

//Gann Swings
//Current Swing
S0 = SWINGEND(GANNSWING(SWINGCOUNT=2, DEFAULT=SwingList, METHOD=Use Next Bar));

//Previous Swings
S1 = OFFSET(S0, OFFSET=1);
S2 = OFFSET(S0, OFFSET=2);

//Swing Ends
SE0 = S0.SWINGEND();
SE1 = S1.SWINGEND();

//Corresponding RSI value of the Swings
R0 = VALUEWHEN(RSI(BARS=14),SE0);
R1 = VALUEWHEN(RSI(BARS=14),SE1);

R1