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
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.
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.
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.
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.
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.
Look first. Then leap.
► 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()
• 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)
• 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)
• This allows the implementation of the step HTF selection mode.
f_multipleOfRes(_res, _mult)
• 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)
• 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.
Look first. Then leap.
เอกสารเผยแพร่:
Updated comments and label function.
เอกสารเผยแพร่:
Fixed alignment in code.
เอกสารเผยแพร่:
Changed variable name in label function.
เอกสารเผยแพร่:
Optimized f_tfResInMinutes(_resolution). Thanks to MichelT!
เอกสารเผยแพร่:
Typo. Thx scarf!
เอกสารเผยแพร่:
.
• 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.
• 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.
เอกสารเผยแพร่:
.
Added one function:
Given a resolution in fractional float minutes, returns it as a string in "timeframe.period" format usable with "security()".
Added one function:
f_resFromMinutes(_minutes)
เอกสารเผยแพร่:
Added 2 functions:
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.
f_theoreticalDilationOf(_res)
f_avgDilationOf(_res)
Tools and ideas for all Pine coders: www.pinecoders.com
Our Pine FAQ & Code: www.pinecoders.com/faq_and_code/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
Our Pine FAQ & Code: www.pinecoders.com/faq_and_code/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders