Bonjour à tous,
Quelqu’un saurait-il pourquoi cette stratégie très simple ne s’arrête pas après que le stop loss ait été touché ?
Que faudrait-il écrire ?
Merci merci !
Chris
defparam cumulateorders = false
n= round(1000/close)
// trailing stop : Moyenne Mobile de Hull
Period=50
inner = 2*weightedaverage[ round( Period/2 ) ](close)-weightedaverage[Period](close)
MMHULL=weightedaverage[ round( sqrt(Period) ) ]( inner )
//
VolBull = (high-open)*volume
MMVolBull = average[23](VolBull)
c1 = VolBull[1] > MMVolBull[1] or VolBull > MMVolBull
c2 = close crosses over MMHULL
if c1 and c2 then
buy n shares at Market
//first stoploss:
SL = MMHULL
set stop loss SL
dynamicSL = SL
if close <= SL then
quit
endif
endif
//dynamicSL
if longonmarket then
if(MMHULL>dynamicSL) then
dynamicSL=MMHULL
endif
sell at dynamicSL stop
if close <= dynamicSL then
quit
endif
endif
graph dynamicSL
Bonjour à tous,
Je bloque sur qch qui peut servir à bon d’entre-nous : sortir d’une stratégie quand un stop loss est touché car sinon la stratégie continue !!!!
@nicolas : help please !!!-)
Mille mercis
defparam cumulateorders = false
//entry = 21.1 // cas ou l'on veut rentrer sur un prix précis
n= round(1000/close)
// trailing stop sur Moyenne Mobile de Hull
Period=25
inner = 2*weightedaverage[ round( Period/2 ) ](close)-weightedaverage[Period](close)
MMHULL=weightedaverage[ round( sqrt(Period) ) ]( inner )
//if high > entry and high < entry*1.02 then // pour éviter de se faire gaper
buy n shares at market
SL = MMHULL
set stop loss SL
dynamicSL = SL
//endif
//dynamicSL
if longonmarket then
if (MMHULL>dynamicSL) then
dynamicSL=MMHULL
endif
sell at dynamicSL stop
//if close [tradeindex(1)] <= dynamicSL or close [tradeindex(1)] <= SL then // j'ai essayé cela mais ca ne marche pas ... ca ne marche pas non plus avec if low <= dynamicSL
//quit
//endif
endif
On peut tester POSITIONPERF si on était au marché sur la barre précédente et qu’on ne l’est plus à présent:
if onmarket[1] and not onmarket and positionperf(1)<0 then
quit
endif
super ; mille mercis Nicolas 😉
juste un point :
=> pourquoi positionperf serait négatif ?
Je viens d’essayer sans postionperf et le test fonctionne et la stratégie est quittée ;
Ca vous semble correct ?
Positionperf(N) retourne la performance du trade N, donc si elle est négative c’est que l’ordre est en perte (stoploss).
ok top donc c’est une condition supplémentaire mais pas nécessaire ;
Merci pour l’astuce !