金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 837|回复: 2

大神,TradingView软件的Pine语音,lenko能改成金字塔吗?

[复制链接]

47

主题

163

帖子

163

积分

等级: 免费版

注册:
2024-1-11
曾用名:
发表于 2024-6-1 13:19 | 显示全部楼层 |阅读模式
//@version=5
indicator('Renko', max_bars_back=5000)
get_renko(box_size) =>
    var float base_price = input(title='Base price', defval=close)
    var float r_open = base_price - box_size
    var float r_close = close
    var int up_list = 0
    var int down_list = 0
    var int up_move = 0
    var int down_move = 0
    var int built_bricks_up = 0
    var int built_bricks_down = 0
    var int counter_up_series = 0
    var int counter_down_series = 0
    var int required_series_up = 0
    var int required_series_down = 0
    var int required_bricks_up = 0
    var int required_bricks_down = 0
    var bool b_up_list = false
    var bool b_down_list = false
    var bool b_up_move = false
    var bool b_down_move = false
    var bool in_the_range_up = false
    var bool in_the_range_down = false
    var int up_stop_index = 0
    var int down_stop_index = 0
    var int up_temporary_index = 0
    var int down_temporary_index = 0
    // creating lists
    if bar_index > 0
        if close > open
            down_move := 0
            if b_up_list
                up_move := int((close - base_price) / box_size)
                if up_move > up_list
                    up_list := up_move
                down_list := na
            else if b_down_list
                up_move := int((close - (base_price - down_list * box_size)) / box_size)
            else
                down_list := na
        else if close < open
            up_move := 0
            if b_down_list
                down_move := int((base_price - close) / box_size)
                if down_move > down_list
                    down_list := down_move
                up_list := na
            else if b_up_list
                down_move := int((base_price + up_list * box_size - close) / box_size)
            else
                down_list := na
                up_list := na
        if b_up_list and down_move >= 2
            base_price += (up_list - 1) * box_size
            b_up_list := false
            up_list := na
            b_down_list := true
            down_list := down_move - 1

        else if b_down_list and up_move >= 2
            base_price -= (down_list - 1) * box_size
            b_down_list := false
            down_list := na
            b_up_list := true
            up_list := up_move - 1

        if not b_up_list and not b_down_list
            up_move := int((close - base_price) / box_size)
            down_move := int((base_price - close) / box_size)
            if up_move > 0
                down_move := 0
                b_up_list := true
                b_up_move := true
                up_list := up_move
                down_list := na
            else if down_move > 0
                up_move := 0
                b_down_list := true
                b_down_move := true
                down_list := down_move
                up_list := na
    else
        up_list := na
        down_list := na
        r_close := na
    // creating open and close series
    if b_up_move
        for i = 0 to bar_index - up_stop_index - 1 by 1
            if not na(up_list) and na(up_list[i + 1])
                counter_up_series += 1
                required_bricks_up := up_list
                required_bricks_up
            if i == bar_index - up_stop_index - 1
                for j = i to 0 by 1
                    up_temporary_index := bar_index[j]
                    required_bricks_up := up_list[j]
                    if j == 0
                        break
                    if not na(up_list[j]) and na(up_list[j - 1])
                        up_temporary_index := bar_index[j - 1]
                        break
                break
        if counter_up_series == 1 and not na(up_list[0])
            in_the_range_up := true
        counter_up_series := 0
        if built_bricks_up < required_bricks_up
            r_open += box_size
            r_close := r_open + box_size
            built_bricks_up += 1

        else if in_the_range_up and built_bricks_up == required_bricks_up
            r_close := na
        else
            up_stop_index := up_temporary_index
            built_bricks_up := 0
            built_bricks_down := 1
            b_up_move := false
            b_down_move := true
            r_close := r_open - box_size

        in_the_range_up := false
    else if b_down_move
        for i = 0 to bar_index - down_stop_index - 1 by 1
            if not na(down_list) and na(down_list[i + 1])
                counter_down_series += 1
                required_bricks_down := down_list
            if i == bar_index - down_stop_index - 1
                for j = i to 0 by 1
                    down_temporary_index := bar_index[j]
                    required_bricks_down := down_list[j]
                    if j == 0
                        break
                    if not na(down_list[j]) and na(down_list[j - 1])
                        down_temporary_index := bar_index[j - 1]
                        break
                break
        if counter_down_series == 1 and not na(down_list[0])
            in_the_range_down := true
        counter_down_series := 0
        if built_bricks_down < required_bricks_down
            if up_stop_index == 0 and down_stop_index == 0 and built_bricks_down == 0
                r_open += box_size
                r_close := r_open - box_size
                built_bricks_down += 1
            else
                r_open -= box_size
                r_close := r_open - box_size
                built_bricks_down += 1
        else if in_the_range_down and built_bricks_down == required_bricks_down
            r_close := na
        else
            down_stop_index := down_temporary_index
            built_bricks_down := 0
            built_bricks_up := 1
            b_down_move := false
            b_up_move := true
            r_close := r_open + box_size
        in_the_range_down := false
    else
        r_close := na
    [r_open, r_open > r_close ? r_open : r_close, r_open < r_close ? r_open : r_close, r_close]
[r_open, r_high, r_low, r_close] = get_renko(input.float(defval=200.0, title='Box size', minval=0.00000001))
plotcandle(r_open, r_high, r_low, r_close, color=r_close > r_open ? color.green : color.red)

回复

使用道具 举报

37

主题

1万

帖子

6万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
wenarm
发表于 2024-6-3 08:51 | 显示全部楼层
改不了,语法相差过大,你可以考虑整理成完整思路,我们评估后看是否可以实现
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

47

主题

163

帖子

163

积分

等级: 免费版

注册:
2024-1-11
曾用名:
 楼主| 发表于 2024-6-3 13:23 | 显示全部楼层
技术006 发表于 2024-6-3 08:51
改不了,语法相差过大,你可以考虑整理成完整思路,我们评估后看是否可以实现

好的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2025-7-29 13:41 , Processed in 0.099059 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表