Buonasera,
sono alle prime armi con ProRealCode.
Per imparare, sto cercando di programmare un TS semplice, che utilizzo quotidianamente nel trading discrezionale, e che ha le seguenti caratteristiche:
- entry al primo cambio di colore del supertrend, dopo le 8:00
- Target1 e Target2
- stop & reverse
Ringrazio Nicolas, che in altro topic mi ha aiutato col supertrend 😉
Ora però ho difficoltà con lo Stop & reverse: ho preso il codice da alcuni post ed ho cercato di adattarlo alle mie esigenze, ma ancora non funziona….
DEFPARAM FlatAfter = 223000
st = supertrend[3,10]
CambioVerde = close[1] < st[1] AND close > st
CambioRosso = close[1] > st[1] AND close < st
ncontr=2
if intradaybarindex=0 then
traded=0
reverse=0
endif
// ENTRY
if traded=0 then
//LONG
IF NOT ONMARKET AND TIME > 075500 AND CambioVerde THEN
BUY ncontr contracts AT MARKET
traded=1
reverse=1
ENDIF
//SHORT
IF NOT ONMARKET AND TIME > 075500 AND CambioRosso THEN
SELLSHORT ncontr contracts AT MARKET
traded=2
reverse=1
ENDIF
endif
//Reverse
if reverse=1 then
if traded=1 AND NOT ONMARKET AND POSITIONPERF(1)<0 THEN
SELLSHORT ncontr contracts AT MARKET
reverse=0
ENDIF
IF traded=2 AND NOT ONMARKET AND POSITIONPERF(1)<0 THEN
BUY ncontr contracts AT MARKET
reverse=0
ENDIF
endif
SET STOP pLOSS mystop
SET TARGET pPROFIT mytarget
Inoltre, sto cercando di capire come si potrebbero programmare e gestire 2 TARGET con prorealcode.
Infatti, vorrei che questo TS entrasse con più contratti e liquidasse 1/2 posizione a target 1 e l’altra 1/2 posizione a target 2.
Mi sembra, però, che i comandi “SET STOP LOSS….” e “SET TARGET PROFIT” chiudano l’intera posizione, senza permettere di distinguere tra più target. E’ così? E’ giusto?
Se è così – spero di avere capito bene – immagino di dover definire, con apposita variabili, i livelli di entry, stop, target1 e target 2, per poi utilizzare sia gli ordini “stop” che quelli “market”. Ad esempio:
....
IF condizioni THEN
BUY 2 contracts AT MARKET
entry=close
target1=close+(15*pointsize)
target2= close+(50*pointsize)
mystop=close-(15*pointsize)
ENDIF
..........
.........
SELL 1 contracts AT target1 STOP
//(o anche...)
IF condizioni AND high >= target2 THEN
SELL 1 contracts AT MARKET
//(o anche, per lo stop...)
SET STOP pLOSS mystop
Ringrazio anticipatamente tutti gli amici di questo Forum che volessero darmi indicazioni e suggerimenti.
Gian Paolo