Ciao, sto cercando di realizzare un sistema che, ogni giorno alle 14:00, verifichi le 15 barre precedenti per trovare il MAX HIGH e MIN LOW e utilizzarli come livelli di breakout.
Il sistema deve chiudere tutte le posizioni alle 23:00
Il codice che posto qui di seguito non esegue nulla… qualcuno saprebbe aiutarmi? grazie mille
Fabio
EnterTime = 140000
ExitTime = 230000
SetTP = 0
SetSL = 0
VarTP = 100000
VarSL = 100000
IF Time = EnterTime THEN
Hi = highest[15](High)
Lo = lowest[15](Low)
IF CLOSE > Hi THEN
BUY 1 CONTRACT AT MARKET
ELSIF close < Lo THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
ENDIF
IF LONGONMARKET AND TIME = ExitTime THEN
SELL 1 CONTRACT AT MARKET
ENDIF
IF SHORTONMARKET AND TIME = ExitTime THEN
EXITSHORT 1 CONTRACT AT MARKET
ENDIF
IF SetTP = 1 Then
SET TARGET PPROFIT varTP
endif
IF SETSL = 1 Then
SET STOP PLOSS varSL
endif
IF CLOSE > Hi(1) THEN
BUY 1 CONTRACT AT MARKET
ELSIF close < Lo(1) THEN
SELLSHORT 1 CONTRACT AT MARKET
Ciao, grazie mille per la risposta.
Però non capisco: HI e LO non dovrebbero già contenere i valori di massimo e minimo degli ultimi 15 giorni? Perchè devo inserire anche (1)?
Grazie
Fabio
Perché l’Hi e Lo in esame si riferiscono alle 15 candele precedenti e il periodo di osservazione non termina con la candela attuale ma con quella precedente.
Ciao Il sistema non fa nulla perché l'espressione close > highest[15](High) non sarà mai soddisfatta poiché è impossibile che il prezzo di chiusura superi il massimo delle ultime 15 barre compresa quella corrente. Per questo motivo phoentzs ti dice close > Hi[1] in modo che cerchi il massimo delle 15 candele precedenti a quella attuale. Spero di essermi spiegato. Partendo dal tuo codice, ti lascio qui un codice che può servirti da guida:
defparam cumulateorders = false
EnterTime = 140000
ExitTime = 230000
SetTP = 0
SetSL = 0
VarTP = 100000
VarSL = 100000
IF Time = EnterTime THEN
Hi = highest[15](High)
Lo = lowest[15](Low)
endif
//-----Long
IF not onmarket and CLOSE > Hi[1] and time > EnterTime and time < Exittime THEN
BUY 1 CONTRACT AT MARKET
endif
IF LONGONMARKET AND TIME >= ExitTime THEN
SELL AT MARKET
ENDIF
//-----Short
IF not onmarket and close < Lo[1] and time > EnterTime and time < Exittime THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
IF SHORTONMARKET AND TIME >= ExitTime THEN
EXITSHORT AT MARKET
ENDIF
graphonprice Hi coloured("blue")
graphonprice Lo coloured("red")
Grazie mille!!! Chiarissimo!