This code makes most v3 scripts work in v4 with only a few minor changes below. Place the framework code before the first input statement. You can totally delete all comments.
Pros: - to port to v4 you only need to make a few simple changes, not affecting the core v3 code functionality Cons: - without #include - large redundant code block, but can be reduced as needed - no proper syntax highlighting, intellisence for substitute constant names
Make the following changes in v3 script:
1. standard types can't be var names, color_transp can't be in a function, rename in v3 script: color() => color.new() bool => bool_ integer => integer_ float => float_ string => string_
2. init na requires explicit type declaration float a = na color col = na
3. persistent var init (optional): s = na s := nz(s[1], s) // or s := na(s[1]) ? 0 : s[1] // can be replaced with var s var s = 0 s := s + 1
1. optional explicit type declaration/conversion (you still can't cast series to int) float s 2. persistent var modifier var s var float s
3. string series - persistent strings now can be used in cond and output to screen dynamically
4. label and line objects - can be dynamically created, deleted, modified using get/set functions, moved before/after the current bar - can be in if or a function unlike plot - max limit: 50-55 label, and 50-55 line drawing objects in addition to already existing plots - both not affected by max plot outputs 64 - can only be used in the main chart - can serve as the only output function - at least one is required: plot, barcolor, line, label etc. - dynamic var values (including strings) can be output to screen as text using label.new and to_string
str = close >= open ? "up" : "down" label.new(bar_index, high, text=str)
col = close >= open ? color.green : color.red label.new(bar_index, na, "close = " + tostring(close), color=col, textcolor=color.white, style=label.style_labeldown, yloc=yloc.abovebar)
// create new objects, delete old ones l = line.new(bar_index, high, bar_index[10], low[10], width=4) line.delete(l[1])
// free object buffer by deleting old objects first, then create new ones var l = na line.delete(l) l = line.new(bar_index, high, bar_index[10], low[10], width=4)
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.