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).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.
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;