4801Participant
Junior
Bonjour à tous et bonne année 2025.
J’ utilise en fin de code : SET STOP PLOSS 100 , afin de limiter mes pertes à 100. Si mon trade est ainsi clôturé par 1 ordre STOP, je souhaite ouvrir une nouvelle position
seulement en sens contraire du trade précédent clôturé par 1 STOP. Quel code doit-on écrire pour : ” le dernier trade a été cloturé par 1 ordre STOP “
J’ ai cherché un peu partout sans succès et vous remercie pour votre aide .
Voici le code :
ONCE TradeLong = 1
ONCE TradeShort = 1
ONCE LongFlag = 0
ONCE ShortFlag = 0
Sma20 = average[20,0](close)
// check whether the closed trade was a Loss or a Win
IF StrategyProfit < StrategyProfit[1] THEN
// If it's a loss, then only trade the opposite direction next time
IF LongFlag THEN
TradeLong = 0
TradeShort = 1
ELSIF ShortFlag THEN
TradeLong = 1
TradeShort = 0
ENDIF
ELSIF StrategyProfit > StrategyProfit[1] THEN
// If it's a win, then trade any direction
TradeLong = 1
TradeShort = 1
ENDIF
// Entry
IF Not OnMarket THEN
LongFlag = 0
ShortFlag = 0
IF close CROSSES OVER Sma20 AND TradeLong THEN
BUY 1 Contract at Market
LongFlag = 1
ELSIF close CROSSES UNDER Sma20 AND TradeShort THEN
SELLSHORT 1 Contract at Market
ShortFlag = 1
ENDIF
ENDIF
SET STOP pLOSS 100
SET TARGET pPROFIT 200
4801Participant
Junior
Bonjour Roberto,
Un grand merci pour votre aide . Le code que vous avez écrit est Top, cela fonctionne très bien. J’ ai mis un peu de temps à vous répondre suite une grippe.
Bonne journée.