Bonjour à toute la communauté,
J’utilise actuellement les instructions “SET STOP loss” et “SET TARGET PROFIT” pour placer mon SL et TP de façon dynamique :
IF ConditionsLONG THEN
BUY PositionSize CONTRACTS AT MARKET
SET STOP loss customVar
SET TARGET PROFIT TPfactor
ENDIF
IF ConditionsSHORT THEN
SELLSHORT PositionSize CONTRACTS AT MARKET
SET STOP loss customVar
SET TARGET PROFIT TPfactor
ENDIF
Sur une position où PositionSize = 2 je voudrais à présent placer un 2ème TP = customVar.
En d’autres termes, je voudrais placer deux TP différents :
- 1er contrat clôturé à 1 x SL pour sécuriser
- 2e contrat clôturé à 2 x SL (ou éventuellement en trailing stop)
Puisque les instructions “Set Stop” et “Set Target” ne peuvent être appelés qu’une seule fois par sens (long/short), quelle est la meilleure manière de structurer un ordre multi-TP, si c’est possible techniquement ?
Merci pour votre aide !
Vous devez utiliser SET TARGET PROFIT pour la dernière cible, la plus éloignée, et vérifier de combien le prix dépasse la première CIBLE, la plus proche, et sortir AT MARKET avec la moitié de votre position):
IF ConditionsLONG THEN
BUY PositionSize CONTRACTS AT MARKET
SET STOP loss customVar
SET TARGET PROFIT TPfactor*2
ENDIF
IF ConditionsSHORT THEN
SELLSHORT PositionSize CONTRACTS AT MARKET
SET STOP loss customVar
SET TARGET PROFIT TPfactor*2
ENDIF
IF abs(CountOfPosition) < PositionSize THEN
IF LongOnMarket AND (close - TradePrice) >= TPfactor THEN
SELL (PositionSize / 2) Contract at Market
ELSIF ShortOnMarket AND (TradePrice - close) >= TPfactor THEN
EXITSHORT (PositionSize / 2) Contract at Market
ENDIF
ENDIF
Super clair, merci beaucoup !
Lien vers le code ci-dessus ajouté en tant que journal 394 ici…
Snippet Link Library