Med5Participant
Junior
Bonjour,
SVP, j’aime beaucoup l’indicateur PRC_Protein+, mais il ralentit fortement mes graphiques (parfois plusieurs secondes en UT 5min).
J’ai demandé à GPT de l’optimiser, et il m’a signalé que le ralentissement venait probablement de :
J’ai tenté une version corrigée avec lookbackLimit et une limite de pivots, mais le résultat n’est pas concluant.
Avez-vous une version optimisée qui ne provoque pas ce type de lenteur sans perdre sa logique ?
Merci beaucoup pour votre retour et votre aide comme toujours.
//---------------------------------------------------------//
//PRC_Protein +
//version = 0
//14.10.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//---------------------------------------------------------//
defparam drawonlastbaronly=true
//---------------------------------------------------------//
//----Inputs----------------------------------------------//
//---------------------------------------------------------//
length=10
leftbars=length
rightbars=length
src1 = low
src2 = high
boxwidth=5
atr=averagetruerange[50](close)
//---------------------------------------------------------//
//-----Calculate Pivots Low--------------------------------//
//---------------------------------------------------------//
if src1 > src1[rightbars] and lowest[rightbars](src1) > src1[rightbars] and src1[rightbars] < lowest[leftbars](src1)[rightbars+1] then
$ply[z+1] = src1[rightbars]
$plx[z+1] = barindex[rightbars]
$crossLow[z+1]=0
$Lowrightidx[z+1]=0
$atrLow[z+1]=atr
z = z + 1
endif
//---------------------------------------------------------//
//-----Calculate Pivots High-------------------------------//
//---------------------------------------------------------//
if src2 < src2[rightbars] and highest[rightbars](src2)<src2[rightbars] and src2[rightbars]>highest[leftbars](src2)[rightbars+1] then
$phy[t+1]=src2[rightbars]
$phx[t+1]=barindex[rightbars]
$crossHigh[t+1]=0
$Highrightidx[t+1]=0
$atrHigh[t+1]=atr
t=t+1
endif
//---------------------------------------------------------//
//-----Check for broken levels-----------------------------//
//---------------------------------------------------------//
n=barindex
if islastbarupdate then
for i=t downto 1 do
//drawpoint($phx[i],$phy[i],2)coloured("blue",50)
for j=barindex downto 0 do
if barindex[j]>$phx[i] and high[j]>$phy[i] and $crossHigh[i]=0 then
$crossHigh[i]=1
$Highrightidx[i]=barindex[j]
break
endif
next
if $crossHigh[i]=1 then
drawsegment($phx[i],$phy[i],$Highrightidx[i],$phy[i])coloured("red")style(dottedline)
else
drawrectangle($phx[i],$phy[i]-0.5*$atrHigh[i]*boxwidth/10,barindex,$phy[i]+0.5*$atrHigh[i]*boxwidth/10)coloured("red",0)fillcolor("red",30)
endif
next
for i=z downto 1 do
//drawpoint($plx[i],$ply[i],2)coloured("blue",50)
for j=barindex downto 0 do
if barindex[j]>$plx[i] and low[j]<$ply[i] and $crossLow[i]=0 then
$crossLow[i]=1
$Lowrightidx[i]=barindex[j]
break
endif
next
if $crossLow[i]=1 then
drawsegment($plx[i],$ply[i],$Lowrightidx[i],$ply[i])coloured("blue")style(dottedline)
else
drawrectangle($plx[i],$ply[i]-0.5*$atrLow[i]*boxwidth/10,barindex,$ply[i]+0.5*$atrLow[i]*boxwidth/10)coloured("blue",0)fillcolor("blue",30)
endif
next
endif
return
//---------------------------------------------------------//
//PRC_Protein + Stéroïdes
//version = 0
//14.10.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//---------------------------------------------------------//
defparam drawonlastbaronly = true
//---------------------------------------------------------//
//----Inputs----------------------------------------------//
//---------------------------------------------------------//
once length = 10
once leftbars = length
once rightbars = length
once boxwidth = 5
once coef = 0.05*boxwidth
once ShowOnlyLastPivots = 20
once idxPLow = -1
once idxPHigh = -1
atr=averagetruerange[50](close)
//---------------------------------------------------------//
//-----Calculate Pivots Low--------------------------------//
//---------------------------------------------------------//
if low[rightbars] = lowest[leftbars+rightbars+1](low) then
$plx[idxPLow+1] = barindex-rightbars
$Lowrightidx[idxPLow+1] = 0
$atrLow[idxPLow+1] = atr[rightbars]*coef
idxPLow = idxPLow+1
endif
//---------------------------------------------------------//
//-----Calculate Pivots High-------------------------------//
//---------------------------------------------------------//
if high[rightbars] = highest[leftbars+rightbars+1](high) then
$phx[idxPHigh+1] = barindex-rightbars
$Highrightidx[idxPHigh+1] = 0
$atrHigh[idxPHigh+1] = atr[rightbars]*coef
idxPHigh = idxPHigh+1
endif
//---------------------------------------------------------//
//-----Check for broken levels-----------------------------//
//---------------------------------------------------------//
If idxPHigh >= 0 then
for i= idxPHigh downto Max(0,idxPHigh-ShowOnlyLastPivots+1) do
if $Highrightidx[i] = 0 then
if high > High[barindex-$phx[i]] then
$Highrightidx[i] = barindex
endif
endif
if $Highrightidx[i] > 0 then
drawsegment($phx[i],High[barindex-$phx[i]],$Highrightidx[i],High[barindex-$phx[i]])coloured("red")style(dottedline)
else
drawrectangle($phx[i],High[barindex-$phx[i]]-$atrHigh[i],barindex,High[barindex-$phx[i]]+$atrHigh[i]) coloured("red",0) fillcolor("red",30)
endif
next
Endif
If idxPLow >= 0 then
for i= idxPLow downto Max(0,idxPLow-ShowOnlyLastPivots+1) do
if $Lowrightidx[i] = 0 then
if low < low[barindex-$plx[i]] then
$Lowrightidx[i] = barindex
endif
endif
if $Lowrightidx[i] > 0 then
drawsegment($plx[i],Low[barindex-$plx[i]],$Lowrightidx[i],Low[barindex-$plx[i]])coloured("blue")style(dottedline)
else
drawrectangle($plx[i],Low[barindex-$plx[i]]-$atrLow[i],barindex,Low[barindex-$plx[i]]+$atrLow[i]) coloured("blue",0) fillcolor("blue",30)
endif
next
Endif
return