Conversión indicador EMA 9/21 con Precio Objetivo
Forums › ProRealTime foro Español › Soporte ProBuilder › Conversión indicador EMA 9/21 con Precio Objetivo
- This topic has 7 replies, 3 voices, and was last updated 9 months ago by Iván.
-
-
01/16/2024 at 11:32 AM #226412
Solicito si es posible, ayuda para intentar convertir el indicador adjunto.
Dicho indicador procede de Tradingview , utilizando arrays. Esencialmente, solo combina 2 EMA ( 9 y 21, totalmente configurables lógicamente) con un análisis basado en ATR para calcular el rango promedio que experimenta el precio después de un cruce de EMA 9 / 21 bien al alza o a la baja.
La longitud del ATR está predeterminada en 500, pero una vez más indico que es personalizable.
Adjunto gráfico y código:
// © Steversteves//@version=5indicator(“EMA 9/21 with Target Price [SS]”, overlay=true)arraylookback = input.float(500, “ATR Lookback Length”)showlbls = input.bool(true, “Show Target Price Labels”)ema9=ta.ema(close,9)ema21=ta.ema(close,21)// determine the crossover pointsema9_cross_ema21 = ta.crossover(ema9, ema21)ema21_cross_ema9 = ta.crossover(ema21, ema9)// plot arrows on the chart at the crossover pointsplotshape(ema9_cross_ema21 ? close : na, title=”Up Arrow”, location=location.belowbar, style=shape.triangleup, size=size.small, color=color.green)plotshape(ema21_cross_ema9 ? close : na, title=”Down Arrow”, location=location.abovebar, style=shape.triangledown, size=size.small, color=color.red)// sentimentboolbullish=close>=ema9andclose>=ema21boolbearish=close<=ema9andclose<=ema21boolneutral=close<ema9andclose>ema21// define coloursbull = color.new(color.lime, 50)bear= color.new(color.red,50)white= color.whiteneutralcolor=color.new(color.gray,50)crossovercolor = color.new(color.purple, 75)crossundercolor=color.new(color.orange,75)color pallette = bullish ? bull : bearish ? bear : neutralcolorcoloremacolor=ema9_cross_ema21?crossovercolor:ema21_cross_ema9?crossundercolor:pallettefilla=plot(ema9,color=emacolor,linewidth=1)fillb = plot(ema21, color=emacolor, linewidth=1)fill(filla, fillb, color=pallette)boolabove_ema=close>=ema9andclose>=ema21boolbelow_ema=close<ema9andclose<=ema21boolcrossover=ema9_cross_ema21boolcrossunder=ema21_cross_ema9bull_a=array.new_float()open_a=array.new_float()crossover_a=array.new_float()crossunder_a=array.new_float()bear_a=array.new_float()fori=0toarraylookbackifabove_ema[i]array.push(bull_a,close[i])ifcrossover[i]array.push(crossover_a, close[i])array.push(open_a,open[i])ifbelow_ema[i]array.push(bear_a,close[i])ifcrossunder[i]array.push(crossunder_a,close[i])max_above=array.max(bull_a)crossover_avg=array.avg(crossover_a)max_below=array.min(bear_a)crossunder_avg=array.avg(crossunder_a)bull_dif1=(max_above-crossover_avg)/2bull_dif2=(max_above-crossover_avg)bear_dif1=(crossunder_avg-max_below)/2bear_dif2=(crossunder_avg-max_below)floatop=0.0floatbull_tgt=0.0floatbull_tgt_2=0.0floatbear_tgt=0.0floatbear_tgt_2=0.0varlabelbull_tgt_1_lbl=navarlabelbull_tgt_2_lbl=navarlabelbear_tgt_1_lbl=navarlabelbear_tgt_2_lbl=navar line bull_tgt_lin = navarlinebull_tgt_lin_2=navarlinebear_tgt_lin=navarlinebear_tgt_lin_2=naifcrossoverif array.size(open_a) > 0op:=array.get(open_a,0)bull_tgt := op + bull_dif1bull_tgt_2 := op + bull_dif2ifcrossunderifarray.size(open_a)>0op:=array.get(open_a,0)bear_tgt:=op-bear_dif1bear_tgt_2:=op-bear_dif2if crossover and barstate.isconfirmedline.delete(bull_tgt_lin)line.delete(bull_tgt_lin_2)label.delete(bull_tgt_1_lbl)label.delete(bull_tgt_2_lbl)bull_tgt_lin := line.new(bar_index[1], y1 = bull_tgt, x2= bar_index, y2 = bull_tgt, extend = extend.right, color = bull, width=3)bull_tgt_lin_2 := line.new(bar_index[1], y1 = bull_tgt_2, x2= bar_index, y2 = bull_tgt_2, extend = extend.right, color = bull, width=3)ifshowlblsbull_tgt_1_lbl := label.new(bar_index[1], y = bull_tgt, text = “Bull Target 1 \n” + str.tostring(math.round(bull_tgt,2)), color = bull, textcolor = white)bull_tgt_2_lbl := label.new(bar_index[1], y = bull_tgt_2, text = “Bull Target 2 \n” + str.tostring(math.round(bull_tgt_2,2)), color = bull, textcolor = white)if crossunder and barstate.isconfirmedline.delete(bear_tgt_lin)line.delete(bear_tgt_lin_2)label.delete(bear_tgt_1_lbl)label.delete(bear_tgt_2_lbl)bear_tgt_lin:=line.new(bar_index[1],y1=bear_tgt,x2=bar_index,y2=bear_tgt,extend=extend.right,color=bear,width=3)bear_tgt_lin_2 := line.new(bar_index[1], y1 = bear_tgt_2, x2= bar_index, y2 = bear_tgt_2, extend = extend.right, color = bear, width=3)if showlblsbear_tgt_1_lbl := label.new(bar_index[1], y = bear_tgt, text = “Bear Target 1 \n” + str.tostring(math.round(bear_tgt,2)), color = bear, style=label.style_label_up, textcolor = white)bear_tgt_2_lbl := label.new(bar_index[1], y = bear_tgt_2, text = “Bear Target 2 \n” + str.tostring(math.round(bear_tgt_2,2)), color = bear, style=label.style_label_up, textcolor = white)alertcondition(crossover,”EMA 9/21 Crossover”,”Bullish Cross”)alertcondition(crossunder, “EMA 9/21 Crossunder”, “Bearish Cross”)01/16/2024 at 11:50 AM #226415No incrustes documentos (imágenes y otros archivos) en tus publicaciones, ya que esto ralentizará la carga de la página.
Utilice únicamente el botón “select file”.
Gracias 🙂
01/16/2024 at 12:19 PM #22642101/22/2024 at 7:12 PM #226732Buenas tardes, he intentado convertir yo mismo el indicador, pero dado mi desconocimiento de las arrays me indica lo siguiente: “se espera un campo entero positivo para SRC” y creo que es por algo relacionado con las arrays.
Podría alguien ayudarme.
Muchas gracias por anticipado.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172//EMA 9/21 with Target Pricearraylookback = 500ema9 = exponentialaverage[9](close)ema21 = exponentialaverage[21](close)bullish = close >= ema9 and close >= ema21bearish = close <= ema9 and close <= ema21neutral = close < ema9 and close > ema21aboveema = close >= ema9 and close >= ema21belowema = close < ema9 and close <= ema21crossover = ema9 crosses over ema21crossunder = ema21 crosses over ema9///////////////////////////////for i = 0 to arraylookbackif aboveema[i] then$bulla[i] = close[i]if crossover[i] then$crossovera[i] = close[i]$opena[i] = open[i]if belowema[i] then$beara[i] = close[i]if crossunder[i] then$crossundera[i] = close[i]endifendifendifendif/////////////////////////////maxabove = arraymax($bulla)crossoveravg = average($crossovera[arraylookback])maxbelow = arraymax($beara)crossunderavg = average($crossundera[arraylookback])bulldif1 = (maxabove - crossoveravg) / 2bulldif2 = (maxabove - crossoveravg)beardif1 = (crossunderavg - maxbelow) / 2beardif2 = (crossunderavg - maxbelow)if crossover thenif $opena[i] > 0 thenop= openbulltgt = round(op + bulldif1)bulltgt2 = round(op + bulldif2)if crossunder thenif $opena[i] > 0 thenop= openbeartgt = round(op - beardif1)beartgt2= round(op - beardif2)endifendifendifendifnextif crossover thenDRAWSEGMENT(barindex,op,barindex+10,op)coloured(255,255,0)DRAWSEGMENT(barindex,op,barindex+10,op)coloured(255,255,0)DRAWTEXT("#bulltgt#",barindex,open,SansSerif,Bold,16)coloured(153,0,0)DRAWTEXT("#bulltgt2#",barindex,open,SansSerif,Bold,16)coloured(153,0,0)endifif crossunder thenDRAWSEGMENT(barindex,op,barindex+10,op)coloured(255,255,0)DRAWSEGMENT(barindex,op,barindex+10,op)coloured(255,255,0)DRAWTEXT("#beartgt#",barindex,open,SansSerif,Bold,16)coloured(153,0,0)DRAWTEXT("#beartgt2#",barindex,open,SansSerif,Bold,16)coloured(153,0,0)endifreturn02/12/2024 at 7:21 PM #22801502/13/2024 at 9:01 AM #22802402/13/2024 at 9:28 AM #22802702/13/2024 at 4:32 PM #228075Buenas!
Aquí tienes el código: https://www.prorealcode.com/prorealtime-indicators/ema-9-21-with-targets/ -
AuthorPosts
Find exclusive trading pro-tools on