Ciao, creato un indicatore che riesca ad identificare le formazioni di candle pattern più significative. Ora volevo utilizzare lo stesso criterio per generare una strategia di lavoro ma il programma mi segnala una serie di errori. Dove sbaglio?
Grazie
allego codice e allarme:
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
// Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
DEFPARAM FLATBEFORE = 083000
// Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
DEFPARAM FLATAFTER = 201500
// Impedisce al sistema di tradare in giorni specifici della settimana
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
atr = averagetruerange[10](close)*0.5
body=close[1]-open[1]
body1=close[2]-open[2]
body2=close[3]-open[3]
body3=close[4]-open[4]
body4=close[5]-open[5]
abody=abs(body)
abody1=abs(body1)
abody2=abs(body2)
abody3=abs(body3)
abody4=abs(body4)
if range>0 then
ratio=abody/range
else
ratio=0
endif
dimension=abody/(averagetruerange[50]*2)
dimension1=abody1/(averagetruerange[50]*2)
dimension2=abody2/(averagetruerange[50]*2)
dimension3=abody3/(averagetruerange[50]*2)
dimension4=abody4/(averagetruerange[50]*2)
lunga=dimension > 0.3 and dimension <1
extralunga=dimension > 1
piccola=dimension<0.3
extrapiccola=dimension > 0 and dimension <0.1
lunga1=dimension1 > 0.3 and dimension1 <1
extralunga1=dimension1 > 1
piccola1=dimension1<0.3
extrapiccola1=dimension1 > 0 and dimension1 <0.1
lunga2=dimension2 > 0.3 and dimension2 <1
extralunga2=dimension2 > 1
piccola2=dimension2<0.3
extrapiccola2=dimension2 > 0 and dimension2 <0.1
lunga3=dimension3 > 0.3 and dimension3 <1
extralunga3=dimension3 > 1
piccola3=dimension3<0.3
extrapiccola3=dimension2 > 0 and dimension2 <0.1
lunga4=dimension4 > 0.3 and dimension4 <1
extralunga4=dimension4 > 1
piccola4=dimension4<0.3
extrapiccola4=dimension4 > 0 and dimension4 <0.1
mid=(open[1]+close[1])/2
mid1=(open[2]+close[2])/2
mid2=(open[3]+close[3])/2
mid3=(open[4]+close[4])/2
mid4=(open[5]+close[5])/2
Sbratio=0
Sbratio1=0
Sbratio2=0
Sbratio3=0
Sbratio4=0
if (shadowbottom / abody)<0.15 then
Sbratio=1
else
if (shadowbottom / abody) > 0.15 and (shadowbottom / abody) < 1 then
Sbratio=2
if (shadowbottom / abody) > 1 and (shadowbottom / abody) < 2 then
Sbratio=3
if (shadowbottom / abody) > 2 then
Sbratio=4
endif
endif
endif
endif
if (shadowbottom1 / abody1)<0.15 then
Sbratio1=1
else
if (shadowbottom1 / abody1) > 0.15 and (shadowbottom1 / abody1)< 1 then
Sbratio1=2
if (shadowbottom1 / abody1) > 1 and (shadowbottom1 / abody1) < 2 then
Sbratio1=3
if (shadowbottom1 / abody1) > 2 then
Sbratio1=4
endif
endif
endif
endif
if (shadowbottom2 / abody2)<0.15 then
Sbratio2=1
else
if (shadowbottom2 / abody2) > 0.15 and (shadowbottom2 / abody2) < 1 then
Sbratio2=2
if (shadowbottom2 / abody2) > 1 and (shadowbottom2 / abody2) < 2 then
Sbratio2=3
if (shadowbottom2 / abody2) > 2 then
Sbratio2=4
endif
endif
endif
endif
if (shadowbottom3 / abody3)<0.15 then
Sbratio3=1
else
if (shadowbottom3 / abody3) > 0.15 and (shadowbottom3 / abody3) < 1 then
Sbratio3=2
if (shadowbottom3 / abody3) > 1 and (shadowbottom3 / abody3) < 2 then
Sbratio3=3
if (shadowbottom3 / abody3) > 2 then
Sbratio3=4
endif
endif
endif
endif
if (shadowbottom4 / abody4)<0.15 then
Sbratio4=1
else
if (shadowbottom4 / abody4) > 0.15 and (shadowbottom4 / abody4) < 1 then
Sbratio4=2
if (shadowbottom4 / abody4) > 1 and (shadowbottom4 / abody4) < 2 then
Sbratio4=3
if (shadowbottom4 / abody4) > 2 then
Sbratio4=4
endif
endif
endif
endif
Stratio=0
Stratio1=0
Stratio2=0
Stratio3=0
Stratio4=0
if (shadowtop / abody)<0.15 then
Stratio=1
else
if (shadowtop / abody) > 0.15 and (shadowtop / abody) < 1 then
Stratio=2
if (shadowtop / abody) > 1 and (shadowtop / abody) < 2 then
Stratio=3
if (shadowtop / abody) > 2 then
Stratio=4
endif
endif
endif
endif
if (shadowtop1 / abody1)<0.15 then
Stratio1=1
else
if (shadowtop1 / abody1) > 0.15 and (shadowtop1 / abody1) < 1 then
Stratio1=2
if (shadowtop1 / abody1) > 1 and (shadowtop1 / abody1) < 2 then
Stratio1=3
if (shadowtop1 / abody1) > 2 then
Stratio1=4
endif
endif
endif
endif
if (shadowtop2 / abody2)<0.15 then
Stratio2=1
else
if (shadowtop2 / abody2) > 0.15 and (shadowtop2 / abody2) < 1 then
Stratio2=2
if (shadowtop2 / abody2) > 1 and (shadowtop2 / abody2) < 2 then
Stratio2=3
if (shadowtop2 / abody2) > 2 then
Stratio2=4
endif
endif
endif
endif
if (shadowtop3 / abody3)<0.15 then
Stratio3=1
else
if (shadowtop3 / abody3) > 0.15 and (shadowtop3 / abody3) < 1 then
Stratio3=2
if (shadowtop3 / abody3) > 1 and (shadowtop3 / abody3) < 2 then
Stratio3=3
if (shadowtop3 / abody3) > 2 then
Stratio3=4
endif
endif
endif
endif
if (shadowtop4 / abody4)<0.15 then
Stratio4=1
else
if (shadowtop4 / abody4) > 0.15 and (shadowtop4 / abody4) < 1 then
Stratio4=2
if (shadowtop4 / abody4) > 1 and (shadowtop4 / abody4) < 2 then
Stratio4=3
if (shadowtop4 / abody4) > 2 then
Stratio4=4
endif
endif
endif
endif
bodytop=max(open[1], close[1])
bodytop1=max(open[2], close[2])
bodytop2=max(open[3], close[3])
bodytop3=max(open[4], close[4])
bodytop4=max(open[5], close[5])
bodybottom=min(open[1], close[1])
bodybottom1=min(open[2], close[2])
bodybottom2=min(open[3], close[3])
bodybottom3=min(open[4], close[4])
bodybottom4=min(open[5], close[5])
shadowtop=high[1]-bodytop
shadowtop1=high[2]-bodytop1
shadowtop2=high[3]-bodytop2
shadowtop3=high[4]-bodytop3
shadowtop4=high[5]-bodytop4
shadowbottom=bodybottom-low[1]
shadowbottom1=bodybottom1-low[2]
shadowbottom2=bodybottom2-low[3]
shadowbottom3=bodybottom3-low[4]
shadowbottom4=bodybottom4-low[5]
longcandle= (ratio>0.6)
GapBottom=(bodybottom - bodytop1) / averagetruerange[7]
GapBottom1=(bodybottom1 - bodytop2) / averagetruerange[7]
GapBottom2=(bodybottom2 - bodytop3) / averagetruerange[7]
GapBottom3=(bodybottom3 - bodytop4) / averagetruerange[7]
Gaptop=(bodybottom1 - bodytop)/ averagetruerange[7]
Gaptop1=(bodybottom2 - bodytop1)/ averagetruerange[7]
Gaptop2=(bodybottom3 - bodytop2)/ averagetruerange[7]
Gaptop3=(bodybottom4 - bodytop3)/ averagetruerange[7]
TrendUp=(ADX[14]>23 AND DI[14](close)>0)
TrendDown=(ADX[14]>23 AND DI[14](close)<0)
MorningStar=lunga and piccola1 and lunga2 and body>0 and body2<0 and open[1]>Bodybottom1 and open[1]<open[3] and Bodybottom1<open[3] and close[1]>bodytop1 and bodytop1<close[3] and Bodybottom1<close[3] and close[1]>Bodybottom1 and bodytop1<open[3] and mid[2]<close[1] AND min(open,close) > bodybottom // and (close-open)>0
ThreeStarsInTheSouth=body2<0 and Sbratio2=2 and lunga2 and stratio2/abody2<0.1 and body1<0 and range[3]>range[2] and low[2]>low[3] and abody<abody1 and body<0 and close[1]>low[2] and close[1]<high[2] and sbratio/abody<0.1 and stratio/abody<0.1 AND min(open,close) > bodybottom // and (close-open)>0
ThreeLineStrike=body1<0 and body2<0 and body3<0 and close[4]>close[3] and close[3]>close[2] and body>0 and open[1]<close[2] and close[1]>open[4]AND min(open,close) > bodybottom // and (close-open)>0
MatHold=body4>0 and Gapbottom3>0.4 and lunga4 and body3<0 and body2<0 and abody4>abody3 and abody2<abody4 and abody1<abody4 and close[4]>bodybottom2 and bodybottom2>bodybottom1 and close[2]>low[5] and body>0 and lunga and close[1]>high[4]AND min(open,close)> bodybottom
ThreeOutsideUp=body2<0 and lunga1 and body1>0 and body>0 and open[2]<low[3] and close[2]>high[3] and open[1]>close[2]AND min(open,close)> bodybottom
RisingThreeMethods=body>0 and body4>0 and lunga4 and lunga and abody4>abody3 and abody4>abody2 and abody4>abody2 and abody>abody3 and abody>abody2 and abody>abody1 and bodybottom3>bodybottom2 and bodybottom2>bodybottom1 and bodytop3>bodytop2 and bodytop2>bodytop1 and low[2]>low[5] and low[3]>low[5] and low[4]>low[5] and high[4]<high[5] and high[3]<high[5] and high[2]<high[5] and close[1]>close[5]AND min(open,close)> bodybottom
BullishSeparatingLines=body1<0 and lunga1 and body>0 and ((max(bodytop1,bodybottom)-min(bodytop1,bodybottom))/abody)<0.2AND min(open,close)> bodybottom
BeltHoldLine=lunga and body>0 and Stratio=1 and low[1]=open[1]AND min(open,close)> bodybottom
AbandonedBaby=body2<0 and body>0 and lunga2 and lunga and extrapiccola1 and open[1]>high[2] and close[3]>high[2] and gaptop1 AND min(open,close)> bodybottom
ThreeStarsInTheNorth=body2>0 and stratio2=2 and lunga2 and sbratio2/abody2<0.1 and body1>0 and body>0 and range[3]>range[2] and high[3]>high[2] and abody<abody1 and close[1]>low[2] and close[1]<high[2] and stratio/abody<0.1 and sbratio/abody<0.1 AND max(open,close)< bodybottom
BearishEngulfing=body1>0 and body<0 and open[1]>close[2] and close[1]<open[2] and abody1/abody<0.6AND max(open,close)< bodybottom
IdenticalThreeCrows=body<0 and body1<0 and body2<0 and ((max(bodybottom2,bodytop1)-min(bodybottom2,bodytop1))/abody1)<0.1 and ((max(bodybottom1,bodytop)-min(bodybottom1,bodytop))/abody)<0.1 and lunga and lunga1 and lunga2 AND max(open,close)< bodybottom
BearishMatHold=body4<0 and body3>0 and body<0 and body1>0 and abody3<abody4 and close[5]>close[4] and bodybottom3<bodybottom2 and bodybottom2<bodybottom1 and Bodytop3<Bodytop2 and close[1]<low[4]AND min(open,close) > bodybottom
EveningStar=lunga and piccola1 and lunga2 and body<0 and body1>0 and body2>0 and open[1]<open[2] and open[1]>open[3] and open[2]>open[3] and close[1]<close[2] and close[1]<close[3] and close[2]>close[3] and mid<close[2] and mid<close[3] and mid1>close[3] and open[1]<close[2] and open[1]<close[3] and open[2]>close[3] and close[1]<open[2] and close[1]<open[3] and close[2]>open[3]AND max(open,close)< bodybottom
FallingThreeMethods=body<0 and body4<0 and lunga and lunga4 and abody>abody1 and abody>abody2 and abody>abody3 and abody4>abody1 and abody4>abody2 and abody4>abody3 and bodybottom3<bodybottom2 and bodybottom2<bodybottom1 and bodytop3<bodytop2 and bodytop2<bodytop1 and high[5]>bodytop1 and low[5]<bodybottom1 and close[1]<close[5]AND max(open,close)< bodybottom
BearishAbandonedBaby=body2>0 and body<0 and lunga2 and ((bodytop1-bodybottom1)/abody)<0.05 and lunga and open[1]<low[2] and gaptop AND max(open,close)< bodybottom
ThreeWhiteSoldiers=body2>0 and body1>0 and body>0 and abody1=>abody2 and abody=>abody1 and open[1]>open[2] and open[2]>open[3] and open[1]<close[2] and open[2]<close[3]AND min(open,close) > bodybottom
BullishHarami=body1<0 and body>0 and bodybottom>bodybottom1 and bodytop<bodytop1 and high[1]=<high[2] and low[1]=>low[2]AND min(open,close) > bodybottom
BearishHarami=body1>0 and body<0 and bodybottom>bodybottom1 and bodytop<bodytop1 and high[1]=<high[2] and low[1]=>low[2]AND max(open,close)< bodybottom
BullishHaramiInverted=body2<0 and body1>0 and body>0 and bodybottom1>bodybottom2 and bodytop1<bodytop2 and high[2]=<high[3] and low[2]=>low[3] and abody>abody1 and open[1]>open[2]AND min(open,close) > bodybottom
BearishHaramiInverted=body2>0 and body1<0 and body<0 and bodybottom1>bodybottom2 and bodytop1<bodytop2 and high[2]=<high[3] and low[2]=>low[3] and abody>abody1 and open[1]<open[2]AND min(open,close) > bodybottom
BullishEngulfing=body1<0 and body>0 and bodybottom<bodybottom1 and bodytop>bodytop1 and (abody1/abody)<0.6 AND min(open,close) > bodybottom
DarkCloudCover=body1>0 and body<0 and bodybottom<mid1 and bodybottom>open[2] and open[1]=>high[2]AND max(open,close)< bodybottom
PiercingLine=body1<0 and body>0 and bodytop>mid1 and bodytop<open[2] and open[1]=<low[2]AND min(open,close) > bodybottom
Hammer=piccola and shadowbottom/abody>2 and shadowtop/abody<0.1 AND min(open,close) > bodybottom
ShootingStar=piccola and shadowbottom/abody<0.1 and shadowtop/abody>2AND max(open,close)< bodybottom
DojiStar=open[1]=close[1] and (min(shadowtop,shadowbottom)/max(shadowtop,shadowbottom))<0.85 and (min(shadowtop,shadowbottom)/max(shadowtop,shadowbottom))>0.5 and shadowtop<(dimension*2)
DojiLongLeggend=open[1]=close[1] and (min(shadowtop,shadowbottom)/max(shadowtop,shadowbottom))<0.85 and (min(shadowtop,shadowbottom)/max(shadowtop,shadowbottom))>0.5 and shadowtop>(dimension*2)
DojiGravestone=open[1]=close[1] and low[1]=bodybottom and shadowtop>(dimension*2)AND max(open,close)< bodybottom
DojiDragonfly=open[1]=close[1] and high[1]=bodytop and shadowbottom>(dimension*2)AND max(open,close)< bodybottom
DojiFourPriced=open[1]=close[1] and high[1]=bodytop and low[1]=Bodybottom
LongWhite= body>0 and extralunga AND min(open,close) > bodybottom
LongBlack=body<0 and extralunga AND max(open,close)< bodybottom
WhiteMarabozu=body>0 and low[1]=bodybottom and high[1]=bodytop and lunga AND min(open,close) > bodybottom
BlackMarabozu=body<0 and low[1]=bodybottom and high[1]=bodytop and lunga AND max(open,close)< bodybottom
BlackOpeningMarabozu=body<0 and low[1]<bodybottom and high[1]=bodytop and lunga AND max(open,close)< bodybottom
WhiteOpeningMarabozu=body>0 and low[1]=bodybottom and high[1]>bodytop and lunga AND min(open,close) > bodybottom
WhiteClosingMarabozu=body>0 and low[1]<bodybottom and high[1]=bodytop and lunga AND min(open,close) > bodybottom
BlackClosingMarabozu=body<0 and low[1]=bodybottom and high[1]>bodytop and lunga AND max(open,close)< bodybottom
CanUpUp5=MatHold or RisingThreeMethods or BearishMatHold
CanUpUp3=ThreeWhiteSoldiers
CanUpUp2=BearishHaramiInverted or BullishSeparatingLines
CanDownUp5=BearishMatHold
CanDownup4=MatHold
CanDownUp3=ThreeOutsideUp or ThreeStarsInTheSouth or MorningStar or AbandonedBaby
CanDownUp2=PiercingLine or BullishHaramiInverted or BullishHarami or BullishEngulfing
CanDownUp1=Hammer or BeltHoldLine
CanUp1=DojiDragonfly or WhiteOpeningMarabozu or WhiteClosingMarabozu or WhiteMarabozu or LongWhite
CanUpDown3=EveningStar or IdenticalThreeCrows or ThreeStarsInTheNorth or BearishAbandonedBaby
CanUpDown2=BearishEngulfing or DarkCloudCover or BearishHarami
CanDownDown5=FallingThreeMethods
CanUpDown1=ShootingStar
CanDown1=DojiGravestone or BlackOpeningMarabozu or BlackClosingMarabozu or BlackMarabozu or LongBlack
IF (trandup and (CanUpUp5 or Canupup2 or Canupup3 or canup1)) AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
else
if (tranddown and (Candownup5 or Candownup3 or Candownup2 or candownup1)) AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
endif
IF (trandup and (CanUpdown3 or Canupdown2 or Canupdown1 or Candown1)) then
SELL AT MARKET
else
if (tranddown and Candowndown5 ) THEN
SELL AT MARKET
endif
ENDIF
IF (trandup and (CanUpdown3 or Canupdown2 or Canupdown1 or Candown1)) and not daysForbiddenEntry then
SELLSHORT 1 CONTRACT AT MARKET
else
if (tranddown and Candowndown5 ) and not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
endif
ENDIF
IF (trandup and (CanUpUp5 or Canupup2 or Canupup3 or canup1)) THEN
EXITSHORT AT MARKET
else
if (tranddown and (Candownup5 or Candownup3 or Candownup2 or candownup1)) THEN
EXITSHORT AT MARKET
ENDIF
endif