PineCoders

MTF Selection Framework - PineCoders FAQ

Our MTF Selection Framework allows Pine coders to add multi-timeframe capabilities to their script with the following features:

► Timeframe selection
The higher timeframe can be selected using 3 different ways:
• By steps (60 min., 1D, 3D, 1W, 1M, 1Y).
• As a multiple of the current chart's resolution, which can be fractional, so 3.5 will work.
• Fixed.

► Non-repainting or Repainting mode can be selected.

► Smoothing of the HTF line
Can be turned on/off and a smoothing factor allows the user to select the degree of smoothing he requires.

The framework is used here to create a higher timeframe version of a simple RSI line, but it can be used to access HTF information for almost any signal.


Functions used


f_resInMinutes()
Converts the current timeframe.multiplier plus the TF into minutes of type float.
• In Pine, the timeframe.multiplier is an integer representing the resolution, but a value of 1 can mean one day or one minute. This function converts that information in a standard fractional float minutes format that can then be used by the other functions in the framework.
• If the chart's current resolution is 15 seconds, the function will return 0.25. If the chart's resolution is one day, it will return 1440.

f_tfResInMinutes(_resolution)
Returns resolution of _resolution period in minutes.
• This function does the same as f_resInMinutes(), but on the target resolution supplied as a parameter in the timeframe.period string format.

f_resNextStep(_res)
Given a current resolution in fractional float minutes, returns its corresponding stepped HTF in the timeframe.period string format.
• This allows the implementation of the step HTF selection mode.

f_multipleOfRes(_res, _mult)
Given a current resolution in fractional float minutes and a fractional multiplier, returns a multiple of the resolution as a string in "timeframe.period" format usable with "security()".
• A multiple like 3.5 is allowed.
• Note that with seconds resolutions, the result returned is constrained by the discrete seconds resolutions available on TV.

f_htfLabel(_txt, _y, _color)
Used to display a label showing either:
• A warning when the chart's resolution is not lower than the HTF.
• The HTF resolution currently used.
The y position used to position the label will require adaptation to the signal you are using. For use in "overlay = true" mode, a technique that works well is commented out in the code.

Phát hành các Ghi chú: Updated comments and label function.
Phát hành các Ghi chú: Fixed alignment in code.
Phát hành các Ghi chú: Changed variable name in label function.
Phát hành các Ghi chú: Optimized f_tfResInMinutes(_resolution). Thanks to MichelT!
Phát hành các Ghi chú: Typo. Thx scarf!
Phát hành các Ghi chú: .
• Added steps to the shorter TFs in f_resNextStep(). The steps are now: 15 min., 60 min., 4H, 1D, 3D, 1W, 1M, 1Y.
• Also added a compact version of the functions at the end of the script, which uses only 7 lines.
Phát hành các Ghi chú: .
Added one function:
f_resFromMinutes(_minutes)
Given a resolution in fractional float minutes, returns it as a string in "timeframe.period" format usable with "security()".
Phát hành các Ghi chú: Added 2 functions:
f_theoreticalDilationOf(_res)
f_avgDilationOf(_res)
They return the theoretical and the average number of chart bars (the dilation) in the higher resolution. The average number will vary because of non-trading period or irregularities in datasets.
Mã nguồn mở

Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
Tools and ideas for all Pine coders: http://www.pinecoders.com
Our Pine FAQ & Code: http://www.pinecoders.com/faq_and_code/
Pine news broadcasts: https://t.me/PineCodersSquawkBox or https://twitter.com/PineCoders

Bình luận

awesome, thanks LucF!
+2 Phản hồi
Always amazed by your work! Thanks so much for sharing!
+1 Phản hồi
Nice work man! How I can plotcandle from higher order timeframe. For example I have 4 bars on 15m timeframe and I would like to plotcandle from 1h timeframe but from full hour to full hour eg. 9:00 to 10:00 not 9:15 to 10:15 because security function returns timeframe "60" not for full hours.
Phản hồi
PineCoders Kapucha
@Kapucha, If you want to plot candle-like drawings that extend across bars you'll need to use a technique like @RicardoSantos is using here: and the numbers of candles you'll be able to draw will be limited. The only other option, afawk, would be to `plotcandle()` the same candle on all intrabars.
Phản hồi
LucF, A quick question as I am struggeling with the smoothing factor. Right now you have somekind a an automatic smooth factor defined in line 123 (vHtfSmoothLen = max(2, rsiLength / vHtfSmooothFact))
But would it be possible to use the timeframe multiplier for this? Something like f_multipleOfRes(vResInMinutes, vHtfType2) / timeframe.period ???

Right now the smoothing isn't that great
Phản hồi
@GeVe, You can make the smoothing factor whatever you want. Keeping it of the "simple int" type will make it usable as a length with `ema()`, so will avoid having to use a special averaging function able to work with a "series" period. If your objective is to adapt smoothing to the mode 2 type of selection using a multiple of the current TF, you could try just using that multiple as is, like so:
 vHtfSmoothLen = int(max(2, vHtfType2))
If you wanted to make the smoothing length independent of the MTF selection mode and just use the ratio of the HTF/TF, regardless of how the HTF was calculated, then you could use something like:
vHtfSmoothLen = int(max(2, f_tfResInMinutes(vHtf)/vResInMinutes))
Sma(src,p) => a = cum(src), (a - a[max(p,0)])/max(p,0)
rHtf := vHtfOn and vHtfSmooth ? Sma(Sma(Sma(rHtf, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : rHtf
This uses alexgrover's `Sma()` function which accepts a series value for its period. It's lifted from here:
Phản hồi
GeVe PineCoders
@PineCoders, This was exactly what I was looking for Luc. It's magic. Thanks a lot for your crispy explanation
Phản hồi
Looks nice! Is it possible to plot warning text if the user selects a TF lower than the chart TF?
Phản hồi
PineCoders coininvestor
@coininvestor, Yes. Look at lines 117-118.
+1 Phản hồi
Trang chủ Bộ lọc cổ phiếu Bộ lọc Forex Bộ lọc Tiền điện tử Lịch kinh tế Cách thức hoạt động Tính năng Biểu đồ Trả phí Giới thiệu bạn Quy tắc Áp dụng Trung tâm Trợ giúp Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Thư viện Biểu đồ Lightweight Blog & Tin tức Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Tin nhắn riêng Trò chuyện Đăng xuất