
Originariamente Scritto da
armando
Smash, se puoi riscriverlo ....... risolveresti al meglio l'uscita dai trend di questa strategia (da aggiungere a quanto ho detto ad Apo stamane)
Grazie x l'assiduo aiuto.
Armando
OK, allora proviamolo in questo altro modo:
Buy Script
INPUTS: @Gap(30)
INPUTS: @periods(14) , @price(CLOSE), @matype(EXPONENTIAL),
INPUTS: @trailAmount(100),@trailPercent(10), @stopLoss(400)
SET TRAILING_STOP = @trailAmount
SET TRAILING_PERCENT = @trailPercent
SET STOP_LOSS = @stopLoss
SET Gap = @Gap
SET a = MovingAverage(@price, 6, @matype)
SET b = MovingAverage(@price, 10, @matype)
SET c = MovingAverage(@price, 14, @matype)
SET d = MovingAverage(@price, 20, @matype)
SET e = MovingAverage(@price, 28, @matype)
SET f = LinearRegressionForecast(@price, 8)
SET g = LinearRegressionForecast(@price, 5)
SET BuyCondition = f - Gap > ( a + b + c + d + e / 5)
SET SellCondition = f + Gap < ( a + b + c + d + e / 5)
SET EntryCondition = BuyCondition - SellCondition
SET LastEntry = CHANGEIF(EntryCondition <> 0, EntryCondition)
SET LastEntryLong = IF(LastEntry = 1, 1, 0)
SET ExitLongCondition = CROSSOVER(a, g) * LastEntryLong
SET LongExited = CHANGEIF(LastEntryLong = ExitLongCondition, LastEntryLong)
BuyCondition AND NOT LongExited
Sell Script
SET Gap = @Gap
SET a = MovingAverage(@price, 6, @matype)
SET b = MovingAverage(@price, 10, @matype)
SET c = MovingAverage(@price, 14, @matype)
SET d = MovingAverage(@price, 20, @matype)
SET e = MovingAverage(@price, 28, @matype)
SET f = LinearRegressionForecast(@price, 8)
SET g = LinearRegressionForecast(@price, 5)
SET BuyCondition = f - Gap > ( a + b + c + d + e / 5)
SET SellCondition = f + Gap < ( a + b + c + d + e / 5)
SET EntryCondition = BuyCondition - SellCondition
SET LastEntry = CHANGEIF(EntryCondition <> 0, EntryCondition)
SET LastEntryShort = IF(LastEntry = -1, 1, 0)
SET ExitShortCondition = CROSSOVER(g, a) * LastEntryShort
SET ShortExited = CHANGEIF(LastEntryShort = ExitShortCondition, LastEntryShort)
SellCondition AND NOT ShortExited
ExitLong Script
SET a = MovingAverage(@price, 6, @matype)
SET g = LinearRegressionForecast(@price, 5)
CROSSOVER(a, g)
ExitShort Script
SET a = MovingAverage(@price, 6, @matype)
SET g = LinearRegressionForecast(@price, 5)
CROSSOVER(g, a)
Due precisazioni:
- ho trasformato quel valore di 30 in un parametro di Input, così se ne hai voglia lo potresti anche ottimizzare
- il sistema scritto in questo modo dovrebbe fermarsi in attesa di Reverse quando si verifica la condizione di ExitLong o di ExitShort, ma non necessariamente quando la posizione è stata chiusa realmente per l'ultima volta in ExitLong o ExitShort, in quanto al verificarsi dell'ExitLong o dell'ExitShort poteva essere già stata chiusa prima in TrailingStop senza poi essere stata mai riaperta.
Io comunque non lo complicherei più di così.
Provalo e poi fammi sapere!