Bonjour,
tout d’abord, merci pour ce super outils qu’est prorealtime, et la simplicité de son utilisation (même si ça parait pas très user friendly au début :D). Je code un bot (Ahah, je vous vois vous marrer), qui fonctionne très bien en positon longue pour l’instant, et j’essaye de lui adjoindre son inverse histoire de profiter des deux directions de marché.
Donc j’ajoute une boucle de SELLSHORT tel que ce qui suit :
IF timeok AND Not OnMarket AND C2 THEN
SELLSHORT NbShare SHARE AT MARKET
//SET STOP pLOSS Stoplossmini
SELLSHORTSELL = SELLSHORTSELL + 1
Graph SELLSHORTSELL AS "SELLCOMMAND"
BullFlag15 = 0
BearFlag15 = 0
ENDIF
Le graph de la variable SELLSHORTSELL montre bien que je rentre dans la boucle, et s’incrémente régulièrement (59 positions, enfin peu importe), mais dans le carnet d’ordre aucune trace des ventes courtes…
Je bug depuis 1 heure sur ce morceau de code sans comprendre. Est ce que vous voyez un truc que j’ai loupé?
Le defparam cumulateorders est à false ? Si oui le cumul de positions est désactivé.
Tu devrais sortir le GRAPH de ton bloc conditionnel, et le placer à la fin. Ta variable ne devrait pas s’incrémenter si tu es déjà au marché cependant ..
Merci pour ces réponses. Passer de Cumulate Order de True à False n’a rien changé.
Je Graph C2 maintenant pour detecter les triggers. On les voit bien passer de 1 à 0. Mais pas d’ordre correspondant. Et il n’y a pas de position en cours, je vais faire une passe en intégrant un “NOT ONMARKET” dans ma condition C2. Ca me rend fou! 😀
Je vous livre le code complet :
// DAX
// 1 Minute ticks
DEFPARAM CumulateOrders = True
//DEFPARAM PRELOADBARS = 1000
BrokerStop = 0
Stoplossmini = 10
NbShare = 1
// Noloss Parameter Place le Stop à PositionPrice+Margin Si Close > Positionprice + NolossGap
NoLoss = 1
NoLossBroker = a
NolossGap = 10
Margin = NolossGap - 5
timeframe(10 minute)
timeok = (time >090000 AND time <200000 )
// BULL DETECTOR
F115 = high[2] < high[1]
F215 = high[1] < high
F315 = high[2] < high[3]
F415 = high[3] < high[4]
FBull15 = F115 AND F215 AND F315 AND F415
IF FBull15 THEN
BullFlag15 = 1
Lastsummit15 = high[2]
BearFlag15 = 0
ENDIF
F1b15 = low[2] > low[1]
F2b15 = low[1] > low
F3b15 = low[2] > low[3]
F4b15 = low[3] > low[4]
FBear15 = F1b15 AND F2b15 AND F3b15 AND F4b15
//Graph BullFlag15 As "BullFlagh"
//Graph BearFlag15 As "BearFlag"
IF FBear15 THEN
BearFlag15 = 1
LastBottom15 = low[2]
BullFlag15 = 0
//Lastbottom15 = low[2]
ENDIF
timeframe(10 minute)
//====== Enter market - start =====
// LONG side
//MMOKBull = Average[a](close) > Average[a](close[1])
C1 = Close > Close[1] AND Close[1] CROSSES OVER Lastsummit15 AND BearFlag15 AND timeok
// Conditions pour ouvrir une position acheteuse
IF NOT LongOnMarket AND C1 THEN
BUY NbShare CONTRACTS AT MARKET
IF BrokerStop = 1 THEN
SET STOP pLOSS Stoplossmini
ENDIF
ENDIF
// SHORT side
//MMOKBear = Average[a](close) < Average[a](close[1])
CrossesUnderLastBottom = Close < Close[1] AND Close[1] CROSSES UNDER Lastbottom15
C2 = BullFlag15 AND CrossesUnderLastBottom AND TimeOK
//Graph Lastbottom15 as "LastBottom"
Graph C2 AS "C2"
//Graph BullFlag15 as "BullFlag15"
//Graph CrossesUnderLastBottom as "CrossesUnderLastBottom"
// Conditions pour ouvrir une position en vente à découvert
IF C2 THEN
SELLSHORT 1 CONTRACTS AT MARKET
IF BrokerStop = 1 THEN
SET STOP pLOSS Stoplossmini
ENDIF
ENDIF
//====== Enter market - end =====
//############ GESTION DE LA POSITION ###################### //
timeframe(2 minute)
// Detection de Fractale haussieres
F1 = high[2] < high[1]
F2 = high[1] < high
F3 = high[2] < high[3]
F4 = high[3] < high[4]
FBull = F1 AND F2 AND F3 AND F4
IF FBull THEN
BOTTOMClose = Close[2]
ENDIF
// Detection de Fractale baissiere
Fbe1 = low[2] > low[1]
Fbe2 = low[1] > low
Fbe3 = low[2] > low[3]
Fbe4 = low[3] > low[4]
FBear = Fbe1 AND Fbe2 AND Fbe3 AND Fbe4
IF FBear THEN
SummitClose = Close[2]
ENDIF
//--> NOLOSS
IF NoLoss = 1 AND Close > PositionPrice + NolossGap THEN
IF NoLossBroker = 1 THEN
SET STOP pLOSS Margin
ENDIF
LongNoLossPrice = PositionPrice + Margin
ENDIF
IF LongonMarket AND NoLoss = 1 AND Close CROSSES Under LongNoLossPrice THEN
SELL AT MARKET
ENDIF
IF NoLoss = 1 AND Close < PositionPrice - NolossGap THEN
IF NoLossBroker = 1 THEN
SET STOP pLOSS Margin
ENDIF
ShortNoLossPrice = PositionPrice - Margin
ENDIF
IF LongonMarket AND NoLoss = 1 AND Close CROSSES Under ShortNoLossPrice THEN
EXITSHORT AT MARKET
ENDIF
//--> Trailling stop
IF Close > BOTTOMclose THEN
stoploss1 = BOTTOMclose
ENDIF
IF LongonMarket AND Close < stoploss1 OR Close < PositionPrice - StopLossMini THEN
SELL AT MARKET
stoploss1 = 0
ENDIF
IF Close < SummitClose THEN
stoploss2 = SummitClose
ENDIF
IF ShortOnMarket AND Close > stoploss2 OR Close > PositionPrice + StopLossMini THEN
EXITSHORT AT MARKET
stoploss2 = 0
ENDIF
//--> Fermeture des positions en fin de journée
IF ShortOnMarket AND Not TimeOk THEN
EXITSHORT AT MARKET
stoploss2 = 0
ENDIF
IF LongOnMarket AND Not TimeOk THEN
SELL AT MARKET
stoploss2 = 0
ENDIF
//<-- Fin de fermeture des positions en fin de jorunée
Et ici, on voit les Trigger, mais pas d’ordre..
Je viens de tester sur mon compte démo, même résultat.
Et quand je remplace SELLSHORT par BUY, les ordres d’achat sont bien effectués.
Le problème vient du fait que tu évalues le timeframe 10 minutes à chaque clôture du TF le plus petit (fonctionnement normal quand on utilise pas “updateonclose”). Tes instructions de prises de positions sont situées dans le TF 10 minutes, mais aucun ordre ne sera passé puisque quand ta condition est bonne on ne se situe pas à la fermeture de la bougie 10-minutes.
Il faut donc déplacer tes commandes de lancement de positions dans le timeframe le plus petit.
Le code à sacrément évolué, j’ai laissé tomber cette histoire de SELLSHORT.
Dans la derniere version, il est dans le timeframe 1 minute.
// DAX
// 1 Minute ticks
DEFPARAM CumulateOrders = False
DEFPARAM PRELOADBARS = 200
//DEFPARAM PRELOADBARS = 1000
BrokerStop = 0
Stoplossmini = (BollingerUp - BollingerDown)/2
NbShare = 1
// Rocket Traill - Colllage du Stoploss au prix si croissance fusée!
RocketTrailActivation = 1
QuickEjectRatio = 13
// Noloss Parameter Place le Stop à PositionPrice+Margin Si Close > Positionprice + NolossGap
NoLoss = 1
NoLossBroker = 0
NolossGap = 7
Margin = NolossGap - 2
timeframe(10 minute)
timeok = (time >090000 AND time <200000 )
// ############ FLAG le marché Début
// BULL DETECTOR
F115 = high[2] < high[1]
F215 = high[1] < high
F315 = high[2] < high[3]
F415 = high[3] < high[4]
FBull15 = F115 AND F215 AND F315 AND F415
IF FBull15 THEN
BullFlag15 = 1
Lastsummit15 = high[2]
BearFlag15 = 0
ENDIF
F1b15 = low[2] > low[1]
F2b15 = low[1] > low
F3b15 = low[2] > low[3]
F4b15 = low[3] > low[4]
FBear15 = F1b15 AND F2b15 AND F3b15 AND F4b15
//Graph BullFlag15 As "BullFlagh"
//Graph BearFlag15 As "BearFlag"
IF FBear15 THEN
BearFlag15 = 1
LastBottom15 = low[2]
BullFlag15 = 0
//Lastbottom15 = low[2]
ENDIF
C1 = Close > Close[1] AND Close[1] CROSSES OVER Lastsummit15 AND BearFlag15 AND timeok AND NOT ONMARKET
C2 = BullFlag15 AND TimeOK AND NOT ONMARKET AND Close < Close[1] AND Close[1] CROSSES UNDER Lastbottom15
IF LongOnMarket THEN
BullFlag15 = 0
ENDIF
IF ShortOnMarket THEN
BearFlag15 = 0
ENDIF
Timeframe(1 minutes)
// ############# FLAG LE MARCHé Fin
//====== Enter market - start =====
// LONG side
// Conditions pour ouvrir une position acheteuse
IF NOT LongOnMarket AND C1 THEN
BUY NbShare CONTRACTS AT MARKET
IF BrokerStop = 1 THEN
SET STOP pLOSS Stoplossmini
ENDIF
ENDIF
// SHORT side
//Graph Lastbottom15 as "LastBottom"
//Graph BullFlag15 as "BullFlag15"
//Graph CrossesUnderLastBottom as "CrossesUnderLastBottom"
// Conditions pour ouvrir une position en vente à découvert
IF C2 THEN
SELLSHORT NbShare SHARES AT MARKET
IF BrokerStop = 1 THEN
SET STOP pLOSS Stoplossmini
ENDIF
ENDIF
//Graph C2 AS "C2"
//====== Enter market - end =====
//############ GESTION DE LA POSITION ###################### //
timeframe(2 minute)
// Detection de Fractale haussieres
F1 = high[2] < high[1]
F2 = high[1] < high
F3 = high[2] < high[3]
F4 = high[3] < high[4]
FBull = F1 AND F2 AND F3 AND F4
IF FBull THEN
BOTTOMClose = Close[2]
ENDIF
// Detection de Fractale baissiere
Fbe1 = low[2] > low[1]
Fbe2 = low[1] > low
Fbe3 = low[2] > low[3]
Fbe4 = low[3] > low[4]
FBear = Fbe1 AND Fbe2 AND Fbe3 AND Fbe4
IF FBear THEN
SummitClose = Close[2]
ENDIF
timeframe(1 minute)
//--> NOLOSS
IF NoLoss = 1 AND Close > PositionPrice + NolossGap THEN
IF NoLossBroker = 1 THEN
SET STOP pLOSS Margin
ENDIF
LongNoLossPrice = PositionPrice + Margin
ENDIF
IF LongonMarket AND NoLoss = 1 AND Close CROSSES Under LongNoLossPrice THEN
SELL AT MARKET
ENDIF
IF NoLoss = 1 AND Close < PositionPrice - NolossGap THEN
IF NoLossBroker = 1 THEN
SET STOP pLOSS Margin
ENDIF
ShortNoLossPrice = PositionPrice - Margin
ENDIF
IF LongonMarket AND NoLoss = 1 AND Close CROSSES Under ShortNoLossPrice THEN
EXITSHORT AT MARKET
ENDIF
//--> Fractal Trailling stop
IF Close > BOTTOMclose THEN
stoploss1 = BOTTOMclose
ENDIF
IF LongonMarket AND Close < stoploss1 OR Close < PositionPrice - StopLossMini THEN
SELL AT MARKET
stoploss1 = 0
ENDIF
IF Close < SummitClose THEN
stoploss2 = SummitClose
ENDIF
IF ShortOnMarket AND Close > stoploss2 OR Close > PositionPrice + StopLossMini THEN
EXITSHORT AT MARKET
stoploss2 = 0
ENDIF
//--> Rocket Trail Long
If NOT OnMarket THEN
Eject = 0
ENDIF
IF OnMarket AND RocketTrailActivation = 1 THEN
IF Close - open > QuickEjectRatio AND Close[1] - Open[1] > QuickEjectRatio THEN
QuickEjectInitiated = 1
ENDIF
ENDIF
Graph QuickEjectInitiated As "QuickEjectInitiated"
IF QuickEjectInitiated = 1 THEN
If Close < (High - Low)*0.3 OR Close < OPEN THEN
Eject = 1
QuickEjectInitiated = 0
ENDIF
ENDIF
//--> Fermeture des positions en fin de journée
IF ShortOnMarket AND Not TimeOk THEN
EXITSHORT AT MARKET
stoploss2 = 0
ENDIF
IF LongOnMarket AND Not TimeOk THEN
SELL AT MARKET
stoploss1 = 0
ENDIF
// EJECT!!!!
IF LongOnMarket AND Eject = 1 THEN
SELL AT MARKET
ENDIF
Graph Eject+2 As "Eject"