YvesParticipant
Junior
Hi all,
hope someboday can fix that little problem. I want that indicator to show previous month high low and close in any lower timeframe. Highs and lows works fine but the monthly close shows the wrong price.
thanks in advance
once monthlyHigh=undefined
once monthlyLow=undefined
once monthlyClose=undefined
dailyHigh= DHigh(1)
dailyLow= DLow(1)
// monthly high/low
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
lastMonthBarIndex = BarIndex
ENDIF
// monthly close
If Month <> Month[1] then
monthlyClose = DClose(1)[BarIndex - lastMonthBarIndex]
lastMonthBarIndex = BarIndex
ENDIF
return monthlyHigh as "Prev Month High", monthlyLow as "Prev Month Low", monthlyClose as "Prev Month Close"
Hi, is it for cfd’s with IG? Could be that on the last day of the month, apart maybe from December because of early market close on the 31st, if the candle close in its market happens to be at midnight or more in your time zone, the month on your last candle is switching early (for example a return of 5 for may on the last day of April, but a return of 4 of the day before that) therefore triggering your “month<>month[1]” condition 1 day early (or 1 candle early in lower time frames)
A quick fix to this could be to use “openmonth” instead of “month”, because your last day of the month most likely still starts on the “proper” month regardless of the time difference between your area and the cfd market close time.
Also line 19 could be shorter, all together a suggestion for lines 18 to 21 could be:
If openMonth <> openMonth[1] then
monthlyClose = DClose(1)
lastMonthBarIndex = BarIndex
ENDIF
YvesParticipant
Junior
Thank you. It should work with any brokers data depending on my pro realtime timeframe settings. Month open is okay but not really that what i am looking for. In that case i need that previous month closes.
I did not propose to give month open price level instead of close. That’s why I kept part of your line 19 when using Dclose of last day of previous month and wrote:
monthlyClose = DClose(1)
And in your line 18, when instead of “month” I suggested using “openMonth”, it might be worth reminding openMonth is not the month open price level, it is the month number in which the candle opens (the same way “Month” is not the close price level but is the month number in which the candle closes).
Using “openmonth” instead of “month” makes sure you avoid the glitch of month number switching one candle earlier than you want, because your “if month<>month[1]” is triggered on last day of month rather than first day of new month, and captures close of the day-before-last (which you don’t want) rather than the last day of the month (which you want).
Hi, I’m looking for an indicator that show previous quarter high and low. Thanks in advance.
@kinyo
Quarter high/low can be retrieved with this code snippet:
If Month<>Month[1] then
monthlyH = Highest[BarIndex - lastMonthBarIndex](High)[1]
monthlyL = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
lastMonthBarIndex = BarIndex
if trimH=0 then
trimH=monthlyH
endif
trimH=max(trimH,monthlyH)
if trimL=0 then
trimL=monthlyL
endif
trimL=min(trimL,monthlyL)
if openmonth=4 or openmonth=7 or openmonth=10 or openmonth=1 then
trimestrialH=trimH
trimestrialL=trimL
endif
Endif
Hello Nicolas, thank you for this code but there is a problem.
Your indicator only draws correctly the highest of the previous quarter (red line). The lowest is not good (green line). If anyone has an idea to solve this bug ?
Sorry, wrong code, this one should work better:
trimH=max(trimH,high)
trimL=min(trimL,low)
If openMonth<>openMonth[1] then
if openmonth=4 or openmonth=7 or openmonth=10 or openmonth=1 then
trimestrialH=trimH
trimestrialL=trimL
trimL=close*100
trimH=0
endif
Endif
return trimestrialH,trimestrialL
Great ! Thank you very much.
Hello, I try to code a screener that display the forex pairs whose price closes (in daily) on the previous highest (display number 2), below the previous lowest (display number 1) or in the middle (display number 0) for monthly and quarterly.
Unfortunately nothing appears when launching this screener and I don’t understand why ?
timeframe(daily)
// previous monthly high/low
if Month <> Month[1] then
Mhi = Highest[BarIndex - lastMonthBarIndex](DHigh(1))
Mlo = Lowest[BarIndex - lastMonthBarIndex](DLow(1))
lastMonthBarIndex = BarIndex
endif
// previous quartly high/low
trimH = max(trimH,high)
trimL = min(trimL,low)
if openmonth <> openmonth[1] then
if openmonth = 4 or openmonth = 7 or openmonth = 10 or openmonth = 1 then
Qhi = trimH
Qlo = trimL
trimL = close*100
trimH = 0
endif
endif
if close > Qhi then
q = 20
endif
if close < Qlo then
q = 10
endif
if close < Qhi and close > Qlo then
q = 0
endif
if close > Mhi then
m = 2
endif
if close < Mlo then
m = 1
endif
if close < Mhi and close > Mlo then
m = 0
endif
t = q + m
SCREENER (t as "Q M")
I can not do anything with OpenMonth, I fixed the screener to return information with “Month” instead, but the values of the quarters may not be the right ones, to be checked:
// previous quartly high/low
trimH = max(trimH,high)
trimL = min(trimL,low)
if month <> month[1] then
Mhi=trimH
Mlo=trimL
if month = 4 or month = 7 or month = 10 or month = 1 then
Qhi = trimH
Qlo = trimL
trimL = close*100
trimH = 0
endif
endif
if close > Qhi then
q = 20
endif
if close < Qlo then
q = 10
endif
if close < Qhi and close > Qlo then
q = 0
endif
//m=0
if close > Mhi then
m = 2
endif
if close < Mlo then
m = 1
endif
if close < Mhi and close > Mlo then
m = 0
endif
t = q + m
SCREENER (t as "Q M")
Hi Nicolas, thank you very much once again for your precious help. Your code seems to work properly.
Hello, what is wrong, why is this not working?
AboveMonthlyHigh = 0
BelowMonthlyLow=0
once monthlyHigh=undefined
once monthlyLow=undefined
dailyHigh= DHigh(1)
dailyLow= DLow(1)
// monthly high/low
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
lastMonthBarIndex = BarIndex
ENDIF
If Dclose(0) > monthlyHigh[1] then
AboveMonthlyHigh = 1
endif
If Dclose(0) < monthlyLow[1] then
BelowMonthlyLow = 1
endif
SCREENER [AboveMonthlyHigh or BelowMonthlyLow]
Strange, this code works as an indicator but not as a screener??
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)
lastMonthBarIndex = BarIndex
ENDIF
C1 = Dclose(0) > monthlyHigh
C2 = Dclose(0) < monthlyLow
SCREENER[C1 or C2]
@Swingforfortune
Because it needs at least some history to be loaded (barindex>20):
If Month <> Month[1] and barindex>20 then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)
lastMonthBarIndex = BarIndex
ENDIF
C1 = Dclose(0) > monthlyHigh
C2 = Dclose(0) < monthlyLow
SCREENER[C1 or C2]
I still have some of your posts in pending review, because you didn’t send me the code in open source format 🙂 You can send them to me at my email: nicolas[at]prorealcode.com ; many thanks for sharing!