Hi
My need is to get, from the 15min TF, the xopen value from the daily TF.
The here below code provides
- correct daily “Heiken Ashi Close” (xClose)
- uncorrect daily “Heiken Ashi Open” (xOpen) and I fail to understand why.
TIMEFRAME(daily)
if barindex>1 then
xClose = (Open + High + Low + Close) / 4
xOpen = (xOpen[1] +xClose[1])/2
endif
TIMEFRAME(15 minutes)
return xOpen, xClose coloured(255,0,0)
Any idea ?
I search the problem since hours…
Change you code:
- add ONCE xOpen = Open as line 2
- line 3 must be written outside the IF…ENDIF
TIMEFRAME(daily) //or TIMEFRAME(daily,UpdateOnClose) for yesterday's values
ONCE xOpen = Open
xClose = (Open + High + Low + Close) / 4
if barindex>1 then
xOpen = (xOpen[1] +xClose[1])/2
endif
TIMEFRAME(15 minutes)
return xOpen, xClose coloured(255,0,0)
Thank you.
I get same result and problem
(e.g. on the stock PDSB – PDS BIOTECHNOLOGY) xOpen shows a result of 5.2883 instead of 4.59
Yes, you are right. It’s really weird!
I suggest that you hit Ctrl+M from your platform and send a request for assistance.
Please post any solution you will be suggested. Thank you 🙂
OK I do and I will keep you aware of any solution
Thank you
If you just want the H.A. daily xopen and xclose you should use the xClose updated on the latest 15m bar not the xClose from the previous daily bar. The next code works for me:
//init
if barindex = 1 then
xOpen = open
endif
timeframe(daily)
dayOPEN = open
dayhigh = high
daylow = low
timeframe(default)
IF dayOPEN <> dayOPEN[1] THEN //calculate daily HA open
xOpen =( xOpen[1]+xClose[1])/2
ENDIF
xClose=(dayOpen+close+dayhigh+daylow)/4
RETURN xOpen AS "xOPEN", xClose as "xClose"
It works ! Problem solved !
and……I understand now why.
Thank you for your help and time
…i THINK I understand why but… unsure
And if I want to get data from previous daily Ha, I would do that but seems not working
if barindex = 1 then
xOpen = open
endif
timeframe(daily)
dayOPEN = open
dayOPEN1 = open[1]
dayhigh = high
dayhigh1 = high[1]
daylow = low
daylow1 = low[1]
timeframe(default)
IF dayOPEN <> dayOPEN[1] THEN //calculate daily HA open
xOpen =( xOpen[1]+xClose[1])/2
ENDIF
IF dayOPEN[1] <> dayOPEN[2] THEN //calculate daily HA open
xOpen1 =( xOpen[2]+xClose[2])/2
ENDIF
xClose=(dayOpen+close+dayhigh+daylow)/4
xClose1=(dayOpen1+close[1]+dayhigh1+daylow1)/4
RETURN xOpen AS "xOPEN", xClose as "xClose", xOpen1 AS "xOPEN1", xClose1 as "xClose1",
pableitor ‘s code works fine as long as you don’t use UPDATEONCLOSE.
It’s a workaround, but it should not be necessary, as it’s the same code as in prior posts and is executed every 15 minutes like the prior one.
It’s good it works, but it would be better that the prior code worked as well.
Just note that the daily HA Close is the same than the last 15minutes HA Close of the day, so we must use xClose[1] from the 15minutes timeframe, not the daily. In order to get the previous day HA data just save it in a couple of variables before updating the daily xOpen and xClose, like this:
if barindex = 1 then
xOpen = open
endif
timeframe(daily)
dayOPEN = open
dayhigh = high
daylow = low
timeframe(default)
IF dayOPEN <> dayOPEN[1] THEN //calculate daily HA open
xOpen1 = xOpen
xClose1 = xClose[1]
xOpen =( xOpen[1]+xClose[1])/2
ENDIF
xClose=(dayOpen+close+dayhigh+daylow)/4
RETURN xOpen AS "xOPEN", xOpen1 AS "prev_xOpen" , xClose as "xClose", xClose1 as "prev_xClose"
I used your variables names, but for multiple related variables you can use an array as well.
Pableitor, Robertogozzi
Thank you both.
To be honest : It works but I do not understand why and I am lost with regards to your thoughts.
Pableitor, thank you very much. Last question: I guess the same function but only applied the simple default TF would be simply
IF BarIndex = 1 THEN
XOpen = (Open + Close) / 2
ELSE
XClose = TotalPrice
XClose1=XClose[1]
XOpen = (XOpen[1] + Xclose[1]) / 2
XOpen1 = XOpen[1]
ENDIF
Thank you again both
@jerome888 I just cleaned the code a little bit so it can be used on any default TF from 1 min up to 1h. BTW its a pity that PRT doesnt give the HA OHLC values as indicator so it would be easier to calculate the MTF values:
if barindex = 1 then
xOpen = open
endif
timeframe(daily)
dayOPEN = open
xClose=Totalprice
timeframe(default, updateonclose)
IF dayOpen <> dayOPEN[1] THEN //calculate daily HA open
xOpen =( xOpen[1]+xClose[1])/2
ENDIF
RETURN xOpen AS "xOPen" , xClose as "xClose"
PS Yes your code works fine for the default TF.
Thanks a lot pableitor, I will use replace existing code by this one
pableitor – Do not use the ‘Quote’ button unless you are actually quoting someone! Your post had your own text included in a quote and no one else’s text in it.
- Be careful when quoting others in your posts. Only use the quote option when you need to highlight a particular bit of text that you are referring to or to highlight that you are replying to a particular member if there are several involved in a conversation. Do not include large amounts of code in your quotes. Just highlight the text you want to quote and then click on ‘Quote’.