Scanner & chart RSI are different when data bars vary. Why?  [SOLVED]

Questions about MultiCharts and user contributed studies.
bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Scanner & chart RSI are different when data bars vary. Why?

Postby bowlesj3 » 04 Aug 2017

Update:
Anna's answer points in a few directions. One of them is correct. I kept digging. The last post gives the correct answer and the details.
At this point I am not sure if this is a bug. I am just curious if others have experienced this. I have some code shown below that gives accurate results when I apply it to a chart but when I put it into the scanner it does not give accurate results (the results are consistently off by about 1 unit of RSI plus or minus). I set the scanner to 80 bars back which should be enough. I am not sure what else to try at this point other than dumping the actual 15 minute bar closing prices back 2 days (that which I will do soon). Here is the code. It already has the append statements so it can be used to test. The code is the normal RSI but modified to pick up the highest RSI for the day that just finished or the day before. I will remove that and put in an append of the close. I will probably create a special workspace with the scanner having only one symbol (the one I am testing).

Code: Select all

inputs:
Price( Close ),
Length( 14 ),
OverSold( 30 ),
OverBought( 70 ),
OverSColor( Cyan ),
OverBColor( Red ),
PrevDateIn(0);

variables:
PrevDate(0),
intrabarpersist LogPath(""),
intrabarpersist LogFile(""),
intrabarpersist BarType(""),
intrabarpersist BarSize(""),
intrabarpersist BarSizeType(""),
intrabarpersist Score05Min(0),
intrabarpersist Score15Min(0),
intrabarpersist ScoreDaily(0),
intrabarpersist ScoreWeekly(0),
intrabarpersist FirstTime("Y"),
intrabarpersist PrevDayHighestRSI(0),
intrabarpersist MyHighestRSI(0),
intrabarpersist MyCount(0),
intrabarpersist strMessage(""),
intrabarpersist RealSym(""),
MyRSI( 0 ) ;

if currentbar = 1 then
begin
LogFile = "A_MY_RSI_HighestForTheDay.txt";
LogPath = "C:\Users\John Bowles\Downloads\" + LogFile;
RealSym = getsymbolname;
switch bartype_ex
begin
{
NumericSimple bartype_ex [of Data(*)] - returns MC adaptable symbol resolution info:
Tick = 1, // Tick
Volume = 8,
Second = 9,
Minute = 2,
Hour = 3,
Day = 4,
Week = 5,
Month = 6,
Year = 7,
Quarter = 10,
Points = 11,
Change = 12,
OrigPoints = 13,
}
case 1: {tick bars}
BarType = "T";
case 2: {minute bars}
BarType = "M";
case 4: {daily bars}
BarType = "D";
case 5: {weekly bars}
BarType = "W";
case 9: {second bars}
BarType = "S";
Default:
raiseruntimeerror("A_MY_RSI_HighestForTheDay has invalid bartype_ex. Aborting.");
end; {switch MySide}
BarSize = numtostr(barinterval,0);
BarSizeType = BarSize + BarType;
if BarSizeType = "15M" then {this test is needed because this study will be in the scanner as well as in the 15 minute bar chart.}
begin
PrevDayHighestRSI = A_GV_GetNamedFloat(RealSym + "_Highest15Min_RSI_Today",-1);
if PrevDayHighestRSI < 0 then
PrevDayHighestRSI = 9999; //This will be less than zero if not initialized in the morning
{
FileAppend(LogPath,
" Symbol=" +
RealSym +
" Date=" +
numtostr(Date,0) +
" Time=" +
numtostr(time,0) +
" PrevDayHighestRSI=" +
numtostr(PrevDayHighestRSI,2) +
NewLine);
}
end;

if realSym = "ABX" then
FileAppend(LogPath,
"CurrentBar=1: " +
" Symbol=" +
RealSym +
" Date=" +
numtostr(Date[MyCount],0) +
" Time=" +
numtostr(time[MyCount],0) +
" Close=" +
numtostr(Close[MyCount],2) +
" RSI=" +
NewLine);

end;



if BarSizeType = "15M" then
begin
MyRSI = RSI( Price, Length ) ;
if date = currentdate and time > 0930 and time < 1600 and barstatus = 2 then
begin
if MyRSI > PrevDayHighestRSI and FirstTime = "Y" then
begin
FirstTime = "N";
Score05Min = A_GV_GetNamedInt(RealSym + "_SC_5M", -1); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
if Score05Min < 0 then
begin
value1 = A_GV_SetNamedInt(RealSym + "_SC_5M", 0); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
strMessage = "15 Minute Bar RSI break." +
" Symbol=" +
RealSym +
" Time=" +
numtostr(time,0) +
" PrevRSI=" +
numtostr(PrevDayHighestRSI,4) +
" CurrentRSI=" +
numtostr(MyRSI,4) +
NewLine;
//FileAppend(LogPath, strMessage);
Alert(strMessage);
end;
Score15Min = A_GV_GetNamedInt(RealSym + "_SC_15M", -1); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
if Score15Min < 0 then
begin
value1 = A_GV_SetNamedInt(RealSym + "_SC_15M", 0); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
end;
ScoreDaily = A_GV_GetNamedInt(RealSym + "_SC_D", -1); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
if ScoreDaily < 0 then
begin
value1 = A_GV_SetNamedInt(RealSym + "_SC_D", 0); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
end;
ScoreWeekly = A_GV_GetNamedInt(RealSym + "_SC_W", -1); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
if ScoreWeekly < 0 then
begin
value1 = A_GV_SetNamedInt(RealSym + "_SC_W", 0); {SC_5M means shift count 5 minutes - shift means the shift in the wave}
end;
end;
end;
Plot1( MyRSI, "RSI" ) ;
Plot2( OverBought, "OverBot" ) ;
Plot3( OverSold, "OverSld" ) ;
if MyRSI > OverBought then
SetPlotColor( 1, OverBColor );
if MyRSI < OverSold then
SetPlotColor( 1, OverSColor );
end;

Condition1 = false;
if BarSizeType = "15M" and barstatus = 2 and time = 1600 then
begin
if date = PrevDateIn then
begin
condition1 = true;
PrevDate = PrevDateIn;
end
else
begin
if lastbaronchart = true then
begin
condition1 = true;
PrevDate = date;
end;
end;
end;

If condition1 = true then
begin
MyHighestRSI = 0;
For MyCount = 0 to 96
Begin
if date[MyCount] < prevDate then
break;
if realSym = "ABX" then
FileAppend(LogPath,
"15 Min Close Info." +
" Symbol=" +
RealSym +
" Date=" +
numtostr(Date[MyCount],0) +
" Time=" +
numtostr(time[MyCount],0) +
" Close=" +
numtostr(Close[MyCount],2) +
" RSI=" +
numtostr(MyRSI[MyCount],2) +
NewLine);
End;
For MyCount = 0 to 96
Begin
if date[MyCount] < prevDate then
break;
if MyRSI[MyCount] > MyHighestRSI then
begin
MyHighestRSI = MyRSI[MyCount];
end;
{
if realSym = "ABX" then
FileAppend(LogPath,
"PrevDays RSI." +
" Symbol=" +
RealSym +
" Date=" +
numtostr(Date[MyCount],0) +
" Time=" +
numtostr(time[MyCount],0) +
" HighestRSI=" +
numtostr(MyHighestRSI,2) +
NewLine);
}
End;
value1 = A_GV_SetNamedFloat(RealSym + "_Highest15Min_RSI_Today",MyHighestRSI);
if realSym = "ABX" then
BEGIN
FileAppend(LogPath,
"PrevDays RSI." +
" Symbol=" +
RealSym +
" Date=" +
numtostr(Date,0) +
" Time=" +
numtostr(time,0) +
" HighestRSI=" +
numtostr(MyHighestRSI,2) +
NewLine);
FileAppend(LogPath,
" " +
NewLine);
END;
end;
Last edited by bowlesj3 on 05 Aug 2017, edited 8 times in total.

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Scanner and chart are different.

Postby Anna MultiCharts » 04 Aug 2017

Hello, bowlesj3!

Most likely you’ve got different symbol and indicator settings. You need to make sure that symbol settings (Quote Field, Sessions, Resolution, Data Range) and MaxBarsBack setting of the indicator are the same on the chart and in the Scanner.

The MaxBarsBack setting for the indicator on a chart can be found in Format -> Indicators -> Format -> Properties tab -> Max number of bars study will reference.
Indicators in the Scanner window do not have MaxBarsBack controls, the values are read from the indicator settings that are configured in the Power Language editor.
Right click on the study in the PL Editor window -> Properties -> Properties tab -> Max number of bars study will reference.
You will need to re-add the study to the Scanner window after changing this setting.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Scanner and chart are different.  [SOLVED]

Postby bowlesj3 » 04 Aug 2017

I think I solved it (at least on one symbol). I had to set the number of bars back in the scanner to match exactly the chart. This is not the number of bars the study will reference but the number of bars back of the data series itself (the bars that show on the chart). I wrote down exactly what I had to do.

Chart:
I had the chart set to 100,000 so it would show all data available (I think). This is done by left clicking on the data series in the chart to highlight it, right clicking, left clicking format ABX (the symbol), clicking the settings tab, choosing data range and setting it to 100,000 bars back current date (I don't know what the little push pin means).

Scanner:
I had to set the scanner to 100,00 so it would also show all the data available (I think). This is done by left clicking on the Resolution column (of a symbol that has been entered), right clicking, choosing format resolution for all instruments, clicking the checkbox for "use custom Data Range" at the bottom, Making the values match the chart exactly.

I created an improved Append statements and I show the results in the attached files. This script has a display on the CurrentBar=1 statement. I also display all the closing prices and the RSI prices for the last day on the chart so I can be sure the RSI gets consistent closing data and be sure that the RSI is calculating properly. You will notice that both runs of the ABX symbol take a few tries before they settle down and become exactly the same. They don't do it the same way. I don't really understand why it takes a few tries at processing the symbol. Maybe tech support would know.

I updated the code in the first post just in case anyone is having problems with this and wants an example for a test.

I tested a few other symbols. It worked except for one problem. I get a message that my PC is running out of memory and I should reduce the number of bars on the chart.

Question: (now with the answer below)
I can reduce the bars on the scanner by a fair but. However I don't really understand why the scanner is such that the RSI needs to have exactly the same number of bars as the chart does to be accurate when it only goes back 14 bars to get its information. I would have thought the scanner could only have a few days worth of data and the RSI numbers would be accurate once it got enough to start. I tried setting up two charts with different bars back for the data series. The same thing happens (the close prices are exactly the same but the RSI calculations are different). It should not matter as far as my understanding of the RSI. Maybe someone can clarify this. Currently I am punching the closing prices in excel and trying to figure out what numbers I get with 14 bars of data going into the RSI formula.

Answer:
I think this link provides the answer.
http://stockcharts.com/school/doku.php? ... _index_rsi
Apparently the longer the data series the more accurate the RSI becomes and 250 is what these guys try to use at a minimum.
Also there are actually two RSI. One is not smoothed and one is. See this page. http://www.tc2000.com/tc2000help/Conten ... _s_RSI.htm
I think the smoothed RSI is more popular and it is the one in MC. I am curious as to whether the non smoothed RSI would differ if the number of bars differ.
Attachments
Scanner_FBOC_100000.txt
Scanner 100,000 First Bar In Chart Display
(5.79 KiB) Downloaded 195 times
Chart_FBOC_100000.txt
Chart 100,000 First Bar In Chart Display
(3.89 KiB) Downloaded 182 times


Return to “MultiCharts”