MaxParticipant
Average
Qui di seguito una domanda inviata a ProRealTime:
Buongiorno,
avrei bisogno del codice per chiudere la posizione quando la perdita supera un valore prestabilito.
Per esempio entro long con un incrocio di medie mobili (media breve crosses over media lunga) e rimango long finché le medie non s’incrociano nuovamente al ribasso.
quello che vorrei aggiungere è che quando la curva dell’equity perde un certo valore dall’ultimo massimo raggiunto il sistema esca dalla posizione.
grazie mille
E un esempio di risposta:
Perte=50 //in the currency of the stock
EMAbreve = Average[21](close)
EMAlunga = Average[90](close)
Long = (EMAbreve Crosses Over EMAlunga)
Short = (EMAbreve Crosses Under EMAlunga)
// Condizioni per entrare su posizioni long
IF NOT LongOnMarket AND Long THEN
BUY 1 CONTRACTS AT MARKET
maxlong=strategyprofit
ENDIF
// Condizioni per entrare su posizioni short
IF NOT ShortOnMarket AND Short THEN
SELLSHORT 1 CONTRACTS AT MARKET
maxshort=strategyprofit
ENDIF
if longonmarket then
maxlong=max(maxlong,strategyprofit+((close -tradeprice)*COUNTOFLONGSHARES/POINTSIZE))
if strategyprofit+((close -tradeprice)*COUNTOFLONGSHARES/POINTSIZE) < maxlong-perte then
sell at market
endif
elsif shortonmarket then
maxshort=max(maxshort,strategyprofit+((tradeprice -close)*COUNTOFSHORTSHARES/POINTSIZE))
if strategyprofit+((tradeprice -close)*COUNTOFSHORTSHARES/POINTSIZE) <maxshort - perte then
exitshort at market
endif
endif
un traing profit dai massimi?
te la butta la velocemente
calcola highest di close
piualto= highest[20](close)
poi calcoli il prezzo di uscita di highest di close
prezzouscita= piualto/1.005 // se 0.5% di perdita
if long onmarket then
sell at prezzouscita limit
endif
messa molto velocemente