Ho impostato una strategia short e vorrei che se il trade va in stop mi faccia lo stop e reverse UNA SOLA VOLTA. Riporto il codice che ho utilizzato. Il problema è che il trade (long) di stop and reverse continua a entrare di nuovo se anche il trade stop&reverse è andato in stop. Come posso fare per fare in modo che faccia SOLO un trade di stop e reverse e non continui a farne altri long indipendentemente dal profitto o stop di quest’ultimo? Grazie
//strategia short
if condizioni short then
sellshort 1 contract at market
mystop=20
Myprofit=30
endif
Set stop loss mystop
Set target profit myprofit
//strategia di stop&reverse
if strategyprofit<>strategyprofit[1] then
if positionperf(1)<0 then
if close>tradeprice(1) then
gain=-1
elsif close>tradeprice(1) then
gain=1
endif
else
gain=0
endif
endif
IF gain=-1 then
buy 1 contracts at market
mystopb= 20
Myprofitb=40
Set stop loss mystopb
Set target profit myprofitb
endif
Prova questo codice:
ONCE Trade = 0
//strategia short
if condizionishort then
sellshort 1 contract at market
mystop=20
Myprofit=30
Trade = -1
endif
Set stop loss mystop
Set target profit myprofit
//strategia di stop&reverse
IF Trade = -1 THEN
if strategyprofit<strategyprofit[1] then
buy 1 contracts at market
mystopb= 20
Myprofitb=40
Set stop loss mystopb
Set target profit myprofitb
Trade = 0
endif
endif
Il codice non legge la performance del sistema. Fa alternativamente short e long. Inoltre quando va in stop in base alla prima strategia non rispetta lo stop ma chiude come gli pare, anche in profitto (Nel mio codice era tutto ok con i valori tranne che continuava a fare a ripetizioni long e si fermava solo al primo trade di nuovo in profit)
Prova questa versione. Ho usato la tua ed ho solo inserito un flag per impedire che ci siano più operazioni LONG senza che prima ce ne sia stata una SHORT:
ONCE StopReverse = 0
//strategia short
if condizionishort then
sellshort 1 contract at market
mystop=20
Myprofit=30
StopReverse = 1
endif
Set stop loss mystop
Set target profit myprofit
//strategia di stop&reverse
if strategyprofit<>strategyprofit[1] then
if positionperf(1)<0 then
if close>tradeprice(1) then
gain=-1
elsif close>tradeprice(1) then
gain=1
endif
else
gain=0
endif
endif
IF gain=-1 then
IF StopReverse THEN
buy 1 contracts at market
mystopb= 20
Myprofitb=40
Set stop loss mystopb
Set target profit myprofitb
StopReverse = 0
ENDIF
endif