Heikin Ashi MTF Trend [Pt]

PtGambler · study · 55 行 · 点赞 907 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PtGambler
 
//@version=5
indicator("Heikin Ashi MTF Trend [Pt]", shorttitle = 'HA MTF Trend [Pt]', overlay = false)
 
tf1 = input.timeframe('15', 'Timeframe 1', inline = 'tf1')
tf_weight1 = input.int(10, 'Weight', minval = 0, inline = 'tf1')
 
tf2 = input.timeframe('30', 'Timeframe 2', inline = 'tf2')
tf_weight2 = input.int(20, 'Weight', minval = 0, inline = 'tf2')
 
tf3 = input.timeframe('60', 'Timeframe 3', inline = 'tf3')
tf_weight3 = input.int(30, 'Weight', minval = 0, inline = 'tf3')
 
tf4 = input.timeframe('240', 'Timeframe 4', inline = 'tf4')
tf_weight4 = input.int(40, 'Weight', minval = 0, inline = 'tf4')
 
show_bar_color = input.bool(true, 'Show Bar Color', inline = 'col')
strong_bear_col = input.color(color.rgb(255, 74, 74), '', inline = 'col')
weak_bear_col = input.color(color.rgb(223, 126, 61), '', inline = 'col')
weak_bull_col = input.color(color.rgb(157, 159, 46), '', inline = 'col')
strong_bull_col = input.color(color.rgb(0, 255, 8), '', inline = 'col')
 
show_hist_lookahead = input.bool(true, 'Shows repainted historical HA bar colors')
 
lookahead_in = show_hist_lookahead ? barmerge.lookahead_on : barmerge.lookahead_off
 
total_weight = tf_weight1 + tf_weight2 + tf_weight3 + tf_weight4
 
[ha_o1, ha_c1] = request.security(ticker.heikinashi(syminfo.tickerid), tf1, [open, close], lookahead = lookahead_in)
[ha_o2, ha_c2] = request.security(ticker.heikinashi(syminfo.tickerid), tf2, [open, close], lookahead = lookahead_in)
[ha_o3, ha_c3] = request.security(ticker.heikinashi(syminfo.tickerid), tf3, [open, close], lookahead = lookahead_in)
[ha_o4, ha_c4] = request.security(ticker.heikinashi(syminfo.tickerid), tf4, [open, close], lookahead = lookahead_in)
 
ha_trend1 = ha_c1 > ha_o1 ? 1 : ha_c1 < ha_o1 ? -1 : 0
ha_trend2 = ha_c2 > ha_o2 ? 1 : ha_c2 < ha_o2 ? -1 : 0
ha_trend3 = ha_c3 > ha_o3 ? 1 : ha_c3 < ha_o3 ? -1 : 0
ha_trend4 = ha_c4 > ha_o4 ? 1 : ha_c4 < ha_o4 ? -1 : 0
 
plotshape(3, 'TF 1 TTrend', shape.square, location.absolute, ha_trend1 == 1 ? color.green : ha_trend1 == -1 ? color.red : color.gray, size = size.small)
plotshape(2, 'TF 2 TTrend', shape.square, location.absolute, ha_trend2 == 1 ? color.green : ha_trend2 == -1 ? color.red : color.gray, size = size.small)
plotshape(1, 'TF 3 TTrend', shape.square, location.absolute, ha_trend3 == 1 ? color.green : ha_trend3 == -1 ? color.red : color.gray, size = size.small)
plotshape(0, 'TF 4 TTrend', shape.square, location.absolute, ha_trend4 == 1 ? color.green : ha_trend4 == -1 ? color.red : color.gray, size = size.small)
 
trend_score = tf_weight1 * ha_trend1 + tf_weight2 * ha_trend2 + tf_weight3 * ha_trend3 + tf_weight4 * ha_trend4
trend_color = trend_score > 0 ? color.from_gradient(trend_score, 0, total_weight, weak_bull_col, strong_bull_col) : trend_score < 0 ? color.from_gradient(trend_score, -total_weight, 0, strong_bear_col, weak_bear_col) : color.gray
 
plotshape(trend_score > 0 and trend_score[1] < 0, 'Bull Trend Signal', shape.triangleup, location.bottom, color.green, size = size.small)
plotshape(trend_score < 0 and trend_score[1] > 0, 'Bear Trend Signal', shape.triangledown, location.top, color.red, size = size.small)
 
barcolor(trend_color)
 
alertcondition(trend_score > 0 and trend_score[1] < 0, 'Bull Trend Signal Alert', 'MTF HA Bull Trend Signal')
alertcondition(trend_score < 0 and trend_score[1] > 0, 'Bear Trend Signal Alert', 'MTF HA Bear Trend Signal')

← 返回列表