BCParticipant
Master
I want to capture yesterday (9:15 – 16:30) high low and show on today chart, but my code didn’t show correctly, what I did wrong?
Once StartTime = 91500
Once EndTime = 163000
If Time >= StartTime and Time <= EndTime then
If Time = StartTime then
DailyHigh = High
DailyLow = Low
Endif
If High > DailyHigh then
DailyHigh = High
Endif
If Low < DailyLow then
DailyLow = Low
Endif
Endif
return DailyHigh[1], DailyLow[1]
You need to store yesterdays value before resetting and looking for todays value.
Once StartTime = 91500
Once EndTime = 163000
If Time >= StartTime and Time <= EndTime then
If Time = StartTime then
YesterdaysHigh = DailyHigh
YesterdaysLow = DailyLow
DailyHigh = High
DailyLow = Low
Endif
If High > DailyHigh then
DailyHigh = High
Endif
If Low < DailyLow then
DailyLow = Low
Endif
Endif
return YesterdaysHigh, YesterdaysLow
You could also use MAX and MIN instead of all the IF and THEN’s.
Once StartTime = 91500
Once EndTime = 163000
If Time >= StartTime and Time <= EndTime then
If Time = StartTime then
YesterdaysHigh = DailyHigh
YesterdaysLow = DailyLow
DailyHigh = High
DailyLow = Low
Endif
DailyHigh = max(high,DailyHigh)
DailyLow = min(low,Dailylow)
Endif
return YesterdaysHigh, YesterdaysLow
BCParticipant
Master
Hi PRT Master
I stuck again on how to capture last week (9:15 – 16:30) high low, anyone can help?
Thanks
Try this:
StartTime = 091500
EndTime = 163000
once LastWeeksHigh = undefined
once LastWeeksLow = undefined
if opendayofweek < opendayofweek[1] then
LastWeeksHigh = DailyHigh
LastWeeksLow = DailyLow
firsttime = 0
endif
If not firsttime and Time = StartTime then
DailyHigh = High
DailyLow = Low
firsttime = 1
endif
if firsttime and Time >= StartTime and Time <= EndTime then
DailyHigh = max(high,DailyHigh)
DailyLow = min(low,Dailylow)
Endif
return LastWeeksHigh, LastWeeksLow
EDIT : Code corrected 20191021
BCParticipant
Master
Hi Vonasi
I just test the code, but the output not same as your screen cap.
BC
BCParticipant
Master
Hi Vonasi
I found where is the problem, should use OpenDayOfWeek command instead of OpenDay.
Thanks
Sorry about that – not sure how that typo got in there! I’ll edit the code in my post to correct it.
BCParticipant
Master
Hi Vonasi
I stuck again on capture last X week high low within 9:15-16:00, can you help?
Thanks
By X do you mean you want the high and low between 0915 and 1600 for the week X weeks ago or do you mean you want them for the last X weeks all included?
BCParticipant
Master
High and low between 0915 and 1600 for the week X weeks ago, eg: 10 weeks ago.
Thanks
This code will do that – but be warned it is very slow to draw due to the loop.
StartTime = 091500
EndTime = 160000
once myWeeksHigh = undefined
once myWeeksLow = undefined
if opendayofweek < opendayofweek[1] then
firsttime = 0
endif
If not firsttime and Time = StartTime then
myWeeksHigh = DailyHigh
myWeeksLow = DailyLow
weekindex = weekindex + 1
DailyHigh = High
DailyLow = Low
firsttime = 1
endif
if firsttime and openTime >= StartTime and opentime < EndTime then
DailyHigh = max(high,DailyHigh)
DailyLow = min(low,Dailylow)
endif
if weekindex > lookback then
for j = 1 to barindex
if WeekIndex[j] = WeekIndex - lookback then
myweekshigh = Dailyhigh[j]
myweekslow = Dailylow[j]
break
endif
next
endif
return myWeeksHigh, MyWeeksLow