Salve,
sto cercando un modo per individuale automaticamente tutte le divergenze (dirette e nascoste) presenti tra prezzo ed RSI a 12 periodi, ho navigato nella libreria ed ho importato il codice qui sotto, ma funziona solo per le divergenze dirette (disegnando dei segmenti colorati direttamente sul RSI), ma a seconda di come viene settato il periodo (N=numero di barre) individua (alternativamente) solo quelle di breve termine o solo quelle più “lunghe”, mentre io vorrei che venissero individuate tutte; ed inoltre non trova le divergenze nascoste.
///N= ///N is the number of bars to look back for a divergence.
myrsi = RSI[12](close)
IF (myrsi[1]>myrsi AND myrsi[1]>myrsi[2]) THEN
newmaxrsi=myrsi[1]
oldmaxrsi=highest[N](myrsi)
newmaxprice=close[1]
oldmaxprice=Highest[N](close)
IF(newmaxrsi<oldmaxrsi AND newmaxprice>oldmaxprice[1]) THEN
for j=1 to N
if myrsi[j]=oldmaxrsi then
zzr=j
drawsegment (barindex[1], myrsi[1], barindex[zzr], myrsi[zzr])coloured(155,0,0)style(line,2)
DRAWPOINT(barindex[1], myrsi[1],1)coloured(155,0,0,0)BORDERCOLOR(155,0,0)
DRAWPOINT(barindex[zzr], myrsi[zzr],1)coloured(155,0,0,0)BORDERCOLOR(155,0,0)
endif
next
endif
endif
IF (myrsi[1]<myrsi AND myrsi[1]<myrsi[2]) THEN
newminrsi=myrsi[1]
oldminrsi=lowest[N](myrsi)
newminprice=close[1]
oldminprice=lowest[N](close)
IF(newminrsi>oldminrsi AND newminprice<oldminprice[1]) THEN
for j2=1 to N
if myrsi[j2]=oldminrsi then
zzr2=j2
drawsegment (barindex[1], myrsi[1], barindex[zzr2], myrsi[zzr2])coloured(0,155,0)style(line,2)
DRAWPOINT(barindex[1], myrsi[1],1)coloured(0,155,0,0)BORDERCOLOR(0,155,0)
DRAWPOINT(barindex[zzr2], myrsi[zzr2],1)coloured(0,155,0,0)BORDERCOLOR(0,155,0)
endif
next
endif
endif
return myrsi as "RSI"
Andando avanti nella ricerca ho trovato questo secondo codice, che ho personalizzato, che dovrebbe individuare entrambi i tipi di divergenze con delle frecce sul grafico in alto, ma non esce assolutamente nulla.
//RSI Divergences By Frank (Francesco)
//Description: the indicator draws arrows on chart as entry points when a direct or an hidden RSI divergence is found.
//When a DIRECT divergence is found, "dd" (direct divergence) text is added to chart over (Sell signal) or under (Buy signal) the arrow
//When an HIDDEN or INVERSE divergence is found, "hd" (hidden divergence) text is added to chart over (Sell signal) or under (Buy signal) the arrow
//Variables:
//RsiPeriod: number of bars to calculare RSI value
//RsiOverSold: Oversold Level
//RsiOverBought: OverBought Level
//MinBarRange: minimum distance from two consecutive RSI Highs or RSI Lows
Rge = averagetruerange[10](close)
MyRSI = rsi[RsiPeriod](Close)
ONCE ShiftText = 3
RsiMax = MyRSI < MyRSI[1] and MyRSI[1] > MyRSI[2] and MyRSI[1] > RsiOverBought
RsiMin = MyRSI > MyRSI[1] and MyRSI[1] < MyRSI[2] and MyRSI[1] < RsiOverSold
if RsiMax then
RSIMax1 = MyRSI[1]
High1 = Close[1]
for I = MinBarRange to 40
if RsiMax[I] then
RSIMax2 = MyRSI[I + 1]
High2 = Close[I + 1]
If High1 > High2 and RSIMax1 < RSIMax2 then
DRAWARROWDOWN(barindex, High + Rge / ShiftText)coloured(255,192,203,255)
DRAWTEXT("dd", barindex, High + Rge / ShiftText / 0.3,SansSerif,Italic,10)coloured(0,0,255,255)
elsif High1 < High2 and RSIMax1 > RSIMax2 then
DRAWARROWDOWN(barindex, High + Rge / ShiftText)coloured(255,192,203,255)
DRAWTEXT("hd", barindex, High + Rge / ShiftText / 0.2,SansSerif,Italic,10)coloured(0,0,255,255)
endif
break
endif
next
endif
if RsiMin then
RSIMin1 = MyRSI[1]
Low1 = Close[1]
for I = MinBarRange to 80
if RSIMin[I] then
RSIMin2 = MyRSI[I + 1]
Low2 = Close[I + 1]
If Low1 < Low2 and RSIMin1 > RSIMin2 then
DRAWARROWUP(barindex, lOW - Rge / ShiftText)coloured(0,0,255,255)
DRAWTEXT("dd", barindex, lOW - Rge / ShiftText / 0.3,SansSerif,Italic,10)coloured(0,0,255,255)
elsif Low1 > Low2 and RSIMin1 < RSIMin2 then
DRAWARROWUP(barindex, lOW - Rge / ShiftText)coloured(0,0,255,255)
DRAWTEXT("hd", barindex, lOW - Rge / ShiftText / 0.2,SansSerif,Italic,10)coloured(0,0,255,255)
endif
break
endif
next
endif
return
Grazie in anticipo per il prezioso aiuto
Cordialmente
P