Bonjour à tous,
Je souhaite vendre après que mon prix ait cassé une MM à la baisse (condition 1) et que ce prix soit resté sous la MM les 30 bougies suivantes (condition 2).
Mon code me semble correct mais les ventes sur le graphique sont fausse. Quelqu’un maîtrise-t-il le barindex ?
Merci d’avance !
Livien
DEFPARAM CumulateOrders = FALSE //une seule position
Indicator1= Average[200](Close)
MyRsi=RSI[14](Close)
c1= Close CROSSES UNDER Indicator1
c2= Close < indicator1
// Conditions pour ouvrir une position acheteuse
IF NOT LongOnMarket AND MyRsi<30 THEN
Buy 1 CONTRACTS AT MARKET
ENDIF
// conditions pour ouvrir une position vendeuse
IF c1 THEN
bar1 = barindex
IF c2 and barindex-bar1<30 THEN
SELL 1 contracts at market
ENDIF
endif
Voilà:
DEFPARAM CumulateOrders = FALSE
Indicator1= Average[200](Close)
MyRsi=RSI[14](Close)
c1= Close CROSSES UNDER Indicator1
c2= Close < indicator1
IF NOT LongOnMarket AND MyRsi<30 THEN
Buy 1 CONTRACTS AT MARKET
ENDIF
IF c1[31] and summation[30](c2)=30 THEN
SELL 1 contracts at market
ENDIF
bonjour montil,
par exemple
barindex-tradeindex donne le nombre de bar quand tu es en position
cordialement
Oui, mais quand il y a un moyen plus facile, pourquoi ne pas l'utiliser? Il est préférable d’utiliser cette expression pour quitter après un nombre de mesures donné:
If barindex-tradeindex > 20 then
Sell at market
endif
A la ligne 9 ci-dessus, 31 doit être remplacé par 30.
Si vous souhaitez utiliser BarIndex, voici le code:
DEFPARAM CumulateOrders = FALSE
Indicator1= Average[200](Close)
MyRsi=RSI[14](Close)
c1= Close CROSSES UNDER Indicator1
c2= Close < indicator1
IF NOT LongOnMarket AND MyRsi<30 THEN
Buy 1 CONTRACTS AT MARKET
ENDIF
IF c1[30] AND LongOnMarket AND (BarIndex - TradeIndex) > 30 THEN
Flag = 1
FOR i = 0 TO 29
IF c2[i] = 0 THEN
Flag = 0
Break
ENDIF
NEXT
IF Flag = 1 THEN
SELL 1 Contract at market
ENDIF
ENDIF
Merci beaucoup pour la rapidité de vos réponses ! Cela fonctionne bien maintenant.