英文:
Seeking advise to de-duplicate Month/Week/Day Open when occuring on same day
问题
当一个新的月份/周/(交易)日开始时,它们经常共享相同的日期/时间(尤其是新的周开盘也总是新的日开盘)。
由于我想要绘制相应时间段的“开盘”线,我经常会得到需要一些逻辑来消除重复的情况。
举个例子,当一个新的月份开始,同时也是新的一周和新的一天的开始时,我只想显示该事件的月度开盘价 - 但不想显示相同的事件作为周/日开盘价。
似乎几乎不可能处理(至少在我的大脑中)考虑到不同的交易日(例如,盘前市场)的24/7(加密货币)、指数和外汇交易会话。简而言之:我完全被困住了,但我有点自信我过于复杂化了事情/错过了一些已经处理这个问题的现有函数或者只是误解了Pine脚本概念的部分。
有没有人知道有没有处理这个问题的库/函数/方法,或者能够给我一个起点来帮助我理清这个问题?
英文:
When a new Month/Week/(Trading)Day starts they often share the same date/time (especially a new week Open always also is a new day Open).
As I want to plot lines for the "Open" of the corresponding timeframe, I am frequently getting duplicates that need quite some logic to eliminate duplicates.
As an example, when a new months starts that also is the start of a new week as well as a new day, I only want to show the monthly open for that occurence - but do not want to show the same occurence as week/day open.
It seems to become close to impossible to handle (in my brain at least) taking 24/7 (crypto), indecies, and Forex sessions with different tradingdays (e.g. pre-market) into consideration. Simply put: I am completely stuck but kinda confident I overcomplicate things/missed some existing functions handling that already or simply misunderstood parts of pine-script concepts.
<br>
Is anyone aware of a library/function/method handling this or got a starter to help me unwiring my mind on this topic?
<br><br>
<br>
Please: I don't expect anyone writing code for me (but happily take an example) but seek a pointer helping me to unwire my brain on how to achieve this in a elegant (and resource friendly) way.
答案1
得分: 1
你可以像这样定义三种不同的开盘线,然后使用 if / else if 语句只绘制你想要的线条
var line dayOpenLine = na
var line weekOpenLine = na
var line monthOpenLine = na
dayChange = ta.change(time('D'))
weekChange = ta.change(time('W'))
monthChange = ta.change(time('M'))
allThree = dayChange and weekChange and monthChange
if allThree
monthOpenLine := line.new(bar_index, open, bar_index + 1, open, extend = extend.right)
line.delete(monthOpenLine[1])
英文:
You can do something like this to define the three different opens and then use an if / else if statement to only plot the line you want
var line dayOpenLine = na
var line weekOpenLine = na
var line monthOpenLine = na
dayChange = ta.change(time('D'))
weekChange = ta.change(time('W'))
monthChange = ta.change(time('M'))
allThree = dayChange and weekChange and monthChange
if allThree
monthOpenLine := line.new(bar_index, open, bar_index + 1, open, extend = extend.right)
line.delete(monthOpenLine[1])
答案2
得分: 0
接收自 @bjorgum 通过 TV 聊天。
//@version=5
indicator("我的脚本", overlay = true)
switch
timeframe.change("M") => line.new(time, open, time_close("M"), open, xloc.bar_time, color = color.red)
timeframe.change("W") => line.new(time, open, time_close("W"), open, xloc.bar_time, color = color.yellow)
timeframe.change("D") => line.new(time, open, time_close("D"), open, xloc.bar_time, color = color.green)
英文:
Received from @bjorgum through TV chat.
//@version=5
indicator("My script", overlay = true)
switch
timeframe.change("M") => line.new(time, open, time_close("M"), open, xloc.bar_time, color = color.red)
timeframe.change("W") => line.new(time, open, time_close("W"), open, xloc.bar_time, color = color.yellow)
timeframe.change("D") => line.new(time, open, time_close("D"), open, xloc.bar_time, color = color.green)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论