I write a piece of code for Market Scanner to record the DayHigh and DayLow Time. Resolution is in 1 tick.
The code does two things:
1) Even the code runs for example 2 hours after the market opens, the code will find the DayOpen, DayHigh and DayLow of today.
2) Calculate the latest daily change (Last-PreviousClose)/Previous.
I use the "lastbaronchart" to initiate the code. The code works as expected so far.
Code: Select all
Variable: FirstRun(True),
BarCount(0), //Find Yesterday bar
BarCountII(0), //Loop for Today's OHL
PreviousClose(0),
PreviousDate(0),
ThisBarDate(0),
ThisBarTime(0),
DayOpen(0),
DayHigh(0),
DayHighTime(0),
DayLow(0),
DayLowTime(0),
DailyChg(0);
If LastBaronChart AND FirstRun = True then begin
For BarCount = 1 to 100000 begin
If Date <> Date[BarCount] then begin
//Record Last Close
PreviousDate = Date[BarCount];
PreviousClose = Close[BarCount]; //Locate Previous Day Close by BarCount
//Record Today's first tick as Open, High, Low
ThisBarDate = Date[BarCount-1];
ThisBarTime = Time[BarCount-1];
DayOpen = Close[BarCount-1];
DayHigh = Close[BarCount-1];
DayLow = Close[BarCount-1];
Break;
End;
End;
For BarCountII = BarCount-2 downto 0 begin
//Find the DayHigh and DayLow from last bar to the first bar of today
If Close[BarCountII] >= DayHigh then begin
DayHigh = Close[BarCountII];
DayHighTime = Time[BarCountII];
End;
If Close[BarCountII] <= DayLow then begin
DayLow = Close[BarCountII];
DayLowTime = Time[BarCountII];
End;
End;
End;
Plot1(BarCount,"BarCount");
Plot2(PreviousDate,"PreviousDate");
Plot3(PreviousClose,"PreviousClose");
Plot4(DayHigh, "High");
Plot5(FormatTime("HH:mm",ELTimetoDateTime(DayHighTime)), "H-Time");
Plot6(DayLow, "Low");
Plot7(FormatTime("HH:mm",ELTimeToDateTime(DayLowTime)), "L-Time");
Plot8(DayOpen, "Open");
Plot9(ThisBarDate, "Today");
Plot10(FormatTime("HH:mm",ELTimeToDateTime(ThisBarTime)), "TodayT");
Code: Select all
Variable: FirstRun(True),
BarCount(0), //Find Yesterday bar
BarCountII(0), //Loop for Today's OHL
PreviousClose(0),
PreviousDate(0),
ThisBarDate(0),
ThisBarTime(0),
DayOpen(0),
DayHigh(0),
DayHighTime(0),
DayLow(0),
DayLowTime(0),
DailyChg(0);
//Subsequent Run
If FirstRun = False then begin
If Close >= DayHigh then begin
DayHigh = Close;
DayHighTime = Time;
End;
If Close <= DayLow then begin
DayLow = Close;
DayLowTime = Time;
End;
End;
//FirstRun
If FirstRun = True AND LastBaronChart then begin
For BarCount = 1 to 100000 begin
If Date <> Date[BarCount] then begin
//Record Last Close
PreviousDate = Date[BarCount];
PreviousClose = Close[BarCount]; //Locate Previous Day Close by BarCount
//Record Today's first tick as Open, High, Low
ThisBarDate = Date[BarCount-1];
ThisBarTime = Time[BarCount-1];
DayOpen = Close[BarCount-1];
DayHigh = Close[BarCount-1];
DayLow = Close[BarCount-1];
Break;
End;
End;
For BarCountII = BarCount-2 to 0 begin
//Find the DayHigh and DayLow from last bar to the first bar of today
If Close[BarCountII] >= DayHigh then begin
DayHigh = Close[BarCountII];
DayHighTime = Time[BarCountII];
End;
If Close[BarCountII] <= DayLow then begin
DayLow = Close[BarCountII];
DayLowTime = Time[BarCountII];
End;
End;
FirstRun = False;
End;