Bonjour,
Pouvez m’indiquer pourquoi mes positions s’ouvrent et se ferment aussitôt.
Merci
if Achat and Not OnMarket then
// POUR UN ACHAT
//Ordre Achat
BUY 1 CONTRACT AT MARKET
SLFinance = 1
SLA = LOW//close-lowest[2](close[1])
TP1A = close + (abs(close - SLA) * 1)
TP2A = close + (abs(close - SLA) * 2)
SET STOP pLOSS SLA
ELSIF Vente and Not OnMarket THEN
//Ordre VENTE
SELLSHORT 1 CONTRACT AT MARKET
SLFinance = 1
SLV = HIGH//close-highest[2](close[1])
TP1V = close - (abs(SLV - close) * 1)
TP2V = close - (abs(SLV - close) * 2)
SET STOP pLOSS SLV
ENDIF
//SL et TP pour la position d'achat
if longonmarket and close >= TP1A and SLFinance = 1 then
sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
//SL et TP pour la position de vente
If shortonmarket and close >= TP1V and SLFinance = 1 then
buy abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
GRAPHONPRICE SLV coloured("Red")
GRAPHONPRICE TP1V coloured("Blue")
GRAPHONPRICE TP2V coloured("GREEN")
Sur la ligne 29, vous ne devez PAS utiliser « BUY », car elle sert à ouvrir une position longue (et donc à clôturer la position courte actuelle).
Pour sortir d’une position courte, vous devez utiliser « EXITSHORT» :
EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
Merci Roberto mais malgré ce changement cela est toujours pareil. Il doit y avoir quelque chose d’autre
If shortonmarket and close >= TP1V and SLFinance = 1 then
EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
DEFPARAM CUMULATEORDERS = false
TIMEFRAME(5 Minute)
//Réinitialisation VALEUR
if Not OnMarket THEN
SLFinance = 0
//SL = 0
//TP1 = 0
//TP2 = 0
endif
niveau = 23460
Achat = open < niveau and close > niveau+2*pipsize
Vente = open > niveau and close < niveau+2*pipsize
if Achat and Not OnMarket then
// POUR UN ACHAT
//Ordre Achat
BUY 1 CONTRACT AT MARKET
SLFinance = 1
SLA = LOW//close-lowest[2](close[1])
TP1A = close + (abs(close - SLA) * 1)
TP2A = close + (abs(close - SLA) * 2)
SET STOP pLOSS SLA
ELSIF Vente and Not OnMarket THEN
//Ordre VENTE
SELLSHORT 1 CONTRACT AT MARKET
SLFinance = 1
SLV = HIGH//close-highest[2](close[1])
TP1V = close - (abs(SLV - close) * 1)
TP2V = close - (abs(SLV - close) * 2)
SET STOP pLOSS SLV
ENDIF
//SL et TP pour la position d'achat
if longonmarket and close >= TP1A and SLFinance = 1 then
sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
//SL et TP pour la position de vente
If shortonmarket and close >= TP1V and SLFinance = 1 then
EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
GRAPHONPRICE SLV coloured("Red")
GRAPHONPRICE TP1V coloured("Blue")
GRAPHONPRICE TP2V coloured("GREEN")
Bonjour,
Dans le code du post d’en-tête, si ta ligne 21 pour un achat dit:
if longonmarket and close >= TP1A and …
par analogie j’aurais imaginé ta ligne 28 non pas: If shortonmarket and close >= TP1V and …
mais plutôt: If shortonmarket and close <= TP1V
A tester.
Bonjour JC,
Non ce n’est pas cela non plus 🙁
Les set stop ploss ne sont pas ok non plus, car tu leur as mis un niveau alors que cette commande s’attend à une distance en points, par exemple close-SLA plutôt que SLA
Je ne juge pas de la validité ou pas de ton stop, mais de la nature de la valeur que tu as associé à la commande ploss, c’est-à-dire si j’enlève le terme SLA de la discussion pour ne pas être ambigu: “set stop ploss (close-low)” serait correct là où “set stop ploss low” (puisque ton SLA=low) ne n’est pas.
(et à la vente “set stop ploss high-close” serait correct là où “set stop ploss high” (puisque ton slv=high) ne n’est pas.)
Entendu, je vais tester cela.
Par contre, lorsque j’affiche ces données sur le graphique, elles sont correctement identifiées grâce à “GRAPHONPRICE ” comme tu peux le voir sur la pj.
GRAPHONPRICE SLV coloured(“Red”)
GRAPHONPRICE TP1V coloured(“Blue”)
GRAPHONPRICE TP2V coloured(“GREEN”)
J’ai essayé ce code mais ne fonctionne pas. Pourtant celui ci m’avait l’air correct … Je souhaite simplement le SL au dessus /dessous de la bougie précédente et ensuite Tp *1 et *2
DEFPARAM CUMULATEORDERS = false
TIMEFRAME(5 Minute)
//Réinitialisation VALEUR
if Not OnMarket THEN
SLFinance = 0
//SL = 0
//TP1 = 0
//TP2 = 0
endif
niveau = 23460
Achat = open < niveau and close > niveau+2*pipsize
Vente = open > niveau and close < niveau+2*pipsize
if Achat and Not OnMarket then
// POUR UN ACHAT
//Ordre Achat
BUY 1 CONTRACT AT MARKET
SLFinance = 1
SLA = abs(close - Low[1]) //low//close-lowest[2](close[1])
TP1A = SLA*2 //close + (abs(close - SLA) * 1)
TP2A = SLA*3 //close + (abs(close - SLA) * 2)
SET STOP pLOSS SLA
ELSIF Vente and Not OnMarket THEN
//Ordre VENTE
SELLSHORT 1 CONTRACT AT MARKET
SLFinance = 1
SLV = abs(close - High[1])
TP1V = SLV*2 //close - (abs(SLV - close) * 1)
TP2V = SLV*3 //close - (abs(SLV - close) * 2)
SET STOP pLOSS SLV
ENDIF
//SL et TP pour la position d'achat
if longonmarket and close >= TP1A and SLFinance = 1 then
sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
//SL et TP pour la position de vente
If shortonmarket and close >= TP1V and SLFinance = 1 then
EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
GRAPHONPRICE SLV coloured("Red")
GRAPHONPRICE TP1V coloured("Blue")
GRAPHONPRICE TP2V coloured("GREEN")
JSParticipant
Senior
Tu calcules : SLA = abs(Close – Low[1])
Ce calcul donne un nombre de points, donc pas un niveau de prix mais bien un nombre de points (par exemple 10 points).
Ensuite, tu ecris :
If LongOnMarket and Close >= TP1A and SLFinance = 1 then
Tu verifies alors si Close est superieur ou egal a un nombre de points.
Mais Close est naturellement toujours superieur a une valeur exprimee en points (SL), ce qui fait que ta position est immediatement cloturee partiellement (abs(CountOfPosition) / 2).
JSParticipant
Senior
Voici le code modifié avec l’utilisation de niveaux de prix…
DEFPARAM CUMULATEORDERS = false
TIMEFRAME(5 Minute)
//Réinitialisation VALEUR
if Not OnMarket THEN
SLFinance = 0
//SL = 0
//TP1 = 0
//TP2 = 0
endif
niveau = 42000 //Dow Jones
Achat = open < niveau and close > niveau+2*pipsize
Vente = open > niveau and close < niveau+2*pipsize
if Achat and Not OnMarket then
// POUR UN ACHAT
//Ordre Achat
BUY 1 CONTRACT AT MARKET
SLFinance = 1
SLA = Close-abs(Close - Low[1]) //low//close-lowest[2](close[1])
TP1A = Close+2*(abs(Close-Low[1])) //close + (abs(close - SLA) * 1)
TP2A = Close+3*(abs(Close-Low[1])) //close + (abs(close - SLA) * 2)
SET STOP Price SLA
ELSIF Vente and Not OnMarket THEN
//Ordre VENTE
SELLSHORT 1 CONTRACT AT MARKET
SLFinance = 1
SLV = Close+abs(close - High[1])
TP1V = Close-2*(abs(Close-High[1])) //close - (abs(SLV - close) * 1)
TP2V = Close-3*(abs(Close-High[1])) //close - (abs(SLV - close) * 2)
SET STOP Price SLV
ENDIF
//SL et TP pour la position d'achat
if longonmarket and close >= TP1A and SLFinance = 1 then
sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
//SL et TP pour la position de vente
If shortonmarket and close <= TP1V and SLFinance = 1 then
EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
GRAPHONPRICE SLV coloured("Red")
GRAPHONPRICE TP1V coloured("Blue")
GRAPHONPRICE TP2V coloured("GREEN")
Bonjour JS,
Merci pour tes retours. Effectivement, oui j’affichais un niveau de prix et non un nombre de point.
J’ai relancé l’algo, j’ai maintenant juste un soucis de le Stop Loss qui ne s’affiche pas sur le plus Haut/bas de la bougie précédente mais environ 30pts au dessus comme tu peux le voir sur la piece jointe.
Sais tu de quoi cela peux venir ?
Merci encore pour ton aide.
JSParticipant
Senior
Salut,
Lorsqu’un ordre est passe, le stop loss (SL) depend de la taille de la bougie precedente : SLV = Close + abs(Close - High[1])…
Le SL est donc variable et depend de la distance entre Close et High[1]…
Une grande distance entraine un SL plus large…