Is it possible to create an indicator that will let me know the number of times price close inside initial balance for a particlar period of time (ie Year , Month)?
What is an initial balance?
Trading time between 8am and 9am. Thanks
Say the price from 080000 to 090000, today, sits in the range 19000 – 19100, do you want to know how many times, in the past days, months, years, that price range sat in that same time interval?
Hi, I don't know if this is useful for you. The indicator shows the number of candles in which the price has moved between 2 levels and at certain times.
starttime=080000
endtime=090000
minlevel=20000
maxlevel=21000
if opentime>=starttime and opentime<=endtime then
n=n+1
if close>=minlevel and close<=maxlevel then
m=m+1
endif
endif
return m
Try this one:
DEFPARAM DrawOnLastBarOnly = true
ONCE FromDate = 20240901 //from Sep. 1st, 2024
ONCE ToDate = 20241125 //to Nov. 25th, 2024
//
ONCE FromTime = 080000 //from 8am (candle opening at 8am)
ONCE ToTime = 090000 //to 9am (candle opening at 9am)
//
ONCE Tally = 0
//
IF (OpenTime >= FromTime) AND (OpenTime <= ToTime) THEN
IF (OpenTime = FromTime) OR ((OpenTime > FromTime) AND (OpenTime[1] < FromTime)) OR ((OpenTime > FromTime) AND (IntraDayBarIndex = 0)) THEN
HH = High
LL = low
Flag = 0
ENDIF
HH = max(HH,high)
LL = min(LL,low)
ENDIF
IF Flag = 0 AND (OpenTime >= ToTime) THEN
Flag = 1
Tally = 0
FOR i = (BarIndex - 1) DownTo 0
IF (OpenDate[i] >= FromDate) AND (OpenDate[i] <= ToDate) THEN
IF (OpenTime[i] >= FromTime) AND (OpenTime[i] <= ToTime) THEN
IF (OpenTime[i] = FromTime) OR ((OpenTime[i] > FromTime) AND (OpenTime[i + 1] < FromTime)) OR ((OpenTime[i] > FromTime) AND (IntraDayBarIndex[i] = 0)) THEN
HHx = High[i]
LLx = low[i]
Flagx = 0
ENDIF
HHx = max(HHx,high[i])
LLx = min(LLx,low[i])
ENDIF
IF Flagx = 0 AND (OpenTime[i] >= ToTime) THEN
Flagx = 1
IF (HHx <= HH) AND (LLx >= LL) THEN
Tally = Tally + 1
ENDIF
ENDIF
ENDIF
NEXT
ENDIF
DrawText("#Tally# occurrences",BarIndex+10,high+range,Dialog,Bold,10) coloured("Green")
RETURN
You can choose the DATE range (a few days, up to several years) and the TIME range.
I am attaching the ITF file.