Bonjour ,
pour continuer mon développement de stratégie, peut on mettre un robot en pause pendant 5 mn par exemple après la clôture d’une position?
Si oui quel type de code dois je utiliser?
Merci,
On peut compter en terme de bougies par exemple:
//1)
waitbar = 5
//2)
if not onmarket and (onmarket[1] or longtriggered or shorttriggered) then
lastindex = barindex
endif
//3)
gotrading = barindex-lastindex >= waitbar
Explication du code dans l’ordre:
- définition du paramètre pour la quantité de barres à attendre après un ordre
- test si on est plus au marché alors qu’on l’était à la barre précédente et enregistrement du barindex
- variable booléenne (à mettre dans ta chaîne de conditions pour ouvrir une position) qui teste si on a suffisamment de barres depuis le dernier trade
Bonjour Nicolas,
merci pour la réponse mais cela ne fonctionne pas , peut être que j’ai mal positionné le code, ci joint le détail.
DEFPARAM cumulateorders = false
DEFPARAM FlatAfter =200000
tradestart = time > 090000
Tradeend= time < 140000
joursdetrading = dayofweek>=1 and dayofweek<=6
TakeProfit = 30
//
waitbar = 5
if not onmarket and (onmarket[1] or longtriggered or shorttriggered) then
lastindex = barindex
endif
gotrading = barindex-lastindex >= waitbar
//
MM100 = Average[100](close)
IF MM100 > MM100[20]and joursdetrading AND tradestart AND tradeend THEN
BUY 3 SHARES AT MARKET
ENDIF
IF MM100 < MM100[20] and joursdetrading AND tradestart AND tradeend THEN
SELLSHORT 3 SHARES AT MARKET
ENDIF
SET STOP %LOSS 0.1
SET TARGET PPROFIT TakeProfit
La variable gotrading n’est pas utilisé dans tes conditions pour ouvrir les positions. Il faut l’ajouter à ta chaîne IF AND THEN
Merci Nicolas, le code fonctionne très bien sur une stratégie simple en revanche dès que ça se complique un peut ça ne va plus.
je te joins ici le développement sur lequel je travaille actuellement la base est ton indicateur “Supertrend+CCI” :
DEFPARAM CumulateOrders = false // Cumul des positions désactivé
// System closes all orders at 00.00 No new orders allowed until "FLATBEFORE" time
DEFPARAM FLATBEFORE = 090000
// Cancel all orders and close all positions at "FLATAFTER" Time
DEFPARAM FLATAFTER = 180000
joursdetrading = dayofweek>=1 and dayofweek<=5
// No new orders or enlarging position before
noEntryBeforeTime = 090000
timeEnterBefore = time >= noEntryBeforeTime
// No new orders or enlarging positions after
noEntryAfterTime = 180000
timeEnterAfter = time < noEntryAfterTime
// --- settings
CCIPeriod = 50 // Période de l'indicateur CCI
ATRPeriod = 5 // Période de l'indicateur ATR
Level = 0 // Niveau d'activation du CCI
// --- fin des paramètres
//
waitbar = 3
if not onmarket and (onmarket[1] or longtriggered or shorttriggered) then
lastindex = barindex
endif
gotrading = barindex-lastindex >= waitbar
//
icci = CCI[CCIPeriod](typicalPrice)
iatr = AverageTrueRange[ATRPeriod](close)
TrendUp = 0.0
TrendDown = 0.0
SignUp = 0.0
SignDown = 0.0
if (icci >= Level and icci[1] < Level) then
TrendUp = TrendDown[1]
endif
if (icci <= Level and icci[1] > Level) then
TrendDown = TrendUp[1]
endif
if (icci > Level) then
TrendUp = low - iatr
if (TrendUp < TrendUp[1] and icci[1] >= Level) then
TrendUp = TrendUp[1]
endif
endif
if (icci < Level) then
TrendDown = high + iatr
if (TrendDown > TrendDown[1] and icci[1] <= Level) then
TrendDown = TrendDown[1]
endif
endif
if (TrendDown[1] <> 0.0 and TrendUp <> 0.0) then
SignUp = TrendUp
endif
if (TrendUp[1] <> 0.0 and TrendDown <> 0.0) then
SignDown = TrendDown
endif
st = max(TrendUp, TrendDown)
// Conditions de trading
longCondition = TrendUp > 0.0
shortCondition = TrendDown > 0.0
// Entrée en position longue
if (longCondition)AND joursdetrading and gotrading then
Buy 3 CONTRACT at market
endif
// Entrée en position courte
if (shortCondition)AND joursdetrading and gotrading then
Sellshort 3 CONTRACT at market
endif
// Sortie de position longue
if (shortCondition)AND joursdetrading and gotrading then
Sellshort 3 CONTRACT at market
endif
// Sortie de position courte
if (longCondition)AND joursdetrading and gotrading then
Buy 3 CONTRACT at market
endif
SET STOP %LOSS 0.25
Pour moi ça fonctionne, si je graph gotrading, je remarque bien qu’elle retourne 0 durant 3 chandeliers dés qu’un ordre se ferme (voir image).
Quand je fais un back test sur la journée d’aujourd’hui voilà ce que ça donne, on voit bien qu’une position s’ouvre dès la fermeture de la précédente ??
Merci de m’indiquer timeframe et instrument.
C’est normal, les positions sont clôturées par l’ouverture d’une nouvelle position inverse. Donc à aucun moment nous n’avons plus était au marché et dans ce cas pas d’attente.
Pour mémoire, la demande initiale était: “peut on mettre un robot en pause pendant 5 mn par exemple après la clôture d’une position?”
Merci beaucoup pour la réponse c’est très clair, en revanche y a t il une possibilité pour décaler le déclenchement de la suivante afin d’éviter ces ouvertures/fermetures consécutives?
Donc cela modifierait ta stratégie, si il y a une condition pour ouvrir un ordre inverse alors que nous sommes déjà au marché, il ne faut pas l’ouvrir ?
Oui par exemple, on peut essayer. Si tu pouvais me faire la modification du code ça serait sympa. Merci
Pour éviter qu’un short ferme et long et vice-versa, ajoute Not Onmarket dans tes conditions. J’ai oublié de l’intégrer dans une stratégie live et j”ai perdu de l’argent bêtement.
Exemple:
if Not Onmarket AND (longCondition)AND joursdetrading and gotrading then
Buy 3 CONTRACT at market
endif
Je ne sais pas si tu peux ouvrir 2 positions dans le même sens. Ca donnerait:
if Not ShortOnMarket AND (longCondition) AND joursdetrading and gotrading then
Buy 3 CONTRACT at market
endif
Merci , je vais regarder ça.