I wrote a binary search that could be used to find the offset for any date and time in the chart. It has been working accurately for years. I was thinking maybe I could use the MouseClickBarNumber to replace my binary search in some scripts to speed things up. So I did a test. The script is below. The test results are at the bottom. To make the test results easy to read I clicked the mouse exactly 1 bar back from the current last bar on the chart. The binary search gives the correct offset value of 1. The MouseClickBarNumber is giving a larger bar number than the last bar on the chart bar number resulting in an offset difference calculation of -5. I am wondering why that might be and if the difference of -5 might be consistent that I could still use it by adding 5 to the calculation results?
Thanks, John
Code: Select all
{A_Test_MouseClickEvents =======================================================}
[ProcessMouseEvents = True];
inputs:
FutureUse(0);
variables:
CurrentBar1BarNumber(0),
LastBarOnChartBarNumber(0),
MouseClickDate(0),
MouseClickTime(0),
OffSetCalc(0),
OffSetSearch(0),
LogFile(""),
LogPath("");
if currentbar = 1 then
begin
LogFile = "A_Test_MouseClickEvents.txt";
LogPath = "C:\Users\John Bowles\Downloads\" + LogFile;
CurrentBar1BarNumber = BarNumber;
end;
If LastBarOnChart then
begin
if MouseClickDataNumber = 1 then
begin
MouseClickDate = JulianToDate(MouseClickDateTime) ;
MouseClickTime = DateTime2ELTime(MouseClickDateTime);
OffSetSearch = A_FindOffsetViaBinary(MouseClickDate,MouseClickTime,"Test");
if OffSetSearch = -3 then {If -3 then the restart of multicharts is so late the text is farther back than the maxbarsback setting}
begin
FileAppend(LogPath,
" Textoffset=-3 " +
" CurrentTime=" +
numtostr(CurrentTime,0) +
NewLine);
end;
OffSetCalc = BarNumber - MouseClickBarNumber;
LastBarOnChartBarNumber = BarNumber;
FileAppend(LogPath,
"5-Min Bars: " +
" Date=" +
numtostr(Date,0) +
" Time=" +
numtostr(Time,0) +
" MouseClickDate=" +
numtostr(MouseClickDate,0) +
" MouseClickTime=" +
numtostr(MouseClickTime,0) +
" CurrentBar1BarNumber=" +
numtostr(CurrentBar1BarNumber,0) +
" LastBarOnChartBarNumber=" +
numtostr(LastBarOnChartBarNumber,0) +
" MouseClickBarNumber=" +
numtostr(MouseClickBarNumber,0) +
" OffSetCalc=" +
numtostr(OffSetCalc,0) +
" OffSetSearch=" +
numtostr(OffSetSearch,0) +
NewLine);
end;
RecalcLastBarAfter(1);
end;
5-Min Bars: Date=1180703 Time=1225 MouseClickDate=1180703 MouseClickTime=1220 CurrentBar1BarNumber=1 LastBarOnChartBarNumber=519 MouseClickBarNumber=524 OffSetCalc=-5 OffSetSearch=1