Heikin Ashi MTF Trend [Pt]
Forums › ProRealTime forum Italiano › Supporto ProBuilder › Heikin Ashi MTF Trend [Pt]
- This topic has 4 replies, 2 voices, and was last updated 3 months ago by Iván.
-
-
07/18/2024 at 11:48 AM #235470
// 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)group_display = ‘Display Options’
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’)
show_trend_signal = input.bool(false, ‘Show Weighted Trend Signal’)display_style = input.string(‘Squares’, ‘Style’, options = [‘Squares’, ‘Lines’], group = group_display)
line_thickness = input.int(2, ‘ └ Line Thickness’, group = group_display)
bull_col = input.color(color.green, ‘Bull’, group = group_display, inline = ‘col2’)
bear_col = input.color(color.red, ‘Bear’, group = group_display, inline = ‘col2’)lookahead_in = show_hist_lookahead ? barmerge.lookahead_on : barmerge.lookahead_off
total_weight = tf_weight1 + tf_weight2 + tf_weight3 + tf_weight4
//Non repainting security
f_security(_symbol, _res, _src, _repaint) =>
request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]ha_o1 = f_security(ticker.heikinashi(syminfo.tickerid), tf1, open, show_hist_lookahead)
ha_c1 = f_security(ticker.heikinashi(syminfo.tickerid), tf1, close, show_hist_lookahead)
ha_o2 = f_security(ticker.heikinashi(syminfo.tickerid), tf2, open, show_hist_lookahead)
ha_c2 = f_security(ticker.heikinashi(syminfo.tickerid), tf2, close, show_hist_lookahead)
ha_o3 = f_security(ticker.heikinashi(syminfo.tickerid), tf3, open, show_hist_lookahead)
ha_c3 = f_security(ticker.heikinashi(syminfo.tickerid), tf3, close, show_hist_lookahead)
ha_o4 = f_security(ticker.heikinashi(syminfo.tickerid), tf4, open, show_hist_lookahead)
ha_c4 = f_security(ticker.heikinashi(syminfo.tickerid), tf4, close, show_hist_lookahead)// [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 lvl1 = 3 lvl2 = 2 lvl3 = 1 lvl4 = 0 plotshape(lvl1, 'TF 1 Trend', shape.square, location.absolute, display_style == 'Squares' ? ha_trend1 == 1 ? bull_col : ha_trend1 == -1 ? bear_col : color.gray : na, size = size.small) plotshape(lvl2, 'TF 2 Trend', shape.square, location.absolute, display_style == 'Squares' ? ha_trend2 == 1 ? bull_col : ha_trend2 == -1 ? bear_col : color.gray : na, size = size.small) plotshape(lvl3, 'TF 3 Trend', shape.square, location.absolute, display_style == 'Squares' ? ha_trend3 == 1 ? bull_col : ha_trend3 == -1 ? bear_col : color.gray : na, size = size.small) plotshape(lvl4, 'TF 4 Trend', shape.square, location.absolute, display_style == 'Squares' ? ha_trend4 == 1 ? bull_col : ha_trend4 == -1 ? bear_col : color.gray : na, size = size.small) plot(lvl1, 'TF 1 Trend', display_style == 'Lines' ? ha_trend1 == 1 ? bull_col : ha_trend1 == -1 ? bear_col : color.gray : na, linewidth = line_thickness) plot(lvl2, 'TF 2 Trend', display_style == 'Lines' ? ha_trend2 == 1 ? bull_col : ha_trend2 == -1 ? bear_col : color.gray : na, linewidth = line_thickness) plot(lvl3, 'TF 3 Trend', display_style == 'Lines' ? ha_trend3 == 1 ? bull_col : ha_trend3 == -1 ? bear_col : color.gray : na, linewidth = line_thickness) plot(lvl4, 'TF 4 Trend', display_style == 'Lines' ? ha_trend4 == 1 ? bull_col : ha_trend4 == -1 ? bear_col : color.gray : na, linewidth = line_thickness) 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(show_trend_signal and trend_score > 0 and ta.change(math.sign(trend_score)), ‘Bull Trend Signal’, shape.triangleup, location.bottom, bull_col, size = size.small)
plotshape(show_trend_signal and trend_score < 0 and ta.change(math.sign(trend_score)), 'Bear Trend Signal', shape.triangledown, location.top, bear_col, size = size.small) barcolor(show_bar_color ? trend_color : na) 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’)f_drawLabelX(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size, _textalign, _tooltip) =>
var id = label.new(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size, _textalign, _tooltip)
label.set_xy(id, _x, _y)
label.set_text(id, _text)
label.set_tooltip(id, _tooltip)
label.set_textcolor(id, _textcolor)
idif barstate.islast
f_drawLabelX(bar_index, lvl1, str.tostring(tf1), xloc.bar_index, yloc.price, chart.bg_color, label.style_label_left, chart.fg_color, size.small, text.align_left, ”)
f_drawLabelX(bar_index, lvl2, str.tostring(tf2), xloc.bar_index, yloc.price, chart.bg_color, label.style_label_left, chart.fg_color, size.small, text.align_left, ”)
f_drawLabelX(bar_index, lvl3, str.tostring(tf3), xloc.bar_index, yloc.price, chart.bg_color, label.style_label_left, chart.fg_color, size.small, text.align_left, ”)
f_drawLabelX(bar_index, lvl4, str.tostring(tf4), xloc.bar_index, yloc.price, chart.bg_color, label.style_label_left, chart.fg_color, size.small, text.align_left, ”)07/19/2024 at 8:38 AM #235500Ciao! Ecco l'indicatore. Tieni presente che ci sono alcune funzionalità che non possono essere implementate:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107//-------------------------------------------------------------////-------------------------------------------------------------//showarrows=1tfWeight1=10tfWeight2=20tfWeight3=30tfWeight4=40lvl1=3lvl2=2lvl3=1lvl4=0//-------------------------------------------------------------////-------------------------------------------------------------//timeframe(15mn)once haopen1=openhaclose1=(open+close+high+low)/4if barindex> 0 thenhaopen1=(haopen1+haclose1[1])/2endiftimeframe(30mn)once haopen2=openhaclose2=(open+close+high+low)/4if barindex> 0 thenhaopen2=(haopen2+haclose2[1])/2endiftimeframe(1h)once haopen3=openhaclose3=(open+close+high+low)/4if barindex> 0 thenhaopen3=(haopen3+haclose3[1])/2endiftimeframe(4h)once haopen4=openhaclose4=(open+close+high+low)/4if barindex> 0 thenhaopen4=(haopen4+haclose4[1])/2endif//-------------------------------------------------------------//timeframe(default)if haclose1>haopen1 thenhaTrend1=1r1=0g1=255elsif haclose1<haopen1 thenhatrend1=-1r1=255g1=0elsehatrend1=0r1=0g1=0endifif haclose2>haopen2 thenhaTrend2=1r02=0g02=255elsif haclose2<haopen2 thenhatrend2=-1r02=255g02=0elsehatrend2=0r02=0g02=0endifif haclose3>haopen3 thenhaTrend3=1r3=0g3=255elsif haclose3<haopen3 thenhatrend3=-1r3=255g3=0elsehatrend3=0r3=0g3=0endifif haclose4>haopen4 thenhaTrend4=1r4=0g4=255elsif haclose4<haopen4 thenhatrend4=-1r4=255g4=0elsehatrend4=0r4=0g4=0endif//-------------------------------------------------------------////-------------------------------------------------------------//trendScore=tfWeight1*hatrend1+tfWeight2*hatrend2+tfWeight3*hatrend3+tfWeight4*hatrend4if showarrows thenif trendScore>0 and trendScore[1]<0 thendrawarrowup(barindex,1.5)coloured("green")elsif trendScore<0 and trendScore[1]>0 thendrawarrowdown(barindex,1.5)coloured("red")endifendif//-------------------------------------------------------------//return lvl1 as "Tf15mn Trend" coloured(r1,g1,0)style(line,5),lvl2 as "Tf30mn Trend" coloured(r02,g02,0)style(line,5),lvl3 as "Tf1H Trend" coloured(r3,g3,0)style(line,5),lvl4 as "Tf4h Trend" coloured(r4,g4,0)style(line,5)07/19/2024 at 8:57 AM #235502Lo he modificado ligeramente para darle otro aspecto:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122//-------------------------------------------------------------////PRC_Heikin Ashi MTF Trend//version = 0//19.07.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//-------------------------------------------------------------//showarrows=0tfWeight1=10tfWeight2=20tfWeight3=30tfWeight4=40lvl1=2.5lvl2=1.5lvl3=-1.5lvl4=-2.5//-------------------------------------------------------------////-------------------------------------------------------------//timeframe(15mn)once haopen1=openhaclose1=(open+close+high+low)/4if barindex> 0 thenhaopen1=(haopen1+haclose1[1])/2endiftimeframe(30mn)once haopen2=openhaclose2=(open+close+high+low)/4if barindex> 0 thenhaopen2=(haopen2+haclose2[1])/2endiftimeframe(1h)once haopen3=openhaclose3=(open+close+high+low)/4if barindex> 0 thenhaopen3=(haopen3+haclose3[1])/2endiftimeframe(4h)once haopen4=openhaclose4=(open+close+high+low)/4if barindex> 0 thenhaopen4=(haopen4+haclose4[1])/2endif//-------------------------------------------------------------//timeframe(default)if haclose1>haopen1 thenhaTrend1=1r1=0g1=255elsif haclose1<haopen1 thenhatrend1=-1r1=255g1=0elsehatrend1=0r1=0g1=0endifif haclose2>haopen2 thenhaTrend2=1r02=0g02=255elsif haclose2<haopen2 thenhatrend2=-1r02=255g02=0elsehatrend2=0r02=0g02=0endifif haclose3>haopen3 thenhaTrend3=1r3=0g3=255elsif haclose3<haopen3 thenhatrend3=-1r3=255g3=0elsehatrend3=0r3=0g3=0endifif haclose4>haopen4 thenhaTrend4=1r4=0g4=255elsif haclose4<haopen4 thenhatrend4=-1r4=255g4=0elsehatrend4=0r4=0g4=0endif//-------------------------------------------------------------////-------------------------------------------------------------//totalWeight=tfWeight1+tfWeight2+tfWeight3+tfWeight4trendScore=(tfWeight1*hatrend1+tfWeight2*hatrend2+tfWeight3*hatrend3+tfWeight4*hatrend4)/totalWeightif showarrows thenif trendScore>0 and trendScore[1]<0 thendrawarrowup(barindex,0)coloured("green")elsif trendScore<0 and trendScore[1]>0 thendrawarrowdown(barindex,0)coloured("red")endifendifif trendScore > 0 thenr=51g=255b=255elser=255g=102b=255endif//-------------------------------------------------------------//return lvl1 as "Tf15mn Trend" coloured(r1,g1,0)style(line,5),lvl2 as "Tf30mn Trend" coloured(r02,g02,0)style(line,5),lvl3 as "Tf1H Trend" coloured(r3,g3,0)style(line,5),lvl4 as "Tf4h Trend" coloured(r4,g4,0)style(line,5), 0 style(dottedline2,2), trendScore coloured(r,g,b)style(histogram,1)07/20/2024 at 5:37 AM #235543Grazie mille e complimenti.
Vorrei utilizzare questo indicatore essenzialmente come filtro per le strategie di inseguimento del trend di media durata (timeframe giornalieri posizionamenti che durano settimane per capirci).
Come filtro di entrata che eviti l’apertura di posizioni in fasi laterali ma che aiuti anche a rilevare il cambiamento di trend sul timeframe sottostante per anticipare l’uscita dalla posizione prima di conferme più “importanti”.
Vedo però che Proreal obbliga a lavorare su tmeframe multipli… proverò a farlo lavorare su frame orario o giornaliero ritoccato il codice (ora usandolo sul Daily da errore).
I frame che vorrei utilizzare sono 6 ore + Daily + Weekly
Grazie mille ancora
- Come faccio a compensarti ?
07/22/2024 at 10:22 AM #235618 -
AuthorPosts
Find exclusive trading pro-tools on