R05Participant
Veteran
Ciao Roberto io ho il seguente sistema che cerca di usare lo zig zag appositamente creato, ovviamente non da me. Premetto che in queste prove sto usando il dax time frame 30 secondi con zig zag settato a 12 punti. Il sistema ha però delle lacune che io non riesco proprio a risolvere. Te le elenco:
- Il sistema apre la posizione alla chiusura della candela, mi spiego meglio: una volta individuati i punti A, B e C, qualora una candela chiuda sopra il punto B mi entra all’apertura della candela successiva con conseguente entrata in taluni casi molto ritardata; a me serve che entri direttamente alla rottura del punto B (ti allego come esempio il file “esempio1” della giornata del 28 agosto alle ore 09:01)
- In data 29 agosto alle 9:38:30 il sistema ha fatto un’operazione long che non doveva fare mentre invece avrebbe dovuto fare l’operazione short delle 9:26 cosa che non ha fatto (ti allego come esempio il file “esempio2”)
Ti ringrazio.
DEFPARAM preloadbars=6000
DEFPARAM CumulateOrders = True
DEFPARAM FlatBefore = 090000
DEFPARAM FlatAfter = 173000
//------------parametri trading system----------
once contratti=1
once stoploss=40
once targetprofit=50
once pivotmargine=5
once livellobreakeven=100
once betargetprofit=5
once stoplossSAR=45
once targetprofitSAR=50
once maxritardozig30s=500
once punti30s=12
once maxstoploss30s=30
once tscmin=10
once tstop=8
once contr=contratti
lz, sz, sarz, sarsl, llvl, slvl, line0 = CALL "Zig-Zag ottimizzato"[1, 12, 4, 30, 1, 40, 90000, 215500, 1, 0]
//------------------------------------
once pm=pivotmargine
close0=close[0]
dh=dhigh(1)
dl=dlow(1)
dc=dclose(1)
P=(dh+dl+dc)/3
pR1=2*P-dl
pS1=2*P-dh
pR2=P+dh-dl
pS2=P+dl-dh
pR3=dh+2*(P-dl)
pS3=dl-2*(dh-P)
t=time
posperf=positionperf(0)
cpos=countofposition[0]
cpos1=countofposition[1]
posix=positionprice[0]
c2 = lz CROSSES OVER llvl
c3 = lz <= line0
c4 = sz CROSSES UNDER slvl
c5 = sz >= line0
c7=sarz>0
c8=sarz<=0
c9=sarsl<0
c10=sarsl>0
c11=posperf<0
once az2=close0
once pz12=close0
once pz22=close0
once zmax2=1
once zmin2=1
once amax2=close0
once amin2=close0
if t mod 100 = 0 then
cl1=cl0
cl0=close0
amax2=max(amax2,cl0)
amin2=min(amin2,cl0)
if amax2-cl0>=punti30s and zmin2 then
zmax2=1
zmin2=0
pz22=pz12
pz12=az2
az2=amax2
amin2=cl0
operato2=0
endif
if cl0-amin2>=punti30s and zmax2 then
zmax2=0
zmin2=1
pz22=pz12
pz12=az2
az2=amin2
amax2=cl0
operato2=0
endif
okstop=abs(pz22-pz12)<=maxstoploss30s
endif
long30s=zmin2 and cl0>pz12 and cl1<=pz12 and az2>=pz22 and not operato2 and okstop
short30s=zmax2 and cl0<pz12 and cl1>=pz12 and az2<=pz22 and not operato2 and okstop
if long30s then
zig30s=1
operato2=1
elsif short30s then
zig30s=-1
operato2=1
else
zig30s=0
endif
// Condizioni per entrare su posizioni long
once okl=0
l=c2
l2=cpos<>0 AND c2
IF (c7 or c11) and l2 THEN
contr=max(cpos,contratti)*1
tl=close0+targetprofitSAR
sl=stoplossSAR
okl=1
elsif (summation[maxritardozig30s](l)>0 and zig30s=1) or (summation[maxritardozig30s](zig30s=1)>0 and l)then
contr=contratti
tl=close0+targetprofit
sl=stoploss
okl=1
else
okl=0
ENDIF
if okl then
if P<=tl and tl<=P+pm then
tp=p-close0
elsif pr1<=tl and tl<=pr1+pm then
tp=pr1-close0
elsif pr2<=tl and tl<=pr2+pm then
tp=pr2-close0
elsif ps1<=tl and tl<=ps1+pm then
tp=ps1-close0
elsif ps2<=tl and tl<=ps2+pm then
tp=ps2-close0
elsif pr3<=tl and tl<=pr3+pm then
tp=pr3-close0
elsif ps3<=tl and tl<=ps3+pm then
tp=ps3-close0
else
tp=tl-close0
endif
BUY contr CONTRACT AT MARKET
trailst=0
be=0
ENDIF
// Condizioni per entrare su posizioni short
once oks=0
s=c4
s2=cpos<>0 AND c4
IF (c8 or c11) and s2 THEN
contr=max(cpos,contratti)*1
tl=close0-targetprofitSAR
sl=stoplossSAR
oks=1
elsif (summation[maxritardozig30s](s)>0 and zig30s=-1)or (summation[maxritardozig30s](zig30s=-1)>0 and s) then
contr=contratti
tl=close0-targetprofit
sl=stoploss
oks=1
else
oks=0
ENDIF
if oks then
if P-pm<=tl and tl<=P+pm then
tp=close-p
elsif pr1-pm<=tl and tl<=pr1+pm then
tp=close0-pr1
elsif pr2-pm<=tl and tl<=pr2+pm then
tp=close0-pr2
elsif ps1-pm<=tl and tl<=ps1+pm then
tp=close0-ps1
elsif ps2-pm<=tl and tl<=ps2+pm then
tp=close0-ps2
elsif pr3-pm<=tl and tl<=pr3+pm then
tp=close0-pr3
elsif ps3-pm<=tl and tl<=ps3+pm then
tp=close0-ps3
else
tp=close0-tl
endif
SELLSHORT contr CONTRACT AT MARKET
trailst=0
be=0
endif
if cpos>0 then
if cpos1<=0 then
slcl=posix-sl
tscl=posix+tscmin
prezzots=slcl
endif
if close0>=posix+livellobreakeven and not be then
slcl=posix+betargetprofit
be=1
endif
if close0>=tscl and not trailst then
prezzots=close0-tstop
trailst=1
endif
if trailst then
prezzots=max(prezzots,close0-tstop)
endif
if trailst or be then
prezzoexit=max(prezzots,slcl)
SELL AT prezzoexit STOP
endif
elsif cpos<0 then
if cpos1>=0 then
slcs=posix+sl
tscl=posix-tscmin
prezzots=slcs
endif
if close0<=posix-livellobreakeven and not be then
slcs=posix-betargetprofit
be=1
endif
if close0<=tscl and not trailst then
prezzots=close0+tstop
trailst=1
endif
if trailst then
prezzots=min(prezzots,close0+tstop)
endif
if trailst or be then
prezzoexit=min(prezzots,slcs)
EXITSHORT AT prezzoexit STOP
endif
else
trailst=0
be=0
endif
// Condizioni per uscire da posizioni long
IF c3 OR c9 THEN
SELL AT MARKET
ENDIF
// Condizioni per uscire da posizioni short
IF c5 OR c10 THEN
EXITSHORT AT MARKET
ENDIF
// Stop e target
SET STOP pLOSS sl
SET TARGET pPROFIT tp
Mi serve l’indicatore, postalo oppure indica un link dove trovarlo (purché tu non l’abbia modificato, altrimenti devi postare il tuo).
R05Participant
Veteran
Si Roberto grazie ti allego l’indicatore.
Poi volevo, gentilmente, aggiungere due cose:
- vorrei che il sistema facesse lo stop and reverse in modo da recuperare subito la perdita (ma mi sa che il sistema già in parte lo fa anche se non so con quali criteri)
- lo stop loss deve essere poco sotto il punto C per avere una perdita inferiore
Lo ZigZag è un indicatore REPAINTING, cioè che torna indietro per modificare l’aspetto sul grafico al verificarsi di certe condizioni, cosa non possibile nelle strategie. Quindi, insieme ad alcuni altri (tipo DPO) NON può essere utilizzato con ProOrder.
R05Participant
Veteran
Ok Roberto grazie comunque.
Un’ultima cosa riguardante lo zig zag: a questo link https://www.prorealcode.com/courses/prorealtime-advanced-programming/ potrei imparare sulla programmazione delle cose avanzate tra cui appunto la possibilità di creare ad hoc un indicatore zig zag: la domanda è: se dovessi fare il corso e imparare a creare l’indicatore zig zag, questo, poi, lo posso usare in un’eventuale strategia automatica?