Heikin Ashi MTF Trend [Pt]

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #235470 quote
    Gius
    Participant
    New

    // 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)
    id

    if 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, ”)

    #235500 quote
    Iván González
    Moderator
    Master

    Ciao! Ecco l'indicatore. Tieni presente che ci sono alcune funzionalità che non possono essere implementate:

    //-------------------------------------------------------------//
    //-------------------------------------------------------------//
    showarrows=1
    tfWeight1=10
    tfWeight2=20
    tfWeight3=30
    tfWeight4=40
    lvl1=3
    lvl2=2
    lvl3=1
    lvl4=0
    //-------------------------------------------------------------//
    //-------------------------------------------------------------//
    timeframe(15mn)
    once haopen1=open
    haclose1=(open+close+high+low)/4
    if barindex> 0 then
    haopen1=(haopen1+haclose1[1])/2
    endif
    timeframe(30mn)
    once haopen2=open
    haclose2=(open+close+high+low)/4
    if barindex> 0 then
    haopen2=(haopen2+haclose2[1])/2
    endif
    timeframe(1h)
    once haopen3=open
    haclose3=(open+close+high+low)/4
    if barindex> 0 then
    haopen3=(haopen3+haclose3[1])/2
    endif
    timeframe(4h)
    once haopen4=open
    haclose4=(open+close+high+low)/4
    if barindex> 0 then
    haopen4=(haopen4+haclose4[1])/2
    endif
    //-------------------------------------------------------------//
    timeframe(default)
    
    if haclose1>haopen1 then
    haTrend1=1
    r1=0
    g1=255
    elsif haclose1<haopen1 then
    hatrend1=-1
    r1=255
    g1=0
    else
    hatrend1=0
    r1=0
    g1=0
    endif
    
    if haclose2>haopen2 then
    haTrend2=1
    r02=0
    g02=255
    elsif haclose2<haopen2 then
    hatrend2=-1
    r02=255
    g02=0
    else
    hatrend2=0
    r02=0
    g02=0
    endif
    
    if haclose3>haopen3 then
    haTrend3=1
    r3=0
    g3=255
    elsif haclose3<haopen3 then
    hatrend3=-1
    r3=255
    g3=0
    else
    hatrend3=0
    r3=0
    g3=0
    endif
    
    if haclose4>haopen4 then
    haTrend4=1
    r4=0
    g4=255
    elsif haclose4<haopen4 then
    hatrend4=-1
    r4=255
    g4=0
    else
    hatrend4=0
    r4=0
    g4=0
    endif
    //-------------------------------------------------------------//
    //-------------------------------------------------------------//
    trendScore=tfWeight1*hatrend1+tfWeight2*hatrend2+tfWeight3*hatrend3+tfWeight4*hatrend4
    if showarrows then
    if trendScore>0 and trendScore[1]<0 then
    drawarrowup(barindex,1.5)coloured("green")
    elsif trendScore<0 and trendScore[1]>0 then
    drawarrowdown(barindex,1.5)coloured("red")
    endif
    endif
    //-------------------------------------------------------------//
    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)
    #235502 quote
    Iván González
    Moderator
    Master

    Lo he modificado ligeramente para darle otro aspecto:

    //-------------------------------------------------------------//
    //PRC_Heikin Ashi MTF Trend
    //version = 0
    //19.07.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------------------------------//
    showarrows=0
    tfWeight1=10
    tfWeight2=20
    tfWeight3=30
    tfWeight4=40
    lvl1=2.5
    lvl2=1.5
    lvl3=-1.5
    lvl4=-2.5
    //-------------------------------------------------------------//
    //-------------------------------------------------------------//
    timeframe(15mn)
    once haopen1=open
    haclose1=(open+close+high+low)/4
    if barindex> 0 then
    haopen1=(haopen1+haclose1[1])/2
    endif
    timeframe(30mn)
    once haopen2=open
    haclose2=(open+close+high+low)/4
    if barindex> 0 then
    haopen2=(haopen2+haclose2[1])/2
    endif
    timeframe(1h)
    once haopen3=open
    haclose3=(open+close+high+low)/4
    if barindex> 0 then
    haopen3=(haopen3+haclose3[1])/2
    endif
    timeframe(4h)
    once haopen4=open
    haclose4=(open+close+high+low)/4
    if barindex> 0 then
    haopen4=(haopen4+haclose4[1])/2
    endif
    //-------------------------------------------------------------//
    timeframe(default)
    
    if haclose1>haopen1 then
    haTrend1=1
    r1=0
    g1=255
    elsif haclose1<haopen1 then
    hatrend1=-1
    r1=255
    g1=0
    else
    hatrend1=0
    r1=0
    g1=0
    endif
    
    if haclose2>haopen2 then
    haTrend2=1
    r02=0
    g02=255
    elsif haclose2<haopen2 then
    hatrend2=-1
    r02=255
    g02=0
    else
    hatrend2=0
    r02=0
    g02=0
    endif
    
    if haclose3>haopen3 then
    haTrend3=1
    r3=0
    g3=255
    elsif haclose3<haopen3 then
    hatrend3=-1
    r3=255
    g3=0
    else
    hatrend3=0
    r3=0
    g3=0
    endif
    
    if haclose4>haopen4 then
    haTrend4=1
    r4=0
    g4=255
    elsif haclose4<haopen4 then
    hatrend4=-1
    r4=255
    g4=0
    else
    hatrend4=0
    r4=0
    g4=0
    endif
    //-------------------------------------------------------------//
    //-------------------------------------------------------------//
    totalWeight=tfWeight1+tfWeight2+tfWeight3+tfWeight4
    trendScore=(tfWeight1*hatrend1+tfWeight2*hatrend2+tfWeight3*hatrend3+tfWeight4*hatrend4)/totalWeight
    if showarrows then
    if trendScore>0 and trendScore[1]<0 then
    drawarrowup(barindex,0)coloured("green")
    elsif trendScore<0 and trendScore[1]>0 then
    drawarrowdown(barindex,0)coloured("red")
    endif
    endif
    if trendScore > 0 then
    r=51
    g=255
    b=255
    else
    r=255
    g=102
    b=255
    endif
    //-------------------------------------------------------------//
    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)
    
    #235543 quote
    Gius
    Participant
    New

    Grazie 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

    1. Come faccio a compensarti ?
    #235618 quote
    Iván González
    Moderator
    Master

    Prego! buona fortuna con la tua programmazione! Mi risarcisci? Grazie è sufficiente 😉

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Heikin Ashi MTF Trend [Pt]


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Gius @gius Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Iván González
1 year, 6 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 07/18/2024
Status: Active
Attachments: 2 files
Logo Logo
Loading...