Bonjour,
J’essaie de coder un bot mais celui ci ne répond pas à mes attentes surement suites à des erreurs de codage.
Question N°1 => (Voir pj) Je veux mettre mon SL sous le plus bas de la bougie qui casse la EMA20 avec +2pts. Mais celui ci est trés souvent exécuter alors que les prix ne sont pas touchés.
Questions N°2 => (Voir pj) J’indique un TP1 à 2*SL et le TP2 à 3*SL mais seul le tp2 est pris alors qu’il y avait plusieurs cible pour prendre le TP2 et mis à BE.
Merci pour votre aide.
Voici le code:
DEFPARAM CUMULATEORDERS = false
DEFPARAM FLATBEFORE = 070000
DEFPARAM FLATAFTER = 183000
TIMEFRAME(5 Minute)
//Réinitialisation VALEUR
if Not OnMarket THEN
SLFinance = 0
SL = 0
endif
ema20 = ExponentialAverage[20](close)
Achat = open < ema20 and close > ema20+2
Vente = open > ema20 and close < ema20+2
if time>100000 and time<=1200000 AND Achat and Not OnMarket then
// POUR UN ACHAT
//Ordre Achat
BUY 1 CONTRACT AT MARKET
SLFinance = 1
SL = close-lowest[2](close[1])
SET STOP pLOSS SL
//SET TARGET pPROFIT 100
ELSIF time>100000 and time<=120000 AND Vente and Not OnMarket THEN
//Ordre VENTE
SELLSHORT 1 CONTRACT AT MARKET
SLFinance = 1
SL = close-highest[2](close[1])
SET STOP pLOSS SL
ENDIF
//SL et TP pour la position d'achat
if longonmarket and close-tradeprice>=SL*2 and SLFinance = 1 then
sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
if longonmarket and close-tradeprice>=SL*3 and SLFinance = 2 then //REMPLACER ENSUITE par IBX2
//sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
//SLFinance = 2
SELLSHORT AT MARKET
endif
//SL et TP pour la position de vente
//StopLoss financé à x points en coupant la moitié de la position
If shortonmarket and tradeprice-close>=SL*2 and SLFinance = 1 then
buy abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
If shortonmarket and tradeprice-close>=100/PipSize and SLFinance = 2 then//REMPLACER ENSUITE par IBX2
//buy abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
//SLFinance = 2
EXITSHORT AT MARKET
endif
GRAPHONPRICE SL
Essayez cette version :
DEFPARAM CUMULATEORDERS = false
DEFPARAM FLATBEFORE = 070000
DEFPARAM FLATAFTER = 183000
TIMEFRAME(5 Minute)
//Réinitialisation VALEUR
if Not OnMarket THEN
SLFinance = 0
//SL = 0
endif
ema20 = ExponentialAverage[20](close)
Achat = open < ema20 and close > ema20+2*pipsize
Vente = open > ema20 and close < ema20-2*pipsize
if time>100000 and time<=1200000 AND Achat and Not OnMarket then
// POUR UN ACHAT
//Ordre Achat
BUY 1 CONTRACT AT MARKET
SLFinance = 1
SL = low//close-lowest[2](close[1])
TP1 = close + (abs(close - SL) * 2)
TP2 = close + (abs(close - SL) * 3)
SET STOP PRICE SL
SET TARGET PRICE TP2
//SET TARGET pPROFIT 100
ELSIF time>100000 and time<=120000 AND Vente and Not OnMarket THEN
//Ordre VENTE
SELLSHORT 1 CONTRACT AT MARKET
SLFinance = 1
SL = high//close-highest[2](close[1])
TP1 = close + (abs(close - SL) * 2)
TP2 = close + (abs(close - SL) * 3)
SET STOP PRICE SL
SET TARGET PRICE TP2
ENDIF
//SL et TP pour la position d'achat
if longonmarket and close >= TP1 and SLFinance = 1 then
sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
if longonmarket and close-tradeprice>=SL*3 and SLFinance = 2 then //REMPLACER ENSUITE par IBX2
//sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
//SLFinance = 0
//SELLSHORT AT MARKET
endif
//SL et TP pour la position de vente
//StopLoss financé à x points en coupant la moitié de la position
if shortonmarket and close <= TP1 and SLFinance = 1 then
exitshort abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
If shortonmarket and tradeprice-close>=100/PipSize and SLFinance = 2 then//REMPLACER ENSUITE par IBX2
//buy abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
//SLFinance = 2
//EXITSHORT AT MARKET
endif
GRAPHONPRICE SL coloured("Red")
GRAPHONPRICE TP2 coloured("Blue")
Bonjour Roberto,
Merci pour ton retour. Malheureusement cela n’a rien changé. Les 2 TP sont pris au TP2, aucun de pris au TP1
Voir pj
Je pense que le problème vient de ces 2 lignes et en remplacement par *1 et *2 cela a l’air de fonctionner. Je te retiens au courant.
TP1 = close + (abs(close – SL) * 2) => * 1)
TP2 = close + (abs(close – SL) * 3) => * 2)
Pouvez vous me dire comment mettre les TP pour une position “Short” car comme ci dessous cela m’ouvre et me ferme la position aussitôt.
TP1 = close + (abs(close – SL) * 1)
TP2 = close + (abs(close – SL) * 2)
C’est bon j’ai trouvé merci 🙂
Maintenant toutes mes positions s’ouvrent et se ferment aussitôt (Voir pj)
if "condition" and Not OnMarket then
// POUR UN ACHAT
//Ordre Achat
BUY 1 CONTRACT AT MARKET
SLFinance = 1
SL = LOW//close-lowest[2](close[1])
TP1 = close + (abs(close - SL) * 1)
TP2 = close + (abs(close - SL) * 2)
SET STOP pLOSS SL
ELSIF "condition" and Not OnMarket THEN
//Ordre VENTE
SELLSHORT 1 CONTRACT AT MARKET
SLFinance = 1
SL = HIGH//close-highest[2](close[1])
TP1 = close - (abs(SL - close) * 1)
TP2 = close - (abs(SL - close) * 2)
SET STOP pLOSS SL
ENDIF
//SL et TP pour la position d'achat
if longonmarket and close >= TP1 and SLFinance = 1 then
sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
//if longonmarket and close-tradeprice>=100/PipSize and SLFinance = 2 then
//sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
//SLFinance = 2
//SELLSHORT AT MARKET
//endif
//SL et TP pour la position de vente
If shortonmarket and close >= TP1 and SLFinance = 1 then
buy abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
set stop BREAKEVEN
SLFinance = 2
endif
//If shortonmarket and tradeprice-close>=100/PipSize and SLFinance = 2 then
//buy abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
//SLFinance = 2
//EXITSHORT AT MARKET
//endif
GRAPHONPRICE SL coloured("Red")
GRAPHONPRICE TP1 coloured("Blue")
GRAPHONPRICE TP2 coloured("GREEN")