绘制每日高、低、收盘的手动水平 [英] Plotting manual levels for daily high,low,close

查看:64
本文介绍了绘制每日高、低、收盘的手动水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了解决我的问题,我已经在这里提出了几个问题,这个新问题将它们联系在一起并提供了一些背景信息.
以前与此相关的问题:

  • 解决方案

    这应该可以扩展.只需 POC 多行即可确定:

    //@version=4研究(HLC 级别",",真)initOnDate(_y, _m, _d, _prev, _init) =>if _y == year and _m == month and _d == dayofmonth_在里面别的_prev浮动 h = na浮动 l = na浮动 c = na整数 y = 0整数 m = 0整数 d = 0y := 2020, m := 03, d := 31, h := initOnDate(y, m, d, h, 2600), l := initOnDate(y, m, d, l, 2500), c :=initOnDate(y, m, d, c, 2525)y := 2020, m := 04, d := 01, h := initOnDate(y, m, d, h, 2610), l := initOnDate(y, m, d, l, 2510), c :=initOnDate(y, m, d, c, 2535)y := 2020, m := 04, d := 02, h := initOnDate(y, m, d, h, 2620), l := initOnDate(y, m, d, l, 2520), c :=initOnDate(y, m, d, c, 2545)plot(h, "h", change(h) ? na : color.green, 1)plot(l, "l", change(l) ? na : color.red, 1)plot(c, "c", change(c) ? na : color.orange, 1)

    As I've already asked a couple of questions here in an attempt to solve my problem, this new question ties them all together and provides some context.
    Previous questions related to this:

    I have a program (outside of TradingView) that tries to estimate the high/low/close levels of the ticker SPX for the next trading day.
    I'm planning to plot this only on intraday timeframes (anything from 1 minute to 4 hours).
    The only ticker I'm going to plot this on is SPX.

    Now I'm trying to plot these levels in TradingView, to have a visual representation on how accurate the predicted levels are.
    This means that I have a high/low/close value for every trading day.
    The current dataset contains about 50 entries (so 50 days where I have a high/low/close level to plot) and will grow by 1 entry every trading day.
    So in 1 year, the dataset will contain about 200 entries.

    Because the dataset is larger than the number of drawing objects that can be displayed by TradingView, I've ruled out the use of drawing objects like line.new().
    The garbage collecter would cause only the last 50 or so drawn objects to be shown, and I'd like the full dataset to be displayed.
    Therefore, I think I will need to resort to the plot() function.

    This means I will end up with 3 series to plot: high, low and close.
    Each will have a different value per trading date.
    So essentially, I'm trying to manually create these 3 series by assigning them a value for each date.
    But so far, I've failed to accomplish that.
    I'm also trying to have only 1 data entry line per trading date to avoid clutter and to keep the code clean and maintainable.
    Therefore, I'm trying to set these 3 data points per trading date with only 1 function.

    The below script is my latest attempt with a reduced dataset of only 5 trading days for clarity.
    I know the script below is wrong, because a variable cannot be re-used.
    That's why it says line 19: 'h' is already defined.
    I don't have a workaround for this, and I'd really like to find one.

    //@version=4
    study("Study", overlay=true)
    
    // Variables    
    var float dh = na
    var float dl = na
    var float dc = na
    
    // Functions
    isDate(y,m,d) => y==year and m==month and d==dayofmonth ? true:false 
    d(y,m,d,h,l,c) => // Daily Levels
        if isDate(y,m,d)
            [h,l,c]
        else
            [na,na,na] 
    
    // Set data for Daily High,Low,Close
    [h,l,c] = d(2020,04,13,2800,2700,2725), dh:=h,dl:=l,dc:=c
    [h,l,c] = d(2020,04,14,2850,2810,2825), dh:=h,dl:=l,dc:=c
    [h,l,c] = d(2020,04,15,2800,2750,2710), dh:=h,dl:=l,dc:=c
    [h,l,c] = d(2020,04,16,2850,2700,2790), dh:=h,dl:=l,dc:=c
    [h,l,c] = d(2020,04,17,2900,2800,2850), dh:=h,dl:=l,dc:=c
    
    // Plot Daily High,Low,Close
    plot(dh, color=color.red)
    plot(dl, color=color.green)
    plot(dc, color=color.blue)
    

    Another attempt is this code below, which does compile ok.

    //@version=4
    study("Functions test", overlay=true)
    
    var float h = na
    var float l = na
    var float c = na
    
    isDate(y,m,d) => y==year and m==month and d==dayofmonth ? true:false
    setData() => 
        if isDate(2020,04,13)
            [2800,2700,2725]
        if isDate(2020,04,14)
            [2850,2810,2825]
        if isDate(2020,04,15)
            [2800,2750,2710]
        if isDate(2020,04,16)
            [2850,2700,2790]
        if isDate(2020,04,17)
            [2900,2800,2850]
    
    [h1,l1,c1] = setData()
    
    h := h1
    l := l1
    c := c1
    
    plot(h,color=color.red)
    plot(l,color=color.green)
    plot(c,color=color.blue)
    

    The problem here is that it only plots the values for the last date.

    解决方案

    This should scale. Just POC it with lots of lines to be sure:

    //@version=4
    study("HLC Levels", "", true)
    
    initOnDate(_y, _m, _d, _prev, _init) => 
        if _y == year and _m == month and _d == dayofmonth
            _init
        else
            _prev
    
    float h = na
    float l = na
    float c = na
    int   y = 0
    int   m = 0
    int   d = 0
    
    y := 2020, m := 03, d := 31, h := initOnDate(y, m, d, h, 2600), l := initOnDate(y, m, d, l, 2500), c := initOnDate(y, m, d, c, 2525)
    y := 2020, m := 04, d := 01, h := initOnDate(y, m, d, h, 2610), l := initOnDate(y, m, d, l, 2510), c := initOnDate(y, m, d, c, 2535)
    y := 2020, m := 04, d := 02, h := initOnDate(y, m, d, h, 2620), l := initOnDate(y, m, d, l, 2520), c := initOnDate(y, m, d, c, 2545)
    
    plot(h, "h", change(h) ? na : color.green,  1)
    plot(l, "l", change(l) ? na : color.red,    1)
    plot(c, "c", change(c) ? na : color.orange, 1)
    

    这篇关于绘制每日高、低、收盘的手动水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆