Essentially, it just combines the 2 only EMA’s (the 9 and 21) with an ATR based analysis to calculate the average range a ticker undergoes after an EMA 9 / 21 Cross-over and Cross-under.
Author: Steversteves
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
//PRC_EMA 9-21 WITH TARGETS //version = 0 //13.02.24 //Iván González @ www.prorealcode.com //Sharing ProRealTime knowledge //////inputs arraylookback = 500 //Lookback length //////indicators ema9 = average[9,1](close) ema21 = average[21,1](close) //////Crossover points ema9crossema21 = ema9 crosses over ema21 ema21crossema9 = ema21 crosses over ema9 //////Plot arrows on the chart at the crossover points if ema9crossema21 then drawtext("▲",barindex,low-0.1*averagetruerange[10](close))coloured(0,250,0) elsif ema21crossema9 then drawtext("▼",barindex,high+0.1*averagetruerange[10](close))coloured(250,0,0) endif //////Sentiment if close >= ema9 and close >= ema21 then bullish = 1 bearish = 0 neutral = 0 r = 0 g = 230 b = 118 elsif close <= ema9 and close <= ema21 then bullish = 0 bearish = 1 neutral = 0 r = 255 g = 82 b = 82 else bullish = 0 bearish = 0 neutral = 1 r = 120 g = 123 b = 134 endif if barindex > 21 then COLORBETWEEN(ema9,ema21,r,g,b) endif //////Target prices aboveema = close >= ema9 and close >= ema21 belowema = close <= ema9 and close <= ema21 crossover = ema9crossema21 crossunder = ema21crossema9 for i=0 to arraylookback do if aboveema[i] then $bulla[i] = close[i] endif if crossover[i] then $crossovera[i] = close[i] $opena[i] = open[i] endif if belowema[i] then $beara[i] = close[i] endif if crossunder then $crossundera[i] = close[i] endif next opena = $opena[0] ///max close when close >= ema9 and close >= ema21 maxabove = arraymax($bulla) ///average of close when crossover if ema9 crosses over ema21 then crosstimes = 1+crosstimes avgcrossover = ($crossovera[0]+avgcrossover*crosstimes[1])/crosstimes endif ///min close when close <= ema9 and close <= ema21 maxbelow = arraymin($beara) ///average of close when crossunder if ema9 crosses under ema21 then crossundtimes = 1 + crossundtimes avgcrossund = ($crossundera[0]+avgcrossund*crossundtimes[1])/crossundtimes endif bulldif1 = (maxabove-avgcrossover)/2 bulldif2 = (maxabove-avgcrossover) beardif1 = (avgcrossund-maxbelow)/2 beardif2 = (avgcrossund-maxbelow) if crossover then if isset($opena[0]) then op = $opena[0] bulltgt1 = op+bulldif1 bulltgt2 = op+bulldif2 endif endif if crossunder then if isset($opena[0]) then op = $opena[0] beartgt1 = op-beardif1 beartgt2 = op-beardif2 endif endif if IsLastBarUpdate then drawsegment(barindex,bulltgt1,barindex+20,bulltgt1)coloured(0,250,0) drawsegment(barindex,bulltgt2,barindex+20,bulltgt2)coloured(0,250,0) drawsegment(barindex,beartgt1,barindex+20,beartgt1)coloured(250,0,0) drawsegment(barindex,beartgt2,barindex+20,beartgt2)coloured(250,0,0) endif return ema9 as "Ema9"COLOURED(r,g,b), ema21 as "Ema21"coloured(r,g,b) |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :
Filename : download the ITF files
How to import ITF files into ProRealTime platform?
PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Muchas gracias Iván
De nada!! espero que te resulte útil
¿Podrías darme algún consejo para que las flechitas rojas y verdes que aparecen cuando los indicadores cambian de dirección salgan más grandes, para poder apreciarlo mejor? Muchas gracias por el indicador.
Simplemente modifica las lineas 19 y 21 por las siguientes:
drawtext(“▲”,barindex,low-0.1*averagetruerange[10](close),Dialog,Bold,14)coloured(0,250,0)
drawtext(“▼”,barindex,high+0.1*averagetruerange[10](close),Dialog,Bold,14)coloured(250,0,0).
He añadido Dialog,Bold,14. Siendo 14 lo que determina el tamaño de las flechas.
Gracias!!
i copied the code into strategy and it gives error on line 21 and 23.
it says ” Line 1: one of the following character is more suitable then “DRAWTEXT”: ENDIF. so basically it doesn’t identify “Drawtext” as a code.